diff --git a/src/sql/parts/jobManagement/views/jobManagementView.ts b/src/sql/parts/jobManagement/views/jobManagementView.ts index b38607e6e6..ab31d14f64 100644 --- a/src/sql/parts/jobManagement/views/jobManagementView.ts +++ b/src/sql/parts/jobManagement/views/jobManagementView.ts @@ -3,13 +3,13 @@ * Licensed under the Source EULA. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ +import * as azdata from 'azdata'; import { ElementRef, AfterContentChecked, ViewChild } from '@angular/core'; import { Table } from 'sql/base/browser/ui/table/table'; import { AgentViewComponent } from 'sql/parts/jobManagement/agent/agentView.component'; import { CommonServiceInterface } from 'sql/services/common/commonServiceInterface.service'; import { IAction, Action } from 'vs/base/common/actions'; import { ResolvedKeybinding } from 'vs/base/common/keyCodes'; -import { TPromise } from 'vs/base/common/winjs.base'; import { IContextMenuService } from 'vs/platform/contextview/browser/contextView'; import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; @@ -75,7 +75,7 @@ export abstract class JobManagementView extends TabChild implements AfterContent let rowIndex = event.cell.row; let targetObject = this.getCurrentTableObject(rowIndex); - let actions = this.getTableActions(); + let actions = this.getTableActions(targetObject); if (actions) { let ownerUri: string = this._commonService.connectionManagementService.connectionInfo.ownerUri; let actionContext = { @@ -98,11 +98,11 @@ export abstract class JobManagementView extends TabChild implements AfterContent return kb; } - protected getTableActions(): IAction[] { + protected getTableActions(targetObject?: any): IAction[] { return undefined; } - protected getCurrentTableObject(rowIndex: number): any { + protected getCurrentTableObject(rowIndex: number): JobActionContext { return undefined; } @@ -117,4 +117,9 @@ export abstract class JobManagementView extends TabChild implements AfterContent { action: newAction } ]); } +} + +export interface JobActionContext { + canEdit: boolean; + job: azdata.AgentJobInfo; } \ No newline at end of file diff --git a/src/sql/parts/jobManagement/views/jobsView.component.ts b/src/sql/parts/jobManagement/views/jobsView.component.ts index 4713974985..5004701015 100644 --- a/src/sql/parts/jobManagement/views/jobsView.component.ts +++ b/src/sql/parts/jobManagement/views/jobsView.component.ts @@ -25,7 +25,7 @@ import { EditJobAction, DeleteJobAction, NewJobAction } from 'sql/platform/jobMa import { JobManagementUtilities } from 'sql/platform/jobManagement/common/jobManagementUtilities'; import { HeaderFilter } from 'sql/base/browser/ui/table/plugins/headerFilter.plugin'; import { IJobManagementService } from 'sql/platform/jobManagement/common/interfaces'; -import { JobManagementView } from 'sql/parts/jobManagement/views/jobManagementView'; +import { JobManagementView, JobActionContext } from 'sql/parts/jobManagement/views/jobManagementView'; import { CommonServiceInterface } from 'sql/services/common/commonServiceInterface.service'; import { ICommandService } from 'vs/platform/commands/common/commands'; import { IContextMenuService } from 'vs/platform/contextview/browser/contextView'; @@ -193,7 +193,6 @@ export class JobsViewComponent extends JobManagementView implements OnInit, OnDe self._agentViewComponent.agentJobInfo = job; self._agentViewComponent.showHistory = true; }); - this._register(this._table.onContextMenu(e => { self.openContextMenu(e); })); @@ -859,9 +858,13 @@ export class JobsViewComponent extends JobManagementView implements OnInit, OnDe }); } - protected getTableActions(): IAction[] { + protected getTableActions(targetObject: JobActionContext): IAction[] { let actions: IAction[] = []; - actions.push(this._instantiationService.createInstance(EditJobAction)); + let editAction = this._instantiationService.createInstance(EditJobAction); + if (!targetObject.canEdit) { + editAction.enabled = false; + } + actions.push(editAction); actions.push(this._instantiationService.createInstance(DeleteJobAction)); return actions; } @@ -900,7 +903,7 @@ export class JobsViewComponent extends JobManagementView implements OnInit, OnDe return result; } - protected getCurrentTableObject(rowIndex: number): any { + protected getCurrentTableObject(rowIndex: number): JobActionContext { let data = this._table.grid.getData(); if (!data || rowIndex >= data.getLength()) { return undefined; @@ -920,24 +923,30 @@ export class JobsViewComponent extends JobManagementView implements OnInit, OnDe return job.jobId === jobId; }); - // add steps - if (this.jobSteps && this.jobSteps[jobId]) { - let steps = this.jobSteps[jobId]; - job[0].jobSteps = steps; - } + if (job && job.length > 0) { + // add steps + if (this.jobSteps && this.jobSteps[jobId]) { + let steps = this.jobSteps[jobId]; + job[0].jobSteps = steps; + } - // add schedules - if (this.jobSchedules && this.jobSchedules[jobId]) { - let schedules = this.jobSchedules[jobId]; - job[0].jobSchedules = schedules; - } + // add schedules + if (this.jobSchedules && this.jobSchedules[jobId]) { + let schedules = this.jobSchedules[jobId]; + job[0].jobSchedules = schedules; + } + // add alerts + if (this.jobAlerts && this.jobAlerts[jobId]) { + let alerts = this.jobAlerts[jobId]; + job[0].alerts = alerts; + } - // add alerts - if (this.jobAlerts && this.jobAlerts[jobId]) { - let alerts = this.jobAlerts[jobId]; - job[0].alerts = alerts; + if (job[0].jobSteps && job[0].jobSchedules && job[0].alerts) { + return { job: job[0], canEdit: true }; + } + return { job: job[0], canEdit: false }; } - return job && job.length > 0 ? job[0] : undefined; + return undefined; } public openCreateJobDialog() {