Browse Source

Fix analytic units fetching (#221)

- Show preloader while fetching analytic units from server #219
- Fetch analytic units' statuses on load #220
master
rozetko 6 years ago committed by GitHub
parent
commit
2bbb40f75c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      src/panel/graph_panel/controllers/analytic_controller.ts
  2. 12
      src/panel/graph_panel/partials/tab_analytics.html

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

@ -47,6 +47,7 @@ export class AnalyticController {
private _currentMetric: MetricExpanded; private _currentMetric: MetricExpanded;
private _currentDatasource: DatasourceRequest; private _currentDatasource: DatasourceRequest;
private _thresholds: Threshold[]; private _thresholds: Threshold[];
private _loading = true;
constructor( constructor(
private _grafanaUrl: string, private _grafanaUrl: string,
@ -65,6 +66,10 @@ export class AnalyticController {
get helpSectionText() { return text; } get helpSectionText() { return text; }
get loading() {
return this._loading;
}
getSegmentsSearcher(): AnalyticSegmentsSearcher { getSegmentsSearcher(): AnalyticSegmentsSearcher {
return this._segmentsSearcher.bind(this); return this._segmentsSearcher.bind(this);
} }
@ -90,7 +95,7 @@ export class AnalyticController {
this._newAnalyticUnit = new AnalyticUnit(); this._newAnalyticUnit = new AnalyticUnit();
this._creatingNewAnalyticType = true; this._creatingNewAnalyticType = true;
this._savingNewAnalyticUnit = false; this._savingNewAnalyticUnit = false;
if (this.analyticUnits.length === 0) { if(this.analyticUnits.length === 0) {
this._newAnalyticUnit.labeledColor = ANALYTIC_UNIT_COLORS[0]; this._newAnalyticUnit.labeledColor = ANALYTIC_UNIT_COLORS[0];
} else { } else {
let colorIndex = ANALYTIC_UNIT_COLORS.indexOf(_.last(this.analyticUnits).labeledColor) + 1; let colorIndex = ANALYTIC_UNIT_COLORS.indexOf(_.last(this.analyticUnits).labeledColor) + 1;
@ -229,7 +234,7 @@ export class AnalyticController {
if(!_.isNumber(+to)) { if(!_.isNumber(+to)) {
throw new Error('to isn`t number'); throw new Error('to isn`t number');
} }
var tasks = this.analyticUnits.map(a => this.fetchSegments(a, from, to)); const tasks = this.analyticUnits.map(a => this.fetchSegments(a, from, to));
return Promise.all(tasks); return Promise.all(tasks);
} }
@ -286,7 +291,7 @@ export class AnalyticController {
options.markings = []; options.markings = [];
} }
for(var i = 0; i < this.analyticUnits.length; i++) { for(let i = 0; i < this.analyticUnits.length; i++) {
const analyticUnit = this.analyticUnits[i]; const analyticUnit = this.analyticUnits[i];
if(!analyticUnit.visible) { if(!analyticUnit.visible) {
continue; continue;
@ -401,6 +406,8 @@ export class AnalyticController {
async fetchAnalyticUnits(): Promise<void> { async fetchAnalyticUnits(): Promise<void> {
const units = await this.getAnalyticUnits(); const units = await this.getAnalyticUnits();
this._analyticUnitsSet = new AnalyticUnitsSet(units); this._analyticUnitsSet = new AnalyticUnitsSet(units);
this._loading = false;
this.fetchAnalyticUnitsStatuses();
} }
async updateThresholds(): Promise<void> { async updateThresholds(): Promise<void> {

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

@ -18,7 +18,7 @@
</button> </button>
</div> </div>
<div ng-if="ctrl.analyticsController.serverStatus === true"> <div ng-if="ctrl.analyticsController.serverStatus === true && !ctrl.analyticsController.loading">
<h5> Analytic Units </h5> <h5> Analytic Units </h5>
<div class="editor-row"> <div class="editor-row">
<div class="gf-form" ng-repeat="analyticUnit in ctrl.analyticsController.analyticUnits"> <div class="gf-form" ng-repeat="analyticUnit in ctrl.analyticsController.analyticUnits">
@ -88,7 +88,7 @@
<select class="gf-form-input width-12" <select class="gf-form-input width-12"
ng-model="ctrl.analyticsController.labelingMode" ng-model="ctrl.analyticsController.labelingMode"
ng-options="type.value as type.name for type in [ ng-options="type.value as type.name for type in [
{ name:'Label Positive', value: 'LABELING' }, { name:'Label Positive', value: 'LABELING' },
{ name:'Label Negative', value: 'DELETING' }, { name:'Label Negative', value: 'DELETING' },
{ name:'Unlabel', value: 'UNLABELING' } { name:'Unlabel', value: 'UNLABELING' }
]" ]"
@ -222,8 +222,12 @@
<i class="fa fa-caret-right" ng-hide="ctrl.showHelp"></i> <i class="fa fa-caret-right" ng-hide="ctrl.showHelp"></i>
</button> </button>
</div> </div>
<div class="gf-form" ng-show="ctrl.showHelp" ng-bind-html="ctrl.analyticsController.helpSectionText"></div>
</div> </div>
</div>
<div class="gf-form" ng-show="ctrl.showHelp" ng-bind-html="ctrl.analyticsController.helpSectionText"></div> <div ng-if="ctrl.analyticsController.serverStatus === true && ctrl.analyticsController.loading">
<i class="fa fa-spinner fa-spin" /> Fetching analytic units...
</div>
</div>

Loading…
Cancel
Save