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 +1 -1
- package/src/frame/crud/actions/create.js +55 -43
- package/src/frame/crud/actions/details.js +70 -52
- package/src/frame/crud/actions/list.js +1 -0
- package/src/frame/crud/actions/update.js +73 -56
- package/src/frame/crud/const.js +3 -0
- package/src/frame/crud/create.crud.action.ui.view.js +24 -2
- package/src/frame/crud/message.js +20 -15
package/package.json
CHANGED
|
@@ -1,49 +1,61 @@
|
|
|
1
|
-
import {notForm} from
|
|
1
|
+
import { notForm } from "../../components";
|
|
2
|
+
import { DEFAULT_TRASFORMER } from "../const";
|
|
2
3
|
|
|
3
|
-
const ACTION =
|
|
4
|
-
const MODEL_ACTION =
|
|
4
|
+
const ACTION = "create";
|
|
5
|
+
const MODEL_ACTION = "create";
|
|
5
6
|
|
|
6
7
|
export default class CRUDActionCreate {
|
|
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
|
-
|
|
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
|
|
1
|
+
import { notForm } from "../../components";
|
|
2
|
+
import { DEFAULT_TRASFORMER } from "../const";
|
|
2
3
|
|
|
3
|
-
const ACTION =
|
|
4
|
-
const MODEL_ACTION =
|
|
4
|
+
const ACTION = "details";
|
|
5
|
+
const MODEL_ACTION = "get";
|
|
5
6
|
|
|
6
7
|
export default class CRUDActionDetails {
|
|
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
|
-
|
|
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
|
}
|
|
@@ -1,68 +1,85 @@
|
|
|
1
|
-
import {notForm} from
|
|
2
|
-
import notCommon from
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
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
|
-
|
|
17
|
+
controller.setBreadcrumbs([
|
|
18
|
+
{
|
|
19
|
+
title: "Редактирование",
|
|
20
|
+
url: controller.getModelActionURL(id, ACTION),
|
|
21
|
+
},
|
|
22
|
+
]);
|
|
16
23
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
24
|
+
if (controller.ui[ACTION]) {
|
|
25
|
+
return;
|
|
26
|
+
} else {
|
|
27
|
+
controller.$destroyUI();
|
|
28
|
+
}
|
|
21
29
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}]);
|
|
47
|
+
const resultTransformer = controller.getOptions(
|
|
48
|
+
`${ACTION}.transformer`,
|
|
49
|
+
DEFAULT_TRASFORMER
|
|
50
|
+
);
|
|
39
51
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
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
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
}
|