mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
Task context + schema (#849)
* commting .d.ts changes * added serverinfo to .d.ts * maybe its working? * works * updated contrib * remove unnecessary code * fix compile errors * update task schema and add the ability to specifiy a when clause * update defaults for tasks widget * add when to restore and back up tasks to not show up for cloud servers * formatting * fixing engine * add restore to server page
This commit is contained in:
@@ -95,7 +95,7 @@ export const databaseDashboardSettingSchema: IJSONSchema = {
|
|||||||
sizey: 1
|
sizey: 1
|
||||||
},
|
},
|
||||||
widget: {
|
widget: {
|
||||||
'tasks-widget': {}
|
'tasks-widget': [{ name: 'backup', when: '!mssql:iscloud' }, { name: 'restore', when: '!mssql:iscloud' }, 'configureDashboard', 'newQuery']
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ let defaultVal = [
|
|||||||
{
|
{
|
||||||
name: 'Tasks',
|
name: 'Tasks',
|
||||||
widget: {
|
widget: {
|
||||||
'tasks-widget': {}
|
'tasks-widget': [{ name: 'restore', when: '!mssql:iscloud' }, 'configureDashboard', 'newQuery']
|
||||||
},
|
},
|
||||||
gridItemConfig: {
|
gridItemConfig: {
|
||||||
sizex: 1,
|
sizex: 1,
|
||||||
|
|||||||
@@ -30,13 +30,17 @@ import { $, Builder } from 'vs/base/browser/builder';
|
|||||||
import * as DOM from 'vs/base/browser/dom';
|
import * as DOM from 'vs/base/browser/dom';
|
||||||
import { CommandsRegistry, ICommand } from 'vs/platform/commands/common/commands';
|
import { CommandsRegistry, ICommand } from 'vs/platform/commands/common/commands';
|
||||||
import { MenuRegistry, ICommandAction } from 'vs/platform/actions/common/actions';
|
import { MenuRegistry, ICommandAction } from 'vs/platform/actions/common/actions';
|
||||||
|
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
|
||||||
|
|
||||||
interface IConfig {
|
interface ITask {
|
||||||
tasks: Array<Object>;
|
name: string;
|
||||||
|
when: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const selector = 'tasks-widget';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'tasks-widget',
|
selector,
|
||||||
templateUrl: decodeURI(require.toUrl('sql/parts/dashboard/widgets/tasks/tasksWidget.component.html'))
|
templateUrl: decodeURI(require.toUrl('sql/parts/dashboard/widgets/tasks/tasksWidget.component.html'))
|
||||||
})
|
})
|
||||||
export class TasksWidget extends DashboardWidget implements IDashboardWidget, OnInit {
|
export class TasksWidget extends DashboardWidget implements IDashboardWidget, OnInit {
|
||||||
@@ -58,11 +62,22 @@ export class TasksWidget extends DashboardWidget implements IDashboardWidget, On
|
|||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
this._profile = this._bootstrap.connectionManagementService.connectionInfo.connectionProfile;
|
this._profile = this._bootstrap.connectionManagementService.connectionInfo.connectionProfile;
|
||||||
let tasksConfig = <IConfig>Object.values(this._config.widget)[0];
|
let tasksConfig = this._config.widget[selector] as Array<string | ITask>;
|
||||||
let tasks = TaskRegistry.getTasks();
|
let tasks = TaskRegistry.getTasks();
|
||||||
|
|
||||||
if (tasksConfig.tasks) {
|
if (types.isArray(tasksConfig) && tasksConfig.length > 0) {
|
||||||
tasks = Object.keys(tasksConfig.tasks).filter(i => tasks.includes(i));
|
tasks = tasksConfig.map(i => {
|
||||||
|
if (types.isString(i)) {
|
||||||
|
if (tasks.includes(i)) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (tasks.includes(i.name) && _bootstrap.contextKeyService.contextMatchesRules(ContextKeyExpr.deserialize(i.when))) {
|
||||||
|
return i.name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}).filter(i => !!i);
|
||||||
}
|
}
|
||||||
|
|
||||||
this._tasks = tasks.map(i => MenuRegistry.getCommand(i));
|
this._tasks = tasks.map(i => MenuRegistry.getCommand(i));
|
||||||
|
|||||||
@@ -6,13 +6,26 @@ import { IJSONSchema } from 'vs/base/common/jsonSchema';
|
|||||||
import { registerDashboardWidget } from 'sql/platform/dashboard/common/widgetRegistry';
|
import { registerDashboardWidget } from 'sql/platform/dashboard/common/widgetRegistry';
|
||||||
import { TaskRegistry } from 'sql/platform/tasks/common/tasks';
|
import { TaskRegistry } from 'sql/platform/tasks/common/tasks';
|
||||||
|
|
||||||
let tasksSchema: IJSONSchema = {
|
const tasksSchema: IJSONSchema = {
|
||||||
|
type: 'array',
|
||||||
|
items: {
|
||||||
|
anyOf: [{
|
||||||
|
type: 'string',
|
||||||
|
enum: TaskRegistry.getTasks()
|
||||||
|
},
|
||||||
|
{
|
||||||
type: 'object',
|
type: 'object',
|
||||||
properties: {
|
properties: {
|
||||||
tasks: {
|
name: {
|
||||||
type: 'object'
|
type: 'string',
|
||||||
|
enum: TaskRegistry.getTasks()
|
||||||
|
},
|
||||||
|
when: {
|
||||||
|
type: 'string'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}]
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
registerDashboardWidget('tasks-widget', '', tasksSchema);
|
registerDashboardWidget('tasks-widget', '', tasksSchema);
|
||||||
@@ -6,8 +6,10 @@ import { IInsightsConfig } from 'sql/parts/dashboard/widgets/insights/interfaces
|
|||||||
|
|
||||||
import * as platform from 'vs/platform/registry/common/platform';
|
import * as platform from 'vs/platform/registry/common/platform';
|
||||||
import { IJSONSchema, IJSONSchemaMap } from 'vs/base/common/jsonSchema';
|
import { IJSONSchema, IJSONSchemaMap } from 'vs/base/common/jsonSchema';
|
||||||
|
import { IJSONContributionRegistry, Extensions as JSONExtensions } from 'vs/platform/jsonschemas/common/jsonContributionRegistry';
|
||||||
import * as nls from 'vs/nls';
|
import * as nls from 'vs/nls';
|
||||||
import { deepClone } from 'vs/base/common/objects';
|
|
||||||
|
const contributionRegistry = platform.Registry.as<IJSONContributionRegistry>(JSONExtensions.JSONContribution);
|
||||||
|
|
||||||
export type WidgetIdentifier = string;
|
export type WidgetIdentifier = string;
|
||||||
|
|
||||||
@@ -89,15 +91,15 @@ class DashboardWidgetRegistry implements IDashboardWidgetRegistry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public get databaseWidgetSchema(): CustomIJSONSchema {
|
public get databaseWidgetSchema(): CustomIJSONSchema {
|
||||||
return deepClone(this._dashboardWidgetSchema);
|
return this._dashboardWidgetSchema;
|
||||||
}
|
}
|
||||||
|
|
||||||
public get serverWidgetSchema(): CustomIJSONSchema {
|
public get serverWidgetSchema(): CustomIJSONSchema {
|
||||||
return deepClone(this._serverWidgetSchema);
|
return this._serverWidgetSchema;
|
||||||
}
|
}
|
||||||
|
|
||||||
public get allSchema(): CustomIJSONSchema {
|
public get allSchema(): CustomIJSONSchema {
|
||||||
return deepClone(this._allSchema);
|
return this._allSchema;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import { Action } from 'vs/base/common/actions';
|
|||||||
import { IConstructorSignature3, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
|
import { IConstructorSignature3, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
|
||||||
import * as nls from 'vs/nls';
|
import * as nls from 'vs/nls';
|
||||||
import { ILocalizedString, IMenuItem, MenuRegistry, ICommandAction } from 'vs/platform/actions/common/actions';
|
import { ILocalizedString, IMenuItem, MenuRegistry, ICommandAction } from 'vs/platform/actions/common/actions';
|
||||||
import Event from 'vs/base/common/event';
|
import Event, { Emitter } from 'vs/base/common/event';
|
||||||
import { IDisposable } from 'vs/base/common/lifecycle';
|
import { IDisposable } from 'vs/base/common/lifecycle';
|
||||||
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
|
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
|
||||||
import { IConnectionProfile } from 'sql/parts/connection/common/interfaces';
|
import { IConnectionProfile } from 'sql/parts/connection/common/interfaces';
|
||||||
@@ -96,11 +96,14 @@ export interface ITaskRegistry {
|
|||||||
registerTask(id: string, command: ITaskHandler): IDisposable;
|
registerTask(id: string, command: ITaskHandler): IDisposable;
|
||||||
registerTask(command: ITask): IDisposable;
|
registerTask(command: ITask): IDisposable;
|
||||||
getTasks(): string[];
|
getTasks(): string[];
|
||||||
|
onTaskRegistered: Event<string>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const TaskRegistry: ITaskRegistry = new class implements ITaskRegistry {
|
export const TaskRegistry: ITaskRegistry = new class implements ITaskRegistry {
|
||||||
|
|
||||||
private _tasks = new Array<string>();
|
private _tasks = new Array<string>();
|
||||||
|
private _onTaskRegistered = new Emitter<string>();
|
||||||
|
public readonly onTaskRegistered: Event<string> = this._onTaskRegistered.event;
|
||||||
|
|
||||||
registerTask(idOrTask: string | ITask, handler?: ITaskHandler): IDisposable {
|
registerTask(idOrTask: string | ITask, handler?: ITaskHandler): IDisposable {
|
||||||
let disposable: IDisposable;
|
let disposable: IDisposable;
|
||||||
@@ -114,6 +117,7 @@ export const TaskRegistry: ITaskRegistry = new class implements ITaskRegistry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this._tasks.push(id);
|
this._tasks.push(id);
|
||||||
|
this._onTaskRegistered.fire(id);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
dispose: () => {
|
dispose: () => {
|
||||||
|
|||||||
@@ -153,6 +153,8 @@ import 'sql/parts/dashboard/widgets/insights/views/charts/types/scatterChart.con
|
|||||||
import 'sql/parts/dashboard/widgets/insights/views/charts/types/timeSeriesChart.contribution';
|
import 'sql/parts/dashboard/widgets/insights/views/charts/types/timeSeriesChart.contribution';
|
||||||
import 'sql/parts/dashboard/widgets/insights/views/countInsight.contribution';
|
import 'sql/parts/dashboard/widgets/insights/views/countInsight.contribution';
|
||||||
import 'sql/parts/dashboard/widgets/insights/views/imageInsight.contribution';
|
import 'sql/parts/dashboard/widgets/insights/views/imageInsight.contribution';
|
||||||
|
/* Tasks */
|
||||||
|
import 'sql/workbench/common/actions.contribution';
|
||||||
/* Widgets */
|
/* Widgets */
|
||||||
import 'sql/parts/dashboard/widgets/insights/insightsWidget.contribution';
|
import 'sql/parts/dashboard/widgets/insights/insightsWidget.contribution';
|
||||||
import 'sql/parts/dashboard/widgets/explorer/explorerWidget.contribution';
|
import 'sql/parts/dashboard/widgets/explorer/explorerWidget.contribution';
|
||||||
@@ -166,7 +168,5 @@ import 'sql/parts/dashboard/containers/dashboardWidgetContainer.contribution';
|
|||||||
import 'sql/parts/dashboard/containers/dashboardContainer.contribution';
|
import 'sql/parts/dashboard/containers/dashboardContainer.contribution';
|
||||||
import 'sql/parts/dashboard/containers/dashboardNavSection.contribution';
|
import 'sql/parts/dashboard/containers/dashboardNavSection.contribution';
|
||||||
import 'sql/parts/dashboard/common/dashboardTab.contribution';
|
import 'sql/parts/dashboard/common/dashboardTab.contribution';
|
||||||
/* Tasks */
|
|
||||||
import 'sql/workbench/common/actions.contribution';
|
|
||||||
/* Extension Host */
|
/* Extension Host */
|
||||||
import 'sql/workbench/api/electron-browser/sqlExtensionHost.contribution';
|
import 'sql/workbench/api/electron-browser/sqlExtensionHost.contribution';
|
||||||
|
|||||||
Reference in New Issue
Block a user