diff --git a/package/le-edubar@c3sl.ufpr.br/constants.js b/package/le-edubar@c3sl.ufpr.br/constants.js index cd1b77cc440ec9398776c7e8d94e56599d051555..2b61eb7bf10f4e29a098cf976b2b44106d983292 100644 --- a/package/le-edubar@c3sl.ufpr.br/constants.js +++ b/package/le-edubar@c3sl.ufpr.br/constants.js @@ -56,14 +56,6 @@ const URL_SUBJECTS = "https://api.portalmec.c3sl.ufpr.br/v1/subjects"; const URL_EDUCATIONAL_STAGES = "https://api.portalmec.c3sl.ufpr.br/v1/educational_stages"; const URL_OBJECT_TYPES = "https://api.portalmec.c3sl.ufpr.br/v1/object_types" -/*URL reserved characters*/ -const SPECIAL_CHARS = { - "\[": "", "]": "", "\{": "", "}": "","\\": "", - "/": "", "\"": "", "\'": "", ";": "", "?": "", - ":": "", "@": "", "=": "", "&": "", "%": "", - "<": "", ">": "", "~": "", "#": "", "+": "", -}; - const ICON_THUMBNAIL = { /*DEFAULT*/ "default": "default-application", diff --git a/package/le-edubar@c3sl.ufpr.br/edu-dbus b/package/le-edubar@c3sl.ufpr.br/edu-dbus index a0dafabfcdb828b604b0b910cfa10c6938274a05..a463e0c8cf7d4adb2fdfb6319f0f90c5284cf31a 100755 --- a/package/le-edubar@c3sl.ufpr.br/edu-dbus +++ b/package/le-edubar@c3sl.ufpr.br/edu-dbus @@ -1,8 +1,10 @@ #!/usr/bin/nodejs - var DBus = require('./dbus'); var exec = require('child_process').exec; var fs = require('fs'); +var path = require('path'); + +const download_dir = '/var/cache/le-edubar' /* Create a new service, object and interface */ var service = DBus.registerService('system', 'br.ufpr.c3sl.edubar'); @@ -14,7 +16,7 @@ var iface_download = obj.createInterface('br.ufpr.c3sl.edubar.Download'); /* Add method */ iface_download.addMethod('Start', { in: [ DBus.Define(Array) ], - out: DBus.Define(Number) + out: DBus.Define(Number) }, function(edu,callback) { console.log('Fazendo download de id=' + edu[4] + ' ' + edu[2]); @@ -75,7 +77,7 @@ var iface_file = obj.createInterface('br.ufpr.c3sl.edubar.File'); /* Check if a file or a dir in path exists. */ iface_file.addMethod('Exists', { in: [ DBus.Define(String) ], - out: DBus.Define(Boolean) }, + out: DBus.Define(Boolean) }, function(path, callback) { fs.exists(path, function (exists) { exists ? callback(null, true) : callback(null, false); @@ -86,9 +88,8 @@ iface_file.addMethod('Exists', { /* Return the size of a file or a dir if path exists. */ iface_file.addMethod('Size', { in: [ DBus.Define(String) ], - out: DBus.Define(Number) }, + out: DBus.Define(Number)}, function(path, callback) { - fs.exists(path, function (exists) { if (exists){ callback(null, fs.statSync(path).size); @@ -99,5 +100,88 @@ iface_file.addMethod('Size', { }); }); +iface_file.addMethod('GetLocalFiles',{ + in: [ DBus.Define(Number), DBus.Define(String), DBus.Define(String) ], + out: DBus.Define(String) }, + function(page, search_text, order_property, callback) { + fs.exists(download_dir, function (exists) { + if (exists) { + var directories = fs.readdirSync(download_dir).map( function(name) { + return path.join(download_dir,name); + }).filter(function(download_dir){ + return fs.lstatSync(download_dir).isDirectory(); + }); + var result_JSON = "[" + var i = directories.length; + var file_json; + while (i--> 0) { + file_json = directories[i].split("/"); + file_json = file_json[file_json.length -1]; + file_json = directories[i] + "/." + file_json + ".json"; + + if (fs.existsSync(file_json)) { + result_JSON += fs.readFileSync(file_json).toString().replace(/(\r\n|\n|\r)/gm,""); + if (i > 0) { + result_JSON += ","; + } + } + } + result_JSON += "]"; + result_JSON = JSON.parse(result_JSON); + + result_JSON.sort(function(a,b) { + switch (order_property) { + case 'publicationdesc': + return a.updated_at.localeCompare(b.updated_at); + break; + case 'publicationasc': + return b.updated_at.localeCompare(a.updated_at); + break; + case 'review_average': + return a.review_average > b.review_average; + break; + case 'author': + return a.author.localeCompare(b.author); + break; + case 'title': + return a.name.localeCompare(b.name); + break; + case 'likes': + return a.likes_count > b.likes_count; + break; + default: + return a.score > b.score; + break; + } + }); + + for (i = result_JSON.length - 1; i >= 0; --i) { + if (result_JSON[i].name.toLowerCase().search(search_text.toLowerCase()) < 0) { + result_JSON[i].name = 'ISSO NÃO DEVIA ESTAR AQUI'; + } + } + var temp_result = result_JSON.splice(page*10,10); + + callback(null,JSON.stringify(temp_result),result_JSON.length); + } else { + callback(null, "[]"); + } + }); + } +); + +iface_file.addMethod('GetTotalFiles', { out: DBus.Define(Number) }, function(callback) { + if (fs.existsSync(download_dir)){ + var directories = fs.readdirSync(download_dir).map( function(name) { + return path.join(download_dir,name); + }).filter(function(download_dir){ + return fs.lstatSync(download_dir).isDirectory(); + }); + callback(null,directories.length); + } + callback(null,0); +}); + + /* Update file interface */ iface_file.update(); diff --git a/package/le-edubar@c3sl.ufpr.br/edubus.js b/package/le-edubar@c3sl.ufpr.br/edubus.js index 70af0066de0e0423a9a7e9e3321e073b4c5c11be..859a245650892713e6f985eff513d835d01373b7 100644 --- a/package/le-edubar@c3sl.ufpr.br/edubus.js +++ b/package/le-edubar@c3sl.ufpr.br/edubus.js @@ -29,8 +29,17 @@ const file_interface = '<node>\ <arg type="s" direction="in"/>\ <arg type="d" direction="out" />\ </method>\ + <method name="GetLocalFiles">\ + <arg type="i" direction="in"/>\ + <arg type="s" direction="in"/>\ + <arg type="s" direction="in"/>\ + <arg type="sd" direction="out" />\ + </method>\ + <method name="GetTotalFiles">\ + <arg type="d" direction="out" />\ + </method>\ </interface>\ </node>'; var iface_file = Gio.DBusProxy.makeProxyWrapper(file_interface); -var file = iface_file(Gio.DBus.system,"br.ufpr.c3sl.edubar","/br/ufpr/c3sl/edubar"); +var file = iface_file(Gio.DBus.system,"br.ufpr.c3sl.edubar","/br/ufpr/c3sl/edubar"); \ No newline at end of file diff --git a/package/le-edubar@c3sl.ufpr.br/extension.js b/package/le-edubar@c3sl.ufpr.br/extension.js index 64291fd40c2f9e48b466718b3f17826ee7004223..65b2d41546b6143243014e4ebe33f47d1e0fda29 100644 --- a/package/le-edubar@c3sl.ufpr.br/extension.js +++ b/package/le-edubar@c3sl.ufpr.br/extension.js @@ -53,6 +53,7 @@ let box_result, /*Container with created results of API request*/ educational_subjects, /*list of subjects to filter*/ educational_stages, /*list of educational stages to filter*/ educational_types, /*list of object types to filter*/ + is_local_search,/*False to use Portal MEC API, true to use DBus.File.GetLo*/ meta_path, /*Path to extension directory*/ soup_session, /*Session created to connect with Portal MEC*/ soup_result, /*JSON content from API request*/ @@ -94,7 +95,11 @@ function create_soup_session() { function jump_to_page(page) { box_result.destroy_all_children(); search_page=page; - start_soup(); + if (is_local_search) { + start_local_search(); + }else { + start_soup(); + } } /* @@ -124,7 +129,9 @@ function create_navigation_page(navigation_box, page) { * This function creates the navigation box. */ function create_navigation() { - let navigation_box = new St.BoxLayout({}); + let navigation_box = new St.BoxLayout({ + style_class: 'navigation-box', + }); navigation_box.add_actor(new St.Label({ text: 'Ir para a página:', style_class: 'navigation-text', @@ -192,23 +199,24 @@ function send_soup_request (request_message, searching_text, local_text) { if (message.status_code !== 200) { searching_text.text = 'Sem resposta do serivdor.'; on_going_downloads = new Array(); - return - } - /*Restart request if the search text changed*/ - if (local_text != search_text){ - soup_session.abort(); - start_search(); + return; } soup_result = JSON.parse(message.response_body.data); if (search_page == 0) { max_pages = Math.ceil(message.response_headers.get_one("x-total-count") - /Constants.RESULTS_PER_REQUEST); + /Constants.RESULTS_PER_REQUEST); if (max_pages > Constants.MAX_API_RESULTS) { max_pages = Constants.MAX_API_RESULTS; } } + /*Restart request if the search text changed*/ + if (local_text != search_text){ + soup_session.abort(); + start_search(); + } + if (soup_result.length > 0) { searching_text.get_parent().destroy(); searching_text.destroy(); @@ -281,17 +289,41 @@ function start_soup () { function start_search() { box_result.destroy_all_children(); - if (edu_screen.get_child_at_index(1).name == 'Reload') { - edu_screen.get_child_at_index(1).destroy(); - } - if (result_screen.get_last_child().name == 'navigation') { result_screen.get_last_child().destroy(); } search_page = 0; is_searching = false; - start_soup(); + + if (is_local_search) { + start_local_search(); + } else { + start_soup(); + } +} + +function start_local_search() { + search_text = input_edu.get_text(); + + if (result_screen.get_last_child().name == 'navigation') { + result_screen.get_last_child().destroy(); + } + + var result_json = EduBus.file.GetLocalFilesSync(search_page, + Prefabs.clear_special_chars(search_text), + order_property); + + soup_result = JSON.parse(result_json); + if (search_page == 0) { + max_pages = Math.ceil(EduBus.file.GetTotalFilesSync() /Constants.RESULTS_PER_REQUEST); + } + + if (soup_result.length > 0) { + show_results(); + } else { + + } } /* @@ -579,6 +611,7 @@ function show_results() { } catch (e) { InternalError("Learning content with id=" + soup_result[i].id + " can't be created."); + } } @@ -864,52 +897,51 @@ function open_folder_button(download_path,folder,file, edu_object) { }); let bin_tmp = new St.BoxLayout ({}); + /*#TODO: Change to DBUS Signals*/ + Mainloop.timeout_add(500, function() { + /*Begin Mainloop to check if is downloading*/ + bin_tmp.destroy_all_children(); + + if (edu_object.size != EduBus.file.SizeSync(file_path)){ + bin_tmp.add_actor(new St.Button({ + label: 'Baixando...', + style_class: 'downloading-button', + })); + return true; + + } else if (EduBus.file.ExistsSync(file_path)) { + /*Add open folder and file buttons*/ + Tweener.addTween(bin_tmp, + { + time: 0.1, + transition:"linear", + opacity: 0, + onComplete: function() { + bin_tmp.add_actor(button); + button.connect('clicked',function () { + Util.spawn(["nautilus",download_path + folder]); + close_edu_screen(); + }); - /*#TODO: Change to DBUS Signals*/ - Mainloop.timeout_add(500, function() { - /*Begin Mainloop to check if is downloading*/ - bin_tmp.destroy_all_children(); + bin_tmp.add_actor(open_file_button(file_path)); - if (edu_object.size != EduBus.file.SizeSync(file_path)[0]){ - bin_tmp.add_actor(new St.Button({ - label: 'Baixando...', - style_class: 'downloading-button', - })); - return true; - - } else if (EduBus.file.ExistsSync(file_path)[0]) { - /*Add open folder and file buttons*/ - Tweener.addTween(bin_tmp, - { - time: 0.1, - transition:"linear", - opacity: 0, - onComplete: function() { - bin_tmp.add_actor(button); - button.connect('clicked',function () { - Util.spawn(["nautilus",download_path + folder]); - close_edu_screen(); - }); - - bin_tmp.add_actor(open_file_button(file_path)); - - Tweener.addTween(bin_tmp, - { - time: 0.1, - transition:"linear", - opacity: 255, - }); - } - }); - } else { - /*Add download button*/ - bin_tmp.add_actor(download_button(edu_object,file)); + Tweener.addTween(bin_tmp, + { + time: 0.1, + transition:"linear", + opacity: 255, + }); + } + }); + } else { + /*Add download button*/ + bin_tmp.add_actor(download_button(edu_object,file)); - } - return false; + } + return false; - /*End Mainloop*/ - }); + /*End Mainloop*/ + }); return bin_tmp; } @@ -1090,7 +1122,7 @@ var toggle_overview = { } Main.overview._controls._group.get_last_child().opacity = 0; Overview._dash.actor.hide(); - Overview._searchEntryBin.set_child(input_edu.entry); + Overview._searchEntryBin.set_child(input_edu.entry_box); input_edu.set_text(""); Overview.show(); input_edu.entry.grab_key_focus(); @@ -1180,19 +1212,41 @@ var input_edu = { toggle_overview.close(); } }); + + this.local_button.connect('clicked',function(button) { + is_local_search = !is_local_search; + if (is_local_search) { + button.label = 'Ver conteúdo online'; + } else { + button.label = 'Ver conteúdo baixado'; + } + start_search(); + }); }, create: function() { + this.entry_box = new St.BoxLayout({ + vertical: true, + }); + this.entry = new St.Entry ({ style_class: 'search-entry', - }), + }); this.icon = new St.Icon ({ icon_name : 'portal-system-search', icon_size: 30, - }), + }); + + this.local_button = new St.Button({ + label: 'Ver conteúdo baixado', + style_class: 'portal-button', + }) + this.connect_events(); this.entry.set_primary_icon(this.icon); + this.entry_box.add_actor(this.entry); + this.entry_box.add_actor(this.local_button); }, get_text: function () { @@ -1211,6 +1265,7 @@ function init(extensionMeta) { theme.append_search_path(meta_path + "/icons/portal"); theme.append_search_path(meta_path + "/icons/FlatRemix"); on_going_downloads = new Array(); + is_local_search = false; input_edu.create(); portal_button.create(); } diff --git a/package/le-edubar@c3sl.ufpr.br/prefabs.js b/package/le-edubar@c3sl.ufpr.br/prefabs.js index 6d3c632e48a711e03099f7eefcdf2ba737bd1394..54b2073f9939fc68c86f6224a96b25327b2553d3 100644 --- a/package/le-edubar@c3sl.ufpr.br/prefabs.js +++ b/package/le-edubar@c3sl.ufpr.br/prefabs.js @@ -54,15 +54,7 @@ function get_query(txt) { /*This function clear the special chars like '&%$' * of the string txt*/ function clear_special_chars(txt) { - let result = txt; - for (let i = 0; i < result.length; ++i) { - if (Constants.SPECIAL_CHARS[result.charAt(i)] != undefined) { - result = result.replace(result.charAt(i), - Constants.SPECIAL_CHARS[result.charAt(i)]); - i--; - } - } - return result; + return txt.replace(/[^a-zA-Z0-9àèìòùÀÈÌÒÙáéíóúýÁÉÍÓÚÝâêîôûÂÊÎÔÛãñõÃÑÕäëïöüÿÄËÏÖÜŸçÇߨøÅ寿œ]/g,''); } /*This function open or close de order by group diff --git a/package/le-edubar@c3sl.ufpr.br/stylesheet.css b/package/le-edubar@c3sl.ufpr.br/stylesheet.css old mode 100755 new mode 100644 index d988e30b9e8cd8198193035cbd4a62e5df6fbe69..8a236640886632645594153a4215f3e5421d5dcb --- a/package/le-edubar@c3sl.ufpr.br/stylesheet.css +++ b/package/le-edubar@c3sl.ufpr.br/stylesheet.css @@ -22,11 +22,11 @@ .portal-button { margin: 3px; min-width: 105px; - background-color: #1f292d; + background-color: #303030; border-width: 1px; min-height: 25px; border-radius: 6px; - box-shadow: inset 0 -1px 0px #1f292d; + box-shadow: inset 0 -1px 0px #303030; font-weight: bold; } @@ -77,7 +77,7 @@ border-width: 1px; padding-right: 10px; padding-left: 10px; - background-color: #1f292d; + background-color: #303030; min-height: 26px; border-radius: 6px; font-weight: bold; @@ -91,7 +91,7 @@ padding: 0 2px 0 2px; margin: 0 2px 2px 2px; width: 150px; - background-color: #1f292d; + background-color: #444444; min-height: 26px; border-radius: 6px; font-weight: bold; @@ -102,10 +102,10 @@ border-width: 1px; padding: 0 2px 0 2px; margin: 0 2px 2px 2px; - background-color: #1f292d; + background-color: #303030; min-height: 26px; border-radius: 6px; - box-shadow: inset 0 -1px 0px #1f292d; + box-shadow: inset 0 -1px 0px #303030; } .order-button:active, @@ -116,8 +116,8 @@ background-color: #c9a016; min-height: 26px; border-radius: 6px; - box-shadow: inset 0 -1px 0px #1f292d; - color: #1f292d; + box-shadow: inset 0 -1px 0px #303030; + color: #303030; } .order-icon { @@ -188,7 +188,7 @@ border-width: 1px; min-height: 25px; border-radius: 6px; - box-shadow: inset 0 -1px 0px #1f292d; + box-shadow: inset 0 -1px 0px #303030; font-weight: bold; } @@ -203,7 +203,10 @@ background-color: #c9a016; min-height: 26px; border-radius: 6px; - box-shadow: inset 0 -1px 0px #1f292d; + box-shadow: inset 0 -1px 0px #303030; color: #111; } +.navigation-box { + margin-top: 4px; +} \ No newline at end of file