-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjwebdesk-package-manager.js
executable file
·285 lines (246 loc) · 11 KB
/
jwebdesk-package-manager.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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
define([
"jwebkit",
"jwebdesk",
], function(jwk, jwebdesk) {
/*
if (window.top == window) {
jwebdesk.init();
}
*/
var packManager;
var data;
var selected_package_layout = ["header", ["left", "|%", ["list_panel", "|", "package_panel"]],"footer"];
var no_package_layout = ["header", ["left", "|%", ["list_panel", "|", "no_package_panel"]],"footer"];
var default_icon = jwebdesk.rawURL + "/jwebdesk/jwebdesk-package-manager/alpha-0.5/application_default_icon.png";
// jwebdesk --------------------------------------------------------------------------
jwebdesk.PackManager = function (settings) {
if (!settings) return;
var table = this;
var def = {
"class": "expand",
"ui_type": "jwebdesk-packManager",
"namespace": "jwebdesk"
};
settings = jwk.extend(def, settings);
jwebdesk.App.call(this, settings);
// -------------------------------
// HACK: para separar el jwk del jwk.ui
var c = new jwk.ui.Component();
for (var i in c) {
if (typeof c[i] == "function" && typeof this[i] == "undefined") {
this[i] = c[i];
}
}
jwk.ui.Component.call(this, settings);
// -------------------------------
document.body.removeAttribute("loading");
console.assert(this.proxy);
this.proxy.on("command", function (n,e){
// app.container().target.append($("<span>").text("Submenu Command: ", e.command));
console.log("Submenu Command: ", e.command);
});
data = new jwk.Object();
data.set("search", "");
data.set("packages.labels", ["Owner", "Name", "Version", "Type", "Codetype", "Brief", "Date"], {deep: true});
data.set("packages.fields", ["owner", "name", "version", "type", "codetype", "brief", "date"], {deep: true});
data.set("packages.rows", [], {deep: true});
data.set("package.visible", false, {deep: true});
data.set("main_layout", no_package_layout);
jwebdesk.wait_service("user-auth").then(function (user) {
// console.error("aaaaaaaaaaaaaaaaaa", [user]);
return user.logged();
}).then(function (is_logged, user) {
// console.error("aaaaaaaaaaaaaaaaaa", [user]);
if (is_logged) return user;
return {id: 0};
}).then(function (user) {
// console.error("aaaaaaaaaaaaaaaaaa", [user]);
jwebdesk.repository.list(/*{
"left": {"prop":"state", "equals":"prod"},
"op": "or",
"right": {"prop":"publisher","equals":user.id}
}*/).done(function (lista) {
var _packages = [];
for (package_path in lista) {
package_json = lista[package_path];
try {
if (typeof package_json == "string") {
package_json = JSON.parse(package_json);
console.error("ESTO SE USA????");
}
} catch (err) {
console.error("ERROR: trying to parse JSON: ", err.message, [package_json]);
}
package_json.path = package_path;
_packages.push(package_json);
}
console.log("data.packages.rows", [_packages]);
data.set("packages.rows", _packages, {deep: true});
});
});
}
jwebdesk.PackManager.prototype = new jwebdesk.App();
jwebdesk.PackManager.prototype.constructor = jwebdesk.PackManager;
var start_pkg_config_node = "/config/vapaee/jwebdesk/alpha-0.5";
jwebdesk.PackManager.prototype.install = function (package) {
return jwebdesk.wait_service("package-manager").done(function(manager) {
manager.install(package);
});
}
jwebdesk.PackManager.prototype.uninstall = function (package) {
return jwebdesk.wait_service("package-manager").done(function(manager) {
manager.uninstall(package);
});
}
jwebdesk.PackManager.prototype.structure_tree = function () {
var manager = this;
this.on("change:structure", function (n, e) {
var structure = e.value;
structure.search("pack_list").on("selection", function (n,e) {
var obj = data.packages.rows[e.index];
obj.icon = obj.icon || default_icon;
data.set("selected", new jwk.Object(obj));
});
/*
structure.search("btn_open_app").on("click", function (n,e) {
jwebdesk.open_app(data.get("package.path"));
});
structure.search("btn_install").on("click", function (n,e) {
manager.install(data.get("selected").valueOf().path).done(function () {
data.set("package.installed", true);
data.set("package.not_installed", false);
});
});
structure.search("btn_uninstall").on("click", function (n,e) {
manager.uninstall(data.get("selected").valueOf().path).done(function () {
data.set("package.installed", false);
data.set("package.not_installed", true);
});
});
structure.search("btn_clone_package").on("click", function (n,e) {
});
*/
structure.search("btn_create").on("click", function (n,e) {
jwebdesk.open_app("jwebdesk-package-wizard");
});
});
return {
"data": data,
"disable_selection": true,
"class": "expand b3",
"name": "structure",
"ui_type": "panel.inset",
"namespace": "jwk-ui",
"children": {
"main_layout": {
"start": "col",
"layout": ["header", ["left", "|", ["list_panel", "|", "package_panel"]],"footer"],
"ui_type": "panel.layout",
"class": "expand",
"children": {
"header": {
"class": "expand",
"ui_type": "panel",
"children": {
"btn_refresh": {
"ui_type": "button",
"text": "Refresh"
},
"big_title": {
"ui_type": "label",
"text": "Fast Filter"
},
"input_search": {
"ui_type": "input",
"datapath": "search"
},
"btn_search": {
"ui_type": "button",
"text": "Search"
},
"btn_create": {
"ui_type": "button",
"text": "Create Package"
}
}
},
"left": {
"class": "expand",
"ui_type": "panel.inset",
"children": {
"btn_1": {
"ui_type": "button",
"text": "Useless button"
},
"btn_2": {
"ui_type": "button",
"text": "harmless"
},
"btn_3": {
"ui_type": "button",
"text": "Don't press this one"
}
}
},
"list_panel": {
"class": "expand",
"ui_type": "panel.inset",
"children": {
"pack_list": {
"ui_type": "table",
"class": "expand",
"labels": "<<data.packages.labels>>",
"fields": "<<data.packages.fields>>",
"value": "<<data.packages.rows>>"
}
}
},
"no_package_panel": {
"class": "expand",
"ui_type": "panel.inset"
},
"package_panel": {
"class": "expand",
"ui_type": "panel.inset",
"children": {
"p_scroll": {
"style": "top: 5px; left: 5px; right: 5px; bottom: 5px; position: absolute",
"ui_type": "panel.scroll",
"children": {
"package_view": {
"class": "jwk-ui expand",
"ui_type": "package.view",
"namespace": "jwebdesk",
"value": "<<data.selected>>"
}
}
}
}
},
"footer": {
"class": "expand",
"ui_type": "panel",
}
}
}
}
};
}
jwebdesk.PackManager.prototype.parent_for = function (name, index) {
switch (name) {
case "structure":
return {parent:this};
}
return {parent:this.get("structure"), query:".content"};
}
jwk.ui.component({
ui_type: "jwebdesk-packmanager",
namespace: "jwebdesk",
constructor: jwebdesk.PackManager
});
packManager = jwk.ui.display_component({
"ui_type": "jwebdesk-packmanager",
"namespace": "jwebdesk"
});
return packManager.get("main");
});