Commit 1fcd0227 authored by Roque's avatar Roque Committed by Roque

erp5_web_project_ui: refactoring in queries and html document parsing

- test extended
parent b394f150
/*global document, window, rJS */ /*global window, rJS, SimpleQuery, ComplexQuery, Query */
/*jslint nomen: true, indent: 2, maxerr: 10, maxlen: 90 */ /*jslint nomen: true, indent: 2, maxerr: 10, maxlen: 90 */
(function (document, window, rJS) { (function (window, rJS, SimpleQuery, ComplexQuery, Query) {
"use strict"; "use strict";
function createMultipleSimpleOrQuery(key, value_list) {
var i,
search_query,
query_list = [];
for (i = 0; i < value_list.length; i += 1) {
query_list.push(new SimpleQuery({
key: key,
operator: "",
type: "simple",
value: value_list[i]
}));
}
search_query = new ComplexQuery({
operator: "OR",
query_list: query_list,
type: "complex"
});
return Query.objectToSearchText(search_query);
}
rJS(window) rJS(window)
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
...@@ -17,14 +37,25 @@ ...@@ -17,14 +37,25 @@
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
.declareMethod("render", function (options) { .declareMethod("render", function (options) {
var gadget = this, id, var gadget = this,
types = '("Text", "File", "PDF", "Drawing", ' + type_list = ["Text", "File", "PDF", "Drawing",
'"Presentation", "Spreadsheet")', "Presentation", "Spreadsheet"],
states = '("shared", "published", "released", ' + state_list = ["shared", "published", "released", "shared_alive",
'"shared_alive", "published_alive", "released_alive")', "published_alive", "released_alive"],
query = 'portal_type:' + types + portal_type_query = createMultipleSimpleOrQuery('portal_type', type_list),
'AND reference:"' + options.reference + state_query = createMultipleSimpleOrQuery('validation_state', state_list),
'" AND validation_state:' + states; reference_query = new SimpleQuery({
key: "reference",
operator: "=",
type: "simple",
value: options.reference
}),
query = new ComplexQuery({
operator: "AND",
query_list: [portal_type_query, state_query, reference_query],
type: "complex"
});
query = Query.objectToSearchText(query);
return gadget.jio_allDocs({ return gadget.jio_allDocs({
query: query, query: query,
limit: 1 limit: 1
...@@ -38,10 +69,9 @@ ...@@ -38,10 +69,9 @@
'history': options.history 'history': options.history
} }
}); });
} else {
return gadget.redirect({command: 'history_previous', options: {}});
} }
return gadget.redirect({command: 'history_previous', options: {}});
}); });
}); });
}(document, window, rJS)); }(window, rJS, SimpleQuery, ComplexQuery, Query));
\ No newline at end of file \ No newline at end of file
...@@ -234,7 +234,7 @@ ...@@ -234,7 +234,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>979.50783.7411.19677</string> </value> <value> <string>979.57611.25870.2542</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>1573658874.74</float> <float>1574068976.28</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
/*jslint nomen: true, indent: 2 */ /*jslint nomen: true, indent: 2 */
/*global window, rJS, RSVP, document, ensureArray*/ /*global window, rJS, RSVP, document, ensureArray, DOMParser, XMLSerializer, SimpleQuery, ComplexQuery, Query*/
(function (window, rJS, RSVP, document, ensureArray) { (function (window, rJS, RSVP, document, ensureArray, DOMParser, XMLSerializer, SimpleQuery, ComplexQuery, Query) {
"use strict"; "use strict";
function parseHTMLLinks(html, url) { function addRedirectionToReference(href, url) {
var content = document.createElement('html'), if (!href.startsWith("https") && !href.startsWith("http") &&
regex = /href="(.*?)"/g, !href.startsWith("ftp") && !href.includes("/")
link;
while ((link = regex.exec(html)) !== null) {
if (! link[1].startsWith("https") && ! link[1].startsWith("http") &&
! link[1].startsWith("ftp") && ! link[1].includes("/")
) { ) {
html = html.replace(link[1], url + "&n.reference=" + link[1]); href = url + "&n.reference=" + href;
}
return href;
} }
function parseHTMLLinks(html, url) {
var parser = new DOMParser(), i,
oSerializer = new XMLSerializer(),
doc = parser.parseFromString(html, "text/html"),
link_list = doc.getElementsByTagName("a");
for (i = 0; i < link_list.length; i += 1) {
link_list[i].setAttribute('href', addRedirectionToReference(link_list[i].getAttribute('href'), url));
} }
return html; return oSerializer.serializeToString(doc);
} }
function enableLink(link_element, url) { function enableLink(link_element, url) {
...@@ -29,7 +35,8 @@ ...@@ -29,7 +35,8 @@
function setLastTestResult(gadget, project_title, span_element) { function setLastTestResult(gadget, project_title, span_element) {
span_element.classList.remove("ui-disabled"); span_element.classList.remove("ui-disabled");
var query = 'portal_type:="Benchmark Result" AND source_project_title:"' + project_title + '"'; var query = createProjectQuery(project_title,
[["portal_type", "Benchmark Result"]]);
return gadget.jio_allDocs({ return gadget.jio_allDocs({
query: query, query: query,
limit: 2, //first result could be the running test limit: 2, //first result could be the running test
...@@ -44,7 +51,8 @@ ...@@ -44,7 +51,8 @@
if (state === "stopped" || state === "public_stopped") { if (state === "stopped" || state === "public_stopped") {
span_element.classList.add("pass"); span_element.classList.add("pass");
break; break;
} else if (state === "failed") { }
if (state === "failed") {
span_element.classList.add("fail"); span_element.classList.add("fail");
break; break;
} }
...@@ -52,15 +60,66 @@ ...@@ -52,15 +60,66 @@
}); });
} }
function createProjectQuery(project_title, key_value_list) {
var i, query_list = [];
if (project_title) {
query_list.push(new SimpleQuery({
key: "source_project_title",
operator: "",
type: "simple",
value: project_title
}));
}
for (i = 0; i < key_value_list.length; i += 1) {
query_list.push(new SimpleQuery({
key: key_value_list[i][0],
operator: "",
type: "simple",
value: key_value_list[i][1]
}));
}
return Query.objectToSearchText(new ComplexQuery({
operator: "AND",
query_list: query_list,
type: "complex"
}));
}
function getWebPageInfo(gadget, project_reference) { function getWebPageInfo(gadget, project_reference) {
var query = 'portal_type:="Web Page" AND reference:"' + project_reference + var id,
'-Home.Page" AND validation_state:"published_alive"', content,
id, content, edit_view, redirector_ulr; edit_view,
redirector_ulr,
query,
query_list = [];
query_list.push(new SimpleQuery({
key: "portal_type",
operator: "=",
type: "simple",
value: "Web Page"
}));
query_list.push(new SimpleQuery({
key: "reference",
operator: "=",
type: "simple",
value: project_reference + '-Home.Page'
}));
query_list.push(new SimpleQuery({
key: "validation_state",
operator: "=",
type: "simple",
value: "published_alive"
}));
query = new ComplexQuery({
operator: "AND",
query_list: query_list,
type: "complex"
});
return gadget.getUrlFor({command: 'push_history', options: {page: "project_redirector"}}) return gadget.getUrlFor({command: 'push_history', options: {page: "project_redirector"}})
.push(function (url) { .push(function (url) {
redirector_ulr = url; redirector_ulr = url;
return gadget.jio_allDocs({ return gadget.jio_allDocs({
query: query, query: Query.objectToSearchText(query),
limit: 1, limit: 1,
select_list: ['text_content'] select_list: ['text_content']
}); });
...@@ -72,7 +131,9 @@ ...@@ -72,7 +131,9 @@
return gadget.jio_getAttachment(id, "links") return gadget.jio_getAttachment(id, "links")
.push(function (web_page_document) { .push(function (web_page_document) {
edit_view = getActionListByName( edit_view = getActionListByName(
ensureArray(web_page_document._links.view), "view_editor"); ensureArray(web_page_document._links.view),
"view_editor"
);
return {"id": id, "content": content, "edit_view": edit_view}; return {"id": id, "content": content, "edit_view": edit_view};
}); });
} }
...@@ -126,7 +187,9 @@ ...@@ -126,7 +187,9 @@
}) })
.push(function (result_list) { .push(function (result_list) {
var milestone_view = getActionListByName( var milestone_view = getActionListByName(
ensureArray(result_list[1]._links.view), "milestone"), ensureArray(result_list[1]._links.view),
"milestone"
),
document_view = result_list[3] + document_view = result_list[3] +
'/ERP5Document_getHateoas?mode=traverse&relative_url=' + '/ERP5Document_getHateoas?mode=traverse&relative_url=' +
modification_dict.jio_key + '&view=Project_viewDocumentList'; modification_dict.jio_key + '&view=Project_viewDocumentList';
...@@ -139,42 +202,42 @@ ...@@ -139,42 +202,42 @@
getUrlParameterDict('task_module', "view", [["delivery.start_date", "descending"]], getUrlParameterDict('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 + createProjectQuery(modification_dict.project_title,
'" AND selection_domain_state_task_domain: "confirmed"')), [["selection_domain_state_task_domain", "confirmed"]])),
getUrlParameterDict('support_request_module', "view", [["delivery.start_date", "descending"]], getUrlParameterDict('support_request_module', "view", [["delivery.start_date", "descending"]],
null, ('source_project_title: "' + modification_dict.project_title + null, createProjectQuery(modification_dict.project_title,
'" AND destination_project_title: "' + modification_dict.project_title + [["destination_project_title", modification_dict.project_title],
'" AND selection_domain_state_support_domain: "validated"')), ["selection_domain_state_support_domain", "validated"]])),
getUrlParameterDict('bug_module', "view", [["delivery.start_date", "descending"]], getUrlParameterDict('bug_module', "view", [["delivery.start_date", "descending"]],
["title", "description", "delivery.start_date"], ["title", "description", "delivery.start_date"],
('source_project_title: "' + modification_dict.project_title + createProjectQuery(modification_dict.project_title,
'" AND selection_domain_state_bug_domain: "started"')), [["selection_domain_state_bug_domain", "started"]])),
getUrlParameterDict('bug_module', "view", [["delivery.start_date", "descending"]], getUrlParameterDict('bug_module', "view", [["delivery.start_date", "descending"]],
["title", "description", "delivery.start_date"], ["title", "description", "delivery.start_date"],
('source_project_title: "' + modification_dict.project_title + createProjectQuery(modification_dict.project_title,
'" AND selection_domain_state_bug_domain: "closed"')), [["selection_domain_state_bug_domain", "closed"]])),
getUrlParameterDict('task_report_module', 'view', [["delivery.start_date", "descending"]], getUrlParameterDict('task_report_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 + createProjectQuery(modification_dict.project_title,
'" AND selection_domain_state_task_report_domain: "started"')), [["selection_domain_state_task_report_domain", "started"]])),
getUrlParameterDict('task_report_module', 'view', [["delivery.start_date", "descending"]], getUrlParameterDict('task_report_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 + createProjectQuery(modification_dict.project_title,
'" AND selection_domain_state_task_report_domain: "closed"')), [["selection_domain_state_task_report_domain", "closed"]])),
getUrlParameterDict('test_result_module', 'view', [["delivery.start_date", "descending"]], getUrlParameterDict('test_result_module', 'view', [["delivery.start_date", "descending"]],
null, ('source_project_title: "' + modification_dict.project_title + '"')), null, createProjectQuery(modification_dict.project_title, [])),
getUrlParameterDict('test_suite_module', 'view', [["creation_date", "descending"]], getUrlParameterDict('test_suite_module', 'view', [["creation_date", "descending"]],
null, ('source_project_title: "' + modification_dict.project_title + '"')), null, createProjectQuery(modification_dict.project_title, [])),
getUrlParameterDict('task_module', "view", [["delivery.start_date", "descending"]], getUrlParameterDict('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 + createProjectQuery(modification_dict.project_title,
'" AND selection_domain_state_task_domain: "not_confirmed"')), [["selection_domain_state_task_domain", "not_confirmed"]])),
getUrlParameterDict(web_page_info.id, web_page_info.edit_view), getUrlParameterDict(web_page_info.id, web_page_info.edit_view),
getUrlParameterDict(modification_dict.jio_key, document_view, [["modification_date", "descending"]], getUrlParameterDict(modification_dict.jio_key, document_view, [["modification_date", "descending"]],
null, ('selection_domain_state_document_domain: "confirmed"')) null, createProjectQuery(null, [["selection_domain_state_document_domain", "confirmed"]]))
]); ]);
}) })
.push(function (url_list) { .push(function (url_list) {
...@@ -205,4 +268,4 @@ ...@@ -205,4 +268,4 @@
return true; return true;
}); });
}(window, rJS, RSVP, document, ensureArray)); }(window, rJS, RSVP, document, ensureArray, DOMParser, XMLSerializer, SimpleQuery, ComplexQuery, Query));
\ No newline at end of file \ No newline at end of file
...@@ -24,17 +24,25 @@ ...@@ -24,17 +24,25 @@
</tr> </tr>
<!-- Initialize --> <!-- Initialize -->
<tr>
<td>open</td>
<td>${base_url}/portal_skins/erp5_web_project_test/ERP5Site_createTestStartedProject/</td>
<td></td>
</tr>
<tr>
<td>assertTextPresent</td>
<td>Project Created</td>
<td></td>
</tr>
<tal:block metal:use-macro="here/Zuite_CommonTemplate/macros/wait_for_activities" />
<tr> <tr>
<td>open</td> <td>open</td>
<td>${base_url}/web_site_module/project_management/</td> <td>${base_url}/web_site_module/project_management/</td>
<td></td> <td></td>
</tr> </tr>
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_app_loaded" /> <tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_app_loaded" />
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_listbox_loaded" /> <tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/wait_for_listbox_loaded" />
<tr> <tr>
<td>assertElementPresent</td> <td>assertElementPresent</td>
<td>//div[@data-gadget-url='${base_url}/web_site_module/project_management/gadget_erp5_field_listbox.html']</td> <td>//div[@data-gadget-url='${base_url}/web_site_module/project_management/gadget_erp5_field_listbox.html']</td>
...@@ -45,6 +53,17 @@ ...@@ -45,6 +53,17 @@
<td>Projects</td> <td>Projects</td>
<td></td> <td></td>
</tr> </tr>
<!-- Check filter -->
<tr>
<td>assertElementPresent</td>
<td>//div[@data-gadget-url='${base_url}/web_site_module/project_management/gadget_erp5_searchfield.html']</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>//div[@data-gadget-url='${base_url}/web_site_module/project_management/gadget_erp5_searchfield.html']//button[text()="started"]</td>
<td></td>
</tr>
<!-- Check sort --> <!-- Check sort -->
<tr> <tr>
<td>assertElementPresent</td> <td>assertElementPresent</td>
...@@ -87,6 +106,94 @@ ...@@ -87,6 +106,94 @@
<td>//div[@class='document_table']//th//a[text()="Location"]</td> <td>//div[@class='document_table']//th//a[text()="Location"]</td>
<td></td> <td></td>
</tr> </tr>
<!-- Check project present -->
<tr>
<td>assertElementPresent</td>
<td>//div[@class='document_table']//table//tbody//tr//a[text()="test-project"]</td>
<td></td>
</tr>
<tr>
<td>click</td>
<td>//div[@class='document_table']//table//tbody//tr//a[text()="test-project"]</td>
<td></td>
</tr>
<!-- check project quick view page elements -->
<tr>
<td>waitForElementPresent</td>
<td>//div[@data-gadget-url='${base_url}/web_site_module/project_management/gadget_project_info.html']//a[@id='milestone_link' and @class='first-line-buttons']</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>//div[@data-gadget-url='${base_url}/web_site_module/project_management/gadget_project_info.html']//a[text()='Milestones' and contains(@href, '#!push_history') and contains(@href, 'n.jio_key=milestone_module') and contains(@href, 'view%3Dmilestone')]</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>//div[@data-gadget-url='${base_url}/web_site_module/project_management/gadget_project_info.html']//a[text()='Support requests']</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>//div[@data-gadget-url='${base_url}/web_site_module/project_management/gadget_project_info.html']//a[text()='Documents']</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>//div[@data-gadget-url='${base_url}/web_site_module/project_management/gadget_project_info.html']//a[text()='Opened Bugs']</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>//div[@data-gadget-url='${base_url}/web_site_module/project_management/gadget_project_info.html']//a[text()='Closed Bugs']</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>//div[@data-gadget-url='${base_url}/web_site_module/project_management/gadget_project_info.html']//a[text()='Confirmed Tasks']</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>//div[@data-gadget-url='${base_url}/web_site_module/project_management/gadget_project_info.html']//a[text()='Not Confirmed Tasks']</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>//div[@data-gadget-url='${base_url}/web_site_module/project_management/gadget_project_info.html']//a[text()='Opened Task Reports']</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>//div[@data-gadget-url='${base_url}/web_site_module/project_management/gadget_project_info.html']//a[text()='Closed Task Reports']</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>//div[@data-gadget-url='${base_url}/web_site_module/project_management/gadget_project_info.html']//a[text()='Last test result']</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>//div[@data-gadget-url='${base_url}/web_site_module/project_management/gadget_project_info.html']//a[text()='Test suite']</td>
<td></td>
</tr>
<tr>
<td>assertElementPresent</td>
<td>//div[@data-gadget-url='${base_url}/web_site_module/project_management/gadget_project_info.html']//a[text()='Edit Project Page']</td>
<td></td>
</tr>
</tbody></table> </tbody></table>
</body> </body>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Folder" module="OFS.Folder"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_objects</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>erp5_web_project_test</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
portal = context.getPortalObject()
module = portal.getDefaultModule('Project')
project = module.newContent(portal_type = 'Project',
reference = 'test-project')
project.validate()
print "Project Created"
return printed
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ERP5Site_createTestStartedProject</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
erp5_web_project_test
\ No newline at end of file
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