Commit ff845a4c authored by Vitali Stupin's avatar Vitali Stupin
Browse files

Bugfixes, cleanups

parent 2b12f3d5
......@@ -4,8 +4,7 @@ import { SubsystemListComponent } from './subsystem-list/subsystem-list.componen
import { SubsystemComponent } from './subsystem/subsystem.component';
const routes: Routes = [
{ path: '', redirectTo: '/list', pathMatch: 'full' },
{ path: 'list', component: SubsystemListComponent },
{ path: '', component: SubsystemListComponent },
{ path: 'subsystem/:id', component: SubsystemComponent },
];
......
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpClientModule } from '@angular/common/http';
import { AppComponent } from './app.component';
......
......@@ -13,11 +13,12 @@ export class MessageComponent implements OnInit {
constructor(private methodsService: MethodsService) { }
ngOnInit() {
this.message = this.methodsService.getMessage();
// Service will tell when updated data is available!
this.methodsService.newMessage.subscribe(signal => {
this.message = signal;
});
// This line must be after subscription (data may be changed while we start subscription)
this.message = this.methodsService.getMessage();
}
}
......@@ -46,10 +46,7 @@ export class MethodsService {
private filteredSubsystems(): Subsystem[] {
let filtered: Subsystem[] = []
let limit: number = this.limit
for (let x of this.subsystems) {
// Copy object to avoid overwriting methods array
// TODO: Is there a better way???
let subsystem = Object.assign(Object.create(x), x);
for (let subsystem of this.subsystems) {
if (this.nonEmpty && !subsystem.methods.length) {
// Filtering out empty subsystems
continue
......@@ -76,6 +73,9 @@ export class MethodsService {
continue
}
// Copy object to avoid overwriting methods array in subsystem object
// TODO: Is there a better way???
subsystem = Object.assign(Object.create(subsystem), subsystem);
// Leaving only matcing methods
subsystem.methods = filteredMethods
}
......@@ -104,6 +104,22 @@ export class MethodsService {
}
}
/**
* Handle Http operation that failed.
* Let the app continue.
* @param operation - name of the operation that failed
* @param result - optional value to return as the observable result
*/
private handleError<T> (operation = 'operation', result?: T) {
return (error: any): Observable<T> => {
this.lastMessage = 'Error loading data!'
this.newMessage.emit(this.lastMessage);
// Let the app keep running by returning an empty result.
return of(result as T);
};
}
getApiUrlBase(): string {
return this.apiUrlBase
}
......@@ -166,33 +182,7 @@ export class MethodsService {
})
}
getHideDetails(): boolean {
if (this.filter == '') {
return true
} else {
return false
}
}
getMessage(): string {
return this.lastMessage
}
/**
* Handle Http operation that failed.
* Let the app continue.
* @param operation - name of the operation that failed
* @param result - optional value to return as the observable result
*/
private handleError<T> (operation = 'operation', result?: T) {
return (error: any): Observable<T> => {
//console.error(error); // log to console for debuging
this.lastMessage = 'Error loading data!'
this.newMessage.emit(this.lastMessage);
// Let the app keep running by returning an empty result.
return of(result as T);
};
}
}
......@@ -4,13 +4,13 @@
</div>
<div class="card-body">
<div class="form-group form-check">
<input type="checkbox" class="form-check-input" id="exampleCheck1"
<input type="checkbox" class="form-check-input" id="nonEmptyCheck"
[(ngModel)]="nonEmpty" (change)="setNonEmpty(nonEmpty)">
<label class="form-check-label" for="exampleCheck1">Show only producer subsystems</label>
<label class="form-check-label" for="nonEmptyCheck">Show only producer subsystems</label>
</div>
<div class="form-group">
<label for="exampleFormControlSelect1">Amount of subsystems to display</label>
<select class="form-control" id="exampleFormControlSelect1"
<label for="limitSelect">Amount of subsystems to display</label>
<select class="form-control" id="limitSelect"
[(ngModel)]="limit" (change)="setLimit(limit)">
<option>10</option>
<option>20</option>
......@@ -19,8 +19,8 @@
</select>
</div>
<div class="form-group">
<label for="exampleFormControlInput1">Filter by method name</label>
<input type="text" class="form-control" id="exampleFormControlInput1"
<label for="filterInput">Filter by method name</label>
<input type="text" class="form-control" id="filterInput"
[(ngModel)]="filter" (ngModelChange)="setFilter(filter)">
</div>
</div>
......
......@@ -13,11 +13,13 @@ export class SubsystemListComponent implements OnInit {
constructor(private methodsService: MethodsService) { }
ngOnInit() {
this.getMethods();
// Service will tell when updated data is available!
this.methodsService.subsystemsUpdated.subscribe(signal => {
this.getMethods();
});
// If json data is loaded update event will not be emited.
// This line must be after subscription (data may be changed while we start subscription)
this.getMethods();
}
getMethods(): void {
......
......@@ -4,6 +4,8 @@
<app-message></app-message>
<button type="button" class="btn btn-secondary" (click)="goToList()">Show all subsystems</button>
<div *ngIf="loadingDone() && subsystem">
<div class="card">
<div class="card-header">
......@@ -34,5 +36,3 @@
Subsystem "{{subsystemId}}" cannot be found!
</p>
</div>
<button type="button" class="btn btn-secondary" (click)="goToList()">Show all subsystems</button>
\ No newline at end of file
......@@ -2,7 +2,6 @@ import { Component, OnInit } from '@angular/core';
import { MethodsService } from '../methods.service';
import { Subsystem } from '../subsystem';
import { ActivatedRoute, Router } from '@angular/router';
//import { Location } from '@angular/common';
@Component({
selector: 'app-subsystem',
......@@ -17,7 +16,6 @@ export class SubsystemComponent implements OnInit {
private methodsService: MethodsService,
private route: ActivatedRoute,
private router: Router
//private location: Location
) { }
ngOnInit() {
......@@ -30,14 +28,13 @@ export class SubsystemComponent implements OnInit {
getSubsystem() {
this.subsystemId = this.route.snapshot.paramMap.get('id')
// Show data if already available
this.subsystem = this.methodsService.getSubsystem(this.subsystemId)
//console.log(this.subsystem)
// Service will tell when data has finished loading
this.methodsService.subsystemsUpdated.subscribe(signal => {
this.subsystem = this.methodsService.getSubsystem(this.subsystemId)
//console.log(this.subsystem)
});
// If json data is loaded update event will not be emited.
// This line must be after subscription (data may be changed while we start subscription)
this.subsystem = this.methodsService.getSubsystem(this.subsystemId)
}
getApiUrlBase(): string {
......@@ -45,7 +42,6 @@ export class SubsystemComponent implements OnInit {
}
goToList(): void {
//this.location.back();
this.router.navigateByUrl('/list')
this.router.navigateByUrl('/')
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment