Commit cdd5c664 authored by mdsecurity's avatar mdsecurity
Browse files

add(data-provider) built service to pull API data

also commented out place card stuff because it was braking when i changed the Place class
parent 7d577ec4
......@@ -4,7 +4,7 @@ root = true
[*]
charset = utf-8
indent_style = space
indent_size = 2
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true
......
# Contributor Code of Conduct
## Version 0.3a-angular
As contributors and maintainers of the What's Open project, we pledge to respect everyone who contributes by posting issues, updating documentation, submitting pull requests, providing feedback in comments, and any other activities.
Communication through any of What's Open's channels (GitLab, IRC, mailing lists, Google+, Twitter, etc.) must be constructive and never resort to personal attacks, trolling, public or private harrassment, insults, or other unprofessional conduct.
We promise to extend courtesy and respect to everyone involved in this project regardless of gender, gender identity, sexual orientation, disability, age, race, ethnicity, religion, or level of experience. We expect anyone contributing to the Angular project to do the same.
If any member of the community violates this code of conduct, the maintainers of the Angular project may take action, removing issues, comments, and PRs or blocking accounts as deemed appropriate.
If you are subject to or witness unacceptable behavior, or have any other concerns, please email us at [conduct@angularjs.org](mailto:coc@angularjs.org).
<div class="context-bar-button-container">
<!--<button class="show-hide-button"(click)="show=!show">Click Me</button>-->
<app-show-hide-arrow class="show-hide-button" [isRight]='true' (change)="show = $event"></app-show-hide-arrow>
<div [ngClass]="(show)?'light-card context-bar-open' : 'light-card context-bar-closed'">
<div class="context-bar-header">
......
import { Component, OnInit} from '@angular/core';
import {DataProviderService} from '../data-provider.service'
import { Place } from '../place';
@Component({
selector: 'app-context-bar',
templateUrl: './context-bar.component.html',
styleUrls: ['./context-bar.component.scss']
styleUrls: ['./context-bar.component.scss'],
providers:[DataProviderService]
})
export class ContextBarComponent implements OnInit {
show: boolean = true;
constructor() { }
data:Place[];
error:any;
constructor(private dataProvider:DataProviderService) { }
ngOnInit() {
}
private tempF =function(event){
console.log(event);
}
}
}
/* tslint:disable:no-unused-variable */
import { TestBed, async, inject } from '@angular/core/testing';
import { DataProviderService } from './data-provider.service';
describe('DataProviderService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [DataProviderService]
});
});
it('should ...', inject([DataProviderService], (service: DataProviderService) => {
expect(service).toBeTruthy();
}));
});
import { Injectable } from '@angular/core';
import { Http, Response, Headers, RequestOptions } from '@angular/http';
import { MockData } from './mock-data'
import { Observable } from 'rxjs/Observable';
import { Place } from './place';
import { Day } from './day';
// Operators
import 'rxjs/add/observable/throw';
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/debounceTime';
import 'rxjs/add/operator/distinctUntilChanged';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/switchMap';
import 'rxjs/add/operator/toPromise';
@Injectable()
export class DataProviderService {
private Url = 'https://whatsopen.gmu.edu/api/facilities/'; // URL to web API
constructor(private http: Http) { }
getApiData(): Observable<Place[]> {
return this.http.get(this.Url)
.map(this.extractData)
.catch(this.handleError);
}
extractData(res:Response):Place[] {
let places: Place[] = [];
let data = res.json();
for (let i = 0; i < data.length; i++) {
let main_schedule_times: Day[] = [];
for (let e = 0; e < data[i].main_schedule.open_times.length; e++) {
let jsonDay = data[i].main_schedule.open_times[e];
main_schedule_times.push(new Day(
jsonDay.id,
jsonDay.last_modified,
jsonDay.schedule,
jsonDay.start_day,
jsonDay.start_time,
jsonDay.end_day,
jsonDay.end_time));
}
places.push(new Place(
main_schedule_times,
[],
data[i].id,
data[i].last_modified,
data[i].name,
data[i].category,
data[i].location
));
}
return places;
}
private handleError(error: Response | any) {
// In a real world app, we might use a remote logging infrastructure
let errMsg: string;
if (error instanceof Response) {
const body = error.json() || '';
const err = body.error || JSON.stringify(body);
errMsg = `${error.status} - ${error.statusText || ''} ${err}`;
} else {
errMsg = error.message ? error.message : error.toString();
}
console.error(errMsg);
return Observable.throw(errMsg);
}
}
export class Day {
id: number;
last_modified: string;
schedule:number;
start_day: number;
start_time: string;
end_day: number;
end_time: string;
constructor(id: number, last_modified: string,schedule:number, start_day: number, start_time: string, end_day: number, end_time: string) {
this.id = id;
this.last_modified = last_modified;
this.schedule = schedule;
this.start_day = start_day;
this.start_time = start_time;
this.end_day = end_day;
this.end_time = end_time;
}
}
This diff is collapsed.
<div class="light-card place-card">
<img src="../../assets/BKing.jpg" class="place-picture">
<!--<img src="../../assets/BKing.jpg" class="place-picture">
<div class="place-info-block">
<i class="fa fa-star-o star-icon" aria-hidden="true"></i>
<div class="place-title">{{place.name}}</div>
......@@ -10,5 +10,5 @@
<div class="status-text">~13Hrs</div>
</div>
<div class="place-location">{{place.location}}</div>
</div>
</div>-->
</div>
......@@ -13,33 +13,31 @@ export class PlaceCardComponent implements OnInit {
constructor() { }
ngOnInit() {
let weekOpenTimes: number[][] = [];
let weekCloseTimes: number[][] = [];
// let weekOpenTimes: number[][] = [];
// let weekCloseTimes: number[][] = [];
for (let i = 0; i < 7; i++) {
const hour1 = Math.floor(Math.random() * 24);
const minute1 = Math.floor(Math.random() * 60);
const hour2 = Math.floor(Math.random() * 24);
const minute2 = Math.floor(Math.random() * 60);
weekOpenTimes.push([hour1, minute1]);
weekCloseTimes.push([hour2, minute2]);
}
this.place = new Place('Burger King', weekOpenTimes,
weekCloseTimes, 'picture: string', 'The Johnson Center');
// for (let i = 0; i < 7; i++) {
// const hour1 = Math.floor(Math.random() * 24);
// const minute1 = Math.floor(Math.random() * 60);
// const hour2 = Math.floor(Math.random() * 24);
// const minute2 = Math.floor(Math.random() * 60);
// weekOpenTimes.push([hour1, minute1]);
// weekCloseTimes.push([hour2, minute2]);
// }
this.status = 'OPEN';
}
//if t1 is bigger than t2 it returns true ;
private time_between = function (t1: number[], t2: number[]): boolean {
// multiplying hours by 60 and adding minutes
const t1_minutes = t1[0] * 60 + t1[1];
const t2_minutes = t2[0] * 60 + t2[1];
// this.status = 'OPEN';
// }
// //if t1 is bigger than t2 it returns true ;
// private time_between = function (t1: number[], t2: number[]): boolean {
// // multiplying hours by 60 and adding minutes
// const t1_minutes = t1[0] * 60 + t1[1];
// const t2_minutes = t2[0] * 60 + t2[1];
if (t1_minutes > t2_minutes) {
return true;
}
return false;
// if (t1_minutes > t2_minutes) {
// return true;
// }
// return false;
}
}
\ No newline at end of file
import { Day } from './day';
export class Place {
name: string;
picture: string;
openTimes: number[][];
closeTimes: number[][];
location: string;
constructor(name: string, openTimes: number[][],
closeTimes: number[][], picture: string, location: string) {
main_schedule_times: Day[] = [];
special_schedule_times = [];
id:number;
last_modified:string;
name:string;
category:number;
location:string;
constructor(main_schedule_times:Day[],special_schedule_times,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.id = id;
this.last_modified = last_modified;
this.name = name;
this.openTimes = openTimes;
this.closeTimes = closeTimes;
this.picture = picture;
this.category = category;
this.location = location;
}
}
}
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