2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing,
12 * software distributed under the License is distributed on an
13 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 * KIND, either express or implied. See the License for the
15 * specific language governing permissions and limitations
19 import {Component, OnInit} from '@angular/core';
20 import {ActivatedRoute} from '@angular/router';
21 import {UserService} from "../../../../services/user.service";
22 import {FormBuilder, FormControl} from "@angular/forms";
23 import {catchError, map, switchMap, tap} from 'rxjs/operators';
24 import {ManageUsersBaseComponent} from "../manage-users-base.component";
25 import {ErrorResult} from "../../../../model/error-result";
28 selector: 'app-manage-users-edit',
29 templateUrl: './manage-users-edit.component.html',
30 styleUrls: ['./manage-users-edit.component.scss']
32 export class ManageUsersEditComponent extends ManageUsersBaseComponent implements OnInit {
34 editProperties = ['user_id', 'full_name', 'email', 'locked', 'password_change_required',
35 'password', 'confirm_password', 'validated'];
41 constructor(private route: ActivatedRoute, public userService: UserService, public fb: FormBuilder) {
42 super(userService, fb);
44 this.route.queryParams.subscribe((params)=>{
45 if (params.editmode) {
49 this.editUser = this.route.params.pipe(
50 map(params => params.userid), switchMap(userid => userService.getUser(userid))).subscribe(user => {
52 this.originUser = user;
53 this.copyToForm(this.editProperties, this.editUser);
58 // This resets the validators of the base class
59 this.userForm.get('user_id').clearValidators();
60 this.userForm.get('user_id').clearAsyncValidators();
63 valid(field: string): string[] {
65 let classArr = super.valid(field);
66 return classArr.concat('form-control')
68 return ['form-control-plaintext'];
74 let user = this.copyFromForm(this.editProperties);
75 this.userService.updateUser(user).pipe(
76 catchError((err: ErrorResult) => {
79 this.errorResult = err;
82 ).subscribe(userInfo=>{
85 this.errorResult=null;
86 this.result = userInfo;
87 this.editMode = false;