diff --git a/var/www/modules/browsepastes/Flask_browsepastes.py b/var/www/modules/browsepastes/Flask_browsepastes.py index 67923fbd..a3f238c7 100644 --- a/var/www/modules/browsepastes/Flask_browsepastes.py +++ b/var/www/modules/browsepastes/Flask_browsepastes.py @@ -20,6 +20,7 @@ app = Flask_config.app cfg = Flask_config.cfg max_preview_char = Flask_config.max_preview_char max_preview_modal = Flask_config.max_preview_modal +r_serv_metadata = Flask_config.r_serv_metadata #init all lvlDB servers curYear = datetime.now().year @@ -56,6 +57,14 @@ def getPastebyType(server, module_name): def event_stream_getImportantPasteByModule(module_name, year): index = 0 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: 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 curr_date = str(paste._get_p_date()) 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["module"] = module_name data["index"] = index @@ -71,6 +96,8 @@ def event_stream_getImportantPasteByModule(module_name, year): data["content"] = content[0:content_range] data["linenum"] = paste.get_lines_info()[0] data["date"] = curr_date + data["l_tags"] = l_tags + data["bootstrap_label"] = bootstrap_label data["char_to_display"] = max_preview_modal 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 @@ -98,8 +125,17 @@ def importantPasteByModule(): paste_date = [] paste_linenum = [] all_path = [] + paste_tags = [] 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]: all_path.append(path) paste = Paste.Paste(path) @@ -110,6 +146,23 @@ def importantPasteByModule(): curr_date = curr_date[0:4]+'/'+curr_date[4:6]+'/'+curr_date[6:] paste_date.append(curr_date) 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: finished = False @@ -124,6 +177,8 @@ def importantPasteByModule(): paste_date=paste_date, paste_linenum=paste_linenum, char_to_display=max_preview_modal, + paste_tags=paste_tags, + bootstrap_label=bootstrap_label, finished=finished) @browsepastes.route("/_getImportantPasteByModule", methods=['GET']) diff --git a/var/www/modules/browsepastes/templates/important_paste_by_module.html b/var/www/modules/browsepastes/templates/important_paste_by_module.html index a76fb870..1e49a127 100644 --- a/var/www/modules/browsepastes/templates/important_paste_by_module.html +++ b/var/www/modules/browsepastes/templates/important_paste_by_module.html @@ -12,7 +12,13 @@ {% for path in all_path %} {{ loop.index0 }} - {{ path }} + {{ path }} +
+ {% for tag in paste_tags[loop.index0] %} + {{ tag }} + {% endfor %} +
+ {{ paste_date[loop.index0] }} {{ paste_linenum[loop.index0] }}

@@ -89,14 +95,19 @@ function add_entries_X(to_add) { } else { var feed = json_array.shift(); elem_added++; - search_table.row.add( [ - feed.index, - " "+ feed.path +"", - feed.date, - feed.linenum, - "

" - ] ).draw( false ); - $("#myTable_"+moduleName).attr('data-numElem', curr_numElem+1); + var tag = "" + for(j=0; j" + feed.l_tags[j] + "" + } + search_table.row.add( [ + feed.index, + " "+ feed.path +"" + + "
" + tag + "
" , + feed.date, + feed.linenum, + "

" + ] ).draw( false ); + $("#myTable_"+moduleName).attr('data-numElem', curr_numElem+1); } } $("#load_more_json_button1").removeAttr('disabled'); diff --git a/var/www/modules/search/Flask_search.py b/var/www/modules/search/Flask_search.py index afce2452..4714e31f 100644 --- a/var/www/modules/search/Flask_search.py +++ b/var/www/modules/search/Flask_search.py @@ -22,6 +22,7 @@ import Flask_config app = Flask_config.app cfg = Flask_config.cfg 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_modal = Flask_config.max_preview_modal @@ -95,6 +96,7 @@ def search(): c = [] #preview of the paste content paste_date = [] paste_size = [] + paste_tags = [] index_name = request.form['index_name'] num_elem_to_get = 50 @@ -125,7 +127,8 @@ def search(): results = searcher.search_page(query, 1, pagelen=num_elem_to_get) for x in results: 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_range = max_preview_char if len(content)>max_preview_char else len(content)-1 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:] paste_date.append(curr_date) 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) 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_max = len(get_index_list()) return render_template("search.html", r=r, c=c, query=request.form['query'], paste_date=paste_date, paste_size=paste_size, char_to_display=max_preview_modal, 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) ) @@ -165,6 +195,15 @@ def get_more_search_result(): preview_array = [] date_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) @@ -173,8 +212,9 @@ def get_more_search_result(): query = QueryParser("content", ix.schema).parse(" ".join(q)) results = searcher.search_page(query, page_offset, num_elem_to_get) for x in results: - path_array.append(x.items()[0][1]) - paste = Paste.Paste(x.items()[0][1]) + path = x.items()[0][1] + path_array.append(path) + paste = Paste.Paste(path) content = paste.get_p_content() content_range = max_preview_char if len(content)>max_preview_char else len(content)-1 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:] date_array.append(curr_date) 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["path_array"] = path_array to_return["preview_array"] = preview_array to_return["date_array"] = date_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 to_return["moreData"] = False else: diff --git a/var/www/modules/search/templates/search.html b/var/www/modules/search/templates/search.html index 43895a9f..3ebfc182 100644 --- a/var/www/modules/search/templates/search.html +++ b/var/www/modules/search/templates/search.html @@ -75,7 +75,7 @@
- Index: + Index: