@radiantabyss/vue 3.3.20 → 4.0.0
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 +31 -28
- package/src/Bootstrap.js +11 -5
- package/src/Components.js +1 -1
- package/src/Directives.js +1 -1
- package/src/Invoke.js +89 -89
- package/src/Modals.js +1 -1
- package/src/Routing/Route.js +77 -77
- package/src/Routing/RouteCrud.js +15 -15
- package/src/Routing/Router.js +115 -115
- package/src/Support/Helpers.js +0 -25
- package/src/Support/Item.js +0 -67
- package/src/Support/Items.js +0 -363
- package/src/Support/Str.js +0 -382
package/src/Routing/Router.js
CHANGED
|
@@ -1,115 +1,115 @@
|
|
|
1
|
-
import { nextTick, watch } from 'vue';
|
|
2
|
-
import { createRouter, createWebHistory, createWebHashHistory, createMemoryHistory } from 'vue-router';
|
|
3
|
-
import Str from '
|
|
4
|
-
import Actions from './Actions.js';
|
|
5
|
-
import Middleware from './Middleware.js';
|
|
6
|
-
import RouteFiles from './RouteFiles.js';
|
|
7
|
-
import Route from './Route.js';
|
|
8
|
-
import RouteCrud from './RouteCrud.js';
|
|
9
|
-
|
|
10
|
-
window.RouteFiles = RouteFiles;
|
|
11
|
-
window.Route = Route;
|
|
12
|
-
window.RouteCrud = RouteCrud;
|
|
13
|
-
|
|
14
|
-
//load route files
|
|
15
|
-
let context = import.meta.glob('/app/Routes/**/*.js');
|
|
16
|
-
|
|
17
|
-
const loadModules = async () => {
|
|
18
|
-
window.Actions = await Actions();
|
|
19
|
-
const files = Object.keys(context);
|
|
20
|
-
|
|
21
|
-
for ( let i = 0; i < files.length; i++ ) {
|
|
22
|
-
let file = files[i].replace('/app/Routes/', '').replace(/\.js$/, '');
|
|
23
|
-
window.__route_file = file;
|
|
24
|
-
|
|
25
|
-
if ( !RouteFiles[__route_file] ) {
|
|
26
|
-
RouteFiles[__route_file] = [];
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
await context[files[i]]();
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export default async (history_mode = 'web') => {
|
|
34
|
-
let runMiddleware = await Middleware();
|
|
35
|
-
|
|
36
|
-
await loadModules();
|
|
37
|
-
|
|
38
|
-
let history;
|
|
39
|
-
if ( history_mode == 'web' ) {
|
|
40
|
-
history = createWebHistory();
|
|
41
|
-
}
|
|
42
|
-
else if ( history_mode == 'hash' ) {
|
|
43
|
-
history = createWebHashHistory();
|
|
44
|
-
}
|
|
45
|
-
else if ( history_mode == 'memory' ) {
|
|
46
|
-
history = createMemoryHistory();
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
//create router
|
|
50
|
-
const Router = createRouter({
|
|
51
|
-
history,
|
|
52
|
-
routes: [],
|
|
53
|
-
duplicateNavigationPolicy: 'reload',
|
|
54
|
-
scrollBehavior(to, from, scroll) {
|
|
55
|
-
if ( (to.meta.settings && to.meta.settings.disable_scroll)
|
|
56
|
-
|| (from.name == to.name && (!to.meta.settings || !to.meta.settings.force_scroll)) ) {
|
|
57
|
-
return scroll;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return {
|
|
61
|
-
x: 0,
|
|
62
|
-
y: 0
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
//run middleware
|
|
68
|
-
Router.beforeEach(async (to, from, next) => {
|
|
69
|
-
try {
|
|
70
|
-
await runMiddleware(to, from);
|
|
71
|
-
next();
|
|
72
|
-
}
|
|
73
|
-
catch(redirect) {
|
|
74
|
-
if ( redirect === false || to.path == redirect ) {
|
|
75
|
-
return next();
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
next({path: redirect});
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
Router.afterEach((to, from) => {
|
|
83
|
-
//save previous route
|
|
84
|
-
localStorage.setItem('_previous_route', from.fullPath != '/' ? from.fullPath : '');
|
|
85
|
-
|
|
86
|
-
//change document title
|
|
87
|
-
let title = to.name.replace(/\//g, ' / ').replace(/Action$/, '');
|
|
88
|
-
if ( to.meta.settings.title ) {
|
|
89
|
-
if ( typeof to.meta.settings.title == 'function' ) {
|
|
90
|
-
nextTick(async () => {
|
|
91
|
-
let instance = to.matched[to.matched.length - 1]?.instances?.default;
|
|
92
|
-
if ( !instance ) {
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
watch(
|
|
97
|
-
() => ({ ...instance.$data }),
|
|
98
|
-
async () => {
|
|
99
|
-
document.title = await to.meta.settings.title.call(instance);
|
|
100
|
-
},
|
|
101
|
-
{ deep: true }
|
|
102
|
-
);
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
document.title = to.meta.settings.title;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
document.title = `${title} :: ${import.meta.env.VITE_NAME}`;
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
return { Router, RouteFiles };
|
|
115
|
-
};
|
|
1
|
+
import { nextTick, watch } from 'vue';
|
|
2
|
+
import { createRouter, createWebHistory, createWebHashHistory, createMemoryHistory } from 'vue-router';
|
|
3
|
+
import Str from '@radiantabyss/support/src/Str.js';
|
|
4
|
+
import Actions from './Actions.js';
|
|
5
|
+
import Middleware from './Middleware.js';
|
|
6
|
+
import RouteFiles from './RouteFiles.js';
|
|
7
|
+
import Route from './Route.js';
|
|
8
|
+
import RouteCrud from './RouteCrud.js';
|
|
9
|
+
|
|
10
|
+
window.RouteFiles = RouteFiles;
|
|
11
|
+
window.Route = Route;
|
|
12
|
+
window.RouteCrud = RouteCrud;
|
|
13
|
+
|
|
14
|
+
//load route files
|
|
15
|
+
let context = import.meta.glob('/app/Routes/**/*.js');
|
|
16
|
+
|
|
17
|
+
const loadModules = async () => {
|
|
18
|
+
window.Actions = await Actions();
|
|
19
|
+
const files = Object.keys(context);
|
|
20
|
+
|
|
21
|
+
for ( let i = 0; i < files.length; i++ ) {
|
|
22
|
+
let file = files[i].replace('/app/Routes/', '').replace(/\.js$/, '');
|
|
23
|
+
window.__route_file = file;
|
|
24
|
+
|
|
25
|
+
if ( !RouteFiles[__route_file] ) {
|
|
26
|
+
RouteFiles[__route_file] = [];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
await context[files[i]]();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export default async (history_mode = 'web') => {
|
|
34
|
+
let runMiddleware = await Middleware();
|
|
35
|
+
|
|
36
|
+
await loadModules();
|
|
37
|
+
|
|
38
|
+
let history;
|
|
39
|
+
if ( history_mode == 'web' ) {
|
|
40
|
+
history = createWebHistory();
|
|
41
|
+
}
|
|
42
|
+
else if ( history_mode == 'hash' ) {
|
|
43
|
+
history = createWebHashHistory();
|
|
44
|
+
}
|
|
45
|
+
else if ( history_mode == 'memory' ) {
|
|
46
|
+
history = createMemoryHistory();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
//create router
|
|
50
|
+
const Router = createRouter({
|
|
51
|
+
history,
|
|
52
|
+
routes: [],
|
|
53
|
+
duplicateNavigationPolicy: 'reload',
|
|
54
|
+
scrollBehavior(to, from, scroll) {
|
|
55
|
+
if ( (to.meta.settings && to.meta.settings.disable_scroll)
|
|
56
|
+
|| (from.name == to.name && (!to.meta.settings || !to.meta.settings.force_scroll)) ) {
|
|
57
|
+
return scroll;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
x: 0,
|
|
62
|
+
y: 0
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
//run middleware
|
|
68
|
+
Router.beforeEach(async (to, from, next) => {
|
|
69
|
+
try {
|
|
70
|
+
await runMiddleware(to, from);
|
|
71
|
+
next();
|
|
72
|
+
}
|
|
73
|
+
catch(redirect) {
|
|
74
|
+
if ( redirect === false || to.path == redirect ) {
|
|
75
|
+
return next();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
next({path: redirect});
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
Router.afterEach((to, from) => {
|
|
83
|
+
//save previous route
|
|
84
|
+
localStorage.setItem('_previous_route', from.fullPath != '/' ? from.fullPath : '');
|
|
85
|
+
|
|
86
|
+
//change document title
|
|
87
|
+
let title = to.name.replace(/\//g, ' / ').replace(/Action$/, '');
|
|
88
|
+
if ( to.meta.settings.title ) {
|
|
89
|
+
if ( typeof to.meta.settings.title == 'function' ) {
|
|
90
|
+
nextTick(async () => {
|
|
91
|
+
let instance = to.matched[to.matched.length - 1]?.instances?.default;
|
|
92
|
+
if ( !instance ) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
watch(
|
|
97
|
+
() => ({ ...instance.$data }),
|
|
98
|
+
async () => {
|
|
99
|
+
document.title = await to.meta.settings.title.call(instance);
|
|
100
|
+
},
|
|
101
|
+
{ deep: true }
|
|
102
|
+
);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
document.title = to.meta.settings.title;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
document.title = `${title} :: ${import.meta.env.VITE_NAME}`;
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
return { Router, RouteFiles };
|
|
115
|
+
};
|
package/src/Support/Helpers.js
CHANGED
|
@@ -1,29 +1,4 @@
|
|
|
1
1
|
let self = {
|
|
2
|
-
dmp(text) {
|
|
3
|
-
// eslint-disable-next-line
|
|
4
|
-
console.log(text);
|
|
5
|
-
},
|
|
6
|
-
|
|
7
|
-
handleEmpty(items) {
|
|
8
|
-
if ( items === false ) {
|
|
9
|
-
return false;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
if ( items === null ) {
|
|
13
|
-
return null;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
if ( Array.isArray(items) && !items.length ) {
|
|
17
|
-
return [];
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
if ( !Array.isArray(items) && !Object.keys(items).length ) {
|
|
21
|
-
return {};
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return true;
|
|
25
|
-
},
|
|
26
|
-
|
|
27
2
|
array_unique(arr) {
|
|
28
3
|
return [...new Set(arr)];
|
|
29
4
|
},
|
package/src/Support/Item.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
let self = {
|
|
2
|
-
patch(item, data) {
|
|
3
|
-
return self.setKeys(item, Object.keys(data), Object.values(data));
|
|
4
|
-
},
|
|
5
|
-
|
|
6
|
-
setKey(item, key, value) {
|
|
7
|
-
return self.setKeys(item, key, value);
|
|
8
|
-
},
|
|
9
|
-
|
|
10
|
-
setKeys(item, keys, values) {
|
|
11
|
-
let not_empty = window.handleEmpty(item);
|
|
12
|
-
if ( not_empty !== true ) {
|
|
13
|
-
item = {};
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
if ( Array.isArray(keys) && !Array.isArray(values) ) {
|
|
17
|
-
let array_values = [];
|
|
18
|
-
for ( let key of keys ) {
|
|
19
|
-
array_values.push(values);
|
|
20
|
-
}
|
|
21
|
-
values = array_values;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
if ( !Array.isArray(keys) ) {
|
|
25
|
-
keys = [keys];
|
|
26
|
-
values = [values];
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
for ( let i = 0; i < keys.length; i++ ) {
|
|
30
|
-
item[keys[i]] = values[i];
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return {...item};
|
|
34
|
-
},
|
|
35
|
-
|
|
36
|
-
removeEmptyKeys(item) {
|
|
37
|
-
let new_item = Array.isArray(item) ? [] : {};
|
|
38
|
-
let count = Array.isArray(item) ? item.length : Object.keys(item).length;
|
|
39
|
-
for ( let i = 0; i < count; i++ ) {
|
|
40
|
-
let index = Array.isArray(item) ? i : Object.keys(item)[i];
|
|
41
|
-
|
|
42
|
-
if ( item[index] !== '' ) {
|
|
43
|
-
new_item[index] = item[index];
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return new_item;
|
|
48
|
-
},
|
|
49
|
-
|
|
50
|
-
deleteKeys(item, keys) {
|
|
51
|
-
for ( let key of keys ) {
|
|
52
|
-
delete item[key];
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return {...item};
|
|
56
|
-
},
|
|
57
|
-
|
|
58
|
-
deleteKey(item, key) {
|
|
59
|
-
return self.deleteKeys(item, [key]);
|
|
60
|
-
},
|
|
61
|
-
|
|
62
|
-
clone(item) {
|
|
63
|
-
return JSON.parse(JSON.stringify(item));
|
|
64
|
-
},
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
export default self;
|
package/src/Support/Items.js
DELETED
|
@@ -1,363 +0,0 @@
|
|
|
1
|
-
const self = {
|
|
2
|
-
pluck(items, key = 'id') {
|
|
3
|
-
let plucked = [];
|
|
4
|
-
for (let i = 0; i < items.length; i++) {
|
|
5
|
-
plucked.push(items[i][key]);
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
return plucked;
|
|
9
|
-
},
|
|
10
|
-
|
|
11
|
-
spread(items) {
|
|
12
|
-
return JSON.parse(JSON.stringify(items));
|
|
13
|
-
},
|
|
14
|
-
|
|
15
|
-
keyBy(items, key = 'id') {
|
|
16
|
-
let not_empty = window.handleEmpty(items);
|
|
17
|
-
if ( not_empty !== true ) {
|
|
18
|
-
return not_empty;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
let new_items = {};
|
|
22
|
-
let count = Array.isArray(items) ? items.length : Object.keys(items).length;
|
|
23
|
-
for ( let i = 0; i < count; i++ ) {
|
|
24
|
-
let index = Array.isArray(items) ? i : Object.keys(items)[i];
|
|
25
|
-
new_items[items[index][key]] = items[index];
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return new_items;
|
|
29
|
-
},
|
|
30
|
-
|
|
31
|
-
groupBy(items, key = 'id') {
|
|
32
|
-
let not_empty = window.handleEmpty(items);
|
|
33
|
-
if ( not_empty !== true ) {
|
|
34
|
-
return not_empty;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
let new_items = {};
|
|
38
|
-
let count = Array.isArray(items) ? items.length : Object.keys(items).length;
|
|
39
|
-
for ( let i = 0; i < count; i++ ) {
|
|
40
|
-
let index = Array.isArray(items) ? i : Object.keys(items)[i];
|
|
41
|
-
|
|
42
|
-
if (typeof new_items[items[index][key]] === 'undefined') {
|
|
43
|
-
new_items[items[index][key]] = [];
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
new_items[items[index][key]].push(items[index]);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return new_items;
|
|
50
|
-
},
|
|
51
|
-
|
|
52
|
-
find(items, ids) {
|
|
53
|
-
let not_empty = window.handleEmpty(items);
|
|
54
|
-
if ( not_empty !== true ) {
|
|
55
|
-
return false;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
let single = false;
|
|
59
|
-
if ( !Array.isArray(ids) ) {
|
|
60
|
-
if ( typeof ids === 'string' ) {
|
|
61
|
-
ids = parseInt(ids);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
ids = [ids];
|
|
65
|
-
single = true;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
let new_items = Array.isArray(items) ? [] : {};
|
|
69
|
-
let count = Array.isArray(items) ? items.length : Object.keys(items).length;
|
|
70
|
-
for ( let i = 0; i < count; i++ ) {
|
|
71
|
-
let index = Array.isArray(items) ? i : Object.keys(items)[i];
|
|
72
|
-
|
|
73
|
-
if ( ids.includes(parseInt(items[index].id)) ) {
|
|
74
|
-
if ( Array.isArray(items) ) {
|
|
75
|
-
new_items.push(items[index]);
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
new_items[index] = items[index];
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if ( single ) {
|
|
84
|
-
if ( Array.isArray(new_items) && new_items.length ) {
|
|
85
|
-
return new_items[0];
|
|
86
|
-
}
|
|
87
|
-
else if ( !Array.isArray(new_items) && Object.keys(new_items).length ) {
|
|
88
|
-
return new_items[Object.keys(new_items)[0]];
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
return false;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return new_items;
|
|
95
|
-
},
|
|
96
|
-
|
|
97
|
-
findByKey(items, key, value = true, single = false) {
|
|
98
|
-
let not_empty = window.handleEmpty(items);
|
|
99
|
-
if ( not_empty !== true ) {
|
|
100
|
-
return false;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
let new_items = Array.isArray(items) ? [] : {};
|
|
104
|
-
let count = Array.isArray(items) ? items.length : Object.keys(items).length;
|
|
105
|
-
for ( let i = 0; i < count; i++ ) {
|
|
106
|
-
let index = Array.isArray(items) ? i : Object.keys(items)[i];
|
|
107
|
-
|
|
108
|
-
if ( items[index][key] == value ) {
|
|
109
|
-
if ( Array.isArray(items) ) {
|
|
110
|
-
new_items.push(items[index]);
|
|
111
|
-
}
|
|
112
|
-
else {
|
|
113
|
-
new_items[index] = items[index];
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
if ( single ) {
|
|
119
|
-
if ( Array.isArray(new_items) && new_items.length ) {
|
|
120
|
-
return new_items[0];
|
|
121
|
-
}
|
|
122
|
-
else if ( !Array.isArray(new_items) && Object.keys(new_items).length ) {
|
|
123
|
-
return new_items[Object.keys(new_items)[0]];
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
return false;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
return new_items;
|
|
130
|
-
},
|
|
131
|
-
|
|
132
|
-
add(items, item, at_first_position = false) {
|
|
133
|
-
let not_empty = window.handleEmpty(items);
|
|
134
|
-
if ( not_empty !== true ) {
|
|
135
|
-
items = [];
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
if ( at_first_position ) {
|
|
139
|
-
items.unshift(item);
|
|
140
|
-
}
|
|
141
|
-
else {
|
|
142
|
-
items.push(item);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
return items;
|
|
146
|
-
},
|
|
147
|
-
|
|
148
|
-
addMany(items, added, at_first_position = false) {
|
|
149
|
-
let not_empty = window.handleEmpty(items);
|
|
150
|
-
if ( not_empty !== true ) {
|
|
151
|
-
items = [];
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
if ( at_first_position ) {
|
|
155
|
-
return added.concat(items);
|
|
156
|
-
}
|
|
157
|
-
else {
|
|
158
|
-
return items.concat(added);
|
|
159
|
-
}
|
|
160
|
-
},
|
|
161
|
-
|
|
162
|
-
patch(items, data) {
|
|
163
|
-
if ( !data.id ) {
|
|
164
|
-
throw 'ID is required.';
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
let id = data.id;
|
|
168
|
-
delete data.id;
|
|
169
|
-
|
|
170
|
-
return self.setKeys(items, id, Object.keys(data), Object.values(data));
|
|
171
|
-
},
|
|
172
|
-
|
|
173
|
-
replace(items, item) {
|
|
174
|
-
let not_empty = window.handleEmpty(items);
|
|
175
|
-
if ( not_empty !== true ) {
|
|
176
|
-
return not_empty;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
let new_items = Array.isArray(items) ? [] : {};
|
|
180
|
-
let count = Array.isArray(items) ? items.length : Object.keys(items).length;
|
|
181
|
-
for ( let i = 0; i < count; i++ ) {
|
|
182
|
-
let index = Array.isArray(items) ? i : Object.keys(items)[i];
|
|
183
|
-
|
|
184
|
-
if ( items[index].id == item.id ) {
|
|
185
|
-
new_items[index] = item;
|
|
186
|
-
}
|
|
187
|
-
else {
|
|
188
|
-
new_items[index] = items[index];
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
return new_items;
|
|
193
|
-
},
|
|
194
|
-
|
|
195
|
-
delete(items, ids) {
|
|
196
|
-
let not_empty = window.handleEmpty(items);
|
|
197
|
-
if ( not_empty !== true ) {
|
|
198
|
-
return not_empty;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
if ( !Array.isArray(ids) ) {
|
|
202
|
-
if ( typeof ids === 'string' ) {
|
|
203
|
-
ids = parseInt(ids);
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
ids = [ids];
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
let new_items = Array.isArray(items) ? [] : {};
|
|
210
|
-
let count = Array.isArray(items) ? items.length : Object.keys(items).length;
|
|
211
|
-
for ( let i = 0; i < count; i++ ) {
|
|
212
|
-
let index = Array.isArray(items) ? i : Object.keys(items)[i];
|
|
213
|
-
|
|
214
|
-
if ( ids.includes(parseInt(items[index].id)) ) {
|
|
215
|
-
continue;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
if ( Array.isArray(items) ) {
|
|
219
|
-
new_items.push(items[index]);
|
|
220
|
-
}
|
|
221
|
-
else {
|
|
222
|
-
new_items[index] = items[index];
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
return new_items;
|
|
227
|
-
},
|
|
228
|
-
|
|
229
|
-
deleteByKey(items, key, value) {
|
|
230
|
-
let not_empty = window.handleEmpty(items);
|
|
231
|
-
if ( not_empty !== true ) {
|
|
232
|
-
return not_empty;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
let new_items = Array.isArray(items) ? [] : {};
|
|
236
|
-
let count = Array.isArray(items) ? items.length : Object.keys(items).length;
|
|
237
|
-
for ( let i = 0; i < count; i++ ) {
|
|
238
|
-
let index = Array.isArray(items) ? i : Object.keys(items)[i];
|
|
239
|
-
|
|
240
|
-
if ( items[index][key] != value ) {
|
|
241
|
-
new_items[index] = items[index];
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
return new_items;
|
|
246
|
-
},
|
|
247
|
-
|
|
248
|
-
setKey(items, id, key, value) {
|
|
249
|
-
return self.setKeys(items, id, key, value);
|
|
250
|
-
},
|
|
251
|
-
|
|
252
|
-
setKeys(items, ids, keys, values) {
|
|
253
|
-
let not_empty = window.handleEmpty(items);
|
|
254
|
-
if ( not_empty !== true ) {
|
|
255
|
-
return not_empty;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
if ( !Array.isArray(ids) ) {
|
|
259
|
-
if ( typeof ids === 'string' ) {
|
|
260
|
-
ids = parseInt(ids);
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
ids = [ids];
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
if ( Array.isArray(keys) && !Array.isArray(values) ) {
|
|
267
|
-
let array_values = [];
|
|
268
|
-
for ( let key of keys ) {
|
|
269
|
-
array_values.push(values);
|
|
270
|
-
}
|
|
271
|
-
values = array_values;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
if ( !Array.isArray(keys) ) {
|
|
275
|
-
keys = [keys];
|
|
276
|
-
values = [values];
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
let count = Array.isArray(items) ? items.length : Object.keys(items).length;
|
|
280
|
-
for ( let i = 0; i < count; i++ ) {
|
|
281
|
-
let index = Array.isArray(items) ? i : Object.keys(items)[i];
|
|
282
|
-
|
|
283
|
-
if ( ids.includes(parseInt(items[index].id)) ) {
|
|
284
|
-
for ( let j = 0; j < keys.length; j++ ) {
|
|
285
|
-
items[i][keys[j]] = values[j];
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
return items;
|
|
291
|
-
},
|
|
292
|
-
|
|
293
|
-
toggleKey(items, id, key) {
|
|
294
|
-
return self.toggleKeys(items, id, key);
|
|
295
|
-
},
|
|
296
|
-
|
|
297
|
-
toggleKeys(items, ids, keys) {
|
|
298
|
-
let not_empty = window.handleEmpty(items);
|
|
299
|
-
if ( not_empty !== true ) {
|
|
300
|
-
return not_empty;
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
if ( !Array.isArray(ids) ) {
|
|
304
|
-
if ( typeof ids === 'string' ) {
|
|
305
|
-
ids = parseInt(ids);
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
ids = [ids];
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
if ( !Array.isArray(keys) ) {
|
|
312
|
-
keys = [keys];
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
let count = Array.isArray(items) ? items.length : Object.keys(items).length;
|
|
316
|
-
for ( let i = 0; i < count; i++ ) {
|
|
317
|
-
let index = Array.isArray(items) ? i : Object.keys(items)[i];
|
|
318
|
-
|
|
319
|
-
if ( ids.includes(parseInt(items[index].id)) ) {
|
|
320
|
-
for ( let j = 0; j < keys.length; j++ ) {
|
|
321
|
-
items[index][keys[j]] = !items[index][keys[j]];
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
return items;
|
|
327
|
-
},
|
|
328
|
-
|
|
329
|
-
sort(items, from, to) {
|
|
330
|
-
const copy = [...items];
|
|
331
|
-
const valueToMove = copy.splice(from, 1)[0];
|
|
332
|
-
copy.splice(to, 0, valueToMove);
|
|
333
|
-
|
|
334
|
-
return copy;
|
|
335
|
-
},
|
|
336
|
-
|
|
337
|
-
next(items, current, key = 'id') {
|
|
338
|
-
for ( let i = 0; i < items.length; i++ ) {
|
|
339
|
-
if ( items[i][key] == current[key] && i < items.length - 1 ) {
|
|
340
|
-
return items[i + 1];
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
return false;
|
|
345
|
-
},
|
|
346
|
-
|
|
347
|
-
prev(items, current, key = 'id') {
|
|
348
|
-
for ( let i = items.length - 1; i >= 0; i-- ) {
|
|
349
|
-
if ( items[i][key] == current[key] && i > 0 ) {
|
|
350
|
-
return items[i - 1];
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
return false;
|
|
355
|
-
},
|
|
356
|
-
};
|
|
357
|
-
|
|
358
|
-
window.pluck = self.pluck;
|
|
359
|
-
window.spread = self.spread;
|
|
360
|
-
window.keyBy = self.keyBy;
|
|
361
|
-
window.groupBy = self.groupBy;
|
|
362
|
-
|
|
363
|
-
export default self;
|