|
@ -1,5 +1,6 @@ |
|
|
import { CreateAccessDto } from '@ghostfolio/api/app/access/create-access.dto'; |
|
|
import { CreateAccessDto } from '@ghostfolio/api/app/access/create-access.dto'; |
|
|
import { DataService } from '@ghostfolio/client/services/data.service'; |
|
|
import { DataService } from '@ghostfolio/client/services/data.service'; |
|
|
|
|
|
import { validateObjectForForm } from '@ghostfolio/client/util/form.util'; |
|
|
|
|
|
|
|
|
import { |
|
|
import { |
|
|
ChangeDetectionStrategy, |
|
|
ChangeDetectionStrategy, |
|
@ -40,22 +41,22 @@ export class CreateOrUpdateAccessDialog implements OnDestroy { |
|
|
alias: [this.data.access.alias], |
|
|
alias: [this.data.access.alias], |
|
|
permissions: [this.data.access.permissions[0], Validators.required], |
|
|
permissions: [this.data.access.permissions[0], Validators.required], |
|
|
type: [this.data.access.type, Validators.required], |
|
|
type: [this.data.access.type, Validators.required], |
|
|
userId: [this.data.access.grantee, Validators.required] |
|
|
granteeUserId: [this.data.access.grantee, Validators.required] |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
this.accessForm.get('type').valueChanges.subscribe((accessType) => { |
|
|
this.accessForm.get('type').valueChanges.subscribe((accessType) => { |
|
|
|
|
|
const granteeUserIdControl = this.accessForm.get('granteeUserId'); |
|
|
const permissionsControl = this.accessForm.get('permissions'); |
|
|
const permissionsControl = this.accessForm.get('permissions'); |
|
|
const userIdControl = this.accessForm.get('userId'); |
|
|
|
|
|
|
|
|
|
|
|
if (accessType === 'PRIVATE') { |
|
|
if (accessType === 'PRIVATE') { |
|
|
|
|
|
granteeUserIdControl.setValidators(Validators.required); |
|
|
permissionsControl.setValidators(Validators.required); |
|
|
permissionsControl.setValidators(Validators.required); |
|
|
userIdControl.setValidators(Validators.required); |
|
|
|
|
|
} else { |
|
|
} else { |
|
|
userIdControl.clearValidators(); |
|
|
granteeUserIdControl.clearValidators(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
granteeUserIdControl.updateValueAndValidity(); |
|
|
permissionsControl.updateValueAndValidity(); |
|
|
permissionsControl.updateValueAndValidity(); |
|
|
userIdControl.updateValueAndValidity(); |
|
|
|
|
|
|
|
|
|
|
|
this.changeDetectorRef.markForCheck(); |
|
|
this.changeDetectorRef.markForCheck(); |
|
|
}); |
|
|
}); |
|
@ -65,13 +66,20 @@ export class CreateOrUpdateAccessDialog implements OnDestroy { |
|
|
this.dialogRef.close(); |
|
|
this.dialogRef.close(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public onSubmit() { |
|
|
public async onSubmit() { |
|
|
const access: CreateAccessDto = { |
|
|
const access: CreateAccessDto = { |
|
|
alias: this.accessForm.get('alias').value, |
|
|
alias: this.accessForm.get('alias').value, |
|
|
granteeUserId: this.accessForm.get('userId').value, |
|
|
granteeUserId: this.accessForm.get('granteeUserId').value, |
|
|
permissions: [this.accessForm.get('permissions').value] |
|
|
permissions: [this.accessForm.get('permissions').value] |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
await validateObjectForForm({ |
|
|
|
|
|
classDto: CreateAccessDto, |
|
|
|
|
|
form: this.accessForm, |
|
|
|
|
|
object: access |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
this.dataService |
|
|
this.dataService |
|
|
.postAccess(access) |
|
|
.postAccess(access) |
|
|
.pipe( |
|
|
.pipe( |
|
@ -85,8 +93,11 @@ export class CreateOrUpdateAccessDialog implements OnDestroy { |
|
|
takeUntil(this.unsubscribeSubject) |
|
|
takeUntil(this.unsubscribeSubject) |
|
|
) |
|
|
) |
|
|
.subscribe(() => { |
|
|
.subscribe(() => { |
|
|
this.dialogRef.close({ access }); |
|
|
this.dialogRef.close(access); |
|
|
}); |
|
|
}); |
|
|
|
|
|
} catch (error) { |
|
|
|
|
|
console.error(error); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public ngOnDestroy() { |
|
|
public ngOnDestroy() { |
|
|