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 +1 -1
- package/src/controllers/common/actions/json.import.export/export.to.json.js +5 -7
- package/src/controllers/common/actions/json.import.export/import.from.json.js +9 -10
- package/src/controllers/common/actions/json.import.export/import.from.json.svelte +6 -6
- package/src/controllers/common/import.svelte +135 -113
- package/src/controllers/common/index.js +1 -1
- package/src/controllers/root/index.js +1 -1
- package/src/controllers/root/ncOptions.js +12 -13
- package/src/fields/value.js +5 -2
- package/src/models/options.js +2 -1
package/package.json
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
84
|
-
this.setUI(
|
|
81
|
+
//creating action UI component
|
|
82
|
+
this.buildUI(
|
|
85
83
|
controller,
|
|
86
|
-
|
|
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
|
-
|
|
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.
|
|
73
|
+
this.buildUI(
|
|
75
74
|
controller,
|
|
76
|
-
|
|
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, "
|
|
93
|
+
this.bindUIEvent(controller, "onreject", () => controller.goBack());
|
|
95
94
|
}
|
|
96
95
|
|
|
97
|
-
this.bindUIEvent(controller, "
|
|
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)
|
|
102
|
+
this.getUI(controller).set('loading', true );
|
|
104
103
|
}
|
|
105
104
|
|
|
106
105
|
static setUILoaded(controller) {
|
|
107
|
-
this.getUI(controller)
|
|
106
|
+
this.getUI(controller).set('loading', false );
|
|
108
107
|
}
|
|
109
108
|
|
|
110
109
|
static setUIError(controller, message) {
|
|
111
|
-
this.getUI(controller)
|
|
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 {
|
|
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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
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
|
-
|
|
46
|
-
|
|
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
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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
|
-
|
|
93
|
-
|
|
94
|
-
{
|
|
95
|
-
|
|
96
|
-
{
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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>
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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 =
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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
|
|
133
|
-
this.ui.import
|
|
134
|
-
if (ev.
|
|
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.
|
|
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.
|
|
139
|
+
this.ui.import.set('info', res.result.info);
|
|
141
140
|
this.afterImportSuccess(res.result);
|
|
142
141
|
}
|
|
143
142
|
} else {
|
package/src/fields/value.js
CHANGED
|
@@ -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:
|
|
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",
|
package/src/models/options.js
CHANGED
|
@@ -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
|
-
|
|
10
|
+
`${MODULE_NAME}//value`,
|
|
10
11
|
[
|
|
11
12
|
"active",
|
|
12
13
|
{
|