unictive-angular 1.0.29 → 1.0.30
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/bin/utils/resource/package.json +1 -0
- package/bin/utils/resource/src/app/API/user.service.ts +26 -0
- package/bin/utils/resource/src/app/app.ts +18 -2
- package/bin/utils/resource/src/app/core/config/entity-store.ts +13 -13
- package/bin/utils/resource/src/app/core/interceptors/jwt.interceptor.ts +1 -0
- package/bin/utils/resource/src/app/core/models/entities/user.entity.ts +15 -0
- package/bin/utils/resource/src/app/core/respository/screen_repo/screen.repo.ts +27 -0
- package/bin/utils/resource/src/app/core/respository/user/user_repo.ts +26 -0
- package/package.json +1 -1
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { HttpClient } from '@angular/common/http';
|
|
2
|
+
import { Injectable } from '@angular/core';
|
|
3
|
+
import { AbstractApiService } from '@core/interceptors/jsonrpc';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@Injectable({
|
|
7
|
+
providedIn: 'root'
|
|
8
|
+
})
|
|
9
|
+
export class UserService extends AbstractApiService<any> {
|
|
10
|
+
|
|
11
|
+
constructor(
|
|
12
|
+
http: HttpClient
|
|
13
|
+
) {
|
|
14
|
+
super(http, '');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
get_user(endpoint?: string): Promise<any> {
|
|
19
|
+
return this.get(
|
|
20
|
+
endpoint ? endpoint : '/api/users'
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import { ChangeDetectorRef, Component, OnInit } from '@angular/core';
|
|
1
|
+
import { ChangeDetectorRef, Component, effect, OnInit } from '@angular/core';
|
|
2
2
|
import { RouterOutlet } from '@angular/router';
|
|
3
|
+
import { Entity_User } from '@core/models/entities/user.entity';
|
|
4
|
+
import { Repo_User } from '@core/respository/user/user_repo';
|
|
5
|
+
|
|
3
6
|
import { logger } from '@shared/utils/logger';
|
|
4
7
|
@Component({
|
|
5
8
|
selector: 'app-root',
|
|
@@ -10,8 +13,21 @@ import { logger } from '@shared/utils/logger';
|
|
|
10
13
|
export class App implements OnInit {
|
|
11
14
|
protected title = 'OLD PROJECT';
|
|
12
15
|
|
|
13
|
-
|
|
16
|
+
user = Entity_User.state();
|
|
17
|
+
|
|
18
|
+
constructor(private cdr: ChangeDetectorRef, private repo_user: Repo_User) {
|
|
19
|
+
effect(() => {
|
|
20
|
+
const user = this.user.value;
|
|
21
|
+
logger.log('User state changed:', user);
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
|
|
14
27
|
ngOnInit(): void {
|
|
28
|
+
|
|
29
|
+
this.repo_user.load_user();
|
|
30
|
+
|
|
15
31
|
//MARK:TEST
|
|
16
32
|
setTimeout(() => {
|
|
17
33
|
this.ubah();
|
|
@@ -1,33 +1,33 @@
|
|
|
1
1
|
import { signal, computed } from '@angular/core';
|
|
2
2
|
|
|
3
3
|
export interface EntityState<T> {
|
|
4
|
-
|
|
4
|
+
value: T[];
|
|
5
5
|
loading: boolean;
|
|
6
6
|
error?: string;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
export function entityStoreFactory<T extends { id: string | number }>() {
|
|
10
|
-
const _state = signal<EntityState<T>>({
|
|
10
|
+
const _state = signal<EntityState<T>>({ value: [], loading: false });
|
|
11
11
|
|
|
12
12
|
return {
|
|
13
13
|
state: _state,
|
|
14
14
|
|
|
15
15
|
// Mutations
|
|
16
|
-
setAll(
|
|
17
|
-
_state.set({
|
|
16
|
+
setAll(value: T[]) {
|
|
17
|
+
_state.set({ value, loading: false });
|
|
18
18
|
},
|
|
19
19
|
|
|
20
20
|
add(item: T) {
|
|
21
21
|
_state.update((curr) => ({
|
|
22
22
|
...curr,
|
|
23
|
-
|
|
23
|
+
value: [...curr.value, item]
|
|
24
24
|
}));
|
|
25
25
|
},
|
|
26
26
|
|
|
27
27
|
update(id: T['id'], partial: Partial<T>) {
|
|
28
28
|
_state.update((curr) => ({
|
|
29
29
|
...curr,
|
|
30
|
-
|
|
30
|
+
value: curr.value.map((i) =>
|
|
31
31
|
i.id === id ? { ...i, ...partial } : i
|
|
32
32
|
)
|
|
33
33
|
}));
|
|
@@ -36,27 +36,27 @@ export function entityStoreFactory<T extends { id: string | number }>() {
|
|
|
36
36
|
remove(id: T['id']) {
|
|
37
37
|
_state.update((curr) => ({
|
|
38
38
|
...curr,
|
|
39
|
-
|
|
39
|
+
value: curr.value.filter((i) => i.id !== id)
|
|
40
40
|
}));
|
|
41
41
|
},
|
|
42
42
|
|
|
43
43
|
clear() {
|
|
44
|
-
_state.set({
|
|
44
|
+
_state.set({ value: [], loading: false });
|
|
45
45
|
},
|
|
46
46
|
|
|
47
47
|
// Selectors
|
|
48
48
|
getById: (id: T['id']) =>
|
|
49
|
-
computed(() => _state().
|
|
49
|
+
computed(() => _state().value.find((i) => i.id === id)),
|
|
50
50
|
|
|
51
|
-
all: computed(() => _state().
|
|
52
|
-
count: computed(() => _state().
|
|
51
|
+
all: computed(() => _state().value),
|
|
52
|
+
count: computed(() => _state().value.length),
|
|
53
53
|
|
|
54
54
|
// Async Loader
|
|
55
|
-
async
|
|
55
|
+
async load(fetchFn: () => Promise<T[]>) {
|
|
56
56
|
_state.update((curr) => ({ ...curr, loading: true, error: undefined }));
|
|
57
57
|
try {
|
|
58
58
|
const data = await fetchFn();
|
|
59
|
-
_state.set({
|
|
59
|
+
_state.set({ value: data, loading: false });
|
|
60
60
|
} catch (err: any) {
|
|
61
61
|
_state.update((curr) => ({
|
|
62
62
|
...curr,
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// import { entityStoreFactory } from "@core/config/entity-store";
|
|
2
|
+
import { singleStoreFactory } from "@core/config/single-store";
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
export interface User_m {
|
|
7
|
+
username: string;
|
|
8
|
+
email: string;
|
|
9
|
+
id: number;
|
|
10
|
+
role: string;
|
|
11
|
+
token: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
export const Entity_User = singleStoreFactory<User_m>();
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Injectable } from '@angular/core';
|
|
2
|
+
import { HttpClient } from '@angular/common/http';
|
|
3
|
+
import { ScreenEntity } from '@core/models/entities/screen.entity';
|
|
4
|
+
import { logger } from '@shared/utils/logger';
|
|
5
|
+
import { Entity_User } from '@core/models/entities/user.entity';
|
|
6
|
+
import { UserService } from '@api/user.service';
|
|
7
|
+
|
|
8
|
+
@Injectable({ providedIn: 'root' })
|
|
9
|
+
export class RepoScreen {
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
constructor(
|
|
13
|
+
private api: UserService
|
|
14
|
+
) { }
|
|
15
|
+
|
|
16
|
+
load_user() {
|
|
17
|
+
Entity_User.load(async () => {
|
|
18
|
+
const res = await this.api.get_user();
|
|
19
|
+
const response = res?.data ?? [];
|
|
20
|
+
return response; // hanya return user
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
get getData() {
|
|
25
|
+
return ScreenEntity.state();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Injectable } from "@angular/core";
|
|
2
|
+
import { UserService } from "@api/user.service";
|
|
3
|
+
import { Entity_User } from "@core/models/entities/user.entity";
|
|
4
|
+
|
|
5
|
+
@Injectable({ providedIn: 'root' })
|
|
6
|
+
export class Repo_User {
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
constructor(
|
|
10
|
+
private api: UserService
|
|
11
|
+
) { }
|
|
12
|
+
|
|
13
|
+
load_user() {
|
|
14
|
+
Entity_User.load(async () => {
|
|
15
|
+
const res = await this.api.get_user();
|
|
16
|
+
const response = res?.data ?? null;
|
|
17
|
+
return response; // hanya return user
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
get getData() {
|
|
23
|
+
return Entity_User.state();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
}
|
package/package.json
CHANGED