diff --git a/apps/angular/1-projection/src/app/component/city-card/city-card.component.ts b/apps/angular/1-projection/src/app/component/city-card/city-card.component.ts index 30c8f88ec..6eb308a1a 100644 --- a/apps/angular/1-projection/src/app/component/city-card/city-card.component.ts +++ b/apps/angular/1-projection/src/app/component/city-card/city-card.component.ts @@ -1,13 +1,56 @@ -import { Component, OnInit } from '@angular/core'; +import { Component, OnInit, ViewEncapsulation } from '@angular/core'; +import { CityStore } from '../../data-access/city.store'; +import { + FakeHttpService, + randomCity, +} from '../../data-access/fake-http.service'; +import { CardType } from '../../model/card.model'; +import { City } from '../../model/city.model'; +import { CardComponent } from '../../ui/card/card.component'; @Component({ selector: 'app-city-card', - template: 'TODO City', + template: ` + + + + `, + styles: [ + ` + .bg-light-yellow { + background-color: rgba(250, 250, 0, 0.5); + } + `, + ], standalone: true, - imports: [], + imports: [CardComponent], + encapsulation: ViewEncapsulation.None, }) export class CityCardComponent implements OnInit { - constructor() {} + cities: City[] = []; + cardType = CardType.CITY; - ngOnInit(): void {} + constructor( + private http: FakeHttpService, + private store: CityStore, + ) {} + + ngOnInit(): void { + this.http.fetchCities$.subscribe((s) => this.store.addAll(s)); + this.store.cities$.subscribe((s) => (this.cities = s)); + } + + public add() { + this.store.addOne(randomCity()); + } } diff --git a/apps/angular/1-projection/src/app/component/student-card/student-card.component.ts b/apps/angular/1-projection/src/app/component/student-card/student-card.component.ts index 441cda189..fa7c159aa 100644 --- a/apps/angular/1-projection/src/app/component/student-card/student-card.component.ts +++ b/apps/angular/1-projection/src/app/component/student-card/student-card.component.ts @@ -1,5 +1,8 @@ -import { Component, OnInit } from '@angular/core'; -import { FakeHttpService } from '../../data-access/fake-http.service'; +import { Component, OnInit, ViewEncapsulation } from '@angular/core'; +import { + FakeHttpService, + randStudent, +} from '../../data-access/fake-http.service'; import { StudentStore } from '../../data-access/student.store'; import { CardType } from '../../model/card.model'; import { Student } from '../../model/student.model'; @@ -11,16 +14,26 @@ import { CardComponent } from '../../ui/card/card.component'; + [image]="'assets/img/student.webp'" + [customClass]=" + 'flex w-fit flex-col gap-3 rounded-md border-2 border-black p-4 bg-light-blue' + "> + + `, standalone: true, styles: [ ` - ::ng-deep .bg-light-green { - background-color: rgba(0, 250, 0, 0.1); + .bg-light-blue { + background-color: rgba(0, 0, 250, 0.1); } `, ], + encapsulation: ViewEncapsulation.None, imports: [CardComponent], }) export class StudentCardComponent implements OnInit { @@ -37,4 +50,7 @@ export class StudentCardComponent implements OnInit { this.store.students$.subscribe((s) => (this.students = s)); } + public add() { + this.store.addOne(randStudent()); + } } diff --git a/apps/angular/1-projection/src/app/component/teacher-card/teacher-card.component.ts b/apps/angular/1-projection/src/app/component/teacher-card/teacher-card.component.ts index 995cb7c2f..1027e242a 100644 --- a/apps/angular/1-projection/src/app/component/teacher-card/teacher-card.component.ts +++ b/apps/angular/1-projection/src/app/component/teacher-card/teacher-card.component.ts @@ -1,5 +1,8 @@ -import { Component, OnInit } from '@angular/core'; -import { FakeHttpService } from '../../data-access/fake-http.service'; +import { Component, OnInit, ViewEncapsulation } from '@angular/core'; +import { + FakeHttpService, + randTeacher, +} from '../../data-access/fake-http.service'; import { TeacherStore } from '../../data-access/teacher.store'; import { CardType } from '../../model/card.model'; import { Teacher } from '../../model/teacher.model'; @@ -11,16 +14,26 @@ import { CardComponent } from '../../ui/card/card.component'; + [image]="'assets/img/teacher.png'" + [customClass]=" + 'flex w-fit flex-col gap-3 rounded-md border-2 border-black p-4 bg-light-red' + "> + + `, styles: [ ` - ::ng-deep .bg-light-red { + .bg-light-red { background-color: rgba(250, 0, 0, 0.1); } `, ], standalone: true, + encapsulation: ViewEncapsulation.None, imports: [CardComponent], }) export class TeacherCardComponent implements OnInit { @@ -37,4 +50,8 @@ export class TeacherCardComponent implements OnInit { this.store.teachers$.subscribe((t) => (this.teachers = t)); } + + public add() { + this.store.addOne(randTeacher()); + } } diff --git a/apps/angular/1-projection/src/app/data-access/fake-http.service.ts b/apps/angular/1-projection/src/app/data-access/fake-http.service.ts index 82a8f1813..df2ef2bbe 100644 --- a/apps/angular/1-projection/src/app/data-access/fake-http.service.ts +++ b/apps/angular/1-projection/src/app/data-access/fake-http.service.ts @@ -14,6 +14,7 @@ import { City } from '../model/city.model'; import { Student } from '../model/student.model'; import { Teacher, subject } from '../model/teacher.model'; +// Teacher const factoryTeacher = incrementalNumber(); export const randTeacher = () => ({ @@ -30,6 +31,7 @@ const teachers: Teacher[] = [ randTeacher(), ]; +// Student const factoryStudent = incrementalNumber(); export const randStudent = (): Student => ({ @@ -48,6 +50,7 @@ const students: Student[] = [ randStudent(), ]; +// City const factoryCity = incrementalNumber(); export const randomCity = (): City => ({ @@ -56,13 +59,13 @@ export const randomCity = (): City => ({ country: randCountry(), }); -const cities = [randomCity(), randomCity(), randomCity()]; +const cities: City[] = [randomCity(), randomCity(), randomCity()]; @Injectable({ providedIn: 'root', }) export class FakeHttpService { - fetchTeachers$ = timer(500).pipe(map(() => teachers)); - fetchStudents$ = timer(500).pipe(map(() => students)); - fetchCities$ = timer(500).pipe(map(() => cities)); + fetchTeachers$ = timer(100).pipe(map(() => teachers)); + fetchStudents$ = timer(100).pipe(map(() => students)); + fetchCities$ = timer(100).pipe(map(() => cities)); } diff --git a/apps/angular/1-projection/src/app/ui/card/card.component.ts b/apps/angular/1-projection/src/app/ui/card/card.component.ts index f06c9ae00..650f4ebf0 100644 --- a/apps/angular/1-projection/src/app/ui/card/card.component.ts +++ b/apps/angular/1-projection/src/app/ui/card/card.component.ts @@ -1,61 +1,30 @@ -import { NgFor, NgIf } from '@angular/common'; +import { NgFor } from '@angular/common'; import { Component, Input } from '@angular/core'; -import { randStudent, randTeacher } from '../../data-access/fake-http.service'; -import { StudentStore } from '../../data-access/student.store'; -import { TeacherStore } from '../../data-access/teacher.store'; import { CardType } from '../../model/card.model'; import { ListItemComponent } from '../list-item/list-item.component'; @Component({ selector: 'app-card', template: ` -
- - - +
+
- + @for (item of list; track item.id) { + + }
- - +
`, standalone: true, - imports: [NgIf, NgFor, ListItemComponent], + imports: [NgFor, ListItemComponent], }) export class CardComponent { @Input() list: any[] | null = null; @Input() type!: CardType; @Input() customClass = ''; - - CardType = CardType; - - constructor( - private teacherStore: TeacherStore, - private studentStore: StudentStore, - ) {} - - addNewItem() { - if (this.type === CardType.TEACHER) { - this.teacherStore.addOne(randTeacher()); - } else if (this.type === CardType.STUDENT) { - this.studentStore.addOne(randStudent()); - } - } + @Input() image = ''; } diff --git a/apps/angular/1-projection/src/app/ui/list-item/list-item.component.ts b/apps/angular/1-projection/src/app/ui/list-item/list-item.component.ts index c0f9cff7f..97643dd5c 100644 --- a/apps/angular/1-projection/src/app/ui/list-item/list-item.component.ts +++ b/apps/angular/1-projection/src/app/ui/list-item/list-item.component.ts @@ -1,4 +1,5 @@ import { Component, Input } from '@angular/core'; +import { CityStore } from '../../data-access/city.store'; import { StudentStore } from '../../data-access/student.store'; import { TeacherStore } from '../../data-access/teacher.store'; import { CardType } from '../../model/card.model'; @@ -9,7 +10,7 @@ import { CardType } from '../../model/card.model';
{{ name }}
`, @@ -23,6 +24,7 @@ export class ListItemComponent { constructor( private teacherStore: TeacherStore, private studentStore: StudentStore, + private cityStore: CityStore, ) {} delete(id: number) { @@ -30,6 +32,8 @@ export class ListItemComponent { this.teacherStore.deleteOne(id); } else if (this.type === CardType.STUDENT) { this.studentStore.deleteOne(id); + } else { + this.cityStore.deleteOne(id); } } }