2017-11-13 19:05:39 +00:00
|
|
|
import * as _ from 'underscore';
|
2016-11-04 17:15:09 +00:00
|
|
|
import template from './widget.html';
|
|
|
|
import editTextBoxTemplate from './edit-text-box.html';
|
2017-11-07 08:41:29 +00:00
|
|
|
import './widget.less';
|
2016-11-04 17:15:09 +00:00
|
|
|
|
|
|
|
const EditTextBoxComponent = {
|
|
|
|
template: editTextBoxTemplate,
|
|
|
|
bindings: {
|
|
|
|
resolve: '<',
|
|
|
|
close: '&',
|
|
|
|
dismiss: '&',
|
|
|
|
},
|
|
|
|
controller(toastr) {
|
2017-03-20 15:41:52 +00:00
|
|
|
'ngInject';
|
|
|
|
|
2016-11-04 17:15:09 +00:00
|
|
|
this.saveInProgress = false;
|
|
|
|
this.widget = this.resolve.widget;
|
|
|
|
this.saveWidget = () => {
|
|
|
|
this.saveInProgress = true;
|
2017-08-12 02:17:30 +00:00
|
|
|
if (this.widget.new_text !== this.widget.existing_text) {
|
|
|
|
this.widget.text = this.widget.new_text;
|
|
|
|
this.widget.$save().then(() => {
|
|
|
|
this.close();
|
|
|
|
}).catch(() => {
|
|
|
|
toastr.error('Widget can not be updated');
|
|
|
|
}).finally(() => {
|
|
|
|
this.saveInProgress = false;
|
|
|
|
});
|
|
|
|
} else {
|
2016-11-04 17:15:09 +00:00
|
|
|
this.close();
|
2017-08-12 02:17:30 +00:00
|
|
|
}
|
2016-11-04 17:15:09 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2017-01-10 16:52:03 +00:00
|
|
|
function DashboardWidgetCtrl($location, $uibModal, $window, Events, currentUser) {
|
2016-11-04 17:15:09 +00:00
|
|
|
this.canViewQuery = currentUser.hasPermission('view_query');
|
|
|
|
|
|
|
|
this.editTextBox = () => {
|
2017-07-27 04:15:22 +00:00
|
|
|
this.widget.existing_text = this.widget.text;
|
2017-08-12 02:17:30 +00:00
|
|
|
this.widget.new_text = this.widget.text;
|
2016-11-04 17:15:09 +00:00
|
|
|
$uibModal.open({
|
|
|
|
component: 'editTextBox',
|
|
|
|
resolve: {
|
|
|
|
widget: this.widget,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-11-13 19:05:39 +00:00
|
|
|
this.getWidgetStyles = () => {
|
|
|
|
if (_.isObject(this.widget) && _.isObject(this.widget.visualization)) {
|
|
|
|
const visualization = this.widget.visualization;
|
|
|
|
if (visualization.type === 'PIVOT') {
|
|
|
|
return { overflow: 'visible' };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-01-26 18:56:12 +00:00
|
|
|
this.localParametersDefs = () => {
|
|
|
|
if (!this.localParameters) {
|
2017-10-29 10:03:59 +00:00
|
|
|
this.localParameters = this.widget.getQuery().getParametersDefs().filter(p => !p.global);
|
2017-01-26 18:56:12 +00:00
|
|
|
}
|
|
|
|
return this.localParameters;
|
|
|
|
};
|
|
|
|
|
2016-11-04 17:15:09 +00:00
|
|
|
this.deleteWidget = () => {
|
|
|
|
if (!$window.confirm(`Are you sure you want to remove "${this.widget.getName()}" from the dashboard?`)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-11-23 15:58:00 +00:00
|
|
|
Events.record('delete', 'widget', this.widget.id);
|
2016-11-04 17:15:09 +00:00
|
|
|
|
|
|
|
this.widget.$delete((response) => {
|
2017-10-29 10:03:59 +00:00
|
|
|
this.dashboard.widgets = this.dashboard.widgets.filter(widget => widget.id !== undefined);
|
2016-11-20 11:51:01 +00:00
|
|
|
this.dashboard.version = response.version;
|
2017-01-10 16:25:32 +00:00
|
|
|
if (this.deleted) {
|
|
|
|
this.deleted({});
|
|
|
|
}
|
2016-11-04 17:15:09 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2016-11-23 15:58:00 +00:00
|
|
|
Events.record('view', 'widget', this.widget.id);
|
2016-11-04 17:15:09 +00:00
|
|
|
|
|
|
|
this.reload = (force) => {
|
|
|
|
let maxAge = $location.search().maxAge;
|
|
|
|
if (force) {
|
|
|
|
maxAge = 0;
|
|
|
|
}
|
|
|
|
this.queryResult = this.query.getQueryResult(maxAge);
|
|
|
|
};
|
|
|
|
|
|
|
|
if (this.widget.visualization) {
|
2017-08-06 18:02:11 +00:00
|
|
|
Events.record('view', 'query', this.widget.visualization.query.id, { dashboard: true });
|
|
|
|
Events.record('view', 'visualization', this.widget.visualization.id, { dashboard: true });
|
2016-11-04 17:15:09 +00:00
|
|
|
|
|
|
|
this.query = this.widget.getQuery();
|
|
|
|
this.reload(false);
|
|
|
|
|
|
|
|
this.type = 'visualization';
|
|
|
|
} else if (this.widget.restricted) {
|
|
|
|
this.type = 'restricted';
|
|
|
|
} else {
|
|
|
|
this.type = 'textbox';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-03 17:21:36 +00:00
|
|
|
export default function init(ngModule) {
|
2016-11-04 17:15:09 +00:00
|
|
|
ngModule.component('editTextBox', EditTextBoxComponent);
|
|
|
|
ngModule.component('dashboardWidget', {
|
|
|
|
template,
|
|
|
|
controller: DashboardWidgetCtrl,
|
|
|
|
bindings: {
|
|
|
|
widget: '<',
|
2016-11-24 15:42:56 +00:00
|
|
|
public: '<',
|
2016-11-04 17:15:09 +00:00
|
|
|
dashboard: '<',
|
2017-01-10 16:25:32 +00:00
|
|
|
deleted: '&onDelete',
|
2016-11-04 17:15:09 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|