@oat-sa/tao-core-ui 3.20.0 → 3.21.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -242,7 +242,7 @@ define(['jquery', 'lodash', 'core/request', 'ui/pagination', 'handlebars', 'lib/
242
242
  $selected.parent('li').addClass('active');
243
243
 
244
244
  //internal event to set the file-selector content
245
- updateSelectedClass(fullPath, subTree.total, $selected.data('children-limit'));
245
+ updateSelectedClass(fullPath, content.total, content.childrenLimit);
246
246
  $container.trigger(`folderselect.${ns}`, [content.label, getPage(content.children), content.path, content]);
247
247
  renderPagination();
248
248
  }
@@ -267,9 +267,11 @@ define(['jquery', 'lodash', 'core/request', 'ui/pagination', 'handlebars', 'lib/
267
267
  // if not all, new file will be loaded with next page
268
268
  subTree.children.push(file);
269
269
  }
270
- subTree.total++;
271
- selectedClass.total++;
272
- $container.trigger(`folderselect.${ns}`, [subTree.label, getPage(subTree.children), path]);
270
+ subTree.total = Number.isFinite(Number(subTree.total)) ? Number(subTree.total) + 1 : 1;
271
+ if (selectedClass.path === path) {
272
+ selectedClass.total = subTree.total;
273
+ }
274
+ $container.trigger(`folderselect.${ns}`, [subTree.label, getPage(subTree.children), path, subTree]);
273
275
  renderPagination();
274
276
  }
275
277
  }
@@ -328,7 +330,9 @@ define(['jquery', 'lodash', 'core/request', 'ui/pagination', 'handlebars', 'lib/
328
330
  return !!item.uri;
329
331
  });
330
332
  setToPath(tree, path, {
331
- children: loadedFiles
333
+ children: loadedFiles,
334
+ total: data.total,
335
+ childrenLimit: data.childrenLimit
332
336
  });
333
337
  content = getByPath(tree, path);
334
338
  cb(content);
@@ -392,7 +396,12 @@ define(['jquery', 'lodash', 'core/request', 'ui/pagination', 'handlebars', 'lib/
392
396
  if (tree) {
393
397
  if (tree.path === path) {
394
398
  tree.children = tree.children ? tree.children.concat(data.children) : data.children;
395
- tree.total = data.total;
399
+ if (Object.prototype.hasOwnProperty.call(data, 'total')) {
400
+ tree.total = data.total;
401
+ }
402
+ if (Object.prototype.hasOwnProperty.call(data, 'childrenLimit')) {
403
+ tree.childrenLimit = data.childrenLimit;
404
+ }
396
405
  } else if (tree.children) {
397
406
  _.forEach(tree.children, function (child) {
398
407
  done = setToPath(child, path, data);
@@ -483,10 +492,12 @@ define(['jquery', 'lodash', 'core/request', 'ui/pagination', 'handlebars', 'lib/
483
492
  * @param {Number} childrenLimit - page size
484
493
  */
485
494
  function updateSelectedClass(path, total, childrenLimit) {
495
+ const normalizedTotal = Number(total);
496
+ const normalizedChildrenLimit = Number(childrenLimit);
486
497
  selectedClass = {
487
498
  path,
488
- total,
489
- childrenLimit,
499
+ total: Number.isFinite(normalizedTotal) && normalizedTotal >= 0 ? normalizedTotal : 0,
500
+ childrenLimit: Number.isFinite(normalizedChildrenLimit) && normalizedChildrenLimit > 0 ? normalizedChildrenLimit : selectedClass.childrenLimit || 10,
490
501
  page: 1
491
502
  };
492
503
  }
@@ -495,9 +506,14 @@ define(['jquery', 'lodash', 'core/request', 'ui/pagination', 'handlebars', 'lib/
495
506
  */
496
507
  function renderPagination() {
497
508
  const $paginationContainer = $$1('.pagination-bottom', $container);
509
+ const total = Number(selectedClass.total);
510
+ const childrenLimit = Number(selectedClass.childrenLimit);
498
511
  $paginationContainer.empty();
499
- const totalPages = Math.ceil(selectedClass.total / selectedClass.childrenLimit);
500
- if (selectedClass.total && totalPages > 1) {
512
+ if (!Number.isFinite(total) || !Number.isFinite(childrenLimit) || childrenLimit <= 0) {
513
+ return;
514
+ }
515
+ const totalPages = Math.ceil(total / childrenLimit);
516
+ if (total > 0 && totalPages > 1) {
501
517
  paginationComponent({
502
518
  mode: 'simple',
503
519
  activePage: selectedClass.page,
@@ -375,19 +375,16 @@ define(['jquery', 'lodash', 'async', 'i18n', 'core/mimetype', 'handlebars', 'lib
375
375
  function setUpUploader(currentPath) {
376
376
  let errors = [];
377
377
  let $switcher = $$1('.upload-switcher a', $fileSelector);
378
+ let isUploadMode = false;
378
379
  $uploader.on('upload.uploader', function (e, file, result) {
379
- let path = $$1(`[data-display="${currentPath}"]`).data('path') || $$1(`[data-display="/${currentPath}"]`).data('path');
380
- if (!path) {
381
- path = currentPath;
382
- }
383
- $container.trigger(`filenew.${ns}`, [result, path]);
380
+ $container.trigger(`filenew.${ns}`, [result, currentPath]);
384
381
  });
385
382
  $uploader.on('fail.uploader', function (e, file, err) {
386
383
  errors.push(__('Unable to upload file %s : %s', file.name, err.message));
387
384
  });
388
385
  $uploader.on('end.uploader', function () {
389
386
  if (errors.length === 0) {
390
- _.delay(switchUpload, 500);
387
+ setUploadMode(false);
391
388
  } else {
392
389
  feedback().error(`<ul><li>${errors.join('</li><li>')}</li></ul>`, {
393
390
  encodeHtml: false
@@ -461,8 +458,9 @@ define(['jquery', 'lodash', 'async', 'i18n', 'core/mimetype', 'handlebars', 'lib
461
458
  uploadUrl: `${options.uploadUrl}?${$$1.param(options.params)}&${options.pathParam}=${currentPath}&relPath=${currentPath}`
462
459
  });
463
460
  });
464
- function switchUpload() {
465
- if ($fileContainer.css('display') === 'none') {
461
+ function setUploadMode(enableUploadMode) {
462
+ if (!enableUploadMode) {
463
+ isUploadMode = false;
466
464
  $uploader.hide();
467
465
  $fileContainer.show();
468
466
  // Note: show() would display as inline, not inline-block!
@@ -472,6 +470,7 @@ define(['jquery', 'lodash', 'async', 'i18n', 'core/mimetype', 'handlebars', 'lib
472
470
  $switcher.filter('.listing').hide();
473
471
  $browserTitle.text(__('Browse folders:'));
474
472
  } else {
473
+ isUploadMode = true;
475
474
  $fileContainer.hide();
476
475
  $placeholder.hide();
477
476
  $uploader.show();
@@ -487,8 +486,13 @@ define(['jquery', 'lodash', 'async', 'i18n', 'core/mimetype', 'handlebars', 'lib
487
486
  //switch to upload mode
488
487
  $switcher.click(function (e) {
489
488
  e.preventDefault();
490
- switchUpload();
489
+ if ($$1(this).hasClass('upload')) {
490
+ setUploadMode(true);
491
+ } else if ($$1(this).hasClass('listing')) {
492
+ setUploadMode(false);
493
+ }
491
494
  });
495
+ setUploadMode(isUploadMode);
492
496
  }
493
497
  function updateFiles(path, files) {
494
498
  $fileContainer.empty();
@@ -87,9 +87,28 @@ define(['jquery', 'lodash', 'i18n', 'ui/report', 'ui/feedback', 'layout/loading-
87
87
  loadingBar.start();
88
88
  taskQueue.pollAllStop();
89
89
  taskQueue.create(requestUrl, requestData).then(function (result) {
90
- var infoBox,
91
- message,
90
+ var message,
92
91
  task = result.task;
92
+
93
+ /**
94
+ * Creates feedback box and notifies task queue listeners.
95
+ * @param {Object} taskData
96
+ * @param {String} feedbackMessage
97
+ * @param {String} feedbackType
98
+ * @returns {void}
99
+ */
100
+ var notifyTaskCreated = function notifyTaskCreated(taskData, feedbackMessage, feedbackType) {
101
+ var box = feedback(null, {
102
+ encodeHtml: false,
103
+ timeout: {
104
+ [feedbackType]: 8000
105
+ }
106
+ })[feedbackType](feedbackMessage);
107
+ taskQueue.trigger('taskcreated', {
108
+ task: taskData,
109
+ sourceDom: box.getElement()
110
+ });
111
+ };
93
112
  if (result.finished) {
94
113
  if (task.hasFile) {
95
114
  //download if its is a export-typed task
@@ -104,7 +123,8 @@ define(['jquery', 'lodash', 'i18n', 'ui/report', 'ui/feedback', 'layout/loading-
104
123
  taskQueue.pollAll();
105
124
  });
106
125
  } else {
107
- //immediately archive the finished task as there is no need to display this task in the queue list
126
+ message = __('<strong> %s </strong> has been completed.', _.escape(task.taskLabel));
127
+ notifyTaskCreated(task, message, 'success');
108
128
  taskQueue.archive(task.id).then(function () {
109
129
  self.trigger('finished', result);
110
130
  taskQueue.pollAll();
@@ -115,17 +135,8 @@ define(['jquery', 'lodash', 'i18n', 'ui/report', 'ui/feedback', 'layout/loading-
115
135
  }
116
136
  } else {
117
137
  //enqueuing process:
118
- message = __('<strong> %s </strong> has been moved to the background.', task.taskLabel);
119
- infoBox = feedback(null, {
120
- encodeHtml: false,
121
- timeout: {
122
- info: 8000
123
- }
124
- }).info(message);
125
- taskQueue.trigger('taskcreated', {
126
- task: task,
127
- sourceDom: infoBox.getElement()
128
- });
138
+ message = __('<strong> %s </strong> has been moved to the background.', _.escape(task.taskLabel));
139
+ notifyTaskCreated(task, message, 'info');
129
140
  self.trigger('enqueued', result);
130
141
  }
131
142
  loadingBar.stop();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oat-sa/tao-core-ui",
3
- "version": "3.20.0",
3
+ "version": "3.21.1",
4
4
  "displayName": "TAO Core UI",
5
5
  "description": "UI libraries of TAO",
6
6
  "scripts": {
@@ -107,7 +107,7 @@ export default function (options) {
107
107
  $selected.parent('li').addClass('active');
108
108
 
109
109
  //internal event to set the file-selector content
110
- updateSelectedClass(fullPath, subTree.total, $selected.data('children-limit'));
110
+ updateSelectedClass(fullPath, content.total, content.childrenLimit);
111
111
  $container.trigger(`folderselect.${ns}`, [
112
112
  content.label,
113
113
  getPage(content.children),
@@ -137,9 +137,11 @@ export default function (options) {
137
137
  // if not all, new file will be loaded with next page
138
138
  subTree.children.push(file);
139
139
  }
140
- subTree.total++;
141
- selectedClass.total++;
142
- $container.trigger(`folderselect.${ns}`, [subTree.label, getPage(subTree.children), path]);
140
+ subTree.total = Number.isFinite(Number(subTree.total)) ? Number(subTree.total) + 1 : 1;
141
+ if (selectedClass.path === path) {
142
+ selectedClass.total = subTree.total;
143
+ }
144
+ $container.trigger(`folderselect.${ns}`, [subTree.label, getPage(subTree.children), path, subTree]);
143
145
  renderPagination();
144
146
  }
145
147
  }
@@ -201,7 +203,11 @@ export default function (options) {
201
203
  const loadedFiles = _.filter(data.children, function (item) {
202
204
  return !!item.uri;
203
205
  });
204
- setToPath(tree, path, { children: loadedFiles });
206
+ setToPath(tree, path, {
207
+ children: loadedFiles,
208
+ total: data.total,
209
+ childrenLimit: data.childrenLimit
210
+ });
205
211
  content = getByPath(tree, path);
206
212
  cb(content);
207
213
  });
@@ -263,7 +269,12 @@ export default function (options) {
263
269
  if (tree) {
264
270
  if (tree.path === path) {
265
271
  tree.children = tree.children ? tree.children.concat(data.children) : data.children;
266
- tree.total = data.total;
272
+ if (Object.prototype.hasOwnProperty.call(data, 'total')) {
273
+ tree.total = data.total;
274
+ }
275
+ if (Object.prototype.hasOwnProperty.call(data, 'childrenLimit')) {
276
+ tree.childrenLimit = data.childrenLimit;
277
+ }
267
278
  } else if (tree.children) {
268
279
  _.forEach(tree.children, function (child) {
269
280
  done = setToPath(child, path, data);
@@ -356,10 +367,16 @@ export default function (options) {
356
367
  * @param {Number} childrenLimit - page size
357
368
  */
358
369
  function updateSelectedClass(path, total, childrenLimit) {
370
+ const normalizedTotal = Number(total);
371
+ const normalizedChildrenLimit = Number(childrenLimit);
372
+
359
373
  selectedClass = {
360
374
  path,
361
- total,
362
- childrenLimit,
375
+ total: Number.isFinite(normalizedTotal) && normalizedTotal >= 0 ? normalizedTotal : 0,
376
+ childrenLimit:
377
+ Number.isFinite(normalizedChildrenLimit) && normalizedChildrenLimit > 0
378
+ ? normalizedChildrenLimit
379
+ : selectedClass.childrenLimit || 10,
363
380
  page: 1
364
381
  };
365
382
  }
@@ -368,10 +385,18 @@ export default function (options) {
368
385
  */
369
386
  function renderPagination() {
370
387
  const $paginationContainer = $('.pagination-bottom', $container);
388
+ const total = Number(selectedClass.total);
389
+ const childrenLimit = Number(selectedClass.childrenLimit);
390
+
371
391
  $paginationContainer.empty();
372
- const totalPages = Math.ceil(selectedClass.total / selectedClass.childrenLimit);
373
392
 
374
- if (selectedClass.total && totalPages > 1) {
393
+ if (!Number.isFinite(total) || !Number.isFinite(childrenLimit) || childrenLimit <= 0) {
394
+ return;
395
+ }
396
+
397
+ const totalPages = Math.ceil(total / childrenLimit);
398
+
399
+ if (total > 0 && totalPages > 1) {
375
400
  paginationComponent({
376
401
  mode: 'simple',
377
402
  activePage: selectedClass.page,
@@ -231,14 +231,10 @@ export default function (options) {
231
231
  function setUpUploader(currentPath) {
232
232
  let errors = [];
233
233
  let $switcher = $('.upload-switcher a', $fileSelector);
234
+ let isUploadMode = false;
234
235
 
235
236
  $uploader.on('upload.uploader', function (e, file, result) {
236
- let path =
237
- $(`[data-display="${currentPath}"]`).data('path') || $(`[data-display="/${currentPath}"]`).data('path');
238
- if (!path) {
239
- path = currentPath;
240
- }
241
- $container.trigger(`filenew.${ns}`, [result, path]);
237
+ $container.trigger(`filenew.${ns}`, [result, currentPath]);
242
238
  });
243
239
  $uploader.on('fail.uploader', function (e, file, err) {
244
240
  errors.push(__('Unable to upload file %s : %s', file.name, err.message));
@@ -246,7 +242,7 @@ export default function (options) {
246
242
 
247
243
  $uploader.on('end.uploader', function () {
248
244
  if (errors.length === 0) {
249
- _.delay(switchUpload, 500);
245
+ setUploadMode(false);
250
246
  } else {
251
247
  feedback().error(`<ul><li>${errors.join('</li><li>')}</li></ul>`, { encodeHtml: false });
252
248
  }
@@ -333,8 +329,9 @@ export default function (options) {
333
329
  });
334
330
  });
335
331
 
336
- function switchUpload() {
337
- if ($fileContainer.css('display') === 'none') {
332
+ function setUploadMode(enableUploadMode) {
333
+ if (!enableUploadMode) {
334
+ isUploadMode = false;
338
335
  $uploader.hide();
339
336
  $fileContainer.show();
340
337
  // Note: show() would display as inline, not inline-block!
@@ -342,6 +339,7 @@ export default function (options) {
342
339
  $switcher.filter('.listing').hide();
343
340
  $browserTitle.text(__('Browse folders:'));
344
341
  } else {
342
+ isUploadMode = true;
345
343
  $fileContainer.hide();
346
344
  $placeholder.hide();
347
345
  $uploader.show();
@@ -355,8 +353,14 @@ export default function (options) {
355
353
  //switch to upload mode
356
354
  $switcher.click(function (e) {
357
355
  e.preventDefault();
358
- switchUpload();
356
+ if ($(this).hasClass('upload')) {
357
+ setUploadMode(true);
358
+ } else if ($(this).hasClass('listing')) {
359
+ setUploadMode(false);
360
+ }
359
361
  });
362
+
363
+ setUploadMode(isUploadMode);
360
364
  }
361
365
 
362
366
  function updateFiles(path, files) {
@@ -86,10 +86,25 @@ var taskableComponent = {
86
86
  taskQueue
87
87
  .create(requestUrl, requestData)
88
88
  .then(function(result) {
89
- var infoBox,
90
- message,
89
+ var message,
91
90
  task = result.task;
92
91
 
92
+ /**
93
+ * Creates feedback box and notifies task queue listeners.
94
+ * @param {Object} taskData
95
+ * @param {String} feedbackMessage
96
+ * @param {String} feedbackType
97
+ * @returns {void}
98
+ */
99
+ var notifyTaskCreated = function notifyTaskCreated(taskData, feedbackMessage, feedbackType) {
100
+ var box = feedback(null, {
101
+ encodeHtml: false,
102
+ timeout: { [feedbackType]: 8000 }
103
+ })[feedbackType](feedbackMessage);
104
+
105
+ taskQueue.trigger('taskcreated', { task: taskData, sourceDom: box.getElement() });
106
+ };
107
+
93
108
  if (result.finished) {
94
109
  if (task.hasFile) {
95
110
  //download if its is a export-typed task
@@ -108,7 +123,8 @@ var taskableComponent = {
108
123
  taskQueue.pollAll();
109
124
  });
110
125
  } else {
111
- //immediately archive the finished task as there is no need to display this task in the queue list
126
+ message = __('<strong> %s </strong> has been completed.', _.escape(task.taskLabel));
127
+ notifyTaskCreated(task, message, 'success');
112
128
  taskQueue
113
129
  .archive(task.id)
114
130
  .then(function() {
@@ -122,13 +138,8 @@ var taskableComponent = {
122
138
  }
123
139
  } else {
124
140
  //enqueuing process:
125
- message = __('<strong> %s </strong> has been moved to the background.', task.taskLabel);
126
- infoBox = feedback(null, {
127
- encodeHtml: false,
128
- timeout: { info: 8000 }
129
- }).info(message);
130
-
131
- taskQueue.trigger('taskcreated', { task: task, sourceDom: infoBox.getElement() });
141
+ message = __('<strong> %s </strong> has been moved to the background.', _.escape(task.taskLabel));
142
+ notifyTaskCreated(task, message, 'info');
132
143
  self.trigger('enqueued', result);
133
144
  }
134
145
  loadingBar.stop();