Browse Source

Missing statuses and updates on saving #230 (#234)

* Minor fixes

* Panels are not rendered without a refresh sometimes #223

* Add READY status icon

* Revert minor fix

* Minor fixes

* Send batch detect request

* Analytic unit status: undefined -> null

* Revert "Panels are not rendered without a refresh sometimes #223"
master
rozetko 6 years ago committed by Alexey Velikiy
parent
commit
f4a2beeaea
  1. 19
      src/panel/graph_panel/controllers/analytic_controller.ts
  2. 13
      src/panel/graph_panel/graph_ctrl.ts
  3. 3
      src/panel/graph_panel/models/analytic_unit.ts
  4. 1
      src/panel/graph_panel/partials/tab_analytics.html
  5. 11
      src/panel/graph_panel/services/analytic_service.ts

19
src/panel/graph_panel/controllers/analytic_controller.ts

@ -115,9 +115,6 @@ export class AnalyticController {
this._analyticUnitsSet.addItem(this._newAnalyticUnit);
this._creatingNewAnalyticType = false;
this._savingNewAnalyticUnit = false;
if(this._newAnalyticUnit.detectorType !== 'threshold') {
this._runStatusWaiter(this._newAnalyticUnit);
}
}
get creatingNew() { return this._creatingNewAnalyticType; }
@ -134,7 +131,7 @@ export class AnalyticController {
return this._analyticUnitsSet.byId(this._selectedAnalyticUnitId);
}
async toggleUnitTypeLabelingMode(id: AnalyticUnitId, metric: MetricExpanded, datasource: DatasourceRequest) {
async toggleAnalyticUnitLabelingMode(id: AnalyticUnitId, metric: MetricExpanded, datasource: DatasourceRequest) {
this._currentMetric = metric;
this._currentDatasource = datasource;
@ -148,7 +145,6 @@ export class AnalyticController {
this._selectedAnalyticUnitId = id;
this.labelingUnit.selected = true;
this.toggleLabelingMode(LabelingMode.LABELING);
this.toggleVisibility(id, true);
}
async disableLabeling() {
@ -277,12 +273,15 @@ export class AnalyticController {
return newIds;
}
redetectAll() {
this.analyticUnits.forEach(a => {
a.segments.clear();
this._runStatusWaiter(a);
this._analyticService.runDetect(a.id);
async redetectAll() {
this.analyticUnits.forEach(unit => {
unit.segments.clear();
unit.status = null;
});
const ids = this.analyticUnits.map(analyticUnit => analyticUnit.id);
await this._analyticService.runDetect(ids);
_.each(this.analyticUnits, analyticUnit => this._runStatusWaiter(analyticUnit));
}
// TODO: move to renderer

13
src/panel/graph_panel/graph_ctrl.ts

@ -161,7 +161,6 @@ class GraphCtrl extends MetricsPanelCtrl {
// because of https://github.com/hastic/hastic-grafana-app/issues/162
this.events.on('init-edit-mode', this.onInitEditMode.bind(this));
const grafanaUrlRegex = /^(.+)\/d/;
const parsedUrl = window.location.href.match(grafanaUrlRegex);
if(parsedUrl !== null) {
@ -171,6 +170,7 @@ class GraphCtrl extends MetricsPanelCtrl {
}
this._panelId = `${this.dashboard.uid}/${this.panel.id}`;
this._datasources = {};
}
rebindKeys() {
@ -201,6 +201,9 @@ class GraphCtrl extends MetricsPanelCtrl {
const hasticDatasourceId = this.panel.hasticDatasource;
if(hasticDatasourceId !== undefined && hasticDatasourceId !== null) {
const hasticDatasource = _.find(this._hasticDatasources, { id: hasticDatasourceId });
if(hasticDatasource === undefined) {
return undefined;
}
let url = hasticDatasource.url;
if(hasticDatasource.access === 'proxy') {
url = `api/datasources/proxy/${hasticDatasource.id}`;
@ -247,8 +250,6 @@ class GraphCtrl extends MetricsPanelCtrl {
}
async link(scope, elem, attrs, ctrl) {
this._datasources = {};
this.$graphElem = $(elem[0]).find('#graphPanel');
this.$legendElem = $(elem[0]).find('#graphLegend');
@ -314,7 +315,7 @@ class GraphCtrl extends MetricsPanelCtrl {
this.processor = new DataProcessor(this.panel);
await this._fetchHasticDatasources();
let hasticDatasource = this.hasticDatasource;
const hasticDatasource = this.getHasticDatasource();
if(hasticDatasource === undefined) {
delete this.analyticService;
} else {
@ -638,7 +639,7 @@ class GraphCtrl extends MetricsPanelCtrl {
this.refresh();
const datasource = await this._getDatasourceRequest();
const metric = new MetricExpanded(this.panel.datasource, this.panel.targets);
await this.analyticsController.toggleUnitTypeLabelingMode(id, metric, datasource);
await this.analyticsController.toggleAnalyticUnitLabelingMode(id, metric, datasource);
this.$scope.$digest();
this.render();
}
@ -681,7 +682,7 @@ class GraphCtrl extends MetricsPanelCtrl {
grafanaUrl: window.location.host,
datasourceName: datasource === undefined ? 'unknown' : datasource.name,
datasourceType: datasource === undefined ? 'unknown' : datasource.type,
hasticDatasourceName: datasource === undefined ? 'unknown' : hasticDatasource.name,
hasticDatasourceName: hasticDatasource === undefined || datasource === undefined ? 'unknown' : hasticDatasource.name,
hasticDatasourceUrl: hasticDatasource === undefined ? 'unknown' : hasticDatasource.url
};
}

3
src/panel/graph_panel/models/analytic_unit.ts

@ -120,7 +120,8 @@ export class AnalyticUnit {
value !== 'READY' &&
value !== 'LEARNING' &&
value !== 'PENDING' &&
value !== 'FAILED'
value !== 'FAILED' &&
value !== null
) {
throw new Error('Unsupported status value: ' + value);
}

1
src/panel/graph_panel/partials/tab_analytics.html

@ -159,6 +159,7 @@
</label>
<label>
<i ng-if="analyticUnit.status === 'READY'" class="grafana-tip fa fa-check-circle ng-scope" bs-tooltip="'Ready'"></i>
<i ng-if="analyticUnit.status === 'LEARNING'" class="grafana-tip fa fa-leanpub ng-scope" bs-tooltip="'Learning'"></i>
<i ng-if="analyticUnit.status === 'PENDING'" class="grafana-tip fa fa-list-ul ng-scope" bs-tooltip="'Pending'"></i>
<i ng-if="analyticUnit.status === 'FAILED'" class="grafana-tip fa fa-exclamation-circle ng-scope" bs-tooltip="'Error: ' + analyticUnit.error"></i>

11
src/panel/graph_panel/services/analytic_service.ts

@ -10,6 +10,7 @@ import { isHasticServerResponse, isSupportedServerVersion, SUPPORTED_SERVER_VERS
import { appEvents } from 'grafana/app/core/core';
import * as _ from 'lodash';
export class AnalyticService {
@ -96,8 +97,7 @@ export class AnalyticService {
if(!isHasticServerResponse(response)) {
this.displayWrongUrlAlert();
this._isUp = false;
}
if(!isSupportedServerVersion(response)) {
} else if(!isSupportedServerVersion(response)) {
this.displayUnsupportedVersionAlert(response.packageVersion);
this._isUp = false;
}
@ -203,8 +203,11 @@ export class AnalyticService {
return this.patch('/analyticUnits', updateObj);
}
async runDetect(id: AnalyticUnitId) {
return this.post('/analyticUnits/detect', { id });
async runDetect(ids: AnalyticUnitId | AnalyticUnitId[]) {
if(!_.isArray(ids)) {
ids = [ids];
}
return this.post('/analyticUnits/detect', { ids });
}
private async _analyticRequest(method: string, url: string, data?: any) {

Loading…
Cancel
Save