Commit d06f9eac authored by Alain Takoudjou's avatar Alain Takoudjou

erp5_web_mynij_search: Show build process in activities page

Activities page now show build and torrent activity.
parent f53f1755
...@@ -234,7 +234,7 @@ ...@@ -234,7 +234,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>988.46729.51863.18141</string> </value> <value> <string>989.7259.5245.62788</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -252,7 +252,7 @@ ...@@ -252,7 +252,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1608300703.11</float> <float>1609768857.13</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -8,11 +8,27 @@ ...@@ -8,11 +8,27 @@
<link rel="stylesheet" type="text/css" href="mynij-style.css"> <link rel="stylesheet" type="text/css" href="mynij-style.css">
</head> </head>
<body> <body>
<i class="info">This page will refresh automatically!</i>
<div class="seedbox" id="seedactivities"> <div class="seedbox" id="seedactivities">
<h1 class="head-title">Torrent Background Activities</h1> <h1 class="head-title">Torrent Activities</h1>
<div class="torrent-seed"> <div class="torrent-seed">
<h2 class="info">Please wait while checking seeds...</h2> <h2 class="info">Torrent seeders will appear here...</h2>
</div> </div>
</div> </div>
<div class="buildbox" id="buildactivities">
<h1 class="head-title">Index Build Activities</h1>
<table class="border-bottom table">
<thead>
<tr>
<th>Index name</th>
<th>State</th>
<th>Status</th>
<th></th>
</tr>
</thead>
<tbody class="build-list">
</tbody>
</table>
</div>
</body> </body>
</html> </html>
\ No newline at end of file
...@@ -242,7 +242,7 @@ ...@@ -242,7 +242,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>988.47141.9623.51421</string> </value> <value> <string>989.8582.46803.62617</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -260,7 +260,7 @@ ...@@ -260,7 +260,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1608289101.66</float> <float>1609843960.43</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
.declareAcquiredMethod("getSetting", "getSetting") .declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("setSetting", "setSetting") .declareAcquiredMethod("setSetting", "setSetting")
.declareAcquiredMethod("jio_post", "jio_post") .declareAcquiredMethod("jio_post", "jio_post")
.declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("jio_put", "jio_put")
.ready(function () { .ready(function () {
var indices = [], db; var indices = [], db;
...@@ -121,6 +123,15 @@ ...@@ -121,6 +123,15 @@
}); });
}) })
.declareMethod("updateIndexDoc", function (key, update_dict) {
var gadget = this;
return gadget.jio_get(key)
.push(function (doc) {
var new_doc = Object.assign(doc, update_dict);
return gadget.jio_put(key, new_doc);
});
})
.declareMethod("save_index", function (index_name) { .declareMethod("save_index", function (index_name) {
var gadget = this, var gadget = this,
serialized = this.state.indices[index_name].export_test(), serialized = this.state.indices[index_name].export_test(),
......
...@@ -242,7 +242,7 @@ ...@@ -242,7 +242,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>988.62603.37288.24012</string> </value> <value> <string>989.7469.5007.51797</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -260,7 +260,7 @@ ...@@ -260,7 +260,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1609162985.92</float> <float>1609845884.52</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -8,16 +8,25 @@ ...@@ -8,16 +8,25 @@
<script src="mynij_rss-parser.min.js" type="text/javascript"></script> <script src="mynij_rss-parser.min.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="mynij-style.css"> <link rel="stylesheet" type="text/css" href="mynij-style.css">
<script id="panel-template-progress" type="text/x-handlebars-template"> <script id="build-template-progress" type="text/x-handlebars-template">
<p>Building <span class="build-title">{{title}} ...</span></p> <td>{{title}}</td>
<div class="anbar bar1"></div> <td class="index-state">{{status}}</td>
{{#if building}}
<td class="index-status"><span>Building...</span></td>
<td class="anbuild"><div class="anbar bar1"></div>
<div class="anbar bar2"></div> <div class="anbar bar2"></div>
<div class="anbar bar3"></div> <div class="anbar bar3"></div>
<div class="anbar bar4"></div> <div class="anbar bar4"></div>
<div class="anbar bar5"></div> <div class="anbar bar5"></div>
</td>
{{else}}
<td class="index-status"><span>Stopped</span></td><td></td>
{{/if}}
</script> </script>
</head> </head>
<body> <body>
<div data-gadget-url="gadget_mynij_model.html" data-gadget-scope="model"
data-gadget-sandbox="public"></div>
</body> </body>
</html> </html>
\ No newline at end of file
...@@ -242,7 +242,7 @@ ...@@ -242,7 +242,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>987.31553.14164.37563</string> </value> <value> <string>989.8564.46957.4761</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -260,7 +260,7 @@ ...@@ -260,7 +260,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1603444183.66</float> <float>1609842676.07</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -10,8 +10,8 @@ ...@@ -10,8 +10,8 @@
"https://softinst116265.host.vifib.net/erp5/ERP5Site_getHTTPResource", "https://softinst116265.host.vifib.net/erp5/ERP5Site_getHTTPResource",
"https://softinst116446.host.vifib.net/erp5/ERP5Site_getHTTPResource" "https://softinst116446.host.vifib.net/erp5/ERP5Site_getHTTPResource"
], ],
panel_template_progress = Handlebars.compile(template_element build_template_progress = Handlebars.compile(template_element
.getElementById("panel-template-progress") .getElementById("build-template-progress")
.innerHTML); .innerHTML);
function get_random_id() { function get_random_id() {
...@@ -28,6 +28,16 @@ ...@@ -28,6 +28,16 @@
.declareAcquiredMethod("setSetting", "setSetting") .declareAcquiredMethod("setSetting", "setSetting")
.declareAcquiredMethod("notifySubmitted", "notifySubmitted") .declareAcquiredMethod("notifySubmitted", "notifySubmitted")
.ready(function () {
var gadget = this;
return this.getDeclaredGadget("model")
.push(function (model) {
return gadget.changeState({
model_gadget: model
});
});
})
.declareMethod("preRenderDocument", function (parent_options) { .declareMethod("preRenderDocument", function (parent_options) {
var gadget = this; var gadget = this;
return gadget.jio_get(parent_options.jio_key) return gadget.jio_get(parent_options.jio_key)
...@@ -38,49 +48,53 @@ ...@@ -38,49 +48,53 @@
.declareAcquiredMethod("add_to_index", "add_to_index") .declareAcquiredMethod("add_to_index", "add_to_index")
.declareAcquiredMethod("save_index", "save_index") .declareAcquiredMethod("save_index", "save_index")
.declareAcquiredMethod("getParentElement", "getParentElement")
.declareMethod("pushIndex", function (index_name) { .declareMethod("getIndexToBuild", function () {
var gadget = this; return this.getSetting('build_dict')
return gadget.getSetting('index_list', []) .push(function (build_dict) {
.push(function (index_list) { var key,
if (index_list.indexOf(index_name) === -1) { entry;
index_list.push(index_name); for (key in build_dict) {
return gadget.setSetting('index_list', index_list); if (!entry)
entry = build_dict[key];
else {
if (entry.status === build_dict[key].status)
continue;
if (entry.status && !build_dict[key].status)
entry = build_dict[key];
else if (entry.status === "built" &&
build_dict[key].status !== "built")
entry = build_dict[key];
}
} }
if (entry && entry.status === 'built')
return;
return entry;
}); });
}) })
//declare service to build index in background //declare service to build index in background
.declareService(function () { .declareService(function () {
var gadget = this, var gadget = this;
parent_content;
function build() { function build() {
var entry; var status;
return new RSVP.Queue() return gadget.getIndexToBuild()
.push(function () { .push(function (entry) {
return gadget.getSetting('build_list');
})
.push(function (build_list) {
var link_list, var link_list,
tmp_element; tmp_element;
if (!build_list || !build_list.length) if (!entry)
// wait 5s and check again if there is something to build // wait 5s and check again if there is something to build
return RSVP.delay(5000); return RSVP.delay(5000);
else { else {
entry = build_list[0]; gadget.state.current_build = entry;
link_list = entry.links.split("\n").filter(l => l.length > 0); link_list = entry.links.split("\n").filter(l => l.length > 0);
tmp_element = document.createElement('div');
tmp_element.className = 'building';
tmp_element.innerHTML = panel_template_progress({
title: entry.index_name
});
parent_content.appendChild(tmp_element);
return gadget.build_index(link_list, entry.index_name) return gadget.build_index(link_list, entry.index_name)
.push(function () { .push(function () {
console.log("done building index"); console.log("done building index");
return gadget.save_index(entry.index_name) return gadget.save_index(entry.index_name)
.push(function (result) { .push(function (result) {
status = 'built';
return gadget.notifySubmitted({ return gadget.notifySubmitted({
message: "Index '" + entry.index_name + "' built : " + message: "Index '" + entry.index_name + "' built : " +
result + " item(s) added.", result + " item(s) added.",
...@@ -90,26 +104,34 @@ ...@@ -90,26 +104,34 @@
}) })
.push(undefined, function (my_error) { .push(undefined, function (my_error) {
showError(my_error); showError(my_error);
gadget.state.current_build = undefined;
status = 'build failed';
return gadget.notifySubmitted({ return gadget.notifySubmitted({
message: "Index '" + entry.index_name + "' built failed!", message: "Index '" + entry.index_name + "' built failed!",
status: "error" status: "error"
}); });
}) })
.push(function () { .push(function () {
var indicator = parent_content.querySelector('.building'); gadget.state.current_build = undefined;
if (indicator) return gadget.getSetting('build_dict', {});
parent_content.removeChild(indicator);
return gadget.getSetting('build_list');
}) })
.push(function (current) { .push(function (current) {
if (current && current.length && if (!current[entry.jio_key]) {
current[0].id === entry.id) { console.log("Error: cannot get key '" + entry.jio_key +
current.shift(); "' in build_dict");
return gadget.setSetting('build_list', current); return;
} }
current[entry.jio_key].status = status;
return gadget.setSetting('build_dict', current);
})
.push(function () {
return gadget.state.model_gadget.updateIndexDoc(
entry.jio_key,
{status: 'built'}
);
}) })
.push(function () { .push(function () {
return gadget.pushIndex(entry.index_name); return gadget.state.model_gadget.pushIndex(entry.index_name);
}); });
} }
}) })
...@@ -118,26 +140,46 @@ ...@@ -118,26 +140,46 @@
}); });
} }
return gadget.getParentElement()
.push(function (element) {
parent_content = element;
return build(); return build();
});
}) })
/*.declareMethod("parse_user_entry_list", function (list, index_name) { .onLoop(function () {
var gadget = this, var gadget = this,
links = list.split("\n").filter(link => link.length > 0); container = document.getElementById('buildactivities'),
element;
return gadget.build_index(links, index_name) if (!container)
.push(function (result) { return;
console.log("done building index"); element = container.querySelector('.build-list');
return gadget.save_index(index_name); if (!element)
}) return;
.push(undefined, function (my_error) { return gadget.getSetting('build_dict')
showError(my_error); .push(function (build_dict) {
var key,
tmp_element,
building;
if (build_dict) {
while (element.firstChild) {
element.firstChild.remove();
}
for (key in build_dict) {
building = false;
tmp_element = document.createElement('tr');
if (gadget.state.current_build && (build_dict[key].index_name ===
gadget.state.current_build.index_name)) {
tmp_element.classList.add('building');
building = true;
}
tmp_element.innerHTML = build_template_progress({
title: build_dict[key].index_name,
status: build_dict[key].status || 'not built',
building: building
});
element.appendChild(tmp_element);
}
}
}); });
})*/ }, 5000)
.declareMethod("build_index", function (links, index_name) { .declareMethod("build_index", function (links, index_name) {
var gadget = this, var gadget = this,
......
...@@ -242,7 +242,7 @@ ...@@ -242,7 +242,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>988.6617.37252.48349</string> </value> <value> <string>989.8577.12361.41625</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -260,7 +260,7 @@ ...@@ -260,7 +260,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1605884721.12</float> <float>1609843972.59</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -36,135 +36,17 @@ ...@@ -36,135 +36,17 @@
font-size: 1.5em; font-size: 1.5em;
} }
i.info {
color: #b0b0b0;
font-size: .9em;
}
@media (max-width: 600px) { @media (max-width: 600px) {
#mynij-results > li, #searx-results > li { #mynij-results > li, #searx-results > li {
width: 100%; width: 100%;
} }
} }
/* body {
padding: 0;
margin: 0;
height: 100vh;
width: 100%;
background: #fff;
font-family: arial,sans-serif;
}
form{
position: relative;
top: 3%;
margin : auto;
width: 86%;
max-width: 50em;
height: 5%;
border: 1px solid #cecece;
background: white;
box-sizing: border-box;
border-radius: 25px;
transition:all 200ms ease-out;
}
form:hover{
cursor: pointer;
box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.26);
transition:all 200ms ease-out;
}
form:hover input{
display: block;
}
input{
position: absolute;
top: 0;
left: 0;
width: 100%;;
height: 100%;
line-height: 5%;
outline: 0;
border: 0;
font-size: 1em;
border-radius: 20px;
padding: 0 20px;
}
input[type="button"]{
width: 8em;
height: 2em;
position: relative;
border-radius: 3px;
}
input[type="button"]:hover{
cursor: pointer;
box-shadow: 0 2px 5px 0 rgba(0, 0, 0, 0.26);
transition:all 200ms ease-out;
}
::-webkit-scrollbar {
display: none;
}
#navbar {
margin-top : 3%;
margin-left : 10.3%;
font-size: 1em;
max-width: 49em;
overflow-x: scroll;
overflow-y: hidden;
white-space: nowrap;
}
#navbar > ul {
display: inline-block;
list-style-type: none;
margin: 0;
padding: 0;
margin-left:15%;
}
#navbar > ul > li {
display: inline-block;
}
#navbar > ul > li > a {
display: inline-block;
color : #777;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
#navbar > ul > li > a:hover {
color : black;
}
.active{
color: #1A73E8 !important;
border-bottom: 3px solid #1A73E8;
font-weight: bold;
}
#options{
float: left;
position: absolute;
margin-left:-6%;
background:#fff;
padding-bottom:0.2%;
}
.showbox {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
padding: 5%;
} */
.mynij-results, .searx-results { .mynij-results, .searx-results {
margin-top : 20px; margin-top : 20px;
flex: 50%; flex: 50%;
...@@ -508,6 +390,10 @@ input[type="button"]:hover{ ...@@ -508,6 +390,10 @@ input[type="button"]:hover{
font-weight: 700; font-weight: 700;
} }
.anbuild {
max-width: 90px;
}
.anbar { .anbar {
background-color: #83da41; background-color: #83da41;
background-image: linear-gradient(45deg, #71e721 25%, #cbecc5); background-image: linear-gradient(45deg, #71e721 25%, #cbecc5);
...@@ -558,3 +444,37 @@ input[type="button"]:hover{ ...@@ -558,3 +444,37 @@ input[type="button"]:hover{
} }
/* END Building indicator */ /* END Building indicator */
/* Table style */
table {
border-collapse: collapse;
}
.table {
width: 100%;
margin-bottom: 1rem;
color: #5e6e82;
}
.border-bottom {
border-bottom: 1px solid #d8e2ef;
}
.table th {
background-color: #034163;;
color: white;
font-weight: 600;
}
.table td, .table th {
padding: .75rem;
vertical-align: top;
border-top: 1px solid #edf2f9;
border-width: 0;
text-align: left;
}
.table tbody tr:nth-of-type(even) {
background-color: #f9fafd;
}
/* END Table style */
...@@ -242,7 +242,7 @@ ...@@ -242,7 +242,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>987.31506.15184.56388</string> </value> <value> <string>989.8578.56725.43554</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -260,7 +260,7 @@ ...@@ -260,7 +260,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1603444297.3</float> <float>1609843782.68</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -48,8 +48,9 @@ ...@@ -48,8 +48,9 @@
} }
.head-title { .head-title {
font-size: 2em; font-size: 1.5em;
margin-bottom: 15px; color: #454748;
margin-top: 15px;
} }
.hidden { .hidden {
......
...@@ -242,7 +242,7 @@ ...@@ -242,7 +242,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>988.48207.9318.17339</string> </value> <value> <string>988.48444.33021.4471</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -260,7 +260,7 @@ ...@@ -260,7 +260,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1608303150.22</float> <float>1609842995.14</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -79,6 +79,7 @@ ...@@ -79,6 +79,7 @@
<string>my_title</string> <string>my_title</string>
<string>my_links</string> <string>my_links</string>
<string>my_seed</string> <string>my_seed</string>
<string>my_status</string>
</list> </list>
</value> </value>
</item> </item>
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
.declareAcquiredMethod("notifySubmitting", "notifySubmitting") .declareAcquiredMethod("notifySubmitting", "notifySubmitting")
.declareAcquiredMethod("notifySubmitted", "notifySubmitted") .declareAcquiredMethod("notifySubmitted", "notifySubmitted")
.declareAcquiredMethod("setSetting", "setSetting") .declareAcquiredMethod("setSetting", "setSetting")
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("jio_get", "jio_get") .declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("jio_post", "jio_post") .declareAcquiredMethod("jio_post", "jio_post")
...@@ -19,18 +20,17 @@ ...@@ -19,18 +20,17 @@
var return_submit_dict, var return_submit_dict,
gadget = this, gadget = this,
list = parent_options.doc.links, list = parent_options.doc.links,
index_name = parent_options.doc.title, index_name = parent_options.doc.title;
property;
return new RSVP.Queue() return gadget.getSetting("build_dict", {})
.push(function(){ .push(function(build_dict){
//return gadget.buildIndex(list, index_name); build_dict[parent_options.action_options.jio_key] = {
// we build only one index per time for now
return gadget.setSetting("build_list", [{
links: list, links: list,
index_name: index_name, index_name: index_name,
jio_key: parent_options.action_options.jio_key,
id: Date.now() id: Date.now()
}]); };
return gadget.setSetting("build_dict", build_dict);
}) })
.push(function(){ .push(function(){
return_submit_dict = { return_submit_dict = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment