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 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>988.46729.51863.18141</string> </value>
<value> <string>989.7259.5245.62788</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -252,7 +252,7 @@
</tuple>
<state>
<tuple>
<float>1608300703.11</float>
<float>1609768857.13</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -8,11 +8,27 @@
<link rel="stylesheet" type="text/css" href="mynij-style.css">
</head>
<body>
<i class="info">This page will refresh automatically!</i>
<div class="seedbox" id="seedactivities">
<h1 class="head-title">Torrent Background Activities</h1>
<h1 class="head-title">Torrent Activities</h1>
<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 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>
</html>
\ No newline at end of file
......@@ -242,7 +242,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>988.47141.9623.51421</string> </value>
<value> <string>989.8582.46803.62617</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1608289101.66</float>
<float>1609843960.43</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -16,6 +16,8 @@
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("setSetting", "setSetting")
.declareAcquiredMethod("jio_post", "jio_post")
.declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("jio_put", "jio_put")
.ready(function () {
var indices = [], db;
......@@ -109,17 +111,26 @@
});
})
.declareMethod("createIndexDoc", function (doc) {
var gadget = this;
return gadget.getSetting("portal_type")
.push(function (portal_type) {
doc.portal_type = portal_type;
return gadget.getSetting("parent_portal_type");
})
.push(function (parent_portal_type) {
doc.parent_portal_type = parent_portal_type;
return gadget.jio_post(doc);
});
})
var gadget = this;
return gadget.getSetting("portal_type")
.push(function (portal_type) {
doc.portal_type = portal_type;
return gadget.getSetting("parent_portal_type");
})
.push(function (parent_portal_type) {
doc.parent_portal_type = parent_portal_type;
return gadget.jio_post(doc);
});
})
.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) {
var gadget = this,
......
......@@ -242,7 +242,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>988.62603.37288.24012</string> </value>
<value> <string>989.7469.5007.51797</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1609162985.92</float>
<float>1609845884.52</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -8,16 +8,25 @@
<script src="mynij_rss-parser.min.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="mynij-style.css">
<script id="panel-template-progress" type="text/x-handlebars-template">
<p>Building <span class="build-title">{{title}} ...</span></p>
<div class="anbar bar1"></div>
<div class="anbar bar2"></div>
<div class="anbar bar3"></div>
<div class="anbar bar4"></div>
<div class="anbar bar5"></div>
<script id="build-template-progress" type="text/x-handlebars-template">
<td>{{title}}</td>
<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 bar3"></div>
<div class="anbar bar4"></div>
<div class="anbar bar5"></div>
</td>
{{else}}
<td class="index-status"><span>Stopped</span></td><td></td>
{{/if}}
</script>
</head>
<body>
<div data-gadget-url="gadget_mynij_model.html" data-gadget-scope="model"
data-gadget-sandbox="public"></div>
</body>
</html>
\ No newline at end of file
......@@ -242,7 +242,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>987.31553.14164.37563</string> </value>
<value> <string>989.8564.46957.4761</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1603444183.66</float>
<float>1609842676.07</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -10,8 +10,8 @@
"https://softinst116265.host.vifib.net/erp5/ERP5Site_getHTTPResource",
"https://softinst116446.host.vifib.net/erp5/ERP5Site_getHTTPResource"
],
panel_template_progress = Handlebars.compile(template_element
.getElementById("panel-template-progress")
build_template_progress = Handlebars.compile(template_element
.getElementById("build-template-progress")
.innerHTML);
function get_random_id() {
......@@ -28,6 +28,16 @@
.declareAcquiredMethod("setSetting", "setSetting")
.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) {
var gadget = this;
return gadget.jio_get(parent_options.jio_key)
......@@ -38,49 +48,53 @@
.declareAcquiredMethod("add_to_index", "add_to_index")
.declareAcquiredMethod("save_index", "save_index")
.declareAcquiredMethod("getParentElement", "getParentElement")
.declareMethod("pushIndex", function (index_name) {
var gadget = this;
return gadget.getSetting('index_list', [])
.push(function (index_list) {
if (index_list.indexOf(index_name) === -1) {
index_list.push(index_name);
return gadget.setSetting('index_list', index_list);
.declareMethod("getIndexToBuild", function () {
return this.getSetting('build_dict')
.push(function (build_dict) {
var key,
entry;
for (key in build_dict) {
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
.declareService(function () {
var gadget = this,
parent_content;
var gadget = this;
function build() {
var entry;
return new RSVP.Queue()
.push(function () {
return gadget.getSetting('build_list');
})
.push(function (build_list) {
var status;
return gadget.getIndexToBuild()
.push(function (entry) {
var link_list,
tmp_element;
if (!build_list || !build_list.length)
if (!entry)
// wait 5s and check again if there is something to build
return RSVP.delay(5000);
else {
entry = build_list[0];
gadget.state.current_build = entry;
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)
.push(function () {
console.log("done building index");
return gadget.save_index(entry.index_name)
.push(function (result) {
status = 'built';
return gadget.notifySubmitted({
message: "Index '" + entry.index_name + "' built : " +
result + " item(s) added.",
......@@ -90,26 +104,34 @@
})
.push(undefined, function (my_error) {
showError(my_error);
gadget.state.current_build = undefined;
status = 'build failed';
return gadget.notifySubmitted({
message: "Index '" + entry.index_name + "' built failed!",
status: "error"
});
})
.push(function () {
var indicator = parent_content.querySelector('.building');
if (indicator)
parent_content.removeChild(indicator);
return gadget.getSetting('build_list');
gadget.state.current_build = undefined;
return gadget.getSetting('build_dict', {});
})
.push(function (current) {
if (current && current.length &&
current[0].id === entry.id) {
current.shift();
return gadget.setSetting('build_list', current);
if (!current[entry.jio_key]) {
console.log("Error: cannot get key '" + entry.jio_key +
"' in build_dict");
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 () {
return gadget.pushIndex(entry.index_name);
return gadget.state.model_gadget.pushIndex(entry.index_name);
});
}
})
......@@ -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,
links = list.split("\n").filter(link => link.length > 0);
container = document.getElementById('buildactivities'),
element;
return gadget.build_index(links, index_name)
.push(function (result) {
console.log("done building index");
return gadget.save_index(index_name);
})
.push(undefined, function (my_error) {
showError(my_error);
if (!container)
return;
element = container.querySelector('.build-list');
if (!element)
return;
return gadget.getSetting('build_dict')
.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) {
var gadget = this,
......
......@@ -242,7 +242,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>988.6617.37252.48349</string> </value>
<value> <string>989.8577.12361.41625</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1605884721.12</float>
<float>1609843972.59</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -36,135 +36,17 @@
font-size: 1.5em;
}
i.info {
color: #b0b0b0;
font-size: .9em;
}
@media (max-width: 600px) {
#mynij-results > li, #searx-results > li {
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 {
margin-top : 20px;
flex: 50%;
......@@ -508,6 +390,10 @@ input[type="button"]:hover{
font-weight: 700;
}
.anbuild {
max-width: 90px;
}
.anbar {
background-color: #83da41;
background-image: linear-gradient(45deg, #71e721 25%, #cbecc5);
......@@ -558,3 +444,37 @@ input[type="button"]:hover{
}
/* 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 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>987.31506.15184.56388</string> </value>
<value> <string>989.8578.56725.43554</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1603444297.3</float>
<float>1609843782.68</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -48,8 +48,9 @@
}
.head-title {
font-size: 2em;
margin-bottom: 15px;
font-size: 1.5em;
color: #454748;
margin-top: 15px;
}
.hidden {
......
......@@ -242,7 +242,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>988.48207.9318.17339</string> </value>
<value> <string>988.48444.33021.4471</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1608303150.22</float>
<float>1609842995.14</float>
<string>UTC</string>
</tuple>
</state>
......
......@@ -79,6 +79,7 @@
<string>my_title</string>
<string>my_links</string>
<string>my_seed</string>
<string>my_status</string>
</list>
</value>
</item>
......
......@@ -4,6 +4,7 @@
.declareAcquiredMethod("notifySubmitting", "notifySubmitting")
.declareAcquiredMethod("notifySubmitted", "notifySubmitted")
.declareAcquiredMethod("setSetting", "setSetting")
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("jio_get", "jio_get")
.declareAcquiredMethod("jio_post", "jio_post")
......@@ -19,18 +20,17 @@
var return_submit_dict,
gadget = this,
list = parent_options.doc.links,
index_name = parent_options.doc.title,
property;
index_name = parent_options.doc.title;
return new RSVP.Queue()
.push(function(){
//return gadget.buildIndex(list, index_name);
// we build only one index per time for now
return gadget.setSetting("build_list", [{
return gadget.getSetting("build_dict", {})
.push(function(build_dict){
build_dict[parent_options.action_options.jio_key] = {
links: list,
index_name: index_name,
jio_key: parent_options.action_options.jio_key,
id: Date.now()
}]);
};
return gadget.setSetting("build_dict", build_dict);
})
.push(function(){
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