mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-12 11:08:31 -05:00
Task contribution (#742)
* work in progress * set up necessary code. need to work on getting it working * formatting * work in progress * work in progress * formatting * work in progress * work in progress * work in progress * formatting * needs a lot of work regarding how we do actions vs how extensions do actions * formatting * use connection profile for actions * change action to be
This commit is contained in:
@@ -12,7 +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 { ITaskRegistry, Extensions, TaskAction } from 'sql/platform/tasks/taskRegistry';
|
||||
import { TaskRegistry } from 'sql/platform/tasks/common/tasks';
|
||||
import { IConnectionProfile } from 'sql/parts/connection/common/interfaces';
|
||||
import { BaseActionContext } from 'sql/workbench/common/actions';
|
||||
|
||||
@@ -20,7 +20,6 @@ import { BaseActionContext } from 'sql/workbench/common/actions';
|
||||
import * as themeColors from 'vs/workbench/common/theme';
|
||||
import * as colors from 'vs/platform/theme/common/colorRegistry';
|
||||
import { registerThemingParticipant, ICssStyleCollector, ITheme } from 'vs/platform/theme/common/themeService';
|
||||
import { Registry } from 'vs/platform/registry/common/platform';
|
||||
import { Action } from 'vs/base/common/actions';
|
||||
import Severity from 'vs/base/common/severity';
|
||||
import * as nls from 'vs/nls';
|
||||
@@ -29,6 +28,8 @@ import { ScrollableElement } from 'vs/base/browser/ui/scrollbar/scrollableElemen
|
||||
import { ScrollbarVisibility } from 'vs/base/common/scrollable';
|
||||
import { $, Builder } from 'vs/base/browser/builder';
|
||||
import * as DOM from 'vs/base/browser/dom';
|
||||
import { CommandsRegistry, ICommand } from 'vs/platform/commands/common/commands';
|
||||
import { MenuRegistry, ICommandAction } from 'vs/platform/actions/common/actions';
|
||||
|
||||
interface IConfig {
|
||||
tasks: Array<Object>;
|
||||
@@ -40,7 +41,7 @@ interface IConfig {
|
||||
})
|
||||
export class TasksWidget extends DashboardWidget implements IDashboardWidget, OnInit {
|
||||
private _size: number = 98;
|
||||
private _tasks: Array<TaskAction> = [];
|
||||
private _tasks: Array<ICommandAction> = [];
|
||||
private _profile: IConnectionProfile;
|
||||
private _scrollableElement: ScrollableElement;
|
||||
private $container: Builder;
|
||||
@@ -55,30 +56,14 @@ export class TasksWidget extends DashboardWidget implements IDashboardWidget, On
|
||||
) {
|
||||
super();
|
||||
this._profile = this._bootstrap.connectionManagementService.connectionInfo.connectionProfile;
|
||||
let registry = Registry.as<ITaskRegistry>(Extensions.TaskContribution);
|
||||
let tasksConfig = <IConfig>Object.values(this._config.widget)[0];
|
||||
let taskIds: Array<string>;
|
||||
let tasks = TaskRegistry.getTasks();
|
||||
|
||||
if (tasksConfig.tasks) {
|
||||
taskIds = Object.keys(tasksConfig.tasks);
|
||||
} else {
|
||||
taskIds = registry.ids;
|
||||
tasks = Object.keys(tasksConfig.tasks).filter(i => tasks.includes(i));
|
||||
}
|
||||
|
||||
let ctorMap = registry.idToCtorMap;
|
||||
this._tasks = taskIds.map(id => {
|
||||
let ctor = ctorMap[id];
|
||||
if (ctor) {
|
||||
let action = this._bootstrap.instantiationService.createInstance(ctor, ctor.ID, ctor.LABEL, ctor.ICON);
|
||||
if (this._bootstrap.capabilitiesService.isFeatureAvailable(action, this._bootstrap.connectionManagementService.connectionInfo)) {
|
||||
return action;
|
||||
}
|
||||
} else {
|
||||
this._bootstrap.messageService.show(Severity.Warning, nls.localize('missingTask', 'Could not find task {0}; are you missing an extension?', id));
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}).filter(a => !types.isUndefinedOrNull(a));
|
||||
this._tasks = tasks.map(i => MenuRegistry.getCommand(i));
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
@@ -120,11 +105,15 @@ export class TasksWidget extends DashboardWidget implements IDashboardWidget, On
|
||||
this.$container.style('height', height + 'px').style('width', width + 'px');
|
||||
}
|
||||
|
||||
private _createTile(action: TaskAction): HTMLElement {
|
||||
let label = $('div').safeInnerHtml(action.label);
|
||||
let icon = $('span.icon').addClass(action.icon);
|
||||
let innerTile = $('div').append(icon).append(label);
|
||||
private _createTile(action: ICommandAction): HTMLElement {
|
||||
let label = $('div').safeInnerHtml(types.isString(action.title) ? action.title : action.title.value);
|
||||
let tile = $('div.task-tile').style('height', this._size + 'px').style('width', this._size + 'px');
|
||||
let innerTile = $('div');
|
||||
if (action) {
|
||||
let icon = $('span.icon').addClass(action.iconClass);
|
||||
innerTile.append(icon);
|
||||
}
|
||||
innerTile.append(label);
|
||||
tile.append(innerTile);
|
||||
tile.on(DOM.EventType.CLICK, () => this.runTask(action));
|
||||
return tile.getHTMLElement();
|
||||
@@ -142,11 +131,9 @@ export class TasksWidget extends DashboardWidget implements IDashboardWidget, On
|
||||
}
|
||||
}
|
||||
|
||||
public runTask(task: Action) {
|
||||
let context: BaseActionContext = {
|
||||
profile: this._profile
|
||||
};
|
||||
task.run(context);
|
||||
public runTask(task: ICommandAction) {
|
||||
let serverInfo = this._bootstrap.connectionManagementService.connectionInfo.serverInfo;
|
||||
this._bootstrap.commandService.executeCommand(task.id, this._profile);
|
||||
}
|
||||
|
||||
public layout(): void {
|
||||
|
||||
Reference in New Issue
Block a user