Commit d4b3f299 authored by mdsecurity's avatar mdsecurity
Browse files

checking special schedules now

parent 4b5b83c9
......@@ -6,6 +6,7 @@ import { Subject } from 'rxjs/Subject';
import { Place } from './place';
import { Day } from './day';
import { Time } from './time';
import { SpecialSchedule } from './special-schedule';
// Operators
import 'rxjs/add/observable/throw';
import 'rxjs/add/operator/catch';
......@@ -26,31 +27,31 @@ export class DataProviderService {
constructor(private http: Http) { }
getFacilities(): Observable<Place[]> {
console.log("I was called");
if (this.places) {
return Observable.of(this.places);
} else if (this.placesObs) {
return this.placesObs;
} else {
const facilities = localStorage.getItem('facilities');
if (facilities) {
this.places = this.extractData(JSON.parse(facilities));
this.placesObs = Observable.of(this.places);
return this.placesObs;
} else {
this.placesObs = this.http.get(this.Url)
.map((data) => {
this.placesObs = null;
data = data.json();
this.places = this.extractData(data);
this.contextPlace = this.places[0];
localStorage.setItem('facilities', JSON.stringify(data));
return this.places;
})
.catch(this.handleError).share();
return this.placesObs;
}
}
// if (this.places) {
// return Observable.of(this.places);
// } else if (this.placesObs) {
// return this.placesObs;
// } else {
// const facilities = localStorage.getItem('facilities');
// if (facilities) {
// this.places = this.extractData(JSON.parse(facilities));
// this.placesObs = Observable.of(this.places);
// return this.placesObs;
// } else {
this.placesObs = this.http.get(this.Url)
.map((data) => {
this.placesObs = null;
data = data.json();
this.places = this.extractData(data);
this.contextPlace = this.places[0];
localStorage.setItem('facilities', JSON.stringify(data));
return this.places;
})
.catch(this.handleError).share();
return this.placesObs;
// }
// }
}
getContext(): Observable<Place> {
return this.contextSubj.asObservable();
......@@ -70,8 +71,8 @@ export class DataProviderService {
const places: Place[] = [];
// const data = res.json();
for (let i = 0; i < data.length; i++) {
const main_schedule_times: Day[] = [];
let main_schedule_times: Day[] = [];
let special_schedules: SpecialSchedule[] = [];
for (let e = 0; e < data[i].main_schedule.open_times.length; e++) {
let jsonDay = data[i].main_schedule.open_times[e];
......@@ -85,7 +86,26 @@ export class DataProviderService {
parseTime(jsonDay.end_time));
main_schedule_times.push(Object.freeze(day));
}
for (let e = 0; e < data[i].special_schedules.length; e++) {
const jsonSchedule = data[i].special_schedules[e];
let open_times:Day[] = [];
for(let f = 0; f < jsonSchedule.open_times.length;f++){
let jsonDay = jsonSchedule.open_times[f];
const day = new Day(
jsonDay.id,
jsonDay.last_modified,
jsonDay.schedule,
jsonDay.start_day,
parseTime(jsonDay.start_time),
jsonDay.end_day,
parseTime(jsonDay.end_time));
open_times.push(Object.freeze(day));
}
const schedule = new SpecialSchedule(jsonSchedule.valid_start,jsonSchedule.valid_end,open_times);
special_schedules.push(Object.freeze(schedule));
}
console.log(special_schedules);
places.push(new Place(
main_schedule_times,
[],
......
import { Day } from './day';
import { Time } from './time';
import { SpecialSchedule } from './special-schedule';
export class Place {
main_schedule_times: Day[] = [];
special_schedule_times = [];
special_schedules: SpecialSchedule[] = [];
id: number;
last_modified: string;
name: string;
category: number;
location: string;
constructor(main_schedule_times?: Day[], special_schedule_times?, id?: number, last_modified?: string,
constructor(main_schedule_times?: Day[], special_schedules?:SpecialSchedule[], id?: number, last_modified?: string,
name?: string, category?: number, location?: string) {
this.main_schedule_times = main_schedule_times || [];
this.special_schedule_times = special_schedule_times || [];
this.special_schedules = special_schedules || [];
this.id = id || 0;
this.last_modified = last_modified || '';
this.name = name || '';
......@@ -76,5 +77,5 @@ export class Place {
}
}
}
// useSpecial():
import { Day } from './day';
import { Time } from './time';
export class SpecialSchedule {
open_times: Day[];
valid_start: string;
valid_end: string;
constructor(valid_start:string,valid_end:string,open_times?: Day[]){
this.open_times = open_times || [];
this.valid_end = valid_end;
this.valid_start = valid_start;
}
}
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