Adding user edit component

This commit is contained in:
Martin Stockhammer 2020-11-11 23:02:43 +01:00
parent 34697b1a55
commit dd422882ca
7 changed files with 124 additions and 70 deletions

View File

@ -49,6 +49,7 @@ const routes: Routes = [
{path: 'list', component: ManageUsersListComponent},
{path: 'add', component: ManageUsersAddComponent},
{path: 'edit/:userid', component: ManageUsersEditComponent},
{path: 'edit', redirectTo:'edit/guest' },
{path: '', redirectTo:'list', pathMatch:'full'}
]
},

View File

@ -25,7 +25,7 @@
<a class="nav-link" routerLink="/user/users/add" routerLinkActive="active" href="#">{{'users.add.head' |translate }}</a>
</li>
<li class="nav-item">
<a class="nav-link" routerLink="/user/users/edit/guest" routerLinkActive="active" href="#">{{'users.edit.head' |translate }}</a>
<a class="nav-link" routerLink="/user/users/edit" routerLinkActive="active" href="#">{{'users.edit.head' |translate }}</a>
</li>
</ul>

View File

@ -26,6 +26,7 @@ import {HttpErrorResponse} from "@angular/common/http";
import {ErrorResult} from "../../../../model/error-result";
import {catchError} from "rxjs/operators";
import {of, throwError} from 'rxjs';
import {environment} from "../../../../../environments/environment";
@Component({
selector: 'app-manage-users-add',
@ -34,7 +35,7 @@ import {of, throwError} from 'rxjs';
})
export class ManageUsersAddComponent implements OnInit {
minUserIdSize=8;
minUserIdSize=environment.application.minUserIdLength;
success:boolean=false;
error:boolean=false;
errorResult:ErrorResult;
@ -53,7 +54,7 @@ export class ManageUsersAddComponent implements OnInit {
validator: MustMatch('password', 'confirm_password')
})
constructor(private userService: UserService, private fb: FormBuilder) {
constructor(public userService: UserService, public fb: FormBuilder) {
}
@ -97,16 +98,16 @@ export class ManageUsersAddComponent implements OnInit {
}
valid(field:string) : string {
valid(field:string) : string[] {
let formField = this.userForm.get(field);
if (formField.dirty||formField.touched) {
if (formField.valid) {
return 'is-valid'
return ['is-valid']
} else {
return 'is-invalid'
return ['is-invalid']
}
} else {
return ''
return ['']
}
}

View File

@ -17,56 +17,75 @@
-->
<form class="mt-3 mb-3" [formGroup]="userForm" (ngSubmit)="onSubmit()">
<div class="form-group col-md-8">
<label for="user_id">{{'users.attributes.user_id' |translate}}</label>
<input type="text" class="form-control" formControlName="user_id" id="user_id"
<div class="form-group row col-md-8">
<div class="col-md-1">Edit <span class="fas fa-edit"></span></div>
<div class="col-md-6">
<input class="form-check-input" type="checkbox" [value]="editMode"
(change)="editMode=!editMode"
>
</div>
</div>
<div class="form-group row col-md-8">
<label class="col-md-2 col-form-label" for="user_id">{{'users.attributes.user_id' |translate}}</label>
<div class="col-md-6" >
<input type="text" formControlName="user_id" id="user_id"
[ngClass]="valid('user_id')"
placeholder="{{'users.input.user_id'|translate}}">
<small>{{'users.input.small.user_id'|translate:{'minSize':this.minUserIdSize} }}</small>
value="{{editUser.user_id}}" [attr.readonly]="!editMode">
<small *ngIf="editMode">{{'users.input.small.user_id'|translate:{'minSize':this.minUserIdSize} }}</small>
</div>
<div class="form-group col-md-8">
<label for="full_name">{{'users.attributes.full_name' |translate}}</label>
<input type="text" class="form-control" formControlName="full_name" id="full_name"
[ngClass]="valid('full_name')"
placeholder="{{'users.input.full_name'|translate}}">
<small>{{'users.input.small.full_name'|translate}}</small>
</div>
<div class="form-group col-md-8">
<label for="email">{{'users.attributes.email' |translate}}</label>
<input type="text" class="form-control" formControlName="email" id="email"
[ngClass]="valid('email')"
placeholder="{{'users.input.email'|translate}}">
<div class="form-group row col-md-8">
<label class="col-md-2 col-form-label" for="full_name">{{'users.attributes.full_name' |translate}}</label>
<div class="col-md-6" >
<input type="text" formControlName="full_name" id="full_name"
[ngClass]="valid('full_name')" value="{{editUser.full_name}}" [attr.readonly]="!editMode" >
<small *ngIf="editMode">{{'users.input.small.full_name'|translate}}</small>
</div>
<div class="form-group col-md-8">
<label for="password">{{'users.attributes.password' |translate}}</label>
</div>
<div class="form-group row col-md-8">
<label class="col-md-2 col-form-label" for="email">{{'users.attributes.email' |translate}}</label>
<div class="col-md-6" >
<input type="text" formControlName="email" id="email"
[ngClass]="valid('email')" value="{{editUser.email}}" [attr.readonly]="!editMode">
</div>
</div>
<div class="form-group row col-md-8" *ngIf="editMode">
<label class="col-md-2 col-form-label" for="password">{{'users.attributes.password' |translate}}</label>
<div class="col-md-6" >
<input type="password" class="form-control" formControlName="password" id="password"
[ngClass]="valid('password')"
placeholder="{{'users.input.password'|translate}}">
</div>
<div class="form-group col-md-8">
<label for="confirm_password">{{'users.attributes.confirm_password' |translate}}</label>
</div>
<div class="form-group row col-md-8" *ngIf="editMode">
<label class="col-md-2 col-form-label" for="confirm_password">{{'users.attributes.confirm_password' |translate}}</label>
<div class="col-md-6">
<input type="password" class="form-control" formControlName="confirm_password" id="confirm_password"
[ngClass]="valid('confirm_password')"
placeholder="{{'users.input.confirm_password'|translate}}">
</div>
<div class="form-group col-md-8">
</div>
<div class="form-group row col-md-8">
<div class="col-md-2">Flags</div>
<div class="col-md-6">
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" formControlName="locked" id="locked">
<input class="form-check-input" type="checkbox" value="{{editUser.locked}}" formControlName="locked" id="locked" [attr.disabled]="editMode?null:true">
<label class="form-check-label" for="locked" >
{{'users.attributes.locked'|translate}}
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" formControlName="password_change_required"
id="password_change_required" checked>
<input class="form-check-input" type="checkbox" value="{{editUser.password_change_required}}" formControlName="password_change_required"
id="password_change_required" [attr.disabled]="editMode?null:true">
<label class="form-check-label" for="password_change_required">
{{'users.attributes.password_change_required'|translate}}
</label>
</div>
</div>
<div class="form-group col-md-8">
</div>
<div class="form-group col-md-8" *ngIf="editMode">
<button class="btn btn-primary" type="submit"
[disabled]="!userForm.valid">{{'users.add.submit'|translate}}</button>
[disabled]="!userForm.valid">{{'users.edit.submit'|translate}}</button>
</div>
<div *ngIf="success" class="alert alert-success" role="alert">
User <a [routerLink]="['user','users','edit',userid]">{{userid}}</a> was added to the list.

View File

@ -18,21 +18,40 @@
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import {UserService} from "../../../../services/user.service";
import {FormBuilder, Validators} from "@angular/forms";
import {ManageUsersAddComponent, MustMatch} from "../manage-users-add/manage-users-add.component";
import {environment} from "../../../../../environments/environment";
import {map, switchMap} from 'rxjs/operators';
@Component({
selector: 'app-manage-users-edit',
templateUrl: './manage-users-edit.component.html',
styleUrls: ['./manage-users-edit.component.scss']
})
export class ManageUsersEditComponent implements OnInit {
export class ManageUsersEditComponent extends ManageUsersAddComponent implements OnInit {
userid;
editUser;
editMode:boolean=false;
constructor(private route: ActivatedRoute) {
this.route.params.subscribe(params => this.userid=params.userid);
constructor(private route: ActivatedRoute, public userService: UserService, public fb: FormBuilder) {
super(userService, fb);
this.editUser = this.route.params.pipe(map (params => params.userid ), switchMap(userid => userService.getUser(userid)) ).subscribe(user => {
this.editUser = user;});
}
ngOnInit(): void {
}
}
valid(field: string): string[] {
if (this.editMode) {
let classArr = super.valid(field);
return classArr.concat('form-control')
} else {
return ['form-control-plaintext'];
}
}
}

View File

@ -24,7 +24,6 @@ import {ErrorResult} from "../model/error-result";
import {Observable, throwError} from "rxjs";
import {Permission} from '../model/permission';
import {PagedResult} from "../model/paged-result";
import {EntityService} from "../model/entity-service";
import {User} from '../model/user';
import {catchError, map} from "rxjs/operators";
@ -172,6 +171,7 @@ export class UserService implements OnInit, OnDestroy {
resetPermissions() {
this.deepCopy(this.uiPermissionsDefault, this.uiPermissions);
}
parsePermissions(permissions: Permission[]) {
this.resetPermissions();
for (let perm of permissions) {
@ -268,7 +268,13 @@ export class UserService implements OnInit, OnDestroy {
if (orderBy == null || orderBy.length == 0) {
orderBy = ['user_id'];
}
return this.rest.executeRestCall<PagedResult<UserInfo>>("get", "redback", "users", {'q':searchTerm, 'offset':offset,'limit':limit,'orderBy':orderBy,'order':order});
return this.rest.executeRestCall<PagedResult<UserInfo>>("get", "redback", "users", {
'q': searchTerm,
'offset': offset,
'limit': limit,
'orderBy': orderBy,
'order': order
});
}
@ -278,4 +284,11 @@ export class UserService implements OnInit, OnDestroy {
return throwError(this.rest.getTranslatedErrorResult(error));
}), map((httpResponse: HttpResponse<string>) => httpResponse.headers.get('Location')));
}
public getUser(userid: string): Observable<UserInfo> {
return this.rest.executeRestCall<UserInfo>("get", "redback", "users/" + userid, null).pipe(
catchError((error: HttpErrorResponse) => {
return throwError(this.rest.getTranslatedErrorResult(error));
}));
}
}

View File

@ -28,6 +28,7 @@ export const environment = {
client_id:'archiva_web_client',
baseUrl: 'http://localhost:8080',
restPath: '/archiva/api/v2',
minUserIdLength: 8,
servicePaths: {
archiva:"archiva",
redback:"redback",