import { Injectable } from '@angular/core'; import { Http, Response, URLSearchParams, RequestOptions, Headers } from '@angular/http'; import * as globals from '../core/common'; import { Observable } from 'rxjs'; import { ILoginHistory } from '../core/ILoginHistory'; import { map, catchError } from 'rxjs/operators'; import { SelectItem } from 'primeng/api'; import { IOrganisation } from '../core/IOrganisation'; import { IStaffLoggedTime } from '../core/IStaffLoggedTime'; import { environment } from '../../environments/environment'; @Injectable({ providedIn: 'root' }) export class LoginHistoryService { //------------------- Web API URL sections --------------------- private baseUrl = globals.serverBase; private getPersonTypeFilterUrl = globals.serverBase + '/api/common/GetPersonTypeFilters'; private getGetLoginHistoryUrl = globals.serverBase + '/api/LoginDetails/GetLoginHistory'; constructor(private _http: Http) {} getLoginHistory(id?: string): Observable { let apiURL = ''; let myparams = new URLSearchParams(); myparams.append("id", id); let options = new RequestOptions({ params: myparams }); // ------------ uncomment and configure this to call api ----------- // this 'if' will switch services to use actual data and dummy data if (environment.useDummyData == false) { //send response to component return this._http.get(this.getGetLoginHistoryUrl, options) .pipe(map((response: Response) => response.json()), catchError(this.handleError)) } //dummy data for login history var LoginHistoryList: ILoginHistory[] = []; //dummy instances of IOrganisation created for LoginHistoryList object var Company: IOrganisation = { Id: 1, Type: "Outsource", Industry: "Accounting", CompanyName: "Whytes Chartered Accountants", Website: "", Email: "", Phone: "", Staff: 1, Country: "", LogoUrl: "www.web.com", PublicProfileNote: "public profile details", PrivateProfileNote: "private profile details", KeyWord: "keyword 1, keyword 2" }; var Company2: IOrganisation = { Id: 2, Type: "Affiliate", Industry: "Marketing", CompanyName: "XYZ Accounting PH outsource", Website: "", Email: "", Phone: "", Staff: 2, Country: "", LogoUrl: "www.web.com", PublicProfileNote: "public profile details", PrivateProfileNote: "private profile details", KeyWord: "keyword 1, keyword 2" }; //dummy login history object LoginHistoryList = [ { Id: 1, Firstname: "Des", Lastname: "Whyte", Company: Company, LastLogin: "Today 10:34 AM", LastActive: "Today 12:50 PM", Logins: "+45465465464" }, { Id: 2, Firstname: "Craig", Lastname: "Bull", Company: Company2, LastLogin: "Today 10:34 AM", LastActive: "Today 12:50 PM", Logins: "+45465465464" }, { Id: 3, Firstname: "Van", Lastname: "le", Company: Company2, LastLogin: "Today 10:34 AM", LastActive: "Today 12:50 PM", Logins: "+45465465464" }, { Id: 4, Firstname: "Vin", Lastname: "leong", Company: Company, LastLogin: "Today 10:55 AM", LastActive: "Today 11:50 PM", Logins: "+4546545524" }, { Id: 5, Firstname: "john", Lastname: "doe", Company: Company2, LastLogin: "Today 10:34 AM", LastActive: "Today 12:50 PM", Logins: "+45465465464" }, { Id: 6, Firstname: "kate", Lastname: "austen", Company: Company2, LastLogin: "Today 10:55 AM", LastActive: "Today 11:50 PM", Logins: "+4546545524" }, ] //return dummy response to Component return this._http.get(apiURL) .pipe(map((response: Response) => LoginHistoryList), catchError(this.handleError)) } getFilters(): Observable { let apiURL = ''; // ------------ uncomment and configure this to call api ----------- // this 'if' will switch services to use actual data and dummy data if (environment.useDummyData == false) { //api url apiURL = this.baseUrl + '/api/Company/GetOrganisationFilters'; //send response to component return this._http.get(apiURL) .pipe(map((response: Response) => response.json()), catchError(this.handleError)) } //dummy data for filters var FilterList: SelectItem[] = []; //dummy filter list object FilterList = [ { label: "Internal organisations", value: "Internal organisations" }, { label: "All external organisations", value: "All external organisations" }, { label: "Whytes Chartered Accountants", value: "Whytes Chartered Accountants" }, { label: "XYZ Accounting PH outsource", value: "XYZ Accounting PH outsource" }, { label: "Type:Outsource", value: "Type:Outsource" }, { label: "Type:Affiliate", value: "Type:Affiliate" }, { label: "Industry:Accounting", value: "Industry:Accounting" }, { label: "Industry:Marketing", value: "Industry:Marketing" }, ] //return dummy response to Component return this._http.get(apiURL) .pipe(map((response: Response) => FilterList), catchError(this.handleError)) } getMonthYearFilters(): Observable { let apiURL = ''; // ------------ uncomment and configure this to call api ----------- // this 'if' will switch services to use actual data and dummy data //if (environment.useDummyData == false) { //apiURL = this.baseUrl + ''; // return this._http.get(this.apiURL, options) // .pipe(map((response: Response) => response.json()), // catchError(this.handleError)) //} //dummy data for filters var FilterList: SelectItem[] = []; var years = ["2010","2011","2012","2013","2014","2015","2016","2017","2018","2019"]; var months = ["1","2","3","4","5","6","7","8","9","10","11","12"]; for(var year in years){ for(var month in months){ var labelVal = months[month] + "-" + years[year]; var valueVal = years[year] +"-"+months[month]+"-01"; FilterList.push({ label : labelVal, value : valueVal}); } } //dummy filter list object // FilterList = [ // { label: "Jan-2019", value: "2019-01-01" }, // { label: "Feb-2019", value: "2019-02-01" }, // { label: "Mar-2019", value: "2019-03-01" }, // ] //return dummy response to Component return this._http.get(apiURL) .pipe(map((response: Response) => FilterList), catchError(this.handleError)) } getPersonTypeFilters(id?: string): Observable { let apiURL =''; let myparams = new URLSearchParams(); myparams.append("id", id); let options = new RequestOptions({ params: myparams }); // ------------ uncomment and configure this to call api ----------- if (environment.useDummyData == false) { return this._http.get(this.getPersonTypeFilterUrl, options) .pipe(map((response: Response) => response.json()), catchError(this.handleError)); } //dummy data for filters var FilterList: SelectItem[] = []; //dummy filter list object FilterList = [ { label: "Role:Partner", value: "Role:Partner" }, { label: "Role:Manager", value: "Role:Manager" }, { label: "Des Whyte", value: "Des Whyte" }, { label: "Vin leon", value: "Vin leon" }, ] //return dummy response to Component return this._http.get(apiURL) .pipe(map((response: Response) => FilterList), catchError(this.handleError)) } getStaffLoggedTime(dateRange: string, filterBy: string, FilterSearch: string): Observable { let apiURL =''; // ------------ uncomment and configure this to call api ----------- // this 'if' will switch services to use actual data and dummy data if (environment.useDummyData == false) { apiURL = this.baseUrl + ''; // return this._http.get(this.apiURL, options) // .pipe(map((response: Response) => response.json()), // catchError(this.handleError)) } //dummy data for filters var LoggedTimeList: IStaffLoggedTime[] = []; var dateList = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']; //dummy staff logged time list object LoggedTimeList = [ { Id: 1, Staff: "Van le", Data: { labels: dateList, datasets: [ { label: 'Non-billable', backgroundColor: '#e02365', borderColor: '#e02365', data: [9, 6, 3, 2, 5, 8, 6] }, { label: 'Billable', backgroundColor: '#9CCC65', borderColor: '#7CB342', data: [5, 2, 5, 4, 2, 6, 3] } ] } }, { Id: 2, Staff: "Vin leong", Data: { labels: dateList, datasets: [ { label: 'Non-billable', backgroundColor: '#e02365', borderColor: '#e02365', data: [1, 2, 5, 7, 4, 5, 6] }, { label: 'Billable', backgroundColor: '#9CCC65', borderColor: '#7CB342', data: [9, 5, 4, 6, 2, 8, 5] } ] } } ]; //return dummy response to Component return this._http.get(apiURL) .pipe(map((response: Response) => LoggedTimeList), catchError(this.handleError)) } //The function of handling the error private handleError(error: Response) { console.log("Error in login history service"); console.log(error); return Observable.throw(error.json().error || 'Server error'); } }