-
Notifications
You must be signed in to change notification settings - Fork 1
/
extension.js
129 lines (113 loc) · 4.3 KB
/
extension.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
var vscode = require('vscode')
var http = require('./src/http/thingworx.js')
var statusbar = require('./src/utils/statusbar')
var extractor = require('./src/thingworx/extract')
var enetitieTreeDataProvier = require('./src/providers/treeprovider')
var webViewContentProvider = require('./src/stats/webviewcontent')
// This method is called when your extension is activated
// Your extension is activated the ver y first time the command is executed
/**
* @param {vscode.ExtensionContext} context
*/
function activate(context) {
// Command to start export from thingWorx server
let entityPullAndExtractCommand = vscode.commands.registerCommand('thingworxvcs.export', function () {
// The code you place here will be executed every time your command is executed
statusbar.text = '$(accounts-view-bar-icon~spin)Pulling entities';
http.exportEntities('DBFinder', false);
setTimeout(() => { http.getDownloadableZipFileLink(false) }, 5000);
});
context.subscriptions.push(entityPullAndExtractCommand);
// Command to extract content from the downloaded .zip file
let entitiesExtractionCommand = vscode.commands.registerCommand('thingworxvcs.extract', function () {
// The code you place here will be executed every time your command is executed
extractor.extract()
});
context.subscriptions.push(entitiesExtractionCommand);
// Command to activate the extension
let activateExtension = vscode.commands.registerCommand('thingworxvcs.activate', function () {
vscode.window.showInformationMessage('ThingWorx VCS extension started!');
});
context.subscriptions.push(activateExtension);
// Dont see any usage now can be used mopre efficiently later
// Tree View for the extension to show extracted and non-extracted entities
var entitiesDataProvider = new enetitieTreeDataProvier.EntitiesTreeViewProvider();
var treeView = vscode.window.createTreeView('entities', {
treeDataProvider: entitiesDataProvider,
showCollapseAll: true
});
vscode.commands.registerCommand('thingworxvcs.refresh', function () {
entitiesDataProvider.refresh()
});
treeView.onDidChangeSelection(async (e) => {
var file = e.selection[0].resourceUri
var name = e.selection[0].label;
console.log(name)
if (name.indexOf('.js') > -1 || name.indexOf('.sql') > -1 || name.indexOf('.xml') > -1)
await vscode.commands.executeCommand('vscode.open', file);
})
// For the WebView
let currentPanel = undefined;
webViewCommand = vscode.commands.registerCommand('thingworxvcs.stats', () => {
const columnToShowIn = vscode.window.activeTextEditor
? vscode.window.activeTextEditor.viewColumn
: undefined;
if (currentPanel) {
// If we already have a panel, show it in the target column
currentPanel.reveal(columnToShowIn);
} else {
// Create and show a new webview
currentPanel = vscode.window.createWebviewPanel(
'codestats', // Identifies the type of the webview. Used internally
'ThingWorx Entities Details', // Title of the panel displayed to the user
vscode.ViewColumn.One, // Editor column to show the new webview panel in.
{
// Enable scripts in the webview
enableScripts: true
}// Webview options. More on these later.
);
webViewContentProvider.setWebViewContent(context, currentPanel);
currentPanel.onDidDispose(
() => {
currentPanel = undefined;
},
undefined,
context.subscriptions
);
// Messaging to the WEB UI
currentPanel.webview.onDidReceiveMessage(
message => {
switch (message.command) {
case "git-push":
break;
case "git-pull":
break;
case "twx-fetch":
vscode.window.showInformationMessage('Entities will be downloaded and services will be extracted.')
vscode.commands.executeCommand("thingworxvcs.export").then(()=>{
vscode.commands.executeCommand("thingworxvcs.extract").then(() => {
currentPanel.webview.postMessage({ command: 'twx-fetch-done' });
})
})
break;
default:
break;
}
},
undefined,
context.subscriptions
);
}
})
context.subscriptions.push(
webViewCommand
);
}
// This method is called when your extension is deactivated
function deactivate() { }
module.exports = {
activate,
deactivate
}