Commit 94c6f3d7 authored by Roque's avatar Roque

erp5_web_project_ui: get project home page by publication section preference

- use global preference to get publication section value
- test updated
parent 12ac3d0c
...@@ -212,7 +212,7 @@ ...@@ -212,7 +212,7 @@
<list> <list>
<tuple> <tuple>
<string>state_document_domain</string> <string>state_document_domain</string>
<string>Document Status</string> <string>Document State</string>
</tuple> </tuple>
</list> </list>
</value> </value>
......
...@@ -253,7 +253,7 @@ ...@@ -253,7 +253,7 @@
<dictionary> <dictionary>
<item> <item>
<key> <string>_text</string> </key> <key> <string>_text</string> </key>
<value> <string>python: {"project_title":here.getTitle(), "jio_key": here.getRelativeUrl(), "project_reference": here.getReference()}</string> </value> <value> <string>python: {"jio_key": here.getRelativeUrl(), "publication_section": here.getPortalObject().portal_preferences.getPreferredPublicationSection() }</string> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
......
...@@ -33,8 +33,8 @@ ...@@ -33,8 +33,8 @@
return view_list.filter(d => d.name === name)[0].href; return view_list.filter(d => d.name === name)[0].href;
} }
function setLatestTestResult(gadget, project_title, svg_element, project_id) { function setLatestTestResult(gadget, svg_element, project_jio_key) {
var query = createProjectQuery(project_id, var query = createProjectQuery(project_jio_key,
[["portal_type", "Test Result"]]); [["portal_type", "Test Result"]]);
return gadget.jio_allDocs({ return gadget.jio_allDocs({
query: query, query: query,
...@@ -76,6 +76,7 @@ ...@@ -76,6 +76,7 @@
function createProjectQuery(project_jio_key, key_value_list) { function createProjectQuery(project_jio_key, key_value_list) {
var i, query_list = [], id_query_list = [], id_complex_query; var i, query_list = [], id_query_list = [], id_complex_query;
if (project_jio_key) { if (project_jio_key) {
//relation to project or child project lines
id_query_list.push(new SimpleQuery({ id_query_list.push(new SimpleQuery({
key: "source_project__relative_url", key: "source_project__relative_url",
operator: "", operator: "",
...@@ -110,61 +111,75 @@ ...@@ -110,61 +111,75 @@
})); }));
} }
function getWebPageInfo(gadget, project_reference) { function getWebPageInfo(gadget, project_jio_key, publication_section) {
var id, var id,
content, content,
edit_view, edit_view,
redirector_ulr, redirector_ulr,
i,
query, query,
query_list = [], query_list = [],
valid_state_list = ["shared_alive", "released_alive", "published_alive"]; id_query_list = [],
validation_state_query_list = [],
valid_state_list = ["shared_alive", "released_alive", "published_alive"],
web_page;
query_list.push(new SimpleQuery({ query_list.push(new SimpleQuery({
key: "portal_type", key: "portal_type",
operator: "=", operator: "=",
type: "simple", type: "simple",
value: "Web Page" value: "Web Page"
})); }));
for (i = 0; i < valid_state_list.length; i += 1) {
validation_state_query_list.push(new SimpleQuery({
key: "validation_state",
type: "simple",
operator: "=",
value: valid_state_list[i]
}));
}
query_list.push(new ComplexQuery({
operator: "OR",
query_list: validation_state_query_list,
type: "complex"
}));
query_list.push(new SimpleQuery({ query_list.push(new SimpleQuery({
key: "reference", key: "follow_up__relative_url",
operator: "=", operator: "=",
type: "simple", type: "simple",
value: project_reference + '-Home.Page' value: project_jio_key
})); }));
query = new ComplexQuery({ query_list.push(new SimpleQuery({
key: "publication_section__relative_url",
operator: "=",
type: "simple",
value: "publication_section/" + publication_section
}));
query = Query.objectToSearchText(new ComplexQuery({
operator: "AND", operator: "AND",
query_list: query_list, query_list: query_list,
type: "complex" 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.objectToSearchText(query), query: query,
select_list: ['validation_state', 'text_content'] select_list: ['text_content']
}); });
}) })
.push(function (result_list) { .push(function (result_list) {
if (result_list.data.rows[0]) { if (result_list.data.rows[0]) {
var i, state, web_page; web_page = result_list.data.rows[0];
for (i = 0; i < result_list.data.rows.length; i = i + 1) { id = web_page.id;
state = result_list.data.rows[i].value.validation_state; content = parseHTMLLinks(web_page.value.text_content, redirector_ulr);
if (valid_state_list.includes(state)) { return gadget.jio_getAttachment(id, "links")
web_page = result_list.data.rows[i]; .push(function (web_page_document) {
break; edit_view = getActionListByName(
} ensureArray(web_page_document._links.view),
} "view_editor"
if (web_page) { );
id = web_page.id; return {"id": id, "content": content, "edit_view": edit_view};
content = parseHTMLLinks(web_page.value.text_content, redirector_ulr); });
return gadget.jio_getAttachment(id, "links")
.push(function (web_page_document) {
edit_view = getActionListByName(
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}; return {"id": id, "content": content, "edit_view": edit_view};
}); });
...@@ -195,8 +210,7 @@ ...@@ -195,8 +210,7 @@
.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, publication_section: options.publication_section
project_reference: options.project_reference
}; };
return this.changeState(state_dict); return this.changeState(state_dict);
}) })
...@@ -208,7 +222,7 @@ ...@@ -208,7 +222,7 @@
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
return RSVP.all([ return RSVP.all([
getWebPageInfo(gadget, modification_dict.project_reference), getWebPageInfo(gadget, modification_dict.jio_key, modification_dict.publication_section),
gadget.getDeclaredGadget("editor"), gadget.getDeclaredGadget("editor"),
gadget.getSetting("hateoas_url") gadget.getSetting("hateoas_url")
]); ]);
...@@ -270,8 +284,7 @@ ...@@ -270,8 +284,7 @@
} }
enableLink(document.getElementById("document_link"), url_list[8]); enableLink(document.getElementById("document_link"), url_list[8]);
enableLink(document.getElementById("activity_link"), url_list[9]); enableLink(document.getElementById("activity_link"), url_list[9]);
setLatestTestResult(gadget, modification_dict.project_title, setLatestTestResult(gadget, document.getElementById("test_result_svg"), modification_dict.jio_key);
document.getElementById("test_result_svg"), modification_dict.jio_key);
}); });
}) })
......
portal = context.getPortalObject() portal = context.getPortalObject()
project_reference = 'test-project'
module = portal.getDefaultModule('Project')
project = module.newContent(portal_type = 'Project',
reference = project_reference)
project.validate()
if home_page: if home_page:
system_preference = portal.portal_preferences.getActiveSystemPreference()
system_preference.setPreferredPublicationSection("project_home_page_for_test")
publication_section = context.restrictedTraverse('portal_categories/publication_section/project_home_page_for_test')
module = portal.getDefaultModule('Web Page') module = portal.getDefaultModule('Web Page')
home_page = module.newContent(portal_type = 'Web Page', home_page = module.newContent(portal_type = 'Web Page',
reference = 'test-project-Home.Page') reference = project_reference + '-home.page',
publication_section_value = publication_section,
follow_up_value = project)
home_page.publishAlive() home_page.publishAlive()
module = portal.getDefaultModule('Project')
project = module.newContent(portal_type = 'Project',
reference = 'test-project')
project.validate()
print "Project Created" print "Project Created"
return printed return printed
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