Commit 666586b8 authored by Alain Takoudjou's avatar Alain Takoudjou Committed by Alain Takoudjou

[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 30679038
......@@ -5,25 +5,37 @@
<meta name="viewport" content="width=device-width" />
<title>ERP5 Page Monitoring Dispatch</title>
<link href="gadget_officejs_monitoring_custom.css" rel="stylesheet" type="text/css"/>
<!-- renderjs -->
<script src="rsvp.js" type="text/javascript"></script>
<script src="renderjs.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 id="dispatch-template" type="text/x-handlebars-template">
<section class="ui-content-header-plain">
<h3 class="ui-content-title ui-body-c" data-i18n="[last]{{definition_i18n}}">
<span class="ui-icon ui-icon-custom ui-icon-share">&nbsp;</span>
Monitoring Search
</h3>
</section>
<h1>{{item}}: Not found in monitor!</h1>
<h3 class="ui-content-title ui-body-c" data-i18n="No results from your search">
<span class="ui-icon ui-icon-custom ui-icon-frown-o">&nbsp;</span>
No results from your search!
</h3>
</script>
</head>
<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>
</html>
\ No newline at end of file
......@@ -242,7 +242,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>963.3574.26713.18039</string> </value>
<value> <string>963.33813.35232.64187</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -260,7 +260,7 @@
</tuple>
<state>
<tuple>
<float>1509121633.77</float>
<float>1510936342.8</float>
<string>UTC</string>
</tuple>
</state>
......
/*global window, rJS, Handlebars */
/*global window, rJS, RSVP, Handlebars */
/*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, Handlebars) {
(function (window, rJS, RSVP, Handlebars) {
"use strict";
var gadget_klass = rJS(window),
......@@ -9,6 +9,60 @@
.innerHTML,
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
/////////////////////////////////////////////////////////////////
......@@ -17,21 +71,113 @@
.declareAcquiredMethod("translateHtml", "translateHtml")
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("jio_allDocs", "jio_allDocs")
.declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("getSetting", "getSetting")
/////////////////////////////////////////////////////////////////
// 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) {
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];
}
} else {
portal_type = "promise";
}
return gadget.changeState({
original_query: original_query,
query: options.query,
page_title: page_title,
portal_type: portal_type
});
})
.onStateChange(function () {
var gadget = this;
gadget.element.innerHTML = dispatch_template({item: options.query || undefined});
return gadget.getUrlFor({command: 'display', options: {page: 'ojsm_status_list'}})
.push(function (url) {
return new RSVP.Queue()
.push(function () {
return gadget.getUrlFor({command: 'display', options: {page: 'ojsm_status_list'}});
})
.push(function (back_url) {
return gadget.updateHeader({
back_url: url,
page_title: "Jump to Object"
page_title: gadget.state.page_title,
back_url: back_url
});
})
.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});
}
});
});
}(window, rJS, Handlebars));
\ No newline at end of file
}, false, true);
}(window, rJS, RSVP, Handlebars));
\ No newline at end of file
......@@ -238,7 +238,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>963.29379.61141.36334</string> </value>
<value> <string>963.33811.1739.59187</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -256,7 +256,7 @@
</tuple>
<state>
<tuple>
<float>1510669689.61</float>
<float>1510935658.24</float>
<string>UTC</string>
</tuple>
</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