Add functionality to load a single event; Modify share api to redirect to correct url based on environment
parent
8a4cf9816e
commit
cdc9836450
|
|
@ -94,6 +94,10 @@ const Routes =
|
|||
{
|
||||
path: 'events',
|
||||
component: EventsPageComponent
|
||||
},
|
||||
{
|
||||
path: 'events/:id',
|
||||
component: EventsPageComponent
|
||||
}
|
||||
]
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { MdDialog, MdDialogConfig, MdSnackBar } from '@angular/material';
|
||||
import { ActivatedRoute, Params } from '@angular/router';
|
||||
import { EventService } from './../../services/event.service';
|
||||
import { AddEventPopupComponent } from './../popups/add-event-popup/add-event-popup.component';
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
|
|
@ -22,13 +23,23 @@ export class EventsPageComponent implements OnInit {
|
|||
constructor(private loginService: LoginService,
|
||||
private eventService: EventService,
|
||||
private dialog: MdDialog,
|
||||
private snackbar: MdSnackBar) {
|
||||
private snackbar: MdSnackBar,
|
||||
private activatedRoute: ActivatedRoute) {
|
||||
this.loginService.isLoggedIn(true).subscribe(is => { this.loggedIn = is });
|
||||
this.loginService.onLogin().subscribe(is => { this.loggedIn = is.isLoggedIn; });
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.getEvents(true);
|
||||
this.activatedRoute.params
|
||||
.subscribe((params: Params) =>{
|
||||
let id = +params['id'];
|
||||
id = Number.isNaN(id) ? -1 : id;
|
||||
if (id > -1){
|
||||
this.getSingleEvent(id);
|
||||
} else {
|
||||
this.getEvents(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getEvents(clearExisting: boolean): void{
|
||||
|
|
@ -47,6 +58,15 @@ export class EventsPageComponent implements OnInit {
|
|||
);
|
||||
}
|
||||
|
||||
getSingleEvent(id: Number): void{
|
||||
this.events = [];
|
||||
this.loading = true;
|
||||
this.eventService.getSingleEvent(id).subscribe(event => {
|
||||
this.events.push(event);
|
||||
this.loading = false;
|
||||
});
|
||||
}
|
||||
|
||||
addEvents(events: Event[]): void{
|
||||
for(let i = 0; i < events.length; i++){
|
||||
this.events.push(events[i]);
|
||||
|
|
|
|||
|
|
@ -18,11 +18,11 @@ export class UpcomingEventsComponent implements OnInit {
|
|||
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.getSermons();
|
||||
ngOnInit(): void {
|
||||
this.getEvents();
|
||||
}
|
||||
|
||||
getSermons(): void{
|
||||
getEvents(): void{
|
||||
this.events = [];
|
||||
this.loading = true;
|
||||
this.eventService.getEvents(1).subscribe(events => {
|
||||
|
|
@ -31,4 +31,6 @@ export class UpcomingEventsComponent implements OnInit {
|
|||
console.log(this.events)
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
export const EVENTS_ADD_URL = "/api2/events/a/";
|
||||
export const EVENT_BY_ID = "/api2/events/";
|
||||
export const EVENTS_BY_PAGE_URL = "/api2/events/page/";
|
||||
export const SERMONS_BY_ID = '/api2/sermons/';
|
||||
export const SERMONS_BY_PAGE_URL = '/api2/sermons/page/';
|
||||
|
|
|
|||
|
|
@ -3,7 +3,9 @@ import { Http, Response } from '@angular/http';
|
|||
import { Observable } from 'rxjs/Observable';
|
||||
import { Event } from '../interfaces/event';
|
||||
|
||||
import { EVENTS_BY_PAGE_URL, EVENTS_ADD_URL } from '../constants/urls';
|
||||
import { EVENTS_BY_PAGE_URL,
|
||||
EVENT_BY_ID,
|
||||
EVENTS_ADD_URL } from '../constants/urls';
|
||||
|
||||
@Injectable()
|
||||
export class EventService {
|
||||
|
|
@ -14,7 +16,12 @@ export class EventService {
|
|||
|
||||
getEvents(page: number): Observable<Event[]> {
|
||||
let url = EVENTS_BY_PAGE_URL + page + "?pageSize=" + 10;
|
||||
return this.http.get(url).map(this.gotData).catch(this.dataError)
|
||||
return this.http.get(url).map(this.gotData,this).catch(this.dataError)
|
||||
};
|
||||
|
||||
getSingleEvent(id: Number): Observable<Event>{
|
||||
let url = EVENT_BY_ID + id;
|
||||
return this.http.get(url).map(this.gotDataSingle,this).catch(this.dataError);
|
||||
};
|
||||
|
||||
addEvent(event: Event){
|
||||
|
|
@ -29,19 +36,29 @@ export class EventService {
|
|||
.catch(this.dataError);
|
||||
}
|
||||
|
||||
gotData(res: Response){
|
||||
//if (1 == 1) return MOCK;
|
||||
gotDataSingle(res: Response){
|
||||
let body = res.json();
|
||||
body = body.events.map(e => { return {
|
||||
id: e.id,
|
||||
title: e.title,
|
||||
startDate: new Date(e.startDate),
|
||||
endDate: new Date(e.endDate),
|
||||
description: e.description
|
||||
}});
|
||||
return this.toEvent(body.event);
|
||||
}
|
||||
|
||||
gotData(res: Response){
|
||||
let body = res.json();
|
||||
body = body.events.map(e => {
|
||||
return this.toEvent(e);
|
||||
});
|
||||
return body || { };
|
||||
}
|
||||
|
||||
toEvent(json: any): Event{
|
||||
return {
|
||||
id: json.id,
|
||||
title: json.title,
|
||||
startDate: new Date(json.startDate),
|
||||
endDate: new Date(json.endDate),
|
||||
description: json.description
|
||||
}
|
||||
}
|
||||
|
||||
dataError(error: Response | any){
|
||||
let errMsg: string;
|
||||
if (error instanceof Response) {
|
||||
|
|
@ -56,10 +73,3 @@ export class EventService {
|
|||
}
|
||||
}
|
||||
|
||||
const MOCK: Event[] = [
|
||||
{ id:0, title: 'Missionary', startDate: new Date('2017-04-30T18:00:00'), endDate: null, description: 'Missionary from Africa will be with us' }
|
||||
,{ id:1, title: 'Door 2 Door', startDate: new Date('2017-04-22T10:00:00'), endDate: null, description: 'Handing out Tracts' }
|
||||
,{ id:2, title: 'Banquet', startDate: new Date('2017-06-20T18:00:00'), endDate: null, description: 'Food and Fun at the Banquet' }
|
||||
,{ id:3, title: 'Bible Study', startDate: new Date('2017-08-15T18:00:00'), endDate: null, description: 'Special Bible Study' }
|
||||
,{ id:4, title: 'Camp', startDate: new Date('2017-07-20T18:00:00'), endDate: new Date('2017-07-25T08:00:00'), description: 'Summer Camp for grades 4 - 9' }
|
||||
];
|
||||
|
|
|
|||
|
|
@ -39,7 +39,8 @@ function getSermon(req, res, id){
|
|||
referrer.startsWith('http://opengraphcheck.com')) {
|
||||
getSermonMeta(req, res, id);
|
||||
} else {
|
||||
res.redirect("https://ofbbutte.com/sermons/" + id);
|
||||
var url = req.protocol + "://" + req.hostname + "/sermons/" + id;
|
||||
res.redirect(url);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -89,7 +90,8 @@ function getEvent(req, res, id){
|
|||
referrer.startsWith('http://opengraphcheck.com'))) {
|
||||
getEventMeta(req, res, id);
|
||||
} else {
|
||||
res.redirect("https://ofbbutte.com/events/" + id);
|
||||
var url = req.protocol + "://" + req.hostname + "/events/" + id;
|
||||
res.redirect(url);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue