From b24274ef119f7ae97c307ce6fcdee00653bd2695 Mon Sep 17 00:00:00 2001 From: Snehal Kumbhar Date: Fri, 16 Jul 2021 13:05:08 +0200 Subject: [PATCH] feat(viewer): split pane to compare multiple resource (DSP-1785) (#316) * feat(resource comparison viewer): create component * feat(resource comparison viewer): add component in playground * feat(resource comparison viewer): split window to display resource ids * feat(resource comparison viewer): display resource details * feat(resource comparison viewer): add description in viewer module * feat(resource comparison viewer): add test cases --- package.json | 1 + projects/dsp-ui/src/lib/viewer/index.ts | 1 + .../dsp-ui/src/lib/viewer/viewer.module.ts | 15 ++-- .../multiple-resources-view.component.html | 26 ++++++ .../multiple-resources-view.component.scss | 4 + .../multiple-resources-view.component.spec.ts | 80 +++++++++++++++++++ .../multiple-resources-view.component.ts | 34 ++++++++ .../viewer-playground.component.html | 68 +++++++++++----- .../viewer-playground.component.ts | 9 +++ 9 files changed, 212 insertions(+), 26 deletions(-) create mode 100644 projects/dsp-ui/src/lib/viewer/views/multiple-resources-view/multiple-resources-view.component.html create mode 100644 projects/dsp-ui/src/lib/viewer/views/multiple-resources-view/multiple-resources-view.component.scss create mode 100644 projects/dsp-ui/src/lib/viewer/views/multiple-resources-view/multiple-resources-view.component.spec.ts create mode 100644 projects/dsp-ui/src/lib/viewer/views/multiple-resources-view/multiple-resources-view.component.ts diff --git a/package.json b/package.json index da2d2c9e8..9301fd9ef 100644 --- a/package.json +++ b/package.json @@ -66,6 +66,7 @@ "@types/jasmine": "~3.6.0", "@types/jasminewd2": "~2.0.3", "@types/node": "^12.11.1", + "angular-split": "^4.0.0", "codelyzer": "^6.0.0", "jasmine-core": "~3.6.0", "jasmine-spec-reporter": "~5.0.0", diff --git a/projects/dsp-ui/src/lib/viewer/index.ts b/projects/dsp-ui/src/lib/viewer/index.ts index 5410d42e9..91c7f708c 100644 --- a/projects/dsp-ui/src/lib/viewer/index.ts +++ b/projects/dsp-ui/src/lib/viewer/index.ts @@ -26,6 +26,7 @@ export * from './views/property-view/property-view.component'; export * from './views/list-view/list-view.component'; export * from './views/list-view/resource-list/resource-list.component'; export * from './views/list-view/resource-grid/resource-grid.component'; +export * from './views/multiple-resources-view/multiple-resources-view.component'; // media representations export * from './representation/still-image/still-image.component'; export * from './representation/upload-file/upload-file.component'; diff --git a/projects/dsp-ui/src/lib/viewer/viewer.module.ts b/projects/dsp-ui/src/lib/viewer/viewer.module.ts index 3deed4e2d..50bf54186 100644 --- a/projects/dsp-ui/src/lib/viewer/viewer.module.ts +++ b/projects/dsp-ui/src/lib/viewer/viewer.module.ts @@ -15,11 +15,13 @@ import { MatInputModule } from '@angular/material/input'; import { MatListModule } from '@angular/material/list'; import { MatMenuModule } from '@angular/material/menu'; import { MatPaginatorModule } from '@angular/material/paginator'; +import { MatRadioModule } from '@angular/material/radio'; import { MatSelectModule } from '@angular/material/select'; import { MatSnackBarModule } from '@angular/material/snack-bar'; import { MatToolbarModule } from '@angular/material/toolbar'; import { MatTooltipModule } from '@angular/material/tooltip'; import { CKEditorModule } from '@ckeditor/ckeditor5-angular'; +import { AngularSplitModule } from 'angular-split'; import { MatJDNConvertibleCalendarDateAdapterModule } from 'jdnconvertiblecalendardateadapter'; import { ColorPickerModule } from 'ngx-color-picker'; import { DspActionModule } from '../action/action.module'; @@ -33,6 +35,8 @@ import { BooleanValueComponent } from './values/boolean-value/boolean-value.comp import { ColorPickerComponent } from './values/color-value/color-picker/color-picker.component'; import { ColorValueComponent } from './values/color-value/color-value.component'; import { CalendarHeaderComponent } from './values/date-value/calendar-header/calendar-header.component'; +import { DateEditComponent } from './values/date-value/date-input-text/date-edit/date-edit.component'; +import { DateInputTextComponent } from './values/date-value/date-input-text/date-input-text.component'; import { DateInputComponent } from './values/date-value/date-input/date-input.component'; import { DateValueComponent } from './values/date-value/date-value.component'; import { DecimalValueComponent } from './values/decimal-value/decimal-value.component'; @@ -53,12 +57,10 @@ import { UriValueComponent } from './values/uri-value/uri-value.component'; import { ListViewComponent } from './views/list-view/list-view.component'; import { ResourceGridComponent } from './views/list-view/resource-grid/resource-grid.component'; import { ResourceListComponent } from './views/list-view/resource-list/resource-list.component'; +import { MultipleResourcesViewComponent } from './views/multiple-resources-view/multiple-resources-view.component'; import { PropertyToolbarComponent } from './views/property-view/property-toolbar/property-toolbar.component'; import { PropertyViewComponent } from './views/property-view/property-view.component'; import { ResourceViewComponent } from './views/resource-view/resource-view.component'; -import { DateInputTextComponent } from './values/date-value/date-input-text/date-input-text.component'; -import { DateEditComponent } from './values/date-value/date-input-text/date-edit/date-edit.component'; -import { MatRadioModule } from '@angular/material/radio'; @NgModule({ declarations: [ @@ -96,9 +98,11 @@ import { MatRadioModule } from '@angular/material/radio'; UploadFileComponent, UriValueComponent, DateInputTextComponent, - DateEditComponent + DateEditComponent, + MultipleResourcesViewComponent ], imports: [ + AngularSplitModule.forRoot(), CKEditorModule, ClipboardModule, ColorPickerModule, @@ -152,7 +156,8 @@ import { MatRadioModule } from '@angular/material/radio'; TextValueHtmlLinkDirective, TimeValueComponent, UploadFileComponent, - UriValueComponent + UriValueComponent, + MultipleResourcesViewComponent ] }) export class DspViewerModule { diff --git a/projects/dsp-ui/src/lib/viewer/views/multiple-resources-view/multiple-resources-view.component.html b/projects/dsp-ui/src/lib/viewer/views/multiple-resources-view/multiple-resources-view.component.html new file mode 100644 index 000000000..5121329af --- /dev/null +++ b/projects/dsp-ui/src/lib/viewer/views/multiple-resources-view/multiple-resources-view.component.html @@ -0,0 +1,26 @@ +
+ + + + + + + + + + + + + + + + + + + +
\ No newline at end of file diff --git a/projects/dsp-ui/src/lib/viewer/views/multiple-resources-view/multiple-resources-view.component.scss b/projects/dsp-ui/src/lib/viewer/views/multiple-resources-view/multiple-resources-view.component.scss new file mode 100644 index 000000000..91af80131 --- /dev/null +++ b/projects/dsp-ui/src/lib/viewer/views/multiple-resources-view/multiple-resources-view.component.scss @@ -0,0 +1,4 @@ +.content { + width: 100%; + height: 1400px; +} \ No newline at end of file diff --git a/projects/dsp-ui/src/lib/viewer/views/multiple-resources-view/multiple-resources-view.component.spec.ts b/projects/dsp-ui/src/lib/viewer/views/multiple-resources-view/multiple-resources-view.component.spec.ts new file mode 100644 index 000000000..3491decad --- /dev/null +++ b/projects/dsp-ui/src/lib/viewer/views/multiple-resources-view/multiple-resources-view.component.spec.ts @@ -0,0 +1,80 @@ + +import { Component, Input, ViewChild } from '@angular/core'; +import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; +import { AngularSplitModule } from 'angular-split'; +import { MultipleResourcesViewComponent } from './multiple-resources-view.component'; + +/** + * Test host component to simulate child component, here resource-view. + */ + @Component({ + selector: `dsp-resource-view`, + template: `` + }) + class TestResourceViewComponent { + @Input() iri: string; + @Input() showToolbar: boolean; + } + +/** + * Test host component to simulate parent component. + */ +@Component({ + selector: `dsp-multiple-resources-host-component`, + template: ` + + + ` +}) +class TestHostMultipleResourcesComponent { + + @ViewChild('multipleResourcesView') multipleResourcesView: MultipleResourcesViewComponent; + + resourceIds = [ + 'http://rdfh.ch/0803/18a671b8a601', + 'http://rdfh.ch/0803/7e4cfc5417', + 'http://rdfh.ch/0803/6ad3e2c47501', + 'http://rdfh.ch/0803/009e225a5f01', + 'http://rdfh.ch/0803/00ed33070f02' + ]; + noOfResources = this.resourceIds.length; +} + +describe('MultipleResourcesViewComponent', () => { + + let testHostComponent: TestHostMultipleResourcesComponent + let testHostFixture: ComponentFixture; + + beforeEach(waitForAsync(() => { + + TestBed.configureTestingModule({ + declarations: [ + MultipleResourcesViewComponent, + TestHostMultipleResourcesComponent, + TestResourceViewComponent + ], + imports: [AngularSplitModule] + }) + .compileComponents(); + + })); + + beforeEach(() => { + testHostFixture = TestBed.createComponent(TestHostMultipleResourcesComponent); + testHostComponent = testHostFixture.componentInstance; + testHostFixture.detectChanges(); + }); + + it('should create', () => { + expect(testHostComponent.multipleResourcesView).toBeTruthy(); + }); + + it('expect top row with 2 resources', () => { + expect(testHostComponent.multipleResourcesView.topRow.length).toEqual(2); + }); + + it('expect bottom row with 3 resources', () => { + expect(testHostComponent.multipleResourcesView.bottomRow.length).toEqual(3); + }); + +}); diff --git a/projects/dsp-ui/src/lib/viewer/views/multiple-resources-view/multiple-resources-view.component.ts b/projects/dsp-ui/src/lib/viewer/views/multiple-resources-view/multiple-resources-view.component.ts new file mode 100644 index 000000000..51611298a --- /dev/null +++ b/projects/dsp-ui/src/lib/viewer/views/multiple-resources-view/multiple-resources-view.component.ts @@ -0,0 +1,34 @@ +import { Component, Input, OnInit } from '@angular/core'; + +@Component({ + selector: 'dsp-multiple-resources-view', + templateUrl: './multiple-resources-view.component.html', + styleUrls: ['./multiple-resources-view.component.scss'] +}) +export class MultipleResourcesViewComponent implements OnInit { + + // no of resources selected + @Input() noOfResources: number; + + // list of resources + @Input() resourceIds: string[]; + + // if number of selected resources > 3, divide them in 2 rows + topRow = []; + bottomRow = []; + + constructor() { } + + ngOnInit(): void { + // if number of resources are more than 3, divide it into 2 rows + // otherwise display then in 1 row only + if (this.noOfResources < 4) { + this.topRow = this.resourceIds; + } + else { + this.topRow = this.resourceIds.slice(0, this.noOfResources / 2); + this.bottomRow = this.resourceIds.slice(this.noOfResources / 2) + } + } + +} diff --git a/src/app/viewer-playground/viewer-playground.component.html b/src/app/viewer-playground/viewer-playground.component.html index d9d7acfe5..d20187f44 100644 --- a/src/app/viewer-playground/viewer-playground.component.html +++ b/src/app/viewer-playground/viewer-playground.component.html @@ -1,21 +1,47 @@ -

The DspViewerModule contains different component to display a resource. - The example here shows the usage of dsp-resource-view which combines smaller - components like one of the representation viewer or the value components. All of them can - also be used individually.

- - - - +
+

Single resource viewer

+ +

The DspViewerModule contains different component to display a resource. + The example here shows the usage of dsp-resource-view which combines smaller + components like one of the representation viewer or the value components. All of them can + also be used individually.

+
    + +
+ + + +
+ +

+ +
+ +
+

Multiple resources viewer

+ +

The example here shows the usage of dsp-multiple-resources-view which + splits the view vertically and horizontally depending on the number of resources + selected and displays its details. +

+ +

Resources displayed:

+
    +
  • + {{res}} +
  • +
+ + +
\ No newline at end of file diff --git a/src/app/viewer-playground/viewer-playground.component.ts b/src/app/viewer-playground/viewer-playground.component.ts index a4ce69469..521d4d40f 100644 --- a/src/app/viewer-playground/viewer-playground.component.ts +++ b/src/app/viewer-playground/viewer-playground.component.ts @@ -18,6 +18,15 @@ export class ViewerPlaygroundComponent implements OnInit { ]; resourceIri: string = this.resources[0]; + resourceIds = [ + 'http://rdfh.ch/0803/18a671b8a601', + 'http://rdfh.ch/0803/7e4cfc5417', + 'http://rdfh.ch/0803/6ad3e2c47501', + 'http://rdfh.ch/0803/009e225a5f01', + 'http://rdfh.ch/0803/00ed33070f02' + ]; + noOfResources = this.resourceIds.length; + constructor( private _sessionService: SessionService