#124 [intUI/Filter] for UserRoleAssignment

This commit is contained in:
Michael Hoennig 2019-05-03 14:41:41 +02:00
parent 3c6618e3cb
commit 0a9f2584f1
2 changed files with 67 additions and 7 deletions

View File

@ -21,6 +21,34 @@
<th jhiSortBy="user.login"><span jhiTranslate="hsadminNgApp.userRoleAssignment.user">User</span> <fa-icon [icon]="'sort'"></fa-icon></th> <th jhiSortBy="user.login"><span jhiTranslate="hsadminNgApp.userRoleAssignment.user">User</span> <fa-icon [icon]="'sort'"></fa-icon></th>
<th></th> <th></th>
</tr> </tr>
<!-- filter start: -->
<tr>
<th style="width: 10%"></th>
<th style="width: 10%"><input type="text" class="form-control" style="max-width: 20em" [(ngModel)]="filter.criteria.entityTypeId" (keyup)="filter.trigger($event)"></th>
<th style="width: 10%"><input type="text" class="form-control" style="max-width: 20em" [(ngModel)]="filter.criteria.entityObjectId" (keyup)="filter.trigger($event)"></th>
<th style="width: 10%">
<select class="form-control" [(ngModel)]="filter.criteria.assignedRole" (change)="filter.trigger($event)">
<option value=""></option>
<option value="HOSTMASTER" jhiTranslate="{{'hsadminNgApp.UserRole.HOSTMASTER'}}">HOSTMASTER</option>
<option value="ADMIN" jhiTranslate="{{'hsadminNgApp.UserRole.ADMIN'}}">ADMIN</option>
<option value="SUPPORTER" jhiTranslate="{{'hsadminNgApp.UserRole.SUPPORTER'}}">SUPPORTER</option>
<option value="CONTRACTUAL_CONTACT" jhiTranslate="{{'hsadminNgApp.UserRole.CONTRACTUAL_CONTACT'}}">CONTRACTUAL_CONTACT</option>
<option value="FINANCIAL_CONTACT" jhiTranslate="{{'hsadminNgApp.UserRole.FINANCIAL_CONTACT'}}">FINANCIAL_CONTACT</option>
<option value="TECHNICAL_CONTACT" jhiTranslate="{{'hsadminNgApp.UserRole.TECHNICAL_CONTACT'}}">TECHNICAL_CONTACT</option>
<option value="CUSTOMER_USER" jhiTranslate="{{'hsadminNgApp.UserRole.CUSTOMER_USER'}}">CUSTOMER_USER</option>
</select>
</th>
<th style="width: 30%">
<select id="field_user" class="form-control" name="user" [(ngModel)]="filter.criteria.userId" (change)="filter.trigger($event)">
<option [ngValue]="null" selected></option>
<option [ngValue]="userOption.id" *ngFor="let userOption of users; trackBy: trackId">{{userOption.login}}</option>
</select>
</th>
<th style="width: 20%"><button class="btn btn-primary float-left" (click)="filter.reset()">Reset Filter</button></th>
</tr>
<!-- filter end. -->
</thead> </thead>
<tbody infinite-scroll (scrolled)="loadPage(page + 1)" [infiniteScrollDisabled]="page >= links['last']" [infiniteScrollDistance]="0"> <tbody infinite-scroll (scrolled)="loadPage(page + 1)" [infiniteScrollDisabled]="page >= links['last']" [infiniteScrollDistance]="0">
<tr *ngFor="let userRoleAssignment of userRoleAssignments ;trackBy: trackId"> <tr *ngFor="let userRoleAssignment of userRoleAssignments ;trackBy: trackId">

View File

@ -9,6 +9,9 @@ import { AccountService } from 'app/core';
import { ITEMS_PER_PAGE } from 'app/shared'; import { ITEMS_PER_PAGE } from 'app/shared';
import { UserRoleAssignmentService } from './user-role-assignment.service'; import { UserRoleAssignmentService } from './user-role-assignment.service';
import { IUser } from 'app/core/user/user.model';
import { UserService } from 'app/core/user/user.service';
import { TableFilter, queryEquals, queryContains } from 'app/shared/util/tablefilter';
@Component({ @Component({
selector: 'jhi-user-role-assignment', selector: 'jhi-user-role-assignment',
@ -24,9 +27,17 @@ export class UserRoleAssignmentComponent implements OnInit, OnDestroy {
predicate: any; predicate: any;
reverse: any; reverse: any;
totalItems: number; totalItems: number;
users: IUser[];
filter: TableFilter<{
entityTypeId?: string;
entityObjectId?: string;
assignedRole?: string;
userId?: string;
}>;
constructor( constructor(
protected userRoleAssignmentService: UserRoleAssignmentService, protected userRoleAssignmentService: UserRoleAssignmentService,
protected userService: UserService,
protected jhiAlertService: JhiAlertService, protected jhiAlertService: JhiAlertService,
protected eventManager: JhiEventManager, protected eventManager: JhiEventManager,
protected parseLinks: JhiParseLinks, protected parseLinks: JhiParseLinks,
@ -40,11 +51,24 @@ export class UserRoleAssignmentComponent implements OnInit, OnDestroy {
}; };
this.predicate = 'id'; this.predicate = 'id';
this.reverse = true; this.reverse = true;
this.filter = new TableFilter(
{
entityTypeId: queryContains,
entityObjectId: queryEquals,
assignedRole: queryEquals,
userId: queryEquals
},
500,
() => {
this.loadAll();
}
);
} }
loadAll() { loadAll() {
this.userRoleAssignmentService this.userRoleAssignmentService
.query({ .query({
...this.filter.buildQueryCriteria(),
page: this.page, page: this.page,
size: this.itemsPerPage, size: this.itemsPerPage,
sort: this.sort() sort: this.sort()
@ -71,6 +95,13 @@ export class UserRoleAssignmentComponent implements OnInit, OnDestroy {
this.accountService.identity().then(account => { this.accountService.identity().then(account => {
this.currentAccount = account; this.currentAccount = account;
}); });
this.userService
.query()
.pipe(
filter((mayBeOk: HttpResponse<IUser[]>) => mayBeOk.ok),
map((response: HttpResponse<IUser[]>) => response.body)
)
.subscribe((res: IUser[]) => (this.users = res), (res: HttpErrorResponse) => this.onError(res.message));
this.registerChangeInUserRoleAssignments(); this.registerChangeInUserRoleAssignments();
} }
@ -78,7 +109,7 @@ export class UserRoleAssignmentComponent implements OnInit, OnDestroy {
this.eventManager.destroy(this.eventSubscriber); this.eventManager.destroy(this.eventSubscriber);
} }
trackId(index: number, item: IUserRoleAssignment) { trackId(index: number, item: { id: number }) {
return item.id; return item.id;
} }
@ -97,6 +128,7 @@ export class UserRoleAssignmentComponent implements OnInit, OnDestroy {
protected paginateUserRoleAssignments(data: IUserRoleAssignment[], headers: HttpHeaders) { protected paginateUserRoleAssignments(data: IUserRoleAssignment[], headers: HttpHeaders) {
this.links = this.parseLinks.parse(headers.get('link')); this.links = this.parseLinks.parse(headers.get('link'));
this.totalItems = parseInt(headers.get('X-Total-Count'), 10); this.totalItems = parseInt(headers.get('X-Total-Count'), 10);
this.userRoleAssignments = [];
for (let i = 0; i < data.length; i++) { for (let i = 0; i < data.length; i++) {
this.userRoleAssignments.push(data[i]); this.userRoleAssignments.push(data[i]);
} }