-
Notifications
You must be signed in to change notification settings - Fork 111
/
Copy pathasset.js
398 lines (338 loc) · 10.1 KB
/
asset.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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
/* ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' *\
* .NN. _____ _____ _____ _ _ This file is part of CGRU
* hMMh / ____/ ____| __ \| | | | - The Free And Open Source CG Tools Pack.
* sMMMMs | | | | __| |__) | | | | CGRU is licensed under the terms of LGPLv3, see files
* <yMMMMMMMMMMMMMMy> | | | |_ | _ /| | | | COPYING and COPYING.lesser inside of this folder.
* `+mMMMMMMMMNo` | |___| |__| | | \ \| |__| | Project-Homepage: http://cgru.info
* :MMMMMMMM: \_____\_____|_| \_\\____/ Sourcecode: https://github.com/CGRU/cgru
* dMMMdmMMMd A F A N A S Y
* -Mmo. -omM: Copyright © by The CGRU team
* ' '
\* ....................................................................................................... */
/*
asset.js - user administration page
*/
"use strict";
var ASSETS = {};
var ASSET = null;
var a_copy_params = {template: {}, destination: {}, name: {}};
function View_asset_Open()
{
a_Show();
}
function View_asset_Close()
{
$('asset').textContent = '';
$('asset_top_left').textContent = '';
}
function a_Process()
{
a_AutoSeek();
a_ShowHeaders();
}
function a_Finish()
{
ASSETS = {};
ASSET = null;
a_SetLabel('Asset');
$('asset_tooltip').style.display = 'none';
$('asset_div').style.display = 'none';
$('asset_top_left').textContent = '';
u_el.assets.innerHTML = '';
u_el.asset.innerHTML = '';
}
function a_SetLabel(i_label)
{
$('asset_label').innerHTML = i_label;
}
function a_SetTooltip(i_info)
{
$('asset_tooltip').style.display = 'block';
$('asset_tooltip').title = i_info;
}
function a_Show()
{
$('asset_div').style.display = 'none';
if (ASSET == null)
return;
if ((ASSET.show_in_subdirectories !== true) && (ASSET.path != g_CurPath()))
return;
if (ASSET.show_files !== true)
$('files_div').style.display = 'none';
$('asset_div').style.display = 'block';
window.document.title = ASSET.name + ' ' + window.document.title;
if (ASSET.scripts)
for (var i = 0; i < ASSET.scripts.length; i++)
{
var script = document.createElement('script');
// script.type = 'text/javascript';
// ga.async = true;
// ga.async = false;
script.src = 'rules/assets/' + ASSET.scripts[i];
var scripts = document.getElementsByTagName('script')[0];
scripts.parentNode.insertBefore(script, scripts);
}
}
function a_Create(i_type, i_name, i_path, i_absolute)
{
var asset = {};
asset.name = i_name;
asset.path = i_path;
asset.type = i_type;
asset.absolute = i_absolute;
c_RulesMergeObjs(asset, RULES.assets[i_type]);
ASSETS[i_type] = asset;
if (ASSET)
{
if (asset.path.length > ASSET.path.length)
ASSET = asset;
}
else
ASSET = asset;
if (i_absolute)
c_Log('Asset specified: ' + i_type + '=' + i_name + ': ' + i_path);
else
c_Log('Asset found: ' + i_type + '=' + i_name + ': ' + i_path);
}
function a_Append(i_path, i_rules)
{
// window.console.log('a_Append: '+ i_path);
// window.console.log( JSON.stringify( i_rules));
for (var rules in i_rules)
for (var attr in i_rules[rules])
{
// window.console.log('attr='+attr);
for (var atype in RULES.assets)
{
// if( ASSETS[atype] ) continue;
if (attr != atype)
continue;
a_Create(atype, RULES[attr], i_path, true);
}
}
}
function a_AutoSeek()
{
var log_console = false;
//log_console = true;
if (log_console)
console.log('a_AutoSeek(): "' + g_CurPath() + '"');
var folders = g_elCurFolder.m_path.split('/');
var path = '';
for (let i = 0; i < folders.length; i++)
{
// Skip "" folder if last is "/".
// "/temp/" should be two "" and "temp", but not three with "" at the end.
if ((folders[i].length == 0) && (i != 0))
continue;
// Construct current path:
if (path == '/')
path += folders[i];
else
path += '/' + folders[i];
if (log_console)
console.log('Asset seeking path: "' + path + '"');
for (let asset_type in RULES.assets)
{
// If such asset type already exists, we skip it.
// ( It can't be two projects )
if (ASSETS[asset_type])
continue;
if (log_console)
console.log('Asset seeking: ' + asset_type);
let seekpaths = RULES.assets[asset_type].seek;
if (seekpaths == null)
continue;
for (let l = 0; l < seekpaths.length; l++)
{
let seekpath = seekpaths[l];
// Replace parent asset name on its path:
// ("[project]/SHOTS" -> "/PRJNAME/SHOTS")
if (seekpath.indexOf('[') !== -1)
{
let replaced = false;
for (let a_type in ASSETS)
{
if (seekpath.indexOf('[' + a_type + ']') !== -1)
{
let seekpath_orig = seekpath;
seekpath = seekpath.replace('[' + a_type + ']', ASSETS[a_type].path);
replaced = true;
if (log_console)
console.log(
'Asset ["' + a_type + '"] in seek path "' + seekpath_orig +
'" replaced on "' + ASSETS[a_type].path + '": ' + seekpath);
}
}
if (false == replaced)
continue;
}
// Seek path can finish with '/' ("[scene]/").
// This means that any folder there is an asset.
// ( any folder in "[scene]/" is a shot asset ).
if (seekpath.lastIndexOf('/') == (seekpath.length - 1))
{
if (i == 0)
continue;
seekpath += folders[i];
}
if (log_console)
console.log(path + ' <> ' + seekpath);
let re = new RegExp('^' + seekpath + '$','i');
if (path.match(re) != null)
{
// Verify whether an asset with the same path exists.
// Prevent adding new asset with the same path.
let exists = false;
for (let asset in ASSETS)
{
if (ASSETS[asset].path == path)
{
// console.log( ASSETS[asset].path + ' == ' + path);
exists = true;
break;
}
}
if (exists)
break;
a_Create(asset_type, folders[i], path, false);
if (log_console)
console.log('Asset "' + asset_type + '" founded: ' + path);
break;
}
}
}
}
}
function a_ShowHeaders()
{
u_el.assets.innerHTML = '';
var assets = [];
for (var a_type in ASSETS)
assets.push(ASSETS[a_type]);
assets.sort(function(a, b) {
if (a.path.length > b.path.length)
return 1;
return -1;
});
for (var i = 0; i < assets.length; i++)
{
var asset = assets[i];
// if( RULES.assets[a_type].showontop === false ) continue;
var a_type = asset.type;
var a_name = asset.name;
var href = '#' + asset.path;
var elHeader = document.createElement('div');
u_el.assets.appendChild(elHeader);
elHeader.classList.add('asset');
var elType = document.createElement('a');
elHeader.appendChild(elType);
elType.classList.add('type');
elType.textContent = a_type + ':';
elType.href = href;
var elName = document.createElement('span');
elHeader.appendChild(elName);
elName.classList.add('name');
elName.innerHTML = c_HighlightBadChars(a_name);
// elName.href = href;
}
}
/* ---------------- [ copy functions ] ------------------------------------------------------------------- */
function a_Copy(i_args)
{
// console.log(JSON.stringify(i_args));
var wnd = new cgru_Window({"name": 'copy', "title": 'Copy Asset'});
wnd.m_args = i_args;
var params = {};
params.template = c_PathPM_Server2Client(i_args.template);
params.name = i_args.name;
if (params.name == null)
{
// Try to increment latest number in name by 10:
// Find all numbers
let numbers = ASSET.name.match(/\d+/g);
if ((numbers != null) && numbers.length)
{
let number = numbers[numbers.length-1];
let numplus = '' + (parseInt(number) + 10);
// Apply padding
while (numplus.length < number.length)
numplus = '0' + numplus;
// Lenght may be bigger on 'SHOT_990'
if (numplus.length == number.length)
params.name = ASSET.name.replace(number, numplus);
// Check if such folder already exists:
if (g_elCurFolder.m_elNext)
if (c_PathBase(g_elCurFolder.m_elNext.m_path) == params.name)
params.name = null;
}
}
if (params.name == null)
params.name = ASSET.name + '-01';
params.destination = i_args.destination;
if (params.destination == null)
params.destination = g_CurPath();
gui_Create(wnd.elContent, a_copy_params, [params]);
var elBtns = document.createElement('div');
wnd.elContent.appendChild(elBtns);
elBtns.style.clear = 'both';
elBtns.classList.add('buttons');
var elCreate = document.createElement('div');
elBtns.appendChild(elCreate);
elCreate.textContent = 'Create';
elCreate.classList.add('button');
elCreate.m_wnd = wnd;
elCreate.onclick = function(e) { a_CopySend(e.currentTarget.m_wnd); };
var elResults = document.createElement('div');
wnd.elContent.appendChild(elResults);
wnd.m_elResults = elResults;
elResults.classList.add('output');
}
function a_CopySend(i_wnd)
{
var params = gui_GetParams(i_wnd.elContent, a_copy_params);
// console.log(JSON.stringify(params));
var elWait = document.createElement('div');
i_wnd.elContent.appendChild(elWait);
i_wnd.m_elWait = elWait;
elWait.classList.add('wait');
var cmd = 'rules/bin/copy.py';
cmd += ' -t "' + c_PathPM_Client2Server(params.template) + '"';
cmd += ' -d "' + c_PathPM_Rules2Server(params.destination) + '"';
cmd += ' ' + params.name;
i_wnd.m_go_path = params.destination + '/' + params.name.split(' ')[0];
n_Request({"send": {"cmdexec": {"cmds": [cmd]}}, "func": a_CopyReceived, "wnd": i_wnd});
// Clear walk cache, as we need to navigate there later:
n_walks[params.destination] = null;
}
function a_CopyReceived(i_data, i_args)
{
// console.log(JSON.stringify(i_data));
i_args.wnd.elContent.removeChild(i_args.wnd.m_elWait);
var elResults = i_args.wnd.m_elResults;
elResults.textContent = '';
if ((i_data.cmdexec == null) || (!i_data.cmdexec.length) || (i_data.cmdexec[0].copy == null))
{
elResults.textContent = (JSON.stringify(i_data));
return;
}
var copy = i_data.cmdexec[0].copy;
if (copy.error)
{
elResults.textContent = 'Error: ' + copy.error;
return;
}
var copies = copy.copies;
if (copies == null)
{
elResults.textContent = 'Error: Copies are null.';
return;
}
if (copies.length == 0)
{
elResults.textContent = 'Error: Copies are empty.';
return;
}
i_args.wnd.destroy();
g_GO(i_args.wnd.m_go_path);
}