@oat-sa/tao-core-ui 1.49.0 → 1.49.4

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.
@@ -254,7 +254,7 @@ define(['exports', 'jquery', 'lodash', 'i18n', 'core/mimetype', 'ui/mediaEditor/
254
254
  confirmBox = $('.change-alt-modal-feedback', $form);
255
255
  cancel = confirmBox.find('.cancel');
256
256
  save = confirmBox.find('.save');
257
- $('.alt-text', confirmBox).html("\"".concat($alt.val(), "\"<br>with<br>\"").concat(alt, "\" ?"));
257
+ $('.alt-text', confirmBox).html("\"".concat($alt.val(), "\"<br>").concat(__('with'), "<br>\"").concat(alt, "\" ?"));
258
258
  confirmBox.modal({
259
259
  width: 500
260
260
  });
@@ -255,7 +255,7 @@ define(['jquery', 'nouislider', 'ui/resourcemgr', 'ui/tooltip', 'lodash', 'modul
255
255
  confirmBox = $('.change-alt-modal-feedback', $form);
256
256
  cancel = confirmBox.find('.cancel');
257
257
  save = confirmBox.find('.save');
258
- $('.alt-text', confirmBox).html("\"".concat($alt.val(), "\"<br>with<br>\"").concat(alt, "\" ?"));
258
+ $('.alt-text', confirmBox).html("\"".concat($alt.val(), "\"<br>").concat(__('with'), "<br>\"").concat(alt, "\" ?"));
259
259
  confirmBox.modal({
260
260
  width: 500
261
261
  });
@@ -239,8 +239,8 @@ define(['i18n', 'handlebars', 'lodash', 'lib/dompurify/purify'], function (__, H
239
239
  ASINH: __('sinh') + "<sup>\u207B1</sup>",
240
240
  ACOSH: __('cosh') + "<sup>\u207B1</sup>",
241
241
  ATANH: __('tanh') + "<sup>\u207B1</sup>",
242
- LN: __('ln'),
243
- LOG: __('log') + '<sub>10</sub>',
242
+ LN: 'ln',
243
+ LOG: 'log<sub>10</sub>',
244
244
  ABS: __('abs'),
245
245
  RAND: __('random'),
246
246
  // Actions
@@ -1,10 +1,9 @@
1
- define(['jquery', 'lodash', 'i18n', 'context', 'handlebars', 'lib/dompurify/purify', 'css!ui/searchModal/css/advancedSearch.css', 'ui/component', 'ui/modal', 'ui/datatable', 'select2', 'util/url', 'core/dataProvider/request'], function ($$1, _, __, context, Handlebars, DOMPurify, advancedSearch_css, component, modal, datatable, select2, urlUtil, request) { 'use strict';
1
+ define(['jquery', 'lodash', 'handlebars', 'i18n', 'lib/dompurify/purify', 'css!ui/searchModal/css/advancedSearch.css', 'ui/component', 'ui/modal', 'ui/datatable', 'select2', 'util/url', 'core/dataProvider/request'], function ($$1, _, Handlebars, __, DOMPurify, advancedSearch_css, component, modal, datatable, select2, urlUtil, request) { 'use strict';
2
2
 
3
3
  $$1 = $$1 && Object.prototype.hasOwnProperty.call($$1, 'default') ? $$1['default'] : $$1;
4
4
  _ = _ && Object.prototype.hasOwnProperty.call(_, 'default') ? _['default'] : _;
5
- __ = __ && Object.prototype.hasOwnProperty.call(__, 'default') ? __['default'] : __;
6
- context = context && Object.prototype.hasOwnProperty.call(context, 'default') ? context['default'] : context;
7
5
  Handlebars = Handlebars && Object.prototype.hasOwnProperty.call(Handlebars, 'default') ? Handlebars['default'] : Handlebars;
6
+ __ = __ && Object.prototype.hasOwnProperty.call(__, 'default') ? __['default'] : __;
8
7
  DOMPurify = DOMPurify && Object.prototype.hasOwnProperty.call(DOMPurify, 'default') ? DOMPurify['default'] : DOMPurify;
9
8
  component = component && Object.prototype.hasOwnProperty.call(component, 'default') ? component['default'] : component;
10
9
  urlUtil = urlUtil && Object.prototype.hasOwnProperty.call(urlUtil, 'default') ? urlUtil['default'] : urlUtil;
@@ -339,6 +338,7 @@ define(['jquery', 'lodash', 'i18n', 'context', 'handlebars', 'lib/dompurify/puri
339
338
  * @param {object} config
340
339
  * @param {object} config.renderTo - DOM element where component will be rendered to
341
340
  * @param {string} config.advancedCriteria - advanced criteria to be set on component creation
341
+ * @param {string} config.rootClassUri - rootClassUri to check for whitelist sections
342
342
  * @returns {advancedSearch}
343
343
  */
344
344
 
@@ -403,7 +403,7 @@ define(['jquery', 'lodash', 'i18n', 'context', 'handlebars', 'lib/dompurify/puri
403
403
 
404
404
  _.forEach(criteriaState, function (criterion) {
405
405
  criterion.rendered = false;
406
- criterion.value = undefined;
406
+ criterion.value = null;
407
407
  });
408
408
  },
409
409
 
@@ -458,6 +458,18 @@ define(['jquery', 'lodash', 'i18n', 'context', 'handlebars', 'lib/dompurify/puri
458
458
  $advancedCriteriaContainer = $$1('.advanced-criteria-container', $container);
459
459
  $advancedCriteriaContainer.on('scroll', _.throttle(animateScroll, 100));
460
460
  }
461
+ /**
462
+ * Lookup for characters in text to highlight
463
+ * @param {String} text - text to lookup
464
+ * @param {String} highlight - character(s) to be highlighted
465
+ * @param {regExp|String} match - match to be applied in the text
466
+ * @returns {String} - highlighted text
467
+ */
468
+
469
+
470
+ function highlightCharacter(text, highlight, match) {
471
+ return text.replace(match, "<b>".concat(highlight, "</b>"));
472
+ }
461
473
  /**
462
474
  * Inits select2 on criteria select and its UX logic
463
475
  */
@@ -466,7 +478,7 @@ define(['jquery', 'lodash', 'i18n', 'context', 'handlebars', 'lib/dompurify/puri
466
478
  function initAddCriteriaSelector() {
467
479
  var route = urlUtil.route('status', 'AdvancedSearch', 'tao');
468
480
  return request(route).then(function (response) {
469
- if (!response.enabled || context.shownStructure === 'results') {
481
+ if (!response.enabled || response.whitelist.includes(config.rootClassUri)) {
470
482
  isAdvancedSearchStatusEnabled = false;
471
483
  return;
472
484
  }
@@ -482,8 +494,17 @@ define(['jquery', 'lodash', 'i18n', 'context', 'handlebars', 'lib/dompurify/puri
482
494
  escapeMarkup: function escapeMarkup(markup) {
483
495
  return markup;
484
496
  },
485
- formatResult: function formatResult(result, container, query, escapedMarkup) {
486
- return result.text;
497
+ formatResult: function formatResult(result, container, query) {
498
+ var label = result.element[0].getAttribute('label');
499
+ var sublabel = result.element[0].getAttribute('sublabel');
500
+ var match = new RegExp(query.term, 'ig');
501
+ var template = highlightCharacter(label, query.term, match); // Add sublabel
502
+
503
+ if (sublabel && sublabel.length) {
504
+ template = template + "<span class=\"class-path\"> / ".concat(highlightCharacter(sublabel, query.term, match), "</span>");
505
+ }
506
+
507
+ return template;
487
508
  }
488
509
  }); // open dropdown when user clicks on add criteria input
489
510
 
@@ -510,14 +531,14 @@ define(['jquery', 'lodash', 'i18n', 'context', 'handlebars', 'lib/dompurify/puri
510
531
  /**
511
532
  * inits criteriaState loading it from the store (if present) or empty object.
512
533
  * If there is a stored criteriaState, those criteria that were rendered
513
- * but with undefined value are updated to not being rendered
534
+ * but with null value are updated to not being rendered
514
535
  */
515
536
 
516
537
 
517
538
  function initCriteriaState() {
518
539
  if (instance.config.advancedCriteria) {
519
540
  _.forEach(instance.config.advancedCriteria, function (criterion) {
520
- if (criterion.rendered === true && criterion.value === undefined) {
541
+ if (criterion.rendered === true && criterion.value === null) {
521
542
  criterion.rendered = false;
522
543
  }
523
544
  });
@@ -693,7 +714,7 @@ define(['jquery', 'lodash', 'i18n', 'context', 'handlebars', 'lib/dompurify/puri
693
714
  $$1('input', $criterionContainer).val(criterion.value); // set event to bind input value to critariaState
694
715
 
695
716
  $$1('input', $criterionContainer).on('change', function () {
696
- criterion.value = $$1(this).val() || undefined;
717
+ criterion.value = $$1(this).val() || null;
697
718
  });
698
719
  } else if (criterion.type === criteriaTypes.list && criterion.uri) {
699
720
  // set initial value
@@ -738,7 +759,7 @@ define(['jquery', 'lodash', 'i18n', 'context', 'handlebars', 'lib/dompurify/puri
738
759
  $criteriaSelect.append(newOption); // reset criterion values on criteriaState
739
760
 
740
761
  criteriaState[criterionKey].rendered = false;
741
- criteriaState[criterionKey].value = undefined; // check if advanced criteria container is no longer scrollable
762
+ criteriaState[criterionKey].value = null; // check if advanced criteria container is no longer scrollable
742
763
 
743
764
  if ($advancedCriteriaContainer.get(0).scrollHeight <= $advancedCriteriaContainer.outerHeight()) {
744
765
  $advancedCriteriaContainer.removeClass('scrollable');
@@ -854,7 +875,7 @@ define(['jquery', 'lodash', 'i18n', 'context', 'handlebars', 'lib/dompurify/puri
854
875
  // if new criterion was not on criteriaState we add it
855
876
  criteriaState[criteriaStateId] = criterion;
856
877
  criteriaState[criteriaStateId].rendered = false;
857
- criteriaState[criteriaStateId].value = undefined;
878
+ criteriaState[criteriaStateId].value = null;
858
879
  } // create new option element to criteria select
859
880
 
860
881
 
@@ -864,14 +885,28 @@ define(['jquery', 'lodash', 'i18n', 'context', 'handlebars', 'lib/dompurify/puri
864
885
  });
865
886
  }
866
887
  /**
888
+ * Creates a new option element
889
+ * with attributes to use in select2 markup
867
890
  * @param {Object} criterion
868
- * @returns Option
891
+ * @returns {HTMLOptionElement} Single option criteria
869
892
  */
870
893
 
871
894
 
872
895
  function createCriteriaOption(criterion) {
873
- var infoText = criterion.isDuplicated ? " <span class=\"class-path\">/".concat(criterion.class.label, "</span>") : '';
874
- return new Option(criterion.label + infoText, getCriterionStateId(criterion), false, false);
896
+ var label = criterion.label;
897
+ var sublabel = '';
898
+ var option;
899
+ var optionText = label;
900
+
901
+ if (criterion.isDuplicated) {
902
+ sublabel = criterion.class.label;
903
+ optionText = "".concat(label, " / ").concat(sublabel);
904
+ }
905
+
906
+ option = new Option(optionText, getCriterionStateId(criterion), false, false);
907
+ option.setAttribute('label', label);
908
+ option.setAttribute('sublabel', sublabel);
909
+ return option;
875
910
  }
876
911
  /**
877
912
  * @param {Object} criterion
@@ -246,6 +246,7 @@ define(['jquery', 'lodash', 'i18n', 'context', 'handlebars', 'lib/dompurify/puri
246
246
  var rootClassUri = config.rootClassUri;
247
247
  /**
248
248
  * Creates search modal, inits template selectors, inits search store, and once is created triggers initial search
249
+ * rootClassUri is sent to advancedSearch factory for disabling in whitelisted sections
249
250
  */
250
251
 
251
252
  function renderModal() {
@@ -254,7 +255,8 @@ define(['jquery', 'lodash', 'i18n', 'context', 'handlebars', 'lib/dompurify/puri
254
255
  initUiSelectors();
255
256
  advancedSearch = advancedSearchFactory({
256
257
  renderTo: $$1('.filters-container', $container),
257
- advancedCriteria: instance.config.criterias.advancedCriteria
258
+ advancedCriteria: instance.config.criterias.advancedCriteria,
259
+ rootClassUri: rootClassUri
258
260
  });
259
261
  promises.push(initClassFilter());
260
262
  promises.push(initSearchStore());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oat-sa/tao-core-ui",
3
- "version": "1.49.0",
3
+ "version": "1.49.4",
4
4
  "displayName": "TAO Core UI",
5
5
  "description": "UI libraries of TAO",
6
6
  "scripts": {
@@ -51,7 +51,7 @@
51
51
  "@oat-sa/rollup-plugin-wildcard-external": "^0.1.0",
52
52
  "@oat-sa/tao-core-libs": "^0.4.4",
53
53
  "@oat-sa/tao-core-sdk": "^1.8.1",
54
- "@oat-sa/tao-core-shared-libs": "^1.0.4",
54
+ "@oat-sa/tao-core-shared-libs": "^1.0.5",
55
55
  "@oat-sa/tao-qunit-testrunner": "^1.0.3",
56
56
  "async": "^0.2.10",
57
57
  "autoprefixer": "^9.5.1",
@@ -85,7 +85,7 @@ export const initUpload = function (widget) {
85
85
  cancel = confirmBox.find('.cancel');
86
86
  save = confirmBox.find('.save');
87
87
 
88
- $('.alt-text', confirmBox).html(`"${$alt.val()}"<br>with<br>"${alt}" ?`);
88
+ $('.alt-text', confirmBox).html(`"${$alt.val()}"<br>${__('with')}<br>"${alt}" ?`);
89
89
 
90
90
  confirmBox.modal({ width: 500 });
91
91
 
@@ -98,8 +98,8 @@ export default {
98
98
  ASINH: __('sinh') + '<sup>\u207B1</sup>',
99
99
  ACOSH: __('cosh') + '<sup>\u207B1</sup>',
100
100
  ATANH: __('tanh') + '<sup>\u207B1</sup>',
101
- LN: __('ln'),
102
- LOG: __('log') + '<sub>10</sub>',
101
+ LN: 'ln',
102
+ LOG: 'log<sub>10</sub>',
103
103
  ABS: __('abs'),
104
104
  RAND: __('random'),
105
105
 
@@ -18,8 +18,6 @@
18
18
 
19
19
  import $ from 'jquery';
20
20
  import _ from 'lodash';
21
- import __ from 'i18n';
22
- import context from 'context';
23
21
  import advancedSearchTpl from 'ui/searchModal/tpl/advanced-search';
24
22
  import textCriterionTpl from 'ui/searchModal/tpl/text-criterion';
25
23
  import invalidCriteriaWarningTpl from 'ui/searchModal/tpl/invalid-criteria-warning';
@@ -39,6 +37,7 @@ import request from 'core/dataProvider/request';
39
37
  * @param {object} config
40
38
  * @param {object} config.renderTo - DOM element where component will be rendered to
41
39
  * @param {string} config.advancedCriteria - advanced criteria to be set on component creation
40
+ * @param {string} config.rootClassUri - rootClassUri to check for whitelist sections
42
41
  * @returns {advancedSearch}
43
42
  */
44
43
  export default function advancedSearchFactory(config) {
@@ -99,7 +98,7 @@ export default function advancedSearchFactory(config) {
99
98
  $advancedCriteriaContainer.empty();
100
99
  _.forEach(criteriaState, criterion => {
101
100
  criterion.rendered = false;
102
- criterion.value = undefined;
101
+ criterion.value = null;
103
102
  });
104
103
  },
105
104
  /**
@@ -154,6 +153,17 @@ export default function advancedSearchFactory(config) {
154
153
  $advancedCriteriaContainer.on('scroll', _.throttle(animateScroll, 100));
155
154
  }
156
155
 
156
+ /**
157
+ * Lookup for characters in text to highlight
158
+ * @param {String} text - text to lookup
159
+ * @param {String} highlight - character(s) to be highlighted
160
+ * @param {regExp|String} match - match to be applied in the text
161
+ * @returns {String} - highlighted text
162
+ */
163
+ function highlightCharacter(text, highlight, match) {
164
+ return text.replace(match, `<b>${highlight}</b>`);
165
+ }
166
+
157
167
  /**
158
168
  * Inits select2 on criteria select and its UX logic
159
169
  */
@@ -161,7 +171,7 @@ export default function advancedSearchFactory(config) {
161
171
  const route = urlUtil.route('status', 'AdvancedSearch', 'tao');
162
172
  return request(route)
163
173
  .then(function (response) {
164
- if (!response.enabled || context.shownStructure === 'results') {
174
+ if (!response.enabled || response.whitelist.includes(config.rootClassUri)) {
165
175
  isAdvancedSearchStatusEnabled = false;
166
176
  return;
167
177
  }
@@ -174,8 +184,18 @@ export default function advancedSearchFactory(config) {
174
184
  escapeMarkup: function(markup) {
175
185
  return markup;
176
186
  },
177
- formatResult: function formatResult(result, container, query, escapedMarkup) {
178
- return result.text;
187
+ formatResult: function formatResult(result, container, query) {
188
+ const label = result.element[0].getAttribute('label');
189
+ const sublabel = result.element[0].getAttribute('sublabel');
190
+ const match = new RegExp(query.term, 'ig');
191
+ let template = highlightCharacter(label, query.term, match);
192
+
193
+ // Add sublabel
194
+ if(sublabel && sublabel.length) {
195
+ template = template + `<span class="class-path"> / ${highlightCharacter(sublabel, query.term, match)}</span>`;
196
+ }
197
+
198
+ return template;
179
199
  }
180
200
  });
181
201
 
@@ -209,12 +229,12 @@ export default function advancedSearchFactory(config) {
209
229
  /**
210
230
  * inits criteriaState loading it from the store (if present) or empty object.
211
231
  * If there is a stored criteriaState, those criteria that were rendered
212
- * but with undefined value are updated to not being rendered
232
+ * but with null value are updated to not being rendered
213
233
  */
214
234
  function initCriteriaState() {
215
235
  if (instance.config.advancedCriteria) {
216
236
  _.forEach(instance.config.advancedCriteria, criterion => {
217
- if (criterion.rendered === true && criterion.value === undefined) {
237
+ if (criterion.rendered === true && criterion.value === null) {
218
238
  criterion.rendered = false;
219
239
  }
220
240
  });
@@ -304,7 +324,7 @@ export default function advancedSearchFactory(config) {
304
324
  };
305
325
  },
306
326
  results: (response) => ({
307
- results: response.data.map(option => ({ id: valueMapping === 'uri' ? option.uri : option.label, text: option.label }))
327
+ results: response.data.map(option => ({ id: valueMapping === 'uri' ? option.uri : option.label, text: option.label }))
308
328
  })
309
329
  },
310
330
  initSelection: function (element, callback) {
@@ -341,14 +361,14 @@ export default function advancedSearchFactory(config) {
341
361
  return criterion.value.map(v => ({
342
362
  id: v,
343
363
  text: (data.find(d => d.uri === v) || {}).label
344
- }))
364
+ }));
345
365
  }
346
- let c = (data.find(d => d.uri === criterion.value) || {})
366
+ let c = (data.find(d => d.uri === criterion.value) || {});
347
367
  return {
348
368
  text: c.label,
349
369
  id: criterion.value,
350
- }
351
- })
370
+ };
371
+ });
352
372
  }
353
373
 
354
374
  /**
@@ -363,7 +383,7 @@ export default function advancedSearchFactory(config) {
363
383
  $('input', $criterionContainer).val(criterion.value);
364
384
  // set event to bind input value to critariaState
365
385
  $('input', $criterionContainer).on('change', function () {
366
- criterion.value = $(this).val() || undefined;
386
+ criterion.value = $(this).val() || null;
367
387
  });
368
388
  } else if (criterion.type === criteriaTypes.list && criterion.uri) {
369
389
  // set initial value
@@ -409,7 +429,7 @@ export default function advancedSearchFactory(config) {
409
429
 
410
430
  // reset criterion values on criteriaState
411
431
  criteriaState[criterionKey].rendered = false;
412
- criteriaState[criterionKey].value = undefined;
432
+ criteriaState[criterionKey].value = null;
413
433
 
414
434
  // check if advanced criteria container is no longer scrollable
415
435
  if ($advancedCriteriaContainer.get(0).scrollHeight <= $advancedCriteriaContainer.outerHeight()) {
@@ -520,7 +540,7 @@ export default function advancedSearchFactory(config) {
520
540
  // if new criterion was not on criteriaState we add it
521
541
  criteriaState[criteriaStateId] = criterion;
522
542
  criteriaState[criteriaStateId].rendered = false;
523
- criteriaState[criteriaStateId].value = undefined;
543
+ criteriaState[criteriaStateId].value = null;
524
544
  }
525
545
 
526
546
  // create new option element to criteria select
@@ -531,18 +551,33 @@ export default function advancedSearchFactory(config) {
531
551
  }
532
552
 
533
553
  /**
554
+ * Creates a new option element
555
+ * with attributes to use in select2 markup
534
556
  * @param {Object} criterion
535
- * @returns Option
557
+ * @returns {HTMLOptionElement} Single option criteria
536
558
  */
537
559
  function createCriteriaOption(criterion) {
538
- const infoText = criterion.isDuplicated ? ` <span class="class-path">/${criterion.class.label}</span>` : '';
560
+ let label = criterion.label;
561
+ let sublabel = '';
562
+ let option;
563
+ let optionText = label;
564
+
565
+ if(criterion.isDuplicated) {
566
+ sublabel = criterion.class.label;
567
+ optionText = `${label} / ${sublabel}`;
568
+ }
539
569
 
540
- return new Option(
541
- criterion.label + infoText,
570
+ option = new Option(
571
+ optionText,
542
572
  getCriterionStateId(criterion),
543
573
  false,
544
574
  false
545
575
  );
576
+
577
+ option.setAttribute('label', label);
578
+ option.setAttribute('sublabel', sublabel);
579
+
580
+ return option;
546
581
  }
547
582
 
548
583
  /**
@@ -73,6 +73,7 @@ export default function searchModalFactory(config) {
73
73
 
74
74
  /**
75
75
  * Creates search modal, inits template selectors, inits search store, and once is created triggers initial search
76
+ * rootClassUri is sent to advancedSearch factory for disabling in whitelisted sections
76
77
  */
77
78
  function renderModal() {
78
79
  const promises = [];
@@ -80,7 +81,8 @@ export default function searchModalFactory(config) {
80
81
  initUiSelectors();
81
82
  advancedSearch = advancedSearchFactory({
82
83
  renderTo: $('.filters-container', $container),
83
- advancedCriteria: instance.config.criterias.advancedCriteria
84
+ advancedCriteria: instance.config.criterias.advancedCriteria,
85
+ rootClassUri: rootClassUri
84
86
  });
85
87
  promises.push(initClassFilter());
86
88
  promises.push(initSearchStore());