add auto refresh interval to insights (#1173)

This commit is contained in:
Anthony Dresser
2018-04-19 11:10:44 -07:00
committed by GitHub
parent 4b454581fd
commit 60ccae48f1
3 changed files with 22 additions and 0 deletions

View File

@@ -27,6 +27,7 @@ import * as pfs from 'vs/base/node/pfs';
import * as nls from 'vs/nls';
import { Registry } from 'vs/platform/registry/common/platform';
import { WorkbenchState } from 'vs/platform/workspace/common/workspace';
import { IntervalTimer } from 'vs/base/common/async';
const insightRegistry = Registry.as<IInsightRegistry>(Extensions.InsightContribution);
@@ -52,6 +53,7 @@ export class InsightsWidget extends DashboardWidget implements IDashboardWidget,
private _typeKey: string;
private _init: boolean = false;
private _intervalTimer: IntervalTimer;
public error: string;
public lastUpdated: string;
@@ -76,6 +78,7 @@ export class InsightsWidget extends DashboardWidget implements IDashboardWidget,
result => {
if (this._init) {
this._updateChild(result);
this.setupInterval();
} else {
this.queryObv = Observable.fromPromise(Promise.resolve<SimpleExecuteResult>(result));
}
@@ -100,6 +103,7 @@ export class InsightsWidget extends DashboardWidget implements IDashboardWidget,
this._register(toDisposableSubscription(this.queryObv.subscribe(
result => {
this._updateChild(result);
this.setupInterval();
},
error => {
this.showError(error);
@@ -108,6 +112,14 @@ export class InsightsWidget extends DashboardWidget implements IDashboardWidget,
}
}
private setupInterval(): void {
if (this.insightConfig.autoRefreshInterval) {
this._intervalTimer = new IntervalTimer();
this._register(this._intervalTimer);
this._intervalTimer.cancelAndSet(() => this.refresh(), this.insightConfig.autoRefreshInterval * 60 * 1000);
}
}
private showError(error: string): void {
this.error = error;
this._cd.detectChanges();
@@ -152,6 +164,7 @@ export class InsightsWidget extends DashboardWidget implements IDashboardWidget,
this.lastUpdated = nls.localize('insights.lastUpdated', "Last Updated: {0} {1}", date.toLocaleTimeString(), date.toLocaleDateString());
if (this._init) {
this._updateChild(storedResult.results);
this.setupInterval();
this._cd.detectChanges();
} else {
this.queryObv = Observable.fromPromise(Promise.resolve<SimpleExecuteResult>(JSON.parse(storage)));
@@ -231,6 +244,10 @@ export class InsightsWidget extends DashboardWidget implements IDashboardWidget,
throw new Error('No query was specified for this insight');
}
if (this.insightConfig.autoRefreshInterval && !types.isNumber(this.insightConfig.autoRefreshInterval)) {
throw new Error('Auto Refresh Interval must be a number if specified');
}
if (!types.isStringArray(this.insightConfig.query)
&& !types.isString(this.insightConfig.query)
&& !types.isString(this.insightConfig.queryFile)) {

View File

@@ -32,6 +32,10 @@ export const insightsSchema: IJSONSchema = {
type: 'string',
description: nls.localize('insightQueryFileDescription', '[Optional] path to a file that contains a query. Use if "query" is not set')
},
autoRefreshInterval: {
type: 'number',
description: nls.localize('insightAutoRefreshIntervalDescription', '[Optional] Auto refresh interval in minutes, if not set, there will be no auto refresh')
},
details: {
type: 'object',
properties: {

View File

@@ -56,4 +56,5 @@ export interface IInsightsConfig {
query?: string | Array<string>;
queryFile?: string;
details?: IInsightsConfigDetails;
autoRefreshInterval?: number;
}