Commit 5d44d5be authored by Florent POITTEVIN's avatar Florent POITTEVIN
Browse files

feat: add dialog util everywhere

parent f08ba9fd
import {
ChangeDetectionStrategy,
Component,
Inject,
OnInit,
} from "@angular/core";
import {
......@@ -9,9 +10,12 @@ import {
FormGroup,
Validators,
} from "@angular/forms";
import {MatDialogRef} from "@angular/material/dialog";
import {
MAT_DIALOG_DATA,
MatDialogRef,
} from "@angular/material/dialog";
import {environment} from "@environments/environment";
import {SharedAbstractContainer} from "@shared/components/containers/shared-abstract/shared-abstract.container";
import {SharedAbstractDialog} from "@shared/components/dialogs/shared-abstract/shared-abstract.dialog";
import {BaseFormDefinition} from "@shared/models/base-form-definition.model";
import {
FormValidationHelper,
......@@ -25,7 +29,7 @@ import {
styleUrls: ["./privacy-policy-terms-of-use-approval.dialog.scss"],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class PrivacyPolicyTermsOfUseApprovalDialog extends SharedAbstractContainer implements OnInit {
export class PrivacyPolicyTermsOfUseApprovalDialog extends SharedAbstractDialog<PrivacyPolicyTermsOfUseApprovalDialogData, boolean> implements OnInit {
isLoading: boolean = false;
form: FormGroup;
formDefinition: FormComponentFormDefinition = new FormComponentFormDefinition();
......@@ -33,9 +37,10 @@ export class PrivacyPolicyTermsOfUseApprovalDialog extends SharedAbstractContain
readonly privacyPolicyLink: string = environment.privacyPolicyLink;
readonly termsOfUseLink: string = environment.termsOfUseLink;
constructor(private readonly _dialogRef: MatDialogRef<PrivacyPolicyTermsOfUseApprovalDialog>,
constructor(protected readonly _dialogRef: MatDialogRef<PrivacyPolicyTermsOfUseApprovalDialog>,
@Inject(MAT_DIALOG_DATA) public readonly data: PrivacyPolicyTermsOfUseApprovalDialogData,
private readonly _fb: FormBuilder) {
super();
super(_dialogRef, data);
}
ngOnInit(): void {
......@@ -46,16 +51,12 @@ export class PrivacyPolicyTermsOfUseApprovalDialog extends SharedAbstractContain
});
}
close(): void {
this._dialogRef.close();
}
onSubmit(): void {
if (this.form.invalid) {
return;
}
this.isLoading = true;
this._dialogRef.close(true);
this.submit(true);
}
getFormControl(key: string): AbstractControl {
......@@ -67,6 +68,9 @@ export class PrivacyPolicyTermsOfUseApprovalDialog extends SharedAbstractContain
}
}
export interface PrivacyPolicyTermsOfUseApprovalDialogData {
}
class FormComponentFormDefinition extends BaseFormDefinition {
@PropertyName() acceptPrivacyPolicy: string;
@PropertyName() acceptTermsOfUse: string;
......
......@@ -34,7 +34,7 @@ import {
styleUrls: ["./user.dialog.scss"],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class UserDialog extends SharedAbstractDialog<User, void> implements OnInit {
export class UserDialog extends SharedAbstractDialog<User> implements OnInit {
currentPersonObs: Observable<Person> = MemoizedUtil.current(this._store, AppPersonState);
isLoadingPersonObs: Observable<boolean> = MemoizedUtil.isLoading(this._store, AppPersonState);
......
......@@ -18,10 +18,10 @@ import {
Observable,
} from "rxjs";
import {
DialogUtil,
ObservableUtil,
SOLIDIFY_CONSTANTS,
TokenDialog,
TokenDialogData,
} from "solidify-frontend";
@Component({
......@@ -89,21 +89,18 @@ export class UserMenuPresentational extends SharedAbstractPresentational {
}
displayToken(): void {
this.dialog.open(TokenDialog, {
data: {
extraInformation: [
{
key: LabelTranslateEnum.role,
value: (token: Token) => token.authorities.join(SOLIDIFY_CONSTANTS.COMMA + " "),
},
],
} as TokenDialogData,
DialogUtil.open(this.dialog, TokenDialog, {
extraInformation: [
{
key: LabelTranslateEnum.role,
value: (token: Token) => token.authorities.join(SOLIDIFY_CONSTANTS.COMMA + " "),
},
],
});
}
profileInfo(): void {
this.dialog.open(UserDialog, {
data: this.user,
DialogUtil.open(this.dialog, UserDialog, this.user, {
width: "90%",
});
}
......
......@@ -33,7 +33,7 @@ import {
styleUrls: ["./admin-language-create-edit.dialog.scss"],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class AdminLanguageCreateEditDialog extends SharedAbstractCreateEditDialog<Language, AdminLanguageStateModel> {
export class AdminLanguageCreateEditDialog extends SharedAbstractCreateEditDialog<Language, AdminLanguageStateModel, CreateEditDialog<Language>> {
@OverrideProperty()
checkAvailableResourceNameSpace: ResourceNameSpace = sharedLanguageActionNameSpace;
......
......@@ -16,19 +16,17 @@ import {
Store,
} from "@ngxs/store";
import {LabelTranslateEnum} from "@shared/enums/label-translate.enum";
import {CreateEditDialog} from "@shared/models/detail-edit-dialog.model";
import {tap} from "rxjs/operators";
import {StateEnum} from "@shared/enums/state.enum";
import {
AbstractListRoutable,
DataTableFieldTypeEnum,
isNullOrUndefined,
DialogUtil,
isTrue,
isTruthyObject,
OrderEnum,
Override,
RouterExtensionService,
} from "solidify-frontend";
import {StateEnum} from "@shared/enums/state.enum";
@Component({
selector: "dlcm-admin-language-list-routable",
......@@ -99,27 +97,22 @@ export class AdminLanguageListRoutable extends AbstractListRoutable<Language, Ad
@Override()
create(element: ElementRef): void {
this.subscribe(this._dialog.open(AdminLanguageCreateEditDialog, {
this.subscribe(DialogUtil.open(this._dialog, AdminLanguageCreateEditDialog, {
current: undefined,
}, {
minWidth: "500px",
data: {
current: undefined,
} as CreateEditDialog<Language>,
}).afterClosed().pipe(
tap((isConfirmed: boolean | undefined) => {
if (isNullOrUndefined(isConfirmed)) {
if (isTruthyObject(element)) {
element.nativeElement.focus();
}
return;
}
if (isTrue(isConfirmed)) {
if (isTruthyObject(element)) {
element.nativeElement.focus();
}
this.getAll();
}, isConfirmed => {
if (isTrue(isConfirmed)) {
if (isTruthyObject(element)) {
element.nativeElement.focus();
}
}),
));
this.getAll();
}
}, () => {
if (isTruthyObject(element)) {
element.nativeElement.focus();
}
}));
}
@Override()
......
......@@ -30,13 +30,13 @@ import {SharedRoleState} from "@shared/stores/role/shared-role.state";
import {Observable} from "rxjs";
import {
AbstractDetailEditCommonRoutable,
DialogUtil,
MemoizedUtil,
OverrideProperty,
QueryParameters,
ResourceNameSpace,
StatusHistory,
StatusHistoryDialog,
StatusHistoryDialogData,
} from "solidify-frontend";
@Component({
......@@ -77,18 +77,17 @@ export class AdminNotificationDetailEditRoutable extends AbstractDetailEditCommo
}
showHistory(): void {
this._dialog.open(StatusHistoryDialog, {
DialogUtil.open(this._dialog, StatusHistoryDialog, {
parentId: null,
resourceResId: this._resId,
name: this._state,
statusHistory: this.historyObs,
isLoading: this.isLoadingHistoryObs,
queryParametersObs: this.queryParametersObs,
state: AdminNotificationStatusHistoryAction,
statusEnums: Enums.Notification.StatusEnumTranslate,
}, {
width: environment.modalWidth,
data: {
parentId: null,
resourceResId: this._resId,
name: this._state,
statusHistory: this.historyObs,
isLoading: this.isLoadingHistoryObs,
queryParametersObs: this.queryParametersObs,
state: AdminNotificationStatusHistoryAction,
statusEnums: Enums.Notification.StatusEnumTranslate,
} as StatusHistoryDialogData,
});
}
}
......@@ -21,6 +21,7 @@ import {
Store,
} from "@ngxs/store";
import {SharedAbstractContainer} from "@shared/components/containers/shared-abstract/shared-abstract.container";
import {SharedAbstractDialog} from "@shared/components/dialogs/shared-abstract/shared-abstract.dialog";
import {BaseFormDefinition} from "@shared/models/base-form-definition.model";
import {Observable} from "rxjs";
import {
......@@ -43,7 +44,7 @@ import {
styleUrls: ["./admin-organizational-unit-additional-fields-rename.dialog.scss"],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class AdminOrganizationalUnitAdditionalFieldsRenameDialog extends SharedAbstractContainer implements OnInit {
export class AdminOrganizationalUnitAdditionalFieldsRenameDialog extends SharedAbstractDialog<AdminOrganizationalUnitAdditionalFieldsRenameDialogData> implements OnInit {
isLoadingObs: Observable<boolean> = MemoizedUtil.isLoading(this._store, AdminOrganizationalUnitAdditionalFieldsFormState);
form: FormGroup;
......@@ -51,10 +52,10 @@ export class AdminOrganizationalUnitAdditionalFieldsRenameDialog extends SharedA
constructor(private readonly _store: Store,
private readonly _actions$: Actions,
private readonly _dialogRef: MatDialogRef<AdminOrganizationalUnitAdditionalFieldsRenameDialog>,
@Inject(MAT_DIALOG_DATA) public data: AdminOrganizationalUnitAdditionalFieldsRenameDialogData,
protected readonly _dialogRef: MatDialogRef<AdminOrganizationalUnitAdditionalFieldsRenameDialog>,
@Inject(MAT_DIALOG_DATA) protected _data: AdminOrganizationalUnitAdditionalFieldsRenameDialogData,
private readonly _fb: FormBuilder) {
super();
super(_dialogRef, _data);
}
ngOnInit(): void {
......
import {
AdminOrganizationalUnitAdditionalFieldsDetailCreateEditDialogData,
AdminOrganizationalUnitAdditionalFieldsDetailCreateUpdateDialog,
} from "@admin/organizational-unit/components/dialogs/admin-organizational-unit-additional-fields-detail-create-update/admin-organizational-unit-additional-fields-detail-create-update.dialog";
import {
AdminOrganizationalUnitAdditionalFieldsRenameDialog,
AdminOrganizationalUnitAdditionalFieldsRenameDialogData,
} from "@admin/organizational-unit/components/dialogs/admin-organizational-unit-additional-fields-rename/admin-organizational-unit-additional-fields-rename.dialog";
import {AdminOrganizationalUnitAdditionalFieldsDetailCreateUpdateDialog} from "@admin/organizational-unit/components/dialogs/admin-organizational-unit-additional-fields-detail-create-update/admin-organizational-unit-additional-fields-detail-create-update.dialog";
import {AdminOrganizationalUnitAdditionalFieldsRenameDialog} from "@admin/organizational-unit/components/dialogs/admin-organizational-unit-additional-fields-rename/admin-organizational-unit-additional-fields-rename.dialog";
import {AdminOrganizationalUnitAdditionalFieldsFormAction} from "@admin/organizational-unit/stores/additional-fields-form/admin-organizational-unit-additional-fields-form.action";
import {AdminOrganizationalUnitAdditionalFieldsFormState} from "@admin/organizational-unit/stores/additional-fields-form/admin-organizational-unit-additional-fields-form.state";
import {
......@@ -21,14 +15,13 @@ import {Store} from "@ngxs/store";
import {IconNameEnum} from "@shared/enums/icon-name.enum";
import {LabelTranslateEnum} from "@shared/enums/label-translate.enum";
import {AppRoutesEnum} from "@shared/enums/routes.enum";
import {
DataTableActions,
DataTableFieldTypeEnum,
} from "solidify-frontend";
import {DataTableColumns} from "solidify-frontend";
import {Observable} from "rxjs";
import {
CompositionState,
DataTableActions,
DataTableColumns,
DataTableFieldTypeEnum,
DialogUtil,
isNullOrUndefined,
MARK_AS_TRANSLATABLE,
MemoizedUtil,
......@@ -108,31 +101,25 @@ export class AdminOrganizationalUnitAdditionalFieldsListRoutable {
}
select(additionalFieldsForm: AdditionalFieldsForm): void {
this._dialog.open(AdminOrganizationalUnitAdditionalFieldsDetailCreateUpdateDialog, {
data: {
parentResId: this._orgUnitResId,
additionalFieldsForm: additionalFieldsForm,
mode: "detail",
} as AdminOrganizationalUnitAdditionalFieldsDetailCreateEditDialogData,
DialogUtil.open(this._dialog, AdminOrganizationalUnitAdditionalFieldsDetailCreateUpdateDialog, {
parentResId: this._orgUnitResId,
additionalFieldsForm: additionalFieldsForm,
mode: "detail",
});
}
private renameVersion(_resId: string, additionalFieldsForm: AdditionalFieldsForm): void {
this._dialog.open(AdminOrganizationalUnitAdditionalFieldsRenameDialog, {
data: {
parentResId: this._orgUnitResId,
additionalFieldsForm: additionalFieldsForm,
} as AdminOrganizationalUnitAdditionalFieldsRenameDialogData,
DialogUtil.open(this._dialog, AdminOrganizationalUnitAdditionalFieldsRenameDialog, {
parentResId: this._orgUnitResId,
additionalFieldsForm: additionalFieldsForm,
});
}
private createNewVersionFromExistingOne(_resId: string, additionalFieldsForm: AdditionalFieldsForm): void {
this._dialog.open(AdminOrganizationalUnitAdditionalFieldsDetailCreateUpdateDialog, {
data: {
parentResId: this._orgUnitResId,
additionalFieldsForm: additionalFieldsForm,
mode: "update",
} as AdminOrganizationalUnitAdditionalFieldsDetailCreateEditDialogData,
DialogUtil.open(this._dialog, AdminOrganizationalUnitAdditionalFieldsDetailCreateUpdateDialog, {
parentResId: this._orgUnitResId,
additionalFieldsForm: additionalFieldsForm,
mode: "update",
});
}
}
import {
AdminOrganizationalUnitAdditionalFieldsDetailCreateEditDialogData,
AdminOrganizationalUnitAdditionalFieldsDetailCreateUpdateDialog,
} from "@admin/organizational-unit/components/dialogs/admin-organizational-unit-additional-fields-detail-create-update/admin-organizational-unit-additional-fields-detail-create-update.dialog";
import {AdminOrganizationalUnitAdditionalFieldsDetailCreateUpdateDialog} from "@admin/organizational-unit/components/dialogs/admin-organizational-unit-additional-fields-detail-create-update/admin-organizational-unit-additional-fields-detail-create-update.dialog";
import {AdminOrganizationalUnitService} from "@admin/organizational-unit/services/admin-organizational-unit.service";
import {adminOrganizationalUnitActionNameSpace} from "@admin/organizational-unit/stores/admin-organizational-unit.action";
import {
......@@ -43,6 +40,7 @@ import {SharedSubmissionPolicyState} from "@shared/stores/submission-policy/shar
import {Observable} from "rxjs";
import {
AbstractDetailEditCommonRoutable,
DialogUtil,
ExtraButtonToolbar,
MARK_AS_TRANSLATABLE,
MemoizedUtil,
......@@ -137,12 +135,10 @@ export class AdminOrganizationalUnitDetailEditRoutable extends AbstractDetailEdi
}
private createAdditionalFieldsFromScratch(_resId: string): void {
this._dialog.open(AdminOrganizationalUnitAdditionalFieldsDetailCreateUpdateDialog, {
data: {
parentResId: this._resId,
additionalFieldsForm: undefined,
mode: "create",
} as AdminOrganizationalUnitAdditionalFieldsDetailCreateEditDialogData,
DialogUtil.open(this._dialog, AdminOrganizationalUnitAdditionalFieldsDetailCreateUpdateDialog, {
parentResId: this._resId,
additionalFieldsForm: undefined,
mode: "create",
});
}
......
......@@ -39,7 +39,7 @@ import {
styleUrls: ["./admin-research-domain-create-edit.dialog.scss"],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class AdminResearchDomainCreateEditDialog extends SharedAbstractCreateEditDialog<ResearchDomain, AdminResearchDomainStateModel> {
export class AdminResearchDomainCreateEditDialog extends SharedAbstractCreateEditDialog<ResearchDomain, AdminResearchDomainStateModel, CreateEditDialog<ResearchDomain>> {
languagesObs: Observable<Language[]> = MemoizedUtil.list(this._store, SharedLanguageState);
@OverrideProperty()
......
......@@ -23,19 +23,18 @@ import {DataTableComponentEnum} from "@shared/enums/data-table-component.enum";
import {LabelTranslateEnum} from "@shared/enums/label-translate.enum";
import {StateEnum} from "@shared/enums/state.enum";
import {DataTableComponentHelper} from "@shared/helpers/data-table-component.helper";
import {CreateEditDialog} from "@shared/models/detail-edit-dialog.model";
import {SharedLanguageAction} from "@shared/stores/language/shared-language.action";
import {SharedLanguageState} from "@shared/stores/language/shared-language.state";
import {Observable} from "rxjs";
import {
filter,
take,
tap,
} from "rxjs/operators";
import {
AbstractListRoutable,
DataTableColumns,
DataTableFieldTypeEnum,
DialogUtil,
isNullOrUndefined,
isTrue,
isTruthyObject,
......@@ -73,8 +72,8 @@ export class AdminResearchDomainListRoutable extends AbstractListRoutable<Resear
super.ngOnInit();
this._store.dispatch(new SharedLanguageAction.GetAll());
this.subscribe(this.languagesObs.pipe(
filter(languages => !isNullOrUndefined(languages)),
take(1),
filter(languages => !isNullOrUndefined(languages)),
take(1),
),
languages => this.addLanguagesColumns(languages));
}
......@@ -148,46 +147,40 @@ export class AdminResearchDomainListRoutable extends AbstractListRoutable<Resear
@Override()
create(element: ElementRef): void {
this.subscribe(this._dialog.open(AdminResearchDomainCreateEditDialog, {
minWidth: "500px",
data: {
this.subscribe(DialogUtil.open(this._dialog, AdminResearchDomainCreateEditDialog, {
current: undefined,
} as CreateEditDialog<ResearchDomain>,
}).afterClosed().pipe(
tap((isConfirmed: boolean | undefined) => {
if (isNullOrUndefined(isConfirmed)) {
if (isTruthyObject(element)) {
element.nativeElement.focus();
}
return;
}
},
{
minWidth: "500px",
},
isConfirmed => {
if (isTrue(isConfirmed)) {
if (isTruthyObject(element)) {
element.nativeElement.focus();
}
this.getAll();
}
}),
));
},
() => {
if (isTruthyObject(element)) {
element.nativeElement.focus();
}
}));
}
@Override()
goToEdit(model: ResearchDomain): void {
this.subscribe(this._dialog.open(AdminResearchDomainCreateEditDialog, {
minWidth: "500px",
data: {
this.subscribe(DialogUtil.open(this._dialog, AdminResearchDomainCreateEditDialog, {
current: model,
} as CreateEditDialog<ResearchDomain>,
}).afterClosed().pipe(
tap((isConfirmed: boolean | undefined) => {
if (isNullOrUndefined(isConfirmed)) {
return;
}
},
{
minWidth: "500px",
},
isConfirmed => {
if (isTrue(isConfirmed)) {
this.getAll();
}
}),
));
}));
}
@Override()
......
......@@ -11,6 +11,7 @@ import {
import {Enums} from "@enums";
import {Store} from "@ngxs/store";
import {SharedAbstractContainer} from "@shared/components/containers/shared-abstract/shared-abstract.container";
import {SharedAbstractDialog} from "@shared/components/dialogs/shared-abstract/shared-abstract.dialog";
@Component({
selector: "dlcm-admin-user-edit-role-current-user-dialog",
......@@ -18,23 +19,19 @@ import {SharedAbstractContainer} from "@shared/components/containers/shared-abst
styleUrls: ["./admin-user-edit-role-current-user.dialog.scss"],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class AdminUserEditRoleCurrentUserDialog extends SharedAbstractContainer implements OnInit {
export class AdminUserEditRoleCurrentUserDialog extends SharedAbstractDialog<AdminUserEditRoleCurrentUserDialogData, boolean> {
get userApplicationRoleEnum(): typeof Enums.UserApplicationRole.UserApplicationRoleEnum {
return Enums.UserApplicationRole.UserApplicationRoleEnum;
}
constructor(protected store: Store,
protected dialogRef: MatDialogRef<AdminUserEditRoleCurrentUserDialog>,
@Inject(MAT_DIALOG_DATA) public data: AdminUserEditRoleCurrentUserDialogData) {
super();
}
ngOnInit(): void {
super.ngOnInit();
constructor(protected readonly store: Store,
protected readonly _dialogRef: MatDialogRef<AdminUserEditRoleCurrentUserDialog>,
@Inject(MAT_DIALOG_DATA) public readonly data: AdminUserEditRoleCurrentUserDialogData) {
super(_dialogRef, data);
}
confirm(): void {
this.dialogRef.close(true);
this.submit(true);
}
}
......
......@@ -45,6 +45,7 @@ import {
} from "rxjs/operators";
import {
AbstractDetailEditCommonRoutable,
DialogUtil,
isNullOrUndefined,
isTrue,
MemoizedUtil,
......@@ -111,18 +112,12 @@ export class AdminUserDetailEditRoutable extends AbstractDetailEditCommonRoutabl
}
private openModalConfirmEditRole(data: AdminUserEditRoleCurrentUserDialogData, model: ModelFormControlEvent<User>): void {
this.subscribe(this._dialog.open(AdminUserEditRoleCurrentUserDialog