import { Injectable } from '@angular/core'; import * as globals from '../core/common'; import { Observable } from 'rxjs'; import { Http, Response, RequestOptions ,URLSearchParams} from '@angular/http'; import { catchError, map } from 'rxjs/operators'; import { environment } from '../../environments/environment'; import { IEventCalendar } from '../core/IEventCalendar'; @Injectable({ providedIn: 'root' }) export class EventCalendarService { //------------------- Web API URL sections --------------------- private getStaffEventsUrl = globals.serverBase + '/api/Staff/GetCalendarEvents'; constructor(private _http: Http) { } getStaffEvents(Id? : string, companyId? : string): Observable { let myparams = new URLSearchParams(); myparams.append("id", Id); myparams.append("companyId", companyId); let options = new RequestOptions({ params: myparams }); // ------------ uncomment and configure this to call api ----------- if (environment.useDummyData == false) { return this._http.get(this.getStaffEventsUrl, options) .pipe(map((response: Response) => response.json()), catchError(this.handleError)) } //dummy data for login history var events = [ { "title": "All Day Event", "start": "2016-01-01" }, { "title": "Long Event", "start": "2016-01-07", "end": "2016-01-10" }, { "title": "Repeating Event", "start": "2016-01-09T16:00:00" }, { "title": "Repeating Event", "start": "2016-01-16T16:00:00" }, { "title": "Conference", "start": "2016-01-11", "end": "2016-01-13" } ]; //return dummy response to Component return this._http.get('', options) .pipe(map((response: Response) => response.json()), catchError(this.handleError)) } //The function of handling the error private handleError(error: Response) { console.log("Error in staff activity service"); console.log(error); return Observable.throw(error.json().error || 'Server error'); } }