connected search to chat

master
nberting 7 years ago
parent 7c82f2af95
commit d49738db27

@ -84,7 +84,6 @@ class Chat(db.Model):
self.message = message self.message = message
self.time = datetime.datetime.utcnow() self.time = datetime.datetime.utcnow()
class Stack(db.Model): class Stack(db.Model):
__tablename__ = 'stacks' __tablename__ = 'stacks'
id = db.Column(db.Integer, primary_key = True) id = db.Column(db.Integer, primary_key = True)

@ -139,7 +139,7 @@ font-size: 18px;
padding:6px 15px; padding:6px 15px;
left:0px; left:0px;
border:0px solid #dbdbdb; border:0px solid #dbdbdb;
background-color: grey; background-color: #686d72;
color:#fafafa; color:#fafafa;
} }
@ -225,7 +225,7 @@ div.marquee > div.marquee-text {
padding: 10px; padding: 10px;
margin: 0px; margin: 0px;
height: 100%; height: 100%;
background-color: #551A8B; background-color: #b4b9be;
overflow-y: scroll; overflow-y: scroll;
overflow-x: hidden; overflow-x: hidden;
color: white; color: white;
@ -262,7 +262,7 @@ z-index: 100000;
margin:0px!important; margin:0px!important;
padding:0px!important; padding:0px!important;
height: 40px; height: 40px;
font-size: 20px; font-size: 16px;
word-wrap: break-word; word-wrap: break-word;
word-break: break-all; word-break: break-all;
float: left; float: left;
@ -287,7 +287,7 @@ box-sizing: border-box;
margin-top: 20px; margin-top: 20px;
} }
.messages .msg{ .messages .msg{
font-size: 30px; font-size: 24px;
margin: 0px; margin: 0px;
margin-top: -15px; margin-top: -15px;
margin-bottom: 10px; margin-bottom: 10px;

@ -60,7 +60,7 @@ console.log(time)
return ('0'+time.getDate()).slice(-2) + '.' + ('0'+(time.getMonth()+1)).slice(-2) + '.' + time.getFullYear() +" " + ('0'+time.getHours()).slice(-2)+":"+ ('0'+time.getMinutes()).slice(-2); return ('0'+time.getDate()).slice(-2) + '.' + ('0'+(time.getMonth()+1)).slice(-2) + '.' + time.getFullYear() +" " + ('0'+time.getHours()).slice(-2)+":"+ ('0'+time.getMinutes()).slice(-2);
} }
//change addr when ONLINE::::::-> //change addr when ONLINE::::::->
var socket = io.connect('http://localhost:5000'); var socket = io.connect('http://localhost:8080');
var app = new Vue({ var app = new Vue({
el: "#app", el: "#app",
delimiters: ['[[', ']]'], delimiters: ['[[', ']]'],

@ -1,13 +1,17 @@
{% extends 'base.html' %} {% extends 'base.html' %}
{% block main %} {% block main %}
<div class="container"> <div class="container">
{% from "_formhelpers.html" import render_field %} {% from "_formhelpers.html" import render_field %}
<form method="POST"> <form method="POST">
<div>{{ form.select(style="width: 100px; margin: 10px; float: left; font-size: 20px") }}</div> <div>{{ form.select(style="width: 100px; margin: 10px; float: left; font-size: 20px") }}</div>
<div class="search"> <div class="search">
{{ render_field(form.search) }} </div> {{ render_field(form.search) }} </div>
<button type="submit" class="button">browse</button> <button type="submit" @click="sendMessage" class="button is-info" >browse</button>
<p><br> <p><br>
{{ form.grid(style="font-size:20px")}}{{ form.listview(style="font-size:20px")}}</p> {{ form.grid(style="font-size:20px")}}{{ form.listview(style="font-size:20px")}}</p>
</form> </form>

@ -45,6 +45,7 @@ def allowed_file(filename):
def home(): def home():
chat_form = ChatForm() chat_form = ChatForm()
chat_messages = db.session.query(Chat).all() chat_messages = db.session.query(Chat).all()
username = 'librarian'
# if request.method == 'POST': # if request.method == 'POST':
# if chat_form.validate_on_submit(): # if chat_form.validate_on_submit():
@ -53,7 +54,7 @@ def home():
# db.session.add(msg) # db.session.add(msg)
# db.session.commit() # db.session.commit()
return render_template('home.html',domain=DOMAIN,chat=chat_messages, channel = 1, username="librarian") return render_template('home.html',domain=DOMAIN,chat=chat_messages, channel = 1, username=username)
@app.route('/hello/<name>') @app.route('/hello/<name>')
def hello(name): def hello(name):
@ -368,6 +369,23 @@ def show_books():
return render_template ('show_books.html', books=books, form=search) return render_template ('show_books.html', books=books, form=search)
if request.method == 'POST': if request.method == 'POST':
newmsg = 'searched for: ' + search.search.data
# message = search.search.data
# newmessage = Chat(message)
# db.session.add(newmessage)
# db.session.commit()
# Send search to socket chat
socketio.emit('channel-' + str(1), {
'username': 'Search form',
'text': search.search.data,
'time': str(datetime.datetime.utcnow().strftime("%d.%m.%Y %H:%M"))}, broadcast=True)
# Save message
my_new_chat = Chat(message=newmsg)
db.session.add(my_new_chat)
try:
db.session.commit()
except:
db.session.rollback()
return redirect((url_for('search_results', searchtype=search.select.data, query=search.search.data, viewby=viewby))) return redirect((url_for('search_results', searchtype=search.select.data, query=search.search.data, viewby=viewby)))
return render_template('show_books.html', books=books, form=search) return render_template('show_books.html', books=books, form=search)
@ -415,6 +433,19 @@ def search_results(searchtype, query, viewby):
return render_template('results_grid.html', books=results, form=search, query=query, books_all=random_order, searchtype=search.select.data, count = count, whole = whole, percentage = percentage) return render_template('results_grid.html', books=results, form=search, query=query, books_all=random_order, searchtype=search.select.data, count = count, whole = whole, percentage = percentage)
if request.method == 'POST': if request.method == 'POST':
newmsg = 'searched for: ' + search.search.data
socketio.emit('channel-' + str(1), {
'username': 'Search form',
'text': search.search.data,
'time': str(datetime.datetime.utcnow().strftime("%d.%m.%Y %H:%M"))}, broadcast=True)
# Save message
my_new_chat = Chat(message=newmsg)
db.session.add(my_new_chat)
try:
db.session.commit()
except:
db.session.rollback()
query = search.search.data query = search.search.data
results = [] results = []
if viewby == '1': if viewby == '1':
@ -562,7 +593,6 @@ def new_message(message):
db.session.rollback() db.session.rollback()
if __name__ == '__main__': if __name__ == '__main__':
socketio.run(app) socketio.run(app)
#app.run(debug=True,host="0.0.0.0",port="8080") #app.run(debug=True,host="0.0.0.0",port="8080")

@ -1,4 +1,4 @@
#! /usr/bin/env python #! /usr/bin/env python
from app import app, socketio from app import app, socketio
socketio.run(app) socketio.run(app, port=8080)
#app.run(debug=True,host="0.0.0.0",port=8080) #app.run(debug=True,host="0.0.0.0",port=8080)

Loading…
Cancel
Save