diff --git a/ui/src/app/metadata/configuration/action/restore.action.ts b/ui/src/app/metadata/configuration/action/restore.action.ts index b05594fab..290367054 100644 --- a/ui/src/app/metadata/configuration/action/restore.action.ts +++ b/ui/src/app/metadata/configuration/action/restore.action.ts @@ -7,8 +7,8 @@ export enum RestoreActionTypes { SELECT_VERSION_REQUEST = '[Restore Version] Select Version Request', RESTORE_VERSION_REQUEST = '[Restore Version] Restore Version Request', - RESTORE_VERSION_SUCCESS = '[Restore Version] Restore Version Request', - RESTORE_VERSION_ERROR = '[Restore Version] Restore Version Request', + RESTORE_VERSION_SUCCESS = '[Restore Version] Restore Version Success', + RESTORE_VERSION_ERROR = '[Restore Version] Restore Version Error', CLEAR_VERSION = '[Restore Version] Clear Versions' } @@ -26,7 +26,7 @@ export class RestoreVersionRequest implements Action { export class RestoreVersionSuccess implements Action { readonly type = RestoreActionTypes.RESTORE_VERSION_SUCCESS; - constructor(public payload: Metadata) { } + constructor(public payload: { id: string, type: string, model: Metadata }) { } } export class RestoreVersionError implements Action { diff --git a/ui/src/app/metadata/configuration/container/restore.component.ts b/ui/src/app/metadata/configuration/container/restore.component.ts index 83d3cb98f..feffeb71b 100644 --- a/ui/src/app/metadata/configuration/container/restore.component.ts +++ b/ui/src/app/metadata/configuration/container/restore.component.ts @@ -29,7 +29,7 @@ export class RestoreComponent implements OnDestroy { this.restore$.pipe( withLatestFrom( this.store.select(fromConfiguration.getSelectedVersionId), - this.store.select(fromConfiguration.getConfigurationModelType), + this.store.select(fromConfiguration.getConfigurationModelKind), this.store.select(fromConfiguration.getConfigurationModelId) ), map(([restore, version, type, id]) => new RestoreVersionRequest({ id, type, version })) diff --git a/ui/src/app/metadata/configuration/effect/restore.effect.ts b/ui/src/app/metadata/configuration/effect/restore.effect.ts index 3a7f10002..d91682c61 100644 --- a/ui/src/app/metadata/configuration/effect/restore.effect.ts +++ b/ui/src/app/metadata/configuration/effect/restore.effect.ts @@ -7,10 +7,16 @@ import { SelectVersionRestoreRequest, SelectVersionRestoreError, SelectVersionRestoreSuccess, - RestoreVersionRequest + RestoreVersionRequest, + RestoreVersionSuccess, + RestoreVersionError } from '../action/restore.action'; import { MetadataHistoryService } from '../service/history.service'; import { of } from 'rxjs'; +import { Router, ActivatedRoute } from '@angular/router'; + +import { AddNotification } from '../../../notification/action/notification.action'; +import { Notification, NotificationType } from '../../../notification/model/notification'; @Injectable() @@ -32,16 +38,40 @@ export class RestoreVersionEffects { restoreVersion$ = this.actions$.pipe( ofType(RestoreActionTypes.RESTORE_VERSION_REQUEST), map(action => action.payload), - switchMap(({ id, type, version }) => { - return this.historyService.getVersion(id, version, type).pipe( - map(v => new SelectVersionRestoreSuccess(v)), - catchError(err => of(new SelectVersionRestoreError(err))) - ); - }) + switchMap(({ id, type, version }) => + this.historyService.restoreVersion(id, type, version).pipe( + map(v => new RestoreVersionSuccess({ id, type, model: v })), + catchError(err => of(new RestoreVersionError(err))) + ) + ) + ); + + @Effect() + restoreVersionSuccessNotification$ = this.actions$.pipe( + ofType(RestoreActionTypes.RESTORE_VERSION_SUCCESS), + map(action => action.payload), + map((data) => + new AddNotification(new Notification( + NotificationType.Success, + `Version Restored!`, + 5000 + )) + ) + ); + + @Effect({dispatch: false}) + restoreVersionSuccessRedirect$ = this.actions$.pipe( + ofType(RestoreActionTypes.RESTORE_VERSION_SUCCESS), + map(action => action.payload), + switchMap((data) => + this.router.navigate(['/metadata', data.type, data.id, 'configuration', 'options']) + ) ); constructor( private historyService: MetadataHistoryService, - private actions$: Actions + private actions$: Actions, + private router: Router, + private route: ActivatedRoute ) { } } diff --git a/ui/src/app/metadata/configuration/service/history.service.ts b/ui/src/app/metadata/configuration/service/history.service.ts index 700e88e6a..02529cde5 100644 --- a/ui/src/app/metadata/configuration/service/history.service.ts +++ b/ui/src/app/metadata/configuration/service/history.service.ts @@ -5,8 +5,9 @@ import { MetadataHistory } from '../model/history'; import { PATHS } from '../../configuration/configuration.values'; import { MetadataVersion } from '../model/version'; -import { map } from 'rxjs/operators'; +import { map, catchError, switchMap } from 'rxjs/operators'; import { Metadata } from '../../domain/domain.type'; +import { withLatestFrom } from 'rxjs-compat/operator/withLatestFrom'; @Injectable() export class MetadataHistoryService { @@ -39,4 +40,16 @@ export class MetadataHistoryService { `/${this.base}/${PATHS[type]}/${resourceId}`; return this.http.get(api); } + + updateVersion(resourceId: string, type: string, model: Metadata): Observable { + return this.http.put(`/${this.base}/${PATHS[type]}/${resourceId}`, model); + } + + restoreVersion(resourceId: string, type: string, versionId: string): Observable { + return this.getVersions(resourceId, [null, versionId], type).pipe( + switchMap(([current, toRestore]) => + this.updateVersion(resourceId, type, { ...toRestore, version: current.version }) + ) + ); + } } diff --git a/ui/src/app/metadata/domain/model/wizards/metadata-source-base.ts b/ui/src/app/metadata/domain/model/wizards/metadata-source-base.ts index aab844d5e..02b1a2625 100644 --- a/ui/src/app/metadata/domain/model/wizards/metadata-source-base.ts +++ b/ui/src/app/metadata/domain/model/wizards/metadata-source-base.ts @@ -86,6 +86,7 @@ export class MetadataSourceBase implements Wizard { const checkOrg = (value, property, form) => { const org = property.parent; const orgValue = org.value || {}; + console.log(orgValue); const err = Object.keys(orgValue) && !value ? { code: 'ORG_INCOMPLETE', path: `#${property.path}`,