diff --git a/src/app/components/auth-dialog/auth-dialog.component.ts b/src/app/components/auth-dialog/auth-dialog.component.ts deleted file mode 100644 index cb6b6128..00000000 --- a/src/app/components/auth-dialog/auth-dialog.component.ts +++ /dev/null @@ -1,111 +0,0 @@ -import { Component, computed, inject, OnInit, signal } from '@angular/core'; -import { - FormControl, - FormGroup, - FormsModule, - ReactiveFormsModule, - Validators, -} from '@angular/forms'; -import { MAT_DIALOG_DATA, MatDialog, MatDialogRef } from '@angular/material/dialog'; - -import { MatButtonModule } from '@angular/material/button'; -import { MatDividerModule } from '@angular/material/divider'; -import { MatFormFieldModule } from '@angular/material/form-field'; -import { MatIconModule } from '@angular/material/icon'; -import { MatInputModule } from '@angular/material/input'; -import { ExtenderPluginManager } from '@kompakkt/plugins/extender'; -import { - ForgotPasswordDialogComponent, - ForgotUsernameDialogComponent, - RegisterDialogComponent, -} from 'src/app/dialogs'; -import { AccountService } from 'src/app/services'; -import { TranslatePipe } from '../../pipes/translate.pipe'; -import { OutlinedInputComponent } from '../outlined-input/outlined-input.component'; -import { viewChild } from '@angular/core'; -import { ElementRef } from '@angular/core'; -import { ExtenderSlotDirective } from 'src/app/directives/extender-slot.directive'; - -export type AuthDialogData = { - concern?: string; - username?: string; -}; - -@Component({ - selector: 'app-auth-dialog', - templateUrl: './auth-dialog.component.html', - styleUrls: ['./auth-dialog.component.scss'], - imports: [ - FormsModule, - ReactiveFormsModule, - MatFormFieldModule, - MatInputModule, - MatDividerModule, - MatButtonModule, - TranslatePipe, - MatIconModule, - OutlinedInputComponent, - ExtenderSlotDirective, - ], -}) -export class AuthDialogComponent implements OnInit { - dialogRef = inject(MatDialogRef); - account = inject(AccountService); - #dialog = inject(MatDialog); - - public waitingForResponse = false; - public loginFailed = false; - - hasAuthMethods = signal(false); - - data = inject(MAT_DIALOG_DATA); - concern = computed(() => this.data?.concern ?? ''); - - public form = new FormGroup({ - username: new FormControl('', Validators.required), - password: new FormControl('', Validators.required), - }); - - public async trySubmit() { - const { username, password } = { - username: this.form.get('username')!.value as string, - password: this.form.get('password')!.value as string, - }; - - this.waitingForResponse = true; - this.dialogRef.disableClose = true; - - const userdata = await this.account.loginOrFetch({ username, password }); - - this.dialogRef.disableClose = false; - this.waitingForResponse = false; - - this.loginFailed = !userdata; - if (!userdata) return; - - this.dialogRef.close({ username, password }); - } - - public openForgotUsernameDialog() { - this.#dialog.open(ForgotUsernameDialogComponent); - } - - public openForgotPasswordDialog() { - this.#dialog.open(ForgotPasswordDialogComponent); - } - - public openRegistrationDialog() { - this.#dialog.open(RegisterDialogComponent); - } - - authMethodsSlotRef = viewChild.required>('authMethodsSlot'); - ngOnInit() { - if (this.data?.username) this.form.get('username')?.patchValue(this.data.username); - - this.hasAuthMethods.set(ExtenderPluginManager.hasComponentsForSlot('auth-method')); - console.log('AuthDialogComponent', { - hasAuthMethods: this.hasAuthMethods(), - elementRef: this.authMethodsSlotRef(), - }); - } -} diff --git a/src/app/components/index.ts b/src/app/components/index.ts index 20691fbc..962b1ddf 100644 --- a/src/app/components/index.ts +++ b/src/app/components/index.ts @@ -1,5 +1,5 @@ export { ActionbarComponent } from './actionbar/actionbar.component'; -export { AuthDialogComponent } from './auth-dialog/auth-dialog.component'; +export { AuthDialogComponent } from '../dialogs/auth-dialog/auth-dialog.component'; export { CompilationDetailComponent } from './compilation-detail/compilation-detail.component'; export { DetailEntityComponent } from './entity-detail/detail-entity/detail-entity.component'; export { EntityDetailComponent } from './entity-detail/entity-detail.component'; diff --git a/src/app/components/metadata/agents/agents.component.html b/src/app/components/metadata/agents/agents.component.html index 63de60a0..7e7a2068 100644 --- a/src/app/components/metadata/agents/agents.component.html +++ b/src/app/components/metadata/agents/agents.component.html @@ -242,7 +242,7 @@

{{ 'Assigned role(s)' | translate }}

- @for (role of availableRoles; track role) { + @for (role of availableRoles(); track role) { {{ role.value }} diff --git a/src/app/components/metadata/agents/agents.component.ts b/src/app/components/metadata/agents/agents.component.ts index 34f51484..4add9060 100644 --- a/src/app/components/metadata/agents/agents.component.ts +++ b/src/app/components/metadata/agents/agents.component.ts @@ -9,7 +9,6 @@ import { signal, SimpleChanges, viewChild, - ViewChild, } from '@angular/core'; import { FormControl, FormsModule, ReactiveFormsModule } from '@angular/forms'; @@ -26,7 +25,7 @@ import { MatIconModule } from '@angular/material/icon'; import { MatInputModule } from '@angular/material/input'; import { MatTabChangeEvent, MatTabGroup, MatTabsModule } from '@angular/material/tabs'; -import { Address, AnyEntity, ContactReference, Institution, Person, Tag } from 'src/app/metadata'; +import { Address, AnyEntity, ContactReference, Institution, Person } from 'src/app/metadata'; import { TranslatePipe } from '../../../pipes/translate.pipe'; import { @@ -44,7 +43,6 @@ import { AccountService, BackendService } from 'src/app/services'; import { MetadataCommunicationService } from 'src/app/services/metadata-communication.service'; import { AgentListComponent } from './agent-list/agent-list.component'; import { - Collection, IInstitution, IPerson, isAddress, @@ -284,10 +282,10 @@ export class AgentsComponent implements OnDestroy, OnChanges, OnInit { selectedTabIndex = 0; - availableRoles = [ + availableRoles = signal([ { type: 'RIGHTS_OWNER', value: 'Rightsowner', checked: false }, { type: 'CONTACT_PERSON', value: 'Contact person', checked: false }, - ]; + ]); newCustomRole = { value: '', checked: false }; @@ -323,7 +321,7 @@ export class AgentsComponent implements OnDestroy, OnChanges, OnInit { get atLeastOneRoleSelected(): boolean { return ( - this.availableRoles.some(role => role.checked) || + this.availableRoles().some(role => role.checked) || (this.newCustomRole.checked && this.newCustomRole.value != '') ); } @@ -333,7 +331,7 @@ export class AgentsComponent implements OnDestroy, OnChanges, OnInit { } get currentRoleSelection(): string[] { - const availableRoleTypes = this.availableRoles + const availableRoleTypes = this.availableRoles() .filter(role => role.checked) .map(role => role.type); @@ -422,11 +420,13 @@ export class AgentsComponent implements OnDestroy, OnChanges, OnInit { if (this.isUpdating()) { this.clearRoleSelection(); - for (const role of agent.roles[this.entityId()] ?? []) { - for (const roleOption of this.availableRoles) { - if (roleOption.type === role) roleOption.checked = true; - } - } + const rolesToActivate = agent.roles[this.entityId()] ?? []; + + this.availableRoles.update(roles => + roles.map(role => + rolesToActivate.includes(role.type) ? { ...role, checked: true } : role, + ), + ); } } @@ -511,13 +511,13 @@ export class AgentsComponent implements OnDestroy, OnChanges, OnInit { private addRoleIfNotExists(newRoleName: string) { const entity = this.entity(); const cleanedUpRoleName = entity.formatRoleLabel(newRoleName); - if (!cleanedUpRoleName || this.availableRoles.some(r => r.value === cleanedUpRoleName)) return; + if (!cleanedUpRoleName || this.availableRoles().some(r => r.value === cleanedUpRoleName)) + return; - this.availableRoles.push({ - type: cleanedUpRoleName, - value: cleanedUpRoleName, - checked: false, - }); + this.availableRoles.update(roles => [ + ...roles, + { type: cleanedUpRoleName, value: cleanedUpRoleName, checked: false }, + ]); } public updateAgent() { @@ -592,9 +592,7 @@ export class AgentsComponent implements OnDestroy, OnChanges, OnInit { } clearRoleSelection() { - this.availableRoles.forEach(role => { - role.checked = false; - }); + this.availableRoles.update(roles => roles.map(role => ({ ...role, checked: false }))); this.newCustomRole = { value: '', checked: false }; } @@ -615,7 +613,7 @@ export class AgentsComponent implements OnDestroy, OnChanges, OnInit { } ngOnInit(): void { - const fixedRoles = this.availableRoles.map(r => r.type); + const fixedRoles = this.availableRoles().map(r => r.type); const allAgents = [...this.entity().persons, ...this.entity().institutions]; for (const agent of allAgents) { diff --git a/src/app/components/metadata/optional/creation/creation.component.html b/src/app/components/metadata/optional/creation/creation.component.html index 9287b89f..66d46532 100644 --- a/src/app/components/metadata/optional/creation/creation.component.html +++ b/src/app/components/metadata/optional/creation/creation.component.html @@ -37,7 +37,7 @@