Skip to content

Commit

Permalink
SHIBUI-1361 Fixed issue with displaying proper version
Browse files Browse the repository at this point in the history
  • Loading branch information
rmathis committed Aug 9, 2019
1 parent 3d66d91 commit 52089a2
Show file tree
Hide file tree
Showing 20 changed files with 293 additions and 62 deletions.
11 changes: 9 additions & 2 deletions ui/src/app/metadata/configuration/action/configuration.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ export enum ConfigurationActionTypes {
LOAD_XML_SUCCESS = '[Metadata Configuration] Load XML Success',
LOAD_XML_ERROR = '[Metadata Configuration] Load XML Error',

SET_METADATA = '[Metadata Configuration] Set Metadata Model',
SET_METADATA = '[Metadata Configuration] Set Metadata Attributes',
SET_DEFINITION = '[Metadata Configuration] Set Metadata Definition',
SET_SCHEMA = '[Metadata Configuration] Set Metadata Schema',
SET_XML = '[Metadata Configuration] Set Metadata Xml',
SET_METADATA_MODEL = '[Metadata Configuration] Set Metadata Model',

DOWNLOAD_XML = '[Metadata Configuration] Download Metadata Xml',

Expand Down Expand Up @@ -61,7 +62,13 @@ export class LoadXmlError implements Action {
export class SetMetadata implements Action {
readonly type = ConfigurationActionTypes.SET_METADATA;

constructor(public payload: { id: string, type: string }) { }
constructor(public payload: { id: string, type: string, version?: string }) { }
}

export class SetMetadataModel implements Action {
readonly type = ConfigurationActionTypes.SET_METADATA_MODEL;

constructor(public payload: Metadata) { }
}

export class SetDefinition implements Action {
Expand Down
36 changes: 36 additions & 0 deletions ui/src/app/metadata/configuration/action/restore.action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Action } from '@ngrx/store';
import { Metadata } from '../../domain/domain.type';

export enum RestoreActionTypes {
SELECT_VERSION_SUCCESS = '[Restore Version] Select Version Success',
SELECT_VERSION_ERROR = '[Restore Version] Select Version Error',
SELECT_VERSION_REQUEST = '[Restore Version] Select Version Request',
CLEAR_VERSION = '[Restore Version] Clear Versions'
}

export class SelectVersionRestoreRequest implements Action {
readonly type = RestoreActionTypes.SELECT_VERSION_REQUEST;

constructor(public payload: { type: string, id: string, version: string }) { }
}

export class SelectVersionRestoreSuccess implements Action {
readonly type = RestoreActionTypes.SELECT_VERSION_SUCCESS;

constructor(public payload: Metadata) { }
}
export class SelectVersionRestoreError implements Action {
readonly type = RestoreActionTypes.SELECT_VERSION_ERROR;

constructor(public payload: any) { }
}

export class ClearVersionRestore implements Action {
readonly type = RestoreActionTypes.CLEAR_VERSION;
}

export type RestoreActionsUnion =
| SelectVersionRestoreRequest
| SelectVersionRestoreError
| SelectVersionRestoreSuccess
| ClearVersionRestore;
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<th scope="col">
<span class="sr-only" translate="label.select-version">Select Version</span>
</th>
<th scope="col" translate="label.version">Version</th>
<th scope="col" translate="label.save-date">Save Date</th>
<th scope="col" translate="label.changed-by">Changed By</th>
<th scope="col" translate="label.actions">Actions</th>
Expand All @@ -21,12 +20,19 @@
</label>
</div>
</td>
<td *ngIf="i === 0"><translate-i18n key="label.current">Current</translate-i18n> (v{{ history.length - i }})</td>
<td *ngIf="i > 0">v{{ history.length - (i) }}</td>
<td>{{ version.date | date:DATE_FORMAT }}</td>
<td>
<a [routerLink]="['../', 'options']" [queryParams]="{'version': version.id}">
<ng-container>
{{ version.date | date:DATE_FORMAT }}&nbsp;
<ng-container *ngIf="i === 0">
(<translate-i18n key="label.current">Current</translate-i18n>)
</ng-container>
</ng-container>
</a>
</td>
<td>{{ version.creator }}</td>
<td>
<button class="btn btn-link" (click)="restore.emit(version)">
<button class="btn btn-text btn-link" (click)="restore.emit(version)" *ngIf="i > 0">
<i class="fa fa-undo"></i>&nbsp;
<translate-i18n key="label.restore">Restore</translate-i18n>
</button>
Expand Down
8 changes: 6 additions & 2 deletions ui/src/app/metadata/configuration/configuration.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import { FilterConfigurationListComponent } from './component/filter-configurati
import { FilterConfigurationListItemComponent } from './component/filter-configuration-list-item.component';
import { SharedModule } from '../../shared/shared.module';
import { FilterTargetPropertyComponent } from './component/filter-target-property.component';
import { RestoreComponent } from './container/restore.component';
import { RestoreVersionEffects } from './effect/restore.effect';

@NgModule({
declarations: [
Expand All @@ -47,7 +49,8 @@ import { FilterTargetPropertyComponent } from './component/filter-target-propert
MetadataComparisonComponent,
FilterConfigurationListComponent,
FilterConfigurationListItemComponent,
FilterTargetPropertyComponent
FilterTargetPropertyComponent,
RestoreComponent
],
entryComponents: [],
imports: [
Expand Down Expand Up @@ -82,7 +85,8 @@ export class MetadataConfigurationModule {
[
MetadataConfigurationEffects,
MetadataHistoryEffects,
CompareVersionEffects
CompareVersionEffects,
RestoreVersionEffects
])
],
providers: []
Expand Down
5 changes: 5 additions & 0 deletions ui/src/app/metadata/configuration/configuration.routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { MetadataOptionsComponent } from './container/metadata-options.component
import { MetadataXmlComponent } from './container/metadata-xml.component';
import { MetadataHistoryComponent } from './container/metadata-history.component';
import { MetadataComparisonComponent } from './container/metadata-comparison.component';
import { RestoreComponent } from './container/restore.component';

export const ConfigurationRoutes: Routes = [
{
Expand All @@ -29,6 +30,10 @@ export const ConfigurationRoutes: Routes = [
{
path: 'compare',
component: MetadataComparisonComponent
},
{
path: 'restore',
component: RestoreComponent
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ import { Component, ChangeDetectionStrategy, OnDestroy, HostListener } from '@an
import { ActivatedRoute, Router, Scroll, Event } from '@angular/router';
import { takeUntil, map, withLatestFrom, filter, timeout, delay } from 'rxjs/operators';
import { Store } from '@ngrx/store';
import { Observable, Subject, interval } from 'rxjs';
import { Observable, Subject, interval, combineLatest } from 'rxjs';

import * as fromConfiguration from '../reducer';

import { ClearConfiguration, SetMetadata } from '../action/configuration.action';
import { LoadHistoryRequest, ClearHistory, SelectVersion } from '../action/history.action';
import * as fromReducer from '../reducer';
import { ViewportScroller } from '@angular/common';

@Component({
selector: 'configuration-page',
Expand All @@ -27,9 +26,17 @@ export class ConfigurationComponent implements OnDestroy {
private store: Store<fromConfiguration.ConfigurationState>,
private routerState: ActivatedRoute
) {
this.routerState.params.pipe(

combineLatest(
this.routerState.params,
this.routerState.queryParams
).pipe(
takeUntil(this.ngUnsubscribe),
map(params => new SetMetadata({id: params.id, type: params.type}))
map(([{ id, type }, { version }]) => new SetMetadata({
id,
type,
version
}))
).subscribe(store);

this.routerState.params.pipe(
Expand All @@ -38,20 +45,14 @@ export class ConfigurationComponent implements OnDestroy {
).subscribe(store);

this.store.select(fromReducer.getVersionCollection).pipe(
filter(collection => collection && collection.length > 0),
takeUntil(this.ngUnsubscribe),
withLatestFrom(
this.routerState.queryParams
),
map(([collection, params]) => {
if (collection && collection.length) {
return params.version || collection[0].id;
}
return null;
})
map(([collection, params]) => params.version || collection && collection.length ? collection[0].id : null)
).subscribe(version => {
if (version) {
this.store.dispatch(new SelectVersion(version));
}
this.store.dispatch(new SelectVersion(version));
});

this.name$ = this.store.select(fromReducer.getConfigurationModelName);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<div class="container">
<history-list
[history]="history$ | async"
(compare)="compareVersions($event)"></history-list>
(compare)="compareVersions($event)"
(restore)="restoreVersion($event)"></history-list>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,13 @@ export class MetadataHistoryComponent {
}
);
}

restoreVersion(version: MetadataVersion): void {
this.router.navigate(
[ '../', 'restore' ],
{
relativeTo: this.route
}
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<div class="d-flex justify-content-center align-items-center">
<div class="card m-4 w-50">
<div class="card-body">
<h3 class="card-title">Create new version from {{ date | date:DATE_FORMAT }} settings</h3>
<p>Restoring this version will copy the configuration from the selected version and create a new version from these settings. You can then edit the configuration before saving the new version.</p>
<a href="#" class="btn btn-light">Cancel</a>&nbsp;<a href="#" class="btn btn-primary">Restore</a>
</div>
</div>
</div>
31 changes: 31 additions & 0 deletions ui/src/app/metadata/configuration/container/restore.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Component, ChangeDetectionStrategy, OnDestroy } from '@angular/core';
import { ActivatedRoute, } from '@angular/router';
import { Store } from '@ngrx/store';
import { Subject } from 'rxjs';

import * as fromConfiguration from '../reducer';
import { CONFIG_DATE_FORMAT } from '../configuration.values';

@Component({
selector: 'restore-component',
changeDetection: ChangeDetectionStrategy.OnPush,
templateUrl: './restore.component.html',
styleUrls: []
})
export class RestoreComponent implements OnDestroy {
private ngUnsubscribe: Subject<void> = new Subject<void>();

DATE_FORMAT = CONFIG_DATE_FORMAT;

date = new Date();

constructor(
private store: Store<fromConfiguration.ConfigurationState>,
private routerState: ActivatedRoute
) {}

ngOnDestroy() {
this.ngUnsubscribe.next();
this.ngUnsubscribe.complete();
}
}
34 changes: 23 additions & 11 deletions ui/src/app/metadata/configuration/effect/configuration.effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,20 @@ import {
DownloadXml
} from '../action/configuration.action';
import { ResolverService } from '../../domain/service/resolver.service';
import { EntityIdService } from '../../domain/service/entity-id.service';
import { State } from '../reducer/configuration.reducer';
import { getConfigurationModel, getConfigurationXml } from '../reducer';
import { MetadataResolver } from '../../domain/model';
import { MetadataResolver, MetadataProvider } from '../../domain/model';
import {
SelectProviderRequest, SelectProviderSuccess, ProviderCollectionActionTypes
SelectProviderSuccess,
ProviderCollectionActionTypes
} from '../../provider/action/collection.action';
import {
SelectResolver,
SelectResolverSuccess,
ResolverCollectionActionTypes
} from '../../resolver/action/collection.action';
import { MetadataHistoryService } from '../service/history.service';
import { Metadata } from '../../domain/domain.type';
import { SelectVersion } from '../action/history.action';

@Injectable()
export class MetadataConfigurationEffects {
Expand All @@ -40,12 +42,22 @@ export class MetadataConfigurationEffects {
loadMetadata$ = this.actions$.pipe(
ofType<SetMetadata>(ConfigurationActionTypes.SET_METADATA),
map(action => action.payload),
map(payload => {
const action = (payload.type === 'resolver') ?
new SelectResolver(payload.id) :
new SelectProviderRequest(payload.id);
return action;
})
switchMap(payload =>
this.historyService.getVersion(payload.id, payload.type, payload.version).pipe(
map((response: Metadata) =>
(payload.type === 'resolver') ?
new SelectResolverSuccess(response as MetadataResolver) :
new SelectProviderSuccess(response as MetadataProvider)
)
)
)
);

@Effect()
setMetadataVersion$ = this.actions$.pipe(
ofType<SetMetadata>(ConfigurationActionTypes.SET_METADATA),
map(action => action.payload),
map(({version}) => new SelectVersion(version))
);

@Effect()
Expand Down Expand Up @@ -119,7 +131,7 @@ export class MetadataConfigurationEffects {
private configService: MetadataConfigurationService,
private actions$: Actions,
private resolverService: ResolverService,
private entityService: EntityIdService,
private historyService: MetadataHistoryService,
private store: Store<State>
) { }
}
34 changes: 34 additions & 0 deletions ui/src/app/metadata/configuration/effect/restore.effect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Injectable } from '@angular/core';
import { Actions, Effect, ofType } from '@ngrx/effects';
import { map, catchError, switchMap } from 'rxjs/operators';

import {
RestoreActionTypes,
SelectVersionRestoreRequest,
SelectVersionRestoreError,
SelectVersionRestoreSuccess
} from '../action/restore.action';
import { MetadataHistoryService } from '../service/history.service';
import { of } from 'rxjs';


@Injectable()
export class RestoreVersionEffects {

@Effect()
restoreVersionFromId$ = this.actions$.pipe(
ofType<SelectVersionRestoreRequest>(RestoreActionTypes.SELECT_VERSION_REQUEST),
map(action => action.payload),
switchMap(({ type, id, version }) => {
return this.historyService.getVersion(id, version, type).pipe(
map(v => new SelectVersionRestoreSuccess(v)),
catchError(err => of(new SelectVersionRestoreError(err)))
);
})
);

constructor(
private historyService: MetadataHistoryService,
private actions$: Actions
) { }
}
Loading

0 comments on commit 52089a2

Please sign in to comment.