Commit a57daf87 authored by Alain Takoudjou's avatar Alain Takoudjou Committed by Rafael Monnerat

[erp5_web_monitoring] Monitoring dispatch now be used to access items in monitor.

If the search result is only one item, redirect to the item view page, else redirect to the list of that items and let user choose the good one.
parent 0b90a87f
...@@ -5,25 +5,37 @@ ...@@ -5,25 +5,37 @@
<meta name="viewport" content="width=device-width" /> <meta name="viewport" content="width=device-width" />
<title>ERP5 Page Monitoring Dispatch</title> <title>ERP5 Page Monitoring Dispatch</title>
<link href="gadget_officejs_monitoring_custom.css" rel="stylesheet" type="text/css"/>
<!-- renderjs --> <!-- renderjs -->
<script src="rsvp.js" type="text/javascript"></script> <script src="rsvp.js" type="text/javascript"></script>
<script src="renderjs.js" type="text/javascript"></script> <script src="renderjs.js" type="text/javascript"></script>
<script src="handlebars.js" type="text/javascript"></script> <script src="handlebars.js" type="text/javascript"></script>
<script src="gadget_erp5_page_ojsm_dispatch.js" type="text/javascript"></script> <script src="gadget_erp5_page_ojsm_dispatch.js" type="text/javascript"></script>
<script id="dispatch-template" type="text/x-handlebars-template"> <script id="dispatch-template" type="text/x-handlebars-template">
<section class="ui-content-header-plain"> <h3 class="ui-content-title ui-body-c" data-i18n="No results from your search">
<h3 class="ui-content-title ui-body-c" data-i18n="[last]{{definition_i18n}}"> <span class="ui-icon ui-icon-custom ui-icon-frown-o">&nbsp;</span>
<span class="ui-icon ui-icon-custom ui-icon-share">&nbsp;</span> No results from your search!
Monitoring Search
</h3> </h3>
</section>
<h1>{{item}}: Not found in monitor!</h1>
</script> </script>
</head> </head>
<body> <body>
<section class="ui-content-header-plain">
<h3 class="ui-content-title ui-body-c" data-i18n="Monitoring Search">
<span class="ui-icon ui-icon-custom ui-icon-search">&nbsp;</span>
Monitoring Search
</h3>
</section>
<p class="text-info">Type a text or query. ie: <i>portal_type: "Software Instance" AND title: "foo"</i></p>
<form class="dialog_form">
<button type="submit"
class="ui-btn ui-btn-b ui-btn-inline
ui-icon-action ui-btn-icon-right ui-screen-hidden">Submit</button>
<div data-gadget-url="gadget_erp5_searchfield.html"
data-gadget-scope="erp5_searchfield"
data-gadget-sandbox="public"></div>
</form>
<div class="search-result"></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>963.3574.26713.18039</string> </value> <value> <string>963.33813.35232.64187</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>1509121633.77</float> <float>1510936342.8</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
/*global window, rJS, Handlebars */ /*global window, rJS, RSVP, Handlebars */
/*jslint nomen: true, indent: 2, maxerr: 3 */ /*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, Handlebars) { (function (window, rJS, RSVP, Handlebars) {
"use strict"; "use strict";
var gadget_klass = rJS(window), var gadget_klass = rJS(window),
...@@ -9,6 +9,60 @@ ...@@ -9,6 +9,60 @@
.innerHTML, .innerHTML,
dispatch_template = Handlebars.compile(source); dispatch_template = Handlebars.compile(source);
function searchItem(gadget, search_query) {
var redirect_options = {},
select_list = ["portal_type"];
if (search_query === undefined || search_query === "") {
return new RSVP.Queue()
.push(function () {
return;
});
}
return new RSVP.Queue()
.push(function () {
return gadget.getSetting("listbox_lines_limit", 20);
})
.push(function (lines_limit) {
return gadget.jio_allDocs({
query: search_query,
select_list: select_list,
limit: [0, lines_limit]
});
})
.push(function (result) {
if (result === undefined || result.data.total_rows === 0) {
// no result from the query
return;
}
if (result.data.total_rows === 1) {
// one item found, redirect to it
redirect_options = {
"jio_key": result.data.rows[0].id
};
if (result.data.rows[0].value.portal_type === "opml") {
redirect_options.page = "ojsm_hosting_subscription_view";
redirect_options.opml_key = result.data.rows[0].id;
}
return gadget.redirect({"command": "index", options: redirect_options});
}
redirect_options = {
extended_search: gadget.state.query
};
if (gadget.state.portal_type === undefined) {
// take the first one
gadget.state.portal_type = result.data.rows[0].value.portal_type;
}
if (gadget.state.portal_type === "opml") {
redirect_options.page = "ojsm_hosting_subscription_list";
} else if (gadget.state.portal_type === "Software Instance") {
redirect_options.page = "ojsm_software_instance_list";
} else if (gadget.state.portal_type === "promise") {
redirect_options.page = "ojsm_status_list";
}
return gadget.redirect({"command": "display", options: redirect_options});
});
}
gadget_klass gadget_klass
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
...@@ -17,21 +71,135 @@ ...@@ -17,21 +71,135 @@
.declareAcquiredMethod("translateHtml", "translateHtml") .declareAcquiredMethod("translateHtml", "translateHtml")
.declareAcquiredMethod("getUrlFor", "getUrlFor") .declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("updateHeader", "updateHeader") .declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("jio_allDocs", "jio_allDocs")
.declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("setSetting", "setSetting")
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// declared methods // declared methods
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
.declareMethod("triggerSubmit", function () {
var argument_list = arguments;
return this.getDeclaredGadget('form_view')
.push(function (gadget) {
return gadget.triggerSubmit.apply(gadget, argument_list);
});
})
.declareMethod("render", function (options) { .declareMethod("render", function (options) {
var gadget = this; var gadget = this,
regex = /portal_type\s*\:\s*[\'\"]([\w+\s+]+)[\'\"]/i,
regex_list = /\(?([\w\d\_]+)\s*\:\s*\(([\"\w\_\d\-\.\s*\,]+)\)\)?/g,
query_list = [],
i,
tmp,
page_title = "Monitoring Search",
original_query,
portal_type,
pt_result,
result;
result = regex_list.exec(options.query);
if (result !== null) {
tmp = result[2].split(',');
for (i = 0; i < tmp.length; i += 1) {
query_list.push(result[1] + ': ' + tmp[i].trim());
}
options.query = options.query
.replace(regex_list, '(' + query_list.join(' OR ') + ')');
}
original_query = JSON.parse(JSON.stringify(options.query || ""));
pt_result = regex.exec(options.query);
if (pt_result !== null) {
page_title = "Searching " + pt_result[1] + "(s)";
if (pt_result[1] === "Hosting Subscription") {
portal_type = "opml";
options.query = options.query.replace(pt_result[1], 'opml');
} else {
portal_type = pt_result[1];
}
}
gadget.element.innerHTML = dispatch_template({item: options.query || undefined});
return gadget.getUrlFor({command: 'display', options: {page: 'ojsm_status_list'}}) return gadget.getUrlFor({command: 'display', options: {page: 'ojsm_status_list'}})
.push(function (url) { .push(function (back_url) {
return gadget.updateHeader({ return gadget.updateHeader({
back_url: url, page_title: page_title,
page_title: "Jump to Object" back_url: back_url
});
})
.push(function () {
return gadget.changeState({
original_query: original_query,
query: options.query,
portal_type: portal_type || "promise",
import_opml: portal_type === undefined ? false : options.import_opml || true
}); });
}); });
})
.onStateChange(function () {
var gadget = this;
return new RSVP.Queue()
.push(function () {
if (gadget.state.import_opml) {
return gadget.getSetting('latest_import_date')
.push(function (import_date) {
// If import was never done, or was done more than 2 weeks ago
// 1209600000 = 1000*60*60*24*14
var current_date = new Date().getTime();
if (import_date === undefined ||
(import_date + 1209600000) < current_date) {
return gadget.setSetting('sync_redirect_options', {
query: gadget.state.original_query,
page: 'ojsm_dispatch'
})
.push(function () {
return gadget.redirect({command: 'change', options: {
page: "ojsm_erp5_configurator",
type: "erp5"
}});
});
}
});
}
})
.push(function () {
return gadget.getDeclaredGadget('erp5_searchfield');
})
.push(function (searchfield) {
return searchfield.render({
extended_search: gadget.state.original_query,
focus: true
});
})
.push(function () {
return searchItem(gadget, gadget.state.query);
})
.push(function (search_result) {
if (search_result === undefined && gadget.state.query) {
gadget.element.querySelector('.search-result')
.innerHTML = dispatch_template({});
}
}); });
})
.onEvent('submit', function () {
var gadget = this;
return gadget.getDeclaredGadget("erp5_searchfield")
.push(function (search_gadget) {
return search_gadget.getContent();
})
.push(function (data) {
var options = {
page: "ojsm_dispatch"
};
if (data.search) {
options.query = data.search;
return gadget.redirect({command: 'change', options: options});
}
});
}, false, true);
}(window, rJS, Handlebars)); }(window, rJS, RSVP, Handlebars));
\ No newline at end of file \ No newline at end of file
...@@ -238,7 +238,7 @@ ...@@ -238,7 +238,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>963.29379.61141.36334</string> </value> <value> <string>963.38063.22401.1996</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -256,7 +256,7 @@ ...@@ -256,7 +256,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1510669689.61</float> <float>1511190866.88</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
Your ERP5 Connection parameters Your ERP5 Connection parameters
</h3> </h3>
</section> </section>
<p>You have to be logged in this ERP5 prior to synchronising</p> <p>You have to be logged in this ERP5 prior to import OPML</p>
</article> </article>
<br> <br>
<form class="save_form ui-body-c" novalidate> <form class="save_form ui-body-c" novalidate>
......
...@@ -242,7 +242,7 @@ ...@@ -242,7 +242,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>962.54628.50882.58453</string> </value> <value> <string>963.27666.8050.30907</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>1508258766.54</float> <float>1511257051.71</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -590,10 +590,13 @@ ...@@ -590,10 +590,13 @@
status: "error" status: "error"
}); });
} }
return gadget.notifySubmitted({ return RSVP.all([
gadget.setSetting("latest_import_date", new Date().getTime()),
gadget.notifySubmitted({
message: "Configuration Saved!", message: "Configuration Saved!",
status: "success" status: "success"
}); })
]);
}) })
.push(function () { .push(function () {
if (!has_failed) { if (!has_failed) {
......
...@@ -250,7 +250,7 @@ ...@@ -250,7 +250,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>963.27984.14453.52343</string> </value> <value> <string>963.37770.32649.6058</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -268,7 +268,7 @@ ...@@ -268,7 +268,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1510833881.21</float> <float>1511174176.26</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -110,7 +110,7 @@ ...@@ -110,7 +110,7 @@
"lines": lines_limit, "lines": lines_limit,
"list_method": "portal_catalog", "list_method": "portal_catalog",
"query": "urn:jio:allDocs?query=portal_type%3A%22" + "query": "urn:jio:allDocs?query=portal_type%3A%22" +
"Software Instance" + "%22", "Software%20Instance" + "%22",
"portal_type": [], "portal_type": [],
"search_column_list": column_list, "search_column_list": column_list,
"sort_column_list": column_list, "sort_column_list": column_list,
......
...@@ -242,7 +242,7 @@ ...@@ -242,7 +242,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>963.32354.21099.3054</string> </value> <value> <string>963.33701.38666.63044</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>1510928975.35</float> <float>1511187464.03</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
.declareAcquiredMethod("updateHeader", "updateHeader") .declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("redirect", "redirect") .declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("setSetting", "setSetting")
.declareMethod("render", function () { .declareMethod("render", function () {
var gadget = this; var gadget = this;
...@@ -22,10 +24,20 @@ ...@@ -22,10 +24,20 @@
return sync_gadget.register({now: true}); return sync_gadget.register({now: true});
}); });
}) })
.push(function () {
var redirect_options = {"page": "ojsm_status_list"};
return gadget.getSetting('sync_redirect_options')
.push(function (redirect_dict) {
if (redirect_options) {
redirect_options = redirect_dict;
return gadget.setSetting("sync_redirect_options", undefined);
}
})
.push(function () { .push(function () {
return gadget.redirect({ return gadget.redirect({
command: "change", "command": "display",
options: {page: "ojsm_status_list"} "options": redirect_options
});
}); });
}); });
}); });
......
...@@ -250,7 +250,7 @@ ...@@ -250,7 +250,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>963.29336.22296.43468</string> </value> <value> <string>963.37808.2626.47837</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -268,7 +268,7 @@ ...@@ -268,7 +268,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1510668189.54</float> <float>1511175451.34</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
...@@ -223,6 +223,7 @@ gadget_erp5_page_ojsm_synchronize.html\n ...@@ -223,6 +223,7 @@ gadget_erp5_page_ojsm_synchronize.html\n
gadget_erp5_page_ojsm_erp5_configurator.html\n gadget_erp5_page_ojsm_erp5_configurator.html\n
gadget_erp5_page_ojsm_jump.html\n gadget_erp5_page_ojsm_jump.html\n
gadget_officejs_monitoring_opml_edit.html\n gadget_officejs_monitoring_opml_edit.html\n
gadget_erp5_page_ojsm_dispatch.html\n
\n \n
# monitoring js\n # monitoring js\n
gadget_officejs_monitoring_jio.js\n gadget_officejs_monitoring_jio.js\n
...@@ -249,6 +250,7 @@ gadget_erp5_page_ojsm_synchronize.js\n ...@@ -249,6 +250,7 @@ gadget_erp5_page_ojsm_synchronize.js\n
gadget_erp5_page_ojsm_jump.js\n gadget_erp5_page_ojsm_jump.js\n
gadget_erp5_page_ojsm_erp5_configurator.js\n gadget_erp5_page_ojsm_erp5_configurator.js\n
gadget_officejs_monitoring_opml_edit.js\n gadget_officejs_monitoring_opml_edit.js\n
gadget_erp5_page_ojsm_dispatch.js\n
\n \n
# erp5_web_renderjs_ui\n # erp5_web_renderjs_ui\n
gadget_erp5_editor_panel.html\n gadget_erp5_editor_panel.html\n
...@@ -383,7 +385,7 @@ NETWORK:\n ...@@ -383,7 +385,7 @@ NETWORK:\n
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>963.33744.19919.32631</string> </value> <value> <string>963.40590.4483.37222</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -401,7 +403,7 @@ NETWORK:\n ...@@ -401,7 +403,7 @@ NETWORK:\n
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1510932931.68</float> <float>1511342469.81</float>
<string>UTC</string> <string>UTC</string>
</tuple> </tuple>
</state> </state>
......
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