not-options 0.2.1 → 0.2.2

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/index.js CHANGED
@@ -11,10 +11,10 @@ try{
11
11
  });
12
12
 
13
13
  module.exports = {
14
- name: 'not-options',
14
+ name: require('./src/const').MODULE_NAME,
15
15
  paths,
16
- getMiddleware(options){
17
- log.info('...options middleware');
16
+ getMiddleware(){
17
+ log?.info('...options middleware');
18
18
  return middleware.bind(this);
19
19
  },
20
20
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "not-options",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "not-* family options model in not- environment",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/const.js ADDED
@@ -0,0 +1,4 @@
1
+ module.exports ={
2
+ MODULE_NAME: 'not-options',
3
+ DATA_MODEL_NAME: "options"
4
+ };
@@ -0,0 +1,103 @@
1
+ import CRUDGenericActionRead from "not-bulma/src/frame/crud/actions/generic/read";
2
+ import UIExportToJSON from "./export.to.json.svelte";
3
+ import { MODULE_NAME, DATA_MODEL_NAME } from "../../../../const.js";
4
+
5
+ const DEFAULT_BREADCRUMB_TAIL = `${MODULE_NAME}:action_export_to_json_title`;
6
+
7
+ class ncaExportToJSON extends CRUDGenericActionRead {
8
+ /**
9
+ * @static {string} ACTION this controller action name, used in URI
10
+ */
11
+ static get ACTION() {
12
+ return "exportToJSON";
13
+ }
14
+
15
+ static get deafultBreadcrumbsTail() {
16
+ return DEFAULT_BREADCRUMB_TAIL;
17
+ }
18
+
19
+ static get breadcrumbsTails() {
20
+ return {
21
+ preset: DEFAULT_BREADCRUMB_TAIL,
22
+ set: DEFAULT_BREADCRUMB_TAIL,
23
+ };
24
+ }
25
+
26
+ /**
27
+ * @static {string} MODEL_ACTION network model interface action name, used in API
28
+ */
29
+ static get MODEL_ACTION_GET() {
30
+ return "exportToJSON";
31
+ }
32
+
33
+ /**
34
+ * @static {object} UIConstructor constructor of UI component
35
+ */
36
+ static get UIConstructor() {
37
+ return UIExportToJSON;
38
+ }
39
+
40
+ static actionButton(controller) {
41
+ return {
42
+ title: `${MODULE_NAME}:action_export_to_json_title`,
43
+ action() {
44
+ controller.navigateAction(undefined, ncaExportToJSON.ACTION);
45
+ },
46
+ };
47
+ }
48
+
49
+ static prepareUIOptions(controller, response) {
50
+ const actionName = this.getModelActionName(controller);
51
+ return {
52
+ target: controller.getContainerInnerElement(),
53
+ props: {
54
+ value: response.result,
55
+ actionName,
56
+ },
57
+ };
58
+ }
59
+
60
+ static async loadData(controller, params) {
61
+ return await controller
62
+ .getModel(DATA_MODEL_NAME, {
63
+ moduleName: controller.getModuleName(),
64
+ })
65
+ .$getForModule();
66
+ }
67
+
68
+ static async run(controller, params) {
69
+ try {
70
+ //inform that we are starting
71
+ controller.emit(`before:render:${this.ACTION}`, params);
72
+ //if UI for this action exists exiting
73
+ if (this.isUIRendered(controller)) {
74
+ return;
75
+ }
76
+ //setting initial state of breadcrumbs tail
77
+ this.presetBreadcrumbs(controller, params);
78
+ const response = await this.loadData(controller, params);
79
+ if (this.isResponseBad(response)) {
80
+ return controller.showErrorMessage(response);
81
+ }
82
+ //creating action UI component
83
+ const uiComponent = this.UIConstructor;
84
+ this.setUI(
85
+ controller,
86
+ new uiComponent(this.prepareUIOptions(controller, response))
87
+ );
88
+ //bind events to UI
89
+ this.bindUIEvents(controller, params, response);
90
+ //inform that we are ready
91
+ controller.emit(`after:render:${this.ACTION}`, params, response);
92
+ } catch (e) {
93
+ //informing about exception
94
+ controller.emit(`exception:render:${this.ACTION}`, params, e);
95
+ //reporting exception
96
+ controller.report(e);
97
+ //showing error message
98
+ controller.showErrorMessage(e);
99
+ }
100
+ }
101
+ }
102
+
103
+ export default ncaExportToJSON;
@@ -0,0 +1,19 @@
1
+ <script>
2
+ export let value = {};
3
+ import UIButtons from "not-bulma/src/elements/button/ui.buttons.svelte";
4
+
5
+ $: json = value && JSON.stringify(value, null, 4);
6
+
7
+ const BUTTONS = [
8
+ {
9
+ icon: "clipboard",
10
+ action: () => {
11
+ navigator.clipboard.writeText(json);
12
+ },
13
+ },
14
+ ];
15
+ </script>
16
+
17
+ <pre class="not-top-padding">
18
+ <UIButtons values={BUTTONS} right={true} />
19
+ {json}</pre>
@@ -0,0 +1,139 @@
1
+ import CRUDGenericActionCreate from "not-bulma/src/frame/crud/actions/generic/create";
2
+ import UIImportFromJSON from "./import.from.json.svelte";
3
+ import { MODULE_NAME,DATA_MODEL_NAME } from "./../../../../const.js";
4
+ import notCommon from "not-bulma/src/frame/common";
5
+
6
+ const DEFAULT_BREADCRUMB_TAIL = `${MODULE_NAME}:action_import_from_json_title`;
7
+
8
+ class ncaImportFromJSON extends CRUDGenericActionCreate {
9
+ static get deafultBreadcrumbsTail() {
10
+ return DEFAULT_BREADCRUMB_TAIL;
11
+ }
12
+
13
+ static get breadcrumbsTails() {
14
+ return {
15
+ preset: DEFAULT_BREADCRUMB_TAIL,
16
+ set: DEFAULT_BREADCRUMB_TAIL,
17
+ };
18
+ }
19
+
20
+ /**
21
+ * @static {string} ACTION this controller action name, used in URI
22
+ */
23
+ static get ACTION() {
24
+ return "importFromJSON";
25
+ }
26
+
27
+ static get MODEL_ACTION_GET() {
28
+ return undefined;
29
+ }
30
+
31
+ static get MODEL_ACTION_PUT() {
32
+ return "updateForModule";
33
+ }
34
+
35
+ /**
36
+ * @static {object} UIConstructor constructor of UI component
37
+ */
38
+ static get UIConstructor() {
39
+ return UIImportFromJSON;
40
+ }
41
+
42
+ static prepareUIOptions(controller, value) {
43
+ const actionName = this.getModelActionName(controller);
44
+ return {
45
+ props: {
46
+ actionName,
47
+ },
48
+ target: controller.getContainerInnerElement(),
49
+ };
50
+ }
51
+
52
+ static actionButton(controller) {
53
+ return {
54
+ action() {
55
+ controller.navigateAction(undefined, ncaImportFromJSON.ACTION);
56
+ },
57
+ title: `${MODULE_NAME}:action_import_from_json_title`,
58
+ };
59
+ }
60
+
61
+ static async run(controller, params) {
62
+ try {
63
+ //inform that we are starting
64
+ controller.emit(`before:render:${this.ACTION}`, params);
65
+ //if UI for this action exists exiting
66
+ if (this.isUIRendered(controller)) {
67
+ return;
68
+ }
69
+ //setting initial state of breadcrumbs tail
70
+ this.presetBreadcrumbs(controller, params);
71
+ //creating action UI component
72
+ const uiComponent = this.UIConstructor;
73
+ const response = {};
74
+ this.setUI(
75
+ controller,
76
+ new uiComponent(this.prepareUIOptions(controller, response))
77
+ );
78
+ //bind events to UI
79
+ this.bindUIEvents(controller, params, response);
80
+ //inform that we are ready
81
+ controller.emit(`after:render:${this.ACTION}`, params, response);
82
+ } catch (e) {
83
+ //informing about exception
84
+ controller.emit(`exception:render:${this.ACTION}`, params, e);
85
+ //reporting exception
86
+ controller.report(e);
87
+ //showing error message
88
+ controller.showErrorMessage(e);
89
+ }
90
+ }
91
+
92
+ static bindUIEvents(controller, params, response) {
93
+ if (notCommon.isFunc(controller.goBack)) {
94
+ this.bindUIEvent(controller, "reject", () => controller.goBack());
95
+ }
96
+
97
+ this.bindUIEvent(controller, "import", ({ detail }) => {
98
+ ncaImportFromJSON.import(controller, detail);
99
+ });
100
+ }
101
+
102
+ static setUILoading(controller) {
103
+ this.getUI(controller).$set({ loading: true });
104
+ }
105
+
106
+ static setUILoaded(controller) {
107
+ this.getUI(controller).$set({ loading: false });
108
+ }
109
+
110
+ static setUIError(controller, message) {
111
+ this.getUI(controller).$set({ error: message });
112
+ }
113
+
114
+ static async import(controller, jsonAsText) {
115
+ try {
116
+ ncaImportFromJSON.setUILoading(controller);
117
+ const res = await controller
118
+ .getModel(DATA_MODEL_NAME, {
119
+ moduleName: controller.MODULE_NAME,
120
+ options: jsonAsText
121
+ })
122
+ [`$${ncaImportFromJSON.MODEL_ACTION_PUT}`]();
123
+ if (this.isResponseBad(res)) {
124
+ controller.showErrorMessage(res);
125
+ } else {
126
+ controller.showSuccessMessage(
127
+ "",
128
+ `${MODULE_NAME}:action_import_success`
129
+ );
130
+ controller.navigateAction(undefined, "list", "NORMAL");
131
+ }
132
+ } catch (e) {
133
+ controller.showErrorMessage(e);
134
+ } finally {
135
+ ncaImportFromJSON.setUILoaded(controller);
136
+ }
137
+ }
138
+ }
139
+ export default ncaImportFromJSON;
@@ -0,0 +1,21 @@
1
+ <script>
2
+ import { createEventDispatcher } from "svelte";
3
+ const dispatch = createEventDispatcher();
4
+ import UITextarea from "not-bulma/src/elements/form/ui.textarea.svelte";
5
+ import UIButton from "not-bulma/src/elements/button/ui.button.svelte";
6
+ import { MODULE_NAME } from "../../../../const.js";
7
+ export let value = "";
8
+ export let loading = false;
9
+ </script>
10
+
11
+ <UITextarea bind:value rows={20} disabled={loading} placeholder={""} />
12
+
13
+ <UIButton
14
+ action={() => {
15
+ dispatch("import", value);
16
+ }}
17
+ color={"primary"}
18
+ disabled={loading}
19
+ {loading}
20
+ title={`${MODULE_NAME}:action_import_from_json_title`}
21
+ />
@@ -1,3 +1,5 @@
1
+ import 'styles.scss';
2
+
1
3
  export default class Common{
2
4
  static DEFAULT_REDIRECT_TIMEOUT = 5000;
3
5
  static CLASS_OK = 'is-success';
@@ -0,0 +1,3 @@
1
+ .not-top-padding{
2
+ padding-top: 0rem!important;
3
+ }
@@ -1,4 +1,6 @@
1
1
  {
2
2
  "title": "Options module",
3
- "document_not_found": "Document was not found"
4
- }
3
+ "document_not_found": "Document was not found",
4
+ "action_export_to_json_title": "Export to JSON",
5
+ "action_import_from_json_title": "Import from JSON"
6
+ }
@@ -1,4 +1,7 @@
1
1
  {
2
2
  "title": "Модуль настроек",
3
- "document_not_found": "Документ не найден"
4
- }
3
+ "document_not_found": "Документ не найден",
4
+ "action_export_to_json_title": "Экспорт в JSON",
5
+ "action_import_from_json_title": "Импорт из JSON",
6
+ "action_import_success": "Импорт успешно завершен!"
7
+ }