68 lines
2.3 KiB
TypeScript
68 lines
2.3 KiB
TypeScript
|
|
import {controller, directive} from '../../infrastructure/Dectorators/Components';
|
|
import {FlightService, IFlightDetail, IFlightListRequest, IFlightService} from '../../core/service/flightService';
|
|
import {IFlightInformationService} from '../../flight-detail/services/flightInformationService';
|
|
import {Mod} from '../flight-list.mod';
|
|
|
|
export interface FlightListParams extends ng.ui.IStateParamsService {
|
|
filter: string;
|
|
}
|
|
|
|
@controller(Mod, 'flightListController', ['flightService', '$stateParams', '$state', '$window', 'flightInformationService'])
|
|
export class Controller {
|
|
|
|
public static NO_FLIGHTS_MESSAGE = 'This window has no flights';
|
|
|
|
public flights: Array<IFlightDetail>;
|
|
public request: IFlightListRequest;
|
|
public loading: boolean = true;
|
|
public window: string;
|
|
public message: string;
|
|
|
|
constructor(private flightService: IFlightService,
|
|
private $stateParams: FlightListParams,
|
|
private $state: ng.ui.IStateService,
|
|
private $window: ng.IWindowService,
|
|
public flightInformationService: IFlightInformationService) {
|
|
this.window = this.$stateParams.filter;
|
|
this.$window.sessionStorage.setItem('chroma:current-filter', this.window);
|
|
this.load();
|
|
}
|
|
public load(initial: boolean = true): void {
|
|
if (!initial) {
|
|
this.loading = true;
|
|
}
|
|
|
|
this.flightService.getFilter(this.window, !initial)
|
|
.then((r) => this.onFilterLoad(r));
|
|
}
|
|
private onFilterLoad(request: any): void {
|
|
this.request = request;
|
|
|
|
this.flights = request.Flights;
|
|
|
|
if (!this.flights || this.flights.length === 0) {
|
|
this.message = Controller.NO_FLIGHTS_MESSAGE;
|
|
}
|
|
|
|
this.loading = false;
|
|
}
|
|
public showDetail(flight: IFlightDetail): void {
|
|
this.$state.go('chroma.flight-detail', {
|
|
id: flight.Id,
|
|
flight: flight,
|
|
requestId: this.request.RequestId
|
|
});
|
|
}
|
|
}
|
|
|
|
@directive(Mod, 'chromaFlightList', ['$stateParams'])
|
|
export class Directive implements ng.IDirective {
|
|
controller: string = Controller.$componentName;
|
|
controllerAs: string = 'vm';
|
|
templateUrl: string = 'app/flight-list/list/flight-list.tpl.html';
|
|
restrict: string = 'E';
|
|
replace: boolean = false;
|
|
scope: any = true;
|
|
}
|