-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathworkspace.js
More file actions
96 lines (77 loc) · 2.5 KB
/
Copy pathworkspace.js
File metadata and controls
96 lines (77 loc) · 2.5 KB
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
var util = require("./util");
var Workspace = module.exports = function(config) {
if (config)
for (var prop in config)
this[prop] = config[prop];
else
throw new Error("No parameters were passed to Workspace.");
this.init();
};
(function() {
this.init = function() {
this.workspaceId = this.ide.options.workspaceId;
this.workspaceDir = this.ide.options.workspaceDir;
};
this.createPlugins = function (plugins) {
this.plugins = {};
for (var name in plugins) {
this.plugins[name] = new plugins[name](this.ide, this);
}
for (var name in plugins) {
if (this.plugins[name].init)
this.plugins[name].init();
}
};
this.getServerExclude = function(user) {
return util.arrayToMap(user.getPermissions().server_exclude.split("|"));
};
this.execHook = function(hook, user /* varargs */) {
var args = Array.prototype.slice.call(arguments, 1);
var hook = hook.toLowerCase().trim();
var server_exclude = this.getServerExclude(user);
for (var name in this.plugins) {
if (server_exclude[name]) continue;
var plugin = this.plugins[name];
var hooks = plugin.getHooks();
if (hooks.indexOf(hook) > -1 && plugin[hook].apply(plugin, args) === true) {
return;
}
}
};
this.getExt = function(name) {
return this.plugins[name] || null;
};
this.send = function(msg, replyTo, scope) {
if (replyTo)
msg.sid = replyTo.sid;
this.ide.broadcast(JSON.stringify(msg), scope);
};
this.sendError = function(error, client) {
if (client)
client.send(JSON.stringify(error));
else
this.ide.broadcast(error);
};
this.error = function(description, code, message, client) {
var sid = (message || {}).sid || -1;
var error = {
"type": "error",
"sid": sid,
"code": code,
"message": description
};
this.sendError(error, client || null);
};
this.dispose = function(callback) {
var count;
for (var name in this.plugins) {
count += 1;
this.plugins[name].dispose(function() {
count -= 1;
if (count == 0)
callback();
});
}
//this.ide.davServer.unmount();
};
}).call(Workspace.prototype);