Commit 07b74347 authored by mdsecurity's avatar mdsecurity
Browse files

changed internals of how things are calculated

how long a place is open for and if a place is open are now calculated in a different way.
in the future i may change the openFor method to also tell you how long a place is closed for but for now it will just say closed
parent 889e0c89
...@@ -13,7 +13,7 @@ import 'rxjs/add/operator/catch'; ...@@ -13,7 +13,7 @@ import 'rxjs/add/operator/catch';
import 'rxjs/add/observable/of'; import 'rxjs/add/observable/of';
import 'rxjs/add/operator/share'; import 'rxjs/add/operator/share';
import 'rxjs/add/operator/map'; import 'rxjs/add/operator/map';
import 'rxjs/add/operator/DefaultIfEmpty'; import 'rxjs/add/operator/defaultIfEmpty';
@Injectable() @Injectable()
export class DataProviderService { export class DataProviderService {
......
<!--<div class="area-card-header">--> <!--<div class="area-card-header">-->
<!--<div class="hexagon center"> <!--<div class="hexagon center">
<div class="hexTop"></div> <div class="hexTop"></div>
<div class="hexBottom"></div> <div class="hexBottom"></div>
</div>--> </div>-->
<!--<div class="area-title">FAVORITES</div>--> <!--<div class="area-title">FAVORITES</div>-->
<!--<hr>--> <!--<hr>-->
<!--</div>--> <!--</div>-->
<div class="place-card-holder"> <div class="place-card-holder">
<div *ngFor="let place of places; let i = index;">
<app-place-card [place]="place"></app-place-card> <div *ngIf="!show; else showCards">
</div> </div>
<ng-template #showCards>
<div *ngFor="let place of places; let i = index;">
<app-place-card [place]="place"></app-place-card>
</div>
</ng-template>
</div> </div>
import { Component, OnInit} from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { DataProviderService } from '../../data-provider.service'; import { DataProviderService } from '../../data-provider.service';
import { Place } from '../../place'; import { Place } from '../../place';
@Component({ @Component({
...@@ -8,14 +8,17 @@ import { Place } from '../../place'; ...@@ -8,14 +8,17 @@ import { Place } from '../../place';
}) })
export class AreaComponent implements OnInit { export class AreaComponent implements OnInit {
private places: Place[] = []; private places: Place[] = [];
private placee:Place = new Place(); private placee: Place = new Place();
private show = false;
constructor(private dataProvider: DataProviderService) { } constructor(private dataProvider: DataProviderService) { }
ngOnInit() { ngOnInit() {
this.dataProvider.getFacilities().subscribe( this.dataProvider.getFacilities().subscribe(
(places) => { this.places = places; (places) => {
this.placee = places[2]; this.places = places;
console.log(places[2]);}, this.placee = places[12];
this.show = true;
},
(error) => { console.log(error); } (error) => { console.log(error); }
) )
} }
......
...@@ -16,19 +16,19 @@ ...@@ -16,19 +16,19 @@
<div class="title-container"> <div class="title-container">
<div class="place-title">{{place.name | removeBrackets}}</div> <div class="place-title">{{place.name | removeBrackets}}</div>
</div> </div>
<div *ngIf="isOpen; else elseBlock"> <div *ngIf="isOpen; else showClosed">
<div class="place-open-badge"> <div class="place-open-badge">
<div class="place-status">OPEN</div> <div class="place-status">OPEN</div>
<div class="place-divider"></div> <div class="place-divider"></div>
<div class="place-time-remaining">~{{openFor.hour}}Hrs</div> <div class="place-time-remaining">~{{showTime(openFor)}}</div>
</div> </div>
</div> </div>
<ng-template #elseBlock> <ng-template #showClosed>
<div class="closed-shader"></div> <div class="closed-shader"></div>
<div class="place-open-badge" style="width:102px;background-color:#C4B9B9;"> <div class="place-open-badge" style="width:75px;background-color:#C4B9B9;">
<div class="place-status">CLOSED</div> <div class="place-status-closed">CLOSED</div>
<div class="place-divider"></div> <!--<div class="place-divider"></div>-->
<div class="place-time-remaining">~{{openFor.hour}}Hrs</div> <!--<div class="place-time-remaining">~{{showTime(openFor)}}</div>-->
</div> </div>
</ng-template> </ng-template>
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
.place-open-badge { .place-open-badge {
min-height: 20px; min-height: 20px;
width: 88px; width: 92px;
height: 20px; height: 20px;
margin: 0px auto 0px auto; margin: 0px auto 0px auto;
background-color: #3ac550; background-color: #3ac550;
...@@ -48,6 +48,12 @@ ...@@ -48,6 +48,12 @@
color: #FFFFFF; color: #FFFFFF;
margin: 0px 0px 0px 3px; margin: 0px 0px 0px 3px;
} }
.place-status-closed {
font-family: NunitoSans-SemiBold;
font-size: 11px;
color: #FFFFFF;
margin: auto;
}
.place-divider { .place-divider {
width: 2px; width: 2px;
...@@ -62,6 +68,10 @@ ...@@ -62,6 +68,10 @@
font-family: NunitoSans-Regular; font-family: NunitoSans-Regular;
font-size: 11px; font-size: 11px;
color: #FFFFFF; color: #FFFFFF;
display: flex;
justify-content: center;
flex-grow: 2;
margin-left: -10px;
} }
.place-location { .place-location {
......
...@@ -5,7 +5,7 @@ import { DataProviderService } from '../../../data-provider.service'; ...@@ -5,7 +5,7 @@ import { DataProviderService } from '../../../data-provider.service';
import { MdDialog } from '@angular/material'; import { MdDialog } from '@angular/material';
import { FeedbackDialogComponent } from './feedback-dialog/feedback-dialog.component'; import { FeedbackDialogComponent } from './feedback-dialog/feedback-dialog.component';
import { DomSanitizer } from '@angular/platform-browser'; import { DomSanitizer } from '@angular/platform-browser';
import { Observable } from 'rxjs/Rx'; import { Observable } from 'rxjs/rx';
@Component({ @Component({
selector: 'app-place-card', selector: 'app-place-card',
templateUrl: './place-card.component.html', templateUrl: './place-card.component.html',
...@@ -20,10 +20,10 @@ export class PlaceCardComponent implements OnInit { ...@@ -20,10 +20,10 @@ export class PlaceCardComponent implements OnInit {
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)));
let timer = Observable.timer(0,60000); let timer = Observable.timer(0, 60000);
timer.subscribe(t => { timer.subscribe(t => {
this.openFor = this.place.openFor(); this.openFor = this.place.openFor();
this.isOpen = this.place.isOpen() this.isOpen = this.place.isOpen();
}); });
} }
openInContext() { openInContext() {
...@@ -36,4 +36,16 @@ export class PlaceCardComponent implements OnInit { ...@@ -36,4 +36,16 @@ export class PlaceCardComponent implements OnInit {
dialogRef.afterClosed().subscribe(result => { dialogRef.afterClosed().subscribe(result => {
}); });
} }
showTime(time: Time) {
if (time.hour === 1) {
return (time.hour + "Hr");
} else if (time.hour > 0) {
return (time.hour + "Hrs");
} else {
if (time.minute === 1) {
return (time.minute + "Min");
}
return (time.minute + "Mins");
}
}
} }
\ No newline at end of file
...@@ -34,25 +34,6 @@ export class Place { ...@@ -34,25 +34,6 @@ 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];
if ((dayOfWeek === day.start_day || dayOfWeek === day.end_day) && day.start_day === day.end_day) { if ((dayOfWeek === day.start_day || dayOfWeek === day.end_day) && day.start_day === day.end_day) {
...@@ -60,20 +41,16 @@ export class Place { ...@@ -60,20 +41,16 @@ export class Place {
if (inSeconds <= day.end_time.inSeconds()) { if (inSeconds <= day.end_time.inSeconds()) {
return true; return true;
} }
return false;
} }
return false;
} else if (dayOfWeek >= day.start_day && dayOfWeek <= day.end_day) { } else if (dayOfWeek >= day.start_day && dayOfWeek <= day.end_day) {
if (dayOfWeek === day.start_day) { if (dayOfWeek === day.start_day) {
if (inSeconds >= day.start_time.inSeconds()) { if (inSeconds >= day.start_time.inSeconds()) {
return true; return true;
} }
return false;
} else if (dayOfWeek === day.end_day) { } else if (dayOfWeek === day.end_day) {
if (inSeconds >= day.end_time.inSeconds()) { if (inSeconds <= day.end_time.inSeconds()) {
return false; return true;
} }
return true;
} else { } else {
return true; return true;
} }
...@@ -97,59 +74,50 @@ export class Place { ...@@ -97,59 +74,50 @@ 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];
// if (day.end_day !== day.start_day) {
// if (dayOfWeek === day.end_day) {
// sumSeconds = day.end_time.inSeconds() - inSeconds - 86400;
// } 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++) { for (let i = 0; i < schedule.length; i++) {
const day = schedule[i]; const day = schedule[i];
if ((dayOfWeek === day.start_day || dayOfWeek === day.end_day) && day.start_day === day.end_day) { if ((dayOfWeek === day.start_day || dayOfWeek === day.end_day) && day.start_day === day.end_day) {
if (inSeconds >= day.start_time.inSeconds()) { if (inSeconds >= day.start_time.inSeconds()) {
if (inSeconds <= day.end_time.inSeconds()) { if (inSeconds <= day.end_time.inSeconds()) {
sumSeconds = day.end_time.inSeconds() - inSeconds; sumSeconds = day.end_time.inSeconds() - inSeconds;
return timeTilClose.fromSeconds(sumSeconds);
} else { } else {
//not done //not done
sumSeconds = 86400 - inSeconds; sumSeconds = 86400 - inSeconds;
return timeTilClose.fromSeconds(sumSeconds);
} }
} else { } else {
sumSeconds = day.start_time.inSeconds() - inSeconds; sumSeconds = day.start_time.inSeconds() - inSeconds;
return timeTilClose.fromSeconds(sumSeconds);
} }
// console.log(sumSeconds); // console.log(sumSeconds);
return timeTilClose.fromSeconds(sumSeconds);
} else if (dayOfWeek >= day.start_day && dayOfWeek <= day.end_day) { } else if (dayOfWeek >= day.start_day && dayOfWeek <= day.end_day) {
if (dayOfWeek === day.start_day) { if (dayOfWeek === day.start_day) {
if (inSeconds >= day.start_time.inSeconds()) { if (inSeconds >= day.start_time.inSeconds()) {
sumSeconds = 86400 - inSeconds + (86400 * (day.end_day - day.start_day - 1)) + day.end_time.inSeconds(); sumSeconds = 86400 - inSeconds + (86400 * (day.end_day - day.start_day - 1)) + day.end_time.inSeconds();
return timeTilClose.fromSeconds(sumSeconds);
} else { } else {
sumSeconds = day.start_time.inSeconds() - inSeconds; sumSeconds = day.start_time.inSeconds() - inSeconds;
return timeTilClose.fromSeconds(sumSeconds);
} }
} else if (dayOfWeek === day.end_day) { } else if (dayOfWeek === day.end_day) {
if (inSeconds >= day.end_time.inSeconds()) { if (inSeconds >= day.end_time.inSeconds()) {
//not done //not done
sumSeconds = 86400 - inSeconds; sumSeconds = 86400 - inSeconds;
return timeTilClose.fromSeconds(sumSeconds);
} else { } else {
sumSeconds = day.end_time.inSeconds() - inSeconds; sumSeconds = day.end_time.inSeconds() - inSeconds;
return timeTilClose.fromSeconds(sumSeconds);
} }
} else { } else {
sumSeconds = 86400 - inSeconds + (86400 * (day.end_day - dayOfWeek - 2)) + day.end_time.inSeconds(); sumSeconds = 86400 - inSeconds + (86400 * (day.end_day - dayOfWeek - 2)) + day.end_time.inSeconds();
return timeTilClose.fromSeconds(sumSeconds);
} }
// console.log(sumSeconds); // console.log(sumSeconds);
return timeTilClose.fromSeconds(sumSeconds);
} }
} }
return { "hour": "closed" }; return new Time();
} }
useSpecial(): number { useSpecial(): number {
......
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