Просмотр исходного кода

Hooked up the advanced search button to the clientData, so it shows when configured, and restricts the number of search items.

jalbr74 6 лет назад
Родитель
Сommit
b40e17ae21

+ 12 - 15
client/src/modules/peoplesearch/peoplesearch-base.component.ts

@@ -20,9 +20,9 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-
+import * as angular from 'angular';
 import {isArray, isString, IPromise, IQService, IScope, ITimeoutService} from 'angular';
-import { IPeopleSearchConfigService } from '../../services/peoplesearch-config.service';
+import {AdvancedSearchConfig, IPeopleSearchConfigService} from '../../services/peoplesearch-config.service';
 import { IPeopleService } from '../../services/people.service';
 import IPwmService from '../../services/pwm.service';
 import LocalStorageService from '../../services/local-storage.service';
@@ -32,19 +32,9 @@ import SearchResult from '../../models/search-result.model';
 
 abstract class PeopleSearchBaseComponent {
     advancedSearch = false;
-    advancedSearchTags = [
-        { id: 'userKey', label: 'User ID' },
-        { id: 'givenName', label: 'First Name' },
-        { id: 'sn', label: 'Last Name' },
-        { id: 'mail', label: 'Email' },
-        { id: 'telephoneNumber', label: 'Telephone Number' },
-        { id: 'title', label: 'Title' },
-        { id: 'workforceId', label: 'Workforce ID' },
-        { id: 'managerId', label: 'Manager User ID' },
-        { id: '_displayName', label: 'Display Name' },
-        { id: 'displayNames', label: 'Display Names' },
-        { id: 'detail', label: 'Detail' }
-    ];
+    advancedSearchTags = [];
+    advancedSearchEnabled: boolean;
+    advancedSearchMaxRows: number;
     errorMessage: string;
     inputDebounce: number;
     orgChartEnabled: boolean;
@@ -234,6 +224,12 @@ abstract class PeopleSearchBaseComponent {
             this.orgChartEnabled = orgChartEnabled;
         });
 
+        this.configService.advancedSearchConfig().then((advancedSearchConfig: AdvancedSearchConfig) => {
+            this.advancedSearchEnabled = advancedSearchConfig.enabled;
+            this.advancedSearchTags = advancedSearchConfig.attributes;
+            this.advancedSearchMaxRows = advancedSearchConfig.maxRows;
+        });
+
         this.query = this.getSearchText();
 
         // Once <ias-search-box> from ng-ias allows the autofocus attribute, we can remove this code
@@ -260,6 +256,7 @@ abstract class PeopleSearchBaseComponent {
     }
 
     toggleAdvancedSearch(): void {
+        this.query = '';
         this.advancedSearch = !this.advancedSearch;
     }
 

+ 3 - 2
client/src/modules/peoplesearch/peoplesearch-cards.component.html

@@ -30,7 +30,7 @@
     </ias-search-box>
 
     <ias-button id="advanced-search-icon" class="ias-icon-button" ng-click="$ctrl.toggleAdvancedSearch()"
-                ng-if="!$ctrl.advancedSearch"
+                ng-if="!$ctrl.advancedSearch && $ctrl.advancedSearchEnabled"
                 ng-attr-title="{{ 'Title_AdvancedSearch' | translate }}">
         <ias-icon class="ias-selected" icon="search_advanced"></ias-icon>
     </ias-button>
@@ -60,7 +60,7 @@
     <div ng-repeat="query in $ctrl.queries">
         <select ng-model="query.name">
             <option value="" selected disabled>{{ 'Display_SelectAttribute' | translate }}</option>
-            <option ng-repeat="tag in $ctrl.advancedSearchTags" ng-attr-value="{{tag.id}}">{{tag.label}}</option>
+            <option ng-repeat="tag in $ctrl.advancedSearchTags" ng-attr-value="{{tag.id}}">{{tag.attribute}}</option>
         </select>
         <input ng-model="query.value" autocomplete="off">
         <ias-button class="ias-icon-button" ng-click="$ctrl.removeSearchTag($index)" ng-if="$index > 0"
@@ -71,6 +71,7 @@
 
     <br>
     <ias-button id="advanced-search-icon" class="ias-icon-button" ng-click="$ctrl.addSearchTag()"
+                ng-if="$ctrl.queries.length < $ctrl.advancedSearchMaxRows"
                 ng-attr-title="{{ 'Button_AddSearchAttribute' | translate }}">
         <ias-icon icon="new_thin"></ias-icon>
     </ias-button>

+ 22 - 1
client/src/services/peoplesearch-config.service.dev.ts

@@ -24,7 +24,7 @@
 import { IPromise, IQService } from 'angular';
 import {ConfigBaseService} from './base-config.service.dev';
 import {IConfigService} from './base-config.service';
-import {IPeopleSearchConfigService} from './peoplesearch-config.service';
+import {AdvancedSearchConfig, IPeopleSearchConfigService} from './peoplesearch-config.service';
 
 
 export default class ConfigService
@@ -56,4 +56,25 @@ export default class ConfigService
     orgChartShowChildCount(): IPromise<boolean> {
         return this.$q.resolve(true);
     }
+
+    advancedSearchConfig(): IPromise<AdvancedSearchConfig> {
+        return this.$q.resolve({
+            enabled: true,
+            maxRows: 3,
+            attributes: [
+                {
+                    id: 'title',
+                    attribute: 'Title'
+                },
+                {
+                    id: 'givenName',
+                    attribute: 'Given Name'
+                },
+                {
+                    id: 'sn',
+                    attribute: 'First Name'
+                }
+            ]
+        });
+    }
 }

+ 27 - 0
client/src/services/peoplesearch-config.service.ts

@@ -29,11 +29,24 @@ import {ConfigBaseService, IConfigService} from './base-config.service';
 const ORGCHART_ENABLED = 'orgChartEnabled';
 const ORGCHART_MAX_PARENTS = 'orgChartMaxParents';
 const ORGCHART_SHOW_CHILD_COUNT = 'orgChartShowChildCount';
+const ADVANCED_SEARCH_ENABLED = 'enableAdvancedSearch';
+const ADVANCED_SEARCH_MAX_ATTRIBUTES = 'maxAdvancedSearchAttributes';
+const ADVANCED_SEARCH_ATTRIBUTES = 'advancedSearchAttributes';
+
+export interface AdvancedSearchConfig {
+    enabled: boolean;
+    maxRows: number;
+    attributes: {
+        'id': string;
+        'attribute': string;
+    }[];
+}
 
 export interface IPeopleSearchConfigService extends IConfigService {
     getOrgChartMaxParents(): IPromise<number>;
     orgChartEnabled(): IPromise<boolean>;
     orgChartShowChildCount(): IPromise<boolean>;
+    advancedSearchConfig(): IPromise<AdvancedSearchConfig>;
 }
 
 export default class PeopleSearchConfigService
@@ -57,4 +70,18 @@ export default class PeopleSearchConfigService
     orgChartShowChildCount(): IPromise<boolean> {
         return this.getValue(ORGCHART_SHOW_CHILD_COUNT);
     }
+
+    advancedSearchConfig(): IPromise<AdvancedSearchConfig> {
+        return this.$q.all([
+            this.getValue(ADVANCED_SEARCH_ENABLED),
+            this.getValue(ADVANCED_SEARCH_MAX_ATTRIBUTES),
+            this.getValue(ADVANCED_SEARCH_ATTRIBUTES)
+        ]).then((result) => {
+            return {
+                enabled: result[0],
+                maxRows: result[1],
+                attributes: result[2]
+            };
+        });
+    }
 }