not-bulma 1.2.52 → 1.2.54

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "not-bulma",
3
- "version": "1.2.52",
3
+ "version": "1.2.54",
4
4
  "description": "not-* family UI components on Bulma CSS Framework",
5
5
  "main": "src/index.js",
6
6
  "svelte": "src/index.js",
@@ -39,7 +39,7 @@ class notCRUD extends notController {
39
39
  });
40
40
  }
41
41
 
42
- static getMenu() {
42
+ static getMenu(itemCustomProps = {}) {
43
43
  return [
44
44
  {
45
45
  section: this.MODULE_NAME,
@@ -47,6 +47,7 @@ class notCRUD extends notController {
47
47
  url: `/${notCommon.lowerFirstLetter(
48
48
  this.MODULE_NAME
49
49
  )}/${notCommon.lowerFirstLetter(this.MODEL_NAME)}`,
50
+ ...itemCustomProps,
50
51
  },
51
52
  ];
52
53
  }
@@ -220,8 +221,25 @@ class notCRUD extends notController {
220
221
  }
221
222
 
222
223
  getTitleFromLib(propName, id) {
223
- throw new Error("not suported anymore");
224
- //return Form.getVariant(propName, id).title;
224
+ const actionName = this.getCurrentAction();
225
+ this.debug(
226
+ "notCRUD.getTitleFromLib is obsolete, use notCRUD.getPreloadedVariantTitle(actionName, propName, id)"
227
+ );
228
+ return this.getPreloadedVariantTitle(actionName, propName, id);
229
+ }
230
+
231
+ getPreloadedVariants(actionName, propName) {
232
+ return this.getOptions(`variants.${actionName}.${propName}`, []);
233
+ }
234
+
235
+ getPreloadedVariantTitle(actionName, propName, id) {
236
+ const variants = this.getPreloadedVariants(actionName, propName);
237
+ const item = variants.find((item) => item.id === id);
238
+ if (item) {
239
+ return item.title;
240
+ } else {
241
+ return id;
242
+ }
225
243
  }
226
244
 
227
245
  getItemTitle(item) {
@@ -1,42 +1,50 @@
1
- import notBase from '../base';
2
- import notCommon from '../common';
1
+ import notCommon from "../common";
3
2
 
4
- const PRELOADABLE = ['create','update','list','delete','details'];
3
+ const PRELOADABLE = ["create", "update", "list", "delete", "details"];
5
4
 
6
- export default class CRUDVariantsPreloader{
7
- static async preload(controller, type = 'list'){
8
- try{
9
- if (!PRELOADABLE.includes(type)) { return; }
10
- let preload = controller.getOptions(`${type}.preload`, {});
11
- if(Object.keys(preload).length == 0){
12
- preload = controller.getOptions(`preload`, {});
13
- }
14
- if(Object.keys(preload).length > 0){
15
- let libProps = Object.keys(preload);
16
- let proms = [];
17
- libProps.forEach((prop)=>{
18
- let modelName = notCommon.lowerFirstLetter(preload[prop]);
19
- let Model = controller.make[modelName]({});
20
- proms.push(Model.$listAll());
21
- });
22
- let results = await Promise.all(proms);
23
- for(let i = 0; i < libProps.length; i++){
24
- const propName = libProps[i];
25
- if(Array.isArray(results[i])){
26
- const variants = results[i].map(item => {
27
- return {
28
- id: item._id,
29
- title: item.title
30
- };
31
- });
32
- controller.getOptions(`variants.${type}.${propName}`, variants);
33
- }
5
+ export default class CRUDVariantsPreloader {
6
+ static async preload(controller, type = "list") {
7
+ try {
8
+ if (!PRELOADABLE.includes(type)) {
9
+ return;
10
+ }
11
+ let preload = controller.getOptions(`${type}.preload`, {});
12
+ if (Object.keys(preload).length == 0) {
13
+ preload = controller.getOptions(`preload`, {});
14
+ }
15
+ if (Object.keys(preload).length > 0) {
16
+ let libProps = Object.keys(preload);
17
+ let proms = [];
18
+ libProps.forEach((prop) => {
19
+ let modelName = notCommon.lowerFirstLetter(preload[prop]);
20
+ let Model = controller.make[modelName]({});
21
+ proms.push(Model.$listAll());
22
+ });
23
+ let results = await Promise.all(proms);
24
+ for (let i = 0; i < libProps.length; i++) {
25
+ const propName = libProps[i];
26
+ if (
27
+ results[i].status === "ok" &&
28
+ Array.isArray(results[i].result)
29
+ ) {
30
+ const resultsList = results[i].result;
31
+ const variants = resultsList.map((item) => {
32
+ return {
33
+ id: item._id,
34
+ title: item.title,
35
+ };
36
+ });
37
+ controller.setOptions(
38
+ `variants.${type}.${propName}`,
39
+ variants
40
+ );
41
+ }
42
+ }
43
+ }
44
+ controller.log("preload finished");
45
+ } catch (e) {
46
+ controller.report(e);
47
+ controller.showErrorMessage(e);
34
48
  }
35
- }
36
- controller.log('preload finished');
37
- }catch(e){
38
- controller.report(e);
39
- controller.showErrorMessage(e);
40
49
  }
41
- }
42
- };
50
+ }