display tag on important paste and search

This commit is contained in:
Terrtia 2018-05-17 11:00:05 +02:00
parent 0d164b6f4c
commit 4fbbf8bbd2
No known key found for this signature in database
GPG key ID: 1E1B1F50D84613D0
4 changed files with 159 additions and 23 deletions

View file

@ -20,6 +20,7 @@ app = Flask_config.app
cfg = Flask_config.cfg cfg = Flask_config.cfg
max_preview_char = Flask_config.max_preview_char max_preview_char = Flask_config.max_preview_char
max_preview_modal = Flask_config.max_preview_modal max_preview_modal = Flask_config.max_preview_modal
r_serv_metadata = Flask_config.r_serv_metadata
#init all lvlDB servers #init all lvlDB servers
curYear = datetime.now().year curYear = datetime.now().year
@ -56,6 +57,14 @@ def getPastebyType(server, module_name):
def event_stream_getImportantPasteByModule(module_name, year): def event_stream_getImportantPasteByModule(module_name, year):
index = 0 index = 0
all_pastes_list = getPastebyType(r_serv_db[year], module_name) all_pastes_list = getPastebyType(r_serv_db[year], module_name)
paste_tags = []
bootstrap_label = []
bootstrap_label.append('primary')
bootstrap_label.append('success')
bootstrap_label.append('danger')
bootstrap_label.append('warning')
bootstrap_label.append('info')
bootstrap_label.append('dark')
for path in all_pastes_list: for path in all_pastes_list:
index += 1 index += 1
@ -64,6 +73,22 @@ def event_stream_getImportantPasteByModule(module_name, year):
content_range = max_preview_char if len(content)>max_preview_char else len(content)-1 content_range = max_preview_char if len(content)>max_preview_char else len(content)-1
curr_date = str(paste._get_p_date()) curr_date = str(paste._get_p_date())
curr_date = curr_date[0:4]+'/'+curr_date[4:6]+'/'+curr_date[6:] curr_date = curr_date[0:4]+'/'+curr_date[4:6]+'/'+curr_date[6:]
p_tags = r_serv_metadata.smembers('tag:'+path)
l_tags = []
for tag in p_tags:
tag = tag.split('=')
if len(tag) > 1:
if tag[1] != '':
tag = tag[1][1:-1]
# no value
else:
tag = tag[0][1:-1]
# use for custom tags
else:
tag = tag[0]
l_tags.append(tag)
data = {} data = {}
data["module"] = module_name data["module"] = module_name
data["index"] = index data["index"] = index
@ -71,6 +96,8 @@ def event_stream_getImportantPasteByModule(module_name, year):
data["content"] = content[0:content_range] data["content"] = content[0:content_range]
data["linenum"] = paste.get_lines_info()[0] data["linenum"] = paste.get_lines_info()[0]
data["date"] = curr_date data["date"] = curr_date
data["l_tags"] = l_tags
data["bootstrap_label"] = bootstrap_label
data["char_to_display"] = max_preview_modal data["char_to_display"] = max_preview_modal
data["finished"] = True if index == len(all_pastes_list) else False data["finished"] = True if index == len(all_pastes_list) else False
yield 'retry: 100000\ndata: %s\n\n' % json.dumps(data) #retry to avoid reconnection of the browser yield 'retry: 100000\ndata: %s\n\n' % json.dumps(data) #retry to avoid reconnection of the browser
@ -98,8 +125,17 @@ def importantPasteByModule():
paste_date = [] paste_date = []
paste_linenum = [] paste_linenum = []
all_path = [] all_path = []
paste_tags = []
allPastes = getPastebyType(r_serv_db[currentSelectYear], module_name) allPastes = getPastebyType(r_serv_db[currentSelectYear], module_name)
bootstrap_label = []
bootstrap_label.append('primary')
bootstrap_label.append('success')
bootstrap_label.append('danger')
bootstrap_label.append('warning')
bootstrap_label.append('info')
bootstrap_label.append('dark')
for path in allPastes[0:10]: for path in allPastes[0:10]:
all_path.append(path) all_path.append(path)
paste = Paste.Paste(path) paste = Paste.Paste(path)
@ -110,6 +146,23 @@ def importantPasteByModule():
curr_date = curr_date[0:4]+'/'+curr_date[4:6]+'/'+curr_date[6:] curr_date = curr_date[0:4]+'/'+curr_date[4:6]+'/'+curr_date[6:]
paste_date.append(curr_date) paste_date.append(curr_date)
paste_linenum.append(paste.get_lines_info()[0]) paste_linenum.append(paste.get_lines_info()[0])
p_tags = r_serv_metadata.smembers('tag:'+path)
l_tags = []
for tag in p_tags:
tag = tag.split('=')
if len(tag) > 1:
if tag[1] != '':
tag = tag[1][1:-1]
# no value
else:
tag = tag[0][1:-1]
# use for custom tags
else:
tag = tag[0]
l_tags.append(tag)
paste_tags.append(l_tags)
if len(allPastes) > 10: if len(allPastes) > 10:
finished = False finished = False
@ -124,6 +177,8 @@ def importantPasteByModule():
paste_date=paste_date, paste_date=paste_date,
paste_linenum=paste_linenum, paste_linenum=paste_linenum,
char_to_display=max_preview_modal, char_to_display=max_preview_modal,
paste_tags=paste_tags,
bootstrap_label=bootstrap_label,
finished=finished) finished=finished)
@browsepastes.route("/_getImportantPasteByModule", methods=['GET']) @browsepastes.route("/_getImportantPasteByModule", methods=['GET'])

View file

@ -12,7 +12,13 @@
{% for path in all_path %} {% for path in all_path %}
<tr> <tr>
<td> {{ loop.index0 }}</td> <td> {{ loop.index0 }}</td>
<td><a target="_blank" href="{{ url_for('showsavedpastes.showsavedpaste') }}?paste={{path}}&num={{loop.index0+1}}">{{ path }}</a></td> <td><a target="_blank" href="{{ url_for('showsavedpastes.showsavedpaste') }}?paste={{path}}">{{ path }}</a>
<div>
{% for tag in paste_tags[loop.index0] %}
<span class="label label-{{ bootstrap_label[loop.index0 % 6] }} pull-left">{{ tag }}</span>
{% endfor %}
</div>
</td>
<td>{{ paste_date[loop.index0] }}</td> <td>{{ paste_date[loop.index0] }}</td>
<td>{{ paste_linenum[loop.index0] }}</td> <td>{{ paste_linenum[loop.index0] }}</td>
<td><p><span class="glyphicon glyphicon-info-sign" data-toggle="tooltip" data-placement="left" title="{{ content[loop.index0] }} "></span> <button type="button" class="btn-link" data-num="{{ loop.index0 + 1 }}" data-toggle="modal" data-target="#mymodal" data-url="{{ url_for('showsavedpastes.showsavedpaste') }}?paste={{ path }}&num={{ loop.index0+1 }}" data-path="{{ path }}"><span class="fa fa-search-plus"></span></button></p></td> <td><p><span class="glyphicon glyphicon-info-sign" data-toggle="tooltip" data-placement="left" title="{{ content[loop.index0] }} "></span> <button type="button" class="btn-link" data-num="{{ loop.index0 + 1 }}" data-toggle="modal" data-target="#mymodal" data-url="{{ url_for('showsavedpastes.showsavedpaste') }}?paste={{ path }}&num={{ loop.index0+1 }}" data-path="{{ path }}"><span class="fa fa-search-plus"></span></button></p></td>
@ -89,9 +95,14 @@ function add_entries_X(to_add) {
} else { } else {
var feed = json_array.shift(); var feed = json_array.shift();
elem_added++; elem_added++;
var tag = ""
for(j=0; j<feed.l_tags.length; j++) {
tag = tag + "<span class=\"label label-" + feed.bootstrap_label[j % 6] + " pull-left\">" + feed.l_tags[j] + "</span>"
}
search_table.row.add( [ search_table.row.add( [
feed.index, feed.index,
"<a target=\"_blank\" href=\"{{ url_for('showsavedpastes.showsavedpaste') }}?paste="+feed.path+"&num="+feed.index+"\"> "+ feed.path +"</a>", "<a target=\"_blank\" href=\"{{ url_for('showsavedpastes.showsavedpaste') }}?paste="+feed.path+"&num="+feed.index+"\"> "+ feed.path +"</a>"
+ "<div>" + tag + "</div>" ,
feed.date, feed.date,
feed.linenum, feed.linenum,
"<p><span class=\"glyphicon glyphicon-info-sign\" data-toggle=\"tooltip\" data-placement=\"left\" title=\""+feed.content.replace(/\"/g, "\'").replace(/\r/g, "\'").replace(/\n/g, "\'")+"\"></span> <button type=\"button\" class=\"btn-link\" data-num=\""+feed.index+"\" data-toggle=\"modal\" data-target=\"#mymodal\" data-url=\"{{ url_for('showsavedpastes.showsavedpaste') }}?paste="+feed.path+"&num="+feed.index+"\" data-path=\""+feed.path+"\"><span class=\"fa fa-search-plus\"></span></button></p>" "<p><span class=\"glyphicon glyphicon-info-sign\" data-toggle=\"tooltip\" data-placement=\"left\" title=\""+feed.content.replace(/\"/g, "\'").replace(/\r/g, "\'").replace(/\n/g, "\'")+"\"></span> <button type=\"button\" class=\"btn-link\" data-num=\""+feed.index+"\" data-toggle=\"modal\" data-target=\"#mymodal\" data-url=\"{{ url_for('showsavedpastes.showsavedpaste') }}?paste="+feed.path+"&num="+feed.index+"\" data-path=\""+feed.path+"\"><span class=\"fa fa-search-plus\"></span></button></p>"

View file

@ -22,6 +22,7 @@ import Flask_config
app = Flask_config.app app = Flask_config.app
cfg = Flask_config.cfg cfg = Flask_config.cfg
r_serv_pasteName = Flask_config.r_serv_pasteName r_serv_pasteName = Flask_config.r_serv_pasteName
r_serv_metadata = Flask_config.r_serv_metadata
max_preview_char = Flask_config.max_preview_char max_preview_char = Flask_config.max_preview_char
max_preview_modal = Flask_config.max_preview_modal max_preview_modal = Flask_config.max_preview_modal
@ -95,6 +96,7 @@ def search():
c = [] #preview of the paste content c = [] #preview of the paste content
paste_date = [] paste_date = []
paste_size = [] paste_size = []
paste_tags = []
index_name = request.form['index_name'] index_name = request.form['index_name']
num_elem_to_get = 50 num_elem_to_get = 50
@ -125,7 +127,8 @@ def search():
results = searcher.search_page(query, 1, pagelen=num_elem_to_get) results = searcher.search_page(query, 1, pagelen=num_elem_to_get)
for x in results: for x in results:
r.append(x.items()[0][1]) r.append(x.items()[0][1])
paste = Paste.Paste(x.items()[0][1]) path = x.items()[0][1]
paste = Paste.Paste(path)
content = paste.get_p_content() content = paste.get_p_content()
content_range = max_preview_char if len(content)>max_preview_char else len(content)-1 content_range = max_preview_char if len(content)>max_preview_char else len(content)-1
c.append(content[0:content_range]) c.append(content[0:content_range])
@ -133,15 +136,42 @@ def search():
curr_date = curr_date[0:4]+'/'+curr_date[4:6]+'/'+curr_date[6:] curr_date = curr_date[0:4]+'/'+curr_date[4:6]+'/'+curr_date[6:]
paste_date.append(curr_date) paste_date.append(curr_date)
paste_size.append(paste._get_p_size()) paste_size.append(paste._get_p_size())
p_tags = r_serv_metadata.smembers('tag:'+path)
l_tags = []
for tag in p_tags:
tag = tag.split('=')
if len(tag) > 1:
if tag[1] != '':
tag = tag[1][1:-1]
# no value
else:
tag = tag[0][1:-1]
# use for custom tags
else:
tag = tag[0]
l_tags.append(tag)
paste_tags.append(l_tags)
results = searcher.search(query) results = searcher.search(query)
num_res = len(results) num_res = len(results)
bootstrap_label = []
bootstrap_label.append('primary')
bootstrap_label.append('success')
bootstrap_label.append('danger')
bootstrap_label.append('warning')
bootstrap_label.append('info')
bootstrap_label.append('dark')
index_min = 1 index_min = 1
index_max = len(get_index_list()) index_max = len(get_index_list())
return render_template("search.html", r=r, c=c, return render_template("search.html", r=r, c=c,
query=request.form['query'], paste_date=paste_date, query=request.form['query'], paste_date=paste_date,
paste_size=paste_size, char_to_display=max_preview_modal, paste_size=paste_size, char_to_display=max_preview_modal,
num_res=num_res, index_min=index_min, index_max=index_max, num_res=num_res, index_min=index_min, index_max=index_max,
bootstrap_label=bootstrap_label,
paste_tags=paste_tags,
index_list=get_index_list(selected_index) index_list=get_index_list(selected_index)
) )
@ -165,6 +195,15 @@ def get_more_search_result():
preview_array = [] preview_array = []
date_array = [] date_array = []
size_array = [] size_array = []
list_tags = []
bootstrap_label = []
bootstrap_label.append('primary')
bootstrap_label.append('success')
bootstrap_label.append('danger')
bootstrap_label.append('warning')
bootstrap_label.append('info')
bootstrap_label.append('dark')
schema = Schema(title=TEXT(stored=True), path=ID(stored=True), content=TEXT) schema = Schema(title=TEXT(stored=True), path=ID(stored=True), content=TEXT)
@ -173,8 +212,9 @@ def get_more_search_result():
query = QueryParser("content", ix.schema).parse(" ".join(q)) query = QueryParser("content", ix.schema).parse(" ".join(q))
results = searcher.search_page(query, page_offset, num_elem_to_get) results = searcher.search_page(query, page_offset, num_elem_to_get)
for x in results: for x in results:
path_array.append(x.items()[0][1]) path = x.items()[0][1]
paste = Paste.Paste(x.items()[0][1]) path_array.append(path)
paste = Paste.Paste(path)
content = paste.get_p_content() content = paste.get_p_content()
content_range = max_preview_char if len(content)>max_preview_char else len(content)-1 content_range = max_preview_char if len(content)>max_preview_char else len(content)-1
preview_array.append(content[0:content_range]) preview_array.append(content[0:content_range])
@ -182,11 +222,30 @@ def get_more_search_result():
curr_date = curr_date[0:4]+'/'+curr_date[4:6]+'/'+curr_date[6:] curr_date = curr_date[0:4]+'/'+curr_date[4:6]+'/'+curr_date[6:]
date_array.append(curr_date) date_array.append(curr_date)
size_array.append(paste._get_p_size()) size_array.append(paste._get_p_size())
p_tags = r_serv_metadata.smembers('tag:'+path)
l_tags = []
for tag in p_tags:
tag = tag.split('=')
if len(tag) > 1:
if tag[1] != '':
tag = tag[1][1:-1]
# no value
else:
tag = tag[0][1:-1]
# use for custom tags
else:
tag = tag[0]
l_tags.append(tag)
list_tags.append(l_tags)
to_return = {} to_return = {}
to_return["path_array"] = path_array to_return["path_array"] = path_array
to_return["preview_array"] = preview_array to_return["preview_array"] = preview_array
to_return["date_array"] = date_array to_return["date_array"] = date_array
to_return["size_array"] = size_array to_return["size_array"] = size_array
to_return["list_tags"] = list_tags
to_return["bootstrap_label"] = bootstrap_label
if len(path_array) < num_elem_to_get: #pagelength if len(path_array) < num_elem_to_get: #pagelength
to_return["moreData"] = False to_return["moreData"] = False
else: else:

View file

@ -96,11 +96,17 @@
<tbody id="table_body"> <tbody id="table_body">
{% for path in r %} {% for path in r %}
<tr> <tr>
<td>{{ loop.index0 + 1 }}</td> <td> {{ loop.index0 }}</td>
<td><a target="_blank" href="{{ url_for('showsavedpastes.showsavedpaste') }}?paste={{ path }}&num={{ loop.index0+1 }}"> {{ path }}</a></td> <td><a target="_blank" href="{{ url_for('showsavedpastes.showsavedpaste') }}?paste={{path}}">{{ path }}</a>
<div>
{% for tag in paste_tags[loop.index0] %}
<span class="label label-{{ bootstrap_label[loop.index0 % 6] }} pull-left">{{ tag }}</span>
{% endfor %}
</div>
</td>
<td>{{ paste_date[loop.index0] }}</td> <td>{{ paste_date[loop.index0] }}</td>
<td>{{ paste_size[loop.index0] }}</td> <td>{{ paste_size[loop.index0] }}</td>
<td><p><span class="glyphicon glyphicon-info-sign" data-toggle="tooltip" data-placement="left" title="{{ c[loop.index0] }}"></span> <button type="button" class="btn-link" data-num="{{ loop.index0 + 1 }}" data-toggle="modal" data-target="#mymodal" data-url="{{ url_for('showsavedpastes.showsavedpaste') }}?paste={{ path }}&num={{ loop.index0+1 }}" data-path="{{ path }}"><span class="fa fa-search-plus"></span></button></p></td> <td><p><span class="glyphicon glyphicon-info-sign" data-toggle="tooltip" data-placement="left" title="{{ c[loop.index0] }} "></span> <button type="button" class="btn-link" data-num="{{ loop.index0 + 1 }}" data-toggle="modal" data-target="#mymodal" data-url="{{ url_for('showsavedpastes.showsavedpaste') }}?paste={{ path }}" data-path="{{ path }}"><span class="fa fa-search-plus"></span></button></p></td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
@ -190,9 +196,14 @@
for(i=0; i<data.path_array.length; i++) { for(i=0; i<data.path_array.length; i++) {
var curr_preview = data.preview_array[i].replace(/\"/g, "\'"); var curr_preview = data.preview_array[i].replace(/\"/g, "\'");
var tag = ""
for(j=0; j<data.list_tags[i].length; j++) {
tag = tag + "<span class=\"label label-" + data.bootstrap_label[j % 6] + " pull-left\">" + data.list_tags[j] + "</span>"
}
search_table.row.add( [ search_table.row.add( [
init_num_of_elements_in_table+((offset))+i+1, init_num_of_elements_in_table+((offset))+i+1,
"<a target=\"_blank\" href=\"{{ url_for('showsavedpastes.showsavedpaste') }}?paste="+data.path_array[i]+"&num="+i+"\"> "+ data.path_array[i] +"</a>", "<a target=\"_blank\" href=\"{{ url_for('showsavedpastes.showsavedpaste') }}?paste="+data.path_array[i]+"&num="+i+"\"> "+ data.path_array[i] +"</a>"
+ "<div>" + tag + "</div>",
data.date_array[i], data.date_array[i],
data.size_array[i], data.size_array[i],
"<p><span class=\"glyphicon glyphicon-info-sign\" data-toggle=\"tooltip\" data-placement=\"left\" title=\""+curr_preview+"\"></span> <button type=\"button\" class=\"btn-link\" data-num=\""+i+"\" data-toggle=\"modal\" data-target=\"#mymodal\" data-url=\"{{ url_for('showsavedpastes.showsavedpaste') }}?paste="+data.path_array[i]+"&num="+i+"\" data-path=\""+data.path_array[i]+"\"><span class=\"fa fa-search-plus\"></span></button></p>" "<p><span class=\"glyphicon glyphicon-info-sign\" data-toggle=\"tooltip\" data-placement=\"left\" title=\""+curr_preview+"\"></span> <button type=\"button\" class=\"btn-link\" data-num=\""+i+"\" data-toggle=\"modal\" data-target=\"#mymodal\" data-url=\"{{ url_for('showsavedpastes.showsavedpaste') }}?paste="+data.path_array[i]+"&num="+i+"\" data-path=\""+data.path_array[i]+"\"><span class=\"fa fa-search-plus\"></span></button></p>"