import { Injectable } from '@angular/core'; import * as global from '../core/Common'; import 'rxjs/add/operator/do'; import 'rxjs/add/operator/catch'; import 'rxjs/add/operator/map'; import 'rxjs/add/observable/throw'; import { Http, Response } from '@angular/http'; import { Observable, throwError } from 'rxjs'; import { IQuestions } from '../core/Questionnaire/IQuestions'; import { IQuestionAnswerTypes } from '../core/Questionnaire/IQuestionAnswerTypes'; import { IPhaseSettings } from '../core/Questionnaire/IPhaseSettings'; import { ITypeDateFormats } from '../core/Questionnaire/ITypeDateFormats'; import { ITypeDateFormatSymbols } from '../core/Questionnaire/ITypeDateFormatSymbols'; import { ITypeTimeFormats } from '../core/Questionnaire/ITypeTimeFormats'; import { ITypeChoises } from '../core/Questionnaire/ITypeChoises'; import { ITypeChoiceAllignments } from '../core/Questionnaire/ITypeChoiceAllignments'; import { ITypeMultiSelections } from '../core/Questionnaire/ITypeMultiSelections'; import { ITypeScales } from '../core/Questionnaire/ITypeScales'; @Injectable({ providedIn: 'root' }) export class QuestionnaireService { private InsertPhaseURL = global.serverBase + 'Questionnaire/InsertPhase'; private InsertQuestionnaireURL = global.serverBase + 'Questionnaire/InsertQuestionnaire'; private GetAllIQuestionAnswerTypesURL = global.serverBase + 'Questionnaire/GetAllQuestionAnswerTypes'; private GetAllPhaseSettingTypesURL = global.serverBase + 'Questionnaire/GetAllPhaseSettings'; private GetAllTypeDateFormatsURL = global.serverBase + 'Questionnaire/GetAllTypeDateFormats'; private GetAllITypeDateFormatSymbolsURL = global.serverBase + 'Questionnaire/GetAllTypeDateFormatSymbols'; private GetTypeTimeFormatsURL = global.serverBase + 'Questionnaire/GetTypeTimeFormats'; private GetAllChoisesURL = global.serverBase + 'Questionnaire/GetAllTypeChoises'; private GetAllTypeChoiceAllignmentsURL = global.serverBase + 'Questionnaire/GetAllTypeChoiceAllignments'; private GetAllTypeMultiSelectionsURL = global.serverBase + 'Questionnaire/GetAllTypeMultiSelections'; private GetAllTypeScalesURL = global.serverBase + 'Questionnaire/GetAllTypeScales'; constructor(private http: Http) { } // Insert phase InsertPhaseName(phaseSettingsId: number, jobPlanId: number, phaseName: string) { const urlSearchParams = new URLSearchParams(); urlSearchParams.append('phaseSettingsId', phaseSettingsId.toString()); urlSearchParams.append('jobPlanId', jobPlanId.toString()); urlSearchParams.append('phaseDescription', phaseName.toString()); const body = urlSearchParams.toString(); return this.http.get(this.InsertPhaseURL, { params: body }) .map((response: Response) => response.json() as boolean) .catch(this.handleError); } // Insert Questionnaire InsertQuestionnaire(questions: IQuestions[]) { return this.http.post(this.InsertQuestionnaireURL, questions) .map((response: Response) => response.json() as boolean) .catch(this.handleError); } // Get All Question & Answer Types GetAllIQuestionAnswerTypes() { return this.http.get(this.GetAllIQuestionAnswerTypesURL) .map((response: Response) => response.json() as IQuestionAnswerTypes[]) .catch(this.handleError); } // Get All Phase Settings Types GetAllPhaseSettingTypes() { return this.http.get(this.GetAllPhaseSettingTypesURL) .map((response: Response) => response.json() as IPhaseSettings[]) .catch(this.handleError); } // Get Date Format GetAllTypeDateFormats() { return this.http.get(this.GetAllTypeDateFormatsURL) .map((response: Response) => response.json() as ITypeDateFormats[]) .catch(this.handleError); } // Date Symbols GetAllTypeDateFormatSymbols() { return this.http.get(this.GetAllITypeDateFormatSymbolsURL) .map((response: Response) => response.json() as ITypeDateFormatSymbols[]) .catch(this.handleError); } // Time Format GetTypeTimeFormats() { return this.http.get(this.GetTypeTimeFormatsURL) .map((response: Response) => response.json() as ITypeTimeFormats[]) .catch(this.handleError); } // Get Choises GetAllChoises() { return this.http.get(this.GetAllChoisesURL) .map((response: Response) => response.json() as ITypeChoises[]) .catch(this.handleError); } // Get All Choice Allingments GetAllChoiceAllignments() { return this.http.get(this.GetAllTypeChoiceAllignmentsURL) .map((response: Response) => response.json() as ITypeChoiceAllignments[]) .catch(this.handleError); } // Multiple Selection GetAllMultipleSelections() { return this.http.get(this.GetAllTypeMultiSelectionsURL) .map((response: Response) => response.json() as ITypeMultiSelections[]) .catch(this.handleError); } // Get All Scale Types GetAllScales() { return this.http.get(this.GetAllTypeScalesURL) .map((response: Response) => response.json() as ITypeScales[]) .catch(this.handleError); } // Error handle private handleError(error): Observable { const message = error.statusText || 'Server error'; return throwError(error); } }