Merge branch 'KON-435-Person-automatisch-aus-einem-ausgewählten-LDAP-User-erstellen' of ssh://git.eclipse.org:29418/openk-usermodules/org.eclipse.openk-usermodules.contactBaseData.frontend into DEVELOP
diff --git a/package.json b/package.json
index 67da642..f2edf8c 100644
--- a/package.json
+++ b/package.json
@@ -8,6 +8,7 @@
   "scripts": {
     "start": "npm run sy-pre-start && ng serve --proxy-config proxy.conf.json",
     "start-integration": "npm run sy-pre-start && ng serve --proxy-config proxy.conf-integration.json",
+    "start-local": "npm run sy-pre-start && ng serve --proxy-config proxy.conf-local.json",
     "test": "npm run sy-pre-test && ng test",
     "pree2e": "webdriver-manager update --standalone false --gecko false",
     "e2e": "ng e2e",
diff --git a/proxy.conf-local.json b/proxy.conf-local.json
new file mode 100644
index 0000000..bc0c49b
--- /dev/null
+++ b/proxy.conf-local.json
@@ -0,0 +1,9 @@
+{
+  "/api": {
+    "target": "http://localhost:9155",
+    "secure": false,
+    "pathRewrite": {
+      "^/api": ""
+    }
+  }
+}
diff --git a/src/app/pages/persons/internal-person/internal-person-details/internal-person-details.component.html b/src/app/pages/persons/internal-person/internal-person-details/internal-person-details.component.html
index 1fae53a..7865c91 100644
--- a/src/app/pages/persons/internal-person/internal-person-details/internal-person-details.component.html
+++ b/src/app/pages/persons/internal-person/internal-person-details/internal-person-details.component.html
@@ -108,6 +108,8 @@
               [editable]="false"
               (selectItem)="internalPersonSandBox.setLdapUidValue($event)"
               autocomplete="off"
+              [resultFormatter]="internalPersonSandBox.formatter"
+              [inputFormatter]="internalPersonSandBox.formatter"
             />
           </div>
           <div class="col-sm-4">
diff --git a/src/app/pages/persons/internal-person/internal-person-details/internal-person-details.sandbox.spec.ts b/src/app/pages/persons/internal-person/internal-person-details/internal-person-details.sandbox.spec.ts
index 6b57a01..2724a30 100644
--- a/src/app/pages/persons/internal-person/internal-person-details/internal-person-details.sandbox.spec.ts
+++ b/src/app/pages/persons/internal-person/internal-person-details/internal-person-details.sandbox.spec.ts
@@ -14,7 +14,7 @@
 import { InternalPersonDetailsSandBox } from '@pages/persons/internal-person/internal-person-details/internal-person-details.sandbox';
 import { of } from 'rxjs';
 import * as internalPersonActions from '@shared/store/actions/persons/internal-person.action';
-import { InternalPerson, CommunicationsData, Address } from '@shared/models';
+import { InternalPerson, CommunicationsData, Address, LdapUser } from '@shared/models';
 
 describe('InternalPersonDetailsSandBox', () => {
   let component: InternalPersonDetailsSandBox;
@@ -316,21 +316,22 @@
 
   it('should call dispatch and clear the userref if setLdapUidValue called with null', () => {
     component.internalPersonDetailsCurrentFormState = {
-      controls: { uid: { id: 'test' } },
-      value: { uid: 'test1' },
+      controls: { uid: { id: 'test1' }, firstName: { id: 'test2' }, lastName: { id: 'test3' } },
+      value: { uid: 'test1', firstName: 'test2', lastName: 'test3' },
     } as any;
     const spy = spyOn(appState, 'dispatch').and.callThrough();
     component.setLdapUidValue(null);
-    expect(spy).toHaveBeenCalledTimes(1);
+    expect(spy).toHaveBeenCalledTimes(3);
   });
 
   it('should call dispatch and set the userref if setLdapUidValue called with a value', () => {
     component.internalPersonDetailsCurrentFormState = {
-      controls: { uid: { id: 'test' } },
-      value: { uid: 'test1' },
+      controls: { uid: { id: 'test1' }, firstName: { id: 'test2' }, lastName: { id: 'test3' } },
+      value: { uid: 'test1', firstName: 'test2', lastName: 'test3' },
     } as any;
+    let ldapUser = { firstName: 'Muster', lastName: 'Administrator', uid: 'admin' };
     const spy = spyOn(appState, 'dispatch').and.callThrough();
-    component.setLdapUidValue({ item: 'Muster Administrator (admin)' } as any);
-    expect(spy).toHaveBeenCalledTimes(1);
+    component.setLdapUidValue({ item: ldapUser });
+    expect(spy).toHaveBeenCalledTimes(3);
   });
 });
diff --git a/src/app/pages/persons/internal-person/internal-person-details/internal-person-details.sandbox.ts b/src/app/pages/persons/internal-person/internal-person-details/internal-person-details.sandbox.ts
index 973a374..707545e 100644
--- a/src/app/pages/persons/internal-person/internal-person-details/internal-person-details.sandbox.ts
+++ b/src/app/pages/persons/internal-person/internal-person-details/internal-person-details.sandbox.ts
@@ -49,6 +49,7 @@
   public isCommunicationsDataDetailViewVisible: boolean = false;
   public isAddressDataDetailViewVisible: boolean = false;
   public existMainAddress = false;
+  public showSynchAlertMessage = false;
   public isCurrentAddressMainAddress = false;
   public internalPersonContactId: string;
   private _currentInternalPerson: InternalPerson = null;
@@ -252,9 +253,9 @@
 
   public registerInternalPersonEvents(): void {
     // subscribes to formState
-    this.internalPersonDetailsFormState$
-      .pipe(takeUntil(this._endSubscriptions$))
-      .subscribe((formState: FormGroupState<InternalPerson>) => (this.internalPersonDetailsCurrentFormState = formState));
+    this.internalPersonDetailsFormState$.pipe(takeUntil(this._endSubscriptions$)).subscribe((formState: FormGroupState<InternalPerson>) => {
+      this.internalPersonDetailsCurrentFormState = formState;
+    });
   }
 
   public loadCommunicationsData(internalPersonId: string): void {
@@ -390,18 +391,16 @@
     text$.pipe(
       debounceTime(200),
       distinctUntilChanged(),
-      map(term =>
-        term.length < 2
-          ? []
-          : this._ldapUsers.map((user: LdapUser) => `${user.fullName} (${user.uid})`).filter(v => v.toLowerCase().indexOf(term.toLowerCase()) > -1)
-      )
+      map(term => (term.length < 2 ? [] : this._ldapUsers.filter(v => v.ldapSearchString.toLowerCase().indexOf(term.toLowerCase()) > -1)))
     );
 
+  public formatter = (x: LdapUser) => x.ldapSearchString;
+
   public setLdapUidValue(event: any): void {
     // set the value only if exists - take only the username from the rounded bruckets
-    this.appState$.dispatch(
-      new SetValueAction(this.internalPersonDetailsCurrentFormState.controls.uid.id, event == null ? null : event.item.match(/\(([^)]+)\)/)[1])
-    );
+    this.appState$.dispatch(new SetValueAction(this.internalPersonDetailsCurrentFormState.controls.uid.id, event == null ? null : event.item.uid));
+    this.appState$.dispatch(new SetValueAction(this.internalPersonDetailsCurrentFormState.controls.firstName.id, event == null ? null : event.item.firstName));
+    this.appState$.dispatch(new SetValueAction(this.internalPersonDetailsCurrentFormState.controls.lastName.id, event == null ? null : event.item.lastName));
   }
 
   removeCurrentMainAddress(): void {
diff --git a/src/app/pages/persons/persons.routing.module.ts b/src/app/pages/persons/persons.routing.module.ts
index a5eb379..8b1bfd8 100644
--- a/src/app/pages/persons/persons.routing.module.ts
+++ b/src/app/pages/persons/persons.routing.module.ts
@@ -20,7 +20,7 @@
 
 const PATH = Globals.PATH;
 
-const addNewPersonRoutes: Routes = [
+const editPersonRoutes: Routes = [
   {
     path: `${PATH.PERSONS}/${PATH.EXTERNAL}/:contactId`,
     component: ExternalPersonDetailsComponent,
@@ -37,7 +37,7 @@
   }
 ];
 
-const editPersonRoutes: Routes = [
+const addNewPersonRoutes: Routes = [
   {
     path: `${PATH.PERSONS}/${PATH.EXTERNAL}/${PATH.NEW}`,
     component: ExternalPersonDetailsComponent,
@@ -55,7 +55,7 @@
 ];
 
 @NgModule({
-  imports: [RouterModule.forChild([...addNewPersonRoutes,...editPersonRoutes])],
+  imports: [RouterModule.forChild([...editPersonRoutes,...addNewPersonRoutes])],
   exports: [RouterModule]
 })
 export class PersonsRoutingModule { }
diff --git a/src/app/shared/models/users/ldap-user.model.ts b/src/app/shared/models/users/ldap-user.model.ts
index 02ffb42..42f1d0a 100644
--- a/src/app/shared/models/users/ldap-user.model.ts
+++ b/src/app/shared/models/users/ldap-user.model.ts
@@ -26,4 +26,8 @@
       .filter(property => this.hasOwnProperty(property))
       .forEach(property => (this[property] = data[property]));
   }
+
+  get ldapSearchString(): string {
+    return this.firstName + ' ' + this.lastName + ' (' + this.uid + ')';
+  }
 }