clean up, satisfy tslint

This commit is contained in:
Evert Prants 2020-11-08 17:33:10 +02:00
parent 60b8264f44
commit 3e42d44e83
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
17 changed files with 61 additions and 4420 deletions

View File

@ -1,27 +1,28 @@
import { NgModule } from '@angular/core'; import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router'; import { RouterModule, Routes } from '@angular/router';
import { ListComponent } from './list/list.component' import { ArticleComponent } from './article/article.component';
import { ArticleComponent } from './article/article.component' import { ListComponent } from './list/list.component';
const routes: Routes = [ const routes: Routes = [
{ {
path: '', path: '',
pathMatch: 'full',
redirectTo: '/list', redirectTo: '/list',
pathMatch: 'full'
}, },
{ {
component: ListComponent,
path: 'list', path: 'list',
component: ListComponent
}, },
{ {
component: ArticleComponent,
path: 'article', path: 'article',
component: ArticleComponent },
}
]; ];
@NgModule({ @NgModule({
exports: [RouterModule],
imports: [RouterModule.forRoot(routes)], imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
}) })
export class AppRoutingModule { } export class AppRoutingModule { }

View File

@ -2,9 +2,9 @@ import { Component } from '@angular/core';
@Component({ @Component({
selector: 'app-root', selector: 'app-root',
styleUrls: ['./app.component.styl'],
templateUrl: './app.component.html', templateUrl: './app.component.html',
styleUrls: ['./app.component.styl']
}) })
export class AppComponent { export class AppComponent {
title = 'proovitoo'; public title = 'Proovitöö';
} }

View File

@ -1,18 +1,19 @@
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { HttpClientModule } from '@angular/common/http'; import { HttpClientModule } from '@angular/common/http';
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
import { AppRoutingModule } from './app-routing.module'; import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component'; import { AppComponent } from './app.component';
import { ArticleComponent } from './article/article.component'; import { ArticleComponent } from './article/article.component';
import { ListComponent } from './list/list.component'; import { CustomSortPipe } from './custom-sort.pipe';
import { GenderPipe } from './gender.pipe';
import { ListPaginateComponent } from './list-paginate/list-paginate.component'; import { ListPaginateComponent } from './list-paginate/list-paginate.component';
import { ListService } from './list.service'; import { ListService } from './list.service';
import { GenderPipe } from './gender.pipe'; import { ListComponent } from './list/list.component';
import { CustomSortPipe } from './custom-sort.pipe';
import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
@NgModule({ @NgModule({
bootstrap: [AppComponent],
declarations: [ declarations: [
AppComponent, AppComponent,
ArticleComponent, ArticleComponent,
@ -29,6 +30,5 @@ import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
], ],
providers: [ providers: [
], ],
bootstrap: [AppComponent]
}) })
export class AppModule { } export class AppModule { }

View File

@ -1,9 +1,9 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http'; import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs' import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root',
}) })
export class ArticleService { export class ArticleService {
private articleUrl = 'http://midaiganes.irw.ee/api/list/dad2ec5d'; private articleUrl = 'http://midaiganes.irw.ee/api/list/dad2ec5d';

View File

@ -6,15 +6,15 @@ import { IArticle } from '../article';
@Component({ @Component({
selector: 'app-article', selector: 'app-article',
styleUrls: ['./article.component.styl'],
templateUrl: './article.component.html', templateUrl: './article.component.html',
styleUrls: ['./article.component.styl']
}) })
export class ArticleComponent implements OnInit { export class ArticleComponent implements OnInit {
public article: IArticle; public article: IArticle;
constructor(private articleService: ArticleService) { } constructor(private articleService: ArticleService) { }
ngOnInit(): void { public ngOnInit(): void {
this.articleService.getArticle().subscribe((data) => this.article = data); this.articleService.getArticle().subscribe((data) => this.article = data);
} }

View File

@ -1,5 +1,5 @@
import { Pipe, PipeTransform } from '@angular/core'; import { Pipe, PipeTransform } from '@angular/core';
import { Sort } from './sort' import { Sort } from './sort';
const sorter = new Sort(); const sorter = new Sort();
@ -7,10 +7,10 @@ const sorter = new Sort();
// I couldn't come up with a better way of doing it at the moment. // I couldn't come up with a better way of doing it at the moment.
@Pipe({ @Pipe({
name: 'customSort' name: 'customSort',
}) })
export class CustomSortPipe implements PipeTransform { export class CustomSortPipe implements PipeTransform {
transform(value: Array<any>, field: string, direction: number): Array<any> { public transform(value: Array<any>, field: string, direction: number): Array<any> {
if (direction === 0 || field == null) { if (direction === 0 || field == null) {
return value; return value;
} }

View File

@ -3,10 +3,10 @@ import { Pipe, PipeTransform } from '@angular/core';
// This is a simple pipe for formatting the gender // This is a simple pipe for formatting the gender
@Pipe({ @Pipe({
name: 'gender' name: 'gender',
}) })
export class GenderPipe implements PipeTransform { export class GenderPipe implements PipeTransform {
transform(value: string): string { public transform(value: string): string {
return value === 'm' ? 'Mees' : 'Naine'; return value === 'm' ? 'Mees' : 'Naine';
} }
} }

View File

@ -3,7 +3,7 @@
margin: 20px 0 margin: 20px 0
font-family: Booster font-family: Booster
font-weight: 900 font-weight: 900
font-size: 16x font-size: 16px
display: block display: block
fa-icon, a fa-icon, a

View File

@ -6,15 +6,15 @@ import { faChevronLeft } from '@fortawesome/free-solid-svg-icons';
@Component({ @Component({
selector: 'app-list-paginate', selector: 'app-list-paginate',
styleUrls: ['./list-paginate.component.styl'],
templateUrl: './list-paginate.component.html', templateUrl: './list-paginate.component.html',
styleUrls: ['./list-paginate.component.styl']
}) })
export class ListPaginateComponent { export class ListPaginateComponent {
@Input() @Input()
page: number; public page: number;
@Input() @Input()
pages: number; public pages: number;
public faChevronRight = faChevronRight; public faChevronRight = faChevronRight;
public faChevronLeft = faChevronLeft; public faChevronLeft = faChevronLeft;

View File

@ -1,11 +1,11 @@
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http'; import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs' import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
// This is the service file for the API request // This is the service file for the API request
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root',
}) })
export class ListService { export class ListService {
private listUrl = 'http://midaiganes.irw.ee/api/list?limit=100'; private listUrl = 'http://midaiganes.irw.ee/api/list?limit=100';

View File

@ -31,8 +31,8 @@
</ng-container> </ng-container>
<ng-template #default_sort><fa-icon [icon]="faSort"></fa-icon></ng-template> <ng-template #default_sort><fa-icon [icon]="faSort"></fa-icon></ng-template>
</th> </th>
<th (click)="setSort('date')" class="clickable">Sünnikuupäev <th (click)="setSort('dob')" class="clickable">Sünnikuupäev
<ng-container *ngIf="sortBy === 'date';else default_sort"> <ng-container *ngIf="sortBy === 'dob';else default_sort">
<ng-container [ngSwitch]="sortDir"> <ng-container [ngSwitch]="sortDir">
<fa-icon *ngSwitchCase=-1 [icon]="faSortUp"></fa-icon> <fa-icon *ngSwitchCase=-1 [icon]="faSortUp"></fa-icon>
<fa-icon *ngSwitchCase=1 [icon]="faSortDown"></fa-icon> <fa-icon *ngSwitchCase=1 [icon]="faSortDown"></fa-icon>
@ -57,7 +57,7 @@
<td>{{ person.firstname }}</td> <td>{{ person.firstname }}</td>
<td>{{ person.surname }}</td> <td>{{ person.surname }}</td>
<td>{{ person.sex | gender }}</td> <td>{{ person.sex | gender }}</td>
<td>{{ person.date * 1000 | date:'yyyy.MM.dd'}}</td> <td>{{ person.dob }}</td>
<td>{{ person.phone }}</td> <td>{{ person.phone }}</td>
</tr> </tr>
<tr *ngIf="selected == person"> <tr *ngIf="selected == person">

View File

@ -1,9 +1,9 @@
import { Component, OnInit, SimpleChanges, Input } from '@angular/core'; import { Component, Input, OnInit, SimpleChanges } from '@angular/core';
import { ListService } from '../list.service' import { ListService } from '../list.service';
import { ActivatedRoute } from '@angular/router'; import { ActivatedRoute } from '@angular/router';
import { IPerson } from '../person' import { IPerson, personalCodeStamper } from '../person';
import { faSort } from '@fortawesome/free-solid-svg-icons'; import { faSort } from '@fortawesome/free-solid-svg-icons';
import { faSortUp } from '@fortawesome/free-solid-svg-icons'; import { faSortUp } from '@fortawesome/free-solid-svg-icons';
@ -13,8 +13,8 @@ import { faSortDown } from '@fortawesome/free-solid-svg-icons';
@Component({ @Component({
selector: 'app-list', selector: 'app-list',
styleUrls: ['./list.component.styl'],
templateUrl: './list.component.html', templateUrl: './list.component.html',
styleUrls: ['./list.component.styl']
}) })
export class ListComponent implements OnInit { export class ListComponent implements OnInit {
public people: IPerson[]; public people: IPerson[];
@ -33,7 +33,7 @@ export class ListComponent implements OnInit {
constructor(private route: ActivatedRoute, private listService: ListService) { } constructor(private route: ActivatedRoute, private listService: ListService) { }
ngOnInit(): void { public ngOnInit(): void {
this.route.queryParams this.route.queryParams
.subscribe((params) => { .subscribe((params) => {
this.page = +(params.page || 1); this.page = +(params.page || 1);
@ -74,7 +74,11 @@ export class ListComponent implements OnInit {
private getList(): void { private getList(): void {
this.listService.getList().subscribe( this.listService.getList().subscribe(
(data) => this.people = data.list); (data) => {
this.people = data.list;
// Calculate date of birth from personal codes.
this.people.forEach((p) => p.dob = personalCodeStamper(p.personal_code));
});
} }
private selectPerson(person: IPerson): void { private selectPerson(person: IPerson): void {

View File

@ -3,8 +3,18 @@ export interface IPerson {
firstname: string; firstname: string;
surname: string; surname: string;
sex: string; sex: string;
date: Date; personal_code: number;
dob: string;
phone: string; phone: string;
image: string[]; image: string[];
intro: string; intro: string;
} }
export function personalCodeStamper(personalCode: number): string {
const code = personalCode.toString();
const gender = code.substring(0, 1);
const year = (parseInt(gender, 10) < 5 ? '19' : '20') + code.substring(1, 3);
const month = code.substring(3, 5);
const day = code.substring(5, 7);
return `${year}.${month}.${day}`;
}

View File

@ -2,7 +2,7 @@
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<title>Proovitoo</title> <title>Proovitöö</title>
<base href="/"> <base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico"> <link rel="icon" type="image/x-icon" href="favicon.ico">

View File

@ -9,4 +9,4 @@ if (environment.production) {
} }
platformBrowserDynamic().bootstrapModule(AppModule) platformBrowserDynamic().bootstrapModule(AppModule)
.catch(err => console.error(err)); .catch((err) => console.error(err));

View File

@ -57,7 +57,6 @@
*/ */
import 'zone.js/dist/zone'; // Included with Angular CLI. import 'zone.js/dist/zone'; // Included with Angular CLI.
/*************************************************************************************************** /***************************************************************************************************
* APPLICATION IMPORTS * APPLICATION IMPORTS
*/ */

4373
test.json

File diff suppressed because one or more lines are too long