-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged in feature/SHIBUI-1265 (pull request #318)
CCIE-1265 Added version history component Approved-by: Ryan Mathis <rmathis@unicon.net>
- Loading branch information
Showing
19 changed files
with
411 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
ui/src/app/metadata/version/component/history-list.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| <table class="table"> | ||
| <caption class="sr-only" translate="label.name-and-entityid">Metadata Version History</caption> | ||
| <thead> | ||
| <tr> | ||
| <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> | ||
| </tr> | ||
| </thead> | ||
| <tbody> | ||
| <tr *ngFor="let version of history.versions; 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"> | ||
| <label class="custom-control-label" [for]="'check-' + i"> | ||
| <span class="sr-only" translate="label.check-to-select">Check to select</span> | ||
| </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> | ||
| <button class="btn btn-link" (click)="restoreVersion(version)"> | ||
| <i class="fa fa-undo"></i> | ||
| <translate-i18n key="label.restore">Restore</translate-i18n> | ||
| </button> | ||
| </td> | ||
| </tr> | ||
| </tbody> | ||
| </table> | ||
| <button class="btn btn-primary" (click)="compareSelected(selected)" [disabled]="!selected.length"> | ||
| <translate-i18n key="label.compare-selected">Compare Selected</translate-i18n> <span *ngIf="selected.length">({{ selected.length }})</span> | ||
| </button> |
81 changes: 81 additions & 0 deletions
81
ui/src/app/metadata/version/component/history-list.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| import { Component, ViewChild } from '@angular/core'; | ||
| import { TestBed, ComponentFixture } from '@angular/core/testing'; | ||
| import { MockI18nModule } from '../../../../testing/i18n.stub'; | ||
| import { HistoryListComponent } from './history-list.component'; | ||
| import { MetadataHistory } from '../model/history'; | ||
| import { MetadataVersion } from '../model/version'; | ||
|
|
||
| export const TestData = { | ||
| versions: [ | ||
| { | ||
| versionNumber: 1, | ||
| saveDate: new Date(), | ||
| changedBy: 'admin', | ||
| actions: [] | ||
| } | ||
| ] | ||
| }; | ||
|
|
||
| @Component({ | ||
| template: `<history-list [history]="history" (compare)="compare($event)" (restore)="restore($event)"></history-list>` | ||
| }) | ||
| class TestHostComponent { | ||
| @ViewChild(HistoryListComponent) | ||
| public componentUnderTest: HistoryListComponent; | ||
|
|
||
| history: MetadataHistory = TestData; | ||
|
|
||
| compare(versions: MetadataVersion[]): void {} | ||
| restore(version: MetadataVersion): void {} | ||
| } | ||
|
|
||
| describe('Metadata History List Component', () => { | ||
| let fixture: ComponentFixture<TestHostComponent>; | ||
| let instance: TestHostComponent; | ||
| let table: HistoryListComponent; | ||
|
|
||
| beforeEach(() => { | ||
| TestBed.configureTestingModule({ | ||
| providers: [], | ||
| imports: [ | ||
| MockI18nModule | ||
| ], | ||
| declarations: [ | ||
| HistoryListComponent, | ||
| TestHostComponent | ||
| ], | ||
| }); | ||
|
|
||
| fixture = TestBed.createComponent(TestHostComponent); | ||
| instance = fixture.componentInstance; | ||
| table = instance.componentUnderTest; | ||
| fixture.detectChanges(); | ||
| }); | ||
|
|
||
| it('should compile', () => { | ||
| expect(table).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); | ||
| }); | ||
|
|
||
| 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); | ||
| fixture.detectChanges(); | ||
| expect(instance.compare).toHaveBeenCalledWith(selected); | ||
| }); | ||
|
|
||
| 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); | ||
| fixture.detectChanges(); | ||
| expect(instance.restore).toHaveBeenCalledWith(selected); | ||
| }); | ||
| }); | ||
| }); |
35 changes: 35 additions & 0 deletions
35
ui/src/app/metadata/version/component/history-list.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import { Component, Input, EventEmitter, ChangeDetectionStrategy, Output } from '@angular/core'; | ||
| import { MetadataHistory } from '../model/history'; | ||
| import { MetadataVersion } from '../model/version'; | ||
|
|
||
| @Component({ | ||
| selector: 'history-list', | ||
| changeDetection: ChangeDetectionStrategy.OnPush, | ||
| templateUrl: './history-list.component.html', | ||
| styleUrls: [] | ||
| }) | ||
| export class HistoryListComponent { | ||
| @Input() history: MetadataHistory; | ||
| @Output() compare: EventEmitter<MetadataVersion[]> = new EventEmitter(); | ||
| @Output() restore: EventEmitter<MetadataVersion> = new EventEmitter(); | ||
|
|
||
| selected: MetadataVersion[] = []; | ||
|
|
||
| constructor() {} | ||
|
|
||
| toggleVersionSelected(version: MetadataVersion): void { | ||
| if (this.selected.indexOf(version) > -1) { | ||
| this.selected = this.selected.filter(s => s !== version); | ||
| } else { | ||
| this.selected = [...this.selected, version]; | ||
| } | ||
| } | ||
|
|
||
| compareSelected(selected: MetadataVersion[]): void { | ||
| this.compare.emit(selected); | ||
| } | ||
|
|
||
| restoreVersion(version: MetadataVersion): void { | ||
| this.restore.emit(version); | ||
| } | ||
| } |
18 changes: 18 additions & 0 deletions
18
ui/src/app/metadata/version/container/version-history.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| <div class="container-fluid p-3"> | ||
| <section class="section" aria-label="View Metadata Version History" | ||
| tabindex="0"> | ||
| <div class="section-header bg-info p-2 text-white"> | ||
| <div class="row justify-content-between"> | ||
| <div class="col-md-12"> | ||
| <span class="display-6"> | ||
| <i class="fa fa-fw fa-gears"></i> | ||
| <translate-i18n key="label.metadata-resolver-history">Metadata resolver history</translate-i18n> | ||
| </span> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| <div class="section-body p-4 border border-top-0 border-info"> | ||
| <history-list [history]="history$ | async"></history-list> | ||
| </div> | ||
| </section> | ||
| </div> |
63 changes: 63 additions & 0 deletions
63
ui/src/app/metadata/version/container/version-history.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| import { Component, ViewChild, Input, EventEmitter, Output } from '@angular/core'; | ||
| import { TestBed, ComponentFixture } from '@angular/core/testing'; | ||
| import { MockI18nModule } from '../../../../testing/i18n.stub'; | ||
| import { VersionHistoryComponent } from './version-history.component'; | ||
| import { MetadataHistory } from '../model/history'; | ||
| import { MetadataVersion } from '../model/version'; | ||
| import { HistoryService } from '../service/history.service'; | ||
| import { of } from 'rxjs'; | ||
|
|
||
| export const TestData = { | ||
| versions: [ | ||
| { | ||
| versionNumber: 1, | ||
| saveDate: new Date(), | ||
| changedBy: 'admin', | ||
| actions: [] | ||
| } | ||
| ] | ||
| }; | ||
|
|
||
| @Component({ | ||
| selector: 'history-list', | ||
| template: `<span></span>` | ||
| }) | ||
| class MockHistoryListComponent { | ||
| @Input() history: MetadataHistory; | ||
| @Output() compare: EventEmitter<MetadataVersion[]> = new EventEmitter(); | ||
| @Output() restore: EventEmitter<MetadataVersion> = new EventEmitter(); | ||
| } | ||
|
|
||
| const MockHistoryService = { | ||
| query: () => of(TestData) | ||
| }; | ||
|
|
||
| describe('Metadata Version History Component', () => { | ||
| let fixture: ComponentFixture<VersionHistoryComponent>; | ||
| let instance: VersionHistoryComponent; | ||
|
|
||
| beforeEach(() => { | ||
| TestBed.configureTestingModule({ | ||
| providers: [ | ||
| { | ||
| provide: HistoryService, useValue: MockHistoryService | ||
| } | ||
| ], | ||
| imports: [ | ||
| MockI18nModule | ||
| ], | ||
| declarations: [ | ||
| MockHistoryListComponent, | ||
| VersionHistoryComponent | ||
| ], | ||
| }); | ||
|
|
||
| fixture = TestBed.createComponent(VersionHistoryComponent); | ||
| instance = fixture.componentInstance; | ||
| fixture.detectChanges(); | ||
| }); | ||
|
|
||
| it('should compile', () => { | ||
| expect(instance).toBeDefined(); | ||
| }); | ||
| }); |
21 changes: 21 additions & 0 deletions
21
ui/src/app/metadata/version/container/version-history.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import { Component, ChangeDetectionStrategy } from '@angular/core'; | ||
| import { MetadataHistory } from '../model/history'; | ||
| import { HistoryService } from '../service/history.service'; | ||
| import { Observable } from 'rxjs'; | ||
|
|
||
| @Component({ | ||
| selector: 'version-history', | ||
| changeDetection: ChangeDetectionStrategy.OnPush, | ||
| templateUrl: './version-history.component.html', | ||
| styleUrls: [] | ||
| }) | ||
| export class VersionHistoryComponent { | ||
|
|
||
| history$: Observable<MetadataHistory>; | ||
|
|
||
| constructor( | ||
| private historyService: HistoryService | ||
| ) { | ||
| this.history$ = this.historyService.query(); | ||
| } | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import { MetadataVersion } from './version'; | ||
|
|
||
| export interface MetadataHistory { | ||
| versions: MetadataVersion[]; | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| export interface MetadataVersion { | ||
| versionNumber: Number; | ||
| saveDate: Date; | ||
| changedBy: String; | ||
| actions: string[]; | ||
| } |
28 changes: 28 additions & 0 deletions
28
ui/src/app/metadata/version/service/history.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import { TestBed, async, inject } from '@angular/core/testing'; | ||
| import { HttpClientModule } from '@angular/common/http'; | ||
| import { HttpTestingController, HttpClientTestingModule } from '@angular/common/http/testing'; | ||
| import { HistoryService } from './history.service'; | ||
|
|
||
| describe(`Attributes Service`, () => { | ||
| beforeEach(() => { | ||
| TestBed.configureTestingModule({ | ||
| imports: [ | ||
| HttpClientModule, | ||
| HttpClientTestingModule | ||
| ], | ||
| providers: [ | ||
| HistoryService | ||
| ] | ||
| }); | ||
| }); | ||
|
|
||
| describe('query method', () => { | ||
| it(`should return a MetadataHistory`, async(inject([HistoryService, HttpTestingController], | ||
| (service: HistoryService) => { | ||
| service.query().subscribe(history => { | ||
| expect(history).toBeDefined(); | ||
| }); | ||
| } | ||
| ))); | ||
| }); | ||
| }); |
Oops, something went wrong.