Skip to content

Commit

Permalink
Missing statuses and updates on saving #230 (#234)
Browse files Browse the repository at this point in the history
* 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"
  • Loading branch information
rozetko authored and jonyrock committed Apr 5, 2019
1 parent 28ae0ec commit f4a2bee
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 21 deletions.
19 changes: 9 additions & 10 deletions src/panel/graph_panel/controllers/analytic_controller.ts
Expand Up @@ -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; }
Expand All @@ -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;

Expand All @@ -148,7 +145,6 @@ export class AnalyticController {
this._selectedAnalyticUnitId = id;
this.labelingUnit.selected = true;
this.toggleLabelingMode(LabelingMode.LABELING);
this.toggleVisibility(id, true);
}

async disableLabeling() {
Expand Down Expand Up @@ -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
Expand Down
13 changes: 7 additions & 6 deletions src/panel/graph_panel/graph_ctrl.ts
Expand Up @@ -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) {
Expand All @@ -171,6 +170,7 @@ class GraphCtrl extends MetricsPanelCtrl {
}

this._panelId = `${this.dashboard.uid}/${this.panel.id}`;
this._datasources = {};
}

rebindKeys() {
Expand Down Expand Up @@ -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}`;
Expand Down Expand Up @@ -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');

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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
};
}
Expand Down
3 changes: 2 additions & 1 deletion src/panel/graph_panel/models/analytic_unit.ts
Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions src/panel/graph_panel/partials/tab_analytics.html
Expand Up @@ -159,6 +159,7 @@ <h5> Analytic Units </h5>
</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>
Expand Down
11 changes: 7 additions & 4 deletions src/panel/graph_panel/services/analytic_service.ts
Expand Up @@ -10,6 +10,7 @@ import { isHasticServerResponse, isSupportedServerVersion, SUPPORTED_SERVER_VERS

import { appEvents } from 'grafana/app/core/core';

import * as _ from 'lodash';


export class AnalyticService {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit f4a2bee

Please sign in to comment.