mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 17:02:41 +01:00
5aae1ee034
Summary: Ref T4986. Instead of requiring you to know engine class names and copy/paste URLs, provide select dropdowns that use SCARY JAVASCRIPT to do magical things. I think this is mostly reasonable, the only issue is that it's hard to create a panel out of a completely ad-hoc query (you'd have to save it, then create a panel out of the saved query, then remove the saved query). Once we develop T5307 we can do a better job of this. Test Plan: See screenshots. Reviewers: chad Reviewed By: chad Subscribers: epriestley Maniphest Tasks: T4986 Differential Revision: https://secure.phabricator.com/D9572
64 lines
1.8 KiB
JavaScript
64 lines
1.8 KiB
JavaScript
/**
|
|
* @provides javelin-behavior-dashboard-query-panel-select
|
|
* @requires javelin-behavior
|
|
* javelin-dom
|
|
*/
|
|
|
|
/**
|
|
* When editing a "Query" panel on dashboards, make the "Query" selector control
|
|
* dynamically update in response to changes to the "Engine" selector control.
|
|
*/
|
|
JX.behavior('dashboard-query-panel-select', function(config) {
|
|
|
|
var app_control = JX.$(config.applicationID);
|
|
var query_control = JX.$(config.queryID);
|
|
|
|
// If we have a currently-selected query, add it to the appropriate group
|
|
// in the options list if it does not already exist.
|
|
if (config.value.key !== null) {
|
|
var app = app_control.value;
|
|
if (!(app in config.options)) {
|
|
config.options[app] = [];
|
|
}
|
|
|
|
var found = false;
|
|
for (var ii = 0; ii < config.options[app].length; ii++) {
|
|
if (config.options[app][ii].key == config.value.key) {
|
|
found = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!found) {
|
|
config.options[app] = [config.value].concat(config.options[app]);
|
|
}
|
|
}
|
|
|
|
// When the user changes the selected search engine, update the query
|
|
// control to show avialable queries for that engine.
|
|
function update() {
|
|
var app = app_control.value;
|
|
|
|
var old_value = query_control.value;
|
|
var new_value = null;
|
|
|
|
var options = config.options[app] || [];
|
|
var nodes = [];
|
|
for (var ii = 0; ii < options.length; ii++) {
|
|
if (new_value === null) {
|
|
new_value = options[ii].key;
|
|
}
|
|
if (options[ii].key == old_value) {
|
|
new_value = options[ii].key;
|
|
}
|
|
nodes.push(JX.$N('option', {value: options[ii].key}, options[ii].name));
|
|
}
|
|
|
|
JX.DOM.setContent(query_control, nodes);
|
|
query_control.value = new_value;
|
|
}
|
|
|
|
JX.DOM.listen(app_control, 'change', null, function(e) { update(); });
|
|
update();
|
|
|
|
});
|