not-bulma 1.0.71 → 1.0.73

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.0.71",
3
+ "version": "1.0.73",
4
4
  "description": "not-* family UI components on Bulma CSS Framework",
5
5
  "main": "src/index.js",
6
6
  "svelte": "src/index.js",
@@ -1,49 +1,61 @@
1
- import {notForm} from '../../components';
1
+ import { notForm } from "../../components";
2
+ import { DEFAULT_TRASFORMER } from "../const";
2
3
 
3
- const ACTION = 'create';
4
- const MODEL_ACTION = 'create';
4
+ const ACTION = "create";
5
+ const MODEL_ACTION = "create";
5
6
 
6
7
  export default class CRUDActionCreate {
7
- static async run(controller, params = []) {
8
- try{
9
- await controller.preloadVariants(ACTION);
10
- controller.setBreadcrumbs([{
11
- title: 'Добавление',
12
- url: controller.getModelActionURL(false, ACTION)
13
- }]);
14
- if (controller.ui[ACTION]) {
15
- return;
16
- } else {
17
- controller.$destroyUI();
18
- }
19
- const createActionName = controller.getOptions(`${ACTION}.actionName`, MODEL_ACTION);
20
- let defData = controller.createDefault();
21
- if(defData.getData){
22
- defData = defData.getData();
23
- }
24
- controller.ui[ACTION] = new notForm({
25
- options:{
26
- target: controller.getContainerInnerElement(),
27
- model: controller.getModelName(),
28
- action: createActionName,
29
- name: `${controller.getName()}.${ACTION}Form`,
30
- validators: controller.getOptions('Validators'),
31
- variants: controller.getOptions(`variants.${ACTION}`, {}),
32
- },
33
- data: defData
34
- });
35
- controller.ui[ACTION].on('submit', async (data) => {
36
- const success = await controller.onActionSubmit(createActionName, data);
37
- if(success){
38
- controller.ui[ACTION].setFormSuccess();
39
- setTimeout(() => controller.goList(), 1000);
8
+ static async run(controller, params = []) {
9
+ try {
10
+ await controller.preloadVariants(ACTION);
11
+ controller.setBreadcrumbs([
12
+ {
13
+ title: "Добавление",
14
+ url: controller.getModelActionURL(false, ACTION),
15
+ },
16
+ ]);
17
+ if (controller.ui[ACTION]) {
18
+ return;
19
+ } else {
20
+ controller.$destroyUI();
21
+ }
22
+ const createActionName = controller.getOptions(
23
+ `${ACTION}.actionName`,
24
+ MODEL_ACTION
25
+ );
26
+ let defData = controller.createDefault();
27
+ if (defData.getData) {
28
+ defData = defData.getData();
29
+ }
30
+ controller.ui[ACTION] = new notForm({
31
+ options: {
32
+ target: controller.getContainerInnerElement(),
33
+ model: controller.getModelName(),
34
+ action: createActionName,
35
+ name: `${controller.getName()}.${ACTION}Form`,
36
+ validators: controller.getOptions("Validators"),
37
+ variants: controller.getOptions(`variants.${ACTION}`, {}),
38
+ },
39
+ data: defData,
40
+ });
41
+ controller.ui[ACTION].on("submit", async (data) => {
42
+ const success = await controller.onActionSubmit(
43
+ createActionName,
44
+ data
45
+ );
46
+ if (success) {
47
+ controller.ui[ACTION].setFormSuccess();
48
+ setTimeout(() => controller.goList(), 1000);
49
+ }
50
+ });
51
+ controller.ui[ACTION].on(
52
+ "reject",
53
+ controller.goList.bind(controller)
54
+ );
55
+ controller.emit(`after:render:${ACTION}`);
56
+ } catch (e) {
57
+ controller.report(e);
58
+ controller.showErrorMessage(e);
40
59
  }
41
- });
42
- controller.ui[ACTION].on('reject', controller.goList.bind(controller));
43
- controller.emit(`after:render:${ACTION}`);
44
- }catch(e){
45
- controller.report(e);
46
- controller.showErrorMessage(e);
47
60
  }
48
- }
49
61
  }
@@ -1,57 +1,75 @@
1
- import {notForm} from '../../components';
1
+ import { notForm } from "../../components";
2
+ import { DEFAULT_TRASFORMER } from "../const";
2
3
 
3
- const ACTION = 'details';
4
- const MODEL_ACTION = 'get';
4
+ const ACTION = "details";
5
+ const MODEL_ACTION = "get";
5
6
 
6
7
  export default class CRUDActionDetails {
7
- static async run(controller, params) {
8
- try{
9
- await controller.preloadVariants(ACTION);
10
-
11
- const idField = controller.getOptions(`${ACTION}.idField`, '_id'),
12
- query = {[idField]: params[0]};
13
-
14
- controller.setBreadcrumbs([{
15
- title: 'Просмотр',
16
- url: controller.getModelActionURL(params[0], false)
17
- }]);
18
-
19
- if (controller.ui[ACTION]) {
20
- return;
21
- } else {
22
- controller.$destroyUI();
23
- }
24
- const detailsActionName = controller.getOptions(`${ACTION}.actionName`, MODEL_ACTION);
25
- let res = await controller.getModel(query)[`$${detailsActionName}`]();
26
- if(!res || (res.status !== 'ok')){
27
- return controller.showErrorMessage(res);
28
- }
29
-
30
- const title = controller.getItemTitle(res.result);
31
- controller.setBreadcrumbs([{
32
- title: `Просмотр "${title}"`,
33
- url: controller.getModelActionURL(params[0], false)
34
- }]);
35
-
36
- controller.ui[ACTION] = new notForm({
37
- options: {
38
- target: controller.getContainerInnerElement(),
39
- model: controller.getModelName(),
40
- action: detailsActionName,
41
- name: `${controller.getName()}.${ACTION}Form`,
42
- fields:{
43
- readonly: true,
44
- },
45
- validators: controller.getOptions('Validators'),
46
- variants: controller.getOptions(`variants.${ACTION}`, {}),
47
- },
48
- data: res.result
49
- });
50
- controller.emit(`after:render:${ACTION}`);
51
- controller.ui[ACTION].on('reject', controller.goList.bind(controller));
52
- }catch(e){
53
- controller.report(e);
54
- controller.showErrorMessage(e);
8
+ static async run(controller, params) {
9
+ try {
10
+ await controller.preloadVariants(ACTION);
11
+
12
+ const idField = controller.getOptions(`${ACTION}.idField`, "_id"),
13
+ query = { [idField]: params[0] };
14
+
15
+ controller.setBreadcrumbs([
16
+ {
17
+ title: "Просмотр",
18
+ url: controller.getModelActionURL(params[0], false),
19
+ },
20
+ ]);
21
+
22
+ if (controller.ui[ACTION]) {
23
+ return;
24
+ } else {
25
+ controller.$destroyUI();
26
+ }
27
+ const detailsActionName = controller.getOptions(
28
+ `${ACTION}.actionName`,
29
+ MODEL_ACTION
30
+ );
31
+ let res = await controller
32
+ .getModel(query)
33
+ [`$${detailsActionName}`]();
34
+ if (!res || res.status !== "ok") {
35
+ return controller.showErrorMessage(res);
36
+ }
37
+
38
+ const title = controller.getItemTitle(res.result);
39
+ controller.setBreadcrumbs([
40
+ {
41
+ title: `Просмотр "${title}"`,
42
+ url: controller.getModelActionURL(params[0], false),
43
+ },
44
+ ]);
45
+
46
+ const resultTransformer = controller.getOptions(
47
+ `${ACTION}.transformer`,
48
+ DEFAULT_TRASFORMER
49
+ );
50
+
51
+ controller.ui[ACTION] = new notForm({
52
+ options: {
53
+ target: controller.getContainerInnerElement(),
54
+ model: controller.getModelName(),
55
+ action: detailsActionName,
56
+ name: `${controller.getName()}.${ACTION}Form`,
57
+ fields: {
58
+ readonly: true,
59
+ },
60
+ validators: controller.getOptions("Validators"),
61
+ variants: controller.getOptions(`variants.${ACTION}`, {}),
62
+ },
63
+ data: resultTransformer(res.result),
64
+ });
65
+ controller.emit(`after:render:${ACTION}`);
66
+ controller.ui[ACTION].on(
67
+ "reject",
68
+ controller.goList.bind(controller)
69
+ );
70
+ } catch (e) {
71
+ controller.report(e);
72
+ controller.showErrorMessage(e);
73
+ }
55
74
  }
56
- }
57
75
  }
@@ -23,6 +23,7 @@ export default class CRUDActionList {
23
23
  controller.ui[ACTION] = new notTable(
24
24
  CRUDActionList.prepareOptions(controller)
25
25
  );
26
+
26
27
  controller.emit(`after:render:${ACTION}`);
27
28
  } catch (e) {
28
29
  controller.report(e);
@@ -1,68 +1,85 @@
1
- import {notForm} from '../../components';
2
- import notCommon from '../../common';
1
+ import { notForm } from "../../components";
2
+ import notCommon from "../../common";
3
+ import { DEFAULT_TRASFORMER } from "../const";
4
+ const ACTION = "update";
5
+ const MODEL_ACTION_GET = "getRaw";
6
+ const MODEL_ACTION_UPDATE = "update";
3
7
 
4
- const ACTION = 'update';
5
- const MODEL_ACTION_GET = 'getRaw';
6
- const MODEL_ACTION_UPDATE = 'update';
8
+ export default class CRUDActionUpdate {
9
+ static async run(controller, params) {
10
+ try {
11
+ const idField = controller.getOptions(`${ACTION}.idField`, "_id"),
12
+ id = params[0],
13
+ query = { [idField]: id };
7
14
 
8
- export default class CRUDActionUpdate{
9
- static async run(controller, params) {
10
- try{
11
- const idField = controller.getOptions(`${ACTION}.idField`, '_id'),
12
- id = params[0],
13
- query = {[idField]:id};
15
+ await controller.preloadVariants(ACTION);
14
16
 
15
- await controller.preloadVariants(ACTION);
17
+ controller.setBreadcrumbs([
18
+ {
19
+ title: "Редактирование",
20
+ url: controller.getModelActionURL(id, ACTION),
21
+ },
22
+ ]);
16
23
 
17
- controller.setBreadcrumbs([{
18
- title: 'Редактирование',
19
- url: controller.getModelActionURL(id, ACTION)
20
- }]);
24
+ if (controller.ui[ACTION]) {
25
+ return;
26
+ } else {
27
+ controller.$destroyUI();
28
+ }
21
29
 
22
- if (controller.ui[ACTION]) {
23
- return;
24
- } else {
25
- controller.$destroyUI();
26
- }
30
+ const getActionName = controller.getOptions(
31
+ `${ACTION}.actionName`,
32
+ MODEL_ACTION_GET
33
+ );
34
+ let res = await controller.getModel(query)[`$${getActionName}`]();
35
+ if (!res || res.status !== "ok") {
36
+ return controller.showErrorMessage(res);
37
+ }
27
38
 
28
- const getActionName = controller.getOptions(`${ACTION}.actionName`, MODEL_ACTION_GET);
29
- let res = await controller.getModel(query)[`$${getActionName}`]();
30
- if(!res || (res.status !== 'ok')){
31
- return controller.showErrorMessage(res);
32
- }
39
+ const title = controller.getItemTitle(res.result);
40
+ controller.setBreadcrumbs([
41
+ {
42
+ title: `Редактирование "${title}"`,
43
+ url: controller.getModelActionURL(params[0], ACTION),
44
+ },
45
+ ]);
33
46
 
34
- const title = controller.getItemTitle(res.result);
35
- controller.setBreadcrumbs([{
36
- title: `Редактирование "${title}"`,
37
- url: controller.getModelActionURL(params[0], ACTION)
38
- }]);
47
+ const resultTransformer = controller.getOptions(
48
+ `${ACTION}.transformer`,
49
+ DEFAULT_TRASFORMER
50
+ );
39
51
 
40
- controller.ui[ACTION] = new notForm({
41
- options:{
42
- target: controller.getContainerInnerElement(),
43
- model: controller.getModelName(),
44
- action: MODEL_ACTION_UPDATE,
45
- name: `${controller.getName()}.${ACTION}Form`,
46
- validators: controller.getOptions('Validators'),
47
- variants: controller.getOptions(`variants.${ACTION}`, {}),
48
- ui: controller.getOptions(`${ACTION}.ui`, {}),
49
- fields: controller.getOptions(`${ACTION}.fields`, {}),
50
- },
51
- data: notCommon.stripProxy(res.result)
52
- });
52
+ controller.ui[ACTION] = new notForm({
53
+ options: {
54
+ target: controller.getContainerInnerElement(),
55
+ model: controller.getModelName(),
56
+ action: MODEL_ACTION_UPDATE,
57
+ name: `${controller.getName()}.${ACTION}Form`,
58
+ validators: controller.getOptions("Validators"),
59
+ variants: controller.getOptions(`variants.${ACTION}`, {}),
60
+ ui: controller.getOptions(`${ACTION}.ui`, {}),
61
+ fields: controller.getOptions(`${ACTION}.fields`, {}),
62
+ },
63
+ data: resultTransformer(notCommon.stripProxy(res.result)),
64
+ });
53
65
 
54
- controller.ui[ACTION].on('submit', async (ev) => {
55
- const success = await controller.onActionSubmit(ACTION, Object.assign({}, query, ev));
56
- if(success){
57
- setTimeout(() => controller.goDetails(id), 1000);
66
+ controller.ui[ACTION].on("submit", async (ev) => {
67
+ const success = await controller.onActionSubmit(
68
+ ACTION,
69
+ Object.assign({}, query, ev)
70
+ );
71
+ if (success) {
72
+ setTimeout(() => controller.goDetails(id), 1000);
73
+ }
74
+ });
75
+ controller.ui[ACTION].on(
76
+ "reject",
77
+ controller.goList.bind(controller)
78
+ );
79
+ controller.emit(`after:render:${ACTION}`);
80
+ } catch (e) {
81
+ controller.report(e);
82
+ controller.showErrorMessage(e);
58
83
  }
59
- });
60
- controller.ui[ACTION].on('reject', controller.goList.bind(controller));
61
- controller.emit(`after:render:${ACTION}`);
62
- }catch(e){
63
- controller.report(e);
64
- controller.showErrorMessage(e);
65
84
  }
66
- }
67
-
68
85
  }
@@ -0,0 +1,3 @@
1
+ const DEFAULT_TRASFORMER = (res) => res;
2
+
3
+ export { DEFAULT_TRASFORMER };
@@ -1,4 +1,6 @@
1
- export default (ACTION, TITLE, UIConstructor) => {
1
+ import notCommon from "../common";
2
+ import { DEFAULT_TRASFORMER } from "./const";
3
+ export default ({ ACTION, TITLE, UIConstructor, dataProvider, goBack }) => {
2
4
  return class {
3
5
  static async run(controller, params) {
4
6
  try {
@@ -7,16 +9,36 @@ export default (ACTION, TITLE, UIConstructor) => {
7
9
  title: `Просмотр "${TITLE}"`,
8
10
  },
9
11
  ]);
12
+ await controller.preloadVariants(ACTION);
10
13
  if (controller.ui[ACTION]) {
11
14
  return;
12
15
  } else {
13
16
  controller.$destroyUI();
14
17
  }
18
+ let data = {};
19
+ if (dataProvider) {
20
+ if (notCommon.isFunc(dataProvider)) {
21
+ if (notCommon.isAsync(dataProvider)) {
22
+ data = await dataProvider(params);
23
+ } else {
24
+ data = dataProvider(params);
25
+ }
26
+ } else {
27
+ data = { ...dataProvider };
28
+ }
29
+ }
30
+ const resultTransformer = controller.getOptions(
31
+ `${ACTION}.transformer`,
32
+ DEFAULT_TRASFORMER
33
+ );
15
34
  controller.ui[ACTION] = new UIConstructor({
16
35
  target: controller.getContainerInnerElement(),
17
- props: { params },
36
+ props: { params, ...resultTransformer(data) },
18
37
  });
19
38
  controller.emit(`after:render:${ACTION}`);
39
+ if (goBack && notCommon.isFunc(goBack)) {
40
+ controller.ui[ACTION].on("reject", () => goBack());
41
+ }
20
42
  } catch (e) {
21
43
  controller.report(e);
22
44
  controller.showErrorMessage(e);
@@ -1,18 +1,23 @@
1
- import {UISuccess, UIError} from '../../elements/notification';
1
+ import { UISuccess, UIError } from "../../elements/notification";
2
2
 
3
- export default class CRUDMessage{
3
+ export default class CRUDMessage {
4
+ static error(controller, title, message) {
5
+ controller.setUI(
6
+ "__message__",
7
+ new UIError({
8
+ target: controller.getContainerInnerElement(),
9
+ props: { title, message },
10
+ })
11
+ );
12
+ }
4
13
 
5
- static error(controller, title, message){
6
- controller.setUI('__message__', new UIError({
7
- target: controller.getContainerInnerElement(),
8
- props:{title, message}
9
- }));
10
- }
11
-
12
- static success(controller, title, message){
13
- controller.setUI('__message__', new UISuccess({
14
- target: controller.getContainerInnerElement(),
15
- props:{title, message}
16
- }));
17
- }
14
+ static success(controller, title, message) {
15
+ controller.setUI(
16
+ "__message__",
17
+ new UISuccess({
18
+ target: controller.getContainerInnerElement(),
19
+ props: { title, message },
20
+ })
21
+ );
22
+ }
18
23
  }