Skip to content
Snippets Groups Projects
Verified Commit 9c010ab2 authored by Damien's avatar Damien
Browse files

FEAT #7990 Display baskets in group administration

parent 9e2b2d77
No related branches found
No related tags found
No related merge requests found
...@@ -91,56 +91,77 @@ ...@@ -91,56 +91,77 @@
</mat-tab-group> </mat-tab-group>
</mat-tab> </mat-tab>
<mat-tab label="{{lang.relatedUsers}}" *ngIf="!creationMode"> <mat-tab label="{{lang.relatedUsers}}" *ngIf="!creationMode">
<div class="row" style="margin:0px;"> <div class="row" style="margin:0px;">
<div class="col-md-12" *ngIf="group.canAdminUsers" style="padding:5px;"> <div class="col-md-12" *ngIf="group.canAdminUsers" style="padding:5px;">
<mat-form-field> <mat-form-field>
<span matPrefix><mat-icon class="fa fa-user-plus" color="primary"></mat-icon>&nbsp;&nbsp;</span> <span matPrefix><mat-icon class="fa fa-user-plus" color="primary"></mat-icon>&nbsp;&nbsp;</span>
<input class="autocompleteSearch" #autocompleteFilter placeholder="{{lang.linkUser}}" type="text" matInput [matAutocomplete]="auto" <input class="autocompleteSearch" #autocompleteFilter placeholder="{{lang.linkUser}}" type="text" matInput [matAutocomplete]="auto"
[formControl]="userCtrl"> [formControl]="userCtrl">
<mat-autocomplete #auto="matAutocomplete"> <mat-autocomplete #auto="matAutocomplete">
<mat-option *ngFor="let user of filteredUsers | async" [value]="user.idToDisplay" (click)="linkUser(user)"> <mat-option *ngFor="let user of filteredUsers | async" [value]="user.idToDisplay" (click)="linkUser(user)">
<p mat-line style="margin:0;"> <p mat-line style="margin:0;">
<span class="col-xm-1" style="padding-right:5px;"> <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> <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>
<span class="col-xm-11"> <span class="col-xm-11">
{{ user.idToDisplay }} {{ user.idToDisplay }}
<small>{{ user.otherInfo }}</small> <small>{{ user.otherInfo }}</small>
</span> </span>
</p> </p>
</mat-option> </mat-option>
</mat-autocomplete> </mat-autocomplete>
</mat-form-field> </mat-form-field>
<hr/> <hr/>
</div> </div>
<div class="col-md-6 col-xs-6"> <div class="col-md-6 col-xs-6">
<mat-form-field> <mat-form-field>
<input matInput (keyup)="applyFilter($event.target.value)" placeholder="{{lang.filterBy}}"> <input matInput (keyup)="applyFilter($event.target.value)" placeholder="{{lang.filterBy}}">
</mat-form-field> </mat-form-field>
</div> </div>
<div class="col-md-6 col-xs-6"> <div class="col-md-6 col-xs-6">
<mat-paginator #paginator [length]="100" [pageSize]="10"> <mat-paginator #paginator [length]="100" [pageSize]="10">
</mat-paginator> </mat-paginator>
</div>
</div> </div>
<mat-table #table [dataSource]="dataSource" matSort matSortActive="lastname" matSortDirection="asc"> </div>
<ng-container matColumnDef="user_id"> <mat-table #table [dataSource]="usersDataSource" matSort matSortActive="lastname" matSortDirection="asc">
<mat-header-cell *matHeaderCellDef mat-sort-header>{{lang.id}}</mat-header-cell> <ng-container matColumnDef="firstname">
<mat-cell *matCellDef="let element"> {{element.user_id}} </mat-cell> <mat-header-cell *matHeaderCellDef mat-sort-header>{{lang.firstname}}</mat-header-cell>
</ng-container> <mat-cell *matCellDef="let element"> {{element.firstname}} </mat-cell>
<ng-container matColumnDef="firstname"> </ng-container>
<mat-header-cell *matHeaderCellDef mat-sort-header>{{lang.firstname}}</mat-header-cell> <ng-container matColumnDef="lastname">
<mat-cell *matCellDef="let element"> {{element.firstname}} </mat-cell> <mat-header-cell *matHeaderCellDef mat-sort-header>{{lang.lastname}}</mat-header-cell>
</ng-container> <mat-cell *matCellDef="let element"> {{element.lastname}} </mat-cell>
<ng-container matColumnDef="lastname"> </ng-container>
<mat-header-cell *matHeaderCellDef mat-sort-header>{{lang.lastname}}</mat-header-cell> <mat-header-row *matHeaderRowDef="usersDisplayedColumns"></mat-header-row>
<mat-cell *matCellDef="let element"> {{element.lastname}} </mat-cell> <mat-row *matRowDef="let row; columns: usersDisplayedColumns;" routerLink="/administration/users/{{row.id}}" matTooltip="{{lang.view}}"
</ng-container> style="cursor:pointer;"></mat-row>
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row> </mat-table>
<mat-row *matRowDef="let row; columns: displayedColumns;" routerLink="/administration/users/{{row.id}}" matTooltip="{{lang.view}}" </mat-tab>
style="cursor:pointer;"></mat-row> <mat-tab label="{{lang.relatedBaskets}}" *ngIf="!creationMode">
</mat-table> <div class="row" style="margin:0px;">
</mat-tab> <div class="col-md-6 col-xs-6">
<mat-form-field>
<input matInput (keyup)="applyBasketsFilter($event.target.value)" placeholder="{{lang.filterBy}}">
</mat-form-field>
</div>
<div class="col-md-6 col-xs-6">
<mat-paginator #paginatorBaskets [length]="100" [pageSize]="10">
</mat-paginator>
</div>
</div>
<mat-table #table [dataSource]="basketsDataSource" matSort matSortActive="basket_name" matSortDirection="asc">
<ng-container matColumnDef="basket_name">
<mat-header-cell *matHeaderCellDef mat-sort-header>{{lang.label}}</mat-header-cell>
<mat-cell *matCellDef="let element"> {{element.basket_name}} </mat-cell>
</ng-container>
<ng-container matColumnDef="basket_desc">
<mat-header-cell *matHeaderCellDef mat-sort-header>{{lang.description}}</mat-header-cell>
<mat-cell *matCellDef="let element"> {{element.basket_desc}} </mat-cell>
</ng-container>
<mat-header-row *matHeaderRowDef="basketsDisplayedColumns"></mat-header-row>
<mat-row *matRowDef="let row; columns: basketsDisplayedColumns;" routerLink="/administration/baskets/{{row.basket_id}}" matTooltip="{{lang.view}}" style="cursor:pointer;"></mat-row>
</mat-table>
</mat-tab>
</mat-tab-group> </mat-tab-group>
</mat-card> </mat-card>
</mat-sidenav-content> </mat-sidenav-content>
......
...@@ -30,16 +30,25 @@ export class GroupAdministrationComponent extends AutoCompletePlugin implements ...@@ -30,16 +30,25 @@ export class GroupAdministrationComponent extends AutoCompletePlugin implements
}; };
creationMode : boolean; creationMode : boolean;
displayedColumns = ['firstname', 'lastname']; usersDisplayedColumns = ['firstname', 'lastname'];
dataSource : any; basketsDisplayedColumns = ['basket_name', 'basket_desc'];
usersDataSource : any;
basketsDataSource : any;
@ViewChild('paginatorBaskets') paginatorBaskets: MatPaginator;
@ViewChild(MatPaginator) paginator: MatPaginator; @ViewChild(MatPaginator) paginator: MatPaginator;
@ViewChild(MatSort) sort: MatSort; @ViewChild(MatSort) sort: MatSort;
applyFilter(filterValue: string) { applyFilter(filterValue: string) {
filterValue = filterValue.trim(); filterValue = filterValue.trim();
filterValue = filterValue.toLowerCase(); filterValue = filterValue.toLowerCase();
this.dataSource.filter = filterValue; this.usersDataSource.filter = filterValue;
}
applyBasketsFilter(filterValue: string) {
filterValue = filterValue.trim();
filterValue = filterValue.toLowerCase();
this.basketsDataSource.filter = filterValue;
} }
constructor(changeDetectorRef: ChangeDetectorRef, media: MediaMatcher,public http: HttpClient, private route: ActivatedRoute, private router: Router, private notify: NotificationService) { constructor(changeDetectorRef: ChangeDetectorRef, media: MediaMatcher,public http: HttpClient, private route: ActivatedRoute, private router: Router, private notify: NotificationService) {
...@@ -69,9 +78,12 @@ export class GroupAdministrationComponent extends AutoCompletePlugin implements ...@@ -69,9 +78,12 @@ export class GroupAdministrationComponent extends AutoCompletePlugin implements
this.group = data['group']; this.group = data['group'];
this.loading = false; this.loading = false;
setTimeout(() => { setTimeout(() => {
this.dataSource = new MatTableDataSource(this.group.users); this.usersDataSource = new MatTableDataSource(this.group.users);
this.dataSource.paginator = this.paginator; this.usersDataSource.paginator = this.paginator;
this.dataSource.sort = this.sort; this.usersDataSource.sort = this.sort;
this.basketsDataSource = new MatTableDataSource(this.group.baskets);
this.basketsDataSource.paginator = this.paginatorBaskets;
this.basketsDataSource.sort = this.sort;
}, 0); }, 0);
}, () => { }, () => {
...@@ -98,7 +110,6 @@ export class GroupAdministrationComponent extends AutoCompletePlugin implements ...@@ -98,7 +110,6 @@ export class GroupAdministrationComponent extends AutoCompletePlugin implements
this.notify.error(err.error.errors); this.notify.error(err.error.errors);
}); });
} }
} }
updateService(service: any) { updateService(service: any) {
...@@ -115,22 +126,22 @@ export class GroupAdministrationComponent extends AutoCompletePlugin implements ...@@ -115,22 +126,22 @@ export class GroupAdministrationComponent extends AutoCompletePlugin implements
this.userCtrl.setValue(''); this.userCtrl.setValue('');
$j('.autocompleteSearch').blur(); $j('.autocompleteSearch').blur();
var groupReq = { var groupReq = {
"groupId": this.group.group_id, "groupId" : this.group.group_id,
"role": this.group.role "role" : this.group.role
}; };
this.http.post(this.coreUrl + "rest/users/" + newUser.id + "/groups", groupReq) this.http.post(this.coreUrl + "rest/users/" + newUser.id + "/groups", groupReq)
.subscribe((data: any) => { .subscribe(() => {
var displayName = newUser.idToDisplay.split(" "); var displayName = newUser.idToDisplay.split(" ");
var user = { var user = {
id : newUser.id, id : newUser.id,
user_id : newUser.otherInfo, user_id : newUser.otherInfo,
firstname : displayName[0], firstname : displayName[0],
lastname : displayName[1] lastname : displayName[1]
} };
this.group.users.push(user); this.group.users.push(user);
this.dataSource = new MatTableDataSource(this.group.users); this.usersDataSource = new MatTableDataSource(this.group.users);
this.dataSource.paginator = this.paginator; this.usersDataSource.paginator = this.paginator;
this.dataSource.sort = this.sort; this.usersDataSource.sort = this.sort;
this.notify.success(this.lang.userAdded); this.notify.success(this.lang.userAdded);
}, (err) => { }, (err) => {
this.notify.error(err.error.errors); this.notify.error(err.error.errors);
......
...@@ -319,6 +319,7 @@ export const LANG_EN = { ...@@ -319,6 +319,7 @@ export const LANG_EN = {
"redirects" : "Redirections", "redirects" : "Redirections",
"reinitPassword" : "Reset password", "reinitPassword" : "Reset password",
"relatedUsers" : "Related users", "relatedUsers" : "Related users",
"relatedBaskets" : "Related basket(s)",
"removeUserRedirect" : "Remove user (diffusion list + diffusion model entity)", "removeUserRedirect" : "Remove user (diffusion list + diffusion model entity)",
"renewPsw" : "Enter the password again", "renewPsw" : "Enter the password again",
"reports" : "Reports", "reports" : "Reports",
......
...@@ -401,6 +401,7 @@ export const LANG_FR = { ...@@ -401,6 +401,7 @@ export const LANG_FR = {
"redirectWhenAbscence" : "Rediriger la bannette à une personne", "redirectWhenAbscence" : "Rediriger la bannette à une personne",
"reinitPassword" : "Réinitialiser le mot de passe", "reinitPassword" : "Réinitialiser le mot de passe",
"relatedUsers" : "Utilisateur(s) associé(s)", "relatedUsers" : "Utilisateur(s) associé(s)",
"relatedBaskets" : "Bannette(s) associée(s)",
"removeUserRedirect" : "Supprimer la personne (liste de diffusion + modèle de l'entité)", "removeUserRedirect" : "Supprimer la personne (liste de diffusion + modèle de l'entité)",
"renewPsw" : "Retaper le mot de passe", "renewPsw" : "Retaper le mot de passe",
"reports" : "Statistiques", "reports" : "Statistiques",
......
...@@ -23,13 +23,15 @@ abstract class GroupBasketModelAbstract ...@@ -23,13 +23,15 @@ abstract class GroupBasketModelAbstract
public static function get(array $aArgs) public static function get(array $aArgs)
{ {
ValidatorModel::arrayType($aArgs, ['select', 'where', 'data', 'orderBy']); ValidatorModel::arrayType($aArgs, ['select', 'where', 'data', 'orderBy']);
ValidatorModel::intType($aArgs, ['limit']);
$aGroupsBaskets = DatabaseModel::select([ $aGroupsBaskets = DatabaseModel::select([
'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'],
'table' => ['groupbasket'], 'table' => ['groupbasket'],
'where' => $aArgs['where'], 'where' => empty($aArgs['where']) ? [] : $aArgs['where'],
'data' => $aArgs['data'], 'data' => empty($aArgs['data']) ? [] : $aArgs['data'],
'order_by' => $aArgs['orderBy'] 'order_by' => empty($aArgs['orderBy']) ? [] : $aArgs['orderBy'],
'limit' => empty($aArgs['limit']) ? 0 : $aArgs['limit']
]); ]);
return $aGroupsBaskets; return $aGroupsBaskets;
...@@ -91,4 +93,20 @@ abstract class GroupBasketModelAbstract ...@@ -91,4 +93,20 @@ abstract class GroupBasketModelAbstract
return true; return true;
} }
public static function getBasketsByGroupId(array $aArgs)
{
ValidatorModel::notEmpty($aArgs, ['groupId']);
ValidatorModel::stringType($aArgs, ['groupId']);
ValidatorModel::arrayType($aArgs, ['select']);
$aGroupsBaskets = DatabaseModel::select([
'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'],
'table' => ['groupbasket, baskets'],
'where' => ['groupbasket.group_id = ?', 'groupbasket.basket_id = baskets.basket_id'],
'data' => [$aArgs['groupId']]
]);
return $aGroupsBaskets;
}
} }
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace Group\controllers; namespace Group\controllers;
use Basket\models\GroupBasketModel;
use Group\models\ServiceModel; use Group\models\ServiceModel;
use Group\models\GroupModel; use Group\models\GroupModel;
use Respect\Validation\Validator; use Respect\Validation\Validator;
...@@ -134,10 +135,12 @@ class GroupController ...@@ -134,10 +135,12 @@ class GroupController
return $response->withStatus(400)->withJson(['errors' => 'Group not found']); return $response->withStatus(400)->withJson(['errors' => 'Group not found']);
} }
$group['users'] = GroupModel::getUsersByGroupId(['groupId' => $group['group_id'], 'select' => ['users.id', 'users.user_id', 'users.firstname', 'users.lastname']]); $group['security'] = GroupModel::getSecurityByGroupId(['groupId' => $group['group_id']]);
$group['security'] = GroupModel::getSecurityByGroupId(['groupId' => $group['group_id']]); $group['services'] = GroupModel::getAllServicesByGroupId(['groupId' => $group['group_id']]);
$group['services'] = GroupModel::getAllServicesByGroupId(['groupId' => $group['group_id']]); $group['users'] = GroupModel::getUsersByGroupId(['groupId' => $group['group_id'], 'select' => ['users.id', 'users.user_id', 'users.firstname', 'users.lastname']]);
$group['canAdminUsers'] = ServiceModel::hasService(['id' => 'admin_users', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin']); $group['baskets'] = GroupBasketModel::getBasketsByGroupId(['select' => ['baskets.basket_id', 'baskets.basket_name', 'baskets.basket_desc'], 'groupId' => $group['group_id']]);
$group['canAdminUsers'] = ServiceModel::hasService(['id' => 'admin_users', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin']);
$group['canAdminBaskets'] = ServiceModel::hasService(['id' => 'admin_baskets', 'userId' => $GLOBALS['userId'], 'location' => 'basket', 'type' => 'admin']);
return $response->withJson(['group' => $group]); return $response->withJson(['group' => $group]);
} }
......
...@@ -51,6 +51,12 @@ class GroupControllerTest extends TestCase ...@@ -51,6 +51,12 @@ class GroupControllerTest extends TestCase
$this->assertSame('Y', $responseBody->group->enabled); $this->assertSame('Y', $responseBody->group->enabled);
$this->assertSame('1=2', $responseBody->group->security->where_clause); $this->assertSame('1=2', $responseBody->group->security->where_clause);
$this->assertSame('commentateur du dimanche', $responseBody->group->security->maarch_comment); $this->assertSame('commentateur du dimanche', $responseBody->group->security->maarch_comment);
$this->assertInternalType('array', $responseBody->group->users);
$this->assertInternalType('array', $responseBody->group->baskets);
$this->assertEmpty($responseBody->group->users);
$this->assertEmpty($responseBody->group->baskets);
$this->assertSame(true, $responseBody->group->canAdminUsers);
$this->assertSame(true, $responseBody->group->canAdminBaskets);
} }
public function testUpdate() public function testUpdate()
...@@ -86,6 +92,12 @@ class GroupControllerTest extends TestCase ...@@ -86,6 +92,12 @@ class GroupControllerTest extends TestCase
$this->assertSame('Y', $responseBody->group->enabled); $this->assertSame('Y', $responseBody->group->enabled);
$this->assertSame('1=3', $responseBody->group->security->where_clause); $this->assertSame('1=3', $responseBody->group->security->where_clause);
$this->assertSame('commentateur du dimanche #2', $responseBody->group->security->maarch_comment); $this->assertSame('commentateur du dimanche #2', $responseBody->group->security->maarch_comment);
$this->assertInternalType('array', $responseBody->group->users);
$this->assertInternalType('array', $responseBody->group->baskets);
$this->assertEmpty($responseBody->group->users);
$this->assertEmpty($responseBody->group->baskets);
$this->assertSame(true, $responseBody->group->canAdminUsers);
$this->assertSame(true, $responseBody->group->canAdminBaskets);
} }
public function testDelete() public function testDelete()
......
...@@ -369,6 +369,7 @@ class ResControllerTest extends TestCase ...@@ -369,6 +369,7 @@ class ResControllerTest extends TestCase
// READ // READ
$res = \Resource\models\ResModel::getById(['resId' => self::$id]); $res = \Resource\models\ResModel::getById(['resId' => self::$id]);
$this->assertSame(null, $res); $this->assertInternalType('array', $res);
$this->assertEmpty($res);
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment