Преглед на файлове

Merge pull request #165 from rkeil-git/master

thanks!
Jason преди 8 години
родител
ревизия
581960d6ef

+ 4 - 4
src/main/angular/src/models/orgchart-data.model.ts

@@ -21,10 +21,10 @@
  */
 
 
-import Person from './person.model';
+import { IPerson } from './person.model';
 export default class OrgChartData {
 
-    constructor(public manager: Person,
-                public children: Person[],
-                public self: Person) {}
+    constructor(public manager: IPerson,
+                public children: IPerson[],
+                public self: IPerson) {}
 }

+ 13 - 34
src/main/angular/src/models/person.model.ts

@@ -21,45 +21,24 @@
  */
 
 
-export default class Person {
+export interface IPerson {
     // Common properties
-    userKey: string;
-    numDirectReports: number;
+    userKey?: string;
+    numDirectReports?: number;
 
     // Autocomplete properties (via Search)
-    _displayName: string;
+    _displayName?: string;
 
     // Details properties (not available in search)
-    detail: any;
-    displayNames: string[];
-    photoURL: string;
-    links: any[];
+    detail?: any;
+    displayNames?: string[];
+    photoURL?: string;
+    links?: any[];
 
     // Search properties (not available in details)
-    givenName: string;
-    mail: string;
-    sn: string;
-    telephoneNumber: string;
-    title: string;
-
-    constructor(options: any) {
-        // Common properties
-        this.userKey = options.userKey;
-
-        // Autocomplete properties (via Search)
-        this._displayName = options._displayName;
-
-        // Details properties
-        this.detail = options.detail;
-        this.displayNames = options.displayNames;
-        this.photoURL = options.photoURL;
-        this.links = options.links;
-
-        // Search properties
-        this.givenName = options.givenName;
-        this.mail = options.mail;
-        this.sn = options.sn;
-        this.telephoneNumber = options.telephoneNumber;
-        this.title = options.title;
-    }
+    givenName?: string;
+    mail?: string;
+    sn?: string;
+    telephoneNumber?: string;
+    title?: string;
 }

+ 3 - 3
src/main/angular/src/models/search-result.model.ts

@@ -21,14 +21,14 @@
  */
 
 
-import Person from './person.model';
+import { IPerson } from './person.model';
 
 export default class SearchResult {
     sizeExceeded: boolean;
-    people: Person[];
+    people: IPerson[];
 
     constructor(options: any) {
         this.sizeExceeded = options.sizeExceeded;
-        this.people = options.searchResults.map((person: any) => new Person(person));
+        this.people = options.searchResults.map((person: any) => <IPerson>(person));
     }
 }

+ 9 - 9
src/main/angular/src/peoplesearch/orgchart-search.component.ts

@@ -28,17 +28,17 @@ import IPwmService from '../services/pwm.service';
 import { isArray, isString, IPromise, IQService, IScope } from 'angular';
 import LocalStorageService from '../services/local-storage.service';
 import OrgChartData from '../models/orgchart-data.model';
-import Person from '../models/person.model';
+import { IPerson } from '../models/person.model';
 
 @Component({
     stylesheetUrl: require('peoplesearch/orgchart-search.component.scss'),
     templateUrl: require('peoplesearch/orgchart-search.component.html')
 })
 export default class OrgChartSearchComponent {
-    directReports: Person[];
+    directReports: IPerson[];
     inputDebounce: number;
-    managementChain: Person[];
-    person: Person;
+    managementChain: IPerson[];
+    person: IPerson;
     photosEnabled: boolean;
     query: string;
     searchTextLocalStorageKey: string;
@@ -86,7 +86,7 @@ export default class OrgChartSearchComponent {
                 personId = orgChartData.self.userKey;
 
                 self.peopleService.getPerson(personId)
-                    .then((person: Person) => {
+                    .then((person: IPerson) => {
                             self.person = person;
                         },
                         (error) => {
@@ -94,7 +94,7 @@ export default class OrgChartSearchComponent {
                         });
 
                 self.peopleService.getManagementChain(personId)
-                    .then((managementChain: Person[]) => {
+                    .then((managementChain: IPerson[]) => {
                             self.managementChain = managementChain;
                         },
                         (error) => {
@@ -102,7 +102,7 @@ export default class OrgChartSearchComponent {
                         });
 
                 self.peopleService.getDirectReports(personId)
-                    .then((directReports: Person[]) => {
+                    .then((directReports: IPerson[]) => {
                             self.directReports = directReports;
                         },
                         (error) => {
@@ -114,7 +114,7 @@ export default class OrgChartSearchComponent {
             });
     }
 
-    autoCompleteSearch(query: string): IPromise<Person[]> {
+    autoCompleteSearch(query: string): IPromise<IPerson[]> {
         return this.peopleService.autoComplete(query);
     }
 
@@ -122,7 +122,7 @@ export default class OrgChartSearchComponent {
         this.$state.go(state, { query: this.query });
     }
 
-    onAutoCompleteItemSelected(person: Person): void {
+    onAutoCompleteItemSelected(person: IPerson): void {
         this.$state.go('orgchart.search', { personId: person.userKey, query: null });
     }
 

+ 7 - 7
src/main/angular/src/peoplesearch/orgchart.component.ts

@@ -24,7 +24,7 @@
 import { Component } from '../component';
 import { element, IAugmentedJQuery, IFilterService, IScope, IWindowService } from 'angular';
 import ElementSizeService from '../ux/element-size.service';
-import Person from '../models/person.model';
+import { IPerson } from '../models/person.model';
 
 export enum OrgChartSize {
     ExtraSmall = 0,
@@ -45,15 +45,15 @@ export enum OrgChartSize {
     templateUrl: require('peoplesearch/orgchart.component.html')
 })
 export default class OrgChartComponent {
-    directReports: Person[];
+    directReports: IPerson[];
     elementWidth: number;
     isExtraLargeLayout: boolean;
-    managementChain: Person[];
-    person: Person;
+    managementChain: IPerson[];
+    person: IPerson;
 
     private elementSize: OrgChartSize = OrgChartSize.ExtraSmall;
     private maxVisibleManagers: number;
-    private visibleManagers: Person[];
+    private visibleManagers: IPerson[];
 
     static $inject = [ '$element', '$filter', '$scope', '$state', '$window', 'MfElementSizeService' ];
     constructor(
@@ -88,7 +88,7 @@ export default class OrgChartComponent {
         return this.isExtraLargeLayout ? 'small' : 'normal';
     }
 
-    getManagementChain(): Person[] {
+    getManagementChain(): IPerson[] {
         // Display managers in a row
         if (this.isExtraLargeLayout) {
             // All managers can fit on screen
@@ -103,7 +103,7 @@ export default class OrgChartComponent {
                 this.visibleManagers = this.managementChain.slice(0, this.maxVisibleManagers - 1);
                 const lastManager = this.managementChain[this.maxVisibleManagers - 2];
 
-                this.visibleManagers.push(new Person({
+                this.visibleManagers.push(<IPerson>({
                     userKey: lastManager.userKey,
                     photoURL: null,
                     displayNames: []

+ 2 - 2
src/main/angular/src/peoplesearch/peoplesearch-base.component.ts

@@ -26,7 +26,7 @@ import { IConfigService } from '../services/config.service';
 import { IPeopleService } from '../services/people.service';
 import IPwmService from '../services/pwm.service';
 import LocalStorageService from '../services/local-storage.service';
-import Person from '../models/person.model';
+import { IPerson } from '../models/person.model';
 import PromiseService from '../services/promise.service';
 import SearchResult from '../models/search-result.model';
 
@@ -92,7 +92,7 @@ abstract class PeopleSearchBaseComponent {
         this.fetchData();
     }
 
-    selectPerson(person: Person): void {
+    selectPerson(person: IPerson): void {
         this.$state.go('.details', { personId: person.userKey, query: this.query });
     }
 

+ 4 - 3
src/main/angular/src/peoplesearch/peoplesearch-cards.component.ts

@@ -29,7 +29,7 @@ import IPwmService from '../services/pwm.service';
 import { isString, IAugmentedJQuery, IQService, IScope } from 'angular';
 import LocalStorageService from '../services/local-storage.service';
 import PeopleSearchBaseComponent from './peoplesearch-base.component';
-import Person from '../models/person.model';
+import { IPerson } from '../models/person.model';
 import PromiseService from '../services/promise.service';
 import SearchResult from '../models/search-result.model';
 
@@ -106,6 +106,7 @@ export default class PeopleSearchCardsComponent extends PeopleSearchBaseComponen
     fetchData() {
         let searchResultPromise = this.fetchSearchData();
         if (searchResultPromise) {
+
             searchResultPromise.then(this.onSearchResult.bind(this));
         }
     }
@@ -124,12 +125,12 @@ export default class PeopleSearchCardsComponent extends PeopleSearchBaseComponen
         let self = this;
 
         this.pendingRequests = searchResult.people.map(
-            (person: Person) => {
+            (person: IPerson) => {
                 // Store this promise because it is abortable
                 let promise = this.peopleService.getPerson(person.userKey);
 
                 promise
-                    .then((person: Person) => {
+                    .then((person: IPerson) => {
                         // Aborted request
                         if (!person) {
                             return;

+ 3 - 3
src/main/angular/src/peoplesearch/person-card.component.ts

@@ -23,7 +23,7 @@
 
 import { isString, IAugmentedJQuery } from 'angular';
 import { Component } from '../component';
-import Person from '../models/person.model';
+import { IPerson } from '../models/person.model';
 import { IPeopleService } from '../services/people.service';
 
 @Component({
@@ -41,8 +41,8 @@ import { IPeopleService } from '../services/people.service';
 export default class PersonCardComponent {
     private details: any[]; // For large style cards
     private disableFocus: boolean;
-    private person: Person;
-    private directReports: Person[];
+    private person: IPerson;
+    private directReports: IPerson[];
     private size: string;
     private showDirectReportCount: boolean;
     private showImage: boolean;

+ 3 - 3
src/main/angular/src/peoplesearch/person-details-dialog.component.ts

@@ -24,15 +24,15 @@
 import { Component } from '../component';
 import { IConfigService } from '../services/config.service';
 import { IPeopleService } from '../services/people.service';
-import Person from '../models/person.model';
 import { IAugmentedJQuery, ITimeoutService } from 'angular';
+import { IPerson } from '../models/person.model';
 
 @Component({
     stylesheetUrl: require('peoplesearch/person-details-dialog.component.scss'),
     templateUrl: require('peoplesearch/person-details-dialog.component.html')
 })
 export default class PersonDetailsDialogComponent {
-    person: Person;
+    person: IPerson;
     photosEnabled: boolean;
     orgChartEnabled: boolean;
 
@@ -60,7 +60,7 @@ export default class PersonDetailsDialogComponent {
         this.peopleService
             .getPerson(personId)
             .then(
-                (person: Person) => {
+                (person: IPerson) => {
                     this.person = person;
                 },
                 (error) => {

+ 3 - 3
src/main/angular/src/peoplesearch/person.filters.ts

@@ -21,10 +21,10 @@
  */
 
 
-import Person from '../models/person.model';
+import { IPerson } from '../models/person.model';
 
-export function FullNameFilter(): (person: Person) => string {
-    return (person: Person): string => {
+export function FullNameFilter(): (person: IPerson) => string {
+    return (person: IPerson): string => {
         return `${person.givenName} ${person.sn}`;
     };
 }

+ 18 - 18
src/main/angular/src/services/people.service.dev.ts

@@ -8,7 +8,7 @@
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
+ * (at your option) any later versionI.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -22,7 +22,7 @@
 
 
 import { IPromise, IQService, ITimeoutService } from 'angular';
-import Person from '../models/person.model';
+import { IPerson } from '../models/person.model';
 import { IPeopleService } from './people.service';
 import OrgChartData from '../models/orgchart-data.model';
 import SearchResult from '../models/search-result.model';
@@ -33,14 +33,14 @@ const MAX_RESULTS = 10;
 const SIMULATED_RESPONSE_TIME = 0;
 
 export default class PeopleService implements IPeopleService {
-    private people: Person[];
+    private people: IPerson[];
 
     static $inject = ['$q', '$timeout' ];
     constructor(private $q: IQService, private $timeout: ITimeoutService) {
-        this.people = peopleData.map((person) => new Person(person));
+        this.people = peopleData.map((person) => <IPerson>(person));
 
         // Create directReports detail (instead of managing this in people.data.json
-        this.people.forEach((person: Person) => {
+        this.people.forEach((person: IPerson) => {
             const directReports = this.findDirectReports(person.userKey);
 
             if (!directReports.length) {
@@ -52,7 +52,7 @@ export default class PeopleService implements IPeopleService {
                 label: 'Direct Reports',
                 type: 'userDN',
                 userReferences: directReports
-                    .map((directReport: Person) => {
+                    .map((directReport: IPerson) => {
                         return {
                             userKey: directReport.userKey,
                             displayName: directReport._displayName
@@ -62,7 +62,7 @@ export default class PeopleService implements IPeopleService {
         }, this);
     }
 
-    autoComplete(query: string): IPromise<Person[]> {
+    autoComplete(query: string): IPromise<IPerson[]> {
         return this.search(query)
             .then((searchResult: SearchResult) => {
                 let people = searchResult.people;
@@ -77,17 +77,17 @@ export default class PeopleService implements IPeopleService {
             });
     }
 
-    getDirectReports(id: string): angular.IPromise<Person[]> {
+    getDirectReports(id: string): angular.IPromise<IPerson[]> {
         const people = this.findDirectReports(id);
 
         return this.$q.resolve(people);
     }
 
-    getManagementChain(id: string): angular.IPromise<Person[]> {
+    getManagementChain(id: string): angular.IPromise<IPerson[]> {
         let person = this.findPerson(id);
 
         if (person) {
-            const managementChain: Person[] = [];
+            const managementChain: IPerson[] = [];
 
             while (person = this.findManager(person)) {
                 managementChain.push(person);
@@ -115,12 +115,12 @@ export default class PeopleService implements IPeopleService {
 
     getNumberOfDirectReports(personId: string): IPromise<number> {
         return this.getDirectReports(personId)
-            .then((directReports: Person[]) => {
+            .then((directReports: IPerson[]) => {
                 return this.$q.resolve(directReports.length);
             });
     }
 
-    getPerson(id: string): IPromise<Person> {
+    getPerson(id: string): IPromise<IPerson> {
         let self = this;
 
         let deferred = this.$q.defer();
@@ -154,7 +154,7 @@ export default class PeopleService implements IPeopleService {
         let deferredAbort = this.$q.defer();
 
         let timeoutPromise = this.$timeout(() => {
-            let people = this.people.filter((person: Person) => {
+            let people = this.people.filter((person: IPerson) => {
                 if (!query) {
                     return false;
                 }
@@ -179,16 +179,16 @@ export default class PeopleService implements IPeopleService {
         return deferred.promise;
     }
 
-    private findDirectReports(id: string): Person[] {
-        return this.people.filter((person: Person) => person.detail['manager']['userReferences'][0].userKey == id);
+    private findDirectReports(id: string): IPerson[] {
+        return this.people.filter((person: IPerson) => person.detail['manager']['userReferences'][0].userKey == id);
     }
 
-    private findManager(person: Person): Person {
+    private findManager(person: IPerson): IPerson {
         return this.findPerson(person.detail['manager']['userReferences'][0].userKey);
     }
 
-    private findPerson(id: string): Person {
-        const people = this.people.filter((person: Person) => person.userKey == id);
+    private findPerson(id: string): IPerson {
+        const people = this.people.filter((person: IPerson) => person.userKey == id);
 
         if (people.length) {
             return people[0];

+ 19 - 19
src/main/angular/src/services/people.service.ts

@@ -22,18 +22,18 @@
 
 
 import { isString, IHttpService, ILogService, IPromise, IQService } from 'angular';
-import Person from '../models/person.model';
+import { IPerson } from '../models/person.model';
 import IPwmService from './pwm.service';
 import OrgChartData from '../models/orgchart-data.model';
 import SearchResult from '../models/search-result.model';
 
 export interface IPeopleService {
-    autoComplete(query: string): IPromise<Person[]>;
-    getDirectReports(personId: string): IPromise<Person[]>;
+    autoComplete(query: string): IPromise<IPerson[]>;
+    getDirectReports(personId: string): IPromise<IPerson[]>;
     getNumberOfDirectReports(personId: string): IPromise<number>;
-    getManagementChain(personId: string): IPromise<Person[]>;
+    getManagementChain(personId: string): IPromise<IPerson[]>;
     getOrgChartData(personId: string, skipChildren: boolean): IPromise<OrgChartData>;
-    getPerson(id: string): IPromise<Person>;
+    getPerson(id: string): IPromise<IPerson>;
     search(query: string): IPromise<SearchResult>;
 }
 
@@ -44,7 +44,7 @@ export default class PeopleService implements IPeopleService {
                 private $q: IQService,
                 private pwmService: IPwmService) {}
 
-    autoComplete(query: string): IPromise<Person[]> {
+    autoComplete(query: string): IPromise<IPerson[]> {
         return this.search(query, { 'includeDisplayName': true })
             .then((searchResult: SearchResult) => {
                 let people = searchResult.people;
@@ -57,12 +57,12 @@ export default class PeopleService implements IPeopleService {
             });
     }
 
-    getDirectReports(id: string): IPromise<Person[]> {
+    getDirectReports(id: string): IPromise<IPerson[]> {
         return this.getOrgChartData(id, false).then((orgChartData: OrgChartData) => {
-            let people: Person[] = [];
+            let people: IPerson[] = [];
 
             for (let directReport of orgChartData.children) {
-                let person: Person = new Person(directReport);
+                let person: IPerson = <IPerson>(directReport);
                 people.push(person);
             }
 
@@ -71,17 +71,17 @@ export default class PeopleService implements IPeopleService {
     }
 
     getNumberOfDirectReports(id: string): IPromise<number> {
-        return this.getDirectReports(id).then((people: Person[]) => {
+        return this.getDirectReports(id).then((people: IPerson[]) => {
             return this.$q.resolve(people.length);
         });
     }
 
-    getManagementChain(id: string): IPromise<Person[]> {
-        let people: Person[] = [];
+    getManagementChain(id: string): IPromise<IPerson[]> {
+        let people: IPerson[] = [];
         return this.getManagerRecursive(id, people);
     }
 
-    private getManagerRecursive(id: string, people: Person[]): IPromise<Person[]> {
+    private getManagerRecursive(id: string, people: IPerson[]): IPromise<IPerson[]> {
         return this.getOrgChartData(id, true)
             .then((orgChartData: OrgChartData) => {
                 if (orgChartData.manager) {
@@ -111,17 +111,17 @@ export default class PeopleService implements IPeopleService {
 
                     let responseData = response.data['data'];
 
-                    let manager: Person;
-                    if ('parent' in responseData) { manager = new Person(responseData['parent']); }
-                    const children = responseData['children'].map((child: any) => new Person(child));
-                    const self = new Person(responseData['self']);
+                    let manager: IPerson;
+                    if ('parent' in responseData) { manager = <IPerson>(responseData['parent']); }
+                    const children = responseData['children'].map((child: any) => <IPerson>(child));
+                    const self = <IPerson>(responseData['self']);
 
                     return this.$q.resolve(new OrgChartData(manager, children, self));
                 },
                 this.handleHttpError.bind(this));
     }
 
-    getPerson(id: string): IPromise<Person> {
+    getPerson(id: string): IPromise<IPerson> {
         // Deferred object used for aborting requests. See promise.service.ts for more information
         let httpTimeout = this.$q.defer();
 
@@ -138,7 +138,7 @@ export default class PeopleService implements IPeopleService {
                     return this.handlePwmError(response);
                 }
 
-                let person: Person = new Person(response.data['data']);
+                let person: IPerson = <IPerson>(response.data['data']);
                 return this.$q.resolve(person);
             },
             this.handleHttpError.bind(this));