diff --git a/src/sql/platform/dashboard/browser/insightRegistry.ts b/src/sql/platform/dashboard/browser/insightRegistry.ts index 303e57601d..1c4b386f3d 100644 --- a/src/sql/platform/dashboard/browser/insightRegistry.ts +++ b/src/sql/platform/dashboard/browser/insightRegistry.ts @@ -25,6 +25,7 @@ export interface IInsightsConfig { queryFile?: string; details?: IInsightsConfigDetails; autoRefreshInterval?: number; + id?: string; } export interface IInsightsLabel { @@ -124,3 +125,14 @@ platform.Registry.add(Extensions.InsightContribution, insightRegistry); export function registerInsight(id: string, description: string, schema: IJSONSchema, ctor: Type): InsightIdentifier { 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; +} diff --git a/src/sql/workbench/parts/dashboard/browser/widgets/insights/insightsWidget.component.ts b/src/sql/workbench/parts/dashboard/browser/widgets/insights/insightsWidget.component.ts index b57d50457e..c1c1d148c9 100644 --- a/src/sql/workbench/parts/dashboard/browser/widgets/insights/insightsWidget.component.ts +++ b/src/sql/workbench/parts/dashboard/browser/widgets/insights/insightsWidget.component.ts @@ -13,7 +13,7 @@ import { DashboardWidget, IDashboardWidget, WIDGET_CONFIG, WidgetConfig } from ' import { CommonServiceInterface } from 'sql/platform/bootstrap/browser/commonServiceInterface.service'; import { ComponentHostDirective } from 'sql/workbench/parts/dashboard/browser/core/componentHost.directive'; 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 { RunInsightQueryAction } from './actions'; @@ -46,6 +46,7 @@ interface IStorageResult { template: `
{{error}}
{{lastUpdated}}
+
{{autoRefreshStatus}}
@@ -64,6 +65,7 @@ export class InsightsWidget extends DashboardWidget implements IDashboardWidget, public error: string; public lastUpdated: string; + public autoRefreshStatus: string; constructor( @Inject(forwardRef(() => ComponentFactoryResolver)) private _componentFactoryResolver: ComponentFactoryResolver, @@ -138,7 +140,22 @@ export class InsightsWidget extends DashboardWidget implements IDashboardWidget, if (this.insightConfig.autoRefreshInterval) { this._intervalTimer = new 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(); } } diff --git a/src/sql/workbench/parts/dashboard/browser/widgets/insights/insightsWidget.contribution.ts b/src/sql/workbench/parts/dashboard/browser/widgets/insights/insightsWidget.contribution.ts index 3f1052c59b..e9c77d62e8 100644 --- a/src/sql/workbench/parts/dashboard/browser/widgets/insights/insightsWidget.contribution.ts +++ b/src/sql/workbench/parts/dashboard/browser/widgets/insights/insightsWidget.contribution.ts @@ -6,12 +6,14 @@ import { join } from 'vs/base/common/path'; 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 { insightsContribution, insightsSchema } from 'sql/workbench/parts/dashboard/browser/widgets/insights/insightsWidgetSchemas'; import { IExtensionPointUser, ExtensionsRegistry } from 'vs/workbench/services/extensions/common/extensionsRegistry'; 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(InsightExtensions.InsightContribution); @@ -28,7 +30,7 @@ ExtensionsRegistry.registerExtensionPoint