Commit 4ec4d92c authored by mdsecurity's avatar mdsecurity
Browse files

fixing openFor method so it works with Food Trucks

parent 7e154b7c
...@@ -7,12 +7,15 @@ import { Place } from '../../Place'; ...@@ -7,12 +7,15 @@ import { Place } from '../../Place';
styleUrls: ['./area.component.scss'] styleUrls: ['./area.component.scss']
}) })
export class AreaComponent implements OnInit { export class AreaComponent implements OnInit {
private places: Place[] = [] private places: Place[] = [];
private placee:Place = new Place();
constructor(private dataProvider: DataProviderService) { } constructor(private dataProvider: DataProviderService) { }
ngOnInit() { ngOnInit() {
this.dataProvider.getFacilities().subscribe( this.dataProvider.getFacilities().subscribe(
(places) => { this.places = places;}, (places) => { this.places = places;
this.placee = places[2];
console.log(places[2]);},
(error) => { console.log(error); } (error) => { console.log(error); }
) )
} }
......
...@@ -24,12 +24,13 @@ ...@@ -24,12 +24,13 @@
</div> </div>
</div> </div>
<ng-template #elseBlock> <ng-template #elseBlock>
<div class="closed-shader"></div> hello
<!--<div class="closed-shader"></div>
<div class="place-open-badge" style="width:102px;background-color:#C4B9B9;"> <div class="place-open-badge" style="width:102px;background-color:#C4B9B9;">
<div class="place-status">CLOSED</div> <div class="place-status">CLOSED</div>
<div class="place-divider"></div> <div class="place-divider"></div>
<div class="place-time-remaining">~{{place.openFor().hour}}Hrs</div> <div class="place-time-remaining">~{{place.openFor().hour}}Hrs</div>
</div> </div>-->
</ng-template> </ng-template>
<div class="place-location">{{place.location }}</div> <div class="place-location">{{place.location }}</div>
......
...@@ -14,18 +14,18 @@ import {DomSanitizer} from '@angular/platform-browser'; ...@@ -14,18 +14,18 @@ import {DomSanitizer} from '@angular/platform-browser';
export class PlaceCardComponent implements OnInit { export class PlaceCardComponent implements OnInit {
@Input() private place: Place; @Input() private place: Place;
private status: string; private status: string;
private show;
private week: string[] = ["MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"]; private week: string[] = ["MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"];
private url; private url;
constructor(private dataProvider: DataProviderService, public dialog: MdDialog,private sanitizer: DomSanitizer) { } constructor(private dataProvider: DataProviderService, public dialog: MdDialog,private sanitizer: DomSanitizer) { }
ngOnInit() { ngOnInit() {
this.url = this.sanitizer.bypassSecurityTrustUrl('https://unsplash.it/200/300?image='+Math.floor((Math.random()*999+1))); this.url = this.sanitizer.bypassSecurityTrustUrl('https://unsplash.it/200/300?image='+Math.floor((Math.random()*999+1)));
} }
openInContext() { openInContext() {
this.dataProvider.setContext(this.place); this.dataProvider.setContext(this.place);
// console.log(this.place.openFor().hour+ " "+ this.place.openFor().minute+ " "+ this.place.openFor().second) // console.log(this.place.openFor().hour+ " "+ this.place.openFor().minute+ " "+ this.place.openFor().second)
console.log(this.place); // console.log(this.place);
} }
openDialog() { openDialog() {
let dialogRef = this.dialog.open(FeedbackDialogComponent); let dialogRef = this.dialog.open(FeedbackDialogComponent);
......
...@@ -25,7 +25,7 @@ export class Place { ...@@ -25,7 +25,7 @@ export class Place {
isOpen(): boolean { isOpen(): boolean {
const currTime = new Date(); const currTime = new Date();
const inSeconds = currTime.getHours() * 60 * 60 + currTime.getMinutes() * 60 + currTime.getSeconds(); const inSeconds = currTime.getHours() * 60 * 60 + currTime.getMinutes() * 60 + currTime.getSeconds();
const dayOfWeekShift = [6, 5, 4, 3, 2, 1, 0]; const dayOfWeekShift = [6, 0, 1, 2, 3, 4, 5];
const dayOfWeek = dayOfWeekShift[currTime.getDay()]; const dayOfWeek = dayOfWeekShift[currTime.getDay()];
const useSpecialSchedule = this.useSpecial(); const useSpecialSchedule = this.useSpecial();
let schedule; let schedule;
...@@ -34,36 +34,61 @@ export class Place { ...@@ -34,36 +34,61 @@ export class Place {
} else { } else {
schedule = this.special_schedules[useSpecialSchedule].openTimes; schedule = this.special_schedules[useSpecialSchedule].openTimes;
} }
// for (let i = 0; i < schedule.length; i++) {
// const day = schedule[i];
// // change the order of if statements at some point
// if (day.start_day !== day.end_day) {
// if (day.end_day === dayOfWeek) {
// if (day.end_time.inSeconds() > inSeconds) {
// return true;
// }
// } else if (day.start_day === dayOfWeek) {
// return true;
// }
// } else {
// if (day.start_day === dayOfWeek) {
// if (day.end_time.inSeconds() > inSeconds) {
// return true;
// }
// }
// }
// }
for (let i = 0; i < schedule.length; i++) { for (let i = 0; i < schedule.length; i++) {
const day = schedule[i]; const day = schedule[i];
// change the order of if statements at some point if ((dayOfWeek === day.start_day || dayOfWeek === day.end_day) && day.start_day === day.end_day) {
if (day.start_day !== day.end_day) { if (inSeconds >= day.start_time.inSeconds()) {
if (day.end_day === dayOfWeek) { if (inSeconds <= day.end_time.inSeconds()) {
if (day.end_time.inSeconds() > inSeconds) {
return true; return true;
} }
} else if (day.start_day === dayOfWeek) { return false;
return true;
} }
} else { return false;
if (day.start_day === dayOfWeek) { } else if (dayOfWeek >= day.start_day && dayOfWeek <= day.end_day) {
if (day.end_time.inSeconds() > inSeconds) { if (dayOfWeek === day.start_day) {
if (inSeconds >= day.start_time.inSeconds()) {
return true; return true;
} }
return false;
} else if (dayOfWeek === day.end_day) {
if (inSeconds >= day.end_time.inSeconds()) {
return false;
}
return true;
} else {
return true;
} }
} }
} }
console.log('false');
return false; return false;
} }
openFor(): Time { openFor(): any {
const currTime = new Date(); const currTime = new Date();
const today = currTime.getDay() - 1;
const inSeconds = currTime.getHours() * 60 * 60 + currTime.getMinutes() * 60 + currTime.getSeconds(); const inSeconds = currTime.getHours() * 60 * 60 + currTime.getMinutes() * 60 + currTime.getSeconds();
const dayOfWeekShift = [6, 5, 4, 3, 2, 1, 0]; const dayOfWeekShift = [6, 0, 1, 2, 3, 4, 5];
const dayOfWeek = dayOfWeekShift[currTime.getDay()]; const dayOfWeek = dayOfWeekShift[currTime.getDay()];
const useSpecialSchedule = this.useSpecial(); const useSpecialSchedule = this.useSpecial();
let timeTilClose = new Time(); let timeTilClose = new Time();
let sumSeconds = 0; let sumSeconds = 0;
...@@ -73,25 +98,59 @@ export class Place { ...@@ -73,25 +98,59 @@ export class Place {
} else { } else {
schedule = this.special_schedules[useSpecialSchedule].openTimes; schedule = this.special_schedules[useSpecialSchedule].openTimes;
} }
// clean up if statements later // for (let i = 0; i < schedule.length; i++) {
// if (this.isOpen()) { // const day = schedule[i];
for (let i = 0; i < schedule.length; i++) { // if (day.end_day !== day.start_day) {
const day = schedule[i]; // if (dayOfWeek === day.end_day) {
if (day.end_day !== day.start_day) { // sumSeconds = day.end_time.inSeconds() - inSeconds - 86400;
if (dayOfWeek === day.end_day) { // } else if (dayOfWeek === day.start_day) {
sumSeconds = day.end_time.inSeconds() - inSeconds - 86400; // sumSeconds = day.end_time.inSeconds() + 86400 - inSeconds;
} else if (dayOfWeek === day.start_day) { // }
sumSeconds = day.end_time.inSeconds() + 86400 - inSeconds; // } else {
// sumSeconds = day.end_time.inSeconds() - inSeconds;
// }
// return timeTilClose.fromSeconds(sumSeconds);
// }
for (let i = 0; i < schedule.length; i++) {
const day = schedule[i];
if ((dayOfWeek === day.start_day || dayOfWeek === day.end_day) && day.start_day === day.end_day) {
if (inSeconds >= day.start_time.inSeconds()) {
if (inSeconds <= day.end_time.inSeconds()) {
sumSeconds = day.end_time.inSeconds() - inSeconds;
} else {
//not done
sumSeconds = 86400 - inSeconds;
} }
} else { } else {
sumSeconds = day.end_time.inSeconds() - inSeconds; sumSeconds = day.start_time.inSeconds() - inSeconds;
} }
// console.log(sumSeconds);
return timeTilClose.fromSeconds(sumSeconds);
} else if (dayOfWeek >= day.start_day && dayOfWeek <= day.end_day) {
if (dayOfWeek === day.start_day) {
if (inSeconds >= day.start_time.inSeconds()) {
sumSeconds = 86400 - inSeconds + (86400 * (day.end_day - day.start_day - 1)) + day.end_time.inSeconds();
} else {
sumSeconds = day.start_time.inSeconds() - inSeconds;
}
} else if (dayOfWeek === day.end_day) {
if (inSeconds >= day.end_time.inSeconds()) {
//not done
sumSeconds = 86400 - inSeconds;
} else {
sumSeconds = day.end_time.inSeconds() - inSeconds;
}
} else {
sumSeconds = 86400 - inSeconds + (86400 * (day.end_day - dayOfWeek - 2)) + day.end_time.inSeconds();
}
// console.log(sumSeconds);
return timeTilClose.fromSeconds(sumSeconds); return timeTilClose.fromSeconds(sumSeconds);
} }
// } else {
return timeTilClose; }
// } return { "hour": "closed" };
} }
useSpecial(): number { useSpecial(): number {
......
...@@ -4,7 +4,7 @@ export class Time { ...@@ -4,7 +4,7 @@ export class Time {
second: number; second: number;
constructor(hour?: number, minute?: number, second?: number) { constructor(hour?: number, minute?: number, second?: number) {
this.hour = hour || 1; this.hour = hour || 0;
this.minute = minute || 0; this.minute = minute || 0;
this.second = second || 0; this.second = second || 0;
} }
......
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