mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-03-16 19:11:39 -04:00
* Fix #6477 controller login + fix dashboard layout - Service endpoints shoudl be on own column, cut off smaller screen - Controller login not working due to 404 error This is due to a breaking API change We have requested fixes to help mitigate need for cluster name, but for now have a default value for this Finally, modified code so it's easier to update swagger API and also added instructions on how to update in future
109 lines
3.9 KiB
TypeScript
109 lines
3.9 KiB
TypeScript
/*---------------------------------------------------------------------------------------------
|
|
* 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 * as vscode from 'vscode';
|
|
import * as nls from 'vscode-nls';
|
|
import { ControllerTreeDataProvider } from './bigDataCluster/tree/controllerTreeDataProvider';
|
|
import { IconPath } from './bigDataCluster/constants';
|
|
import { TreeNode } from './bigDataCluster/tree/treeNode';
|
|
import { AddControllerDialogModel, AddControllerDialog } from './bigDataCluster/dialog/addControllerDialog';
|
|
import { ControllerNode } from './bigDataCluster/tree/controllerTreeNode';
|
|
|
|
const localize = nls.loadMessageBundle();
|
|
|
|
const AddControllerCommand = 'bigDataClusters.command.addController';
|
|
const DeleteControllerCommand = 'bigDataClusters.command.deleteController';
|
|
const RefreshControllerCommand = 'bigDataClusters.command.refreshController';
|
|
|
|
let throttleTimers: { [key: string]: any } = {};
|
|
|
|
export function activate(extensionContext: vscode.ExtensionContext) {
|
|
IconPath.setExtensionContext(extensionContext);
|
|
let treeDataProvider = new ControllerTreeDataProvider(extensionContext.globalState);
|
|
|
|
registerTreeDataProvider(treeDataProvider);
|
|
registerCommands(treeDataProvider);
|
|
}
|
|
|
|
export function deactivate() {
|
|
}
|
|
|
|
function registerTreeDataProvider(treeDataProvider: ControllerTreeDataProvider): void {
|
|
vscode.window.registerTreeDataProvider('sqlBigDataCluster', treeDataProvider);
|
|
}
|
|
|
|
function registerCommands(treeDataProvider: ControllerTreeDataProvider): void {
|
|
vscode.commands.registerCommand(AddControllerCommand, (node?: TreeNode) => {
|
|
runThrottledAction(AddControllerCommand, () => addBdcController(treeDataProvider, node));
|
|
});
|
|
|
|
vscode.commands.registerCommand(DeleteControllerCommand, (node: TreeNode) => {
|
|
deleteBdcController(treeDataProvider, node);
|
|
});
|
|
|
|
vscode.commands.registerCommand(RefreshControllerCommand, (node: TreeNode) => {
|
|
if (!node) {
|
|
return;
|
|
}
|
|
treeDataProvider.notifyNodeChanged(node);
|
|
});
|
|
}
|
|
|
|
function addBdcController(treeDataProvider: ControllerTreeDataProvider, node?: TreeNode): void {
|
|
let model = new AddControllerDialogModel(treeDataProvider, node);
|
|
let dialog = new AddControllerDialog(model);
|
|
dialog.showDialog();
|
|
}
|
|
|
|
async function deleteBdcController(treeDataProvider: ControllerTreeDataProvider, node: TreeNode): Promise<boolean> {
|
|
if (!node && !(node instanceof ControllerNode)) {
|
|
return;
|
|
}
|
|
|
|
let controllerNode = node as ControllerNode;
|
|
|
|
let choices: { [id: string]: boolean } = {};
|
|
choices[localize('textYes', 'Yes')] = true;
|
|
choices[localize('textNo', 'No')] = false;
|
|
|
|
let options = {
|
|
ignoreFocusOut: false,
|
|
placeHolder: localize('textConfirmDeleteController', 'Are you sure you want to delete \'{0}\'?', controllerNode.label)
|
|
};
|
|
|
|
let result = await vscode.window.showQuickPick(Object.keys(choices), options);
|
|
let remove: boolean = !!(result && choices[result]);
|
|
if (remove) {
|
|
deleteControllerInternal(treeDataProvider, controllerNode);
|
|
}
|
|
return remove;
|
|
}
|
|
|
|
function deleteControllerInternal(treeDataProvider: ControllerTreeDataProvider, controllerNode: ControllerNode): void {
|
|
let deleted = treeDataProvider.deleteController(controllerNode.url, controllerNode.username);
|
|
if (deleted) {
|
|
treeDataProvider.saveControllers();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* Throttles actions to avoid bug where on clicking in tree, action gets called twice
|
|
* instead of once. Any right-click action is safe, just the default on-click action in a tree
|
|
*/
|
|
function runThrottledAction(id: string, action: () => void) {
|
|
let timer = throttleTimers[id];
|
|
if (!timer) {
|
|
throttleTimers[id] = timer = setTimeout(() => {
|
|
action();
|
|
clearTimeout(timer);
|
|
throttleTimers[id] = undefined;
|
|
}, 150);
|
|
}
|
|
// else ignore this as we got an identical action in the last 150ms
|
|
} |