Skip to content

Commit

Permalink
feat: add action feedbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
Regzox committed Mar 1, 2024
1 parent f3c2cc8 commit 4589bc6
Show file tree
Hide file tree
Showing 10 changed files with 196 additions and 45 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, Input, OnChanges, OnDestroy, OnInit, SimpleChanges } from '@angular/core';
import { BehaviorSubject, Subscription } from 'rxjs';
import { BehaviorSubject, Observable, Subscription } from 'rxjs';

import { FormControl } from '@angular/forms';
import { EditObject } from '../../../object-editor/models/edit-object.model';
Expand Down Expand Up @@ -498,14 +498,14 @@ export class ArchiveUnitEditorComponent implements OnInit, OnChanges, OnDestroy
}

// TODO: Move to tab level
update(): void {
update(): Observable<{ operationId: String }> {
const jsonPatchDto = this.archiveUnitEditorService.toJsonPatchDto();

console.log({ jsonPatchDto, value: this.archiveUnitEditorService.getValue() });

if (jsonPatchDto.jsonPatch.length === 0) return;

this.archiveUnitService.asyncPartialUpdateArchiveUnitByCommands(jsonPatchDto).subscribe((value) => console.log(value));
return this.archiveUnitService.asyncPartialUpdateArchiveUnitByCommands(jsonPatchDto);
}

private initSedaVersionOptions(schema: Schema): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ export class EditObjectService {

(control as FormArray).push(editObject.control);
children.push(editObject);
control.markAsDirty();
};
actions.removeAt = (i: number) => {
(control as FormArray).removeAt(i);
children.splice(i, 1);
control.markAsDirty();
};
}
}
Expand Down
4 changes: 2 additions & 2 deletions ui/ui-frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,7 @@
</mat-tab>

<mat-tab label="{{ 'TAB.DESCRIPTION' | translate }}">
<vitamui-common-archive-unit-viewer
[ngStyle]="{ display: !updateStarted ? 'block' : 'none' }"
[data]="archiveUnit"
></vitamui-common-archive-unit-viewer>
<div [ngStyle]="{ display: updateStarted ? 'block' : 'none' }">
<vitamui-common-editor-banner class="editor-banner">
<button (click)="updateArchiveUnit()" class="btn primary" style="background-color: white; color: #9c31b5">
{{ 'SAVE' | translate }}
</button>
<button
(click)="updateStarted = false"
class="btn primary"
style="background-color: transparent; color: white; box-shadow: none; border: none"
>
{{ 'CANCEL' | translate }}
</button>
</vitamui-common-editor-banner>
<vitamui-common-archive-unit-editor [data]="archiveUnit"></vitamui-common-archive-unit-editor>
</div>
<app-archive-unit-description-tab [archiveUnit]="archiveUnit" [(editMode)]="updateStarted"></app-archive-unit-description-tab>
</mat-tab>

<mat-tab label="{{ 'ARCHIVE_SEARCH.ARCHIVE_UNIT_PREVIEW.TABS.RULES' | translate }}">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,3 @@
.margin-btn {
margin-right: 300px;
}

.editor-banner {
margin-left: -40px;
margin-right: -40px;
position: sticky;
z-index: 10;
top: -20px;
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@
* knowledge of the CeCILL-C license and that you accept its terms.
*/

import { AfterViewInit, Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges, ViewChild } from '@angular/core';
import { Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges } from '@angular/core';
import { MatTabChangeEvent } from '@angular/material/tabs';
import { ActivatedRoute } from '@angular/router';
import { TranslateService } from '@ngx-translate/core';
import { ArchiveUnitEditorComponent, Unit, unitToVitamuiIcon } from 'ui-frontend-common';
import { Unit, unitToVitamuiIcon } from 'ui-frontend-common';

@Component({
selector: 'app-archive-preview',
templateUrl: './archive-preview.component.html',
styleUrls: ['./archive-preview.component.scss'],
})
export class ArchivePreviewComponent implements OnInit, OnChanges, AfterViewInit {
export class ArchivePreviewComponent implements OnInit, OnChanges {
@Input() archiveUnit: Unit;
@Input() accessContract: string;
@Input() isPopup: boolean;
Expand All @@ -57,8 +57,6 @@ export class ArchivePreviewComponent implements OnInit, OnChanges, AfterViewInit
@Output() previewClose: EventEmitter<any> = new EventEmitter();
@Output() showExtendedLateralPanel: EventEmitter<any> = new EventEmitter();

@ViewChild(ArchiveUnitEditorComponent) archiveUnitEditor!: ArchiveUnitEditorComponent;

isPanelextended = false;
selectedIndex = 0;
tenantIdentifier: number;
Expand All @@ -78,10 +76,6 @@ export class ArchivePreviewComponent implements OnInit, OnChanges, AfterViewInit
this.hasAccessContractManagementPermissionsMessage = this.translateService.instant('UNIT_UPDATE.NO_PERMISSION');
}

ngAfterViewInit(): void {
this.archiveUnitEditor.editObject$.subscribe((editObject) => console.log('ArchivePreviewComponent', editObject));
}

emitClose() {
this.previewClose.emit();
this.isPanelextended = false;
Expand Down Expand Up @@ -137,8 +131,4 @@ export class ArchivePreviewComponent implements OnInit, OnChanges, AfterViewInit
getArchiveUnitIcon(unit: Unit) {
return unitToVitamuiIcon(unit);
}

updateArchiveUnit() {
this.archiveUnitEditor.update();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<vitamui-common-archive-unit-viewer
[ngStyle]="{ display: !editMode ? 'block' : 'none' }"
[data]="archiveUnit"
></vitamui-common-archive-unit-viewer>
<div [ngStyle]="{ display: editMode ? 'block' : 'none' }">
<vitamui-common-editor-banner class="editor-banner">
<button (click)="onSave()" [disabled]="editObject?.control?.pristine" class="btn primary save">
{{ 'COMMON.SAVE' | translate }}
</button>
<button (click)="onCancel()" class="btn primary cancel">
{{ 'COMMON.UNDO' | translate }}
</button>
</vitamui-common-editor-banner>
<vitamui-common-archive-unit-editor [data]="archiveUnit"></vitamui-common-archive-unit-editor>
</div>

<ng-template #updateDialog>
<mat-dialog-content>
<br />
<div class="text-title">
{{ 'UNIT_UPDATE.HINT' | translate }}
</div>

<div class="text large bold">
{{ 'UNIT_UPDATE.MESSAGE' | translate }}
</div>
</mat-dialog-content>
<br />
<mat-dialog-actions>
<button [matDialogClose]="true" class="btn primary btn-confirm-dialog margin-btn">{{ 'RULES.COMMON.CONFIRM' | translate }}</button>
<button matDialogClose class="btn link cancel cancel-popup">{{ 'RULES.COMMON.UNDO' | translate }}</button>
</mat-dialog-actions>
</ng-template>

<ng-template #cancelDialog>
<mat-dialog-content>
<br />
<div class="text-title">
{{ 'UNIT_UPDATE.CLOSE_WINDOW_HINT' | translate }}
</div>

<div class="text large bold">
{{ 'UNIT_UPDATE.CONFIRM_CLOSE' | translate }}
</div>
</mat-dialog-content>
<br />
<mat-dialog-actions>
<button [matDialogClose]="true" class="btn primary btn-confirm-dialog margin-btn">{{ 'COMMON.CLOSE' | translate }}</button>
<button matDialogClose class="btn link cancel cancel-popup">{{ 'COMMON.UNDO' | translate }}</button>
</mat-dialog-actions>
</ng-template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
button {
&.save {
background-color: white;
color: var(--vitamui-primary);
}

&.cancel {
background-color: transparent;
color: white;
box-shadow: none;
border: none;
}
}

.editor-banner {
margin-left: -40px;
margin-right: -40px;
position: sticky;
z-index: 10;
top: -20px;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import { AfterViewInit, Component, EventEmitter, Input, OnDestroy, OnInit, Output, TemplateRef, ViewChild } from '@angular/core';
import { MatDialog, MatDialogConfig } from '@angular/material/dialog';
import { MatSnackBar, MatSnackBarConfig } from '@angular/material/snack-bar';
import { ActivatedRoute } from '@angular/router';
import { TranslateService } from '@ngx-translate/core';
import { Subscription } from 'rxjs';
import { filter, switchMap } from 'rxjs/operators';
import { ArchiveUnit, ArchiveUnitEditorComponent, Logger, StartupService } from 'ui-frontend-common';
import { EditObject } from 'ui-frontend-common/app/modules/object-editor/models/edit-object.model';
import { VitamUISnackBarComponent } from '../../shared/vitamui-snack-bar';

@Component({
selector: 'app-archive-unit-description-tab',
templateUrl: './archive-unit-description-tab.component.html',
styleUrls: ['./archive-unit-description-tab.component.scss'],
})
export class ArchiveUnitDescriptionTabComponent implements OnInit, AfterViewInit, OnDestroy {
@Input() archiveUnit: ArchiveUnit;
@Input() editMode = false;
@Output() editModeChange = new EventEmitter<boolean>();

@ViewChild('updateDialog') updateDialog: TemplateRef<ArchiveUnitDescriptionTabComponent>;
@ViewChild('cancelDialog') cancelDialog: TemplateRef<ArchiveUnitDescriptionTabComponent>;
@ViewChild(ArchiveUnitEditorComponent) archiveUnitEditor!: ArchiveUnitEditorComponent;

editObject: EditObject;
tenantId: number;

private readonly subscriptions = new Subscription();
private readonly dialogConfig: MatDialogConfig = { panelClass: 'vitamui-dialog' };
private readonly snackBarConfig: MatSnackBarConfig = {
panelClass: 'vitamui-snack-bar',
data: {
type: 'WorkflowSuccessSnackBar',
},
duration: 100000,
};

constructor(
private logger: Logger,
private dialog: MatDialog,
private snackBar: MatSnackBar,
private startupService: StartupService,
private translateService: TranslateService,
private route: ActivatedRoute,
) {}

ngOnInit(): void {
this.subscriptions.add(
this.route.params.subscribe((params) => {
this.tenantId = params.tenantIdentifier;
}),
);
}

ngAfterViewInit(): void {
this.subscriptions.add(
this.archiveUnitEditor.editObject$.subscribe((editObject) => {
this.editObject = editObject;
}),
);
}

ngOnDestroy(): void {
this.subscriptions.unsubscribe();
}

onCancel(): void {
this.subscriptions.add(
this.dialog
.open(this.cancelDialog, this.dialogConfig)
.afterClosed()
.pipe(filter((result) => !!result))
.subscribe(() => {
this.archiveUnit = { ...this.archiveUnit };
this.editMode = false;
this.editModeChange.emit(this.editMode);
}),
);
}

onSave(): void {
this.subscriptions.add(
this.dialog
.open(this.updateDialog, this.dialogConfig)
.afterClosed()
.pipe(
filter((result) => !!result),
switchMap(() => this.archiveUnitEditor.update()),
)
.subscribe(({ operationId }) => {
if (!operationId) return this.logger.error(this, 'Operation id is mandatory to build logbook operation link');
if (!this.tenantId) return this.logger.error(this, 'Tenant id is mandatory to build logbook operation link');

const serviceUrl = `${this.startupService.getReferentialUrl()}/logbook-operation/tenant/${this.tenantId}?guid=${operationId}`;
const translationKey = 'RULES.EXECUTE_RULE_UPDATE_MESSAGE';
const message = this.translateService.instant(translationKey);

this.snackBar.openFromComponent(VitamUISnackBarComponent, {
...this.snackBarConfig,
data: {
...this.snackBarConfig.data,
message,
serviceUrl,
},
});
this.editObject.control.markAsPristine();
}),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import { ArchiveApiService } from '../core/api/archive-api.service';
import { ArchiveSharedDataService } from '../core/archive-shared-data.service';
import { ManagementRulesSharedDataService } from '../core/management-rules-shared-data.service';
import { ArchivePreviewComponent } from './archive-preview/archive-preview.component';
import { ArchiveUnitDescriptionTabComponent } from './archive-preview/archive-unit-description-tab/archive-unit-description-tab.component';
import { ArchiveUnitInformationTabComponent } from './archive-preview/archive-unit-information-tab/archive-unit-information-tab.component';
import { ArchiveUnitObjectsDetailsTabComponent } from './archive-preview/archive-unit-objects-details-tab/archive-unit-objects-details-tab.component';
import { ArchiveUnitRulesDetailsTabComponent } from './archive-preview/archive-unit-rules-details-tab/archive-unit-rules-details-tab.component';
Expand Down Expand Up @@ -194,6 +195,7 @@ import { ManagementRulesValidatorService } from './validators/management-rules-v
ReclassificationComponent,
DeleteUnitRulesComponent,
ArchiveUnitInformationTabComponent,
ArchiveUnitDescriptionTabComponent,
ArchiveUnitRulesDetailsTabComponent,
ArchiveUnitObjectsDetailsTabComponent,
ArchiveUnitRulesInformationsTabComponent,
Expand Down

0 comments on commit 4589bc6

Please sign in to comment.