Skip to content

Commit f3d34a2

Browse files
committed
improve link handling use service on ready
1 parent bdf9878 commit f3d34a2

25 files changed

+178
-151
lines changed

projects/fusio-sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ngx-fusio-sdk",
3-
"version": "7.0.3",
3+
"version": "7.0.4",
44
"description": "SDK to integrate Fusio into an Angular app",
55
"keywords": [
66
"Fusio",

projects/fusio-sdk/src/lib/abstract/detail.ts

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export abstract class Detail<T> implements OnInit {
1414

1515
selected = signal<T|undefined>(undefined);
1616
response = signal<CommonMessage|undefined>(undefined);
17-
jsonView = false;
17+
jsonView = signal(false);
1818

1919
protected constructor(protected route: ActivatedRoute, public router: Router, protected error: ErrorService) {
2020
}
@@ -29,38 +29,46 @@ export abstract class Detail<T> implements OnInit {
2929
}
3030

3131
async doGet(id: string) {
32-
try {
33-
this.getService().onConfigurationCompleted().then(async (service) => {
32+
this.getService().onReady().then(async (service) => {
33+
try {
3434
this.selected.set(await service.get(id));
3535

3636
this.onLoad();
37-
});
38-
} catch (error) {
39-
this.response.set(this.error.convert(error));
37+
} catch (error) {
38+
this.response.set(this.error.convert(error));
4039

41-
this.onError();
42-
}
40+
this.onError();
41+
}
42+
});
4343
}
4444

45-
public getListLink(): Array<string>
45+
public doList(): void
4646
{
47-
return this.getService().getLink();
47+
this.getService().onReady().then((service) => {
48+
this.router.navigate(service.getLink());
49+
});
4850
}
4951

50-
public getEditLink(id: any): Array<string>
52+
public doEdit(id: any): void
5153
{
52-
const link = this.getService().getLink();
53-
link.push('' + id)
54-
link.push('edit')
55-
return link;
54+
this.getService().onReady().then((service) => {
55+
const link = service.getLink();
56+
link.push('' + id);
57+
link.push('edit');
58+
59+
this.router.navigate(link);
60+
});
5661
}
5762

58-
public getDeleteLink(id: any): Array<string>
63+
public doDelete(id: any): void
5964
{
60-
const link = this.getService().getLink();
61-
link.push('' + id)
62-
link.push('delete')
63-
return link;
65+
this.getService().onReady().then((service) => {
66+
const link = service.getLink();
67+
link.push('' + id);
68+
link.push('delete');
69+
70+
this.router.navigate(link);
71+
});
6472
}
6573

6674
protected abstract getService(): Service<T>;

projects/fusio-sdk/src/lib/abstract/form.ts

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export abstract class Form<T> implements OnInit {
2525
this.route.data.subscribe((data) => {
2626
this.mode = data['mode'];
2727
if (this.mode === Mode.Create) {
28+
// invoke onload since we dont use the doGet method
2829
this.onLoad();
2930
}
3031
});
@@ -38,77 +39,82 @@ export abstract class Form<T> implements OnInit {
3839
}
3940

4041
async doGet(id: string) {
41-
try {
42-
this.getService().onConfigurationCompleted().then(async (service) => {
42+
this.getService().onReady().then(async (service) => {
43+
try {
4344
this.entity.set(await service.get(id));
4445

4546
this.onLoad();
46-
});
47-
} catch (error) {
48-
this.response.set(this.error.convert(error));
47+
} catch (error) {
48+
this.response.set(this.error.convert(error));
4949

50-
this.onError();
51-
}
50+
this.onError();
51+
}
52+
});
5253
}
5354

5455
async doCreate(entity: T|Signal<T>) {
55-
try {
56-
this.getService().onConfigurationCompleted().then(async (service) => {
56+
this.getService().onReady().then(async (service) => {
57+
try {
5758
const payload = entity instanceof Function ? entity() : entity;
5859

5960
this.response.set(await service.create(this.beforeCreate(payload)));
6061

6162
this.onSubmit();
62-
});
63-
} catch (error) {
64-
this.response.set(this.error.convert(error));
63+
} catch (error) {
64+
this.response.set(this.error.convert(error));
6565

66-
this.onError();
67-
}
66+
this.onError();
67+
}
68+
});
6869
}
6970

7071
async doUpdate(entity: T|Signal<T>) {
71-
try {
72-
this.getService().onConfigurationCompleted().then(async (service) => {
72+
this.getService().onReady().then(async (service) => {
73+
try {
7374
const payload = entity instanceof Function ? entity() : entity;
7475

7576
this.response.set(await service.update(this.beforeUpdate(payload)));
7677

7778
this.onSubmit();
78-
});
79-
} catch (error) {
80-
this.response.set(this.error.convert(error));
79+
} catch (error) {
80+
this.response.set(this.error.convert(error));
8181

82-
this.onError();
83-
}
82+
this.onError();
83+
}
84+
});
8485
}
8586

8687
async doDelete(entity: T|Signal<T>) {
87-
try {
88-
this.getService().onConfigurationCompleted().then(async (service) => {
88+
this.getService().onReady().then(async (service) => {
89+
try {
8990
const payload = entity instanceof Function ? entity() : entity;
9091

9192
this.response.set(await service.delete(this.beforeDelete(payload)));
9293

9394
this.onSubmit();
94-
});
95-
} catch (error) {
96-
this.response.set(this.error.convert(error));
95+
} catch (error) {
96+
this.response.set(this.error.convert(error));
9797

98-
this.onError();
99-
}
98+
this.onError();
99+
}
100+
});
100101
}
101102

102-
public getListLink(): Array<string>
103+
public doList(): void
103104
{
104-
return this.getService().getLink();
105+
this.getService().onReady().then((service) => {
106+
this.router.navigate(service.getLink());
107+
});
105108
}
106109

107-
public getDetailLink(id: any): Array<string>
110+
public doDetail(id: any): void
108111
{
109-
const link = this.getService().getLink();
110-
link.push('' + id)
111-
return link;
112+
this.getService().onReady().then((service) => {
113+
const link = service.getLink();
114+
link.push('' + id)
115+
116+
this.router.navigate(link);
117+
});
112118
}
113119

114120
public set(entity: WritableSignal<T>, key: keyof T, propertyValue: any) {

projects/fusio-sdk/src/lib/abstract/list.ts

Lines changed: 60 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Component, OnInit, signal} from '@angular/core';
1+
import {Component, computed, OnInit, signal} from '@angular/core';
22
import {ActivatedRoute, Router} from "@angular/router";
33
import {CommonMessage} from "fusio-sdk";
44
import {ErrorService} from "../service/error.service";
@@ -19,6 +19,20 @@ export abstract class List<T> implements OnInit {
1919
pageSize = signal<number>(16);
2020
response = signal<CommonMessage|undefined>(undefined);
2121

22+
collectionQuery = computed<Array<any>>(() => {
23+
let query: Array<any> = [];
24+
query.push((this.page() - 1) * this.pageSize());
25+
query.push(this.pageSize());
26+
const search = this.search();
27+
if (search) {
28+
query.push(search);
29+
} else {
30+
query.push('');
31+
}
32+
33+
return query;
34+
});
35+
2236
protected constructor(protected route: ActivatedRoute, public router: Router, protected error: ErrorService) {
2337
}
2438

@@ -44,77 +58,78 @@ export abstract class List<T> implements OnInit {
4458
}
4559

4660
async doList() {
47-
try {
48-
this.getService().onConfigurationCompleted().then(async (service) => {
49-
const response = await service.getAll(this.getCollectionQuery());
61+
this.getService().onReady().then(async (service) => {
62+
try {
63+
const response = await service.getAll(this.collectionQuery());
5064

5165
this.totalResults.set(response.totalResults || 0);
5266
this.entries.set(response.entry || []);
5367

5468
this.onLoad();
55-
});
56-
} catch (error) {
57-
this.response.set(this.error.convert(error));
69+
} catch (error) {
70+
this.response.set(this.error.convert(error));
5871

59-
this.onError();
60-
}
72+
this.onError();
73+
}
74+
});
6175
}
6276

6377
async doSearch(page?: number, search?: string) {
6478
if (!this.hasQueryParamsChange(page, search)) {
6579
return;
6680
}
6781

68-
await this.router.navigate(this.getService().getLink(), {
69-
queryParams: {
70-
page: page,
71-
search: search,
72-
}
82+
this.getService().onReady().then((service) => {
83+
this.router.navigate(service.getLink(), {
84+
queryParams: {
85+
page: page,
86+
search: search,
87+
}
88+
});
7389
});
7490
}
7591

76-
public getDetailLink(id: any): Array<string>
92+
public doDetail(id: any): void
7793
{
78-
const link = this.getService().getLink();
79-
link.push('' + id)
80-
return link;
94+
this.getService().onReady().then((service) => {
95+
const link = service.getLink();
96+
link.push('' + id);
97+
98+
this.router.navigate(link);
99+
});
81100
}
82101

83-
public getNewLink(): Array<string>
102+
public doNew(): void
84103
{
85-
const link = this.getService().getLink();
86-
link.push('-')
87-
link.push('new')
88-
return link;
104+
this.getService().onReady().then((service) => {
105+
const link = service.getLink();
106+
link.push('-');
107+
link.push('new');
108+
109+
this.router.navigate(link);
110+
});
89111
}
90112

91-
public getEditLink(id: any): Array<string>
113+
public doEdit(id: any): void
92114
{
93-
const link = this.getService().getLink();
94-
link.push('' + id)
95-
link.push('edit')
96-
return link;
115+
this.getService().onReady().then((service) => {
116+
const link = service.getLink();
117+
link.push('' + id);
118+
link.push('edit');
119+
120+
this.router.navigate(link);
121+
});
97122
}
98123

99-
public getDeleteLink(id: any): Array<string>
124+
public doDelete(id: any): void
100125
{
101-
const link = this.getService().getLink();
102-
link.push('' + id)
103-
link.push('delete')
104-
return link;
105-
}
126+
this.getService().onReady().then((service) => {
127+
const link = service.getLink();
128+
link.push('' + id);
129+
link.push('delete');
106130

107-
protected getCollectionQuery(): Array<any> {
108-
let query: Array<any> = [];
109-
query.push((this.page() - 1) * this.pageSize());
110-
query.push(this.pageSize());
111-
const search = this.search();
112-
if (search) {
113-
query.push(search);
114-
} else {
115-
query.push('');
116-
}
117-
return query;
131+
this.router.navigate(link);
132+
});
118133
}
119134

120135
protected hasQueryParamsChange(page?: number, search?: string): boolean {

projects/fusio-sdk/src/lib/abstract/service.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export abstract class Service<E> implements ServiceInterface<E> {
8585
/**
8686
* Returns a promise which gets resolved in case the configuration is completed
8787
*/
88-
public onConfigurationCompleted(): Promise<ServiceInterface<E>>
88+
public onReady(): Promise<ServiceInterface<E>>
8989
{
9090
if (this.isConfigured()) {
9191
return new Promise<ServiceInterface<E>>((resolve) => {
@@ -176,6 +176,8 @@ interface ServiceInterface<E> {
176176
update(entity: E): Promise<CommonMessage>;
177177

178178
delete(entity: E): Promise<CommonMessage>;
179+
180+
getLink(): Array<string>;
179181
}
180182

181183
export interface IdAndName<T> {

projects/fusio-sdk/src/lib/component/app/detail/app-detail.component.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11

22
<div class="btn-group" role="group">
3-
<a [routerLink]="getListLink()" class="btn btn-secondary fusio-btn-back">Back</a>
4-
<a [routerLink]="getEditLink(selected()?.id)" class="btn btn-primary fusio-btn-update">Update</a>
5-
<a [routerLink]="getDeleteLink(selected()?.id)" class="btn btn-danger fusio-btn-delete">Delete</a>
3+
<a (click)="doList()" class="btn btn-secondary fusio-btn-back">Back</a>
4+
<a (click)="doEdit(selected()?.id)" class="btn btn-primary fusio-btn-update">Update</a>
5+
<a (click)="doDelete(selected()?.id)" class="btn btn-danger fusio-btn-delete">Delete</a>
66
</div>
77
<div class="fusio-detail">
88
<div class="row">

0 commit comments

Comments
 (0)