Browse Source

Show progress when reconnecting to hastic datasource #412 (#417)

master
rozetko 5 years ago committed by GitHub
parent
commit
628748823d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      src/panel/graph_panel/graph_ctrl.ts
  2. 23
      src/panel/graph_panel/partials/reconnect_to_datasource.html
  3. 2
      src/panel/graph_panel/partials/tab_webhooks.html
  4. 26
      src/panel/graph_panel/services/analytic_service.ts

6
src/panel/graph_panel/graph_ctrl.ts

@ -9,7 +9,7 @@ import { MetricExpanded } from './models/metric';
import { DatasourceRequest } from './models/datasource'; import { DatasourceRequest } from './models/datasource';
import { AnalyticUnitId, AnalyticUnit, LabelingMode } from './models/analytic_units/analytic_unit'; import { AnalyticUnitId, AnalyticUnit, LabelingMode } from './models/analytic_units/analytic_unit';
import { BOUND_TYPES } from './models/analytic_units/anomaly_analytic_unit'; import { BOUND_TYPES } from './models/analytic_units/anomaly_analytic_unit';
import { AnalyticService } from './services/analytic_service'; import { AnalyticService, HasticDatasourceConnectionStatus } from './services/analytic_service';
import { AnalyticController } from './controllers/analytic_controller'; import { AnalyticController } from './controllers/analytic_controller';
import { HasticPanelInfo } from './models/hastic_panel_info'; import { HasticPanelInfo } from './models/hastic_panel_info';
import { PanelTemplate, TemplateVariables } from './models/panel'; import { PanelTemplate, TemplateVariables } from './models/panel';
@ -363,6 +363,10 @@ class GraphCtrl extends MetricsPanelCtrl {
this.refresh(); this.refresh();
} }
get connectionStatus(): HasticDatasourceConnectionStatus {
return this.analyticService.connectionStatus;
}
issueQueries(datasource) { issueQueries(datasource) {
// this.annotationsPromise = this.annotationsSrv.getAnnotations({ // this.annotationsPromise = this.annotationsSrv.getAnnotations({
// dashboard: this.dashboard, // dashboard: this.dashboard,

23
src/panel/graph_panel/partials/reconnect_to_datasource.html

@ -1,7 +1,20 @@
<div class="gf-form-button-row" ng-if="ctrl.hasticDatasource !== undefined && ctrl.analyticsController.serverStatus === false"> <div class="gf-form-button-row" ng-if="ctrl.hasticDatasource !== undefined && ctrl.analyticsController.serverStatus === false">
<h5>Hastic server at "{{ctrl.hasticDatasource.url}}" is not available</h5> <div class="gf-form-group">
<button class="btn btn-inverse" ng-click="ctrl.onHasticDatasourceChange()"> <div class="alert-{{ctrl.connectionStatus.status}} alert"">
<i class="fa fa-plug"></i> <div class="alert-icon">
Reconnect to Hastic server <i class="fa fa-spiner fa-spin" ng-show="ctrl.connectionStatus.status === 'info'"></i>
</button> <i class="fa fa-exclamation-triangle" ng-show="ctrl.connectionStatus.status === 'error'"></i>
<i class="fa fa-check" ng-show="ctrl.connectionStatus.status !== 'error'"></i>
</div>
<div class="alert-body">
<div class="alert-title" ng-bind-html="ctrl.connectionStatus.message" />
</div>
</div>
<div ng-hide="ctrl.connectionStatus.status === 'info'">
<button class="btn btn-secondary" ng-click="ctrl.onHasticDatasourceChange()">
<i class="fa fa-plug"></i>
&nbsp; Connect to Hastic Datasource
</button>
</div>
</div>
</div> </div>

2
src/panel/graph_panel/partials/tab_webhooks.html

@ -1,5 +1,3 @@
<ng-include src="ctrl.partialsPath + '/reconnect_to_datasource.html'" />
<div ng-if="ctrl.analyticsController.serverStatus === true"> <div ng-if="ctrl.analyticsController.serverStatus === true">
<div ng-if="!ctrl.analyticsController.analyticUnits.length"> <div ng-if="!ctrl.analyticsController.analyticUnits.length">
<h5> Please create at least 1 analytic unit to enable webhooks </h5> <h5> Please create at least 1 analytic unit to enable webhooks </h5>

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

@ -25,16 +25,22 @@ export type TableTimeSeries = {
}; };
export enum HasticDatasourceStatus { export enum HasticDatasourceStatus {
AVAILABLE, AVAILABLE = 'success',
NOT_AVAILABLE NOT_AVAILABLE = 'error',
CONNECTING = 'info'
}; };
const STATUS_TO_ALERT_TYPE_MAPPING = new Map<HasticDatasourceStatus, string>([ export type HasticDatasourceConnectionStatus = {
[HasticDatasourceStatus.AVAILABLE, 'alert-success'], status: HasticDatasourceStatus,
[HasticDatasourceStatus.NOT_AVAILABLE, 'alert-error'] message: string
]); }
export class AnalyticService { export class AnalyticService {
public connectionStatus: HasticDatasourceConnectionStatus = {
status: HasticDatasourceStatus.CONNECTING,
message: 'Connecting...'
};
private _isUp: boolean = false; private _isUp: boolean = false;
constructor( constructor(
@ -268,6 +274,9 @@ export class AnalyticService {
} }
async checkDatasourceAvailability(): Promise<boolean> { async checkDatasourceAvailability(): Promise<boolean> {
this.connectionStatus.status = HasticDatasourceStatus.CONNECTING;
this.connectionStatus.message = 'Connecting...';
this._isUp = await this._isDatasourceAvailable(); this._isUp = await this._isDatasourceAvailable();
return this._isUp; return this._isUp;
} }
@ -393,6 +402,9 @@ export class AnalyticService {
} }
private _displayConnectionAlert(status: HasticDatasourceStatus, message: string[]): void { private _displayConnectionAlert(status: HasticDatasourceStatus, message: string[]): void {
this.connectionStatus.status = status;
this.connectionStatus.message = message.join('<br />');
const statusChanged = this._updateHasticUrlStatus(status); const statusChanged = this._updateHasticUrlStatus(status);
if(!statusChanged) { if(!statusChanged) {
@ -400,7 +412,7 @@ export class AnalyticService {
} }
appEvents.emit( appEvents.emit(
STATUS_TO_ALERT_TYPE_MAPPING.get(status), `alert-${status}`,
message message
); );
} }

Loading…
Cancel
Save