diff --git a/apps/maarch_entreprise/Views/group-administration.component.html b/apps/maarch_entreprise/Views/group-administration.component.html index 583344641a7a1f311e4a2e7754098c3b3918bc1c..1f46bf9771bc2e5f31fa5c75a9d5d8401ef2827c 100644 --- a/apps/maarch_entreprise/Views/group-administration.component.html +++ b/apps/maarch_entreprise/Views/group-administration.component.html @@ -52,6 +52,25 @@ </mat-tab> <mat-tab label="{{lang.relatedUsers}}" *ngIf="!creationMode"> <div class="row" style="margin:0px;"> + <div class="col-md-12" *ngIf="group.canAdminUsers"> + <mat-form-field> + <input class="autocompleteSearch" #autocompleteFilter type="text" placeholder="{{lang.addUser}}" matInput [matAutocomplete]="auto" + [formControl]="userCtrl"> + <mat-autocomplete #auto="matAutocomplete"> + <mat-option *ngFor="let user of filteredUsers | async" [value]="user.idToDisplay" (click)="linkUser(user)"> + <p mat-line style="margin:0;"> + <span class="col-xm-1" style="padding-right:5px;"> + <mat-icon color="primary" [class]="user.type == 'entity' ? 'fa fa-sitemap fa-2x' : 'fa fa-user fa-2x'" style="margin-right:0px;"></mat-icon> + </span> + <span class="col-xm-11"> + {{ user.idToDisplay }} + <small>{{ user.otherInfo }}</small> + </span> + </p> + </mat-option> + </mat-autocomplete> + </mat-form-field> + </div> <div class="col-md-6 col-xs-6"> <mat-form-field> <input matInput (keyup)="applyFilter($event.target.value)" placeholder="{{lang.filterBy}}"> diff --git a/apps/maarch_entreprise/js/angular/app/administration/group-administration.component.ts b/apps/maarch_entreprise/js/angular/app/administration/group-administration.component.ts index d1bfffb3923c442edb216db3fdcec056908e6707..686644a14c1bbf4768575c3e98605f215b58e1cf 100644 --- a/apps/maarch_entreprise/js/angular/app/administration/group-administration.component.ts +++ b/apps/maarch_entreprise/js/angular/app/administration/group-administration.component.ts @@ -6,6 +6,8 @@ import { LANG } from '../translate.component'; import { NotificationService } from '../notification.service'; import { MatPaginator, MatTableDataSource, MatSort} from '@angular/material'; +import { AutoCompletePlugin } from '../../plugins/autocomplete.plugin'; + declare function $j(selector: any) : any; declare const angularGlobals : any; @@ -14,7 +16,7 @@ declare const angularGlobals : any; templateUrl: "../../../../Views/group-administration.component.html", providers : [NotificationService] }) -export class GroupAdministrationComponent implements OnInit { +export class GroupAdministrationComponent extends AutoCompletePlugin implements OnInit { private _mobileQueryListener : () => void; mobileQuery : MediaQueryList; @@ -41,6 +43,7 @@ export class GroupAdministrationComponent implements OnInit { } constructor(changeDetectorRef: ChangeDetectorRef, media: MediaMatcher,public http: HttpClient, private route: ActivatedRoute, private router: Router, private notify: NotificationService) { + super(http, ['adminUsers']); $j("link[href='merged_css.php']").remove(); this.mobileQuery = media.matchMedia('(max-width: 768px)'); this._mobileQueryListener = () => changeDetectorRef.detectChanges(); @@ -107,4 +110,30 @@ export class GroupAdministrationComponent implements OnInit { this.notify.error(err.error.errors); }); } + + linkUser(newUser:any) { + this.userCtrl.setValue(''); + $j('.autocompleteSearch').blur(); + var groupReq = { + "groupId": this.group.group_id, + "role": this.group.role + }; + this.http.post(this.coreUrl + "rest/users/" + newUser.id + "/groups", groupReq) + .subscribe((data: any) => { + var displayName = newUser.idToDisplay.split(" "); + var user = { + id : newUser.id, + user_id : newUser.otherInfo, + firstname : displayName[0], + lastname : displayName[1] + } + this.group.users.push(user); + this.dataSource = new MatTableDataSource(this.group.users); + this.dataSource.paginator = this.paginator; + this.dataSource.sort = this.sort; + this.notify.success(this.lang.userAdded); + }, (err) => { + this.notify.error(err.error.errors); + }); + } } diff --git a/apps/maarch_entreprise/js/angular/plugins/autocomplete.plugin.ts b/apps/maarch_entreprise/js/angular/plugins/autocomplete.plugin.ts index 2b4d934b0ae95b4b3c617a165a2cd7d468a442a9..b415b7bed113ebb61de962ba54b3ea55e5703922 100644 --- a/apps/maarch_entreprise/js/angular/plugins/autocomplete.plugin.ts +++ b/apps/maarch_entreprise/js/angular/plugins/autocomplete.plugin.ts @@ -36,6 +36,21 @@ export class AutoCompletePlugin { location.href = "index.php"; }); } + if (target.indexOf('adminUsers') != -1) { + this.userCtrl = new FormControl(); + this.http.get(this.coreUrl + 'rest/autocomplete/users/administration') + .subscribe((data: any) => { + this.userList = data; + this.filteredUsers = this.userCtrl.valueChanges + .pipe( + startWith(''), + map(user => user ? this.autocompleteFilterUser(user) : this.userList.slice()) + ); + }, () => { + location.href = "index.php"; + }); + } + if (target.indexOf('statuses') != -1) { this.statusCtrl = new FormControl(); this.http.get(this.coreUrl + 'rest/autocomplete/statuses')