From d4ffb24b41c56f353ab0b42c5f926691c71b4e4e Mon Sep 17 00:00:00 2001 From: Robert Kovacs Date: Sat, 14 Nov 2020 20:10:34 +0100 Subject: [PATCH] AnswerFilter mdl rm observerId add observerPhone (#259) * AnswerFilter mdl rm observerId add observerPhone Added phoneObserver param to srvc Filter by observerPhone instead of observerId * added translations * add observer phone number filter Co-authored-by: Irina Borozan --- .../components/answer/answer.component.html | 145 ++++-------- src/app/components/answer/answer.component.ts | 12 +- src/app/models/answer.filters.model.ts | 2 +- src/app/services/answers.service.ts | 44 ++-- src/app/store/answer/answer.effects.ts | 8 +- src/app/store/answer/answer.reducer.ts | 210 ++++++++---------- src/assets/i18n/en.json | 1 + src/assets/i18n/ro.json | 1 + 8 files changed, 175 insertions(+), 248 deletions(-) diff --git a/src/app/components/answer/answer.component.html b/src/app/components/answer/answer.component.html index a121b682..92cab03e 100644 --- a/src/app/components/answer/answer.component.html +++ b/src/app/components/answer/answer.component.html @@ -1,112 +1,49 @@
-
-
- - -
-
- - -
-
- - -
-
- - -
-
- - + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+ + +
-
- - +
+
+ + +
-
-
-

- {{ - ((answerState | async)?.urgent - ? "URGENT_HEADER" - : "NOT_URGENT_HEADER" - ) | translate - }} -

-

- {{ - ((answerState | async)?.urgent - ? "URGENT_SUBHEADER" - : "NOT_URGENT_SUBHEADER" - ) | translate - }} -

- -
+
+

{{((answerState | async)?.urgent ? 'URGENT_HEADER' : 'NOT_URGENT_HEADER') | translate}}

+
{{((answerState | async)?.urgent ? 'URGENT_SUBHEADER' : 'NOT_URGENT_SUBHEADER') | translate}}
+
-
-
- - -
-
- -
+
+ + +
+
+ +
diff --git a/src/app/components/answer/answer.component.ts b/src/app/components/answer/answer.component.ts index 889bb354..44893bad 100644 --- a/src/app/components/answer/answer.component.ts +++ b/src/app/components/answer/answer.component.ts @@ -23,7 +23,7 @@ export class AnswerComponent implements OnInit { countyCode: string; pollingStationNumber: string; - observerId: number; + observerPhone: number; isUrgent: boolean; fromTime: string; toTime: string; @@ -41,13 +41,13 @@ export class AnswerComponent implements OnInit { this.isUrgent = value.urgent || false; this.countyCode = value.answerFilters.county; this.pollingStationNumber = value.answerFilters.pollingStationNumber; - this.observerId = value.answerFilters.observerId; + this.observerPhone = value.answerFilters.observerPhone; }); } requestFilteredData() { this.store.dispatch(new LoadAnswerPreviewAction(this.isUrgent, 1, 5, true, { - observerId: this.observerId, + observerPhone: this.observerPhone, pollingStationNumber: this.pollingStationNumber, county: this.countyCode })); @@ -81,7 +81,7 @@ export class AnswerComponent implements OnInit { resetFilters(): void { this.countyCode = null; this.pollingStationNumber = null; - this.observerId = null; + this.observerPhone = null; this.fromTime = null; this.toTime = null; } @@ -104,8 +104,8 @@ export class AnswerComponent implements OnInit { filter.pollingStationNumber = this.pollingStationNumber as any; } - if (this.isValidValue(this.observerId)) { - filter.idObserver = this.observerId; + if (this.isValidValue(this.observerPhone)) { + filter.phoneObserver = this.observerPhone; } if (this.isValidValue(this.fromTime)) { diff --git a/src/app/models/answer.filters.model.ts b/src/app/models/answer.filters.model.ts index fff6384a..aa5d773c 100644 --- a/src/app/models/answer.filters.model.ts +++ b/src/app/models/answer.filters.model.ts @@ -1,5 +1,5 @@ export class AnswerFilters { - observerId: number = null; + observerPhone: number = null; pollingStationNumber: string = null; county: string = null; } diff --git a/src/app/services/answers.service.ts b/src/app/services/answers.service.ts index d357c64f..52db6fd1 100644 --- a/src/app/services/answers.service.ts +++ b/src/app/services/answers.service.ts @@ -1,35 +1,37 @@ -import { environment } from 'src/environments/environment'; +import { environment } from '../../environments/environment'; import { Location } from '@angular/common'; import { Injectable } from '@angular/core'; import { ApiService, QueryParamBuilder } from '../core/apiService/api.service'; @Injectable() export class AnswersService { - private baseUrl: string; + private baseUrl: string; - constructor(private http: ApiService) { - this.baseUrl = environment.apiUrl; - } + constructor(private http: ApiService) { + this.baseUrl = environment.apiUrl; + } - downloadAnswers(filter: AnswersPackFilter) { - let paramBuilder = QueryParamBuilder.Instance('/api/v1/export/all'); + downloadAnswers(filter: AnswersPackFilter) { + let paramBuilder = QueryParamBuilder + .Instance('/api/v1/export/all'); - for (const key in filter) { - const value = filter[key]; - paramBuilder = paramBuilder.withParam(key, value); - } - const urlWithParams = paramBuilder.build(); + for (const key in filter) { + const value = filter[key]; + paramBuilder = paramBuilder.withParam(key, value); + } + const urlWithParams = paramBuilder.build(); - const url: string = Location.joinWithSlash(this.baseUrl, urlWithParams); - return this.http.get(url, { responseType: 'blob' as 'json' }); - } + const url: string = Location.joinWithSlash(this.baseUrl, urlWithParams); + return this.http.get(url, {responseType: 'blob' as 'json'}); + } } export interface AnswersPackFilter { - idNgo?: number; - idObserver?: number; - pollingStationNumber?: number; - county?: string; - from?: string; - to?: string; + idNgo?: number; + idObserver?: number; + phoneObserver?: number; + pollingStationNumber?: number; + county?: string; + from?: string; + to?: string; } diff --git a/src/app/store/answer/answer.effects.ts b/src/app/store/answer/answer.effects.ts index 04cbd7a3..9b7cd739 100644 --- a/src/app/store/answer/answer.effects.ts +++ b/src/app/store/answer/answer.effects.ts @@ -110,10 +110,10 @@ export class AnswerEffects { : params.append('county', payload.answerFilters.county); params = isNil(payload.answerFilters.pollingStationNumber) ? params - : params.append( - 'pollingStationNumber', - payload.answerFilters.pollingStationNumber - ); + : params.append('pollingStationNumber', payload.answerFilters.pollingStationNumber); + params = isNil(payload.answerFilters.observerPhone) + ? params + : params.append('observerPhoneNumber', payload.answerFilters.observerPhone.toString()); params = isNil(payload.urgent) ? params : params.append('urgent', payload.urgent.toString()); diff --git a/src/app/store/answer/answer.reducer.ts b/src/app/store/answer/answer.reducer.ts index e77650f3..99512f9a 100644 --- a/src/app/store/answer/answer.reducer.ts +++ b/src/app/store/answer/answer.reducer.ts @@ -6,125 +6,111 @@ import { CompletedQuestion } from '../../models/completed.question.model'; import { AnswerActions, AnswerActionTypes } from './answer.actions'; import { AnswerFilters } from '../../models/answer.filters.model'; export class AnswerState { - threads: AnswerThread[] = []; - urgent: boolean = undefined; - page = 1; - pageSize = 10; - totalItems: number = undefined; - totalPages: number = undefined; - threadsLoading = false; - threadsError = false; + threads: AnswerThread[] = []; + urgent: boolean = undefined; + page = 1; + pageSize = 10; + totalItems: number = undefined; + totalPages: number = undefined; + threadsLoading = false; + threadsError = false; - selectedAnswer: CompletedQuestion[]; - selectedLoading = false; - selectedError = false; - observerId: number; - sectionId: number; + selectedAnswer: CompletedQuestion[]; + selectedLoading = false; + selectedError = false; + observerId: number; + sectionId: number; - notes: Note[]; - notesLoading: boolean; - notesError: boolean; + notes: Note[]; + notesLoading: boolean; + notesError: boolean; - answerExtra: AnswerExtra; - answerExtraLoading = false; - answerExtraError = false; + answerExtra: AnswerExtra; + answerExtraLoading = false; + answerExtraError = false; - answerFilters: AnswerFilters = { - observerId: null, - pollingStationNumber: null, - county: null, - }; + answerFilters: AnswerFilters = { observerPhone: null, pollingStationNumber: null, county: null }; } export let initialAnswerState: AnswerState = new AnswerState(); -export function answerReducer( - state = initialAnswerState, - action: AnswerActions -) { - switch (action.type) { - case AnswerActionTypes.LOAD_PREVIEW: - const newList = - action.payload.refresh || action.payload.urgent !== state.urgent, - shouldLoadList = shouldLoadPage( - action.payload.page, - action.payload.pageSize, - state.threads.length - ); - const shouldUpdateFilters = - Object.keys(action.payload.answerFilters).length > 0; +export function answerReducer(state = initialAnswerState, action: AnswerActions) { + switch (action.type) { + case AnswerActionTypes.LOAD_PREVIEW: + const newList = action.payload.refresh || (action.payload.urgent !== state.urgent), + shouldLoadList = shouldLoadPage(action.payload.page, action.payload.pageSize, state.threads.length); + const shouldUpdateFilters = Object.keys(action.payload.answerFilters).length > 0 ? true : false; - let newState = Object.assign({}, state, { - page: action.payload.page, - answerFilters: shouldUpdateFilters - ? action.payload.answerFilters - : state.answerFilters, - pageSize: action.payload.pageSize, - threads: newList ? [] : state.threads, - threadsLoading: shouldLoadList || newList, - threadsError: false, - urgent: action.payload.urgent, - }); - // if we're loading a new list, deselect any selected answer - if (newList) { - newState = Object.assign({}, newState, { - selectedAnswer: undefined, - selectedLoading: false, - selectedError: false, - observerId: undefined, - sectionId: undefined, - answerExtra: undefined, - answerExtraLoading: false, - answerExtraError: false, - }); - } - return newState; + let newState = Object.assign({}, state, { + page: action.payload.page, + answerFilters: shouldUpdateFilters ? action.payload.answerFilters : state.answerFilters, + pageSize: action.payload.pageSize, + threads: newList ? [] : state.threads, + threadsLoading: shouldLoadList || newList, + threadsError: false, + urgent: action.payload.urgent + }); + // if we're loading a new list, deselect any selected answer + if (newList) { + newState = Object.assign({}, newState, { + selectedAnswer: undefined, + selectedLoading: false, + selectedError: false, + observerId: undefined, + sectionId: undefined, + answerExtra: undefined, + answerExtraLoading: false, + answerExtraError: false + }); + } + return newState; - case AnswerActionTypes.LOAD_PREVIEW_ERROR: - return Object.assign({}, state, { - threadsLoading: false, - threadsError: true, - }); - case AnswerActionTypes.LOAD_PREVIEW_DONE: - return Object.assign({}, state, { - threads: state.threads.concat(action.payload.threads), - totalItems: action.payload.totalItems, - totalPages: action.payload.totalPages, - threadsLoading: false, - threadsError: false, - }); - case AnswerActionTypes.LOAD_DETAILS: - return Object.assign({}, state, action.payload, { - selectedLoading: true, - selectedError: false, - }); - case AnswerActionTypes.LOAD_DETAILS_ERROR: - return Object.assign({}, state, { - selectedLoading: false, - selectedError: true, - }); - case AnswerActionTypes.LOAD_DETAILS_DONE: - return Object.assign({}, state, { - selectedAnswer: action.payload, - selectedLoading: false, - selectedError: false, - }); - case AnswerActionTypes.LOAD_EXTRA: - return Object.assign({}, state, { - answerExtraLoading: false, - answerExtraError: false, - }); - case AnswerActionTypes.LOAD_EXTRA_DONE: - return Object.assign({}, state, { - answerExtra: action.payload, - answerExtraLoading: false, - selectedError: false, - }); - case AnswerActionTypes.LOAD_EXTRA_ERROR: - return Object.assign({}, state, { - answerExtraLoading: false, - selectedError: true, - }); - default: - return state; - } + case AnswerActionTypes.LOAD_PREVIEW_ERROR: + return Object.assign({}, state, { + threadsLoading: false, + threadsError: true, + + }); + case AnswerActionTypes.LOAD_PREVIEW_DONE: + return Object.assign({}, state, { + threads: state.threads.concat(action.payload.threads), + totalItems: action.payload.totalItems, + totalPages: action.payload.totalPages, + threadsLoading: false, + threadsError: false + }); + case AnswerActionTypes.LOAD_DETAILS: + return Object.assign({}, state, action.payload, { + selectedLoading: true, + selectedError: false + }); + case AnswerActionTypes.LOAD_DETAILS_ERROR: + return Object.assign({}, state, { + selectedLoading: false, + selectedError: true + }); + case AnswerActionTypes.LOAD_DETAILS_DONE: + return Object.assign({}, state, { + selectedAnswer: action.payload, + selectedLoading: false, + selectedError: false + }); + case AnswerActionTypes.LOAD_EXTRA: + return Object.assign({}, state, { + answerExtraLoading: false, + answerExtraError: false + }); + case AnswerActionTypes.LOAD_EXTRA_DONE: + return Object.assign({}, state, { + answerExtra: action.payload, + answerExtraLoading: false, + selectedError: false + }); + case AnswerActionTypes.LOAD_EXTRA_ERROR: + return Object.assign({}, state, { + answerExtraLoading: false, + selectedError: true + }); + default: + return state; + } } diff --git a/src/assets/i18n/en.json b/src/assets/i18n/en.json index b613fe66..60cc3688 100644 --- a/src/assets/i18n/en.json +++ b/src/assets/i18n/en.json @@ -56,6 +56,7 @@ "FILTER_BY": "Filter by:", "COUNTY_CODE": "County:", "OBSERVER_ID": "Observer Id:", + "OBSERVER_PHONE": "Observer Phone Number:", "POLLING_STATION_NUMBER": "Polling station number:", "NOTIFICATIONS": "Notifications", "COUNTIES": "Counties", diff --git a/src/assets/i18n/ro.json b/src/assets/i18n/ro.json index ebbf6e8f..a7af5833 100644 --- a/src/assets/i18n/ro.json +++ b/src/assets/i18n/ro.json @@ -56,6 +56,7 @@ "FILTER_BY": "Filtreaza după:", "COUNTY_CODE": "Județ:", "OBSERVER_ID": "Id-ul observatorului:", + "OBSERVER_PHONE": "Telefonul observatorului:", "POLLING_STATION_NUMBER": "Numărul secției de votare:", "DOWNLOAD_ANSWERS": "Descarca raspunsuri", "FROM": "De la",