Skip to content

Commit

Permalink
Feat(#23) Anomaly list page is now functional
Browse files Browse the repository at this point in the history
  • Loading branch information
iamkinetic committed May 14, 2018
1 parent a6b8e33 commit 9db5b37
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 19 deletions.
1 change: 1 addition & 0 deletions src/models/inspection-building-anomaly-for-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export class InspectionBuildingAnomalyForList {
theme: string;
notes: string;
}

6 changes: 6 additions & 0 deletions src/models/inspection-building-anomaly-theme-for-list.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import {InspectionBuildingAnomalyForList} from './inspection-building-anomaly-for-list';

export class InspectionBuildingAnomalyThemeForList {
name: string;
anomalies: InspectionBuildingAnomalyForList[];
}
33 changes: 26 additions & 7 deletions src/pages/building-anomalies/building-anomalies.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
<!--
Generated template for the BuildingAnomaliesPage page.
See http://ionicframework.com/docs/components/#navigation for more info on
Ionic pages and navigation.
-->
<ion-header>
<ion-navbar>
<ion-icon name="menu" menuToggle left></ion-icon>
Expand All @@ -14,6 +8,31 @@
</ion-header>


<ion-content padding>
<ion-content>
<ion-list>
<ion-item-group *ngFor="let theme of themes">

<ion-list-header color="light">
{{theme.theme}}
<button ion-button item-end (click)="onAddAnomalyForTheme(theme.theme)">Ajouter</button>
</ion-list-header>

<button ion-item *ngFor="let anomaly of theme.anomalies" (click)="onItemClick(anomaly.id)">
{{anomaly.notes}}
</button>

</ion-item-group>
</ion-list>
</ion-content>


<ion-footer>
<ion-toolbar>
<ion-buttons>
<button ion-button icon-start full type="button" (click)="onAddNewAnomaly()">
<ion-icon name="add-circle"></ion-icon>
Ajouter une anomalie...
</button>
</ion-buttons>
</ion-toolbar>
</ion-footer>
76 changes: 66 additions & 10 deletions src/pages/building-anomalies/building-anomalies.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';

/**
* Generated class for the BuildingAnomaliesPage page.
*
* See https://ionicframework.com/docs/components/#navigation for more info on
* Ionic pages and navigation.
*/
import {IonicPage, LoadingController, ModalController, NavController, NavParams} from 'ionic-angular';
import {InspectionBuildingAnomalyThemeForList} from '../../models/inspection-building-anomaly-theme-for-list';
import {AuthenticationService} from '../../providers/Base/authentification.service';
import {InspectionBuildingAnomalyRepositoryProvider} from '../../providers/repositories/inspection-building-anomaly-repository-provider.service';

@IonicPage()
@Component({
Expand All @@ -15,11 +11,71 @@ import { IonicPage, NavController, NavParams } from 'ionic-angular';
})
export class BuildingAnomaliesPage {

constructor(public navCtrl: NavController, public navParams: NavParams) {
private readonly idBuilding: string;
private readonly name: string;

public themes: InspectionBuildingAnomalyThemeForList[] = [];

constructor(
private load: LoadingController,
private anomalyRepo: InspectionBuildingAnomalyRepositoryProvider,
private authService: AuthenticationService,
private modalCtrl: ModalController,
public navCtrl: NavController,
public navParams: NavParams) {

this.idBuilding = navParams.get('idBuilding');
this.name = navParams.get('name');
}

ionViewDidLoad() {
console.log('ionViewDidLoad BuildingAnomaliesPage');
}

async ionViewDidEnter() {
await this.loadAnomalies();
}

async ionViewCanEnter() {
let isLoggedIn = await this.authService.isStillLoggedIn();
if (!isLoggedIn)
this.redirectToLoginPage();
}

private redirectToLoginPage(): void{
this.navCtrl.setRoot('LoginPage');
}

private async loadAnomalies() {
let loader = this.load.create({content: 'Patientez...'});
const result = await this.anomalyRepo.getList(this.idBuilding);
this.themes = result;
await loader.dismiss();
}

public onItemClick(idBuildingAnomaly: string): void {
this.openAnomalyPage(idBuildingAnomaly);
}

public onAddAnomalyForTheme(theme: string){
this.openAnomalyPage(null, theme);
}

public onAddNewAnomaly(){
this.selectThemeThenCreateAnomaly();
}

private selectThemeThenCreateAnomaly() {
let matModal = this.modalCtrl.create('AnomalyThemeSelectionPage');
matModal.onDidDismiss(data => {
if (data.hasSelected)
this.openAnomalyPage(null, data.themeSelected);
});
matModal.present();
}

private openAnomalyPage(idBuildingAnomaly: string, theme: string = ""){
let modal = this.modalCtrl.create('BuildingAnomalyDetailPage', { idBuildingAnomaly: idBuildingAnomaly, theme: theme, idBuilding: this.idBuilding });
modal.onDidDismiss(() => this.loadAnomalies());
modal.present();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import {HttpService} from '../Base/http.service';
import {
InspectionBuildingAnomaly} from '../../models/inspection-building-anomaly';
import {map} from 'rxjs/operators';
import {InspectionBuildingAnomalyForList} from '../../models/inspection-building-anomaly-for-list';
import {InspectionBuildingAnomalyThemeForList} from '../../models/inspection-building-anomaly-theme-for-list';

@Injectable()
export class InspectionBuildingAnomalyRepositoryProvider {

constructor(public http: HttpService) {
}

public getList(idBuilding: string): Promise<InspectionBuildingAnomalyForList[]> {
public getList(idBuilding: string): Promise<InspectionBuildingAnomalyThemeForList[]> {
return this.http.get('inspection/building/' + idBuilding + '/anomaly')
.pipe(map(response => response))
.toPromise();
Expand Down

0 comments on commit 9db5b37

Please sign in to comment.