From 4d293f3b6d28bd96f77fa0dae2d3d71c5ccd8e75 Mon Sep 17 00:00:00 2001 From: andrej romanov <50377758+auumgn@users.noreply.github.com> Date: Tue, 6 Feb 2024 22:54:17 +0200 Subject: [PATCH] prettier --- ui/src/app/user/user-update.component.ts | 276 ++++++++++++----------- 1 file changed, 141 insertions(+), 135 deletions(-) diff --git a/ui/src/app/user/user-update.component.ts b/ui/src/app/user/user-update.component.ts index 044b3ddcf..cd67943c1 100644 --- a/ui/src/app/user/user-update.component.ts +++ b/ui/src/app/user/user-update.component.ts @@ -1,39 +1,36 @@ -import { ChangeDetectorRef, Component, OnInit } from '@angular/core'; -import { HttpResponse } from '@angular/common/http'; -import { FormBuilder, Validators } from '@angular/forms'; -import { ActivatedRoute, Router } from '@angular/router'; -import { EMPTY, Observable } from 'rxjs'; -import * as moment from 'moment'; -import { faBan, faCheckCircle, faSave } from '@fortawesome/free-solid-svg-icons'; - - -import { map } from 'rxjs/operators'; -import { AlertService } from '../shared/service/alert.service'; -import { UserService } from './service/user.service'; -import { MemberService } from '../member/service/member.service'; -import { AccountService } from '../account'; -import { IUser, User } from './model/user.model'; -import { IMember } from '../member/model/member.model'; -import { ErrorService } from '../error/service/error.service'; -import { DATE_TIME_FORMAT, emailValidator } from '../app.constants'; +import { ChangeDetectorRef, Component, OnInit } from '@angular/core' +import { HttpResponse } from '@angular/common/http' +import { FormBuilder, Validators } from '@angular/forms' +import { ActivatedRoute, Router } from '@angular/router' +import { EMPTY, Observable } from 'rxjs' +import * as moment from 'moment' +import { faBan, faCheckCircle, faSave } from '@fortawesome/free-solid-svg-icons' + +import { map } from 'rxjs/operators' +import { AlertService } from '../shared/service/alert.service' +import { UserService } from './service/user.service' +import { MemberService } from '../member/service/member.service' +import { AccountService } from '../account' +import { IUser, User } from './model/user.model' +import { IMember } from '../member/model/member.model' +import { ErrorService } from '../error/service/error.service' +import { DATE_TIME_FORMAT, emailValidator } from '../app.constants' @Component({ selector: 'app-user-update', templateUrl: './user-update.component.html', - styleUrls: ['./user-update.component.scss'] + styleUrls: ['./user-update.component.scss'], }) export class UserUpdateComponent { - - - isSaving = false; - isExistentMember = false; - existentUser: IUser | null = null; - faCheckCircle = faCheckCircle; - faBan = faBan; - faSave = faSave; - showIsAdminCheckbox = false; - currentAccount: any; - validation: any; + isSaving = false + isExistentMember = false + existentUser: IUser | null = null + faCheckCircle = faCheckCircle + faBan = faBan + faSave = faSave + showIsAdminCheckbox = false + currentAccount: any + validation: any editForm = this.fb.group({ id: [''], @@ -41,18 +38,18 @@ export class UserUpdateComponent { firstName: ['', Validators.required], lastName: ['', Validators.required], mainContact: [false], - assertionServiceEnabled: [], + assertionServiceEnabled: [false], salesforceId: ['', Validators.required], activated: [false], isAdmin: [false], createdBy: [''], createdDate: [''], lastModifiedBy: [''], - lastModifiedDate: [''] - }); + lastModifiedDate: [''], + }) - memberList = [] as IMember[]; - hasOwner = false; + memberList = [] as IMember[] + hasOwner = false constructor( protected alertService: AlertService, @@ -65,46 +62,46 @@ export class UserUpdateComponent { private fb: FormBuilder, private cdref: ChangeDetectorRef ) { - this.validation = {}; + this.validation = {} } ngOnInit() { - this.isSaving = false; - this.isExistentMember = false; - this.existentUser = null; + this.isSaving = false + this.isExistentMember = false + this.existentUser = null this.activatedRoute.data.subscribe(({ user }) => { - this.existentUser = user; - }); - this.editForm.disable(); - this.accountService.getAccountData().subscribe(account => { - this.currentAccount = account; + this.existentUser = user + }) + this.editForm.disable() + this.accountService.getAccountData().subscribe((account) => { + this.currentAccount = account this.getMemberList().subscribe((list: IMember[]) => { list.forEach((msMember: IMember) => { - this.memberList.push(msMember); - }); - this.editForm.enable(); + this.memberList.push(msMember) + }) + this.editForm.enable() if (this.existentUser) { - this.updateForm(this.existentUser); + this.updateForm(this.existentUser) } - }); - }); - this.cdref.detectChanges(); - this.onChanges(); + }) + }) + this.cdref.detectChanges() + this.onChanges() } onChanges(): void { - this.editForm.get('salesforceId')?.valueChanges.subscribe(val => { - const selectedOrg = this.memberList.find(cm => cm.salesforceId === this.editForm.get(['salesforceId'])?.value); + this.editForm.get('salesforceId')?.valueChanges.subscribe((val) => { + const selectedOrg = this.memberList.find((cm) => cm.salesforceId === this.editForm.get(['salesforceId'])?.value) if (this.hasRoleAdmin()) { if (selectedOrg) { - this.showIsAdminCheckbox = selectedOrg.superadminEnabled || false; + this.showIsAdminCheckbox = selectedOrg.superadminEnabled || false } else { - this.showIsAdminCheckbox = false; + this.showIsAdminCheckbox = false } } else { - this.showIsAdminCheckbox = false; + this.showIsAdminCheckbox = false } - }); + }) } updateForm(user: IUser) { @@ -120,158 +117,153 @@ export class UserUpdateComponent { createdBy: user.createdBy, createdDate: user.createdDate != null ? user.createdDate.format(DATE_TIME_FORMAT) : null, lastModifiedBy: user.lastModifiedBy, - lastModifiedDate: user.lastModifiedDate != null ? user.lastModifiedDate.format(DATE_TIME_FORMAT) : null - }); + lastModifiedDate: user.lastModifiedDate != null ? user.lastModifiedDate.format(DATE_TIME_FORMAT) : null, + }) if (user.mainContact) { - this.editForm.get('mainContact')?.disable(); - this.editForm.get('salesforceId')?.disable(); + this.editForm.get('mainContact')?.disable() + this.editForm.get('salesforceId')?.disable() } if (user.salesforceId) { - this.isExistentMember = true; + this.isExistentMember = true } if (user.email) { - this.editForm.get('email')?.disable(); + this.editForm.get('email')?.disable() } } getMemberList(): Observable { if (this.hasRoleAdmin()) { return this.memberService.getAllMembers().pipe( - map(res => { + map((res) => { if (res.body) { - return res.body; + return res.body } return [] }) - ); + ) } else { return this.memberService.find(this.currentAccount.salesforceId).pipe( - map(res => { + map((res) => { if (res) { - return [res]; + return [res] } return [] }) - ); + ) } } navigateToUsersList() { - this.router.navigate(['/users']); + this.router.navigate(['/users']) } disableSalesForceIdDD() { if (this.hasRoleAdmin()) { - return false; + return false } else if (this.hasRoleOrgOwner() || this.hasRoleConsortiumLead()) { this.editForm.patchValue({ - salesforceId: this.getSalesForceId() - }); - return true; + salesforceId: this.getSalesForceId(), + }) + return true } - return this.isExistentMember; + return this.isExistentMember } getSalesForceId() { - return this.accountService.getSalesforceId(); + return this.accountService.getSalesforceId() } hasRoleAdmin() { - return this.accountService.hasAnyAuthority(['ROLE_ADMIN']); + return this.accountService.hasAnyAuthority(['ROLE_ADMIN']) } hasRoleOrgOwner() { - return this.accountService.hasAnyAuthority(['ROLE_ORG_OWNER']); + return this.accountService.hasAnyAuthority(['ROLE_ORG_OWNER']) } hasRoleConsortiumLead() { - return this.accountService.hasAnyAuthority(['ROLE_CONSORTIUM_LEAD']); + return this.accountService.hasAnyAuthority(['ROLE_CONSORTIUM_LEAD']) } validateOrgOwners() { - this.isSaving = true; + this.isSaving = true const sfId = this.editForm.get('salesforceId')?.value if (sfId) { - this.userService.hasOwner(sfId).subscribe(value => { - this.isSaving = false; + this.userService.hasOwner(sfId).subscribe((value) => { + this.isSaving = false if (!this.editForm.get('mainContact')?.value) { - this.hasOwner = false; + this.hasOwner = false } else { - this.hasOwner = value; + this.hasOwner = value } - }); - + }) + if (this.editForm.get('mainContact')?.value) { - this.editForm.get('salesforceId')?.disable(); + this.editForm.get('salesforceId')?.disable() } else { - this.editForm.get('salesforceId')?.enable(); + this.editForm.get('salesforceId')?.enable() } - } } save() { if (this.editForm.valid) { - this.isSaving = true; - const msUser = this.createFromForm(); + this.isSaving = true + const msUser = this.createFromForm() - this.userService.validate(msUser).subscribe(response => { - const data = response; + this.userService.validate(msUser).subscribe((response) => { + const data = response if (data.valid) { - if (msUser.id !== undefined) { if (this.currentAccount.id === msUser.id) { if (this.currentAccount.mainContact !== msUser.mainContact) { - this.subscribeToUpdateResponseWithOwnershipChange(this.userService.update(msUser)); + this.subscribeToUpdateResponseWithOwnershipChange(this.userService.update(msUser)) } else { - this.subscribeToUpdateResponse(this.userService.update(msUser)); + this.subscribeToUpdateResponse(this.userService.update(msUser)) } } else if (msUser.mainContact && !this.hasRoleAdmin()) { - this.subscribeToUpdateResponseWithOwnershipChange(this.userService.update(msUser)); + this.subscribeToUpdateResponseWithOwnershipChange(this.userService.update(msUser)) } else { - this.subscribeToUpdateResponse(this.userService.update(msUser)); + this.subscribeToUpdateResponse(this.userService.update(msUser)) } } else { if (msUser.mainContact && !this.hasRoleAdmin()) { - this.subscribeToSaveResponseWithOwnershipChange(this.userService.create(msUser)); + this.subscribeToSaveResponseWithOwnershipChange(this.userService.create(msUser)) } else { - this.subscribeToSaveResponse(this.userService.create(msUser)); + this.subscribeToSaveResponse(this.userService.create(msUser)) } } } else { - this.isSaving = false; - this.validation = data; + this.isSaving = false + this.validation = data } - }); + }) } } sendActivate() { - if (this.existentUser) { - this.userService.sendActivate(this.existentUser).subscribe(res => { + if (this.existentUser?.id) { + this.userService.sendActivate(this.existentUser).subscribe((res) => { if (res) { - this.alertService.broadcast('gatewayApp.msUserServiceMSUser.sendActivate.success.string'); + this.alertService.broadcast('gatewayApp.msUserServiceMSUser.sendActivate.success.string') } else { - this.alertService.broadcast('gatewayApp.msUserServiceMSUser.sendActivate.error.string'); + this.alertService.broadcast('gatewayApp.msUserServiceMSUser.sendActivate.error.string') } - this.navigateToUsersList(); - }); + this.navigateToUsersList() + }) } } displaySendActivate() { if (this.existentUser && this.existentUser.email && !this.existentUser.activated) { - console.log('this.existentMSUser: ', this.existentUser); - console.log('this.existentMSUser.activated', this.existentUser.activated); - return true; + return true } - return false; + return false } private createFromForm(): IUser { - return { ...new User(), id: this.editForm.get(['id'])?.value !== '' ? this.editForm.get(['id'])?.value : undefined, @@ -283,57 +275,71 @@ export class UserUpdateComponent { salesforceId: this.editForm.get(['salesforceId'])?.value, createdBy: this.editForm.get(['createdBy'])?.value, createdDate: - this.editForm.get(['createdDate'])?.value != null ? moment(this.editForm.get(['createdDate'])?.value, DATE_TIME_FORMAT) : undefined, + this.editForm.get(['createdDate'])?.value != null + ? moment(this.editForm.get(['createdDate'])?.value, DATE_TIME_FORMAT) + : undefined, lastModifiedBy: this.editForm.get(['lastModifiedBy'])?.value, lastModifiedDate: this.editForm.get(['lastModifiedDate'])?.value != null ? moment(this.editForm.get(['lastModifiedDate'])?.value, DATE_TIME_FORMAT) - : undefined - }; + : undefined, + } } protected subscribeToSaveResponse(result: Observable) { - result.subscribe(() => this.onSaveSuccess(), () => this.onSaveError()); + result.subscribe( + () => this.onSaveSuccess(), + () => this.onSaveError() + ) } protected subscribeToUpdateResponse(result: Observable) { - result.subscribe(() => this.onUpdateSuccess(), () => this.onSaveError()); + result.subscribe( + () => this.onUpdateSuccess(), + () => this.onSaveError() + ) } protected subscribeToSaveResponseWithOwnershipChange(result: Observable) { - result.subscribe(() => this.onSaveSuccessOwnershipChange(), () => this.onSaveError()); + result.subscribe( + () => this.onSaveSuccessOwnershipChange(), + () => this.onSaveError() + ) } protected subscribeToUpdateResponseWithOwnershipChange(result: Observable) { - result.subscribe(() => this.onUpdateSuccessOwnershipChange(), () => this.onSaveError()); + result.subscribe( + () => this.onUpdateSuccessOwnershipChange(), + () => this.onSaveError() + ) } protected onSaveSuccess() { - this.isSaving = false; - this.navigateToUsersList(); - this.alertService.broadcast('userServiceApp.user.created.string'); + this.isSaving = false + this.navigateToUsersList() + this.alertService.broadcast('userServiceApp.user.created.string') } protected onUpdateSuccess() { - this.isSaving = false; - this.navigateToUsersList(); - this.alertService.broadcast('userServiceApp.user.updated.string'); + this.isSaving = false + this.navigateToUsersList() + this.alertService.broadcast('userServiceApp.user.updated.string') } protected onSaveSuccessOwnershipChange() { - this.isSaving = false; + this.isSaving = false // TODO: confirm this actually works, previously it was set to SERVER_API_URL - window.location.href = '/'; - this.alertService.broadcast('userServiceApp.user.created.string'); + window.location.href = '/' + this.alertService.broadcast('userServiceApp.user.created.string') } protected onUpdateSuccessOwnershipChange() { - this.isSaving = false; - window.location.href = '/'; - this.alertService.broadcast('userServiceApp.user.updated.string'); + this.isSaving = false + window.location.href = '/' + this.alertService.broadcast('userServiceApp.user.updated.string') } protected onSaveError() { - this.isSaving = false; + this.isSaving = false } }