-
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-1364 (pull request #378)
SHIBUI-1364 Implemented filter comparison Approved-by: Dmitriy Kopylenko <dkopylenko@unicon.net>
- Loading branch information
Showing
21 changed files
with
605 additions
and
15 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { Action } from '@ngrx/store'; | ||
import { Metadata } from '../../domain/domain.type'; | ||
import { FormDefinition } from '../../../wizard/model/form-definition'; | ||
import { FilterComparison } from '../model/compare'; | ||
import { Schema } from '../model/schema'; | ||
|
||
export enum FilterCompareActionTypes { | ||
LOAD_SCHEMA_REQUEST = '[Filter Compare Version] Compare Version Request', | ||
LOAD_SCHEMA_SUCCESS = '[Filter Compare Version] Compare Version Success', | ||
LOAD_SCHEMA_ERROR = '[Filter Compare Version] Compare Version Error', | ||
SET_SCHEMA = '[Filter Compare Version] Set Schema', | ||
SET_DEFINITION = '[Filter Compare Version] Set Definition', | ||
COMPARE_FILTERS = '[Filter Compare Version] Compare Filters', | ||
CLEAR = '[Filter Compare Version] Clear Filter Comparison' | ||
} | ||
|
||
export class LoadFilterSchemaRequest implements Action { | ||
readonly type = FilterCompareActionTypes.LOAD_SCHEMA_REQUEST; | ||
|
||
constructor(public payload: string) { } | ||
} | ||
|
||
export class LoadFilterSchemaSuccess implements Action { | ||
readonly type = FilterCompareActionTypes.LOAD_SCHEMA_SUCCESS; | ||
|
||
constructor(public payload: Schema) { } | ||
} | ||
|
||
export class LoadFilterSchemaError implements Action { | ||
readonly type = FilterCompareActionTypes.LOAD_SCHEMA_ERROR; | ||
|
||
constructor(public payload: any) { } | ||
} | ||
|
||
export class SetFilterComparisonSchema implements Action { | ||
readonly type = FilterCompareActionTypes.SET_SCHEMA; | ||
constructor(public payload: any) { } | ||
} | ||
|
||
export class SetFilterComparisonDefinition implements Action { | ||
readonly type = FilterCompareActionTypes.SET_DEFINITION; | ||
constructor(public payload: FormDefinition<Metadata>) { } | ||
} | ||
|
||
export class ClearFilterComparison implements Action { | ||
readonly type = FilterCompareActionTypes.CLEAR; | ||
} | ||
|
||
export class CompareFilterVersions implements Action { | ||
readonly type = FilterCompareActionTypes.COMPARE_FILTERS; | ||
|
||
constructor(public payload: FilterComparison) { } | ||
} | ||
|
||
export type FilterCompareActionsUnion = | ||
| LoadFilterSchemaRequest | ||
| LoadFilterSchemaSuccess | ||
| LoadFilterSchemaError | ||
| SetFilterComparisonSchema | ||
| SetFilterComparisonDefinition | ||
| CompareFilterVersions | ||
| ClearFilterComparison; |
51 changes: 51 additions & 0 deletions
51
ui/src/app/metadata/configuration/component/filter-version-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,51 @@ | ||
<ng-container *ngIf="filters && filters.dates.length > 0"> | ||
<div class="d-flex border-bottom border-light border-2 py-2"> | ||
<span [ngStyle]="{'width.%': width}" *ngIf="!comparing">Order</span> | ||
<span [ngStyle]="{'width.%': width}" *ngIf="comparing">Option</span> | ||
<strong *ngFor="let date of filters.dates" [ngStyle]="{'width.%': width}"> | ||
{{ date | date:DATE_FORMAT }} | ||
</strong> | ||
</div> | ||
<div class=""> | ||
<ng-container *ngFor="let version of filters.filters; let i = index; first as isFirst; last as isLast;"> | ||
<div class="d-flex border-bottom border-light"> | ||
<div [ngStyle]="{'width.%': width}" class="py-2"> | ||
{{ i + 1 }} | ||
</div> | ||
<div *ngFor="let filter of version; let i = index; even as isEven" | ||
[ngStyle]="{'width.%': width}" | ||
class="border-primary"> | ||
<div class="p-2 w-100" *ngIf="!filter">-</div> | ||
<div *ngIf="filter" | ||
class="p-2 d-flex align-items-center" | ||
[ngClass]="{ | ||
'bg-lighter': isEven && selected !== filter.resourceId, | ||
'bg-primary-light': selected === filter.resourceId | ||
}"> | ||
<div class="w-50"> | ||
<p class="mb-0">{{ filter.name }}</p> | ||
<p class="mb-0 text-muted">{{ filter['@type'] }}</p> | ||
</div> | ||
<button class="btn btn-link mx-auto" *ngIf="filter.comparable" | ||
(click)="selected = (selected !== filter.resourceId) ? filter.resourceId : null"> | ||
<i class="fa fa-lg" | ||
[ngClass]="{'fa-check-square-o': selected === filter.resourceId, 'fa-square-o': selected !== filter.resourceId}" | ||
aria-hidden="true"></i> | ||
<span class="sr-only">Compare</span> | ||
</button> | ||
</div> | ||
</div> | ||
|
||
</div> | ||
</ng-container> | ||
</div> | ||
<div class="d-flex justify-content-end my-2"> | ||
<button class="btn btn-primary" [disabled]="!selected" (click)="compareSelected()"> | ||
<translate-i18n key="label.compare-selected">Compare Selected</translate-i18n> | ||
</button> | ||
</div> | ||
</ng-container> | ||
<div class="alert alert-info m-4" *ngIf="filters && filters.dates.length < 1"> | ||
<h3 translate="message.no-filters">No Filters</h3> | ||
<p translate="message.no-filters-added">No filters have been added to this Metadata Provider</p> | ||
</div> |
80 changes: 80 additions & 0 deletions
80
ui/src/app/metadata/configuration/component/filter-version-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,80 @@ | ||
import { Component, ViewChild } from '@angular/core'; | ||
import { TestBed, ComponentFixture } from '@angular/core/testing'; | ||
import { RouterTestingModule } from '@angular/router/testing'; | ||
|
||
import { MockI18nModule } from '../../../../testing/i18n.stub'; | ||
import { FilterVersionListComponent } from './filter-version-list.component'; | ||
import { FilterComparison } from '../model/compare'; | ||
import { FilterConfiguration } from '../model/metadata-configuration'; | ||
|
||
export const TestData: FilterConfiguration = { | ||
dates: ['2019-09-23T20:54:31.081Z', '2019-10-23T20:54:31.081Z'], | ||
filters: [ | ||
[ | ||
{ | ||
resourceId: 'foo', | ||
name: 'Test 1', | ||
type: 'EntityAttributesFilter', | ||
comparable: false | ||
}, | ||
{ | ||
resourceId: 'bar', | ||
name: 'Test 2', | ||
type: 'EntityAttributesFilter', | ||
comparable: false | ||
} | ||
] | ||
] | ||
}; | ||
|
||
@Component({ | ||
template: `<filter-version-list [filters]="filters" (compare)="compare($event)"></filter-version-list>` | ||
}) | ||
class TestHostComponent { | ||
@ViewChild(FilterVersionListComponent) | ||
public componentUnderTest: FilterVersionListComponent; | ||
|
||
filters = TestData; | ||
|
||
compare(versions: FilterComparison): void { } | ||
} | ||
|
||
describe('Filter Version List Component', () => { | ||
let fixture: ComponentFixture<TestHostComponent>; | ||
let instance: TestHostComponent; | ||
let list: FilterVersionListComponent; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
providers: [], | ||
imports: [ | ||
MockI18nModule, | ||
RouterTestingModule | ||
], | ||
declarations: [ | ||
FilterVersionListComponent, | ||
TestHostComponent | ||
], | ||
}); | ||
|
||
fixture = TestBed.createComponent(TestHostComponent); | ||
instance = fixture.componentInstance; | ||
list = instance.componentUnderTest; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should compile', () => { | ||
expect(list).toBeDefined(); | ||
}); | ||
|
||
describe('compareSelected', () => { | ||
it('should emit an event with the selected filter data', () => { | ||
spyOn(instance, 'compare'); | ||
list.selected = 'foo'; | ||
fixture.detectChanges(); | ||
list.compareSelected(); | ||
fixture.detectChanges(); | ||
expect(instance.compare).toHaveBeenCalled(); | ||
}); | ||
}); | ||
}); |
40 changes: 40 additions & 0 deletions
40
ui/src/app/metadata/configuration/component/filter-version-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,40 @@ | ||
import { Component, Input, Output, EventEmitter } from '@angular/core'; | ||
import { FilterConfiguration, MetadataConfiguration } from '../model/metadata-configuration'; | ||
import { CONFIG_DATE_FORMAT } from '../configuration.values'; | ||
import { Observable } from 'rxjs'; | ||
import { FilterComparison } from '../model/compare'; | ||
|
||
@Component({ | ||
selector: 'filter-version-list', | ||
templateUrl: './filter-version-list.component.html' | ||
}) | ||
export class FilterVersionListComponent { | ||
|
||
@Input() filters: FilterConfiguration; | ||
@Output() compare: EventEmitter<FilterComparison> = new EventEmitter(); | ||
|
||
selected: string; | ||
comparing: string; | ||
selectedFilters$: Observable<MetadataConfiguration>; | ||
|
||
DATE_FORMAT = CONFIG_DATE_FORMAT; | ||
|
||
constructor() {} | ||
|
||
compareSelected() { | ||
const reduced = this.filters.filters.reduce((acc, l) => acc.concat(l), []); | ||
const filtered = reduced.filter(f => f && f.resourceId === this.selected); | ||
const type = filtered[0]['@type']; | ||
|
||
this.compare.emit({ | ||
modelId: this.selected, | ||
modelType: type, | ||
models: filtered | ||
}); | ||
} | ||
|
||
get width(): string { | ||
const columns = this.filters.dates.length; | ||
return `${Math.floor(100 / (columns + 1))}`; | ||
} | ||
} |
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
Oops, something went wrong.