|
@@ -27,15 +27,18 @@ import {isArray, isString, IPromise, IQService, IScope} from 'angular';
|
|
import {IPerson} from '../models/person.model';
|
|
import {IPerson} from '../models/person.model';
|
|
import {IHelpDeskConfigService} from '../services/helpdesk-config.service';
|
|
import {IHelpDeskConfigService} from '../services/helpdesk-config.service';
|
|
import LocalStorageService from '../services/local-storage.service';
|
|
import LocalStorageService from '../services/local-storage.service';
|
|
|
|
+import PromiseService from '../services/promise.service';
|
|
|
|
|
|
let verificationsDialogTemplateUrl = require('./verifications-dialog.template.html');
|
|
let verificationsDialogTemplateUrl = require('./verifications-dialog.template.html');
|
|
let recentVerificationsDialogTemplateUrl = require('./recent-verifications-dialog.template.html');
|
|
let recentVerificationsDialogTemplateUrl = require('./recent-verifications-dialog.template.html');
|
|
|
|
|
|
export default abstract class HelpDeskSearchBaseComponent {
|
|
export default abstract class HelpDeskSearchBaseComponent {
|
|
columnConfiguration: any;
|
|
columnConfiguration: any;
|
|
|
|
+ errorMessage: string;
|
|
protected pendingRequests: IPromise<any>[] = [];
|
|
protected pendingRequests: IPromise<any>[] = [];
|
|
photosEnabled: boolean;
|
|
photosEnabled: boolean;
|
|
query: string;
|
|
query: string;
|
|
|
|
+ searchMessage: string;
|
|
searchResult: SearchResult;
|
|
searchResult: SearchResult;
|
|
searchTextLocalStorageKey: string;
|
|
searchTextLocalStorageKey: string;
|
|
searchViewLocalStorageKey: string;
|
|
searchViewLocalStorageKey: string;
|
|
@@ -45,10 +48,12 @@ export default abstract class HelpDeskSearchBaseComponent {
|
|
constructor(protected $q: IQService,
|
|
constructor(protected $q: IQService,
|
|
protected $scope: IScope,
|
|
protected $scope: IScope,
|
|
protected $stateParams: angular.ui.IStateParamsService,
|
|
protected $stateParams: angular.ui.IStateParamsService,
|
|
|
|
+ protected $translate: angular.translate.ITranslateService,
|
|
protected configService: IHelpDeskConfigService,
|
|
protected configService: IHelpDeskConfigService,
|
|
protected IasDialogService: any,
|
|
protected IasDialogService: any,
|
|
protected localStorageService: LocalStorageService,
|
|
protected localStorageService: LocalStorageService,
|
|
- protected peopleService: IPeopleService) {
|
|
|
|
|
|
+ protected peopleService: IPeopleService,
|
|
|
|
+ protected promiseService: PromiseService) {
|
|
this.searchTextLocalStorageKey = this.localStorageService.keys.HELPDESK_SEARCH_TEXT;
|
|
this.searchTextLocalStorageKey = this.localStorageService.keys.HELPDESK_SEARCH_TEXT;
|
|
this.searchViewLocalStorageKey = this.localStorageService.keys.HELPDESK_SEARCH_VIEW;
|
|
this.searchViewLocalStorageKey = this.localStorageService.keys.HELPDESK_SEARCH_VIEW;
|
|
|
|
|
|
@@ -65,6 +70,10 @@ export default abstract class HelpDeskSearchBaseComponent {
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ getMessage(): string {
|
|
|
|
+ return this.errorMessage || this.searchMessage;
|
|
|
|
+ }
|
|
|
|
+
|
|
private getSearchText(): string {
|
|
private getSearchText(): string {
|
|
let param: string = this.$stateParams['query'];
|
|
let param: string = this.$stateParams['query'];
|
|
// If multiple query parameters are defined, use the first one
|
|
// If multiple query parameters are defined, use the first one
|
|
@@ -80,12 +89,20 @@ export default abstract class HelpDeskSearchBaseComponent {
|
|
|
|
|
|
abstract fetchData(): void;
|
|
abstract fetchData(): void;
|
|
|
|
|
|
|
|
+ protected clearSearch(): void {
|
|
|
|
+ this.query = null;
|
|
|
|
+ this.searchResult = null;
|
|
|
|
+ this.clearErrorMessage();
|
|
|
|
+ this.clearSearchMessage();
|
|
|
|
+ this.abortPendingRequests();
|
|
|
|
+ }
|
|
|
|
+
|
|
protected fetchSearchData(): IPromise<void | SearchResult> {
|
|
protected fetchSearchData(): IPromise<void | SearchResult> {
|
|
- // this.abortPendingRequests();
|
|
|
|
|
|
+ this.abortPendingRequests();
|
|
this.searchResult = null;
|
|
this.searchResult = null;
|
|
|
|
|
|
if (!this.query) {
|
|
if (!this.query) {
|
|
- // this.clearSearch();
|
|
|
|
|
|
+ this.clearSearch();
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -94,9 +111,9 @@ export default abstract class HelpDeskSearchBaseComponent {
|
|
|
|
|
|
return promise
|
|
return promise
|
|
.then(
|
|
.then(
|
|
- (searchResult: SearchResult) => {
|
|
|
|
- // self.clearErrorMessage();
|
|
|
|
- // self.clearSearchMessage();
|
|
|
|
|
|
+ function(searchResult: SearchResult) {
|
|
|
|
+ this.clearErrorMessage();
|
|
|
|
+ this.clearSearchMessage();
|
|
|
|
|
|
// Aborted request
|
|
// Aborted request
|
|
if (!searchResult) {
|
|
if (!searchResult) {
|
|
@@ -104,24 +121,24 @@ export default abstract class HelpDeskSearchBaseComponent {
|
|
}
|
|
}
|
|
|
|
|
|
// Too many results returned
|
|
// Too many results returned
|
|
- // if (searchResult.sizeExceeded) {
|
|
|
|
- // self.setSearchMessage('Display_SearchResultsExceeded');
|
|
|
|
- // }
|
|
|
|
|
|
+ if (searchResult.sizeExceeded) {
|
|
|
|
+ this.setSearchMessage('Display_SearchResultsExceeded');
|
|
|
|
+ }
|
|
|
|
|
|
// No results returned. Not an else if statement so that the more important message is presented
|
|
// No results returned. Not an else if statement so that the more important message is presented
|
|
- // if (!searchResult.people.length) {
|
|
|
|
- // self.setSearchMessage('Display_SearchResultsNone');
|
|
|
|
- // }
|
|
|
|
|
|
+ if (!searchResult.people.length) {
|
|
|
|
+ this.setSearchMessage('Display_SearchResultsNone');
|
|
|
|
+ }
|
|
|
|
|
|
return this.$q.resolve(searchResult);
|
|
return this.$q.resolve(searchResult);
|
|
- },
|
|
|
|
- (error) => {
|
|
|
|
- /*self.setErrorMessage(error);
|
|
|
|
- self.clearSearchMessage();*/
|
|
|
|
- })
|
|
|
|
- .finally(() => {
|
|
|
|
- // self.removePendingRequest(promise);
|
|
|
|
- });
|
|
|
|
|
|
+ }.bind(this),
|
|
|
|
+ function(error) {
|
|
|
|
+ this.setErrorMessage(error);
|
|
|
|
+ this.clearSearchMessage();
|
|
|
|
+ }.bind(this))
|
|
|
|
+ .finally(function() {
|
|
|
|
+ this.removePendingRequest(promise);
|
|
|
|
+ }.bind(this));
|
|
}
|
|
}
|
|
|
|
|
|
private onSearchTextChange(newValue: string, oldValue: string): void {
|
|
private onSearchTextChange(newValue: string, oldValue: string): void {
|
|
@@ -130,11 +147,55 @@ export default abstract class HelpDeskSearchBaseComponent {
|
|
}
|
|
}
|
|
|
|
|
|
this.storeSearchText();
|
|
this.storeSearchText();
|
|
- // this.clearSearchMessage();
|
|
|
|
- // this.clearErrorMessage();
|
|
|
|
|
|
+ this.clearSearchMessage();
|
|
|
|
+ this.clearErrorMessage();
|
|
this.fetchData();
|
|
this.fetchData();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ protected abortPendingRequests() {
|
|
|
|
+ for (let index = 0; index < this.pendingRequests.length; index++) {
|
|
|
|
+ let pendingRequest = this.pendingRequests[index];
|
|
|
|
+ this.promiseService.abort(pendingRequest);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ this.pendingRequests = [];
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ protected setErrorMessage(message: string) {
|
|
|
|
+ this.errorMessage = message;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ protected clearErrorMessage() {
|
|
|
|
+ this.errorMessage = null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // If message is a string it will be translated. If it is a promise it will assign the string from the resolved
|
|
|
|
+ // promise
|
|
|
|
+ protected setSearchMessage(translationKey: string) {
|
|
|
|
+ if (!translationKey) {
|
|
|
|
+ this.clearSearchMessage();
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ const self = this;
|
|
|
|
+ this.$translate(translationKey.toString())
|
|
|
|
+ .then((translation: string) => {
|
|
|
|
+ self.searchMessage = translation;
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ protected clearSearchMessage(): void {
|
|
|
|
+ this.searchMessage = null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ protected removePendingRequest(promise: IPromise<any>) {
|
|
|
|
+ let index = this.pendingRequests.indexOf(promise);
|
|
|
|
+
|
|
|
|
+ if (index > -1) {
|
|
|
|
+ this.pendingRequests.splice(index, 1);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
protected selectPerson(person: IPerson): void {
|
|
protected selectPerson(person: IPerson): void {
|
|
this.IasDialogService
|
|
this.IasDialogService
|
|
.open({
|
|
.open({
|