rozetko 5 years ago
parent
commit
dff23a4649
  1. 6
      src/panel/graph_panel/graph_ctrl.ts
  2. 12
      src/panel/graph_panel/partials/reconnect_to_datasource.html
  3. 34
      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, HasticDatasourceStatus } from './services/analytic_service'; import { AnalyticService, HasticDatasourceTestingStatus } 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';
@ -353,8 +353,8 @@ class GraphCtrl extends MetricsPanelCtrl {
this.refresh(); this.refresh();
} }
get hasticDatasourceStatus(): HasticDatasourceStatus { get testingStatus(): HasticDatasourceTestingStatus {
return this.analyticService.hasticDatasourceStatus; return this.analyticService.testingStatus;
} }
issueQueries(datasource) { issueQueries(datasource) {

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

@ -1,16 +1,16 @@
<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">
<div class="gf-form-group"> <div class="gf-form-group">
<div class="alert-{{ctrl.hasticDatasourceStatus.status}} alert""> <div class="alert-{{ctrl.testingStatus.status}} alert"">
<div class="alert-icon"> <div class="alert-icon">
<i class="fa fa-spiner fa-spin" ng-show="ctrl.hasticDatasourceStatus.testing"></i> <i class="fa fa-spiner fa-spin" ng-show="ctrl.testingStatus.testing"></i>
<i class="fa fa-exclamation-triangle" ng-show="ctrl.hasticDatasourceStatus.status === 'error'"></i> <i class="fa fa-exclamation-triangle" ng-show="ctrl.testingStatus.status === 'error'"></i>
<i class="fa fa-check" ng-show="ctrl.hasticDatasourceStatus.status !== 'error'"></i> <i class="fa fa-check" ng-show="ctrl.testingStatus.status !== 'error'"></i>
</div> </div>
<div class="alert-body"> <div class="alert-body">
<div class="alert-title" ng-bind-html="ctrl.hasticDatasourceStatus.message" /> <div class="alert-title" ng-bind-html="ctrl.testingStatus.message" />
</div> </div>
</div> </div>
<div ng-hide="ctrl.hasticDatasourceStatus.testing"> <div ng-hide="ctrl.testingStatus.testing">
<button class="btn btn-secondary" ng-click="ctrl.onHasticDatasourceChange()"> <button class="btn btn-secondary" ng-click="ctrl.onHasticDatasourceChange()">
<i class="fa fa-plug"></i> <i class="fa fa-plug"></i>
&nbsp; Connect to Hastic Datasource &nbsp; Connect to Hastic Datasource

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

@ -15,7 +15,7 @@ import * as _ from 'lodash';
declare global { declare global {
interface Window { hasticDatasourcesAvailability: { [key: string]: HasticDatasourceAvailability } } interface Window { hasticDatasourcesAvailability: { [key: string]: HasticDatasourceStatus } }
} }
// TODO: TableTimeSeries is bad name // TODO: TableTimeSeries is bad name
@ -24,21 +24,21 @@ export type TableTimeSeries = {
columns: string[]; columns: string[];
}; };
export enum HasticDatasourceAvailability { export enum HasticDatasourceStatus {
AVAILABLE = 'success', AVAILABLE = 'success',
NOT_AVAILABLE = 'error' NOT_AVAILABLE = 'error'
}; };
export type HasticDatasourceStatus = { export type HasticDatasourceTestingStatus = {
testing: boolean, testing: boolean,
availability: HasticDatasourceAvailability, status: HasticDatasourceStatus,
message: string message: string
} }
export class AnalyticService { export class AnalyticService {
public hasticDatasourceStatus: HasticDatasourceStatus = { public testingStatus: HasticDatasourceTestingStatus = {
testing: false, testing: false,
availability: HasticDatasourceAvailability.NOT_AVAILABLE, status: HasticDatasourceStatus.NOT_AVAILABLE,
message: '' message: ''
}; };
@ -137,7 +137,7 @@ export class AnalyticService {
'Connected to Hastic Datasource', 'Connected to Hastic Datasource',
`Hastic datasource URL: "${this._hasticDatasourceURL}"` `Hastic datasource URL: "${this._hasticDatasourceURL}"`
]; ];
this._displayConnectionAlert(HasticDatasourceAvailability.AVAILABLE, message); this._displayConnectionAlert(HasticDatasourceStatus.AVAILABLE, message);
return true; return true;
} catch(e) { } catch(e) {
@ -274,11 +274,11 @@ export class AnalyticService {
} }
async checkDatasourceAvailability(): Promise<boolean> { async checkDatasourceAvailability(): Promise<boolean> {
this.hasticDatasourceStatus.testing = true; this.testingStatus.testing = true;
this._isUp = await this._isDatasourceAvailable(); this._isUp = await this._isDatasourceAvailable();
this.hasticDatasourceStatus.testing = false; this.testingStatus.testing = false;
return this._isUp; return this._isUp;
} }
@ -368,7 +368,7 @@ export class AnalyticService {
`No connection to Hastic Server. Status: ${statusText}`, `No connection to Hastic Server. Status: ${statusText}`,
`Hastic Datasource URL: "${this._hasticDatasourceURL}"`, `Hastic Datasource URL: "${this._hasticDatasourceURL}"`,
] ]
this._displayConnectionAlert(HasticDatasourceAvailability.NOT_AVAILABLE, message); this._displayConnectionAlert(HasticDatasourceStatus.NOT_AVAILABLE, message);
} }
private _displayConnectionTimeoutAlert(statusText: string): void { private _displayConnectionTimeoutAlert(statusText: string): void {
@ -376,7 +376,7 @@ export class AnalyticService {
`Timeout when connecting to Hastic Server. Status: ${statusText}`, `Timeout when connecting to Hastic Server. Status: ${statusText}`,
`Hastic Datasource URL: "${this._hasticDatasourceURL}"`, `Hastic Datasource URL: "${this._hasticDatasourceURL}"`,
] ]
this._displayConnectionAlert(HasticDatasourceAvailability.NOT_AVAILABLE, message); this._displayConnectionAlert(HasticDatasourceStatus.NOT_AVAILABLE, message);
} }
private displayWrongUrlAlert(): void { private displayWrongUrlAlert(): void {
@ -384,7 +384,7 @@ export class AnalyticService {
'Please check Hastic Server URL', 'Please check Hastic Server URL',
`Something is working at "${this._hasticDatasourceURL}" but it's not Hastic Server`, `Something is working at "${this._hasticDatasourceURL}" but it's not Hastic Server`,
] ]
this._displayConnectionAlert(HasticDatasourceAvailability.NOT_AVAILABLE, message); this._displayConnectionAlert(HasticDatasourceStatus.NOT_AVAILABLE, message);
} }
private displayUnsupportedVersionAlert(actual: string): void { private displayUnsupportedVersionAlert(actual: string): void {
@ -392,16 +392,16 @@ export class AnalyticService {
'Unsupported Hastic Server version', 'Unsupported Hastic Server version',
`Hastic Server at "${this._hasticDatasourceURL}" has unsupported version (got ${actual}, should be ${SUPPORTED_SERVER_VERSION})`, `Hastic Server at "${this._hasticDatasourceURL}" has unsupported version (got ${actual}, should be ${SUPPORTED_SERVER_VERSION})`,
] ]
this._displayConnectionAlert(HasticDatasourceAvailability.NOT_AVAILABLE, message); this._displayConnectionAlert(HasticDatasourceStatus.NOT_AVAILABLE, message);
} }
public get isUp(): boolean { public get isUp(): boolean {
return this._isUp; return this._isUp;
} }
private _displayConnectionAlert(status: HasticDatasourceAvailability, message: string[]): void { private _displayConnectionAlert(status: HasticDatasourceStatus, message: string[]): void {
this.hasticDatasourceStatus.availability = status; this.testingStatus.status = status;
this.hasticDatasourceStatus.message = message.join('<br /> '); this.testingStatus.message = message.join('<br /> ');
const statusChanged = this._updateHasticUrlStatus(status); const statusChanged = this._updateHasticUrlStatus(status);
@ -419,7 +419,7 @@ export class AnalyticService {
* Updates hastic datasource status * Updates hastic datasource status
* @returns true if status has been changed * @returns true if status has been changed
*/ */
private _updateHasticUrlStatus(status: HasticDatasourceAvailability): boolean { private _updateHasticUrlStatus(status: HasticDatasourceStatus): boolean {
if(!window.hasOwnProperty('hasticDatasourcesAvailability')) { if(!window.hasOwnProperty('hasticDatasourcesAvailability')) {
window.hasticDatasourcesAvailability = {}; window.hasticDatasourcesAvailability = {};
} }

Loading…
Cancel
Save