This repository has been archived by the owner on Oct 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
extension.js
240 lines (210 loc) · 7.4 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
/* Copyright (c) 2013-present The TagSpaces Authors.
* Use of this source code is governed by the MIT license which can be found in the LICENSE.txt file. */
define(function(require, exports, module) {
"use strict";
var extensionTitle = "FolderViz";
var extensionID = "perspectiveGraph"; // ID should be equal to the directory name where the ext. is located
var extensionIcon = "fa fa-sitemap";
console.log("Loading " + extensionID);
var TSCORE = require("tscore");
var $viewContainer;
var extensionDirectory = TSCORE.Config.getExtensionPath() + "/" + extensionID;
var graphMode = "mindmap";
var treeData;
function init() {
console.log("Initializing View "+extensionID);
$viewContainer = $("#"+extensionID+"Container").empty();
require([
"text!" + extensionDirectory + '/templates.html',
"css!" + extensionDirectory + '/extension.css',
], function(toolbarTPL) {
var toolbarTemplate = Handlebars.compile(toolbarTPL);
$viewContainer.append(toolbarTemplate({ id: extensionID }));
initUI();
try {
$('#' + extensionID + 'Container [data-i18n]').i18n();
$('#aboutExtensionModalGraph').on('show.bs.modal', function() {
$.ajax({
url: extensionDirectory + '/README.md',
type: 'GET'
})
.done(function(mdData) {
var modalBody = $("#aboutExtensionModalGraph .modal-body");
TSCORE.Utils.setMarkDownContent(modalBody, mdData);
})
.fail(function(data) {
console.warn("Loading file failed " + data);
});
});
} catch (err) {
console.log("Failed translating extension");
}
});
}
function handleLinks($element) {
$element.find("a[href]").each(function() {
var currentSrc = $(this).attr("href");
$(this).bind('click', function(e) {
e.preventDefault();
var msg = {command: "openLinkExternally", link : currentSrc};
window.parent.postMessage(JSON.stringify(msg), "*");
});
});
}
function load() {
console.log("Loading View "+extensionID);
treeData = TSCORE.IO.createDirectoryTree(TSCORE.currentPath);
reDraw();
TSCORE.hideLoadingAnimation();
TSCORE.hideWaitingDialog();
}
function reDraw() {
var $viewContainers = $("#viewContainers");
var height = $viewContainers.height() - 5;
var width = $viewContainers.width() - 5;
switch (graphMode) {
case "treeMap":
require([
extensionDirectory+'/treeViz.js',
'css!'+extensionDirectory+'/styles.css',
], function(viz) {
d3.select("svg").remove();
var svg = d3.select("#"+extensionID+"Container")
.append("svg")
.attr("width", width)
.attr("height", height);
viz.drawTreeMap(svg, treeData);
TSCORE.hideLoadingAnimation();
});
break;
case "treeMap2":
require([
extensionDirectory+'/treeMap.js',
'css!'+extensionDirectory+'/styles.css',
], function(viz) {
d3.select("svg").remove();
var svg = d3.select("#"+extensionID+"Container")
.append("svg")
.attr("width", width)
.attr("height", height);
viz.drawZoomableTreeMap(svg, treeData);
TSCORE.hideLoadingAnimation();
});
break;
case "tree":
require([
extensionDirectory+'/treeViz.js',
'css!'+extensionDirectory+'/styles.css',
], function(viz) {
d3.select("svg").remove();
var svg = d3.select("#"+extensionID+"Container")
.append("svg")
.attr("width", width)
.attr("height", height);
viz.drawTree(svg, treeData);
TSCORE.hideLoadingAnimation();
});
break;
case "mindmap":
require([
extensionDirectory+'/mindmap.js',
'css!'+extensionDirectory+'/mindmap.css',
], function(viz) {
d3.select("svg").remove();
var svg = d3.select("#"+extensionID+"Container")
.append("svg")
.attr("id", "tagspacesMindmap")
.attr("width", width)
.attr("height", height);
viz.drawMindMap(svg, treeData);
TSCORE.hideLoadingAnimation();
});
break;
case "bilevelPartition":
require([
extensionDirectory+'/bilevelPartition.js',
'css!'+extensionDirectory+'/styles.css',
], function(viz) {
d3.select("svg").remove();
var svg = d3.select("#"+extensionID+"Container")
.append("svg")
.attr("width", width)
.attr("height", height);
viz.drawPartition(svg, treeData);
TSCORE.hideLoadingAnimation();
});
break;
default:
break;
}
}
function clearSelectedFiles() {
console.log("clearSelectedFiles not implemented in "+extensionID);
}
function removeFileUI(filePath) {
console.log("removeFileUI not implemented in "+extensionID);
}
function updateFileUI(oldFilePath, newFilePath) {
console.log("updateFileUI not implemented in "+extensionID);
}
function getNextFile(filePath) {
console.log("getNextFile not implemented in "+extensionID);
}
function getPrevFile(filePath) {
console.log("getPrevFile not implemented in "+extensionID);
}
function initUI() {
$("#" + extensionID + "ActivateMindmapButton").click(function() {
graphMode = "mindmap";
TSCORE.showLoadingAnimation();
treeData = TSCORE.IO.createDirectoryTree(TSCORE.currentPath);
reDraw();
TSCORE.hideLoadingAnimation();
TSCORE.hideWaitingDialog();
});
$("#" + extensionID + "ActivateTreeMapButton").click(function() {
graphMode = "treeMap";
TSCORE.showLoadingAnimation();
treeData = TSCORE.IO.createDirectoryTree(TSCORE.currentPath);
reDraw();
TSCORE.hideLoadingAnimation();
TSCORE.hideWaitingDialog();
});
$("#" + extensionID + "ActivateTreeMapNaviButton").click(function() {
graphMode = "treeMap2";
TSCORE.showLoadingAnimation();
treeData = TSCORE.IO.createDirectoryTree(TSCORE.currentPath);
reDraw();
TSCORE.hideLoadingAnimation();
TSCORE.hideWaitingDialog();
});
$("#" + extensionID + "ActivateTreeButton").click(function() {
graphMode = "tree";
TSCORE.showLoadingAnimation();
treeData = TSCORE.IO.createDirectoryTree(TSCORE.currentPath);
reDraw();
TSCORE.hideLoadingAnimation();
TSCORE.hideWaitingDialog();
});
$("#" + extensionID + "ActivateBilevelPartitionButton").click(function() {
graphMode = "bilevelPartition";
TSCORE.showLoadingAnimation();
treeData = TSCORE.IO.createDirectoryTree(TSCORE.currentPath);
reDraw();
TSCORE.hideLoadingAnimation();
TSCORE.hideWaitingDialog();
});
}
// API Vars
exports.Title = extensionTitle;
exports.ID = extensionID;
exports.Icon = extensionIcon;
// API Methods
exports.init = init;
exports.load = load;
exports.clearSelectedFiles = clearSelectedFiles;
exports.getNextFile = getNextFile;
exports.getPrevFile = getPrevFile;
exports.removeFileUI = removeFileUI;
exports.updateFileUI = updateFileUI;
});