Browse Source

Deleting any analytic unit only deletes the first one #33 (#36)

* change all AnalyticUnit key occurences to ids

* Fix map id index (use id instead of name)

* aid -> id
master
Alexey Velikiy 6 years ago committed by rozetko
parent
commit
0335fd40c0
  1. 34
      src/controllers/analytic_controller.ts
  2. 6
      src/models/analytic_unit.ts
  3. 18
      src/module.ts
  4. 12
      src/partials/tab_analytics.html

34
src/controllers/analytic_controller.ts

@ -28,7 +28,7 @@ export const REGION_DELETE_COLOR_DARK = 'white';
export class AnalyticController { export class AnalyticController {
private _analyticUnitsSet: AnalyticUnitsSet; private _analyticUnitsSet: AnalyticUnitsSet;
private _selectedAnalyticUnitKey: AnalyticUnitId = null; private _selectedAnalyticUnitId: AnalyticUnitId = null;
private _labelingDataAddedSegments: SegmentsSet<AnalyticSegment>; private _labelingDataAddedSegments: SegmentsSet<AnalyticSegment>;
private _labelingDataDeletedSegments: SegmentsSet<AnalyticSegment>; private _labelingDataDeletedSegments: SegmentsSet<AnalyticSegment>;
@ -97,27 +97,27 @@ export class AnalyticController {
set graphLocked(value) { this._graphLocked = value; } set graphLocked(value) { this._graphLocked = value; }
get labelingAnomaly(): AnalyticUnit { get labelingAnomaly(): AnalyticUnit {
if(this._selectedAnalyticUnitKey === null) { if(this._selectedAnalyticUnitId === null) {
return null; return null;
} }
return this._analyticUnitsSet.byId(this._selectedAnalyticUnitKey); return this._analyticUnitsSet.byId(this._selectedAnalyticUnitId);
} }
async toggleAnomalyTypeLabelingMode(key: AnalyticUnitId) { async toggleAnomalyTypeLabelingMode(id: AnalyticUnitId) {
if(this.labelingAnomaly && this.labelingAnomaly.saving) { if(this.labelingAnomaly && this.labelingAnomaly.saving) {
throw new Error('Can`t toggel during saving'); throw new Error('Can`t toggel during saving');
} }
if(this._selectedAnalyticUnitKey === key) { if(this._selectedAnalyticUnitId === id) {
return this.disableLabeling(); return this.disableLabeling();
} }
await this.disableLabeling(); await this.disableLabeling();
this._selectedAnalyticUnitKey = key; this._selectedAnalyticUnitId = id;
this.labelingAnomaly.selected = true; this.labelingAnomaly.selected = true;
this.toggleVisibility(key, true); this.toggleVisibility(id, true);
} }
async disableLabeling() { async disableLabeling() {
if(this._selectedAnalyticUnitKey === null) { if(this._selectedAnalyticUnitId === null) {
return; return;
} }
this.labelingAnomaly.saving = true; this.labelingAnomaly.saving = true;
@ -146,12 +146,12 @@ export class AnalyticController {
this._labelingDataAddedSegments.clear(); this._labelingDataAddedSegments.clear();
this._labelingDataDeletedSegments.clear(); this._labelingDataDeletedSegments.clear();
this.labelingAnomaly.selected = false; this.labelingAnomaly.selected = false;
this._selectedAnalyticUnitKey = null; this._selectedAnalyticUnitId = null;
this._tempIdCounted = -1; this._tempIdCounted = -1;
} }
get labelingMode(): boolean { get labelingMode(): boolean {
return this._selectedAnalyticUnitKey !== null; return this._selectedAnalyticUnitId !== null;
} }
get labelingDeleteMode(): boolean { get labelingDeleteMode(): boolean {
@ -170,8 +170,8 @@ export class AnalyticController {
return this._analyticUnitsSet.items; return this._analyticUnitsSet.items;
} }
onAnomalyColorChange(key: AnalyticUnitId, value) { onAnomalyColorChange(id: AnalyticUnitId, value) {
this._analyticUnitsSet.byId(key).color = value; this._analyticUnitsSet.byId(id).color = value;
} }
fetchAnomalyTypesStatuses() { fetchAnomalyTypesStatuses() {
@ -283,11 +283,11 @@ export class AnalyticController {
this.labelingAnomaly.deleteMode = !this.labelingAnomaly.deleteMode; this.labelingAnomaly.deleteMode = !this.labelingAnomaly.deleteMode;
} }
removeAnomalyType(key) { removeAnalyticUnit(id: AnalyticUnitId) {
if(key === this._selectedAnalyticUnitKey) { if(id === this._selectedAnalyticUnitId) {
this.dropLabeling(); this.dropLabeling();
} }
this._analyticUnitsSet.removeItem(key); this._analyticUnitsSet.removeItem(id);
} }
private async _runStatusWaiter(anomalyType: AnalyticUnit) { private async _runStatusWaiter(anomalyType: AnalyticUnit) {
@ -348,8 +348,8 @@ export class AnalyticController {
return this._tempIdCounted; return this._tempIdCounted;
} }
public toggleVisibility(key: AnalyticUnitId, value?: boolean) { public toggleVisibility(id: AnalyticUnitId, value?: boolean) {
var anomaly = this._analyticUnitsSet.byId(key); var anomaly = this._analyticUnitsSet.byId(id);
if(value !== undefined) { if(value !== undefined) {
anomaly.visible = value; anomaly.visible = value;
} else { } else {

6
src/models/analytic_unit.ts

@ -14,8 +14,8 @@ export type AnalyticSegmentsSearcher = (point: number, rangeDist: number) => Ana
export type AnalyticUnitId = string; export type AnalyticUnitId = string;
export class AnalyticSegment extends Segment { export class AnalyticSegment extends Segment {
constructor(public labeled: boolean, key: SegmentId, from: number, to: number) { constructor(public labeled: boolean, id: SegmentId, from: number, to: number) {
super(key, from, to); super(id, from, to);
if(!_.isBoolean(labeled)) { if(!_.isBoolean(labeled)) {
throw new Error('labeled value is not boolean'); throw new Error('labeled value is not boolean');
} }
@ -138,7 +138,7 @@ export class AnalyticUnitsSet {
addItem(item: AnalyticUnit) { addItem(item: AnalyticUnit) {
this._panelObject.push(item.panelObject); this._panelObject.push(item.panelObject);
this._mapIdIndex[item.name] = this._items.length; this._mapIdIndex[item.id] = this._items.length;
this._items.push(item); this._items.push(item);
} }

18
src/module.ts

@ -530,13 +530,19 @@ class GraphCtrl extends MetricsPanelCtrl {
this.render(this.seriesList); this.render(this.seriesList);
} }
onColorChange(key: AnalyticUnitId, value) { onColorChange(id: AnalyticUnitId, value) {
this.analyticsController.onAnomalyColorChange(key, value); if(id === undefined) {
throw new Error('id is undefined');
}
this.analyticsController.onAnomalyColorChange(id, value);
this.render(); this.render();
} }
onRemove(key) { onRemove(id: AnalyticUnitId) {
this.analyticsController.removeAnomalyType(key as string); if(id === undefined) {
throw new Error('id is undefined');
}
this.analyticsController.removeAnalyticUnit(id);
this.render(); this.render();
} }
@ -574,8 +580,8 @@ class GraphCtrl extends MetricsPanelCtrl {
this.analyticsController.toggleAlertEnabled(anomalyType); this.analyticsController.toggleAlertEnabled(anomalyType);
} }
onToggleVisibility(key: AnalyticUnitId) { onToggleVisibility(id: AnalyticUnitId) {
this.analyticsController.toggleVisibility(key); this.analyticsController.toggleVisibility(id);
this.render(); this.render();
} }

12
src/partials/tab_analytics.html

@ -31,13 +31,13 @@
<span class="gf-form-label"> <span class="gf-form-label">
<color-picker <color-picker
color="analyticUnit.color" color="analyticUnit.color"
onChange="ctrl.onAnomalyColorChange.bind(ctrl, analyticUnit.key)" onChange="ctrl.onAnomalyColorChange.bind(ctrl, analyticUnit.id)"
/> />
</span> </span>
<label class="gf-form-label" ng-style="analyticUnit.status === 'learning' && { 'cursor': 'not-allowed' }"> <label class="gf-form-label" ng-style="analyticUnit.status === 'learning' && { 'cursor': 'not-allowed' }">
<a class="pointer" tabindex="1" <a class="pointer" tabindex="1"
ng-click="ctrl.onToggleLabelingMode(analyticUnit.key)" ng-click="ctrl.onToggleLabelingMode(analyticUnit.id)"
ng-disabled="analyticUnit.status === 'learning'" ng-disabled="analyticUnit.status === 'learning'"
> >
<i class="fa fa-bar-chart" ng-if="!analyticUnit.saving"></i> <i class="fa fa-bar-chart" ng-if="!analyticUnit.saving"></i>
@ -71,7 +71,7 @@
ng-if="analyticUnit.visible" ng-if="analyticUnit.visible"
ng-disabled="analyticUnit.selected" ng-disabled="analyticUnit.selected"
bs-tooltip="'Hide. It`s visible now.'" bs-tooltip="'Hide. It`s visible now.'"
ng-click="ctrl.onToggleVisibility(analyticUnit.key)" ng-click="ctrl.onToggleVisibility(analyticUnit.id)"
class="pointer" class="pointer"
> >
<i class="fa fa-eye"></i> <i class="fa fa-eye"></i>
@ -81,7 +81,7 @@
ng-if="!analyticUnit.visible" ng-if="!analyticUnit.visible"
ng-disabled="analyticUnit.selected" ng-disabled="analyticUnit.selected"
bs-tooltip="'Show. It`s hidden now.'" bs-tooltip="'Show. It`s hidden now.'"
ng-click="ctrl.onToggleVisibility(analyticUnit.key)" ng-click="ctrl.onToggleVisibility(analyticUnit.id)"
class="pointer" class="pointer"
> >
<i class="fa fa-eye-slash"></i> <i class="fa fa-eye-slash"></i>
@ -91,7 +91,7 @@
<label class="gf-form-label"> <label class="gf-form-label">
<a <a
ng-if="!analyticUnit.selected" ng-if="!analyticUnit.selected"
ng-click="ctrl.onRemove(analyticUnit.key)" ng-click="ctrl.onRemove(analyticUnit.id)"
class="pointer" class="pointer"
> >
<i class="fa fa-trash"></i> <i class="fa fa-trash"></i>
@ -99,7 +99,7 @@
<a <a
ng-if="analyticUnit.selected" ng-if="analyticUnit.selected"
ng-click="ctrl.onCancelLabeling(analyticUnit.key)" ng-click="ctrl.onCancelLabeling(analyticUnit.id)"
class="pointer" class="pointer"
> >
<i class="fa fa-ban"></i> <i class="fa fa-ban"></i>

Loading…
Cancel
Save