@thzero/library_client_vue3_store_pinia 0.18.36 → 0.19.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/README.md +119 -17
- package/license.md +8 -8
- package/openSource.js +52 -52
- package/package.json +42 -34
- package/service/store/index.js +51 -51
- package/store/admin/news/index.js +86 -76
- package/store/admin/users/index.js +67 -63
- package/store/index.js +329 -323
- package/store/news/index.js +41 -43
- package/store/user/index.js +138 -135
package/README.md
CHANGED
|
@@ -1,17 +1,119 @@
|
|
|
1
|
-

|
|
2
|
-

|
|
2
|
+
[](https://opensource.org/licenses/MIT)
|
|
3
|
+
|
|
4
|
+
# library_client_vue3_store_pinia
|
|
5
|
+
|
|
6
|
+
The application store for [library_client_vue3](https://github.com/thzero/library_client_vue3), on [Pinia](https://pinia.vuejs.org), with persistence through [pinia-plugin-persistedstate](https://prazdevs.github.io/pinia-plugin-persistedstate).
|
|
7
|
+
|
|
8
|
+
## Requirements
|
|
9
|
+
|
|
10
|
+
### NodeJs
|
|
11
|
+
|
|
12
|
+
[NodeJs](https://nodejs.org) version 22+.
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
[](https://npmjs.org/package/@thzero/library_client_vue3_store_pinia)
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
npm install @thzero/library_client_vue3_store_pinia
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
It installs `pinia` and `pinia-plugin-persistedstate`, and requires `@thzero/library_client`, `@thzero/library_client_vue3` and `@thzero/library_common` as peers.
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
### The store
|
|
27
|
+
|
|
28
|
+
Extend `BaseStore` with the application's own state, actions, getters and dispatchers, and export the class:
|
|
29
|
+
|
|
30
|
+
```js
|
|
31
|
+
import BaseStore from '@thzero/library_client_vue3_store_pinia/store/index';
|
|
32
|
+
|
|
33
|
+
class AppStore extends BaseStore {
|
|
34
|
+
_initStoreConfig() {
|
|
35
|
+
return {
|
|
36
|
+
state: () => ({
|
|
37
|
+
launches: []
|
|
38
|
+
}),
|
|
39
|
+
actions: {
|
|
40
|
+
async requestLaunches(correlationId) { /* ... */ }
|
|
41
|
+
},
|
|
42
|
+
getters: {
|
|
43
|
+
getLaunch(id) { /* ... */ }
|
|
44
|
+
},
|
|
45
|
+
dispatcher: {
|
|
46
|
+
async requestLaunches(correlationId) {
|
|
47
|
+
return await LibraryClientUtility.$store.requestLaunches(correlationId);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
_initPluginPersistConfig() {
|
|
54
|
+
return {
|
|
55
|
+
persist: {
|
|
56
|
+
key: '<your application>',
|
|
57
|
+
storage: localStorage,
|
|
58
|
+
paths: [ 'launchesSettings' ]
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export default AppStore;
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Pass the class (not an instance) to `start` in `main.js`; it creates the store, installs Pinia and the persistence plugin, and makes it available as `LibraryClientUtility.$store`. Application code calls actions through `LibraryClientUtility.$store.dispatcher`.
|
|
68
|
+
|
|
69
|
+
`_initPluginPersistConfig` names the state to keep in `storage` between visits; `paths` lists the state keys. Nothing else is persisted.
|
|
70
|
+
|
|
71
|
+
### The store service
|
|
72
|
+
|
|
73
|
+
Register the store service in the application's services boot:
|
|
74
|
+
|
|
75
|
+
```js
|
|
76
|
+
import storeService from '@thzero/library_client_vue3_store_pinia/service/store/index';
|
|
77
|
+
|
|
78
|
+
class ServiceBoot extends RootServicesBoot {
|
|
79
|
+
_initializeStore(injector) {
|
|
80
|
+
return new storeService(injector);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Modules
|
|
86
|
+
|
|
87
|
+
The `news` and `user` modules are always registered: the latest news, and the signed-in user with their settings, claims and token.
|
|
88
|
+
|
|
89
|
+
The admin modules are optional. Register them by overriding `_initModules`, which receives the function that adds a module:
|
|
90
|
+
|
|
91
|
+
```js
|
|
92
|
+
import adminNews from '@thzero/library_client_vue3_store_pinia/store/admin/news';
|
|
93
|
+
import adminUsers from '@thzero/library_client_vue3_store_pinia/store/admin/users';
|
|
94
|
+
|
|
95
|
+
class AppStore extends BaseStore {
|
|
96
|
+
_initModules(addModule) {
|
|
97
|
+
return [
|
|
98
|
+
addModule('adminNews', adminNews),
|
|
99
|
+
addModule('adminUsers', adminUsers)
|
|
100
|
+
];
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Each module's actions are on `LibraryClientUtility.$store.<key>`, and its dispatchers on `LibraryClientUtility.$store.dispatcher.<key>`. The admin components in [library_client_vue3](https://github.com/thzero/library_client_vue3) expect the keys `adminNews` and `adminUsers`.
|
|
106
|
+
|
|
107
|
+
## Development
|
|
108
|
+
|
|
109
|
+
```
|
|
110
|
+
npm install
|
|
111
|
+
npm test
|
|
112
|
+
npm run lint
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Tests use [Vitest](https://vitest.dev) with a real Pinia; the `test` folder and the configuration files are not published.
|
|
116
|
+
|
|
117
|
+
## License
|
|
118
|
+
|
|
119
|
+
[MIT](license.md)
|
package/license.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2022-2026 thZero.com
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
-
|
|
7
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
-
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022-2026 thZero.com
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
9
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/openSource.js
CHANGED
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
export default () => {
|
|
2
|
-
return [
|
|
3
|
-
{
|
|
4
|
-
category: 'client',
|
|
5
|
-
name: '@thzero/library_client',
|
|
6
|
-
url: 'https://github.com/thzero/library_client',
|
|
7
|
-
licenseName: 'MIT',
|
|
8
|
-
licenseUrl: 'https://github.com/thzero/library_client/blob/master/license.md'
|
|
9
|
-
},
|
|
10
|
-
{
|
|
11
|
-
category: 'client',
|
|
12
|
-
name: '@thzero/library_client_vue3',
|
|
13
|
-
url: 'https://github.com/thzero/library_client_vue3',
|
|
14
|
-
licenseName: 'MIT',
|
|
15
|
-
licenseUrl: 'https://github.com/thzero/library_client_vue3/blob/master/license.md'
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
category: 'client',
|
|
19
|
-
name: '@thzero/library_client_vue3_store_pinia',
|
|
20
|
-
url: 'https://github.com/thzero/library_client_vue3_store_pinia',
|
|
21
|
-
licenseName: 'MIT',
|
|
22
|
-
licenseUrl: 'https://github.com/thzero/library_client_vue3_store_pinia/blob/master/license.md'
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
category: 'client',
|
|
26
|
-
name: '@thzero/library_common',
|
|
27
|
-
url: 'https://github.com/thzero/library_common',
|
|
28
|
-
licenseName: 'MIT',
|
|
29
|
-
licenseUrl: 'https://github.com/thzero/library_common/blob/master/license.md'
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
category: 'client',
|
|
33
|
-
name: 'pinia',
|
|
34
|
-
url: 'https://github.com/vuejs/pinia',
|
|
35
|
-
licenseName: 'MIT',
|
|
36
|
-
licenseUrl: 'https://github.com/vuejs/pinia/blob/v2/LICENSE'
|
|
37
|
-
},
|
|
38
|
-
{
|
|
39
|
-
category: 'client',
|
|
40
|
-
name: 'pinia-plugin-persistedstate
|
|
41
|
-
url: 'https://github.com/
|
|
42
|
-
licenseName: 'MIT',
|
|
43
|
-
licenseUrl: 'https://github.com/
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
category: 'client',
|
|
47
|
-
name: 'vue',
|
|
48
|
-
url: 'https://github.com/vuejs/vue',
|
|
49
|
-
licenseName: 'MIT',
|
|
50
|
-
licenseUrl: 'https://github.com/vuejs/vue/blob/dev/LICENSE'
|
|
51
|
-
}
|
|
52
|
-
];
|
|
1
|
+
export default () => {
|
|
2
|
+
return [
|
|
3
|
+
{
|
|
4
|
+
category: 'client',
|
|
5
|
+
name: '@thzero/library_client',
|
|
6
|
+
url: 'https://github.com/thzero/library_client',
|
|
7
|
+
licenseName: 'MIT',
|
|
8
|
+
licenseUrl: 'https://github.com/thzero/library_client/blob/master/license.md'
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
category: 'client',
|
|
12
|
+
name: '@thzero/library_client_vue3',
|
|
13
|
+
url: 'https://github.com/thzero/library_client_vue3',
|
|
14
|
+
licenseName: 'MIT',
|
|
15
|
+
licenseUrl: 'https://github.com/thzero/library_client_vue3/blob/master/license.md'
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
category: 'client',
|
|
19
|
+
name: '@thzero/library_client_vue3_store_pinia',
|
|
20
|
+
url: 'https://github.com/thzero/library_client_vue3_store_pinia',
|
|
21
|
+
licenseName: 'MIT',
|
|
22
|
+
licenseUrl: 'https://github.com/thzero/library_client_vue3_store_pinia/blob/master/license.md'
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
category: 'client',
|
|
26
|
+
name: '@thzero/library_common',
|
|
27
|
+
url: 'https://github.com/thzero/library_common',
|
|
28
|
+
licenseName: 'MIT',
|
|
29
|
+
licenseUrl: 'https://github.com/thzero/library_common/blob/master/license.md'
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
category: 'client',
|
|
33
|
+
name: 'pinia',
|
|
34
|
+
url: 'https://github.com/vuejs/pinia',
|
|
35
|
+
licenseName: 'MIT',
|
|
36
|
+
licenseUrl: 'https://github.com/vuejs/pinia/blob/v2/LICENSE'
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
category: 'client',
|
|
40
|
+
name: 'pinia-plugin-persistedstate',
|
|
41
|
+
url: 'https://github.com/prazdevs/pinia-plugin-persistedstate',
|
|
42
|
+
licenseName: 'MIT',
|
|
43
|
+
licenseUrl: 'https://github.com/prazdevs/pinia-plugin-persistedstate/blob/main/LICENSE'
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
category: 'client',
|
|
47
|
+
name: 'vue',
|
|
48
|
+
url: 'https://github.com/vuejs/vue',
|
|
49
|
+
licenseName: 'MIT',
|
|
50
|
+
licenseUrl: 'https://github.com/vuejs/vue/blob/dev/LICENSE'
|
|
51
|
+
}
|
|
52
|
+
];
|
|
53
53
|
}
|
package/package.json
CHANGED
|
@@ -1,35 +1,43 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@thzero/library_client_vue3_store_pinia",
|
|
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
|
-
"@thzero/
|
|
34
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@thzero/library_client_vue3_store_pinia",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.19.1",
|
|
5
|
+
"version_major": 0,
|
|
6
|
+
"version_minor": 19,
|
|
7
|
+
"version_patch": 1,
|
|
8
|
+
"version_date": "10/03/2026",
|
|
9
|
+
"description": "An opinionated library for vue3 with pinia store for the library_client_vue3 using the https://prazdevs.github.io/pinia-plugin-persistedstate library.",
|
|
10
|
+
"author": "thZero",
|
|
11
|
+
"author_url": "https://www.thzero.com",
|
|
12
|
+
"copyright": "2020-2026",
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/thzero/library_client_vue3_store_pinia.git"
|
|
17
|
+
},
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/thzero/library_client_vue3_store_pinia/issues"
|
|
20
|
+
},
|
|
21
|
+
"homepage": "https://github.com/thzero/library_client_vue3_store_pinia#readme",
|
|
22
|
+
"scripts": {
|
|
23
|
+
"test": "vitest run",
|
|
24
|
+
"lint": "eslint .",
|
|
25
|
+
"lint:fix": "eslint . --fix"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"pinia": "^4.0.3",
|
|
29
|
+
"pinia-plugin-persistedstate": "^4.7.1",
|
|
30
|
+
"vue": "^3.5.42"
|
|
31
|
+
},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"@thzero/library_client": "^0.19",
|
|
34
|
+
"@thzero/library_client_vue3": "^0.19",
|
|
35
|
+
"@thzero/library_common": "^0.19"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@vitejs/plugin-vue": "^6.0.9",
|
|
39
|
+
"eslint": "^9",
|
|
40
|
+
"jsdom": "^30.1.1",
|
|
41
|
+
"vitest": "^5.0.1"
|
|
42
|
+
}
|
|
35
43
|
}
|
package/service/store/index.js
CHANGED
|
@@ -1,51 +1,51 @@
|
|
|
1
|
-
import LibraryClientUtility from '@thzero/library_client/utility/index';
|
|
2
|
-
|
|
3
|
-
import Service from '@thzero/library_client/service/index';
|
|
4
|
-
|
|
5
|
-
class PiniaStoreService extends Service {
|
|
6
|
-
get dispatcher() {
|
|
7
|
-
return LibraryClientUtility.$store.dispatcher;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
get getters() {
|
|
11
|
-
return LibraryClientUtility.$store.getters;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
get news() {
|
|
15
|
-
return LibraryClientUtility.$store.news;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
get state() {
|
|
19
|
-
return LibraryClientUtility.$store;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
get user() {
|
|
23
|
-
return LibraryClientUtility.$store.user.user;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
get userClaims() {
|
|
27
|
-
return LibraryClientUtility.$store.user.claims;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
get userToken() {
|
|
31
|
-
return LibraryClientUtility.$store.user.token;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
get userAuthCompleted() {
|
|
35
|
-
return LibraryClientUtility.$store.user.authCompleted;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
get userAuthIsLoggedIn() {
|
|
39
|
-
return LibraryClientUtility.$store.user.isLoggedIn;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
get userTheme() {
|
|
43
|
-
return LibraryClientUtility.$store.user.theme;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
get userTokenResult() {
|
|
47
|
-
return LibraryClientUtility.$store.user.tokenResult;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export default PiniaStoreService;
|
|
1
|
+
import LibraryClientUtility from '@thzero/library_client/utility/index';
|
|
2
|
+
|
|
3
|
+
import Service from '@thzero/library_client/service/index';
|
|
4
|
+
|
|
5
|
+
class PiniaStoreService extends Service {
|
|
6
|
+
get dispatcher() {
|
|
7
|
+
return LibraryClientUtility.$store.dispatcher;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
get getters() {
|
|
11
|
+
return LibraryClientUtility.$store.getters;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
get news() {
|
|
15
|
+
return LibraryClientUtility.$store.news;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
get state() {
|
|
19
|
+
return LibraryClientUtility.$store;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
get user() {
|
|
23
|
+
return LibraryClientUtility.$store.user.user;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
get userClaims() {
|
|
27
|
+
return LibraryClientUtility.$store.user.claims;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
get userToken() {
|
|
31
|
+
return LibraryClientUtility.$store.user.token;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
get userAuthCompleted() {
|
|
35
|
+
return LibraryClientUtility.$store.user.authCompleted;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
get userAuthIsLoggedIn() {
|
|
39
|
+
return LibraryClientUtility.$store.user.isLoggedIn;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
get userTheme() {
|
|
43
|
+
return LibraryClientUtility.$store.user.theme;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
get userTokenResult() {
|
|
47
|
+
return LibraryClientUtility.$store.user.tokenResult;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export default PiniaStoreService;
|
|
@@ -1,76 +1,86 @@
|
|
|
1
|
-
import LibraryClientConstants from '@thzero/library_client/constants';
|
|
2
|
-
|
|
3
|
-
import LibraryClientUtility from '@thzero/library_client/utility/index';
|
|
4
|
-
import LibraryCommonUtility from '@thzero/library_common/utility';
|
|
5
|
-
|
|
6
|
-
import Response from '@thzero/library_common/response';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
this.news
|
|
22
|
-
this.$logger.debug('store.admin.news', '
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
this
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
return
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
async
|
|
68
|
-
await LibraryClientUtility.$store.
|
|
69
|
-
},
|
|
70
|
-
async
|
|
71
|
-
return await LibraryClientUtility.$store.
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
1
|
+
import LibraryClientConstants from '@thzero/library_client/constants';
|
|
2
|
+
|
|
3
|
+
import LibraryClientUtility from '@thzero/library_client/utility/index';
|
|
4
|
+
import LibraryCommonUtility from '@thzero/library_common/utility';
|
|
5
|
+
|
|
6
|
+
import Response from '@thzero/library_common/response';
|
|
7
|
+
|
|
8
|
+
// An optional module: an app registers it from its store's _initModules as
|
|
9
|
+
// addModule('adminNews', adminNews)
|
|
10
|
+
// The dispatchers below and the admin components both expect that key.
|
|
11
|
+
const store = {
|
|
12
|
+
state: () => ({
|
|
13
|
+
news: null
|
|
14
|
+
}),
|
|
15
|
+
actions: {
|
|
16
|
+
async createAdminNews(correlationId, item) {
|
|
17
|
+
const service = LibraryClientUtility.$injector.getService(LibraryClientConstants.InjectorKeys.SERVICE_ADMIN_NEWS);
|
|
18
|
+
const response = await service.create(correlationId, item);
|
|
19
|
+
this.$logger.debug('store.admin.news', 'createAdminNews', 'response', response, correlationId);
|
|
20
|
+
if (Response.hasSucceeded(response) && response.results) {
|
|
21
|
+
this.$logger.debug('store.admin.news', 'createAdminNews', 'items.a', response.results, correlationId);
|
|
22
|
+
this.$logger.debug('store.admin.news', 'createAdminNews', 'items.b', this.news, correlationId);
|
|
23
|
+
// the list is null until the first search
|
|
24
|
+
this.news = LibraryCommonUtility.updateArrayByObject(this.news ?? [], response.results);
|
|
25
|
+
this.$logger.debug('store.admin.news', 'createAdminNews', 'items.c', this.news, correlationId);
|
|
26
|
+
}
|
|
27
|
+
return response;
|
|
28
|
+
},
|
|
29
|
+
async deleteAdminNews(correlationId, id) {
|
|
30
|
+
const service = LibraryClientUtility.$injector.getService(LibraryClientConstants.InjectorKeys.SERVICE_ADMIN_NEWS);
|
|
31
|
+
const response = await service.delete(correlationId, id);
|
|
32
|
+
this.$logger.debug('store.admin.news', 'deleteAdminNews', 'response', response, correlationId);
|
|
33
|
+
if (Response.hasSucceeded(response)) {
|
|
34
|
+
// deleteArrayById removes in place and returns nothing; assigning its
|
|
35
|
+
// result is what emptied the list
|
|
36
|
+
LibraryCommonUtility.deleteArrayById(this.news, id);
|
|
37
|
+
// and drop it from the public news list too
|
|
38
|
+
await LibraryClientUtility.$store.dispatcher.news.delete(correlationId, id);
|
|
39
|
+
}
|
|
40
|
+
return response;
|
|
41
|
+
},
|
|
42
|
+
async searchAdminNews(correlationId, params) {
|
|
43
|
+
const service = LibraryClientUtility.$injector.getService(LibraryClientConstants.InjectorKeys.SERVICE_ADMIN_NEWS);
|
|
44
|
+
const response = await service.search(correlationId, params);
|
|
45
|
+
this.$logger.debug('store.admin.news', 'searchAdminNews', 'response', response, correlationId);
|
|
46
|
+
const list = response.success && response.results ? response.results.data : null;
|
|
47
|
+
this.$logger.debug('store.admin.news', 'searchAdminNews', 'list.a', list, correlationId);
|
|
48
|
+
this.$logger.debug('store.admin.news', 'searchAdminNews', 'list.b', this.news, correlationId);
|
|
49
|
+
this.news = list;
|
|
50
|
+
this.$logger.debug('store.admin.news', 'searchAdminNews', 'list.c', this.news, correlationId);
|
|
51
|
+
},
|
|
52
|
+
async updateAdminNews(correlationId, item) {
|
|
53
|
+
const service = LibraryClientUtility.$injector.getService(LibraryClientConstants.InjectorKeys.SERVICE_ADMIN_NEWS);
|
|
54
|
+
const response = await service.update(correlationId, item);
|
|
55
|
+
this.$logger.debug('store.admin.news', 'updateAdminNews', 'response', response, correlationId);
|
|
56
|
+
if (Response.hasSucceeded(response) && response.results) {
|
|
57
|
+
this.$logger.debug('store.admin.news', 'updateAdminNews', 'items.a', response.results, correlationId);
|
|
58
|
+
this.$logger.debug('store.admin.news', 'updateAdminNews', 'items.b', this.news, correlationId);
|
|
59
|
+
this.news = LibraryCommonUtility.updateArrayByObject(this.news ?? [], response.results);
|
|
60
|
+
this.$logger.debug('store.admin.news', 'updateAdminNews', 'items.c', this.news, correlationId);
|
|
61
|
+
}
|
|
62
|
+
return response;
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
// module actions live on $store.adminNews, not on the root $store
|
|
66
|
+
dispatcher: {
|
|
67
|
+
async createAdminNews(correlationId, item) {
|
|
68
|
+
return await LibraryClientUtility.$store.adminNews.createAdminNews(correlationId, item);
|
|
69
|
+
},
|
|
70
|
+
async deleteAdminNews(correlationId, id) {
|
|
71
|
+
return await LibraryClientUtility.$store.adminNews.deleteAdminNews(correlationId, id);
|
|
72
|
+
},
|
|
73
|
+
async searchAdminNews(correlationId, params) {
|
|
74
|
+
await LibraryClientUtility.$store.adminNews.searchAdminNews(correlationId, params);
|
|
75
|
+
},
|
|
76
|
+
// the older name for searchAdminNews
|
|
77
|
+
async searchNews(correlationId, params) {
|
|
78
|
+
await LibraryClientUtility.$store.adminNews.searchAdminNews(correlationId, params);
|
|
79
|
+
},
|
|
80
|
+
async updateAdminNews(correlationId, item) {
|
|
81
|
+
return await LibraryClientUtility.$store.adminNews.updateAdminNews(correlationId, item);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export default store;
|