Skip to content

Commit 3fe3ef0

Browse files
add back to list component
1 parent 8a7abd3 commit 3fe3ef0

19 files changed

+75
-48
lines changed

src/generators/AngularGenerator.js

+10
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ export default class extends BaseGenerator {
3434
"app/components/common/svg/edit-svg/edit-svg.component.ts",
3535
"app/components/common/svg/menu/menu.component.svg",
3636
"app/components/common/svg/menu/menu.component.ts",
37+
"app/components/common/back-to-list/back-to-list.component.html",
38+
"app/components/common/back-to-list/back-to-list.component.ts",
3739

3840
// COMPONENTS
3941
"app/components/foo/create/create.component.html",
@@ -122,6 +124,7 @@ export default class extends BaseGenerator {
122124
`${dir}/app/components/${lc}/list`,
123125
`${dir}/app/components/${lc}/show`,
124126
`${dir}/app/components/${lc}/table`,
127+
`${dir}/app/components/common/back-to-list`,
125128
`${dir}/app/components/common/delete`,
126129
`${dir}/app/components/common/header`,
127130
`${dir}/app/components/common/sidebar`,
@@ -153,6 +156,8 @@ export default class extends BaseGenerator {
153156
"app/components/common/sidebar/sidebar.component.css",
154157
"app/components/common/sidebar/sidebar.component.html",
155158
"app/components/common/sidebar/sidebar.component.ts",
159+
"app/components/common/back-to-list/back-to-list.component.html",
160+
"app/components/common/back-to-list/back-to-list.component.ts",
156161
"app/interface/api.ts",
157162
"app/service/api.service.ts",
158163
"app/app.component.html",
@@ -182,6 +187,11 @@ export default class extends BaseGenerator {
182187
this.createFileFromPattern(file, dir, [lc, formFields], context)
183188
);
184189

190+
//UTILS
191+
["utils/date.ts"].forEach((path) =>
192+
this.createFile(path, `${dir}/app/${path}`, context, false)
193+
);
194+
185195
// CONFIG
186196
this.createConfigFile(`${dir}/app/utils/config.ts`, {
187197
entrypoint: api.entrypoint,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<a [routerLink]="url"
2+
class="text-blue-600 hover:text-blue-800">
3+
Back to list
4+
</a>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import {Component, Input} from '@angular/core';
2+
import {RouterLink} from "@angular/router";
3+
4+
@Component({
5+
selector: 'app-back-to-list',
6+
standalone: true,
7+
imports: [
8+
RouterLink
9+
],
10+
templateUrl: './back-to-list.component.html'
11+
})
12+
export class BackToListComponent {
13+
@Input() url!: string;
14+
}

templates/angular/app/components/common/pagination/pagination.component.html

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<li>
55
<a [routerLink]="['/books']"
66
[routerLinkActive]="'bg-gray-200 text-gray-500 pointer-events-none'"
7-
(click)="changeUri(pagination()['hydra:first'])"
7+
(click)="paginationAction(pagination()['hydra:first'])"
88
class="bg-gray block py-2 px-3 rounded"
99
aria-label="First page">
1010
<span aria-hidden="true">&lArr;</span>First
@@ -15,7 +15,7 @@
1515
<a [routerLink]="['/books']"
1616
[queryParams]="pageParamValue('hydra:previous')"
1717
[routerLinkActive]="'bg-gray-200 text-gray-500 pointer-events-none'"
18-
(click)="changeUri(pagination()['hydra:previous'])"
18+
(click)="paginationAction(pagination()['hydra:previous'])"
1919
class="bg-gray block py-2 px-3 rounded"
2020
aria-label="Previous page">
2121
Previous
@@ -27,7 +27,7 @@
2727
<a [routerLink]="['/books']"
2828
[queryParams]="pageParamValue('hydra:next')"
2929
[routerLinkActive]="'bg-gray-200 text-gray-500 pointer-events-none'"
30-
(click)="changeUri(pagination()['hydra:next'])"
30+
(click)="paginationAction(pagination()['hydra:next'])"
3131
class="bg-gray block py-2 px-3 rounded"
3232
aria-label="Next page">
3333
Next
@@ -38,7 +38,7 @@
3838
<a [routerLink]="['/books']"
3939
[queryParams]="pageParamValue('hydra:last')"
4040
[routerLinkActive]="'bg-gray-200 text-gray-500 pointer-events-none'"
41-
(click)="changeUri(pagination()['hydra:last'])"
41+
(click)="paginationAction(pagination()['hydra:last'])"
4242
class="bg-gray block py-2 px-3 rounded"
4343
aria-label="Last page">
4444
<span aria-hidden="true">&rAarr;</span> Last

templates/angular/app/components/common/pagination/pagination.component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export class PaginationComponent {
2323
}
2424
}
2525

26-
changeUri (uri: string) {
26+
paginationAction (uri: string) {
2727
this.handleChangePage.emit(uri)
2828
}
2929
}

templates/angular/app/components/common/svg/edit-svg/edit-svg.component.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import { Component } from '@angular/core';
44
selector: 'app-edit-svg',
55
standalone: true,
66
imports: [],
7-
templateUrl: './edit-svg.component.svg',
8-
styleUrl: './edit-svg.component.css'
7+
templateUrl: './edit-svg.component.svg'
98
})
109
export class EditSvgComponent {
1110

templates/angular/app/components/common/svg/show-svg/show-svg.component.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import { Component } from '@angular/core';
44
selector: 'app-show-svg',
55
standalone: true,
66
imports: [],
7-
templateUrl: './show-svg.component.svg',
8-
styleUrl: './show-svg.component.css'
7+
templateUrl: './show-svg.component.svg'
98
})
109
export class ShowSvgComponent {
1110

templates/angular/app/components/foo/create/create.component.html

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
<div class=" w-full px-4 mt-4">
22
<div class="flex items-center justify-between">
3-
<a [routerLink]="['/{{lc}}']"
4-
class="text-blue-600 hover:text-blue-800">
5-
Back to list
6-
</a>
3+
<app-back-to-list url="/{{lc}}s" />
74
</div>
85
@if (isLoading()) {
96
<div class="bg-blue-100 rounded py-4 px-4 text-blue-700 text-sm">Loading ...</div>

templates/angular/app/components/foo/create/create.component.ts

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {Location} from "@angular/common";
22
import {Component, inject, signal, WritableSignal} from '@angular/core';
33
import {FormsModule, ReactiveFormsModule} from "@angular/forms";
44
import {RouterLink} from "@angular/router";
5+
import {BackToListComponent} from "@components/common/back-to-list/back-to-list.component";
56
import {DeleteComponent} from "@components/common/delete/delete.component";
67
import {FormComponent} from "@components/{{lc}}/form/form.component";
78
import {ApiItem} from "@interface/api";
@@ -11,6 +12,7 @@ import {ApiService} from "@service/api.service";
1112
selector: 'app-create-{{lc}}',
1213
standalone: true,
1314
imports: [
15+
BackToListComponent,
1416
DeleteComponent,
1517
RouterLink,
1618
FormsModule,

templates/angular/app/components/foo/edit/edit.component.html

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
<div class="px-4 mt-4">
22
<div class="flex items-center justify-end">
3-
<a [routerLink]="['/{{lc}}']"
4-
class="text-blue-600 hover:text-blue-800">
5-
Back to list
6-
</a>
3+
<app-back-to-list url="/{{lc}}s" />
74
</div>
85
@if (isLoading()) {
96
<div class="bg-blue-100 rounded py-4 px-4 text-blue-700 text-sm">Loading ...</div>

templates/angular/app/components/foo/edit/edit.component.ts

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
import {takeUntilDestroyed} from "@angular/core/rxjs-interop";
1111
import {FormsModule, ReactiveFormsModule} from "@angular/forms";
1212
import {Router, RouterLink} from "@angular/router";
13+
import {BackToListComponent} from "@components/common/back-to-list/back-to-list.component";
1314
import {DeleteComponent} from "@components/common/delete/delete.component";
1415
import {FormComponent} from "@components/{{lc}}/form/form.component";
1516
import {ApiItem} from "@interface/api";
@@ -19,6 +20,7 @@ import {ApiService} from "@service/api.service";
1920
selector: 'app-edit-{{lc}}',
2021
standalone: true,
2122
imports: [
23+
BackToListComponent,
2224
CommonModule,
2325
DeleteComponent,
2426
RouterLink,

templates/angular/app/components/foo/form/form.component.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,19 @@ import {
55
Input,
66
Output
77
} from '@angular/core';
8-
import {ReactiveFormsModule} from "@angular/forms";
8+
import {FormsModule, ReactiveFormsModule} from "@angular/forms";
99
import {DeleteComponent} from "@components/common/delete/delete.component";
1010
import {ApiItem} from "@interface/api";
1111

1212
@Component({
1313
selector: 'app-form-{{lc}}',
1414
standalone: true,
1515
imports: [
16-
ReactiveFormsModule,
1716
AsyncPipe,
17+
DeleteComponent,
18+
FormsModule,
1819
NgIf,
19-
DeleteComponent
20+
ReactiveFormsModule,
2021
],
2122
templateUrl: './form.component.html',
2223
})

templates/angular/app/components/foo/list/list.component.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div class="flex justify-between items-center">
33
<h1 class="text-3xl mb-2">{{title}} List</h1>
44
<div class="flex">
5-
<a routerLink="/{{lc}}/add"
5+
<a routerLink="/{{lc}}s/add"
66
class="bg-cyan-500 hover:bg-cyan-700 text-white text-sm font-bold py-2 px-4 rounded mr-2"
77
>
88
Create
@@ -22,7 +22,7 @@ <h1 class="text-3xl mb-2">{{title}} List</h1>
2222
(selectedAll)="selectedAll()"
2323
/>
2424
@if (pagination()) {
25-
<app-pagination-{{lc}}
25+
<app-pagination
2626
[pagination]="pagination!"
2727
(handleChangePage)="changePage($event)"
2828
/>

templates/angular/app/components/foo/list/list.component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export class ListComponent implements OnInit {
3939
public items: WritableSignal<ApiItem[]> = signal([])
4040
public error: WritableSignal<String> = signal('')
4141
public bulk: WritableSignal<Array<string>> = signal([])
42-
public uri: WritableSignal<string> = signal('/{{lc}}')
42+
public uri: WritableSignal<string> = signal('/{{lc}}s')
4343
private apiService: ApiService = inject(ApiService)
4444
private destroy: DestroyRef = inject(DestroyRef)
4545

templates/angular/app/components/foo/show/show.component.html

+12-14
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
<div class="bg-blue-100 rounded py-4 px-4 text-blue-700 text-sm">Loading ...</div>
44
} @else {
55
<div class="flex items-center justify-between">
6-
<a [routerLink]="['/{{lc}}']"
7-
class="text-blue-600 hover:text-blue-800">
8-
Back to list
9-
</a>
6+
<app-back-to-list url="/{{lc}}s" />
107
<div class="flex">
118
<a [routerLink]="[item()['@id'], 'edit']"
129
class="px-6 py-2 mr-2 bg-green-600 text-white text-xs rounded shadow-md hover:bg-green-700">
@@ -31,9 +28,9 @@ <h1 class="text-3xl my-4">Edit \{{ item()['name'] }} <span class="text-xl">\{{ i
3128
</tr>
3229
</thead>
3330
<tbody>
31+
@if (item()) {
3432
{{#each fields}}
3533
<tr class="border-b">
36-
@if (item()) {
3734
<th
3835
class="text-sm font-medium px-6 py-4 text-left capitalize"
3936
scope="row"
@@ -42,18 +39,19 @@ <h1 class="text-3xl my-4">Edit \{{ item()['name'] }} <span class="text-xl">\{{ i
4239
</th>
4340
<td class="px-6 py-4 whitespace-nowrap text-sm">
4441
{{#if isReferences}}
45-
\{{ item()['name'] }}
42+
\{{ item(){{name}} }}
43+
44+
{{else if (compare type "==" "dateTime") }}
45+
\{{ formatDateTime(item()['{{name}}']) }}
46+
{{else}}
47+
\{{ item()['{{name}}'] }}
48+
{{/if}}
4649
</td>
47-
{{else if (compare type "==" "dateTime") }}
48-
\{{ formatDateTime(item.{{name}}) }}
49-
{{else}}
50-
\{{ item.{{name}} }}
51-
{{/if}}
52-
} @else {
53-
<td>Rien</td>
54-
}
5550
</tr>
5651
{{/each}}
52+
} @else {
53+
<td>Rien</td>
54+
}
5755
</tbody>
5856
</table>
5957
</div>

templates/angular/app/components/foo/show/show.component.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,20 @@ import {
99
} from '@angular/core';
1010
import {takeUntilDestroyed} from "@angular/core/rxjs-interop";
1111
import {Router, RouterLink} from "@angular/router";
12+
import {BackToListComponent} from "@components/common/back-to-list/back-to-list.component";
1213
import {DeleteComponent} from "@components/common/delete/delete.component";
1314
import {ApiService} from "@service/api.service";
1415
import {ApiItem} from "@interface/api";
16+
import {formatDateTime} from "@utils/date";
1517

1618
@Component({
1719
selector: 'app-show-{{lc}}',
1820
standalone: true,
1921
imports: [
22+
BackToListComponent,
2023
CommonModule,
21-
RouterLink,
22-
DeleteComponent
24+
DeleteComponent,
25+
RouterLink
2326
],
2427
templateUrl: './show.component.html',
2528
})
@@ -32,7 +35,7 @@ export class ShowComponent implements OnInit {
3235
public item: WritableSignal<ApiItem> = signal({} as ApiItem)
3336
public isLoading: WritableSignal<boolean> = signal(false)
3437
public error: WritableSignal<string> = signal('')
35-
38+
protected readonly formatDateTime = formatDateTime;
3639
ngOnInit() {
3740
this.toggleIsLoading()
3841
const id = this.router.url

templates/angular/app/components/foo/table/table.component.html

+6-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
name="selectedAll"
1010
(change)="selected()"
1111
>
12-
</th >
12+
</th>
1313
{{#each fields}}
1414
<th class="text-sm font-medium px-6 py-4 text-left capitalize">{{name}}</th>
1515
{{/each}}
@@ -31,9 +31,9 @@
3131
<td class="px-6 py-4 text-sm">
3232
{{#if isReferences}}
3333
\{{ {{lowercase reference.title}} }}
34-
'coucou"
34+
'coucou"
3535
{{else if (compare type "==" "dateTime") }}
36-
\{{ formatDateTime(item['{{name}}') }}
36+
\{{ formatDateTime(item['{{name}}']) }}
3737
{{else}}
3838
\{{ item['{{name}}'] }}
3939
{{/if}}
@@ -42,13 +42,13 @@
4242
<td class="w-8">
4343
<a [routerLink]="[item['@id']]" class="text-cyan-500">
4444
Show
45-
<app-show-svg></app-show-svg>
45+
<app-show-svg/>
4646
</a>
4747
</td>
4848
<td class="w-8">
49-
<a [routerLink]="[item['id'], 'edit']" class="text-cyan-500">
49+
<a [routerLink]="[item['@id'], 'edit']" class="text-cyan-500">
5050
Edit
51-
<app-edit-svg></app-edit-svg>
51+
<app-edit-svg/>
5252
</a>
5353
</td>
5454
</tr>

templates/angular/app/components/foo/table/table.component.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {RouterLink} from "@angular/router";
1010
import {ShowSvgComponent} from "@components/common/svg/show-svg/show-svg.component";
1111
import {EditSvgComponent} from "@components/common/svg/edit-svg/edit-svg.component";
1212
import {ApiItem} from "@interface/api";
13+
import {formatDateTime} from "@utils/date";
1314

1415
@Component({
1516
selector: 'app-table-{{lc}}',
@@ -27,7 +28,7 @@ export class TableComponent {
2728
@Input() bulk!: Array<string>;
2829
@Output() addToBulkList = new EventEmitter<string>()
2930
@Output() selectedAll = new EventEmitter<Function>()
30-
31+
protected readonly formatDateTime = formatDateTime;
3132

3233
addToBulk(id: string) {
3334
this.addToBulkList.emit(id)

testapp.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ if [ "$1" = "angular" ]; then
8282

8383
ng new angular
8484
cd ../..
85-
yarn --cwd ./tmp/app/angular add tailwindcss postcss autoprefixer
85+
yarn --cwd ./tmp/app/angular add tailwindcss postcss autoprefixer dayjs
8686
yarn --cwd ./tmp/app/angular tailwindcss init -p
8787

8888
cp ./templates/common/tailwind.config.js ./tmp/app/angular

0 commit comments

Comments
 (0)