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;
}
}
export class MockData {
apiData = [
{
"main_schedule": {
"open_times": [
{
"id": 1147,
"last_modified": "2017-01-30T03:07:15.950Z",
"schedule": 1146,
"start_day": 1,
"start_time": "07:00:00",
"end_day": 1,
"end_time": "23:00:00"
},
{
"id": 1148,
"last_modified": "2017-01-30T03:07:15.952Z",
"schedule": 1146,
"start_day": 2,
"start_time": "07:00:00",
"end_day": 2,
"end_time": "23:00:00"
},
{
"id": 1149,
"last_modified": "2017-01-30T03:07:15.953Z",
"schedule": 1146,
"start_day": 3,
"start_time": "07:00:00",
"end_day": 3,
"end_time": "23:00:00"
},
{
"id": 1150,
"last_modified": "2017-01-30T03:08:15.500Z",
"schedule": 1146,
"start_day": 4,
"start_time": "07:00:00",
"end_day": 4,
"end_time": "19:00:00"
},
{
"id": 1151,
"last_modified": "2017-01-30T03:08:15.505Z",
"schedule": 1146,
"start_day": 5,
"start_time": "10:00:00",
"end_day": 5,
"end_time": "16:00:00"
},
{
"id": 1152,
"last_modified": "2017-01-30T03:08:15.509Z",
"schedule": 1146,
"start_day": 6,
"start_time": "11:00:00",
"end_day": 6,
"end_time": "21:00:00"
},
{
"id": 1153,
"last_modified": "2017-01-30T03:07:15.958Z",
"schedule": 1146,
"start_day": 0,
"start_time": "07:00:00",
"end_day": 0,
"end_time": "23:00:00"
}
],
"id": 1146,
"last_modified": "2017-01-30T03:08:15.488Z",
"name": "Argo Tea",
"valid_start": "2017-01-23",
"valid_end": "2017-09-29"
},
"special_schedules": [],
"id": 1154,
"last_modified": "2017-01-30T03:14:06.566Z",
"name": "Argo Tea",
"category": 953,
"location": "Fenwick Library"
},
{
"main_schedule": {
"open_times": [
{
"id": 556,
"last_modified": "2016-08-29T00:35:40.011Z",
"schedule": 101,
"start_day": 0,
"start_time": "11:00:00",
"end_day": 0,
"end_time": "18:00:00"
},
{
"id": 557,
"last_modified": "2016-08-29T00:35:40.013Z",
"schedule": 101,
"start_day": 1,
"start_time": "11:00:00",
"end_day": 1,
"end_time": "18:00:00"
},
{
"id": 558,
"last_modified": "2016-08-29T00:35:40.020Z",
"schedule": 101,
"start_day": 2,
"start_time": "11:00:00",
"end_day": 2,
"end_time": "18:00:00"
},
{
"id": 559,
"last_modified": "2016-08-29T00:35:40.022Z",
"schedule": 101,
"start_day": 3,
"start_time": "11:00:00",
"end_day": 3,
"end_time": "18:00:00"
},
{
"id": 560,
"last_modified": "2016-08-29T00:35:40.028Z",
"schedule": 101,
"start_day": 4,
"start_time": "11:00:00",
"end_day": 4,
"end_time": "18:00:00"
}
],
"id": 101,
"last_modified": "2016-08-29T00:35:40.004Z",
"name": "Auntie Anne's",
"valid_start": "2014-08-24",
"valid_end": "2015-01-01"
},
"special_schedules": [
{
"open_times": [],
"id": 1052,
"last_modified": "2017-01-17T22:30:38.039Z",
"name": "WB2017CLOSED",
"valid_start": "2017-01-09",
"valid_end": "2017-01-22"
}
],
"id": 100,
"last_modified": "2017-01-09T21:28:33.389Z",
"name": "Auntie Anne's",
"category": 953,
"location": "Johnson Center"
},
{
"main_schedule": {
"open_times": [
{
"id": 120,
"last_modified": "2016-08-29T00:36:58.394Z",
"schedule": 119,
"start_day": 0,
"start_time": "07:30:00",
"end_day": 0,
"end_time": "21:00:00"
},
{
"id": 121,
"last_modified": "2016-08-29T00:36:58.396Z",
"schedule": 119,
"start_day": 1,
"start_time": "07:30:00",
"end_day": 1,
"end_time": "21:00:00"
},
{
"id": 122,
"last_modified": "2016-08-29T00:36:58.398Z",
"schedule": 119,
"start_day": 2,
"start_time": "07:30:00",
"end_day": 2,
"end_time": "21:00:00"
},
{
"id": 123,
"last_modified": "2016-08-29T00:36:58.400Z",
"schedule": 119,
"start_day": 3,
"start_time": "07:30:00",
"end_day": 3,
"end_time": "21:00:00"
},
{
"id": 124,
"last_modified": "2016-04-25T19:05:50.864Z",
"schedule": 119,
"start_day": 4,
"start_time": "07:30:00",
"end_day": 4,
"end_time": "20:00:00"
},
{
"id": 530,
"last_modified": "2016-04-25T19:05:50.866Z",
"schedule": 119,
"start_day": 5,
"start_time": "11:00:00",
"end_day": 5,
"end_time": "20:00:00"
},
{
"id": 531,
"last_modified": "2016-04-25T19:05:50.868Z",
"schedule": 119,
"start_day": 6,
"start_time": "11:00:00",
"end_day": 6,
"end_time": "20:00:00"
}
],
"id": 119,
"last_modified": "2016-08-29T00:36:58.391Z",
"name": "Burger King",
"valid_start": "2016-04-25",
"valid_end": "2016-05-25"
},
"special_schedules": [
{
"open_times": [
{
"id": 1104,
"last_modified": "2017-01-10T02:03:10.221Z",
"schedule": 1058,
"start_day": 1,
"start_time": "11:00:00",
"end_day": 1,
"end_time": "15:00:00"
},
{
"id": 1105,
"last_modified": "2017-01-10T02:03:10.222Z",
"schedule": 1058,
"start_day": 2,
"start_time": "11:00:00",
"end_day": 2,
"end_time": "15:00:00"
},
{
"id": 1106,
"last_modified": "2017-01-10T02:03:10.223Z",
"schedule": 1058,
"start_day": 3,
"start_time": "11:00:00",
"end_day": 3,
"end_time": "15:00:00"
},
{
"id": 1107,
"last_modified": "2017-01-10T02:03:10.224Z",
"schedule": 1058,
"start_day": 4,
"start_time": "11:00:00",
"end_day": 4,
"end_time": "15:00:00"
},
{
"id": 1115,
"last_modified": "2017-01-17T23:39:12.005Z",
"schedule": 1058,
"start_day": 6,
"start_time": "11:00:00",
"end_day": 6,
"end_time": "20:00:00"
}
],
"id": 1058,
"last_modified": "2017-01-17T23:39:11.997Z",
"name": "WB2017BURGERKING",
"valid_start": "2017-01-08",
"valid_end": "2017-01-22"
}
],
"id": 118,
"last_modified": "2017-01-09T21:30:42.778Z",
"name": "Burger King",
"category": 953,
"location": "Johnson Center"
},
{
"main_schedule": {
"open_times": [
{
"id": 129,
"last_modified": "2015-08-31T16:59:41.518Z",
"schedule": 128,
"start_day": 0,
"start_time": "08:00:00",
"end_day": 0,
"end_time": "21:00:00"
},
{
"id": 130,
"last_modified": "2015-08-31T16:59:41.524Z",
"schedule": 128,
"start_day": 1,
"start_time": "08:00:00",
"end_day": 1,
"end_time": "21:00:00"
},
{
"id": 131,
"last_modified": "2015-08-31T16:59:41.529Z",
"schedule": 128,
"start_day": 2,
"start_time": "08:00:00",
"end_day": 2,
"end_time": "21:00:00"
},
{
"id": 132,
"last_modified": "2015-08-31T16:59:41.534Z",
"schedule": 128,
"start_day": 3,
"start_time": "08:00:00",
"end_day": 3,
"end_time": "21:00:00"
},
{
"id": 133,
"last_modified": "2016-04-25T19:17:34.421Z",
"schedule": 128,
"start_day": 4,
"start_time": "08:00:00",
"end_day": 4,
"end_time": "15:00:00"
}
],
"id": 128,
"last_modified": "2016-08-29T00:37:52.572Z",
"name": "Chick-Fil-A",
"valid_start": "2016-08-28",
"valid_end": "2016-12-25"
},
"special_schedules": [
{
"open_times": [],
"id": 1052,
"last_modified": "2017-01-17T22:30:38.039Z",
"name": "WB2017CLOSED",
"valid_start": "2017-01-09",
"valid_end": "2017-01-22"
}
],
"id": 127,
"last_modified": "2017-01-09T21:46:46.992Z",
"name": "Chick-Fil-A",
"category": 953,
"location": "SUB I"
},
{
"main_schedule": {
"open_times": [
{
"id": 551,
"last_modified": "2015-08-31T18:18:12.245Z",
"schedule": 137,
"start_day": 0,
"start_time": "07:30:00",
"end_day": 0,
"end_time": "17:00:00"
},
{
"id": 552,
"last_modified": "2015-08-31T18:18:12.248Z",
"schedule": 137,
"start_day": 1,
"start_time": "07:30:00",
"end_day": 1,
"end_time": "17:00:00"
},
{
"id": 553,
"last_modified": "2015-08-31T18:18:12.251Z",
"schedule": 137,
"start_day": 2,
"start_time": "07:30:00",
"end_day": 2,
"end_time": "17:00:00"
},
{
"id": 554,
"last_modified": "2015-08-31T18:18:12.254Z",
"schedule": 137,
"start_day": 3,
"start_time": "07:30:00",
"end_day": 3,
"end_time": "17:00:00"
},
{
"id": 555,
"last_modified": "2015-08-31T18:18:12.256Z",
"schedule": 137,
"start_day": 4,
"start_time": "07:30:00",
"end_day": 4,
"end_time": "17:00:00"
}
],
"id": 137,
"last_modified": "2015-08-31T18:18:12.237Z",
"name": "Einstein Bros Bagels [ENGR]",
"valid_start": "2014-08-24",
"valid_end": "2015-01-01"
},
"special_schedules": [
{
"open_times": [],
"id": 1052,
"last_modified": "2017-01-17T22:30:38.039Z",
"name": "WB2017CLOSED",
"valid_start": "2017-01-09",
"valid_end": "2017-01-22"
}
],
"id": 136,
"last_modified": "2017-01-09T21:48:47.376Z",