Skip to content

Commit aecd360

Browse files
wip
1 parent 5795f3c commit aecd360

23 files changed

+178
-143
lines changed

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@
6767
"test-react-app": "./testapp.sh react",
6868
"test-next-app": "./testapp.sh next",
6969
"test-vue-app": "./testapp.sh vue",
70-
"test-nuxt-app": "./testapp.sh nuxt"
70+
"test-nuxt-app": "./testapp.sh nuxt",
71+
"test-angular-app": "./testapp.sh angular"
7172
},
7273
"lint-staged": {
7374
"src/**/*.js": "yarn lint --fix"

src/generators/AngularGenerator.js

+20-7
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ export default class extends BaseGenerator {
3636
//SVG COMPONENT
3737
"app/components/svg/list-svg/list-svg.component.svg",
3838
"app/components/svg/list-svg/list-svg.component.ts",
39+
"app/components/svg/show-svg/show-svg.component.svg",
40+
"app/components/svg/show-svg/show-svg.component.ts",
41+
"app/components/svg/edit-svg/edit-svg.component.svg",
42+
"app/components/svg/edit-svg/edit-svg.component.ts",
3943
"app/components/svg/menu/menu.component.svg",
4044
"app/components/svg/menu/menu.component.ts",
4145

@@ -89,23 +93,23 @@ export default class extends BaseGenerator {
8993
const hasIsRelation = fields.some((field) => field.isRelation);
9094
const hasIsRelations = fields.some((field) => field.isRelations);
9195
const hasDateField = fields.some((field) => field.type === "dateTime");
92-
93-
console.log(resource);
96+
const formFields = this.buildFields(fields);
9497

9598
const context = {
9699
title: resource.title,
97100
name: resource.name,
98101
lc,
99102
uc: resource.title.toUpperCase(),
100103
fields,
101-
formFields: this.buildFields(fields),
104+
formFields,
102105
hydraPrefix: this.hydraPrefix,
103106
titleUcFirst,
104107
hasIsRelation,
105108
hasIsRelations,
106109
hasRelations: hasIsRelation || hasIsRelations,
107110
hasDateField,
108111
};
112+
console.log("api ==>", api);
109113

110114
//CREATE DIRECTORIES - These directories may already exist
111115
[
@@ -121,6 +125,8 @@ export default class extends BaseGenerator {
121125
`${dir}/app/components/common/sidebar`,
122126
`${dir}/app/components/common/table`,
123127
`${dir}/app/components/svg/list-svg`,
128+
`${dir}/app/components/svg/show-svg`,
129+
`${dir}/app/components/svg/edit-svg`,
124130
`${dir}/app/components/svg/menu`,
125131
`${dir}/app/interface`,
126132
`${dir}/app/router`,
@@ -131,6 +137,10 @@ export default class extends BaseGenerator {
131137
[
132138
"app/components/svg/list-svg/list-svg.component.svg",
133139
"app/components/svg/list-svg/list-svg.component.ts",
140+
"app/components/svg/show-svg/show-svg.component.svg",
141+
"app/components/svg/show-svg/show-svg.component.ts",
142+
"app/components/svg/edit-svg/edit-svg.component.svg",
143+
"app/components/svg/edit-svg/edit-svg.component.ts",
134144
"app/components/svg/menu/menu.component.svg",
135145
"app/components/svg/menu/menu.component.ts",
136146
"app/components/common/delete/delete.component.html",
@@ -150,15 +160,18 @@ export default class extends BaseGenerator {
150160
);
151161

152162
[
163+
"app/router/%s.ts",
164+
"app/components/%s/list/list.component.html",
165+
"app/components/%s/list/list.component.ts",
153166
"app/components/%s/create/create.component.html",
154167
"app/components/%s/create/create.component.ts",
155168
/*"app/components/%s/edit/edit.component.html",
156169
"app/components/%s/edit/edit.component.ts",
157-
"app/components/%s/list/list.component.html",
158-
"app/components/%s/list/list.component.ts",
159-
"app/components/%s/show/show.component.html",
170+
"app/components/%s/show/show.component.svg",
160171
"app/components/%s/show/show.component.ts",*/
161-
].forEach((file) => this.createFileFromPattern(file, dir, [lc], context));
172+
].forEach((file) =>
173+
this.createFileFromPattern(file, dir, [lc, formFields], context)
174+
);
162175
}
163176

164177
parseFields(resource) {

src/generators/AngularGenerator.test.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,14 @@ test("Generate a React app", () => {
6262
].forEach((file) => expect(fs.existsSync(tmpobj.name + file)).toBe(true));
6363

6464
[
65-
"/components/abc/Form.tsx",
66-
"/components/abc/List.tsx",
67-
"/components/abc/Show.tsx",
65+
"app/components/abc/create/create.component.html",
66+
"app/components/abc/create/create.component.ts",
67+
"app/components/abc/edit/edit.component.html",
68+
"app/components/abc/edit/edit.component.ts",
69+
"app/components/abc/list/list.component.html",
70+
"app/components/abc/list/list.component.ts",
71+
"app/components/abc/show/show.component.html",
72+
"app/components/abc/show/show.component.ts",
6873
"/interfaces/Abc.ts",
6974
].forEach((file) => {
7075
expect(fs.existsSync(tmpobj.name + file)).toBe(true);

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

+32-54
Original file line numberDiff line numberDiff line change
@@ -16,59 +16,37 @@
1616
</tr>
1717
</thead>
1818
<tbody>
19-
@for (item of items; track item) {
20-
<tr>
21-
<td class="w-2">
22-
<input type="checkbox"
23-
name="test"
24-
[id]="item['@id']"
25-
[checked]="bulk.includes(item['@id']!)"
26-
(change)="addToBulk(item['@id']!)"
27-
>
28-
</td>
29-
<td>{{ item['id'] }}</td>
30-
<td>{{ item['name'] }}</td>
31-
<td class="w-8">
32-
<a [routerLink]="[item['@id']]" class="text-cyan-500">
33-
Show
34-
<svg
35-
xmlns="http://www.w3.org/2000/svg"
36-
viewBox="0 0 24 24"
37-
fill="currentColor"
38-
class="w-6 h-6"
39-
>
40-
<path d="M12 15a3 3 0 100-6 3 3 0 000 6z"/>
41-
<path
42-
fill-rule="evenodd"
43-
d="M1.323 11.447C2.811 6.976 7.028 3.75 12.001 3.75c4.97 0 9.185 3.223 10.675 7.69.12.362.12.752 0 1.113-1.487 4.471-5.705 7.697-10.677 7.697-4.97 0-9.186-3.223-10.675-7.69a1.762 1.762 0 010-1.113zM17.25 12a5.25 5.25 0 11-10.5 0 5.25 5.25 0 0110.5 0z"
44-
clip-rule="evenodd"
45-
/>
46-
</svg>
47-
</a>
48-
</td>
49-
<td class="w-8">
50-
<a [routerLink]="[item['id'], 'edit']" class="text-cyan-500">
51-
Edit
52-
<svg
53-
xmlns="http://www.w3.org/2000/svg"
54-
viewBox="0 0 24 24"
55-
fill="currentColor"
56-
class="w-6 h-6"
57-
>
58-
<path
59-
d="M21.731 2.269a2.625 2.625 0 00-3.712 0l-1.157 1.157 3.712 3.712 1.157-1.157a2.625 2.625 0 000-3.712zM19.513 8.199l-3.712-3.712-8.4 8.4a5.25 5.25 0 00-1.32 2.214l-.8 2.685a.75.75 0 00.933.933l2.685-.8a5.25 5.25 0 002.214-1.32l8.4-8.4z"/>
60-
<path
61-
d="M5.25 5.25a3 3 0 00-3 3v10.5a3 3 0 003 3h10.5a3 3 0 003-3V13.5a.75.75 0 00-1.5 0v5.25a1.5 1.5 0 01-1.5 1.5H5.25a1.5 1.5 0 01-1.5-1.5V8.25a1.5 1.5 0 011.5-1.5h5.25a.75.75 0 000-1.5H5.25z"/>
62-
</svg>
63-
</a>
64-
</td>
65-
</tr>
66-
} @empty {
67-
<tr>
68-
<td colspan="2" class="text-center italic p-6">
69-
Pas de données.
70-
</td>
71-
</tr>
72-
}
19+
@for (item of items; track item) {
20+
<tr>
21+
<td class="w-2">
22+
<input type="checkbox"
23+
name="test"
24+
[id]="item['@id']"
25+
[checked]="bulk.includes(item['@id']!)"
26+
(change)="addToBulk(item['@id']!)"
27+
>
28+
</td>
29+
<td>{{ item['id'] }}</td>
30+
<td>{{ item['name'] }}</td>
31+
<td class="w-8">
32+
<a [routerLink]="[item['@id']]" class="text-cyan-500">
33+
Show
34+
<app-show-svg />
35+
</a>
36+
</td>
37+
<td class="w-8">
38+
<a [routerLink]="[item['id'], 'edit']" class="text-cyan-500">
39+
Edit
40+
<app-edit-svg />
41+
</a>
42+
</td>
43+
</tr>
44+
} @empty {
45+
<tr>
46+
<td colspan="2" class="text-center italic p-6">
47+
Pas de données.
48+
</td>
49+
</tr>
50+
}
7351
</tbody>
7452
</table>

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,19 @@ import {Component, EventEmitter, Input, Output} from '@angular/core';
22
import {RouterLink} from "@angular/router";
33
import {Hero} from "../../../interface/hero.model";
44
import {FormsModule} from "@angular/forms";
5+
import {ShowComponent} from "../../svg/show/show.component";
6+
import {ShowSvgComponent} from "../../svg/show-svg/show-svg.component";
7+
import {EditSvgComponent} from "../../svg/edit-svg/edit-svg.component";
58

69
@Component({
710
selector: 'app-table',
811
standalone: true,
912
imports: [
1013
RouterLink,
11-
FormsModule
14+
FormsModule,
15+
ShowComponent,
16+
ShowSvgComponent,
17+
EditSvgComponent
1218
],
1319
templateUrl: './table.component.html',
1420
})

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
<div class="bg-blue-100 rounded py-4 px-4 text-blue-700 text-sm">Loading ...</div>
1010
} @else {
1111
<h1 class="text-3xl my-4">Create</h1>
12-
<app-form [fields]="{{{formType}}}" (submit)="onSubmit($event)"/>
12+
<app-form [fields]="formType" (submit)="onSubmit($event)"></app-form>
1313
}
1414
</div>

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

+1-6
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,7 @@ import {FormComponent} from "../../common/form/form.component";
2020
})
2121
export class CreateComponent {
2222
public isLoading: WritableSignal<boolean> = signal(false)
23-
public formType: Array<{ name: string; type: string }> = [
24-
{
25-
name: 'name',
26-
type: 'string',
27-
}
28-
]
23+
public formType ='{{formFields}}'
2924

3025
constructor(private apiService: ApiService, private location: Location) {
3126
}

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Component, computed, OnInit, signal, WritableSignal} from '@angular/core';
1+
import {Component, OnInit, signal, WritableSignal} from '@angular/core';
22
import {DeleteComponent} from "../../common/delete/delete.component";
33
import {Router, RouterLink} from "@angular/router";
44
import {ApiService} from "../../../service/api.service";
@@ -25,7 +25,7 @@ export class EditComponent implements OnInit {
2525

2626
constructor(
2727
private router: Router,
28-
private heroService: ApiService,
28+
private apiService: ApiService,
2929
private location: Location
3030
) {
3131
}
@@ -37,7 +37,7 @@ export class EditComponent implements OnInit {
3737
loadData() {
3838
this.isLoading.set(true)
3939
const splitUrl = this.router.url.split('/edit')[0]
40-
this.heroService
40+
this.apiService
4141
.getData(splitUrl)
4242
.subscribe(item => {
4343
this.item.set(item)
@@ -58,7 +58,7 @@ export class EditComponent implements OnInit {
5858
}
5959

6060
onSubmit(event: any) {
61-
return this.heroService.putHero(
61+
return this.apiService.putHero(
6262
this.item()?.["@id"],
6363
this.item()
6464
).subscribe(() => {
@@ -67,7 +67,7 @@ export class EditComponent implements OnInit {
6767
}
6868

6969
delete() {
70-
return this.heroService.delete(
70+
return this.apiService.delete(
7171
this.item()?.["@id"]
7272
).subscribe(
7373
() => this.location.back()

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<div class="p-8 mt-4">
22
<div class="flex justify-between items-center">
3-
<h1 class="text-3xl mb-2">Heroes List</h1>
3+
<h1 class="text-3xl mb-2">{{title}} List</h1>
44
<div class="flex">
5-
<a routerLink="/heroes/add"
5+
<a routerLink="/{{lc}}/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
@@ -17,7 +17,7 @@ <h1 class="text-3xl mb-2">Heroes List</h1>
1717
@if (isLoading()) {
1818
<div class="bg-blue-100 rounded py-4 px-4 text-blue-700 text-sm">Loading ...</div>
1919
} @else {
20-
<app-table [items]="heroes()"
20+
<app-table [items]="items()"
2121
[bulk]="bulk()"
2222
(addToBulkList)="addToBulk($event)"
2323
(selectedAll)="selectedAll()"

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

+10-13
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
import {Component, computed, OnInit, Output, signal, WritableSignal} from '@angular/core';
1+
import {Component, OnInit, signal, WritableSignal} from '@angular/core';
22
import {RouterLink} from "@angular/router";
33
import {AsyncPipe, Location, NgFor, NgIf} from "@angular/common";
44
import {TableComponent} from "../../common/table/table.component";
55
import {ApiService} from "../../../service/api.service";
66
import {Hero} from "../../../interface/hero.model";
77
import {DeleteComponent} from "../../common/delete/delete.component";
8-
import {log} from "node:util";
9-
import {Validators} from "@angular/forms";
108

119
@Component({
1210
selector: 'app-list',
@@ -22,24 +20,23 @@ import {Validators} from "@angular/forms";
2220
templateUrl: './list.component.html',
2321
})
2422
export class ListComponent implements OnInit {
25-
public heroes: WritableSignal<Hero[] | []> = signal([])
23+
public items: WritableSignal<Hero[] | []> = signal([])
2624
public isLoading = signal(false)
2725
public error = signal(undefined)
28-
@Output() bulk: WritableSignal<Array<string>> = signal([])
26+
public bulk: WritableSignal<Array<string>> = signal([])
2927

3028
constructor(
31-
private heroService: ApiService,
32-
private location: Location
29+
private apiService: ApiService
3330
) {
3431
}
3532

3633
ngOnInit() {
3734
this.isLoading.set(true)
38-
this.heroService
39-
.getDataes('/heroes')
35+
this.apiService
36+
.getData('/{{lc}}')
4037
.subscribe(
4138
(items) => {
42-
this.heroes.set(items['hydra:member'])
39+
this.items.set(items['hydra:member'])
4340
this.isLoading.set(false)
4441
}
4542
)
@@ -56,8 +53,8 @@ export class ListComponent implements OnInit {
5653

5754
selectedAll() {
5855
if (!this.bulk().length) {
59-
this.heroes().forEach(hero => {
60-
this.bulk().push(<string>hero["@id"])
56+
this.items().forEach(item => {
57+
this.bulk().push(<string>item["@id"])
6158
})
6259
} else {
6360
this.bulk.set([])
@@ -70,7 +67,7 @@ export class ListComponent implements OnInit {
7067
items =>
7168
items.forEach(
7269
uri =>
73-
this.heroService.delete(uri)
70+
this.apiService.delete(uri)
7471
.subscribe(
7572
() => {
7673
window.location.reload()

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +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]="['/heroes']"
6+
<a [routerLink]="['/{{lc}}']"
77
class="text-blue-600 hover:text-blue-800">
88
Back to list
99
</a>

0 commit comments

Comments
 (0)