diff --git a/apps/maarch_entreprise/Views/contacts-group-administration.component.html b/apps/maarch_entreprise/Views/contacts-group-administration.component.html index 4a50483d5177ef4f5da3a08de7c21d44abc45a23..b748aefb8dd9c5425aa5d2aab1fdd26a9f0fb9e7 100755 --- a/apps/maarch_entreprise/Views/contacts-group-administration.component.html +++ b/apps/maarch_entreprise/Views/contacts-group-administration.component.html @@ -58,62 +58,49 @@ <mat-tab label="{{lang.relatedContacts}}" *ngIf="!creationMode"> <div class="row" style="margin:0px;"> <div class="col-md-12" style="padding:5px;"> - <!-- <mat-form-field> - <span matPrefix><mat-icon class="fa fa-user-plus" color="primary"></mat-icon> </span> - <input class="autocompleteSearch" #autocompleteFilter placeholder="{{lang.linkContact}}" type="text" 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> --> <mat-form-field> <span matPrefix><mat-icon class="fa fa-user-plus" color="primary"></mat-icon> </span> - <input class="autocompleteSearch" #autocompleteFilter type="text" placeholder="{{lang.linkContact}}" matInput [formControl]="searchTerm" [matAutocomplete]="auto"> - <!-- <mat-autocomplete #auto="matAutocomplete"> - <mat-option *ngFor="let item of searchResult" [value]="item"> - {{ item }} - </mat-option> - </mat-autocomplete> --> + <input class="autocompleteSearch" type="text" placeholder="{{lang.linkContact}}" matInput [formControl]="searchTerm"> </mat-form-field> - <hr/> - </div> - <!-- <div class="col-md-6 col-xs-6"> - <mat-form-field> - <input matInput (keyup)="applyFilter($event.target.value)" placeholder="{{lang.filterBy}}"> - </mat-form-field> </div> <div class="col-md-6 col-xs-6"> <mat-paginator #paginator [length]="100" [pageSize]="10"> </mat-paginator> - </div> --> + </div> </div> - <!-- <mat-table #table [dataSource]="dataSource" matSort matSortActive="lastname" matSortDirection="asc"> - <ng-container matColumnDef="user_id"> - <mat-header-cell *matHeaderCellDef mat-sort-header>{{lang.id}}</mat-header-cell> - <mat-cell *matCellDef="let element"> {{element.user_id}} </mat-cell> + <mat-table #table [dataSource]="dataSource" matSort matSortActive="contact" matSortDirection="asc" *ngIf="dataSource"> + <ng-container matColumnDef="select"> + <mat-header-cell *matHeaderCellDef> + <mat-checkbox (change)="$event ? masterToggle() : null" + [checked]="selection.hasValue() && isAllSelected()" + [indeterminate]="selection.hasValue() && !isAllSelected()"> + </mat-checkbox> + </mat-header-cell> + <mat-cell *matCellDef="let element"> + <mat-checkbox (click)="$event.stopPropagation()" + (change)="$event ? selection.toggle(element.addressId) : null" + [checked]="selection.isSelected(element.addressId)"> + </mat-checkbox> + </mat-cell> </ng-container> - <ng-container matColumnDef="firstname"> - <mat-header-cell *matHeaderCellDef mat-sort-header>{{lang.firstname}}</mat-header-cell> - <mat-cell *matCellDef="let element"> {{element.firstname}} </mat-cell> + <ng-container matColumnDef="contact"> + <mat-header-cell *matHeaderCellDef mat-sort-header>{{lang.contact}}</mat-header-cell> + <mat-cell *matCellDef="let element"> {{element.contact}} </mat-cell> </ng-container> - <ng-container matColumnDef="lastname"> - <mat-header-cell *matHeaderCellDef mat-sort-header>{{lang.lastname}}</mat-header-cell> - <mat-cell *matCellDef="let element"> {{element.lastname}} </mat-cell> + <ng-container matColumnDef="address"> + <mat-header-cell *matHeaderCellDef mat-sort-header>{{lang.address}}</mat-header-cell> + <mat-cell *matCellDef="let element"> {{element.address}} </mat-cell> </ng-container> <mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row> - <mat-row *matRowDef="let row; columns: displayedColumns;" routerLink="/administration/users/{{row.id}}" matTooltip="{{lang.view}}" - style="cursor:pointer;"></mat-row> - </mat-table> --> + <mat-row *matRowDef="let element; columns: displayedColumns;" (click)="selection.toggle(element.addressId)"></mat-row> + </mat-table> + <hr/> + + <div class="form-group"> + <div class="col-sm-12" style="text-align:center;margin-top:30px"> + <button mat-raised-button color="primary" type="button"(click)="saveContactsList()">{{lang.save}}</button> + </div> + </div> </mat-tab> </mat-tab-group> diff --git a/apps/maarch_entreprise/js/angular/app/administration/contacts-group-administration.component.ts b/apps/maarch_entreprise/js/angular/app/administration/contacts-group-administration.component.ts index db5d8756f3f579de144dab612b2c4a2aa7a5d6c0..1e8fe5593cc1e89cf4f34f0573a5a18edacf851f 100755 --- a/apps/maarch_entreprise/js/angular/app/administration/contacts-group-administration.component.ts +++ b/apps/maarch_entreprise/js/angular/app/administration/contacts-group-administration.component.ts @@ -1,4 +1,4 @@ -import { ChangeDetectorRef, Component, OnInit } from '@angular/core'; +import { ChangeDetectorRef, Component, OnInit, ViewChild } from '@angular/core'; import { MediaMatcher } from '@angular/cdk/layout'; import { HttpClient } from '@angular/common/http'; import { Router, ActivatedRoute } from '@angular/router'; @@ -6,6 +6,8 @@ import { LANG } from '../translate.component'; import { NotificationService } from '../notification.service'; import { FormControl } from '@angular/forms'; import { debounceTime, switchMap, distinctUntilChanged, filter } from 'rxjs/operators'; +import { MatPaginator, MatSort, MatTableDataSource } from '@angular/material'; +import { SelectionModel } from '@angular/cdk/collections'; declare function $j(selector: any): any; @@ -30,6 +32,32 @@ export class ContactsGroupAdministrationComponent implements OnInit { searchTerm: FormControl = new FormControl(); searchResult:any = []; + displayedColumns = ['select', 'contact', 'address']; + dataSource : any; + selection = new SelectionModel<Element>(true, []); + + /** Whether the number of selected elements matches the total number of rows. */ + isAllSelected() { + const numSelected = this.selection.selected.length; + const numRows = this.dataSource.data.length; + return numSelected === numRows; + } + + /** Selects all rows if they are not all selected; otherwise clear selection. */ + masterToggle() { + // this.isAllSelected() ? + // this.selection.clear() : + // this.dataSource.data.forEach(row => this.selection.select(row)); + } + + @ViewChild(MatPaginator) paginator: MatPaginator; + @ViewChild(MatSort) sort: MatSort; + applyFilter(filterValue: string) { + filterValue = filterValue.trim(); + filterValue = filterValue.toLowerCase(); + this.dataSource.filter = filterValue; + } + constructor(changeDetectorRef: ChangeDetectorRef, media: MediaMatcher, public http: HttpClient, private route: ActivatedRoute, private router: Router, private notify: NotificationService) { $j("link[href='merged_css.php']").remove(); this.mobileQuery = media.matchMedia('(max-width: 768px)'); @@ -42,7 +70,9 @@ export class ContactsGroupAdministrationComponent implements OnInit { distinctUntilChanged(), switchMap(data => this.http.get(this.coreUrl + 'rest/autocomplete/contacts', {params: {"search" : data, "type" : '106'}})) ).subscribe((response: any) => { - this.searchResult = response.word; + this.dataSource = new MatTableDataSource(response); + this.dataSource.paginator = this.paginator; + this.dataSource.sort = this.sort; }); } @@ -72,6 +102,16 @@ export class ContactsGroupAdministrationComponent implements OnInit { }); } + saveContactsList(): void { + this.http.post(this.coreUrl + 'rest/contactsGroups/'+ this.contactsGroup.id, this.selection.selected) + .subscribe(() => { + this.notify.success(this.lang.contactAdded); + + }, (err) => { + this.notify.error(err.error.errors); + }); + } + onSubmit() { if (this.creationMode) { this.http.post(this.coreUrl + 'rest/contactsGroups', this.contactsGroup) diff --git a/apps/maarch_entreprise/js/angular/lang/lang-en.ts b/apps/maarch_entreprise/js/angular/lang/lang-en.ts index 2a5db38e82f95ff883488d162acd013c22815ef5..a4f29fd73756c28a1001869ebfaf42d5dcdba5f7 100755 --- a/apps/maarch_entreprise/js/angular/lang/lang-en.ts +++ b/apps/maarch_entreprise/js/angular/lang/lang-en.ts @@ -456,5 +456,7 @@ export const LANG_EN = { "contactsGroupDeleted" : "Contacts group deleted", "linkContact" : "Link a contact", "relatedContacts" : "Related contacts", + "contact" : "Contact", + "contactAdded" : "Contact(s) added", }; diff --git a/apps/maarch_entreprise/js/angular/lang/lang-fr.ts b/apps/maarch_entreprise/js/angular/lang/lang-fr.ts index 0ea294209a30a1740be38fabc0841fb280f69d39..a2ddd359fd6b3573f045b7d8d2ae8414ed375f88 100755 --- a/apps/maarch_entreprise/js/angular/lang/lang-fr.ts +++ b/apps/maarch_entreprise/js/angular/lang/lang-fr.ts @@ -476,5 +476,7 @@ export const LANG_FR = { "contactsGroupDeleted" : "Groupement de contacts supprimé", "linkContact" : "Associer un contact", "relatedContacts" : "Contact(s) associé(s)", + "contact" : "Contact", + "contactAdded" : "Contact(s) ajouté(s)", };