Skip to content

Commit 30aa859

Browse files
authored
feat: ng template updated list with computer scientists (#241)
1 parent 8cc9a90 commit 30aa859

File tree

11 files changed

+117
-91
lines changed

11 files changed

+117
-91
lines changed
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { Routes } from '@angular/router';
2-
import { ItemsComponent } from './item/items.component';
3-
import { ItemDetailComponent } from './item/item-detail.component';
2+
import { PeopleComponent } from './people/person.component';
3+
import { PersonDetailComponent } from './people/person-detail.component';
44

55
export const routes: Routes = [
66
{ path: '', redirectTo: '/items', pathMatch: 'full' },
7-
{ path: 'items', component: ItemsComponent },
8-
{ path: 'item/:id', component: ItemDetailComponent },
7+
{ path: 'items', component: PeopleComponent },
8+
{ path: 'item/:id', component: PersonDetailComponent },
99
];

packages/template-hello-world-ng/src/app/item/item-detail.component.html

Lines changed: 0 additions & 9 deletions
This file was deleted.

packages/template-hello-world-ng/src/app/item/item-detail.component.ts

Lines changed: 0 additions & 25 deletions
This file was deleted.

packages/template-hello-world-ng/src/app/item/item.service.ts

Lines changed: 0 additions & 37 deletions
This file was deleted.

packages/template-hello-world-ng/src/app/item/item.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

packages/template-hello-world-ng/src/app/item/items.component.html renamed to packages/template-hello-world-ng/src/app/people/people.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
<ActionBar title="My App"> </ActionBar>
1+
<ActionBar title="Computer Scientists"> </ActionBar>
22

33
<GridLayout>
4-
<ListView [items]="itemService.items()">
4+
<ListView [items]="personService.items()">
55
<ng-template let-item="item">
66
<StackLayout [nsRouterLink]="['/item', item.id]">
77
<Label [text]="item.name" class="text-lg text-gray-500 p-4"></Label>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<ActionBar title="Details">
2+
@if (isAndroid) {
3+
<StackLayout orientation="horizontal" horizontalAlignment="left">
4+
<Label text="< Back" color="#1976d2" (tap)="goBack()" style="font-size: 18; margin-left: 4"></Label>
5+
<Label text="Details" color="#333" style="font-size: 20; font-weight:600; margin-left: 30"></Label>
6+
</StackLayout>
7+
}
8+
</ActionBar>
9+
10+
<FlexboxLayout flexDirection="column">
11+
<FlexboxLayout class="m-4">
12+
<Label class="text-3xl text-gray-400" [text]="person()?.id + '. '"></Label>
13+
<Label class="text-3xl" [text]="person()?.name"></Label>
14+
</FlexboxLayout>
15+
16+
<StackLayout class="text-xl m-2 ml-6">
17+
<Label class="mb-2" fontWeight="700" text="Nationality:"></Label>
18+
<Label textWrap="true" [text]="person()?.nationality"></Label>
19+
</StackLayout>
20+
21+
<StackLayout class="text-xl m-2">
22+
<Label class="m-2 ml-4" fontWeight="700" text="Notable Achievements:"></Label>
23+
<Label
24+
class="text-xl m-2 ml-4"
25+
[text]="formatAchievements(person()?.notableAchievements)"
26+
textWrap="true">
27+
</Label>
28+
</StackLayout>
29+
</FlexboxLayout>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { ChangeDetectionStrategy, Component, NO_ERRORS_SCHEMA, OnInit, inject, signal } from '@angular/core';
2+
import { ActivatedRoute } from '@angular/router';
3+
import { NativeScriptCommonModule, RouterExtensions } from '@nativescript/angular';
4+
import { Person } from './person';
5+
import { PersonService } from './person.service';
6+
7+
@Component({
8+
selector: 'ns-person-detail',
9+
templateUrl: './person-detail.component.html',
10+
imports: [NativeScriptCommonModule],
11+
schemas: [NO_ERRORS_SCHEMA],
12+
changeDetection: ChangeDetectionStrategy.OnPush
13+
})
14+
export class PersonDetailComponent implements OnInit {
15+
personService = inject(PersonService);
16+
routerExtensions = inject(RouterExtensions);
17+
route = inject(ActivatedRoute);
18+
person = signal<Person>(null);
19+
isAndroid = __ANDROID__;
20+
21+
ngOnInit(): void {
22+
const id = +this.route.snapshot.params.id;
23+
this.person.set(this.personService.getPerson(id));
24+
25+
// log the person to the console
26+
console.log(this.person());
27+
}
28+
29+
30+
goBack() {
31+
this.routerExtensions.back();
32+
}
33+
34+
formatAchievements(achievements: string[] | undefined | null): string {
35+
if (!achievements || !Array.isArray(achievements)) return '';
36+
return achievements.map( (a, index) => (index + 1) + '. ' + a.trim()).join('\n');
37+
}
38+
39+
}

packages/template-hello-world-ng/src/app/item/items.component.ts renamed to packages/template-hello-world-ng/src/app/people/person.component.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
1-
import { Component, NO_ERRORS_SCHEMA, inject } from '@angular/core'
1+
import { ChangeDetectionStrategy, Component, NO_ERRORS_SCHEMA, inject } from '@angular/core'
22
import { NativeScriptCommonModule, NativeScriptRouterModule } from '@nativescript/angular'
33
import { Page } from '@nativescript/core'
4-
import { ItemService } from './item.service'
4+
import { PersonService } from './person.service'
55

66
@Component({
7-
selector: 'ns-items',
8-
templateUrl: './items.component.html',
7+
selector: 'ns-people',
8+
templateUrl: './people.component.html',
99
imports: [NativeScriptCommonModule, NativeScriptRouterModule],
1010
schemas: [NO_ERRORS_SCHEMA],
11+
changeDetection: ChangeDetectionStrategy.OnPush
1112
})
12-
export class ItemsComponent {
13-
itemService = inject(ItemService)
14-
page = inject(Page)
13+
export class PeopleComponent {
14+
personService = inject(PersonService);
15+
page = inject(Page);
1516

1617
constructor() {
1718
// Setup large titles on iOS
1819
this.page.on('loaded', (args) => {
1920
if (__IOS__) {
20-
const navigationController: UINavigationController = this.page.frame.ios.controller
21-
navigationController.navigationBar.prefersLargeTitles = true
21+
const navigationController: UINavigationController = this.page.frame.ios.controller;
22+
navigationController.navigationBar.prefersLargeTitles = true;
2223
}
2324
})
2425
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { Injectable, signal } from '@angular/core';
2+
import { Person } from './person';
3+
4+
@Injectable({providedIn: 'root'})
5+
export class PersonService {
6+
items = signal<Person[]>([
7+
{ id: 1, name: 'Alan Turing', nationality: 'British', notableAchievements: ['WW2 code breaking', 'Father of theoretical computer science and AI' ] },
8+
{ id: 2, name: 'Grace Hopper', nationality: 'American', notableAchievements: ['COBOL development', 'Navy commander', 'Implementation of computer systems and components testing'] },
9+
{ id: 3, name: 'Donal Knuth', nationality: 'American', notableAchievements: [ 'Author of The Art of Computer Programming', 'Created TeX typesetting system' ] },
10+
{ id: 4, name: 'Ada Lovelace', nationality: 'British', notableAchievements: [ 'First computer programmer', 'Worked on Analytical Engine' ]},
11+
{ id: 5, name: 'John von Neumann', nationality: 'Hungarian/American', notableAchievements: [ 'Von Neumann architecture', 'Game theory', 'Contributed to EDVAC' ] },
12+
{ id: 6, name: 'Tim Berners-Lee', nationality: 'British', notableAchievements: [ 'Inventor of the World Wide Web' ] },
13+
{ id: 7, name: 'Edsger Dijkstra', nationality: 'Dutch', notableAchievements: [ 'Shortest path algorithm', 'Structured programming advocate' ] },
14+
{ id: 8, name: 'Linus Torvalds', nationality: 'Finnish-American', notableAchievements: ['Creator of Linux kernel', 'Creator of Git'] },
15+
{ id: 9, name: 'John McCarthy', nationality: 'American', notableAchievements: ['Coined term "Artificial Intelligence"', 'Created LISP programming language'] },
16+
{ id: 10, name: 'Dennis Ritchie', nationality: 'American', notableAchievements: ['Creator of C programming language', 'Co-creator of Unix'] },
17+
{ id: 11, name: 'Bjarne Stroustrup', nationality: 'Danish', notableAchievements: [ 'Creator of C++ programming language' ] },
18+
{ id: 12, name: 'Steve Wozniak', nationality: 'American', notableAchievements: ['Co-founder of Apple', 'Designer of Apple I & II', 'Pioneer of personal computing'] },
19+
{ id: 13, name: 'Tommy Flowers', nationality: 'British', notableAchievements: ['Designer of Colossus', 'Pioneer in electronic computing'] },
20+
{ id: 14, name: 'John Backus', nationality: 'American', notableAchievements: ['Created FORTRAN', 'Developed Backus-Naur form(BNF) notation'] },
21+
{ id: 15, name: 'Niklaus Wirth', nationality: 'Swiss', notableAchievements: ['Creator of Pascal, Modula, Oberon languages', 'Software engineering pioneer'] },
22+
]);
23+
24+
getPerson(id: number): Person {
25+
return this.items().find((person) => person.id === id);
26+
}
27+
}

0 commit comments

Comments
 (0)