not-options 0.2.8 → 0.3.1
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/export.to.json.svelte +2 -2
- 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 +13 -7
- package/src/controllers/common/import.svelte +135 -107
- package/src/controllers/common/index.js +1 -1
- package/src/controllers/root/ncOptions.js +11 -11
- 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);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
<script>
|
|
2
|
-
export let value = {};
|
|
3
2
|
import UIButtons from "not-bulma/src/elements/button/ui.buttons.svelte";
|
|
3
|
+
let { value = {} } = $props();
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
let json = $derived(value && JSON.stringify(value, null, 4));
|
|
6
6
|
|
|
7
7
|
const BUTTONS = [
|
|
8
8
|
{
|
|
@@ -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,19 +1,25 @@
|
|
|
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";
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {Object} Props
|
|
7
|
+
* @property {string} [value]
|
|
8
|
+
* @property {boolean} [loading]
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** @type {Props} */
|
|
12
|
+
let {
|
|
13
|
+
value = $bindable(""),
|
|
14
|
+
loading = false,
|
|
15
|
+
onimport = () => {},
|
|
16
|
+
} = $props();
|
|
9
17
|
</script>
|
|
10
18
|
|
|
11
19
|
<UITextarea bind:value rows={20} disabled={loading} placeholder={""} />
|
|
12
20
|
|
|
13
21
|
<UIButton
|
|
14
|
-
action={() =>
|
|
15
|
-
dispatch("import", value);
|
|
16
|
-
}}
|
|
22
|
+
action={() => onimport(value)}
|
|
17
23
|
color={"primary"}
|
|
18
24
|
disabled={loading}
|
|
19
25
|
{loading}
|
|
@@ -1,119 +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
|
-
function fileNameUpdate(){
|
|
33
|
-
if (fileField.files.length > 0){
|
|
34
|
-
let file = fileField.files[0];
|
|
35
|
-
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();
|
|
36
32
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
error = message;
|
|
42
|
-
importing = false;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export function setInfo(message){
|
|
46
|
-
has_info = true;
|
|
47
|
-
info = message;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
async function importFile(){
|
|
51
|
-
try{
|
|
52
|
-
if (fileField.files.length > 0){
|
|
53
|
-
let file = fileField.files[0];
|
|
54
|
-
let contentStr = await file.text();
|
|
55
|
-
importing = true;
|
|
56
|
-
dispatch('import', { options: contentStr });
|
|
57
|
-
}
|
|
58
|
-
}catch(e){
|
|
59
|
-
dispatch('reject', {error: e});
|
|
33
|
+
|
|
34
|
+
function rejectImport() {
|
|
35
|
+
overlay.$destroy();
|
|
36
|
+
onreject({});
|
|
60
37
|
}
|
|
61
|
-
}
|
|
62
|
-
</script>
|
|
63
38
|
|
|
39
|
+
function resolveImport() {
|
|
40
|
+
overlay.$destroy();
|
|
41
|
+
onresolve({});
|
|
42
|
+
}
|
|
64
43
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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>
|
|
85
75
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
{
|
|
89
|
-
|
|
90
|
-
{
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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>
|
|
101
132
|
</div>
|
|
102
|
-
</div>
|
|
103
133
|
</UIOverlay>
|
|
104
134
|
|
|
105
|
-
|
|
106
135
|
<style>
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
.file-select-box .file-label{
|
|
116
|
-
width: 100%;
|
|
117
|
-
}
|
|
136
|
+
.form-paper {
|
|
137
|
+
width: 30vw;
|
|
138
|
+
margin: 35vh auto auto auto;
|
|
139
|
+
}
|
|
140
|
+
.file-select-box {
|
|
141
|
+
margin: 2em 2em;
|
|
142
|
+
}
|
|
118
143
|
|
|
144
|
+
.file-select-box .file-label {
|
|
145
|
+
width: 100%;
|
|
146
|
+
}
|
|
119
147
|
</style>
|
|
@@ -7,6 +7,8 @@ const notCRUD = Frame.notCRUD;
|
|
|
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";
|
|
11
|
+
|
|
10
12
|
const LABELS = {
|
|
11
13
|
plural: `${MODULE_NAME}:${modelName}_label_plural`,
|
|
12
14
|
single: `${MODULE_NAME}:${modelName}_label_single`,
|
|
@@ -119,24 +121,22 @@ class ncOptions extends notCRUD {
|
|
|
119
121
|
openImport() {
|
|
120
122
|
this.log("import");
|
|
121
123
|
this.closeImportPopup();
|
|
122
|
-
this.ui.import = new UIImport
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
if (ev.detail.error) {
|
|
127
|
-
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);
|
|
128
128
|
}
|
|
129
129
|
this.closeImportPopup();
|
|
130
130
|
});
|
|
131
|
-
this.ui.import
|
|
132
|
-
this.ui.import
|
|
133
|
-
if (ev.
|
|
131
|
+
this.ui.import.on("onresolve", () => this.closeImportPopup());
|
|
132
|
+
this.ui.import.on("onimport", async (ev) => {
|
|
133
|
+
if (ev.options) {
|
|
134
134
|
try {
|
|
135
|
-
let res = await this.requestImport(ev.
|
|
135
|
+
let res = await this.requestImport(ev.options);
|
|
136
136
|
this.log(res);
|
|
137
137
|
if (res.status === "ok") {
|
|
138
138
|
if (res.result && res.result.info) {
|
|
139
|
-
this.ui.import.
|
|
139
|
+
this.ui.import.set('info', res.result.info);
|
|
140
140
|
this.afterImportSuccess(res.result);
|
|
141
141
|
}
|
|
142
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
|
{
|