diff --git a/src/sql/parts/dashboard/common/dashboardPage.component.ts b/src/sql/parts/dashboard/common/dashboardPage.component.ts index dd37e13bd5..63e8bb7e2c 100644 --- a/src/sql/parts/dashboard/common/dashboardPage.component.ts +++ b/src/sql/parts/dashboard/common/dashboardPage.component.ts @@ -9,6 +9,7 @@ import 'sql/parts/dashboard/common/dashboardPanelStyles'; import { Component, Inject, forwardRef, ViewChild, ElementRef, ViewChildren, QueryList, OnDestroy, ChangeDetectorRef } from '@angular/core'; import { DashboardServiceInterface } from 'sql/parts/dashboard/services/dashboardServiceInterface.service'; +import { CommonServiceInterface } from 'sql/services/common/commonServiceInterface.service'; import { WidgetConfig, TabConfig, TabSettingConfig } from 'sql/parts/dashboard/common/dashboardWidget'; import { Extensions, IInsightRegistry } from 'sql/platform/dashboard/common/insightRegistry'; import { DashboardWidgetWrapper } from 'sql/parts/dashboard/contents/dashboardWidgetWrapper.component'; @@ -85,13 +86,15 @@ export abstract class DashboardPage extends AngularDisposable { protected abstract propertiesWidget: WidgetConfig; protected abstract get context(): string; + protected dashboardService: DashboardServiceInterface; constructor( - @Inject(forwardRef(() => DashboardServiceInterface)) protected dashboardService: DashboardServiceInterface, + @Inject(forwardRef(() => CommonServiceInterface)) protected commonService: CommonServiceInterface, @Inject(forwardRef(() => ElementRef)) protected _el: ElementRef, @Inject(forwardRef(() => ChangeDetectorRef)) protected _cd: ChangeDetectorRef ) { super(); + this.dashboardService = commonService as DashboardServiceInterface; } protected init() { diff --git a/src/sql/parts/dashboard/containers/dashboardGridContainer.component.ts b/src/sql/parts/dashboard/containers/dashboardGridContainer.component.ts index dcab728a56..a7875d9346 100644 --- a/src/sql/parts/dashboard/containers/dashboardGridContainer.component.ts +++ b/src/sql/parts/dashboard/containers/dashboardGridContainer.component.ts @@ -9,6 +9,7 @@ import { Component, Inject, Input, forwardRef, ViewChild, ElementRef, ViewChildr import { NgGridConfig, NgGrid, NgGridItem } from 'angular2-grid'; import { DashboardServiceInterface } from 'sql/parts/dashboard/services/dashboardServiceInterface.service'; +import { CommonServiceInterface } from 'sql/services/common/commonServiceInterface.service'; import { TabConfig, WidgetConfig } from 'sql/parts/dashboard/common/dashboardWidget'; import { DashboardWidgetWrapper } from 'sql/parts/dashboard/contents/dashboardWidgetWrapper.component'; import { subscriptionToDisposable } from 'sql/base/common/lifecycle'; @@ -153,7 +154,7 @@ export class DashboardGridContainer extends DashboardTab implements OnDestroy { @ViewChildren(DashboardWidgetWrapper) private _widgets: QueryList; @ViewChildren(WebviewContent) private _webViews: QueryList; constructor( - @Inject(forwardRef(() => DashboardServiceInterface)) protected dashboardService: DashboardServiceInterface, + @Inject(forwardRef(() => CommonServiceInterface)) protected dashboardService: CommonServiceInterface, @Inject(forwardRef(() => ElementRef)) protected _el: ElementRef, @Inject(forwardRef(() => ChangeDetectorRef)) protected _cd: ChangeDetectorRef ) { diff --git a/src/sql/parts/dashboard/containers/dashboardHomeContainer.component.ts b/src/sql/parts/dashboard/containers/dashboardHomeContainer.component.ts index 6c185d7b1e..959a7e21a3 100644 --- a/src/sql/parts/dashboard/containers/dashboardHomeContainer.component.ts +++ b/src/sql/parts/dashboard/containers/dashboardHomeContainer.component.ts @@ -11,6 +11,7 @@ import { DashboardWidgetContainer } from 'sql/parts/dashboard/containers/dashboa import { DashboardTab } from 'sql/parts/dashboard/common/interfaces'; import { WidgetConfig } from 'sql/parts/dashboard/common/dashboardWidget'; import { DashboardServiceInterface } from 'sql/parts/dashboard/services/dashboardServiceInterface.service'; +import { CommonServiceInterface } from 'sql/services/common/commonServiceInterface.service'; import { AngularEventType } from '../../../services/angularEventing/angularEventingService'; import { DashboardWidgetWrapper } from 'sql/parts/dashboard/contents/dashboardWidgetWrapper.component'; import { ConfigurationTarget } from 'vs/platform/configuration/common/configuration'; @@ -30,12 +31,15 @@ export class DashboardHomeContainer extends DashboardWidgetContainer { @Input() private properties: WidgetConfig; @ViewChild('propertiesClass') private _propertiesClass: DashboardWidgetWrapper; + private dashboardService: DashboardServiceInterface; + constructor( @Inject(forwardRef(() => ChangeDetectorRef)) _cd: ChangeDetectorRef, - @Inject(forwardRef(() => DashboardServiceInterface)) protected dashboardService: DashboardServiceInterface, + @Inject(forwardRef(() => CommonServiceInterface)) protected commonService: CommonServiceInterface, ) { super(_cd); + this.dashboardService = commonService as DashboardServiceInterface; } ngAfterContentInit() { diff --git a/src/sql/parts/dashboard/containers/dashboardNavSection.component.ts b/src/sql/parts/dashboard/containers/dashboardNavSection.component.ts index b15eabd238..1bb8abeef5 100644 --- a/src/sql/parts/dashboard/containers/dashboardNavSection.component.ts +++ b/src/sql/parts/dashboard/containers/dashboardNavSection.component.ts @@ -8,6 +8,7 @@ import 'vs/css!./dashboardNavSection'; import { Component, Inject, Input, forwardRef, ViewChild, ElementRef, ViewChildren, QueryList, OnDestroy, ChangeDetectorRef, EventEmitter, OnChanges, AfterContentInit } from '@angular/core'; import { DashboardServiceInterface } from 'sql/parts/dashboard/services/dashboardServiceInterface.service'; +import { CommonServiceInterface } from 'sql/services/common/commonServiceInterface.service'; import { WidgetConfig, TabConfig, NavSectionConfig } from 'sql/parts/dashboard/common/dashboardWidget'; import { PanelComponent, IPanelOptions, NavigationBarLayout } from 'sql/base/browser/ui/panel/panel.component'; import { TabComponent } from 'sql/base/browser/ui/panel/tab.component'; @@ -53,7 +54,7 @@ export class DashboardNavSection extends DashboardTab implements OnDestroy, OnCh @ViewChildren(DashboardTab) private _tabs: QueryList; @ViewChild(PanelComponent) private _panel: PanelComponent; constructor( - @Inject(forwardRef(() => DashboardServiceInterface)) protected dashboardService: DashboardServiceInterface, + @Inject(forwardRef(() => CommonServiceInterface)) protected dashboardService: CommonServiceInterface, @Inject(forwardRef(() => ChangeDetectorRef)) protected _cd: ChangeDetectorRef ) { super(); diff --git a/src/sql/parts/dashboard/contents/controlHostContent.component.ts b/src/sql/parts/dashboard/contents/controlHostContent.component.ts index 0790528263..0d72c39578 100644 --- a/src/sql/parts/dashboard/contents/controlHostContent.component.ts +++ b/src/sql/parts/dashboard/contents/controlHostContent.component.ts @@ -13,6 +13,7 @@ import { IDisposable } from 'vs/base/common/lifecycle'; import { DashboardTab } from 'sql/parts/dashboard/common/interfaces'; import { TabConfig } from 'sql/parts/dashboard/common/dashboardWidget'; import { DashboardServiceInterface } from 'sql/parts/dashboard/services/dashboardServiceInterface.service'; +import { CommonServiceInterface } from 'sql/services/common/commonServiceInterface.service'; import * as sqlops from 'sqlops'; import { memoize } from 'vs/base/common/decorators'; @@ -37,7 +38,7 @@ export class ControlHostContent { @ViewChild('agent') private _agentViewComponent: AgentViewComponent; constructor( - @Inject(forwardRef(() => DashboardServiceInterface)) private _dashboardService: DashboardServiceInterface, + @Inject(forwardRef(() => CommonServiceInterface)) private _dashboardService: CommonServiceInterface, @Inject(forwardRef(() => ChangeDetectorRef)) private _changeRef: ChangeDetectorRef, @Inject(forwardRef(() => ElementRef)) private _el: ElementRef ) { diff --git a/src/sql/parts/dashboard/contents/dashboardWidgetWrapper.component.ts b/src/sql/parts/dashboard/contents/dashboardWidgetWrapper.component.ts index 395fbbdef6..a781dd9935 100644 --- a/src/sql/parts/dashboard/contents/dashboardWidgetWrapper.component.ts +++ b/src/sql/parts/dashboard/contents/dashboardWidgetWrapper.component.ts @@ -25,6 +25,7 @@ import { InsightsWidget } from 'sql/parts/dashboard/widgets/insights/insightsWid import { WebviewWidget } from 'sql/parts/dashboard/widgets/webview/webviewWidget.component'; import { DashboardServiceInterface } from 'sql/parts/dashboard/services/dashboardServiceInterface.service'; +import { CommonServiceInterface } from 'sql/services/common/commonServiceInterface.service'; import { IDisposable } from 'vs/base/common/lifecycle'; import { IColorTheme } from 'vs/workbench/services/themes/common/workbenchThemeService'; @@ -88,7 +89,7 @@ export class DashboardWidgetWrapper extends AngularDisposable implements OnInit constructor( @Inject(forwardRef(() => ComponentFactoryResolver)) private _componentFactoryResolver: ComponentFactoryResolver, @Inject(forwardRef(() => ElementRef)) private _ref: ElementRef, - @Inject(forwardRef(() => DashboardServiceInterface)) private _bootstrap: DashboardServiceInterface, + @Inject(forwardRef(() => CommonServiceInterface)) private _bootstrap: CommonServiceInterface, @Inject(forwardRef(() => ChangeDetectorRef)) private _changeref: ChangeDetectorRef, @Inject(forwardRef(() => Injector)) private _injector: Injector ) { diff --git a/src/sql/parts/dashboard/contents/webviewContent.component.ts b/src/sql/parts/dashboard/contents/webviewContent.component.ts index f6df5dd788..715ec72895 100644 --- a/src/sql/parts/dashboard/contents/webviewContent.component.ts +++ b/src/sql/parts/dashboard/contents/webviewContent.component.ts @@ -16,6 +16,7 @@ import { memoize } from 'vs/base/common/decorators'; import { DashboardTab } from 'sql/parts/dashboard/common/interfaces'; import { TabConfig } from 'sql/parts/dashboard/common/dashboardWidget'; import { DashboardServiceInterface } from 'sql/parts/dashboard/services/dashboardServiceInterface.service'; +import { CommonServiceInterface } from 'sql/services/common/commonServiceInterface.service'; import { IDashboardWebview } from 'sql/services/dashboard/common/dashboardViewService'; import { AngularDisposable } from 'sql/base/common/lifecycle'; @@ -36,13 +37,15 @@ export class WebviewContent extends AngularDisposable implements OnInit, IDashbo private _onMessageDisposable: IDisposable; private _webview: Webview; private _html: string; + private _dashboardService: DashboardServiceInterface; constructor( - @Inject(forwardRef(() => DashboardServiceInterface)) private _dashboardService: DashboardServiceInterface, + @Inject(forwardRef(() => CommonServiceInterface)) private commonService: CommonServiceInterface, @Inject(forwardRef(() => ChangeDetectorRef)) private _changeRef: ChangeDetectorRef, @Inject(forwardRef(() => ElementRef)) private _el: ElementRef ) { super(); + this._dashboardService = commonService as DashboardServiceInterface; } ngOnInit() { diff --git a/src/sql/parts/dashboard/contents/widgetContent.component.ts b/src/sql/parts/dashboard/contents/widgetContent.component.ts index bae5dd821b..dbd313ad64 100644 --- a/src/sql/parts/dashboard/contents/widgetContent.component.ts +++ b/src/sql/parts/dashboard/contents/widgetContent.component.ts @@ -9,6 +9,7 @@ import { Component, Inject, Input, forwardRef, ViewChild, ViewChildren, QueryLis import { NgGridConfig, NgGrid, NgGridItem } from 'angular2-grid'; import { DashboardServiceInterface } from 'sql/parts/dashboard/services/dashboardServiceInterface.service'; +import { CommonServiceInterface } from 'sql/services/common/commonServiceInterface.service'; import { WidgetConfig } from 'sql/parts/dashboard/common/dashboardWidget'; import { DashboardWidgetWrapper } from 'sql/parts/dashboard/contents/dashboardWidgetWrapper.component'; import { subscriptionToDisposable, AngularDisposable } from 'sql/base/common/lifecycle'; @@ -111,11 +112,14 @@ export class WidgetContent extends AngularDisposable implements AfterViewInit { @ViewChildren(NgGridItem) private _items: QueryList; @ViewChild('scrollable', { read: ElementRef }) private _scrollable: ElementRef; @ViewChild('scrollContainer', { read: ElementRef }) private _scrollContainer: ElementRef; + + protected dashboardService: DashboardServiceInterface; constructor( - @Inject(forwardRef(() => DashboardServiceInterface)) protected dashboardService: DashboardServiceInterface, + @Inject(forwardRef(() => CommonServiceInterface)) protected commonService: CommonServiceInterface, @Inject(forwardRef(() => ChangeDetectorRef)) protected _cd: ChangeDetectorRef ) { super(); + this.dashboardService = commonService as DashboardServiceInterface; } ngAfterViewInit() { diff --git a/src/sql/parts/dashboard/dashboard.component.ts b/src/sql/parts/dashboard/dashboard.component.ts index be306cc45e..7fb83d3e2a 100644 --- a/src/sql/parts/dashboard/dashboard.component.ts +++ b/src/sql/parts/dashboard/dashboard.component.ts @@ -9,6 +9,7 @@ import { OnInit, Component, Inject, forwardRef, ElementRef, ChangeDetectorRef, O import { Router } from '@angular/router'; import { DashboardServiceInterface } from './services/dashboardServiceInterface.service'; +import { CommonServiceInterface } from 'sql/services/common/commonServiceInterface.service'; import { IConnectionProfile } from 'sql/parts/connection/common/interfaces'; import * as Utils from 'sql/parts/connection/common/utils'; import { RefreshWidgetAction, EditDashboardAction } from 'sql/parts/dashboard/common/actions'; @@ -36,7 +37,7 @@ export class DashboardComponent extends AngularDisposable implements OnInit { private editDisposable: IDisposable; constructor( - @Inject(forwardRef(() => DashboardServiceInterface)) private _bootstrapService: DashboardServiceInterface, + @Inject(forwardRef(() => CommonServiceInterface)) private _bootstrapService: CommonServiceInterface, @Inject(forwardRef(() => Router)) private _router: Router, @Inject(forwardRef(() => ChangeDetectorRef)) private _changeRef: ChangeDetectorRef ) { diff --git a/src/sql/parts/dashboard/dashboard.module.ts b/src/sql/parts/dashboard/dashboard.module.ts index 3622d1e060..20dde955ae 100644 --- a/src/sql/parts/dashboard/dashboard.module.ts +++ b/src/sql/parts/dashboard/dashboard.module.ts @@ -26,6 +26,7 @@ import * as TelemetryKeys from 'sql/common/telemetryKeys'; /* Services */ import { BreadcrumbService } from 'sql/parts/dashboard/services/breadcrumb.service'; import { DashboardServiceInterface } from 'sql/parts/dashboard/services/dashboardServiceInterface.service'; +import { CommonServiceInterface } from 'sql/services/common/commonServiceInterface.service'; /* Directives */ import { ComponentHostDirective } from 'sql/parts/dashboard/common/componentHost.directive'; @@ -53,9 +54,9 @@ import { AgentViewComponent } from 'sql/parts/jobManagement/agent/agentView.comp import { JobHistoryComponent } from 'sql/parts/jobManagement/views/jobHistory.component'; let baseComponents = [DashboardHomeContainer, DashboardComponent, DashboardWidgetWrapper, DashboardWebviewContainer, - DashboardWidgetContainer, DashboardGridContainer, DashboardErrorContainer, DashboardNavSection, ModelViewContent, WebviewContent, WidgetContent, - ComponentHostDirective, BreadcrumbComponent, ControlHostContent, DashboardControlHostContainer, - JobsViewComponent, AgentViewComponent, JobHistoryComponent, JobStepsViewComponent, DashboardModelViewContainer, ModelComponentWrapper]; + DashboardWidgetContainer, DashboardGridContainer, DashboardErrorContainer, DashboardNavSection, ModelViewContent, WebviewContent, WidgetContent, + ComponentHostDirective, BreadcrumbComponent, ControlHostContent, DashboardControlHostContainer, + JobsViewComponent, AgentViewComponent, JobHistoryComponent, JobStepsViewComponent, DashboardModelViewContainer, ModelComponentWrapper]; /* Panel */ import { PanelModule } from 'sql/base/browser/ui/panel/panel.module'; @@ -128,18 +129,19 @@ const appRoutes: Routes = [ providers: [ { provide: APP_BASE_HREF, useValue: '/' }, { provide: IBreadcrumbService, useClass: BreadcrumbService }, - DashboardServiceInterface, + { provide: CommonServiceInterface, useClass: DashboardServiceInterface }, { provide: UrlSerializer, useClass: CustomUrlSerializer } ] }) export class DashboardModule { - + private _bootstrap: DashboardServiceInterface; constructor( @Inject(forwardRef(() => ComponentFactoryResolver)) private _resolver: ComponentFactoryResolver, @Inject(BOOTSTRAP_SERVICE_ID) private _bootstrapService: IBootstrapService, - @Inject(forwardRef(() => DashboardServiceInterface)) private _bootstrap: DashboardServiceInterface, + @Inject(forwardRef(() => CommonServiceInterface)) bootstrap: CommonServiceInterface, @Inject(forwardRef(() => Router)) private _router: Router ) { + this._bootstrap = bootstrap as DashboardServiceInterface; } ngDoBootstrap(appRef: ApplicationRef) { diff --git a/src/sql/parts/dashboard/pages/databaseDashboardPage.component.ts b/src/sql/parts/dashboard/pages/databaseDashboardPage.component.ts index 66124f8b79..19bba802e8 100644 --- a/src/sql/parts/dashboard/pages/databaseDashboardPage.component.ts +++ b/src/sql/parts/dashboard/pages/databaseDashboardPage.component.ts @@ -14,6 +14,7 @@ import { IBootstrapService, BOOTSTRAP_SERVICE_ID } from 'sql/services/bootstrap/ import * as colors from 'vs/platform/theme/common/colorRegistry'; import * as nls from 'vs/nls'; +import { CommonServiceInterface } from 'sql/services/common/commonServiceInterface.service'; export class DatabaseDashboardPage extends DashboardPage implements OnInit { protected propertiesWidget: WidgetConfig = { @@ -35,7 +36,7 @@ export class DatabaseDashboardPage extends DashboardPage implements OnInit { constructor( @Inject(forwardRef(() => IBreadcrumbService)) private _breadcrumbService: IBreadcrumbService, - @Inject(forwardRef(() => DashboardServiceInterface)) dashboardService: DashboardServiceInterface, + @Inject(forwardRef(() => CommonServiceInterface)) dashboardService: DashboardServiceInterface, @Inject(forwardRef(() => ChangeDetectorRef)) _cd: ChangeDetectorRef, @Inject(forwardRef(() => ElementRef)) el: ElementRef ) { diff --git a/src/sql/parts/dashboard/pages/serverDashboardPage.component.ts b/src/sql/parts/dashboard/pages/serverDashboardPage.component.ts index d690b6cf76..b1a12b992b 100644 --- a/src/sql/parts/dashboard/pages/serverDashboardPage.component.ts +++ b/src/sql/parts/dashboard/pages/serverDashboardPage.component.ts @@ -10,6 +10,7 @@ import { BreadcrumbClass } from 'sql/parts/dashboard/services/breadcrumb.service import { IBreadcrumbService } from 'sql/base/browser/ui/breadcrumb/interfaces'; import { WidgetConfig } from 'sql/parts/dashboard/common/dashboardWidget'; import { DashboardServiceInterface } from 'sql/parts/dashboard/services/dashboardServiceInterface.service'; +import { CommonServiceInterface } from 'sql/services/common/commonServiceInterface.service'; import { IBootstrapService, BOOTSTRAP_SERVICE_ID } from 'sql/services/bootstrap/bootstrapService'; import * as colors from 'vs/platform/theme/common/colorRegistry'; @@ -36,7 +37,7 @@ export class ServerDashboardPage extends DashboardPage implements OnInit { constructor( @Inject(forwardRef(() => IBreadcrumbService)) private breadcrumbService: IBreadcrumbService, - @Inject(forwardRef(() => DashboardServiceInterface)) dashboardService: DashboardServiceInterface, + @Inject(forwardRef(() => CommonServiceInterface)) dashboardService: CommonServiceInterface, @Inject(forwardRef(() => ChangeDetectorRef)) _cd: ChangeDetectorRef, @Inject(forwardRef(() => ElementRef)) el: ElementRef ) { diff --git a/src/sql/parts/dashboard/services/breadcrumb.service.ts b/src/sql/parts/dashboard/services/breadcrumb.service.ts index 2e6193bd61..8d4e0c5bab 100644 --- a/src/sql/parts/dashboard/services/breadcrumb.service.ts +++ b/src/sql/parts/dashboard/services/breadcrumb.service.ts @@ -7,6 +7,7 @@ import { Injectable, forwardRef, Inject, OnDestroy } from '@angular/core'; import { Subject } from 'rxjs/Subject'; import { DashboardServiceInterface } from './dashboardServiceInterface.service'; +import { CommonServiceInterface } from 'sql/services/common/commonServiceInterface.service'; import { MenuItem, IBreadcrumbService } from 'sql/base/browser/ui/breadcrumb/interfaces'; import { ConnectionProfile } from 'sql/parts/connection/common/connectionProfile'; @@ -23,9 +24,11 @@ export class BreadcrumbService implements IBreadcrumbService { public breadcrumbItem: Subject; private itemBreadcrums: MenuItem[]; private _currentPage: BreadcrumbClass; + private _bootstrap: DashboardServiceInterface; - constructor( @Inject(forwardRef(() => DashboardServiceInterface)) private _bootstrap: DashboardServiceInterface) { - _bootstrap.onUpdatePage(() => { + constructor( @Inject(forwardRef(() => CommonServiceInterface)) private commonService: CommonServiceInterface) { + this._bootstrap = commonService as DashboardServiceInterface; + this._bootstrap.onUpdatePage(() => { this.setBreadcrumbs(this._currentPage); }); this.breadcrumbItem = new Subject(); diff --git a/src/sql/parts/dashboard/services/dashboardServiceInterface.service.ts b/src/sql/parts/dashboard/services/dashboardServiceInterface.service.ts index 3a32bd98e5..41c08d26d9 100644 --- a/src/sql/parts/dashboard/services/dashboardServiceInterface.service.ts +++ b/src/sql/parts/dashboard/services/dashboardServiceInterface.service.ts @@ -26,6 +26,8 @@ import { TabSettingConfig } from 'sql/parts/dashboard/common/dashboardWidget'; import { IDashboardViewService } from 'sql/services/dashboard/common/dashboardViewService'; import { AngularDisposable } from 'sql/base/common/lifecycle'; import { ConnectionContextkey } from 'sql/parts/connection/common/connectionContextKey'; +import { SingleConnectionMetadataService, SingleConnectionManagementService, SingleAdminService, SingleQueryManagementService, CommonServiceInterface } +from 'sql/services/common/commonServiceInterface.service'; import { ProviderMetadata, DatabaseInfo, SimpleExecuteResult } from 'sqlops'; @@ -50,68 +52,6 @@ import { INotificationService } from 'vs/platform/notification/common/notificati const DASHBOARD_SETTINGS = 'dashboard'; -/* Wrapper for a metadata service that contains the uri string to use on each request */ -export class SingleConnectionMetadataService { - - constructor( - private _metadataService: IMetadataService, - private _uri: string - ) { } - - get metadata(): Observable { - return Observable.fromPromise(this._metadataService.getMetadata(this._uri)); - } - - get databaseNames(): Observable { - return Observable.fromPromise(this._metadataService.getDatabaseNames(this._uri)); - } -} - -/* Wrapper for a connection service that contains the uri string to use on each request */ -export class SingleConnectionManagementService { - - constructor( - private _connectionService: IConnectionManagementService, - private _uri: string, - private _contextKey: ConnectionContextkey - ) { } - - public changeDatabase(name: string): Thenable { - return this._connectionService.changeDatabase(this._uri, name).then(e => { - // we need to update our context - this._contextKey.set(this.connectionInfo.connectionProfile); - return e; - }); - } - - public get connectionInfo(): ConnectionManagementInfo { - return this._connectionService.getConnectionInfo(this._uri); - } -} - -export class SingleAdminService { - - constructor( - private _adminService: IAdminService, - private _uri: string - ) { } - - public get databaseInfo(): Observable { - return Observable.fromPromise(this._adminService.getDatabaseInfo(this._uri)); - } -} - -export class SingleQueryManagementService { - constructor( - private _queryManagementService: IQueryManagementService, - private _uri: string - ) { } - - public runQueryAndReturn(queryString: string): Thenable { - return this._queryManagementService.runQueryAndReturn(this._uri, queryString); - } -} - /* Providers a interface between a dashboard interface and the rest of carbon. Stores the uri and unique selector of a dashboard instance and uses that @@ -120,35 +60,12 @@ export class SingleQueryManagementService { usage of a widget. */ @Injectable() -export class DashboardServiceInterface extends AngularDisposable { - private _uniqueSelector: string; - private _uri: string; - private _bootstrapParams: DashboardComponentParams; +export class DashboardServiceInterface extends CommonServiceInterface { /* Static Services */ - private _themeService = this._bootstrapService.themeService; - private _contextMenuService = this._bootstrapService.contextMenuService; - private _instantiationService = this._bootstrapService.instantiationService; - private _configService = this._bootstrapService.configurationService; - private _insightsDialogService = this._bootstrapService.insightsDialogService; - private _contextViewService = this._bootstrapService.contextViewService; - private _notificationService = this._bootstrapService.notificationService; - private _workspaceContextService = this._bootstrapService.workspaceContextService; - private _storageService = this._bootstrapService.storageService; - private _capabilitiesService = this._bootstrapService.capabilitiesService; - private _configurationEditingService = this._bootstrapService.configurationEditorService; - private _commandService = this._bootstrapService.commandService; - private _dashboardViewService = this._bootstrapService.dashboardViewService; - private _partService = this._bootstrapService.partService; - private _angularEventingService = this._bootstrapService.angularEventingService; - private _environmentService = this._bootstrapService.environmentService; - /* Special Services */ - private _metadataService: SingleConnectionMetadataService; - private _connectionManagementService: SingleConnectionManagementService; - private _adminService: SingleAdminService; - private _queryManagementService: SingleQueryManagementService; - private _contextKeyService: IContextKeyService; + private _dashboardViewService = this._bootstrapService.dashboardViewService; + private _updatePage = new Emitter(); public readonly onUpdatePage: Event = this._updatePage.event; @@ -168,93 +85,19 @@ export class DashboardServiceInterface extends AngularDisposable { private _dashboardContextKey = new RawContextKey('dashboardContext', undefined); public dashboardContextKey: IContextKey; - private _connectionContextKey: ConnectionContextkey; - private _numberOfPageNavigations = 0; constructor( - @Inject(BOOTSTRAP_SERVICE_ID) private _bootstrapService: IBootstrapService, + @Inject(BOOTSTRAP_SERVICE_ID) bootstrapService: IBootstrapService, @Inject(forwardRef(() => Router)) private _router: Router, ) { - super(); - } - - public get notificationService(): INotificationService { - return this._notificationService; - } - - public get configurationEditingService(): ConfigurationEditingService { - return this._configurationEditingService; - } - - public get metadataService(): SingleConnectionMetadataService { - return this._metadataService; - } - - public get connectionManagementService(): SingleConnectionManagementService { - return this._connectionManagementService; - } - - public get commandService(): ICommandService { - return this._commandService; - } - - public get themeService(): IWorkbenchThemeService { - return this._themeService; - } - - public get contextMenuService(): IContextMenuService { - return this._contextMenuService; - } - - public get instantiationService(): IInstantiationService { - return this._instantiationService; + super(bootstrapService); } public get dashboardViewService(): IDashboardViewService { return this._dashboardViewService; } - public get partService(): IPartService { - return this._partService; - } - - public get contextKeyService(): IContextKeyService { - return this._contextKeyService; - } - - public get adminService(): SingleAdminService { - return this._adminService; - } - - public get queryManagementService(): SingleQueryManagementService { - return this._queryManagementService; - } - - public get environmentService(): IEnvironmentService { - return this._environmentService; - } - - public get contextViewService(): IContextViewService { - return this._contextViewService; - } - - public get workspaceContextService(): IWorkspaceContextService { - return this._workspaceContextService; - } - - public get storageService(): IStorageService { - return this._storageService; - } - - public get capabilitiesService(): ICapabilitiesService { - return this._capabilitiesService; - } - - public get angularEventingService(): IAngularEventingService { - return this._angularEventingService; - } - /** * Set the selector for this dashboard instance, should only be set once */ @@ -263,7 +106,7 @@ export class DashboardServiceInterface extends AngularDisposable { this._getbootstrapParams(); } - private _getbootstrapParams(): void { + protected _getbootstrapParams(): void { this._bootstrapParams = this._bootstrapService.getBootstrapParams(this._uniqueSelector); this._contextKeyService = this._bootstrapParams.scopedContextService; this._connectionContextKey = this._bootstrapParams.connectionContextKey; @@ -275,27 +118,11 @@ export class DashboardServiceInterface extends AngularDisposable { * Set the uri for this dashboard instance, should only be set once * Inits all the services that depend on knowing a uri */ - private set uri(uri: string) { - this._uri = uri; - this._metadataService = new SingleConnectionMetadataService(this._bootstrapService.metadataService, this._uri); - this._connectionManagementService = new SingleConnectionManagementService(this._bootstrapService.connectionManagementService, this._uri, this._connectionContextKey); - this._adminService = new SingleAdminService(this._bootstrapService.adminService, this._uri); - this._queryManagementService = new SingleQueryManagementService(this._bootstrapService.queryManagementService, this._uri); + protected set uri(uri: string) { + super.setUri(uri); this._register(toDisposableSubscription(this._bootstrapService.angularEventingService.onAngularEvent(this._uri, (event) => this.handleDashboardEvent(event)))); } - /** - * Gets the underlying Uri for dashboard - * In general don't use this, use specific services instances exposed publically - */ - public getUnderlyingUri(): string { - return this._uri; - } - - public getOriginalConnectionProfile(): IConnectionProfile { - return this._bootstrapParams.connection; - } - /** * Gets the number of page navigation */ diff --git a/src/sql/parts/dashboard/widgets/explorer/explorerTree.ts b/src/sql/parts/dashboard/widgets/explorer/explorerTree.ts index 03144175bf..eb26cb45ac 100644 --- a/src/sql/parts/dashboard/widgets/explorer/explorerTree.ts +++ b/src/sql/parts/dashboard/widgets/explorer/explorerTree.ts @@ -7,7 +7,7 @@ import { Router } from '@angular/router'; import { IConnectionProfile } from 'sql/parts/connection/common/interfaces'; import { MetadataType } from 'sql/parts/connection/common/connectionManagement'; -import { SingleConnectionManagementService } from 'sql/parts/dashboard/services/dashboardServiceInterface.service'; +import { SingleConnectionManagementService } from 'sql/services/common/commonServiceInterface.service'; import { NewQueryAction, ScriptSelectAction, EditDataAction, ScriptCreateAction, ScriptExecuteAction, ScriptAlterAction, BackupAction, ManageActionContext, BaseActionContext, ManageAction, RestoreAction diff --git a/src/sql/parts/dashboard/widgets/explorer/explorerWidget.component.ts b/src/sql/parts/dashboard/widgets/explorer/explorerWidget.component.ts index c9015dc8da..701f2bd289 100644 --- a/src/sql/parts/dashboard/widgets/explorer/explorerWidget.component.ts +++ b/src/sql/parts/dashboard/widgets/explorer/explorerWidget.component.ts @@ -12,6 +12,7 @@ import { Router } from '@angular/router'; import { DashboardWidget, IDashboardWidget, WidgetConfig, WIDGET_CONFIG } from 'sql/parts/dashboard/common/dashboardWidget'; import { DashboardServiceInterface } from 'sql/parts/dashboard/services/dashboardServiceInterface.service'; +import { CommonServiceInterface } from 'sql/services/common/commonServiceInterface.service'; import { toDisposableSubscription } from 'sql/parts/common/rxjsUtils'; import { ExplorerFilter, ExplorerRenderer, ExplorerDataSource, ExplorerController, ObjectMetadataWrapper, ExplorerModel } from './explorerTree'; import { ConnectionProfile } from 'sql/parts/connection/common/connectionProfile'; @@ -49,7 +50,7 @@ export class ExplorerWidget extends DashboardWidget implements IDashboardWidget, @ViewChild('table') private _tableContainer: ElementRef; constructor( - @Inject(forwardRef(() => DashboardServiceInterface)) private _bootstrap: DashboardServiceInterface, + @Inject(forwardRef(() => CommonServiceInterface)) private _bootstrap: CommonServiceInterface, @Inject(forwardRef(() => Router)) private _router: Router, @Inject(forwardRef(() => ChangeDetectorRef)) private _changeRef: ChangeDetectorRef, @Inject(WIDGET_CONFIG) protected _config: WidgetConfig, diff --git a/src/sql/parts/dashboard/widgets/insights/insightsWidget.component.ts b/src/sql/parts/dashboard/widgets/insights/insightsWidget.component.ts index 50136711eb..046d08ddc7 100644 --- a/src/sql/parts/dashboard/widgets/insights/insightsWidget.component.ts +++ b/src/sql/parts/dashboard/widgets/insights/insightsWidget.component.ts @@ -10,6 +10,7 @@ import { Observable } from 'rxjs/Observable'; import { DashboardWidget, IDashboardWidget, WIDGET_CONFIG, WidgetConfig } from 'sql/parts/dashboard/common/dashboardWidget'; import { DashboardServiceInterface } from 'sql/parts/dashboard/services/dashboardServiceInterface.service'; +import { CommonServiceInterface } from 'sql/services/common/commonServiceInterface.service'; import { ComponentHostDirective } from 'sql/parts/dashboard/common/componentHost.directive'; import { InsightAction, InsightActionContext } from 'sql/workbench/common/actions'; import { toDisposableSubscription } from 'sql/parts/common/rxjsUtils'; @@ -57,7 +58,7 @@ export class InsightsWidget extends DashboardWidget implements IDashboardWidget, constructor( @Inject(forwardRef(() => ComponentFactoryResolver)) private _componentFactoryResolver: ComponentFactoryResolver, - @Inject(forwardRef(() => DashboardServiceInterface)) private dashboardService: DashboardServiceInterface, + @Inject(forwardRef(() => CommonServiceInterface)) private dashboardService: CommonServiceInterface, @Inject(WIDGET_CONFIG) protected _config: WidgetConfig, @Inject(forwardRef(() => ViewContainerRef)) private viewContainerRef: ViewContainerRef, @Inject(forwardRef(() => ChangeDetectorRef)) private _cd: ChangeDetectorRef diff --git a/src/sql/parts/dashboard/widgets/properties/propertiesWidget.component.ts b/src/sql/parts/dashboard/widgets/properties/propertiesWidget.component.ts index 47d1d23525..078ee106df 100644 --- a/src/sql/parts/dashboard/widgets/properties/propertiesWidget.component.ts +++ b/src/sql/parts/dashboard/widgets/properties/propertiesWidget.component.ts @@ -7,6 +7,7 @@ import { Component, Inject, forwardRef, ChangeDetectorRef, OnInit, ElementRef, V import { DashboardWidget, IDashboardWidget, WidgetConfig, WIDGET_CONFIG } from 'sql/parts/dashboard/common/dashboardWidget'; import { DashboardServiceInterface } from 'sql/parts/dashboard/services/dashboardServiceInterface.service'; +import { CommonServiceInterface } from 'sql/services/common/commonServiceInterface.service'; import { ConnectionManagementInfo } from 'sql/parts/connection/common/connectionManagementInfo'; import { toDisposableSubscription } from 'sql/parts/common/rxjsUtils'; import { error } from 'sql/base/common/log'; @@ -68,7 +69,7 @@ export class PropertiesWidgetComponent extends DashboardWidget implements IDashb @ViewChild('parent', { read: ElementRef }) private _parent: ElementRef; constructor( - @Inject(forwardRef(() => DashboardServiceInterface)) private _bootstrap: DashboardServiceInterface, + @Inject(forwardRef(() => CommonServiceInterface)) private _bootstrap: CommonServiceInterface, @Inject(forwardRef(() => ChangeDetectorRef)) private _changeRef: ChangeDetectorRef, @Inject(forwardRef(() => ElementRef)) private _el: ElementRef, @Inject(WIDGET_CONFIG) protected _config: WidgetConfig, diff --git a/src/sql/parts/dashboard/widgets/tasks/tasksWidget.component.ts b/src/sql/parts/dashboard/widgets/tasks/tasksWidget.component.ts index 0979424236..c77b6ba701 100644 --- a/src/sql/parts/dashboard/widgets/tasks/tasksWidget.component.ts +++ b/src/sql/parts/dashboard/widgets/tasks/tasksWidget.component.ts @@ -12,6 +12,7 @@ import { DomSanitizer } from '@angular/platform-browser'; /* SQL imports */ import { DashboardWidget, IDashboardWidget, WidgetConfig, WIDGET_CONFIG } from 'sql/parts/dashboard/common/dashboardWidget'; import { DashboardServiceInterface } from 'sql/parts/dashboard/services/dashboardServiceInterface.service'; +import { CommonServiceInterface } from 'sql/services/common/commonServiceInterface.service'; import { TaskRegistry } from 'sql/platform/tasks/common/tasks'; import { IConnectionProfile } from 'sql/parts/connection/common/interfaces'; import { BaseActionContext } from 'sql/workbench/common/actions'; @@ -57,7 +58,7 @@ export class TasksWidget extends DashboardWidget implements IDashboardWidget, On @ViewChild('container', { read: ElementRef }) private _container: ElementRef; constructor( - @Inject(forwardRef(() => DashboardServiceInterface)) private _bootstrap: DashboardServiceInterface, + @Inject(forwardRef(() => CommonServiceInterface)) private _bootstrap: CommonServiceInterface, @Inject(forwardRef(() => DomSanitizer)) private _sanitizer: DomSanitizer, @Inject(forwardRef(() => ChangeDetectorRef)) private _changeref: ChangeDetectorRef, @Inject(WIDGET_CONFIG) protected _config: WidgetConfig diff --git a/src/sql/parts/dashboard/widgets/webview/webviewWidget.component.ts b/src/sql/parts/dashboard/widgets/webview/webviewWidget.component.ts index 392f4bc22e..d7803aff4a 100644 --- a/src/sql/parts/dashboard/widgets/webview/webviewWidget.component.ts +++ b/src/sql/parts/dashboard/widgets/webview/webviewWidget.component.ts @@ -13,6 +13,7 @@ import { memoize } from 'vs/base/common/decorators'; import { DashboardWidget, IDashboardWidget, WidgetConfig, WIDGET_CONFIG } from 'sql/parts/dashboard/common/dashboardWidget'; import { DashboardServiceInterface } from 'sql/parts/dashboard/services/dashboardServiceInterface.service'; +import { CommonServiceInterface } from 'sql/services/common/commonServiceInterface.service'; import { IDashboardWebview } from 'sql/services/dashboard/common/dashboardViewService'; import * as sqlops from 'sqlops'; @@ -35,15 +36,17 @@ export class WebviewWidget extends DashboardWidget implements IDashboardWidget, private _onMessage = new Emitter(); public readonly onMessage: Event = this._onMessage.event; private _onMessageDisposable: IDisposable; + private _dashboardService: DashboardServiceInterface; constructor( - @Inject(forwardRef(() => DashboardServiceInterface)) private _dashboardService: DashboardServiceInterface, + @Inject(forwardRef(() => CommonServiceInterface)) private commonService: CommonServiceInterface, @Inject(forwardRef(() => ChangeDetectorRef)) private _changeRef: ChangeDetectorRef, @Inject(WIDGET_CONFIG) protected _config: WidgetConfig, @Inject(forwardRef(() => ElementRef)) private _el: ElementRef ) { super(); this._id = (_config.widget[selector] as IWebviewWidgetConfig).id; + this._dashboardService = commonService as DashboardServiceInterface; } ngOnInit() { diff --git a/src/sql/parts/jobManagement/views/jobHistory.component.ts b/src/sql/parts/jobManagement/views/jobHistory.component.ts index 5a7bcbc876..0b681128d5 100644 --- a/src/sql/parts/jobManagement/views/jobHistory.component.ts +++ b/src/sql/parts/jobManagement/views/jobHistory.component.ts @@ -19,6 +19,7 @@ import { PanelComponent } from 'sql/base/browser/ui/panel/panel.component'; import { IBootstrapService, BOOTSTRAP_SERVICE_ID } from 'sql/services/bootstrap/bootstrapService'; import { IJobManagementService } from '../common/interfaces'; import { DashboardServiceInterface } from 'sql/parts/dashboard/services/dashboardServiceInterface.service'; +import { CommonServiceInterface } from 'sql/services/common/commonServiceInterface.service'; import { AgentViewComponent } from 'sql/parts/jobManagement/agent/agentView.component'; import { JobHistoryController, JobHistoryDataSource, JobHistoryRenderer, JobHistoryFilter, JobHistoryModel, JobHistoryRow } from 'sql/parts/jobManagement/views/jobHistoryTree'; @@ -63,7 +64,7 @@ export class JobHistoryComponent extends Disposable implements OnInit { @Inject(BOOTSTRAP_SERVICE_ID) private bootstrapService: IBootstrapService, @Inject(forwardRef(() => ElementRef)) el: ElementRef, @Inject(forwardRef(() => ChangeDetectorRef)) private _cd: ChangeDetectorRef, - @Inject(forwardRef(() => DashboardServiceInterface)) private _dashboardService: DashboardServiceInterface, + @Inject(forwardRef(() => CommonServiceInterface)) private _dashboardService: CommonServiceInterface, @Inject(forwardRef(() => AgentViewComponent)) private _agentViewComponent: AgentViewComponent ) { super(); diff --git a/src/sql/parts/jobManagement/views/jobHistoryTree.ts b/src/sql/parts/jobManagement/views/jobHistoryTree.ts index ec83bbbb32..90b3fed776 100644 --- a/src/sql/parts/jobManagement/views/jobHistoryTree.ts +++ b/src/sql/parts/jobManagement/views/jobHistoryTree.ts @@ -7,7 +7,7 @@ import { Router } from '@angular/router'; import { IConnectionProfile } from 'sql/parts/connection/common/interfaces'; import { MetadataType } from 'sql/parts/connection/common/connectionManagement'; -import { SingleConnectionManagementService } from 'sql/parts/dashboard/services/dashboardServiceInterface.service'; +import { SingleConnectionManagementService } from 'sql/services/common/commonServiceInterface.service'; import { NewQueryAction, ScriptSelectAction, EditDataAction, ScriptCreateAction, ScriptExecuteAction, ScriptAlterAction, BackupAction, ManageActionContext, BaseActionContext, ManageAction, RestoreAction diff --git a/src/sql/parts/jobManagement/views/jobStepsView.component.ts b/src/sql/parts/jobManagement/views/jobStepsView.component.ts index 98b49485a8..5ffd92c329 100644 --- a/src/sql/parts/jobManagement/views/jobStepsView.component.ts +++ b/src/sql/parts/jobManagement/views/jobStepsView.component.ts @@ -14,6 +14,7 @@ import { Disposable, IDisposable } from 'vs/base/common/lifecycle'; import { IBootstrapService, BOOTSTRAP_SERVICE_ID } from 'sql/services/bootstrap/bootstrapService'; import { IJobManagementService } from '../common/interfaces'; import { DashboardServiceInterface } from 'sql/parts/dashboard/services/dashboardServiceInterface.service'; +import { CommonServiceInterface } from 'sql/services/common/commonServiceInterface.service'; import { AgentJobHistoryInfo } from 'sqlops'; import { JobStepsViewController, JobStepsViewDataSource, JobStepsViewFilter, JobStepsViewRenderer, JobStepsViewRow, JobStepsViewModel} from 'sql/parts/jobManagement/views/jobStepsViewTree'; @@ -42,7 +43,7 @@ export class JobStepsViewComponent extends Disposable implements OnInit, AfterCo @Inject(BOOTSTRAP_SERVICE_ID) private bootstrapService: IBootstrapService, @Inject(forwardRef(() => ElementRef)) el: ElementRef, @Inject(forwardRef(() => ChangeDetectorRef)) private _cd: ChangeDetectorRef, - @Inject(forwardRef(() => DashboardServiceInterface)) private _dashboardService: DashboardServiceInterface, + @Inject(forwardRef(() => CommonServiceInterface)) private _dashboardService: CommonServiceInterface, @Inject(forwardRef(() => JobHistoryComponent)) private _jobHistoryComponent: JobHistoryComponent ) { super(); diff --git a/src/sql/parts/jobManagement/views/jobStepsViewTree.ts b/src/sql/parts/jobManagement/views/jobStepsViewTree.ts index 3b69eb0ae3..8bd3a7fb15 100644 --- a/src/sql/parts/jobManagement/views/jobStepsViewTree.ts +++ b/src/sql/parts/jobManagement/views/jobStepsViewTree.ts @@ -7,7 +7,7 @@ import { Router } from '@angular/router'; import { IConnectionProfile } from 'sql/parts/connection/common/interfaces'; import { MetadataType } from 'sql/parts/connection/common/connectionManagement'; -import { SingleConnectionManagementService } from 'sql/parts/dashboard/services/dashboardServiceInterface.service'; +import { SingleConnectionManagementService } from 'sql/services/common/commonServiceInterface.service'; import { NewQueryAction, ScriptSelectAction, EditDataAction, ScriptCreateAction, ScriptExecuteAction, ScriptAlterAction, BackupAction, ManageActionContext, BaseActionContext, ManageAction, RestoreAction diff --git a/src/sql/parts/jobManagement/views/jobsView.component.ts b/src/sql/parts/jobManagement/views/jobsView.component.ts index 4c02bb0772..d5f1f7c42e 100644 --- a/src/sql/parts/jobManagement/views/jobsView.component.ts +++ b/src/sql/parts/jobManagement/views/jobsView.component.ts @@ -21,6 +21,7 @@ import { ActionBar } from 'vs/base/browser/ui/actionbar/actionbar'; import { IBootstrapService, BOOTSTRAP_SERVICE_ID } from 'sql/services/bootstrap/bootstrapService'; import { IJobManagementService } from '../common/interfaces'; import { DashboardServiceInterface } from 'sql/parts/dashboard/services/dashboardServiceInterface.service'; +import { CommonServiceInterface } from 'sql/services/common/commonServiceInterface.service'; import * as sqlops from 'sqlops'; import * as vscode from 'vscode'; import * as nls from 'vs/nls'; @@ -74,7 +75,7 @@ export class JobsViewComponent implements AfterContentChecked { constructor( @Inject(BOOTSTRAP_SERVICE_ID) private bootstrapService: IBootstrapService, - @Inject(forwardRef(() => DashboardServiceInterface)) private _dashboardService: DashboardServiceInterface, + @Inject(forwardRef(() => CommonServiceInterface)) private _dashboardService: CommonServiceInterface, @Inject(forwardRef(() => ChangeDetectorRef)) private _cd: ChangeDetectorRef, @Inject(forwardRef(() => ElementRef)) private _el: ElementRef, @Inject(forwardRef(() => AgentViewComponent)) private _agentViewComponent: AgentViewComponent diff --git a/src/sql/parts/modelComponents/modelComponentWrapper.component.ts b/src/sql/parts/modelComponents/modelComponentWrapper.component.ts index 888c2ce469..42325ae355 100644 --- a/src/sql/parts/modelComponents/modelComponentWrapper.component.ts +++ b/src/sql/parts/modelComponents/modelComponentWrapper.component.ts @@ -13,6 +13,7 @@ import { ComponentHostDirective } from 'sql/parts/dashboard/common/componentHost import { error } from 'sql/base/common/log'; import { AngularDisposable } from 'sql/base/common/lifecycle'; import { DashboardServiceInterface } from 'sql/parts/dashboard/services/dashboardServiceInterface.service'; +import { CommonServiceInterface } from 'sql/services/common/commonServiceInterface.service'; import { IComponent, IComponentConfig, IComponentDescriptor, IModelStore, COMPONENT_CONFIG } from './interfaces'; import { Extensions, IComponentRegistry } from 'sql/platform/dashboard/common/modelComponentRegistry'; @@ -27,7 +28,7 @@ import { memoize } from 'vs/base/common/decorators'; import { generateUuid } from 'vs/base/common/uuid'; import * as nls from 'vs/nls'; -const componentRegistry = Registry.as(Extensions.ComponentContribution); +const componentRegistry = Registry.as(Extensions.ComponentContribution); @Component({ selector: 'model-component-wrapper', @@ -52,7 +53,7 @@ export class ModelComponentWrapper extends AngularDisposable implements OnInit { constructor( @Inject(forwardRef(() => ComponentFactoryResolver)) private _componentFactoryResolver: ComponentFactoryResolver, @Inject(forwardRef(() => ElementRef)) private _ref: ElementRef, - @Inject(forwardRef(() => DashboardServiceInterface)) private _bootstrap: DashboardServiceInterface, + @Inject(forwardRef(() => CommonServiceInterface)) private _bootstrap: CommonServiceInterface, @Inject(forwardRef(() => ChangeDetectorRef)) private _changeref: ChangeDetectorRef, @Inject(forwardRef(() => Injector)) private _injector: Injector ) { diff --git a/src/sql/parts/modelComponents/modelViewContent.component.ts b/src/sql/parts/modelComponents/modelViewContent.component.ts index b60b53079b..0eea1aeb08 100644 --- a/src/sql/parts/modelComponents/modelViewContent.component.ts +++ b/src/sql/parts/modelComponents/modelViewContent.component.ts @@ -15,7 +15,7 @@ import nls = require('vs/nls'); import { DashboardTab } from 'sql/parts/dashboard/common/interfaces'; import { TabConfig } from 'sql/parts/dashboard/common/dashboardWidget'; -import { DashboardServiceInterface } from 'sql/parts/dashboard/services/dashboardServiceInterface.service'; +import { CommonServiceInterface } from 'sql/services/common/commonServiceInterface.service'; import { IModelView } from 'sql/services/model/modelViewService'; import { AngularDisposable } from 'sql/base/common/lifecycle'; @@ -42,14 +42,14 @@ export class ModelViewContent extends ViewBase implements OnInit, IModelView { private _onMessageDisposable: IDisposable; constructor( - @Inject(forwardRef(() => DashboardServiceInterface)) private _dashboardService: DashboardServiceInterface, + @Inject(forwardRef(() => CommonServiceInterface)) private _commonService: CommonServiceInterface, @Inject(forwardRef(() => ChangeDetectorRef)) changeRef: ChangeDetectorRef ) { super(changeRef); } ngOnInit() { - this._dashboardService.dashboardViewService.registerModelView(this); + this._commonService.modelViewService.registerModelView(this); this._register(addDisposableListener(window, EventType.RESIZE, e => { this.layout(); })); @@ -64,7 +64,7 @@ export class ModelViewContent extends ViewBase implements OnInit, IModelView { @memoize public get connection(): sqlops.connection.Connection { - let currentConnection = this._dashboardService.connectionManagementService.connectionInfo.connectionProfile; + let currentConnection = this._commonService.connectionManagementService.connectionInfo.connectionProfile; let connection: sqlops.connection.Connection = { providerName: currentConnection.providerName, connectionId: currentConnection.id, @@ -75,6 +75,6 @@ export class ModelViewContent extends ViewBase implements OnInit, IModelView { @memoize public get serverInfo(): sqlops.ServerInfo { - return this._dashboardService.connectionManagementService.connectionInfo.serverInfo; + return this._commonService.connectionManagementService.connectionInfo.serverInfo; } } diff --git a/src/sql/services/bootstrap/bootstrapParams.ts b/src/sql/services/bootstrap/bootstrapParams.ts index a2a69496d3..0b23ad65ba 100644 --- a/src/sql/services/bootstrap/bootstrapParams.ts +++ b/src/sql/services/bootstrap/bootstrapParams.ts @@ -19,13 +19,16 @@ export interface EditDataComponentParams extends BootstrapParams { dataService: DataService; } -export interface DashboardComponentParams extends BootstrapParams { +export interface DefaultComponentParams extends BootstrapParams { connection: IConnectionProfile; ownerUri: string; scopedContextService: IContextKeyService; connectionContextKey: ConnectionContextkey; } +export interface DashboardComponentParams extends DefaultComponentParams { +} + export interface TaskDialogComponentParams extends BootstrapParams { ownerUri: string; } diff --git a/src/sql/services/bootstrap/bootstrapService.ts b/src/sql/services/bootstrap/bootstrapService.ts index 7ebbe63152..4ea28deb59 100644 --- a/src/sql/services/bootstrap/bootstrapService.ts +++ b/src/sql/services/bootstrap/bootstrapService.ts @@ -43,6 +43,7 @@ import { ICommandService } from 'vs/platform/commands/common/commands'; import { IJobManagementService } from 'sql/parts/jobManagement/common/interfaces'; import { IEnvironmentService } from 'vs/platform/environment/common/environment'; import { INotificationService } from 'vs/platform/notification/common/notification'; +import { IModelViewService } from 'sql/services/modelComponents/modelViewService'; export const BOOTSTRAP_SERVICE_ID = 'bootstrapService'; export const IBootstrapService = createDecorator(BOOTSTRAP_SERVICE_ID); @@ -94,6 +95,7 @@ export interface IBootstrapService { configurationEditorService: ConfigurationEditingService; commandService: ICommandService; dashboardViewService: IDashboardViewService; + modelViewService: IModelViewService; jobManagementService: IJobManagementService; environmentService: IEnvironmentService; diff --git a/src/sql/services/bootstrap/bootstrapServiceImpl.ts b/src/sql/services/bootstrap/bootstrapServiceImpl.ts index bd926fa523..d257f8670d 100644 --- a/src/sql/services/bootstrap/bootstrapServiceImpl.ts +++ b/src/sql/services/bootstrap/bootstrapServiceImpl.ts @@ -25,6 +25,7 @@ import { IFileBrowserService, IFileBrowserDialogController } from 'sql/parts/fil import { IClipboardService } from 'sql/platform/clipboard/common/clipboardService'; import { ICapabilitiesService } from 'sql/services/capabilities/capabilitiesService'; import { IDashboardViewService } from 'sql/services/dashboard/common/dashboardViewService'; +import { IModelViewService } from 'sql/services/modelComponents/modelViewService'; import { $ } from 'vs/base/browser/dom'; import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; @@ -103,6 +104,7 @@ export class BootstrapService implements IBootstrapService { @ICapabilitiesService public capabilitiesService: ICapabilitiesService, @ICommandService public commandService: ICommandService, @IDashboardViewService public dashboardViewService: IDashboardViewService, + @IModelViewService public modelViewService: IModelViewService, @IJobManagementService public jobManagementService: IJobManagementService, @IEnvironmentService public environmentService: IEnvironmentService ) { diff --git a/src/sql/services/common/commonServiceInterface.service.ts b/src/sql/services/common/commonServiceInterface.service.ts new file mode 100644 index 0000000000..6448d42893 --- /dev/null +++ b/src/sql/services/common/commonServiceInterface.service.ts @@ -0,0 +1,279 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the Source EULA. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +/* Node Modules */ +import { Injectable, Inject, forwardRef, OnDestroy } from '@angular/core'; +import { Router } from '@angular/router'; +import { Observable } from 'rxjs/Observable'; + +/* SQL imports */ +import { DefaultComponentParams } from 'sql/services/bootstrap/bootstrapParams'; +import { IBootstrapService, BOOTSTRAP_SERVICE_ID } from 'sql/services/bootstrap/bootstrapService'; +import { IMetadataService } from 'sql/services/metadata/metadataService'; +import { IConnectionManagementService } from 'sql/parts/connection/common/connectionManagement'; +import { ConnectionManagementInfo } from 'sql/parts/connection/common/connectionManagementInfo'; +import { IAdminService } from 'sql/parts/admin/common/adminService'; +import { IQueryManagementService } from 'sql/parts/query/common/queryManagement'; +import { toDisposableSubscription } from 'sql/parts/common/rxjsUtils'; +import { IInsightsDialogService } from 'sql/parts/insights/common/interfaces'; +import { ICapabilitiesService } from 'sql/services/capabilities/capabilitiesService'; +import { IConnectionProfile } from 'sql/parts/connection/common/interfaces'; +import { AngularEventType, IAngularEvent, IAngularEventingService } from 'sql/services/angularEventing/angularEventingService'; +import { IModelViewService } from 'sql/services/modelComponents/modelViewService'; +import { AngularDisposable } from 'sql/base/common/lifecycle'; +import { ConnectionContextkey } from 'sql/parts/connection/common/connectionContextKey'; + +import { ProviderMetadata, DatabaseInfo, SimpleExecuteResult } from 'sqlops'; + +/* VS imports */ +import { IWorkbenchThemeService } from 'vs/workbench/services/themes/common/workbenchThemeService'; +import { IContextMenuService, IContextViewService } from 'vs/platform/contextview/browser/contextView'; +import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; +import { IDisposable } from 'vs/base/common/lifecycle'; +import { IConfigurationService, ConfigurationTarget } from 'vs/platform/configuration/common/configuration'; +import { ConfigurationEditingService, IConfigurationValue } from 'vs/workbench/services/configuration/node/configurationEditingService'; +import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; +import { IStorageService } from 'vs/platform/storage/common/storage'; +import Event, { Emitter } from 'vs/base/common/event'; +import Severity from 'vs/base/common/severity'; +import * as nls from 'vs/nls'; +import { IPartService } from 'vs/workbench/services/part/common/partService'; +import { deepClone } from 'vs/base/common/objects'; +import { ICommandService } from 'vs/platform/commands/common/commands'; +import { IContextKeyService, RawContextKey, IContextKey } from 'vs/platform/contextkey/common/contextkey'; +import { IEnvironmentService } from 'vs/platform/environment/common/environment'; +import { INotificationService } from 'vs/platform/notification/common/notification'; + +/* Wrapper for a metadata service that contains the uri string to use on each request */ +export class SingleConnectionMetadataService { + + constructor( + private _metadataService: IMetadataService, + private _uri: string + ) { } + + get metadata(): Observable { + return Observable.fromPromise(this._metadataService.getMetadata(this._uri)); + } + + get databaseNames(): Observable { + return Observable.fromPromise(this._metadataService.getDatabaseNames(this._uri)); + } +} + +/* Wrapper for a connection service that contains the uri string to use on each request */ +export class SingleConnectionManagementService { + + constructor( + private _connectionService: IConnectionManagementService, + private _uri: string, + private _contextKey: ConnectionContextkey + ) { } + + public changeDatabase(name: string): Thenable { + return this._connectionService.changeDatabase(this._uri, name).then(e => { + // we need to update our context + this._contextKey.set(this.connectionInfo.connectionProfile); + return e; + }); + } + + public get connectionInfo(): ConnectionManagementInfo { + return this._connectionService.getConnectionInfo(this._uri); + } +} + +export class SingleAdminService { + + constructor( + private _adminService: IAdminService, + private _uri: string + ) { } + + public get databaseInfo(): Observable { + return Observable.fromPromise(this._adminService.getDatabaseInfo(this._uri)); + } +} + +export class SingleQueryManagementService { + constructor( + private _queryManagementService: IQueryManagementService, + private _uri: string + ) { } + + public runQueryAndReturn(queryString: string): Thenable { + return this._queryManagementService.runQueryAndReturn(this._uri, queryString); + } +} + +/* + Providers a interface between a UI interface and the rest of carbon. + Stores the uri and unique selector of a UI instance and uses that + whenever a call to a carbon service needs this information, so that the widgets + don't need to be aware of the uri or selector. Simplifies the initialization and + usage of a widget. +*/ +@Injectable() +export class CommonServiceInterface extends AngularDisposable { + protected _uniqueSelector: string; + protected _uri: string; + protected _bootstrapParams: DefaultComponentParams; + + /* Static Services */ + protected _themeService = this._bootstrapService.themeService; + protected _contextMenuService = this._bootstrapService.contextMenuService; + protected _instantiationService = this._bootstrapService.instantiationService; + protected _configService = this._bootstrapService.configurationService; + protected _insightsDialogService = this._bootstrapService.insightsDialogService; + protected _contextViewService = this._bootstrapService.contextViewService; + protected _notificationService = this._bootstrapService.notificationService; + protected _workspaceContextService = this._bootstrapService.workspaceContextService; + protected _storageService = this._bootstrapService.storageService; + protected _capabilitiesService = this._bootstrapService.capabilitiesService; + protected _configurationEditingService = this._bootstrapService.configurationEditorService; + protected _commandService = this._bootstrapService.commandService; + protected _modelViewService = this._bootstrapService.modelViewService; + protected _partService = this._bootstrapService.partService; + protected _angularEventingService = this._bootstrapService.angularEventingService; + protected _environmentService = this._bootstrapService.environmentService; + + /* Special Services */ + protected _metadataService: SingleConnectionMetadataService; + protected _connectionManagementService: SingleConnectionManagementService; + protected _adminService: SingleAdminService; + protected _queryManagementService: SingleQueryManagementService; + protected _contextKeyService: IContextKeyService; + + protected _connectionContextKey: ConnectionContextkey; + + constructor( + @Inject(BOOTSTRAP_SERVICE_ID) protected _bootstrapService: IBootstrapService + ) { + super(); + } + + public get notificationService(): INotificationService { + return this._notificationService; + } + + public get configurationEditingService(): ConfigurationEditingService { + return this._configurationEditingService; + } + + public get metadataService(): SingleConnectionMetadataService { + return this._metadataService; + } + + public get connectionManagementService(): SingleConnectionManagementService { + return this._connectionManagementService; + } + + public get commandService(): ICommandService { + return this._commandService; + } + + public get themeService(): IWorkbenchThemeService { + return this._themeService; + } + + public get contextMenuService(): IContextMenuService { + return this._contextMenuService; + } + + public get instantiationService(): IInstantiationService { + return this._instantiationService; + } + + public get modelViewService(): IModelViewService { + return this._modelViewService; + } + + public get partService(): IPartService { + return this._partService; + } + + public get contextKeyService(): IContextKeyService { + return this._contextKeyService; + } + + public get adminService(): SingleAdminService { + return this._adminService; + } + + public get queryManagementService(): SingleQueryManagementService { + return this._queryManagementService; + } + + public get environmentService(): IEnvironmentService { + return this._environmentService; + } + + public get contextViewService(): IContextViewService { + return this._contextViewService; + } + + public get workspaceContextService(): IWorkspaceContextService { + return this._workspaceContextService; + } + + public get storageService(): IStorageService { + return this._storageService; + } + + public get capabilitiesService(): ICapabilitiesService { + return this._capabilitiesService; + } + + public get angularEventingService(): IAngularEventingService { + return this._angularEventingService; + } + + /** + * Set the selector for this instance, should only be set once + */ + public set selector(selector: string) { + this._uniqueSelector = selector; + this._getbootstrapParams(); + } + + protected _getbootstrapParams(): void { + this._bootstrapParams = this._bootstrapService.getBootstrapParams(this._uniqueSelector); + this._contextKeyService = this._bootstrapParams.scopedContextService; + this._connectionContextKey = this._bootstrapParams.connectionContextKey; + this.uri = this._bootstrapParams.ownerUri; + } + + protected setUri(uri: string) { + this._uri = uri; + this._metadataService = new SingleConnectionMetadataService(this._bootstrapService.metadataService, this._uri); + this._connectionManagementService = new SingleConnectionManagementService(this._bootstrapService.connectionManagementService, this._uri, this._connectionContextKey); + this._adminService = new SingleAdminService(this._bootstrapService.adminService, this._uri); + this._queryManagementService = new SingleQueryManagementService(this._bootstrapService.queryManagementService, this._uri); + } + + /** + * Set the uri for this instance, should only be set once + * Inits all the services that depend on knowing a uri + */ + protected set uri(uri: string) { + this.setUri(uri); + } + + protected get uri(): string { + return this._uri; + } + + /** + * Gets the underlying Uri + * In general don't use this, use specific services instances exposed publicly + */ + public getUnderlyingUri(): string { + return this._uri; + } + + public getOriginalConnectionProfile(): IConnectionProfile { + return this._bootstrapParams.connection; + } +} diff --git a/src/sql/services/modelComponents/modelViewService.ts b/src/sql/services/modelComponents/modelViewService.ts new file mode 100644 index 0000000000..44d8c5f5e5 --- /dev/null +++ b/src/sql/services/modelComponents/modelViewService.ts @@ -0,0 +1,23 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the Source EULA. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +'use strict'; + +import { createDecorator } from 'vs/platform/instantiation/common/instantiation'; +import Event from 'vs/base/common/event'; + +import * as sqlops from 'sqlops'; +import { IItemConfig, IComponentShape } from 'sql/workbench/api/common/sqlExtHostTypes'; +import { IView, IModelView } from 'sql/services/model/modelViewService'; + +export const SERVICE_ID = 'modelViewService'; + +export interface IModelViewService { + _serviceBrand: any; + onRegisteredModelView: Event; + registerModelView(widget: IModelView); +} + +export const IModelViewService = createDecorator(SERVICE_ID); \ No newline at end of file diff --git a/src/sql/services/modelComponents/modelViewServiceImpl.ts b/src/sql/services/modelComponents/modelViewServiceImpl.ts new file mode 100644 index 0000000000..21cfb07631 --- /dev/null +++ b/src/sql/services/modelComponents/modelViewServiceImpl.ts @@ -0,0 +1,21 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the Source EULA. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +'use strict'; + +import { IModelViewService } from 'sql/services/modelComponents/modelViewService'; +import Event, { Emitter } from 'vs/base/common/event'; +import { IModelView } from 'sql/services/model/modelViewService'; + +export class ModelViewService implements IModelViewService { + _serviceBrand: any; + + private _onRegisteredModelView = new Emitter(); + public readonly onRegisteredModelView: Event = this._onRegisteredModelView.event; + + public registerModelView(view: IModelView) { + this._onRegisteredModelView.fire(view); + } +} diff --git a/src/sql/workbench/api/node/mainThreadModelView.ts b/src/sql/workbench/api/node/mainThreadModelView.ts index 522a830b24..d66c5ed6ae 100644 --- a/src/sql/workbench/api/node/mainThreadModelView.ts +++ b/src/sql/workbench/api/node/mainThreadModelView.ts @@ -10,7 +10,7 @@ import { IExtHostContext } from 'vs/workbench/api/node/extHost.protocol'; import * as sqlops from 'sqlops'; -import { IDashboardViewService } from 'sql/services/dashboard/common/dashboardViewService'; +import { IModelViewService } from 'sql/services/modelComponents/modelViewService'; import { IItemConfig, ModelComponentTypes, IComponentShape } from 'sql/workbench/api/common/sqlExtHostTypes'; import { IModelView } from 'sql/services/model/modelViewService'; @@ -26,7 +26,7 @@ export class MainThreadModelView implements MainThreadModelViewShape { constructor( context: IExtHostContext, - @IDashboardViewService viewService: IDashboardViewService + @IModelViewService viewService: IModelViewService ) { this._proxy = context.getProxy(SqlExtHostContext.ExtHostModelView); viewService.onRegisteredModelView(view => { diff --git a/src/sqltest/parts/dashboard/widgets/propertiesWidget.component.test.ts b/src/sqltest/parts/dashboard/widgets/propertiesWidget.component.test.ts index a21f7288b1..559b30ec29 100644 --- a/src/sqltest/parts/dashboard/widgets/propertiesWidget.component.test.ts +++ b/src/sqltest/parts/dashboard/widgets/propertiesWidget.component.test.ts @@ -8,7 +8,8 @@ import { Observable } from 'rxjs/Observable'; import 'rxjs/add/observable/of'; import { WidgetConfig } from 'sql/parts/dashboard/common/dashboardWidget'; -import { DashboardServiceInterface, SingleAdminService, SingleConnectionManagementService } from 'sql/parts/dashboard/services/dashboardServiceInterface.service'; +import { DashboardServiceInterface } from 'sql/parts/dashboard/services/dashboardServiceInterface.service'; +import { SingleAdminService, SingleConnectionManagementService } from 'sql/services/common/commonServiceInterface.service'; import { PropertiesWidgetComponent } from 'sql/parts/dashboard/widgets/properties/propertiesWidget.component'; import { ConnectionManagementInfo } from 'sql/parts/connection/common/connectionManagementInfo'; diff --git a/src/vs/workbench/electron-browser/workbench.ts b/src/vs/workbench/electron-browser/workbench.ts index 55d404e8f4..320a5a2433 100644 --- a/src/vs/workbench/electron-browser/workbench.ts +++ b/src/vs/workbench/electron-browser/workbench.ts @@ -155,7 +155,9 @@ import { IResourceProviderService, IAccountPickerService } from 'sql/parts/accou import { ResourceProviderService } from 'sql/parts/accountManagement/common/resourceProviderService'; import { AccountPickerService } from 'sql/parts/accountManagement/accountPicker/accountPickerService'; import { IDashboardViewService } from 'sql/services/dashboard/common/dashboardViewService'; +import { IModelViewService } from 'sql/services/modelComponents/modelViewService'; import { DashboardViewService } from 'sql/services/dashboard/common/dashboardViewServiceImpl'; +import { ModelViewService } from 'sql/services/modelComponents/modelViewServiceImpl'; import { IDashboardService } from 'sql/services/dashboard/common/dashboardService'; import { DashboardService } from 'sql/services/dashboard/common/dashboardServiceImpl'; @@ -678,6 +680,7 @@ export class Workbench implements IPartService { // SQL Tools services serviceCollection.set(IDashboardService, this.instantiationService.createInstance(DashboardService)); serviceCollection.set(IDashboardViewService, this.instantiationService.createInstance(DashboardViewService)); + serviceCollection.set(IModelViewService, this.instantiationService.createInstance(ModelViewService)); serviceCollection.set(IAngularEventingService, this.instantiationService.createInstance(AngularEventingService)); serviceCollection.set(INewDashboardTabDialogService, this.instantiationService.createInstance(NewDashboardTabDialogService)); serviceCollection.set(ISqlOAuthService, this.instantiationService.createInstance(SqlOAuthService));