Skip to content

Commit

Permalink
add back to list component
Browse files Browse the repository at this point in the history
  • Loading branch information
maxime-urbanski committed Jun 24, 2024
1 parent 8a7abd3 commit 3fe3ef0
Show file tree
Hide file tree
Showing 19 changed files with 75 additions and 48 deletions.
10 changes: 10 additions & 0 deletions src/generators/AngularGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export default class extends BaseGenerator {
"app/components/common/svg/edit-svg/edit-svg.component.ts",
"app/components/common/svg/menu/menu.component.svg",
"app/components/common/svg/menu/menu.component.ts",
"app/components/common/back-to-list/back-to-list.component.html",
"app/components/common/back-to-list/back-to-list.component.ts",

// COMPONENTS
"app/components/foo/create/create.component.html",
Expand Down Expand Up @@ -122,6 +124,7 @@ export default class extends BaseGenerator {
`${dir}/app/components/${lc}/list`,
`${dir}/app/components/${lc}/show`,
`${dir}/app/components/${lc}/table`,
`${dir}/app/components/common/back-to-list`,
`${dir}/app/components/common/delete`,
`${dir}/app/components/common/header`,
`${dir}/app/components/common/sidebar`,
Expand Down Expand Up @@ -153,6 +156,8 @@ export default class extends BaseGenerator {
"app/components/common/sidebar/sidebar.component.css",
"app/components/common/sidebar/sidebar.component.html",
"app/components/common/sidebar/sidebar.component.ts",
"app/components/common/back-to-list/back-to-list.component.html",
"app/components/common/back-to-list/back-to-list.component.ts",
"app/interface/api.ts",
"app/service/api.service.ts",
"app/app.component.html",
Expand Down Expand Up @@ -182,6 +187,11 @@ export default class extends BaseGenerator {
this.createFileFromPattern(file, dir, [lc, formFields], context)
);

//UTILS
["utils/date.ts"].forEach((path) =>
this.createFile(path, `${dir}/app/${path}`, context, false)
);

// CONFIG
this.createConfigFile(`${dir}/app/utils/config.ts`, {
entrypoint: api.entrypoint,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<a [routerLink]="url"
class="text-blue-600 hover:text-blue-800">
Back to list
</a>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {Component, Input} from '@angular/core';
import {RouterLink} from "@angular/router";

@Component({
selector: 'app-back-to-list',
standalone: true,
imports: [
RouterLink
],
templateUrl: './back-to-list.component.html'
})
export class BackToListComponent {
@Input() url!: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<li>
<a [routerLink]="['/books']"
[routerLinkActive]="'bg-gray-200 text-gray-500 pointer-events-none'"
(click)="changeUri(pagination()['hydra:first'])"
(click)="paginationAction(pagination()['hydra:first'])"
class="bg-gray block py-2 px-3 rounded"
aria-label="First page">
<span aria-hidden="true">&lArr;</span>First
Expand All @@ -15,7 +15,7 @@
<a [routerLink]="['/books']"
[queryParams]="pageParamValue('hydra:previous')"
[routerLinkActive]="'bg-gray-200 text-gray-500 pointer-events-none'"
(click)="changeUri(pagination()['hydra:previous'])"
(click)="paginationAction(pagination()['hydra:previous'])"
class="bg-gray block py-2 px-3 rounded"
aria-label="Previous page">
Previous
Expand All @@ -27,7 +27,7 @@
<a [routerLink]="['/books']"
[queryParams]="pageParamValue('hydra:next')"
[routerLinkActive]="'bg-gray-200 text-gray-500 pointer-events-none'"
(click)="changeUri(pagination()['hydra:next'])"
(click)="paginationAction(pagination()['hydra:next'])"
class="bg-gray block py-2 px-3 rounded"
aria-label="Next page">
Next
Expand All @@ -38,7 +38,7 @@
<a [routerLink]="['/books']"
[queryParams]="pageParamValue('hydra:last')"
[routerLinkActive]="'bg-gray-200 text-gray-500 pointer-events-none'"
(click)="changeUri(pagination()['hydra:last'])"
(click)="paginationAction(pagination()['hydra:last'])"
class="bg-gray block py-2 px-3 rounded"
aria-label="Last page">
<span aria-hidden="true">&rAarr;</span> Last
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class PaginationComponent {
}
}

changeUri (uri: string) {
paginationAction (uri: string) {
this.handleChangePage.emit(uri)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { Component } from '@angular/core';
selector: 'app-edit-svg',
standalone: true,
imports: [],
templateUrl: './edit-svg.component.svg',
styleUrl: './edit-svg.component.css'
templateUrl: './edit-svg.component.svg'
})
export class EditSvgComponent {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { Component } from '@angular/core';
selector: 'app-show-svg',
standalone: true,
imports: [],
templateUrl: './show-svg.component.svg',
styleUrl: './show-svg.component.css'
templateUrl: './show-svg.component.svg'
})
export class ShowSvgComponent {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<div class=" w-full px-4 mt-4">
<div class="flex items-center justify-between">
<a [routerLink]="['/{{lc}}']"
class="text-blue-600 hover:text-blue-800">
Back to list
</a>
<app-back-to-list url="/{{lc}}s" />
</div>
@if (isLoading()) {
<div class="bg-blue-100 rounded py-4 px-4 text-blue-700 text-sm">Loading ...</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {Location} from "@angular/common";
import {Component, inject, signal, WritableSignal} from '@angular/core';
import {FormsModule, ReactiveFormsModule} from "@angular/forms";
import {RouterLink} from "@angular/router";
import {BackToListComponent} from "@components/common/back-to-list/back-to-list.component";
import {DeleteComponent} from "@components/common/delete/delete.component";
import {FormComponent} from "@components/{{lc}}/form/form.component";
import {ApiItem} from "@interface/api";
Expand All @@ -11,6 +12,7 @@ import {ApiService} from "@service/api.service";
selector: 'app-create-{{lc}}',
standalone: true,
imports: [
BackToListComponent,
DeleteComponent,
RouterLink,
FormsModule,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<div class="px-4 mt-4">
<div class="flex items-center justify-end">
<a [routerLink]="['/{{lc}}']"
class="text-blue-600 hover:text-blue-800">
Back to list
</a>
<app-back-to-list url="/{{lc}}s" />
</div>
@if (isLoading()) {
<div class="bg-blue-100 rounded py-4 px-4 text-blue-700 text-sm">Loading ...</div>
Expand Down
2 changes: 2 additions & 0 deletions templates/angular/app/components/foo/edit/edit.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import {takeUntilDestroyed} from "@angular/core/rxjs-interop";
import {FormsModule, ReactiveFormsModule} from "@angular/forms";
import {Router, RouterLink} from "@angular/router";
import {BackToListComponent} from "@components/common/back-to-list/back-to-list.component";
import {DeleteComponent} from "@components/common/delete/delete.component";
import {FormComponent} from "@components/{{lc}}/form/form.component";
import {ApiItem} from "@interface/api";
Expand All @@ -19,6 +20,7 @@ import {ApiService} from "@service/api.service";
selector: 'app-edit-{{lc}}',
standalone: true,
imports: [
BackToListComponent,
CommonModule,
DeleteComponent,
RouterLink,
Expand Down
7 changes: 4 additions & 3 deletions templates/angular/app/components/foo/form/form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@ import {
Input,
Output
} from '@angular/core';
import {ReactiveFormsModule} from "@angular/forms";
import {FormsModule, ReactiveFormsModule} from "@angular/forms";
import {DeleteComponent} from "@components/common/delete/delete.component";
import {ApiItem} from "@interface/api";

@Component({
selector: 'app-form-{{lc}}',
standalone: true,
imports: [
ReactiveFormsModule,
AsyncPipe,
DeleteComponent,
FormsModule,
NgIf,
DeleteComponent
ReactiveFormsModule,
],
templateUrl: './form.component.html',
})
Expand Down
4 changes: 2 additions & 2 deletions templates/angular/app/components/foo/list/list.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="flex justify-between items-center">
<h1 class="text-3xl mb-2">{{title}} List</h1>
<div class="flex">
<a routerLink="/{{lc}}/add"
<a routerLink="/{{lc}}s/add"
class="bg-cyan-500 hover:bg-cyan-700 text-white text-sm font-bold py-2 px-4 rounded mr-2"
>
Create
Expand All @@ -22,7 +22,7 @@ <h1 class="text-3xl mb-2">{{title}} List</h1>
(selectedAll)="selectedAll()"
/>
@if (pagination()) {
<app-pagination-{{lc}}
<app-pagination
[pagination]="pagination!"
(handleChangePage)="changePage($event)"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class ListComponent implements OnInit {
public items: WritableSignal<ApiItem[]> = signal([])
public error: WritableSignal<String> = signal('')
public bulk: WritableSignal<Array<string>> = signal([])
public uri: WritableSignal<string> = signal('/{{lc}}')
public uri: WritableSignal<string> = signal('/{{lc}}s')
private apiService: ApiService = inject(ApiService)
private destroy: DestroyRef = inject(DestroyRef)

Expand Down
26 changes: 12 additions & 14 deletions templates/angular/app/components/foo/show/show.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
<div class="bg-blue-100 rounded py-4 px-4 text-blue-700 text-sm">Loading ...</div>
} @else {
<div class="flex items-center justify-between">
<a [routerLink]="['/{{lc}}']"
class="text-blue-600 hover:text-blue-800">
Back to list
</a>
<app-back-to-list url="/{{lc}}s" />
<div class="flex">
<a [routerLink]="[item()['@id'], 'edit']"
class="px-6 py-2 mr-2 bg-green-600 text-white text-xs rounded shadow-md hover:bg-green-700">
Expand All @@ -31,9 +28,9 @@ <h1 class="text-3xl my-4">Edit \{{ item()['name'] }} <span class="text-xl">\{{ i
</tr>
</thead>
<tbody>
@if (item()) {
{{#each fields}}
<tr class="border-b">
@if (item()) {
<th
class="text-sm font-medium px-6 py-4 text-left capitalize"
scope="row"
Expand All @@ -42,18 +39,19 @@ <h1 class="text-3xl my-4">Edit \{{ item()['name'] }} <span class="text-xl">\{{ i
</th>
<td class="px-6 py-4 whitespace-nowrap text-sm">
{{#if isReferences}}
\{{ item()['name'] }}
\{{ item(){{name}} }}

{{else if (compare type "==" "dateTime") }}
\{{ formatDateTime(item()['{{name}}']) }}
{{else}}
\{{ item()['{{name}}'] }}
{{/if}}
</td>
{{else if (compare type "==" "dateTime") }}
\{{ formatDateTime(item.{{name}}) }}
{{else}}
\{{ item.{{name}} }}
{{/if}}
} @else {
<td>Rien</td>
}
</tr>
{{/each}}
} @else {
<td>Rien</td>
}
</tbody>
</table>
</div>
Expand Down
9 changes: 6 additions & 3 deletions templates/angular/app/components/foo/show/show.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,20 @@ import {
} from '@angular/core';
import {takeUntilDestroyed} from "@angular/core/rxjs-interop";
import {Router, RouterLink} from "@angular/router";
import {BackToListComponent} from "@components/common/back-to-list/back-to-list.component";
import {DeleteComponent} from "@components/common/delete/delete.component";
import {ApiService} from "@service/api.service";
import {ApiItem} from "@interface/api";
import {formatDateTime} from "@utils/date";

@Component({
selector: 'app-show-{{lc}}',
standalone: true,
imports: [
BackToListComponent,
CommonModule,
RouterLink,
DeleteComponent
DeleteComponent,
RouterLink
],
templateUrl: './show.component.html',
})
Expand All @@ -32,7 +35,7 @@ export class ShowComponent implements OnInit {
public item: WritableSignal<ApiItem> = signal({} as ApiItem)
public isLoading: WritableSignal<boolean> = signal(false)
public error: WritableSignal<string> = signal('')

protected readonly formatDateTime = formatDateTime;
ngOnInit() {
this.toggleIsLoading()
const id = this.router.url
Expand Down
12 changes: 6 additions & 6 deletions templates/angular/app/components/foo/table/table.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
name="selectedAll"
(change)="selected()"
>
</th >
</th>
{{#each fields}}
<th class="text-sm font-medium px-6 py-4 text-left capitalize">{{name}}</th>
{{/each}}
Expand All @@ -31,9 +31,9 @@
<td class="px-6 py-4 text-sm">
{{#if isReferences}}
\{{ {{lowercase reference.title}} }}
'coucou"
'coucou"
{{else if (compare type "==" "dateTime") }}
\{{ formatDateTime(item['{{name}}') }}
\{{ formatDateTime(item['{{name}}']) }}
{{else}}
\{{ item['{{name}}'] }}
{{/if}}
Expand All @@ -42,13 +42,13 @@
<td class="w-8">
<a [routerLink]="[item['@id']]" class="text-cyan-500">
Show
<app-show-svg></app-show-svg>
<app-show-svg/>
</a>
</td>
<td class="w-8">
<a [routerLink]="[item['id'], 'edit']" class="text-cyan-500">
<a [routerLink]="[item['@id'], 'edit']" class="text-cyan-500">
Edit
<app-edit-svg></app-edit-svg>
<app-edit-svg/>
</a>
</td>
</tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {RouterLink} from "@angular/router";
import {ShowSvgComponent} from "@components/common/svg/show-svg/show-svg.component";
import {EditSvgComponent} from "@components/common/svg/edit-svg/edit-svg.component";
import {ApiItem} from "@interface/api";
import {formatDateTime} from "@utils/date";

@Component({
selector: 'app-table-{{lc}}',
Expand All @@ -27,7 +28,7 @@ export class TableComponent {
@Input() bulk!: Array<string>;
@Output() addToBulkList = new EventEmitter<string>()
@Output() selectedAll = new EventEmitter<Function>()

protected readonly formatDateTime = formatDateTime;

addToBulk(id: string) {
this.addToBulkList.emit(id)
Expand Down
2 changes: 1 addition & 1 deletion testapp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ if [ "$1" = "angular" ]; then

ng new angular
cd ../..
yarn --cwd ./tmp/app/angular add tailwindcss postcss autoprefixer
yarn --cwd ./tmp/app/angular add tailwindcss postcss autoprefixer dayjs
yarn --cwd ./tmp/app/angular tailwindcss init -p

cp ./templates/common/tailwind.config.js ./tmp/app/angular
Expand Down

0 comments on commit 3fe3ef0

Please sign in to comment.