Commit a7359e8e authored by Roque's avatar Roque

erp5_web_project_ui: get last test result state using jio

parent 377eef39
...@@ -14,11 +14,17 @@ portal_catalog = portal.portal_catalog ...@@ -14,11 +14,17 @@ portal_catalog = portal.portal_catalog
reference = str(context.getReference()) + "-Home.Page" reference = str(context.getReference()) + "-Home.Page"
home_page = portal_catalog.getResultValue( home_page = portal_catalog.getResultValue(
portal_type = 'Web Page', portal_type = 'Web Page',
reference = reference) reference = reference,
validation_state = "published_alive")
if home_page: if home_page:
content = home_page.getTextContent() content = home_page.getTextContent()
else: else:
content = "" content = ""
return [('project_title', context.getTitle()), ('jio_key', context.getRelativeUrl()), ('home_page_content', content)] if home_page:
home_page_jio_key = home_page.getRelativeUrl()
else:
home_page_jio_key = ""
return [('project_title', context.getTitle()), ('jio_key', context.getRelativeUrl()), ('home_page_jio_key', home_page_jio_key), ('home_page_content', content)]
...@@ -18,35 +18,32 @@ lockGadgetInQueue, unlockGadgetInQueue, Handlebars*/ ...@@ -18,35 +18,32 @@ lockGadgetInQueue, unlockGadgetInQueue, Handlebars*/
link_element.classList.remove("ui-disabled"); link_element.classList.remove("ui-disabled");
} }
function generateAjaxPromise(url) { function getActionListByName(view_list, name) {
return new RSVP.Queue() return view_list.filter(d => d.name === name)[0].href;
.push(function () {
return jIO.util.ajax({
url: url,
dataType: 'text'
});
})
.push(function (evt) {
return evt.target.responseText.split('\n');
});
} }
function setHTMLWithPromiseResult(span_element, promise) { function setLastTestResult(gadget, project_title, span_element) {
return new RSVP.Queue() var query = 'portal_type:="Benchmark Result" AND source_project_title:"' + project_title + '"';
.push(function () { return gadget.jio_allDocs({
return promise; query: query,
}) limit: 2, //first result could be the running test
.push(function (result) { sort_on: [['creation_date', 'descending']],
if (result[0] === "1") { select_list: ['simulation_state']
})
.push(function (result_list) {
var i, state;
result_list = result_list.data.rows;
for (i = 0; i < result_list.length; i = i + 1) {
state = result_list[i].value.simulation_state;
if (state === "stopped" || state === "public_stopped") {
span_element.classList.add("pass"); span_element.classList.add("pass");
} else { break;
} else if (state === "failed") {
span_element.classList.add("fail"); span_element.classList.add("fail");
break;
} }
}); }
} });
function getActionListByName(view_list, name) {
return view_list.filter(d => d.name === name)[0].href;
} }
function getUrlParameters(jio_key, view, sort_list, column_list, extended_search) { function getUrlParameters(jio_key, view, sort_list, column_list, extended_search) {
...@@ -68,13 +65,15 @@ lockGadgetInQueue, unlockGadgetInQueue, Handlebars*/ ...@@ -68,13 +65,15 @@ lockGadgetInQueue, unlockGadgetInQueue, Handlebars*/
.declareAcquiredMethod("getSetting", "getSetting") .declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("getUrlForList", "getUrlForList") .declareAcquiredMethod("getUrlForList", "getUrlForList")
.declareAcquiredMethod("getUrlParameter", "getUrlParameter") .declareAcquiredMethod("getUrlParameter", "getUrlParameter")
.declareAcquiredMethod("jio_allDocs", "jio_allDocs")
.declareAcquiredMethod("jio_getAttachment", "jio_getAttachment") .declareAcquiredMethod("jio_getAttachment", "jio_getAttachment")
.declareMethod('render', function (options) { .declareMethod('render', function (options) {
var state_dict = { var state_dict = {
jio_key: options.jio_key || "", jio_key: options.jio_key || "",
project_title: options.project_title, project_title: options.project_title,
home_page_content: options.home_page_content home_page_content: options.home_page_content,
home_page_jio_key: options.home_page_jio_key
}; };
return this.changeState(state_dict); return this.changeState(state_dict);
}) })
...@@ -82,11 +81,8 @@ lockGadgetInQueue, unlockGadgetInQueue, Handlebars*/ ...@@ -82,11 +81,8 @@ lockGadgetInQueue, unlockGadgetInQueue, Handlebars*/
.onStateChange(function (modification_dict) { .onStateChange(function (modification_dict) {
var gadget = this, var gadget = this,
base_site = window.location.origin + window.location.pathname, base_site = window.location.origin + window.location.pathname,
project_url = base_site + modification_dict.jio_key, project_url = base_site + modification_dict.jio_key;
// REPLACE THIS AJAX REQUEST WITH JIO setLastTestResult(gadget, modification_dict.project_title, document.getElementById("test_result_span"));
last_test_result_promise = generateAjaxPromise(project_url + "/Project_lastTestResult");
setHTMLWithPromiseResult(document.getElementById("test_result_span"), last_test_result_promise);
return gadget.jio_getAttachment(modification_dict.jio_key, "links") return gadget.jio_getAttachment(modification_dict.jio_key, "links")
.push(function (erp5_document) { .push(function (erp5_document) {
var milestone_view = getActionListByName(ensureArray(erp5_document._links.view), "milestone"); var milestone_view = getActionListByName(ensureArray(erp5_document._links.view), "milestone");
...@@ -118,7 +114,8 @@ lockGadgetInQueue, unlockGadgetInQueue, Handlebars*/ ...@@ -118,7 +114,8 @@ lockGadgetInQueue, unlockGadgetInQueue, Handlebars*/
getUrlParameters('task_module', "view", [["delivery.start_date", "descending"]], getUrlParameters('task_module', "view", [["delivery.start_date", "descending"]],
["title", "delivery.start_date", "delivery.stop_date", "destination_decision_title", ["title", "delivery.start_date", "delivery.stop_date", "destination_decision_title",
"source_title", "destination_title", "total_quantity", "task_line_quantity_unit_title"], "source_title", "destination_title", "total_quantity", "task_line_quantity_unit_title"],
('source_project_title: "' + modification_dict.project_title + '" AND selection_domain_state_task_domain: "not_confirmed"')) ]); ('source_project_title: "' + modification_dict.project_title + '" AND selection_domain_state_task_domain: "not_confirmed"')),
getUrlParameters(modification_dict.home_page_jio_key, "view") ]);
}) })
.push(function (url_list) { .push(function (url_list) {
enableLink(document.getElementById("milestone_link"), url_list[0]); enableLink(document.getElementById("milestone_link"), url_list[0]);
......
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