Skip to content

Commit 53bdb45

Browse files
authored
Merge pull request #1 from apioo/6.x
migrate to 6.x
2 parents ccb929b + 41cf7a0 commit 53bdb45

File tree

75 files changed

+1590
-1270
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+1590
-1270
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": "5.1.3",
3+
"version": "6.0.0",
44
"description": "SDK to integrate Fusio into an Angular app",
55
"keywords": [
66
"Fusio",
Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,66 @@
1-
import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
1+
import {Component, OnInit} from '@angular/core';
2+
import {ActivatedRoute, Router} from "@angular/router";
3+
import {CommonMessage} from "fusio-sdk";
4+
import {ErrorService} from "../service/error.service";
5+
import {Service} from "./service";
26

37
/**
4-
* This component is only a basic view component which renders a provided entity. It should only render the provided
5-
* JSON data it should not contain any additional logic to request data from an endpoint
8+
* Base component to show a detail page of a single entity
69
*/
710
@Component({
811
template: '',
912
})
1013
export abstract class Detail<T> implements OnInit {
1114

12-
@Input()
13-
selected!: T;
14-
@Output()
15-
updateClick: EventEmitter<void> = new EventEmitter<void>();
16-
@Output()
17-
deleteClick: EventEmitter<void> = new EventEmitter<void>();
15+
public selected?: T;
16+
public response?: CommonMessage;
1817

19-
jsonView: boolean = false;
18+
protected constructor(protected route: ActivatedRoute, public router: Router, protected error: ErrorService) {
19+
}
20+
21+
async ngOnInit(): Promise<void> {
22+
this.route.paramMap.subscribe(async params => {
23+
const id = params.get('id');
24+
if (id) {
25+
await this.doGet(id);
26+
}
27+
});
28+
}
29+
30+
async doGet(id: string) {
31+
try {
32+
this.selected = await this.getService().get(id);
2033

21-
async ngOnInit() {
34+
this.onLoad();
35+
} catch (error) {
36+
this.response = this.error.convert(error);
37+
}
2238
}
2339

24-
doUpdateClick() {
25-
this.updateClick.emit();
40+
public getListLink(): Array<string>
41+
{
42+
return this.getService().getLink();
2643
}
2744

28-
doDeleteClick() {
29-
this.deleteClick.emit();
45+
public getEditLink(id: any): Array<string>
46+
{
47+
const link = this.getService().getLink();
48+
link.push('' + id)
49+
link.push('edit')
50+
return link;
3051
}
3152

53+
public getDeleteLink(id: any): Array<string>
54+
{
55+
const link = this.getService().getLink();
56+
link.push('' + id)
57+
link.push('delete')
58+
return link;
59+
}
60+
61+
protected abstract getService(): Service<T>;
62+
63+
protected onLoad(): void
64+
{
65+
}
3266
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import {Component, OnInit} from '@angular/core';
2+
import {ActivatedRoute, Router} from "@angular/router";
3+
import {CommonMessage} from "fusio-sdk";
4+
import {ErrorService} from "../service/error.service";
5+
import {Service} from "./service";
6+
7+
/**
8+
* Base component to provide a form to create, update or delete an entity
9+
*/
10+
@Component({
11+
template: '',
12+
})
13+
export abstract class Form<T> implements OnInit {
14+
15+
public entity?: T;
16+
public response?: CommonMessage;
17+
public mode: Mode = Mode.Create;
18+
19+
protected constructor(protected route: ActivatedRoute, public router: Router, protected error: ErrorService) {
20+
}
21+
22+
async ngOnInit(): Promise<void> {
23+
this.entity = this.getService().newEntity();
24+
25+
this.route.data.subscribe((data) => {
26+
this.mode = data['mode'];
27+
});
28+
29+
this.route.paramMap.subscribe(async params => {
30+
const id = params.get('id');
31+
if (id) {
32+
await this.doGet(id);
33+
}
34+
});
35+
}
36+
37+
async doGet(id: string) {
38+
try {
39+
this.entity = await this.getService().get(id);
40+
41+
this.onLoad();
42+
} catch (error) {
43+
this.response = this.error.convert(error);
44+
}
45+
}
46+
47+
async doCreate(entity: T) {
48+
try {
49+
this.response = await this.getService().create(entity);
50+
51+
this.onSubmit();
52+
} catch (error) {
53+
this.response = this.error.convert(error);
54+
}
55+
}
56+
57+
async doUpdate(entity: T) {
58+
try {
59+
this.response = await this.getService().update(entity);
60+
61+
this.onSubmit();
62+
} catch (error) {
63+
this.response = this.error.convert(error);
64+
}
65+
}
66+
67+
async doDelete(entity: T) {
68+
try {
69+
this.response = await this.getService().delete(entity);
70+
71+
this.onSubmit();
72+
} catch (error) {
73+
this.response = this.error.convert(error);
74+
}
75+
}
76+
77+
public getListLink(): Array<string>
78+
{
79+
return this.getService().getLink();
80+
}
81+
82+
protected abstract getService(): Service<T>;
83+
84+
protected onLoad(): void
85+
{
86+
}
87+
88+
protected onSubmit(): void
89+
{
90+
}
91+
}
92+
93+
export enum Mode {
94+
Create = 1,
95+
Update,
96+
Delete,
97+
}
Lines changed: 101 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,125 @@
1-
import {Component} from '@angular/core';
1+
import {Component, OnInit} from '@angular/core';
22
import {ActivatedRoute, Router} from "@angular/router";
3-
import {NgbModal} from "@ng-bootstrap/ng-bootstrap";
4-
import {ClientAbstract} from "sdkgen-client";
5-
import {ApiService} from "../service/api.service";
3+
import {CommonMessage} from "fusio-sdk";
64
import {ErrorService} from "../service/error.service";
7-
import {EventService} from "../service/event.service";
8-
import {Result} from "./modal";
9-
import {ModelId, Query} from "./query";
5+
import {Service} from "./service";
106

117
/**
12-
* List panel which uses a modal to CRUD entities. Note it depends on ng-bootstrap so you can use it only if your
13-
* project also uses ng-bootstrap
8+
* Base component to list entities, with a pagination and a search
149
*/
1510
@Component({
1611
template: '',
1712
})
18-
export abstract class List<C extends ClientAbstract, T extends ModelId> extends Query<C, T> {
13+
export abstract class List<T> implements OnInit {
1914

20-
protected modalService: NgbModal;
15+
public search: string = '';
16+
public totalResults: number = 0;
17+
public entries: Array<T> = [];
18+
public page: number = 1;
19+
public pageSize: number = 16;
20+
public response?: CommonMessage;
2121

22-
constructor(fusio: ApiService<C>, route: ActivatedRoute, router: Router, event: EventService, error: ErrorService, modalService: NgbModal) {
23-
super(fusio, route, router, event, error);
24-
this.modalService = modalService;
22+
protected constructor(protected route: ActivatedRoute, public router: Router, protected error: ErrorService) {
2523
}
2624

27-
openCreateDialog() {
28-
const modalRef = this.modalService.open(this.getDetailComponent(), {
29-
size: 'lg'
30-
});
31-
modalRef.componentInstance.mode = Mode.Create;
32-
modalRef.closed.subscribe(async (result: Result<T>) => {
33-
this.response = result.response;
34-
if (result.response.success) {
35-
this.event.dispatchModelCreated(result.entity, this.getRoute());
25+
async ngOnInit(): Promise<void> {
26+
this.route.queryParams.subscribe(async params => {
27+
let page, search;
28+
if (params['page']) {
29+
page = parseInt(params['page']);
30+
}
31+
if (params['search']) {
32+
search = params['search'];
33+
}
3634

37-
await this.doList();
35+
if (!this.hasQueryParamsChange(page, search)) {
36+
return;
3837
}
38+
39+
this.page = page || 1;
40+
this.search = search || '';
41+
42+
await this.doList();
3943
});
4044
}
4145

42-
openUpdateDialog(entity: T) {
43-
const modalRef = this.modalService.open(this.getDetailComponent(), {
44-
size: 'lg'
45-
});
46-
modalRef.componentInstance.mode = Mode.Update;
47-
modalRef.componentInstance.entity = entity;
48-
modalRef.closed.subscribe(async (result: Result<T>) => {
49-
this.response = result.response;
50-
if (result.response.success) {
51-
this.event.dispatchModelUpdated(result.entity, this.getRoute());
52-
53-
await this.doList();
54-
}
55-
});
46+
async doList() {
47+
try {
48+
const response = await this.getService().getAll(this.getCollectionQuery());
49+
50+
this.totalResults = response.totalResults || 0;
51+
this.entries = response.entry || [];
52+
53+
this.onLoad();
54+
} catch (error) {
55+
this.response = this.error.convert(error);
56+
}
5657
}
5758

58-
openDeleteDialog(entity: T) {
59-
const modalRef = this.modalService.open(this.getDetailComponent(), {
60-
size: 'lg'
61-
});
62-
modalRef.componentInstance.mode = Mode.Delete;
63-
modalRef.componentInstance.entity = entity;
64-
modalRef.closed.subscribe(async (result: Result<T>) => {
65-
this.response = result.response;
66-
if (result.response.success) {
67-
this.event.dispatchModelDeleted(result.entity, this.getRoute());
68-
69-
await this.doList();
70-
}
71-
});
59+
async doSearch(page?: number, search?: string) {
60+
if (!this.hasQueryParamsChange(page, search)) {
61+
return;
62+
}
63+
64+
if (page !== undefined) {
65+
this.page = page;
66+
}
67+
68+
if (search !== undefined) {
69+
this.search = search;
70+
}
71+
72+
await this.doList();
7273
}
7374

74-
protected abstract getDetailComponent(): any;
75+
public getDetailLink(id: any): Array<string>
76+
{
77+
const link = this.getService().getLink();
78+
link.push('' + id)
79+
return link;
80+
}
7581

76-
}
82+
public getNewLink(): Array<string>
83+
{
84+
const link = this.getService().getLink();
85+
link.push('-')
86+
link.push('new')
87+
return link;
88+
}
89+
90+
public getEditLink(id: any): Array<string>
91+
{
92+
const link = this.getService().getLink();
93+
link.push('' + id)
94+
link.push('edit')
95+
return link;
96+
}
97+
98+
public getDeleteLink(id: any): Array<string>
99+
{
100+
const link = this.getService().getLink();
101+
link.push('' + id)
102+
link.push('delete')
103+
return link;
104+
}
105+
106+
protected getCollectionQuery(): Array<any> {
107+
let query: Array<any> = [];
108+
query.push((this.page - 1) * this.pageSize);
109+
query.push(this.pageSize);
110+
if (this.search) {
111+
query.push(this.search);
112+
}
113+
return query;
114+
}
77115

78-
export enum Mode {
79-
Create = 1,
80-
Update,
81-
Delete,
116+
protected hasQueryParamsChange(page?: number, search?: string): boolean {
117+
return this.page !== page || this.search !== search;
118+
}
119+
120+
protected abstract getService(): Service<T>;
121+
122+
protected onLoad(): void
123+
{
124+
}
82125
}

0 commit comments

Comments
 (0)