control the auto refresh state (#6577)

* control the auto refresh state

* visual indicator when autorefresh is off
This commit is contained in:
Alan Ren
2019-08-16 16:36:03 -07:00
committed by GitHub
parent bae87a0a24
commit 076aa51524
3 changed files with 40 additions and 4 deletions

View File

@@ -25,6 +25,7 @@ export interface IInsightsConfig {
queryFile?: string; queryFile?: string;
details?: IInsightsConfigDetails; details?: IInsightsConfigDetails;
autoRefreshInterval?: number; autoRefreshInterval?: number;
id?: string;
} }
export interface IInsightsLabel { export interface IInsightsLabel {
@@ -124,3 +125,14 @@ platform.Registry.add(Extensions.InsightContribution, insightRegistry);
export function registerInsight(id: string, description: string, schema: IJSONSchema, ctor: Type<IInsightsView>): InsightIdentifier { export function registerInsight(id: string, description: string, schema: IJSONSchema, ctor: Type<IInsightsView>): InsightIdentifier {
return insightRegistry.registerInsight(id, description, schema, ctor); return insightRegistry.registerInsight(id, description, schema, ctor);
} }
const WidgetAutoRefreshState: { [key: string]: boolean } = {};
export function getWidgetAutoRefreshState(widgetId: string, connectionId: string): boolean {
const key = widgetId + connectionId;
return Object.keys(WidgetAutoRefreshState).indexOf(key) === -1 || WidgetAutoRefreshState[key];
}
export function setWidgetAutoRefreshState(widgetId: string, connectionId: string, state: boolean): void {
WidgetAutoRefreshState[widgetId + connectionId] = state;
}

View File

@@ -13,7 +13,7 @@ import { DashboardWidget, IDashboardWidget, WIDGET_CONFIG, WidgetConfig } from '
import { CommonServiceInterface } from 'sql/platform/bootstrap/browser/commonServiceInterface.service'; import { CommonServiceInterface } from 'sql/platform/bootstrap/browser/commonServiceInterface.service';
import { ComponentHostDirective } from 'sql/workbench/parts/dashboard/browser/core/componentHost.directive'; import { ComponentHostDirective } from 'sql/workbench/parts/dashboard/browser/core/componentHost.directive';
import { InsightAction, InsightActionContext } from 'sql/workbench/common/actions'; import { InsightAction, InsightActionContext } from 'sql/workbench/common/actions';
import { Extensions, IInsightRegistry, IInsightsConfig, IInsightsView } from 'sql/platform/dashboard/browser/insightRegistry'; import { Extensions, IInsightRegistry, IInsightsConfig, IInsightsView, getWidgetAutoRefreshState } from 'sql/platform/dashboard/browser/insightRegistry';
import { resolveQueryFilePath } from 'sql/workbench/services/insights/common/insightsUtils'; import { resolveQueryFilePath } from 'sql/workbench/services/insights/common/insightsUtils';
import { RunInsightQueryAction } from './actions'; import { RunInsightQueryAction } from './actions';
@@ -46,6 +46,7 @@ interface IStorageResult {
template: ` template: `
<div *ngIf="error" style="text-align: center; padding-top: 20px">{{error}}</div> <div *ngIf="error" style="text-align: center; padding-top: 20px">{{error}}</div>
<div *ngIf="lastUpdated" style="font-style: italic; font-size: 80%; margin-left: 5px">{{lastUpdated}}</div> <div *ngIf="lastUpdated" style="font-style: italic; font-size: 80%; margin-left: 5px">{{lastUpdated}}</div>
<div *ngIf="autoRefreshStatus" style="font-style: italic; font-size: 80%; margin-left: 5px">{{autoRefreshStatus}}</div>
<div style="margin: 10px; width: calc(100% - 20px); height: calc(100% - 20px)"> <div style="margin: 10px; width: calc(100% - 20px); height: calc(100% - 20px)">
<ng-template component-host></ng-template> <ng-template component-host></ng-template>
<loading-spinner [loading]="_loading"></loading-spinner> <loading-spinner [loading]="_loading"></loading-spinner>
@@ -64,6 +65,7 @@ export class InsightsWidget extends DashboardWidget implements IDashboardWidget,
public error: string; public error: string;
public lastUpdated: string; public lastUpdated: string;
public autoRefreshStatus: string;
constructor( constructor(
@Inject(forwardRef(() => ComponentFactoryResolver)) private _componentFactoryResolver: ComponentFactoryResolver, @Inject(forwardRef(() => ComponentFactoryResolver)) private _componentFactoryResolver: ComponentFactoryResolver,
@@ -138,7 +140,22 @@ export class InsightsWidget extends DashboardWidget implements IDashboardWidget,
if (this.insightConfig.autoRefreshInterval) { if (this.insightConfig.autoRefreshInterval) {
this._intervalTimer = new IntervalTimer(); this._intervalTimer = new IntervalTimer();
this._register(this._intervalTimer); this._register(this._intervalTimer);
this._intervalTimer.cancelAndSet(() => this.refresh(), this.insightConfig.autoRefreshInterval * 60 * 1000); this._intervalTimer.cancelAndSet(() => {
const autoRefresh = getWidgetAutoRefreshState(this.insightConfig.id, this.actionsContext.profile.id);
this.updateAutoRefreshStatus(autoRefresh);
if (!autoRefresh) {
return;
}
this.refresh();
}, this.insightConfig.autoRefreshInterval * 60 * 1000);
}
}
private updateAutoRefreshStatus(autoRefreshOn: boolean): void {
let newState = autoRefreshOn ? '' : nls.localize('insights.autoRefreshOffState', "Auto Refresh: OFF");
if (this.autoRefreshStatus !== newState) {
this.autoRefreshStatus = newState;
this._cd.detectChanges();
} }
} }

View File

@@ -6,12 +6,14 @@
import { join } from 'vs/base/common/path'; import { join } from 'vs/base/common/path';
import { registerDashboardWidget, registerNonCustomDashboardWidget } from 'sql/platform/dashboard/browser/widgetRegistry'; import { registerDashboardWidget, registerNonCustomDashboardWidget } from 'sql/platform/dashboard/browser/widgetRegistry';
import { Extensions as InsightExtensions, IInsightRegistry } from 'sql/platform/dashboard/browser/insightRegistry'; import { Extensions as InsightExtensions, IInsightRegistry, setWidgetAutoRefreshState } from 'sql/platform/dashboard/browser/insightRegistry';
import { IInsightTypeContrib } from './interfaces'; import { IInsightTypeContrib } from './interfaces';
import { insightsContribution, insightsSchema } from 'sql/workbench/parts/dashboard/browser/widgets/insights/insightsWidgetSchemas'; import { insightsContribution, insightsSchema } from 'sql/workbench/parts/dashboard/browser/widgets/insights/insightsWidgetSchemas';
import { IExtensionPointUser, ExtensionsRegistry } from 'vs/workbench/services/extensions/common/extensionsRegistry'; import { IExtensionPointUser, ExtensionsRegistry } from 'vs/workbench/services/extensions/common/extensionsRegistry';
import { Registry } from 'vs/platform/registry/common/platform'; import { Registry } from 'vs/platform/registry/common/platform';
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
import { ServicesAccessor } from 'vs/editor/browser/editorExtensions';
const insightRegistry = Registry.as<IInsightRegistry>(InsightExtensions.InsightContribution); const insightRegistry = Registry.as<IInsightRegistry>(InsightExtensions.InsightContribution);
@@ -28,7 +30,7 @@ ExtensionsRegistry.registerExtensionPoint<IInsightTypeContrib | IInsightTypeCont
if (insight.contrib.details && insight.contrib.details.queryFile) { if (insight.contrib.details && insight.contrib.details.queryFile) {
insight.contrib.details.queryFile = join(extension.description.extensionLocation.fsPath, insight.contrib.details.queryFile); insight.contrib.details.queryFile = join(extension.description.extensionLocation.fsPath, insight.contrib.details.queryFile);
} }
insight.contrib.id = insight.id;
registerNonCustomDashboardWidget(insight.id, '', insight.contrib); registerNonCustomDashboardWidget(insight.id, '', insight.contrib);
insightRegistry.registerExtensionInsight(insight.id, insight.contrib); insightRegistry.registerExtensionInsight(insight.id, insight.contrib);
} }
@@ -44,3 +46,8 @@ ExtensionsRegistry.registerExtensionPoint<IInsightTypeContrib | IInsightTypeCont
} }
} }
}); });
CommandsRegistry.registerCommand('azdata.widget.setAutoRefreshState',
function (accessor: ServicesAccessor, widgetId: string, connectionId: string, autoRefresh: boolean) {
setWidgetAutoRefreshState(widgetId, connectionId, autoRefresh);
});