From 768a5b94bb0983ba12b2035cbd27c03182dd77dc Mon Sep 17 00:00:00 2001 From: Vinciane <vinciane.bizet@maarch.org> Date: Wed, 20 Feb 2019 17:41:19 +0100 Subject: [PATCH] FEAT #9511 add templates list in admin entity --- .../entity/controllers/EntityController.php | 12 +++-- .../entities-administration.component.html | 46 ++++++++++++++++--- .../entities-administration.component.ts | 39 +++++++++++----- 3 files changed, 75 insertions(+), 22 deletions(-) diff --git a/src/app/entity/controllers/EntityController.php b/src/app/entity/controllers/EntityController.php index 98e4b1ad624..355d46c0d38 100755 --- a/src/app/entity/controllers/EntityController.php +++ b/src/app/entity/controllers/EntityController.php @@ -27,6 +27,7 @@ use Slim\Http\Response; use Template\models\TemplateAssociationModel; use User\models\UserEntityModel; use User\models\UserModel; +use \Template\models\TemplateModel; class EntityController { @@ -85,7 +86,7 @@ class EntityController $entity['roles'][$key]['id'] = 'cc'; } } - + //Diffusion list $listTemplates = ListTemplateModel::get([ 'select' => ['id', 'object_type', 'item_id', 'item_type', 'item_mode', 'title', 'description', 'sequence'], 'where' => ['object_id = ?'], @@ -140,13 +141,18 @@ class EntityController } } + //List of documents model + $templates = TemplateModel::getByEntity([ + 'select' => ['t.template_id, t.template_label, template_comment, t.template_target, t.template_attachment_type '], + 'entities' => [$aArgs['id']] + ]); + $entity['templates'] = $templates; + $entity['users'] = EntityModel::getUsersById(['id' => $entity['entity_id'], 'select' => ['users.id','users.user_id', 'users.firstname', 'users.lastname', 'users.status']]); $children = EntityModel::get(['select' => [1], 'where' => ['parent_entity_id = ?'], 'data' => [$aArgs['id']]]); $entity['hasChildren'] = count($children) > 0; $documents = ResModel::get(['select' => [1], 'where' => ['destination = ?'], 'data' => [$aArgs['id']]]); $entity['documents'] = count($documents); - $templates = TemplateAssociationModel::get(['select' => [1], 'where' => ['value_field = ?'], 'data' => [$aArgs['id']]]); - $entity['templates'] = count($templates); $instances = ListInstanceModel::get(['select' => [1], 'where' => ['item_id = ?', 'item_type = ?'], 'data' => [$aArgs['id'], 'entity_id']]); $entity['instances'] = count($instances); $redirects = BasketModel::getGroupActionRedirect(['select' => [1], 'where' => ['entity_id = ?'], 'data' => [$aArgs['id']]]); diff --git a/src/frontend/app/administration/entity/entities-administration.component.html b/src/frontend/app/administration/entity/entities-administration.component.html index bfff3dab802..0c599ab6725 100755 --- a/src/frontend/app/administration/entity/entities-administration.component.html +++ b/src/frontend/app/administration/entity/entities-administration.component.html @@ -45,8 +45,7 @@ </mat-card> </mat-sidenav-content> <mat-sidenav #snav2 [mode]="mobileQuery.matches ? 'over' : 'side'" [fixedInViewport]="mobileQuery.matches" fixedTopGap="56" - position='end' [opened]="false" class="col-md-4 col-xs-11"> - + position='end' [opened]="false" class="col-md-5 col-xs-11"> <mat-nav-list> <mat-tab-group> <mat-tab [label]="creationMode ? lang.createNewEntity : lang.informations"> @@ -315,15 +314,15 @@ </div> <div class="col-md-6 col-xs-6"> <mat-form-field> - <input matInput (keyup)="applyFilter($event.target.value)" placeholder="{{lang.filterBy}}"> + <input matInput (keyup)="applyFilterUsers($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 #paginatorUsers [length]="100" [pageSize]="10"> </mat-paginator> </div> </div> - <mat-table #table [dataSource]="dataSource" matSort matSortActive="lastname" matSortDirection="asc"> + <mat-table #tableUsers="matSort" [dataSource]="dataSourceUsers" matSort matSortActive="lastname" matSortDirection="asc"> <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> @@ -332,11 +331,44 @@ <mat-header-cell *matHeaderCellDef mat-sort-header>{{lang.lastname}}</mat-header-cell> <mat-cell *matCellDef="let element"> {{element.lastname}} </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}}" + <mat-header-row *matHeaderRowDef="displayedColumnsUsers"></mat-header-row> + <mat-row *matRowDef="let row; columns: displayedColumnsUsers;" routerLink="/administration/users/{{row.id}}" matTooltip="{{lang.view}}" style="cursor:pointer;"></mat-row> </mat-table> </mat-tab> + <mat-tab label="Modèles de documents associés" *ngIf="!creationMode"> + <div class="row" style="margin:0px;"> + <div class="col-md-6 col-xs-6"> + <mat-form-field> + <input matInput (keyup)="applyFilterTemplates($event.target.value)" placeholder="{{lang.filterBy}}"> + </mat-form-field> + </div> + <div class="col-md-6 col-xs-6"> + <mat-paginator #paginatorTemplates [length]="100" [pageSize]="10"> + </mat-paginator> + </div> + </div> + <mat-table #tableTemplates="matSort" [dataSource]="dataSourceTemplates" matSort matSortActive="template_label" matSortDirection="asc"> + <ng-container matColumnDef="template_label"> + <mat-header-cell *matHeaderCellDef mat-sort-header style="flex:2;">{{lang.templateName}}</mat-header-cell> + <mat-cell *matCellDef="let element" style="flex:2;"> {{element.template_label}} </mat-cell> + </ng-container> + <ng-container matColumnDef="template_comment"> + <mat-header-cell *matHeaderCellDef mat-sort-header [class.hide-for-mobile]="mobileQuery.matches" style="flex:2;">{{lang.description}}</mat-header-cell> + <mat-cell *matCellDef="let element" [class.hide-for-mobile]="mobileQuery.matches" style="flex:2;"> {{element.template_comment}} </mat-cell> + </ng-container> + <ng-container matColumnDef="template_target"> + <mat-header-cell *matHeaderCellDef mat-sort-header [class.hide-for-mobile]="mobileQuery.matches" style="flex:1;">{{lang.templateTarget}}</mat-header-cell> + <mat-cell *matCellDef="let element" [class.hide-for-mobile]="mobileQuery.matches" style="flex:1;"> {{lang[element.template_target]}} </mat-cell> + </ng-container> + <ng-container matColumnDef="template_attachment_type"> + <mat-header-cell *matHeaderCellDef mat-sort-header [class.hide-for-mobile]="mobileQuery.matches" style="flex:1;">{{lang.attachmentType}}</mat-header-cell> + <mat-cell *matCellDef="let element" [class.hide-for-mobile]="mobileQuery.matches" style="flex:1;"> {{element.template_attachment_type}} </mat-cell> + </ng-container> + <mat-header-row *matHeaderRowDef="displayedColumnsTemplates"></mat-header-row> + <mat-row *matRowDef="let row; columns: displayedColumnsTemplates;" routerLink="/administration/templates/{{row.template_id}}" style="cursor:pointer;" matTooltip="{{lang.view}}"></mat-row> + </mat-table> + </mat-tab> </mat-tab-group> </mat-nav-list> </mat-sidenav> diff --git a/src/frontend/app/administration/entity/entities-administration.component.ts b/src/frontend/app/administration/entity/entities-administration.component.ts index 78635a4cf5c..07d97c3b910 100755 --- a/src/frontend/app/administration/entity/entities-administration.component.ts +++ b/src/frontend/app/administration/entity/entities-administration.component.ts @@ -43,16 +43,26 @@ export class EntitiesAdministrationComponent extends AutoCompletePlugin implemen idCircuitVisa : number; config : any = {}; - dataSource = new MatTableDataSource(this.currentEntity.users); - displayedColumns = ['firstname', 'lastname']; + dataSourceUsers = new MatTableDataSource(this.currentEntity.users); + dataSourceTemplates = new MatTableDataSource(this.currentEntity.templates); + displayedColumnsUsers = ['firstname', 'lastname']; + displayedColumnsTemplates = ['template_label', 'template_comment', 'template_target', 'template_attachment_type']; - @ViewChild(MatPaginator) paginator: MatPaginator; - @ViewChild(MatSort) sort: MatSort; - applyFilter(filterValue: string) { + @ViewChild('paginatorUsers') paginatorUsers: MatPaginator; + @ViewChild('paginatorTemplates') paginatorTemplates: MatPaginator; + @ViewChild('tableUsers') sortUsers: MatSort; + @ViewChild('tableTemplates') sortTemplates: MatSort; + applyFilterUsers(filterValue: string) { filterValue = filterValue.trim(); filterValue = filterValue.toLowerCase(); - this.dataSource.filter = filterValue; + this.dataSourceUsers.filter = filterValue; + } + + applyFilterTemplates(filterValue: string) { + filterValue = filterValue.trim(); + filterValue = filterValue.toLowerCase(); + this.dataSourceTemplates.filter = filterValue; } constructor(changeDetectorRef: ChangeDetectorRef, media: MediaMatcher, public http: HttpClient, private notify: NotificationService, public dialog: MatDialog, private headerService: HeaderService) { @@ -193,9 +203,14 @@ export class EntitiesAdministrationComponent extends AutoCompletePlugin implemen } else { this.idCircuitVisa = null; } - this.dataSource = new MatTableDataSource(this.currentEntity.users); - this.dataSource.paginator = this.paginator; - this.dataSource.sort = this.sort; + this.dataSourceUsers = new MatTableDataSource(this.currentEntity.users); + this.dataSourceUsers.paginator = this.paginatorUsers; + this.dataSourceUsers.sort = this.sortUsers; + + this.dataSourceTemplates = new MatTableDataSource(this.currentEntity.templates); + this.dataSourceTemplates.paginator = this.paginatorTemplates; + this.dataSourceTemplates.sort = this.sortTemplates; + }, (err) => { this.notify.error(err.error.errors); }); @@ -705,9 +720,9 @@ export class EntitiesAdministrationComponent extends AutoCompletePlugin implemen lastname : displayName[1] } this.currentEntity.users.push(user); - this.dataSource = new MatTableDataSource(this.currentEntity.users); - this.dataSource.paginator = this.paginator; - this.dataSource.sort = this.sort; + this.dataSourceUsers = new MatTableDataSource(this.currentEntity.users); + this.dataSourceUsers.paginator = this.paginatorUsers; + this.dataSourceUsers.sort = this.sortUsers; this.notify.success(this.lang.userAdded); }, (err) => { this.notify.error(err.error.errors); -- GitLab