Skip to content

Commit

Permalink
Merged in feature/SHIBUI-1268 (pull request #329)
Browse files Browse the repository at this point in the history
SHIBUI-1268 Integrated header with version history

Approved-by: Ryan Mathis <rmathis@unicon.net>
  • Loading branch information
rmathis committed Jun 26, 2019
2 parents e644e3d + 6fe4e4a commit d53c96a
Show file tree
Hide file tree
Showing 43 changed files with 576 additions and 206 deletions.
7 changes: 7 additions & 0 deletions backend/src/main/resources/i18n/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,13 @@ action.move-down=Move Down
action.edit=Edit
action.add-filter=Add Filter
action.manage-filters=Manage Filters
action.version-history=Version History
action.options=Options
action.xml=XML

value.enabled=Enabled
value.disabled=Disabled
value.current=Current
value.none=None
value.file=File
value.memory=Memory
Expand Down Expand Up @@ -402,6 +406,9 @@ label.current=Current
label.restore=Restore
label.compare-selected=Compare Selected

label.saved=Saved
label.by=by

message.delete-user-title=Delete User?
message.delete-user-body=You are requesting to delete a user. If you complete this process the user will be removed. This cannot be undone. Do you wish to continue?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class LoadSchemaError implements Action {
export class LoadXmlRequest implements Action {
readonly type = ConfigurationActionTypes.LOAD_XML_REQUEST;

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

export class LoadXmlSuccess implements Action {
Expand Down
52 changes: 52 additions & 0 deletions ui/src/app/metadata/configuration/action/history.action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { Action } from '@ngrx/store';
import { MetadataHistory } from '../model/history';

export enum HistoryActionTypes {
LOAD_HISTORY_REQUEST = '[Configuration History] Load History Request',
LOAD_HISTORY_SUCCESS = '[Configuration History] Load History Success',
LOAD_HISTORY_ERROR = '[Configuration History] Load History Error',
SET_HISTORY = '[Configuration History] Set History',
CLEAR_HISTORY = '[Configuration History] Clear History',
SELECT_VERSION = '[Configuration History] Select Version'
}

export class LoadHistoryRequest implements Action {
readonly type = HistoryActionTypes.LOAD_HISTORY_REQUEST;

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

export class LoadHistorySuccess implements Action {
readonly type = HistoryActionTypes.LOAD_HISTORY_SUCCESS;

constructor(public payload: MetadataHistory) { }
}

export class LoadHistoryError implements Action {
readonly type = HistoryActionTypes.LOAD_HISTORY_ERROR;

constructor(public payload: any) { }
}

export class SelectVersion implements Action {
readonly type = HistoryActionTypes.SELECT_VERSION;
constructor(public payload: string | null) { }
}

export class SetHistory implements Action {
readonly type = HistoryActionTypes.SET_HISTORY;

constructor(public payload: MetadataHistory) {}
}

export class ClearHistory implements Action {
readonly type = HistoryActionTypes.CLEAR_HISTORY;
}

export type HistoryActionsUnion =
| LoadHistoryRequest
| LoadHistorySuccess
| LoadHistoryError
| SetHistory
| ClearHistory
| SelectVersion;
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</tr>
</thead>
<tbody>
<tr *ngFor="let version of history.versions; index as i;">
<tr *ngFor="let version of history; index as i;">
<td>
<div class="custom-control custom-checkbox" (click)="toggleVersionSelected(version)">
<input [title]="'check-' + i" type="checkbox" class="custom-control-input" [checked]="selected.indexOf(version) > -1">
Expand All @@ -21,19 +21,19 @@
</label>
</div>
</td>
<td *ngIf="i === 0"><translate-i18n key="label.current">Current</translate-i18n> (v{{ version.versionNumber }})</td>
<td *ngIf="i > 0">v{{ version.versionNumber }}</td>
<td>{{ version.saveDate | date }}</td>
<td>{{ version.changedBy }}</td>
<td *ngIf="i === 0"><translate-i18n key="label.current">Current</translate-i18n> (v{{ i + 1 }})</td>
<td *ngIf="i > 0">v{{ i + 1 }}</td>
<td>{{ version.date | date }}</td>
<td>{{ version.creator }}</td>
<td>
<button class="btn btn-link" (click)="restoreVersion(version)">
<i class="fa fa-undo"></i>
<button class="btn btn-link" (click)="restore.emit(version)">
<i class="fa fa-undo"></i>&nbsp;
<translate-i18n key="label.restore">Restore</translate-i18n>
</button>
</td>
</tr>
</tbody>
</table>
<button class="btn btn-primary" (click)="compareSelected(selected)" [disabled]="!selected.length">
<button class="btn btn-primary" (click)="compare.emit(selected)" [disabled]="!selected.length">
<translate-i18n key="label.compare-selected">Compare Selected</translate-i18n> <span *ngIf="selected.length">({{ selected.length }})</span>
</button>
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@ import { MetadataVersion } from '../model/version';
export const TestData = {
versions: [
{
versionNumber: 1,
saveDate: new Date(),
changedBy: 'admin',
actions: []
id: 'foo',
date: new Date().toDateString(),
creator: 'admin'
}
]
};

@Component({
template: `<history-list [history]="history" (compare)="compare($event)" (restore)="restore($event)"></history-list>`
template: `<history-list [history]="history.versions" (compare)="compare($event)" (restore)="restore($event)"></history-list>`
})
class TestHostComponent {
@ViewChild(HistoryListComponent)
Expand All @@ -32,7 +31,7 @@ class TestHostComponent {
describe('Metadata History List Component', () => {
let fixture: ComponentFixture<TestHostComponent>;
let instance: TestHostComponent;
let table: HistoryListComponent;
let list: HistoryListComponent;

beforeEach(() => {
TestBed.configureTestingModule({
Expand All @@ -48,32 +47,34 @@ describe('Metadata History List Component', () => {

fixture = TestBed.createComponent(TestHostComponent);
instance = fixture.componentInstance;
table = instance.componentUnderTest;
list = instance.componentUnderTest;
fixture.detectChanges();
});

it('should compile', () => {
expect(table).toBeDefined();
expect(list).toBeDefined();
});

describe('compare selected', () => {
it('should allow the user to toggle selected versions for comparison', () => {
table.toggleVersionSelected(TestData.versions[0]);
expect(table.selected.length).toBe(1);
list.toggleVersionSelected(TestData.versions[0]);
expect(list.selected.length).toBe(1);
});

it('should emit an event with the selected values when the Compare Selected button is clicked', () => {
spyOn(instance, 'compare');
const selected = TestData.versions;
table.compareSelected(selected);
list.compareSelected(selected);
fixture.detectChanges();
expect(instance.compare).toHaveBeenCalledWith(selected);
});
});

describe('restore', () => {
it('should emit an event with the selected version when the Restore button is clicked', () => {
spyOn(instance, 'restore');
const selected = TestData.versions[0];
table.restoreVersion(selected);
list.restoreVersion(selected);
fixture.detectChanges();
expect(instance.restore).toHaveBeenCalledWith(selected);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { MetadataVersion } from '../model/version';
styleUrls: []
})
export class HistoryListComponent {
@Input() history: MetadataHistory;
@Input() history: MetadataVersion[];
@Output() compare: EventEmitter<MetadataVersion[]> = new EventEmitter();
@Output() restore: EventEmitter<MetadataVersion> = new EventEmitter();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<div *ngIf="configuration">
<section class="px-3 mb-3" *ngFor="let section of configuration.sections; let i = index;">
<section *ngFor="let section of configuration.sections; let i = index;">
<div class="config-group">
<div class="numbered-header d-flex justify-content-start bg-light align-items-center">
<h2 class="title h4 m-0 flex-grow-1">
<span class="d-inline-block px-2 py-1 mr-2 mb-0 h4 number border border-secondary bg-white rounded-lg"><span *ngIf="i + 1 < 10">0</span>{{ i + 1 }}</span>
<span class="text">{{ section.label | translate }}</span>
</h2>
<div class="actions px-2">
<a class="edit-link change-view" [routerLink]="['../', 'edit', section.id]">
<i class="fa fa-edit"></i>
<button class="btn btn-link edit-link change-view" (click)="edit(section.id)">
<i class="fa fa-edit"></i>&nbsp;
<span translate="action.edit">Edit</span>
</a>
</button>
</div>
</div>
<div class="d-flex border-bottom border-light border-2 p-2">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Component, ChangeDetectionStrategy, Input } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
import { MetadataConfiguration } from '../model/metadata-configuration';

@Component({
Expand All @@ -10,5 +11,12 @@ import { MetadataConfiguration } from '../model/metadata-configuration';
export class MetadataConfigurationComponent {
@Input() configuration: MetadataConfiguration;

constructor() { }
constructor(
private router: Router,
private activatedRoute: ActivatedRoute
) { }

edit(id: string): void {
this.router.navigate(['../', 'edit', id], { relativeTo: this.activatedRoute.parent });
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<div class="card enabled-status" *ngIf="version">
<div class="card-body">
<h2 class="card-title version-title">
<translate-i18n key="label.version">Version</translate-i18n> {{ versionNumber }}
</h2>
<p class="card-text version-details">
<translate-i18n key="label.saved">Saved</translate-i18n>&nbsp;
<span class="save-date">{{ version.date | date }}</span>,
<translate-i18n key="label.by">by</translate-i18n>&nbsp;
<span class="author">{{ version.creator }}</span>
</p>
<p class="card-text">
<span class="badge badge-primary" *ngIf="isEnabled" translate="value.enabled">Enabled</span>
&nbsp;
<span class="badge badge-danger" *ngIf="!isEnabled" translate="value.disabled">Disabled</span>
<span class="badge badge-primary" *ngIf="isCurrent" translate="value.current">Current</span>
</p>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { Component, ViewChild } from '@angular/core';
import { TestBed, async, ComponentFixture } from '@angular/core/testing';
import { MockI18nModule } from '../../../../testing/i18n.stub';
import { MetadataVersion } from '../model/version';
import { MetadataHeaderComponent } from './metadata-header.component';

@Component({
template: `
<metadata-header
[isEnabled]="isEnabled"
[version]="version"
[versionNumber]="versionNumber"
[isCurrent]="isCurrent"
></metadata-header>
`
})
class TestHostComponent {
@ViewChild(MetadataHeaderComponent)
public componentUnderTest: MetadataHeaderComponent;

isEnabled = true;

version: MetadataVersion = {
id: 'foo',
creator: 'foobar',
date: new Date().toDateString()
};
versionNumber = 1;
isCurrent = false;
}

describe('Metadata Header Component', () => {

let fixture: ComponentFixture<TestHostComponent>;
let instance: TestHostComponent;
let app: MetadataHeaderComponent;

beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
MockI18nModule
],
declarations: [
MetadataHeaderComponent,
TestHostComponent
]
}).compileComponents();

fixture = TestBed.createComponent(TestHostComponent);
instance = fixture.componentInstance;
app = instance.componentUnderTest;
fixture.detectChanges();
}));

it('should accept a property input', async(() => {
expect(app).toBeTruthy();
}));
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Component, Input } from '@angular/core';
import { Metadata, MetadataTypes } from '../../domain/domain.type';
import { MetadataVersion } from '../model/version';

@Component({
selector: 'metadata-header',
templateUrl: './metadata-header.component.html',
styleUrls: []
})

export class MetadataHeaderComponent {
@Input() isEnabled: boolean;
@Input() version: MetadataVersion;
@Input() versionNumber: number;
@Input() isCurrent: boolean;

constructor() {}
}

16 changes: 12 additions & 4 deletions ui/src/app/metadata/configuration/configuration.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@ import { MetadataConfigurationService } from './service/configuration.service';
import * as fromConfig from './reducer';
import { MetadataConfigurationEffects } from './effect/configuration.effect';
import { ConfigurationPropertyComponent } from './component/configuration-property.component';
import { DomainModule } from '../domain/domain.module';
import { PrimitivePropertyComponent } from './component/primitive-property.component';
import { ObjectPropertyComponent } from './component/object-property.component';
import { ArrayPropertyComponent } from './component/array-property.component';
import { RouterModule } from '@angular/router';
import { MetadataOptionsComponent } from './container/metadata-options.component';
import { MetadataXmlComponent } from './container/metadata-xml.component';
import { MetadataHeaderComponent } from './component/metadata-header.component';
import { MetadataHistoryEffects } from './effect/history.effect';
import { MetadataHistoryService } from './service/history.service';
import { MetadataHistoryComponent } from './container/metadata-history.component';
import { HistoryListComponent } from './component/history-list.component';

@NgModule({
declarations: [
Expand All @@ -29,7 +33,10 @@ import { MetadataXmlComponent } from './container/metadata-xml.component';
PrimitivePropertyComponent,
ObjectPropertyComponent,
ArrayPropertyComponent,
ConfigurationComponent
ConfigurationComponent,
MetadataHeaderComponent,
MetadataHistoryComponent,
HistoryListComponent
],
entryComponents: [],
imports: [
Expand All @@ -46,7 +53,8 @@ export class MetadataConfigurationModule {
return {
ngModule: RootMetadataConfigurationModule,
providers: [
MetadataConfigurationService
MetadataConfigurationService,
MetadataHistoryService
]
};
}
Expand All @@ -56,7 +64,7 @@ export class MetadataConfigurationModule {
imports: [
MetadataConfigurationModule,
StoreModule.forFeature('metadata-configuration', fromConfig.reducers),
EffectsModule.forFeature([MetadataConfigurationEffects])
EffectsModule.forFeature([MetadataConfigurationEffects, MetadataHistoryEffects])
],
providers: []
})
Expand Down
Loading

0 comments on commit d53c96a

Please sign in to comment.