Added bulk editing (#1941)

pull/1959/head
Jamie 7 years ago committed by GitHub
parent f42b2938d2
commit e2a4c4ec17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -3,6 +3,7 @@
<button type="button" class="btn btn-success-outline" [routerLink]="['/usermanagement/add']">Add User</button> <button type="button" class="btn btn-success-outline" [routerLink]="['/usermanagement/add']">Add User</button>
<button type="button" style="float:right;" class="btn btn-primary-outline"(click)="showBulkEdit = !showBulkEdit" [disabled]="!hasChecked()">Bulk Edit</button>
<!-- Table --> <!-- Table -->
<table class="table table-striped table-hover table-responsive table-condensed table-usermanagement"> <table class="table table-striped table-hover table-responsive table-condensed table-usermanagement">
<thead> <thead>
@ -96,3 +97,33 @@
</tr> </tr>
</tbody> </tbody>
</table> </table>
<p-sidebar [(visible)]="showBulkEdit" position="right" styleClass="ui-sidebar-md side-back">
<h3>Bulk Edit</h3>
<hr/>
<div *ngFor="let c of availableClaims">
<div class="form-group">
<div class="checkbox">
<input type="checkbox" [(ngModel)]="c.enabled" [value]="c.value" id="create{{c.value}}" [attr.name]="'create' + c.value" ng-checked="c.enabled">
<label for="create{{c.value}}">{{c.value | humanize}}</label>
</div>
</div>
</div>
<div class="form-group">
<label for="movieRequestLimit" class="control-label">Movie Request Limit</label>
<div>
<input type="text" [(ngModel)]="bulkMovieLimit" class="form-control form-small form-control-custom " id="movieRequestLimit" name="movieRequestLimit" value="{{bulkMovieLimit}}">
</div>
</div>
<div class="form-group">
<label for="episodeRequestLimit" class="control-label">Episode Request Limit</label>
<div>
<input type="text" [(ngModel)]="bulkEpisodeLimit" class="form-control form-small form-control-custom " id="episodeRequestLimit" name="episodeRequestLimit" value="{{bulkEpisodeLimit}}">
</div>
</div>
<button type="button" class="btn btn-success-outline" (click)="bulkUpdate()">Update Users</button>
</p-sidebar>

@ -1,6 +1,6 @@
import { Component, OnInit } from "@angular/core"; import { Component, OnInit } from "@angular/core";
import { ICustomizationSettings, IEmailNotificationSettings, IUser } from "../interfaces"; import { ICheckbox, ICustomizationSettings, IEmailNotificationSettings,IUser } from "../interfaces";
import { IdentityService, NotificationService, SettingsService } from "../services"; import { IdentityService, NotificationService, SettingsService } from "../services";
@Component({ @Component({
@ -16,6 +16,11 @@ export class UserManagementComponent implements OnInit {
public order: string = "u.userName"; public order: string = "u.userName";
public reverse = false; public reverse = false;
public showBulkEdit = false;
public availableClaims: ICheckbox[];
public bulkMovieLimit?: number;
public bulkEpisodeLimit?: number;
constructor(private readonly identityService: IdentityService, constructor(private readonly identityService: IdentityService,
private readonly settingsService: SettingsService, private readonly settingsService: SettingsService,
private readonly notificationService: NotificationService) { } private readonly notificationService: NotificationService) { }
@ -26,6 +31,7 @@ export class UserManagementComponent implements OnInit {
this.users = x; this.users = x;
}); });
this.identityService.getAllAvailableClaims().subscribe(x => this.availableClaims = x);
this.settingsService.getCustomization().subscribe(x => this.customizationSettings = x); this.settingsService.getCustomization().subscribe(x => this.customizationSettings = x);
this.settingsService.getEmailNotificationSettings().subscribe(x => this.emailSettings = x); this.settingsService.getEmailNotificationSettings().subscribe(x => this.emailSettings = x);
} }
@ -49,6 +55,43 @@ export class UserManagementComponent implements OnInit {
user.checked = this.checkAll; user.checked = this.checkAll;
}); });
} }
public hasChecked(): boolean {
return this.users.some(x => {
return x.checked;
});
}
public bulkUpdate() {
const anyRoles = this.availableClaims.some(x => {
return x.enabled;
});
this.users.forEach(x => {
if(!x.checked) {
return;
}
if(anyRoles) {
x.claims = this.availableClaims;
}
if(this.bulkEpisodeLimit && this.bulkEpisodeLimit > 0) {
x.episodeRequestLimit = this.bulkEpisodeLimit;
}
if(this.bulkMovieLimit && this.bulkMovieLimit > 0) {
x.movieRequestLimit = this.bulkMovieLimit;
}
this.identityService.updateUser(x).subscribe(y => {
if(!y.successful) {
this.notificationService.error(`Could not update user ${x.userName}. Reason ${y.errors[0]}`);
}
});
});
this.notificationService.success(`Updated users`);
this.showBulkEdit = false;
this.bulkMovieLimit = undefined;
this.bulkEpisodeLimit = undefined;
}
public setOrder(value: string) { public setOrder(value: string) {
if (this.order === value) { if (this.order === value) {

@ -2,7 +2,7 @@
import { NgModule } from "@angular/core"; import { NgModule } from "@angular/core";
import { FormsModule, ReactiveFormsModule } from "@angular/forms"; import { FormsModule, ReactiveFormsModule } from "@angular/forms";
import { RouterModule, Routes } from "@angular/router"; import { RouterModule, Routes } from "@angular/router";
import { ConfirmationService, ConfirmDialogModule, MultiSelectModule, TooltipModule } from "primeng/primeng"; import { ConfirmationService, ConfirmDialogModule, MultiSelectModule, SidebarModule, TooltipModule } from "primeng/primeng";
import { NgbModule } from "@ng-bootstrap/ng-bootstrap"; import { NgbModule } from "@ng-bootstrap/ng-bootstrap";
@ -37,6 +37,7 @@ const routes: Routes = [
ConfirmDialogModule, ConfirmDialogModule,
TooltipModule, TooltipModule,
OrderModule, OrderModule,
SidebarModule,
], ],
declarations: [ declarations: [
UserManagementComponent, UserManagementComponent,

Loading…
Cancel
Save