Skip to content

Commit 12ee37d

Browse files
committed
update logic for template
1 parent 64cfbec commit 12ee37d

44 files changed

Lines changed: 421 additions & 195 deletions

File tree

Some content is hidden

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

crud/files/__name@/__name@-routing.module.ts.template

Lines changed: 0 additions & 1 deletion
This file was deleted.

crud/files/__name@/__name@.module.ts.template

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
// component/__name@-add/__name@-add.component.html.template
1+
<form [formGroup]="form" (ngSubmit)="submit()">
2+
<ion-item *ngFor="let field of fields">
3+
<ion-label position="stacked">{{ '{{' }} field.key {{ '}}' }}</ion-label>
4+
<ion-input [formControlName]="field.key"></ion-input>
5+
</ion-item>
6+
<ion-button expand="block" type="submit">Save</ion-button>
7+
</form>

crud/files/__name@/component/__name@-add/__name@-add.component.ts.template

Lines changed: 0 additions & 1 deletion
This file was deleted.

crud/files/__name@/component/__name@-details/__name@-details.component.html.template

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,23 @@
1-
// component/__name@-details/__name@-details.component.ts.template
1+
2+
import { Component, OnInit } from '@angular/core';
3+
import { ActivatedRoute } from '@angular/router';
4+
import { Store } from '@ngrx/store';
5+
import { select{{ classify name }}ById } from '../../store/selectors/{{ dasherize name }}.selectors';
6+
import { load{{ classify name }} } from '../../store/actions/{{ dasherize name }}.actions';
7+
8+
@Component({
9+
selector: 'app-{{ dasherize name }}-details',
10+
templateUrl: './{{ dasherize name }}-details.component.html',
11+
standalone: false
12+
})
13+
export class {{ classify name }}DetailsComponent implements OnInit {
14+
id!: number;
15+
data$ = this.store.select(select{{ classify name }}ById(this.id));
16+
17+
constructor(private route: ActivatedRoute, private store: Store) {}
18+
19+
ngOnInit() {
20+
this.id = +this.route.snapshot.params['id'];
21+
this.store.dispatch(load{{ classify name }}());
22+
}
23+
}

crud/files/__name@/component/__name@-edit/__name@-edit.component.html.template

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,35 @@
1-
// component/__name@-edit/__name@-edit.component.ts.template
1+
2+
import { Component, OnInit } from '@angular/core';
3+
import { FormBuilder, FormGroup } from '@angular/forms';
4+
import { ActivatedRoute } from '@angular/router';
5+
import { Store } from '@ngrx/store';
6+
import { update{{ classify name }}, load{{ classify name }} } from '../../store/actions/{{ dasherize name }}.actions';
7+
import { select{{ classify name }}ById } from '../../store/selectors/{{ dasherize name }}.selectors';
8+
9+
@Component({
10+
selector: 'app-{{ dasherize name }}-edit',
11+
templateUrl: './{{ dasherize name }}-edit.component.html',
12+
standalone: false
13+
})
14+
export class {{ classify name }}EditComponent implements OnInit {
15+
form!: FormGroup;
16+
id!: number;
17+
18+
constructor(private fb: FormBuilder, private route: ActivatedRoute, private store: Store) {}
19+
20+
ngOnInit() {
21+
this.id = +this.route.snapshot.params['id'];
22+
this.store.dispatch(load{{ classify name }}());
23+
this.store.select(select{{ classify name }}ById(this.id)).subscribe(data => {
24+
if (data) {
25+
this.form = this.fb.group({ {{~ modelFields.map(f => `${f.key}: [data.${f.key}]`).join(',\n') ~}} });
26+
}
27+
});
28+
}
29+
30+
submit() {
31+
if (this.form.valid) {
32+
this.store.dispatch(update{{ classify name }}({ id: this.id, data: this.form.value }));
33+
}
34+
}
35+
}
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
// component/__name@-list/__name@-list.component.html.template
1+
<ion-list *ngIf="items$ | async as items">
2+
<ion-item *ngFor="let item of items" [routerLink]="[item.id]">
3+
{{ '{{' }} item | json {{ '}}' }}
4+
</ion-item>
5+
</ion-list>
6+
<ion-button routerLink="add">Add New</ion-button>

crud/files/__name@/component/__name@-list/__name@-list.component.ts.template

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)