not-options 0.3.0 → 0.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "not-options",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "not-* family options model in not- environment",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -49,11 +49,10 @@ const DEFAULT_BREADCRUMB_TAIL = `${MODULE_NAME}:action_export_to_json_title`;
49
49
  static prepareUIOptions(controller, response) {
50
50
  const actionName = this.getModelActionName(controller);
51
51
  return {
52
- target: controller.getContainerInnerElement(),
53
- props: {
52
+
54
53
  value: response.result,
55
54
  actionName,
56
- },
55
+
57
56
  };
58
57
  }
59
58
 
@@ -79,11 +78,10 @@ const DEFAULT_BREADCRUMB_TAIL = `${MODULE_NAME}:action_export_to_json_title`;
79
78
  if (this.isResponseBad(response)) {
80
79
  return controller.showErrorMessage(response);
81
80
  }
82
- //creating action UI component
83
- const uiComponent = this.UIConstructor;
84
- this.setUI(
81
+ //creating action UI component
82
+ this.buildUI(
85
83
  controller,
86
- new uiComponent(this.prepareUIOptions(controller, response))
84
+ this.prepareUIOptions(controller, response)
87
85
  );
88
86
  //bind events to UI
89
87
  this.bindUIEvents(controller, params, response);
@@ -42,10 +42,9 @@ class ncaImportFromJSON extends CRUDGenericActionCreate {
42
42
  static prepareUIOptions(controller, value) {
43
43
  const actionName = this.getModelActionName(controller);
44
44
  return {
45
- props: {
45
+
46
46
  actionName,
47
- },
48
- target: controller.getContainerInnerElement(),
47
+
49
48
  };
50
49
  }
51
50
 
@@ -71,9 +70,9 @@ class ncaImportFromJSON extends CRUDGenericActionCreate {
71
70
  //creating action UI component
72
71
  const uiComponent = this.UIConstructor;
73
72
  const response = {};
74
- this.setUI(
73
+ this.buildUI(
75
74
  controller,
76
- new uiComponent(this.prepareUIOptions(controller, response))
75
+ this.prepareUIOptions(controller, response)
77
76
  );
78
77
  //bind events to UI
79
78
  this.bindUIEvents(controller, params, response);
@@ -91,24 +90,24 @@ class ncaImportFromJSON extends CRUDGenericActionCreate {
91
90
 
92
91
  static bindUIEvents(controller, params, response) {
93
92
  if (notCommon.isFunc(controller.goBack)) {
94
- this.bindUIEvent(controller, "reject", () => controller.goBack());
93
+ this.bindUIEvent(controller, "onreject", () => controller.goBack());
95
94
  }
96
95
 
97
- this.bindUIEvent(controller, "import", ({ detail }) => {
96
+ this.bindUIEvent(controller, "onimport", ({ detail }) => {
98
97
  ncaImportFromJSON.import(controller, detail);
99
98
  });
100
99
  }
101
100
 
102
101
  static setUILoading(controller) {
103
- this.getUI(controller).$set({ loading: true });
102
+ this.getUI(controller).set('loading', true );
104
103
  }
105
104
 
106
105
  static setUILoaded(controller) {
107
- this.getUI(controller).$set({ loading: false });
106
+ this.getUI(controller).set('loading', false );
108
107
  }
109
108
 
110
109
  static setUIError(controller, message) {
111
- this.getUI(controller).$set({ error: message });
110
+ this.getUI(controller).set( 'error', message);
112
111
  }
113
112
 
114
113
  static async import(controller, jsonAsText) {
@@ -1,6 +1,4 @@
1
1
  <script>
2
- import { createEventDispatcher } from "svelte";
3
- const dispatch = createEventDispatcher();
4
2
  import UITextarea from "not-bulma/src/elements/form/ui.textarea.svelte";
5
3
  import UIButton from "not-bulma/src/elements/button/ui.button.svelte";
6
4
  import { MODULE_NAME } from "../../../../const.js";
@@ -11,15 +9,17 @@
11
9
  */
12
10
 
13
11
  /** @type {Props} */
14
- let { value = $bindable(""), loading = false } = $props();
12
+ let {
13
+ value = $bindable(""),
14
+ loading = false,
15
+ onimport = () => {},
16
+ } = $props();
15
17
  </script>
16
18
 
17
19
  <UITextarea bind:value rows={20} disabled={loading} placeholder={""} />
18
20
 
19
21
  <UIButton
20
- action={() => {
21
- dispatch("import", value);
22
- }}
22
+ action={() => onimport(value)}
23
23
  color={"primary"}
24
24
  disabled={loading}
25
25
  {loading}
@@ -1,125 +1,147 @@
1
1
  <script>
2
- import { createEventDispatcher } from 'svelte';
3
- import { Elements } from 'not-bulma';
4
- const UIOverlay = Elements.Modals.UIOverlay;
5
-
6
- let has_error = $state(false);
7
- let error = $state('');
8
- let has_info = $state(false);
9
- let info = $state('');
10
- let show = true;
11
- let closeOnClick = false;
12
- let closeButton = false;
13
- /**
14
- * @typedef {Object} Props
15
- * @property {boolean} [importing]
16
- */
17
-
18
- /** @type {Props} */
19
- let { importing = $bindable(false) } = $props();
20
- let fileField = $state(),overlay = $state(), filename = $state('');
21
-
22
- const dispatch = createEventDispatcher();
23
-
24
- function overlayClosed(){
25
- rejectImport();
26
- }
27
-
28
- function rejectImport(){
29
- overlay.$destroy();
30
- dispatch('reject', {});
31
- };
32
-
33
- function resolveImport(){
34
- overlay.$destroy();
35
- dispatch('resolve', {});
36
- };
37
-
38
- function fileNameUpdate(){
39
- if (fileField.files.length > 0){
40
- let file = fileField.files[0];
41
- filename = file.name;
2
+ import { Elements } from "not-bulma";
3
+ const UIOverlay = Elements.Modals.UIOverlay;
4
+
5
+ let closeOnClick = false;
6
+ let closeButton = false;
7
+ /**
8
+ * @typedef {Object} Props
9
+ * @property {boolean} [importing]
10
+ */
11
+
12
+ /** @type {Props} */
13
+ let {
14
+ importing = $bindable(false),
15
+ error = "",
16
+ info = "",
17
+ show = true,
18
+ onreject = () => {},
19
+ onresolve = () => {},
20
+ onimport = () => {},
21
+ } = $props();
22
+
23
+ let has_error = $derived(typeof error === "string" && error.length > 0);
24
+ let has_info = $derived(typeof info === "string" && info.length > 0);
25
+
26
+ let fileField = $state(),
27
+ overlay = $state(),
28
+ filename = $state("");
29
+
30
+ function overlayClosed() {
31
+ rejectImport();
42
32
  }
43
- }
44
-
45
- export function setError(message){
46
- has_error = true;
47
- error = message;
48
- importing = false;
49
- }
50
-
51
- export function setInfo(message){
52
- has_info = true;
53
- info = message;
54
- }
55
-
56
- async function importFile(){
57
- try{
58
- if (fileField.files.length > 0){
59
- let file = fileField.files[0];
60
- let contentStr = await file.text();
61
- importing = true;
62
- dispatch('import', { options: contentStr });
63
- }
64
- }catch(e){
65
- dispatch('reject', {error: e});
33
+
34
+ function rejectImport() {
35
+ overlay.$destroy();
36
+ onreject({});
66
37
  }
67
- }
68
- </script>
69
38
 
39
+ function resolveImport() {
40
+ overlay.$destroy();
41
+ onresolve({});
42
+ }
70
43
 
71
- <UIOverlay on:reject="{overlayClosed}" bind:this={overlay} show={true} {closeOnClick} {closeButton}>
72
- <div class="form-paper box {has_error}">
73
- <h4 class="title is-4">Импорт настроек из файла</h4>
74
- <div class="file is-boxed file-select-box">
75
- <label class="file-label">
76
- <input class="file-input" type="file" name="optionsToImport" onchange={fileNameUpdate} bind:this="{fileField}" accept=".json" multiple="false">
77
- <span class="file-cta">
78
- <span class="file-icon">
79
- <i class="fas fa-upload"></i>
80
- </span>
81
- <span class="file-label has-text-centered">
82
- {#if filename }
83
- {filename}
84
- {:else}
85
- Выберите файл
86
- {/if}
87
- </span>
88
- </span>
89
- </label>
90
- </div>
44
+ function fileNameUpdate() {
45
+ if (fileField.files.length > 0) {
46
+ const file = fileField.files[0];
47
+ filename = file.name;
48
+ }
49
+ }
50
+
51
+ export function setError(message) {
52
+ has_error = true;
53
+ error = message;
54
+ importing = false;
55
+ }
56
+
57
+ export function setInfo(message) {
58
+ has_info = true;
59
+ info = message;
60
+ }
61
+
62
+ async function importFile() {
63
+ try {
64
+ if (fileField.files.length > 0) {
65
+ const file = fileField.files[0];
66
+ const contentStr = await file.text();
67
+ importing = true;
68
+ onimport({ options: contentStr });
69
+ }
70
+ } catch (e) {
71
+ onreject({ error: e });
72
+ }
73
+ }
74
+ </script>
91
75
 
92
- {#if has_error}
93
- <div class="notification is-danger">{error}</div>
94
- {/if}
95
-
96
- {#if has_info}
97
- <div class="notification is-info">{info}</div>
98
- {/if}
99
-
100
- <div class="field is-grouped is-grouped-centered">
101
- <p class="control">
102
- <button class="button is-primary {importing?'is-loading':''}" onclick={importFile}>Загрузить</button>
103
- </p>
104
- <p class="control">
105
- <button class="button is-light" onclick={rejectImport}>Закрыть</button>
106
- </p>
76
+ <UIOverlay
77
+ onreject={overlayClosed}
78
+ bind:this={overlay}
79
+ show={true}
80
+ {closeOnClick}
81
+ {closeButton}
82
+ >
83
+ <div class="form-paper box {has_error}">
84
+ <h4 class="title is-4">Импорт настроек из файла</h4>
85
+ <div class="file is-boxed file-select-box">
86
+ <label class="file-label">
87
+ <input
88
+ class="file-input"
89
+ type="file"
90
+ name="optionsToImport"
91
+ onchange={fileNameUpdate}
92
+ bind:this={fileField}
93
+ accept=".json"
94
+ multiple="false"
95
+ />
96
+ <span class="file-cta">
97
+ <span class="file-icon">
98
+ <i class="fas fa-upload"></i>
99
+ </span>
100
+ <span class="file-label has-text-centered">
101
+ {#if filename}
102
+ {filename}
103
+ {:else}
104
+ Выберите файл
105
+ {/if}
106
+ </span>
107
+ </span>
108
+ </label>
109
+ </div>
110
+
111
+ {#if has_error}
112
+ <div class="notification is-danger">{error}</div>
113
+ {/if}
114
+
115
+ {#if has_info}
116
+ <div class="notification is-info">{info}</div>
117
+ {/if}
118
+
119
+ <div class="field is-grouped is-grouped-centered">
120
+ <p class="control">
121
+ <button
122
+ class="button is-primary {importing ? 'is-loading' : ''}"
123
+ onclick={importFile}>Загрузить</button
124
+ >
125
+ </p>
126
+ <p class="control">
127
+ <button class="button is-light" onclick={rejectImport}
128
+ >Закрыть</button
129
+ >
130
+ </p>
131
+ </div>
107
132
  </div>
108
- </div>
109
133
  </UIOverlay>
110
134
 
111
-
112
135
  <style>
113
- .form-paper {
114
- width: 30vw;
115
- margin: 35vh auto auto auto;
116
- }
117
- .file-select-box{
118
- margin: 2em 2em;
119
- }
120
-
121
- .file-select-box .file-label{
122
- width: 100%;
123
- }
136
+ .form-paper {
137
+ width: 30vw;
138
+ margin: 35vh auto auto auto;
139
+ }
140
+ .file-select-box {
141
+ margin: 2em 2em;
142
+ }
124
143
 
144
+ .file-select-box .file-label {
145
+ width: 100%;
146
+ }
125
147
  </style>
@@ -1,3 +1,3 @@
1
- import "styles.scss";
1
+ import "./styles.scss";
2
2
 
3
3
  export {};
@@ -11,7 +11,7 @@ let manifest = {
11
11
  id: "system.options",
12
12
  section: "system",
13
13
  title: "Настройки",
14
- url: "/not-options/options",
14
+ href: "/not-options/options",
15
15
  },
16
16
  ],
17
17
  },
@@ -6,7 +6,8 @@ const notCRUD = Frame.notCRUD;
6
6
 
7
7
  import UIImport from "../common/import.svelte";
8
8
  import CRUDActionList from "not-bulma/src/frame/crud/actions/list";
9
- import { mount } from "svelte";
9
+
10
+ import { UIAdapterSvelte } from "not-bulma/src/frame/index.js";
10
11
 
11
12
  const LABELS = {
12
13
  plural: `${MODULE_NAME}:${modelName}_label_plural`,
@@ -99,7 +100,7 @@ class ncOptions extends notCRUD {
99
100
  {
100
101
  section: ncOptions.MODULE_NAME,
101
102
  title: ncOptions.LABELS.plural,
102
- url: `/${notCommon.lowerFirstLetter(
103
+ href: `/${notCommon.lowerFirstLetter(
103
104
  ncOptions.MODULE_NAME
104
105
  )}/${notCommon.lowerFirstLetter(ncOptions.MODEL_NAME)}`,
105
106
  },
@@ -120,24 +121,22 @@ class ncOptions extends notCRUD {
120
121
  openImport() {
121
122
  this.log("import");
122
123
  this.closeImportPopup();
123
- this.ui.import = mount(UIImport, {
124
- target: document.body,
125
- });
126
- this.ui.import.$on("reject", (ev) => {
127
- if (ev.detail.error) {
128
- this.error(ev.detail.error);
124
+ this.ui.import = new UIAdapterSvelte(UIImport, document.body);
125
+ this.ui.import.on("onreject", (ev) => {
126
+ if (ev.error) {
127
+ this.error(ev.error);
129
128
  }
130
129
  this.closeImportPopup();
131
130
  });
132
- this.ui.import.$on("resolve", () => this.closeImportPopup());
133
- this.ui.import.$on("import", async (ev) => {
134
- if (ev.detail.options) {
131
+ this.ui.import.on("onresolve", () => this.closeImportPopup());
132
+ this.ui.import.on("onimport", async (ev) => {
133
+ if (ev.options) {
135
134
  try {
136
- let res = await this.requestImport(ev.detail.options);
135
+ let res = await this.requestImport(ev.options);
137
136
  this.log(res);
138
137
  if (res.status === "ok") {
139
138
  if (res.result && res.result.info) {
140
- this.ui.import.setInfo(res.result.info);
139
+ this.ui.import.set('info', res.result.info);
141
140
  this.afterImportSuccess(res.result);
142
141
  }
143
142
  } else {
@@ -1,11 +1,14 @@
1
- const Schema = require("mongoose").Schema;
1
+ //const Schema = require("mongoose").Schema;
2
+ const Validators = require("not-node/src/core/validators");
2
3
 
3
4
  module.exports = {
4
5
  parent: "not-node//requiredObject",
5
6
  model: {
6
- type: Schema.Types.Mixed,
7
+ type: String,
8
+ default: '{}',
7
9
  searchable: true,
8
10
  required: true,
11
+ validate: Validators.String.type
9
12
  },
10
13
  ui: {
11
14
  component: "UITextarea",
@@ -1,12 +1,13 @@
1
1
  const log = require("not-log")(module, "Options Model");
2
2
  try {
3
3
  const MODEL_NAME = "Options";
4
+ const {MODULE_NAME} = require('../const');
4
5
  const Increment = require("not-node").Increment;
5
6
  const notError = require("not-error").notError;
6
7
 
7
8
  const FIELDS = [
8
9
  "id",
9
- "value",
10
+ `${MODULE_NAME}//value`,
10
11
  [
11
12
  "active",
12
13
  {