Skip to content

Commit

Permalink
[ADD] Added some value
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikhil-Pahwa committed Dec 19, 2017
1 parent 0eeb301 commit 2e06a37
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ <h2>{{ 'PICK_YOUR_DESTINATION' | translate:lang }}</h2>
</div>
</div>
<!-- banner END-->
<app-flight-filter *ngIf="flightsList" [flights]=flightsList></app-flight-filter>
<app-flight-filter *ngIf="filteredList" [flights]=filteredList (selectionChanged)="filterSearch($event)"></app-flight-filter>
<!-- Flight Listing -->
<section class="col">
<div class="flight-listing-container">
<ul class="results-list">
<li class="offer-listing" *ngFor="let flight of flightsList">
<li class="offer-listing" *ngFor="let flight of filteredList">
<div class="flex-content">
<div class="flex-area-primary">
<div class="flex-card flex-listing">
Expand Down
15 changes: 14 additions & 1 deletion src/app/modules/flights/flight-search/flight-search.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Component, OnInit } from '@angular/core';
import { Language } from 'angular-l10n';

import { FlightService } from '../';
import { Flight } from '../../../shared/resources/';
import { Flight, Filter } from '../../../shared/resources/';
import { HeaderService } from '../../../shared/components/';

declare let jQuery: any;
Expand All @@ -18,6 +18,7 @@ export class FlightSearchComponent implements OnInit {
@Language() lang;

public flightsList: Flight[];
public filteredList: Flight[];

constructor(private flightService: FlightService, private headerService: HeaderService) { }

Expand All @@ -30,7 +31,19 @@ export class FlightSearchComponent implements OnInit {
this.flightService.getFlightResults()
.subscribe((data: Flight[]) => {
this.flightsList = data;
this.filteredList = data;
});
}

filterSearch(filters: Filter[]) {
this.filteredList = [];
filters.forEach((filter: Filter) => {
let items = this.flightsList.filter(function (flight) {
console.log(flight);
return (filter.selected && (flight.carrierId === filter.id));
});
console.log(items);
this.filteredList = this.filteredList.concat(items);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<span>Airlines included</span>
</legend>
<label class="check filter-option" *ngFor="let filter of flightFilter">
<input type="checkbox">
<input type="checkbox" [ngModel]="filter.selected" (click)="filter.selected = !filter.selected; filterChanged()">
<span class="inline-label">{{filter.name}}
<span class="count" *ngIf="filter.count">({{filter.count}})</span>
</span>
Expand Down
29 changes: 8 additions & 21 deletions src/app/shared/components/flight-filter/flight-filter.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, OnInit, Input, OnChanges } from '@angular/core';
import { Component, OnInit, Input, OnChanges, EventEmitter, Output } from '@angular/core';
import { Flight, Carriers, Filter } from '../../resources';

@Component({
Expand All @@ -9,13 +9,12 @@ import { Flight, Carriers, Filter } from '../../resources';
export class FlightFilterComponent implements OnInit, OnChanges {

@Input() flights: Flight[];
@Output() selectionChanged: EventEmitter<Filter[]> = new EventEmitter<Filter[]>();

public flightFilter: Filter[] = [];
constructor() { }

ngOnInit() {
console.log(this.flights);
// this.flightFilter.push(new Filter('Air India', 'AI', 21));
// this.flightFilter.push(new Filter('Jet Airways', 'JA', 10));
}

ngOnChanges() {
Expand All @@ -24,28 +23,16 @@ export class FlightFilterComponent implements OnInit, OnChanges {

filterAirways() {
this.flights.forEach((flight) => {
let obj = {};

// if (this.flightFilter[0].id === flight.carrierId) {
// this.flightFilter.push(new Filter(flight.airline, flight.carrierId, null));
// }

let dd = this.flightFilter.filter((ff) => {
return ff.id === flight.carrierId;
});

if (!dd.length) {
this.flightFilter.push(new Filter(flight.airline, flight.carrierId, null));
this.flightFilter.push(new Filter(flight.airline, flight.carrierId, null, true));
}

// let airlines = new Map<string, any>();
// switch (cd) {
// case 'AI': airlines.set(Carriers.AI.count, (airlines.get(Carriers.AI.count))++);
// break;
// case 'JA': airlines.set(Carriers.JA, airlines.get(Carriers.JA)++);
// break;
// default: break;
// }
});
}

filterChanged() {
this.selectionChanged.emit(this.flightFilter);
}
}
3 changes: 2 additions & 1 deletion src/app/shared/resources/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export class Filter {
constructor(
public name: string,
public id: string,
public count: number
public count: number,
public selected: boolean
) { }
}
3 changes: 2 additions & 1 deletion src/app/shared/shared.module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { TranslationModule, LocaleService, TranslationService, LocalizationModule } from 'angular-l10n';
import { HeaderComponent } from './components/';
import { PaymentModeComponent } from './components/payment-mode/payment-mode.component';
Expand All @@ -10,7 +11,7 @@ import { FlightFilterComponent } from './components/flight-filter/flight-filter.
exports: [HeaderComponent, FlightFilterComponent],
imports: [
BrowserModule,

FormsModule,
// Translation
TranslationModule.forRoot(),
LocalizationModule.forRoot()
Expand Down

0 comments on commit 2e06a37

Please sign in to comment.