Skip to content
Permalink
Browse files
refactor(search): migrate search module (DSP-1851) (#510)
* refactor(search): migrates:
 - expert-search comp
 - fulltext-search comp
 - search-panel comp
 - _search.scss -> assets

* refactor(search): migrates advanced search
  • Loading branch information
mdelez committed Sep 1, 2021
1 parent 35f6e7b commit fc7ea5c5f1b6b225c20e41cbd3273aa8a1acc4d0
Showing with 7,974 additions and 2 deletions.
  1. +37 −0 src/app/app.module.ts
  2. +1 −1 src/app/workspace/results/list-view/list-view.component.spec.ts
  3. +1 −1 src/app/workspace/results/list-view/list-view.component.ts
  4. +23 −0 src/app/workspace/search/advanced-search/advanced-search.component.html
  5. 0 src/app/workspace/search/advanced-search/advanced-search.component.scss
  6. +179 −0 src/app/workspace/search/advanced-search/advanced-search.component.spec.ts
  7. +175 −0 src/app/workspace/search/advanced-search/advanced-search.component.ts
  8. +33 −0 ...ch/advanced-search/resource-and-property-selection/resource-and-property-selection.component.html
  9. +7 −0 ...ch/advanced-search/resource-and-property-selection/resource-and-property-selection.component.scss
  10. +331 −0 ...advanced-search/resource-and-property-selection/resource-and-property-selection.component.spec.ts
  11. +151 −0 ...arch/advanced-search/resource-and-property-selection/resource-and-property-selection.component.ts
  12. +12 −0 ...arch/resource-and-property-selection/search-select-property/search-select-property.component.html
  13. +3 −0 ...arch/resource-and-property-selection/search-select-property/search-select-property.component.scss
  14. +298 −0 ...h/resource-and-property-selection/search-select-property/search-select-property.component.spec.ts
  15. +151 −0 ...search/resource-and-property-selection/search-select-property/search-select-property.component.ts
  16. +33 −0 ...source-and-property-selection/search-select-property/specify-property-value/operator-constants.ts
  17. +283 −0 ...-search/resource-and-property-selection/search-select-property/specify-property-value/operator.ts
  18. +3 −0 ...h-select-property/specify-property-value/search-boolean-value/search-boolean-value.component.html
  19. 0 ...h-select-property/specify-property-value/search-boolean-value/search-boolean-value.component.scss
  20. +79 −0 ...elect-property/specify-property-value/search-boolean-value/search-boolean-value.component.spec.ts
  21. +53 −0 ...rch-select-property/specify-property-value/search-boolean-value/search-boolean-value.component.ts
  22. +9 −0 .../search-select-property/specify-property-value/search-date-value/search-date-value.component.html
  23. +9 −0 .../search-select-property/specify-property-value/search-date-value/search-date-value.component.scss
  24. +87 −0 ...arch-select-property/specify-property-value/search-date-value/search-date-value.component.spec.ts
  25. +73 −0 ...on/search-select-property/specify-property-value/search-date-value/search-date-value.component.ts
  26. +5 −0 ...h-select-property/specify-property-value/search-decimal-value/search-decimal-value.component.html
  27. 0 ...h-select-property/specify-property-value/search-decimal-value/search-decimal-value.component.scss
  28. +88 −0 ...elect-property/specify-property-value/search-decimal-value/search-decimal-value.component.spec.ts
  29. +53 −0 ...rch-select-property/specify-property-value/search-decimal-value/search-decimal-value.component.ts
  30. +5 −0 ...on/search-select-property/specify-property-value/search-int-value/search-int-value.component.html
  31. 0 ...on/search-select-property/specify-property-value/search-int-value/search-int-value.component.scss
  32. +80 −0 ...search-select-property/specify-property-value/search-int-value/search-int-value.component.spec.ts
  33. +54 −0 ...tion/search-select-property/specify-property-value/search-int-value/search-int-value.component.ts
  34. +11 −0 .../search-select-property/specify-property-value/search-link-value/search-link-value.component.html
  35. 0 .../search-select-property/specify-property-value/search-link-value/search-link-value.component.scss
  36. +154 −0 ...arch-select-property/specify-property-value/search-link-value/search-link-value.component.spec.ts
  37. +129 −0 ...on/search-select-property/specify-property-value/search-link-value/search-link-value.component.ts
  38. +16 −0 ...y/specify-property-value/search-list-value/search-display-list/search-display-list.component.html
  39. 0 ...y/specify-property-value/search-list-value/search-display-list/search-display-list.component.scss
  40. +110 −0 ...pecify-property-value/search-list-value/search-display-list/search-display-list.component.spec.ts
  41. +25 −0 ...rty/specify-property-value/search-list-value/search-display-list/search-display-list.component.ts
  42. +32 −0 .../search-select-property/specify-property-value/search-list-value/search-list-value.component.html
  43. +3 −0 .../search-select-property/specify-property-value/search-list-value/search-list-value.component.scss
  44. +164 −0 ...arch-select-property/specify-property-value/search-list-value/search-list-value.component.spec.ts
  45. +102 −0 ...on/search-select-property/specify-property-value/search-list-value/search-list-value.component.ts
  46. +5 −0 .../search-select-property/specify-property-value/search-text-value/search-text-value.component.html
  47. 0 .../search-select-property/specify-property-value/search-text-value/search-text-value.component.scss
  48. +79 −0 ...arch-select-property/specify-property-value/search-text-value/search-text-value.component.spec.ts
  49. +52 −0 ...on/search-select-property/specify-property-value/search-text-value/search-text-value.component.ts
  50. +5 −0 ...on/search-select-property/specify-property-value/search-uri-value/search-uri-value.component.html
  51. 0 ...on/search-select-property/specify-property-value/search-uri-value/search-uri-value.component.scss
  52. +80 −0 ...search-select-property/specify-property-value/search-uri-value/search-uri-value.component.spec.ts
  53. +55 −0 ...tion/search-select-property/specify-property-value/search-uri-value/search-uri-value.component.ts
  54. +33 −0 ...rty-selection/search-select-property/specify-property-value/specify-property-value.component.html
  55. +3 −0 ...rty-selection/search-select-property/specify-property-value/specify-property-value.component.scss
  56. +375 −0 ...-selection/search-select-property/specify-property-value/specify-property-value.component.spec.ts
  57. +189 −0 ...perty-selection/search-select-property/specify-property-value/specify-property-value.component.ts
  58. +10 −0 ...e-and-property-selection/search-select-resource-class/search-select-resource-class.component.html
  59. +3 −0 ...e-and-property-selection/search-select-resource-class/search-select-resource-class.component.scss
  60. +204 −0 ...nd-property-selection/search-select-resource-class/search-select-resource-class.component.spec.ts
  61. +113 −0 ...rce-and-property-selection/search-select-resource-class/search-select-resource-class.component.ts
  62. +7 −0 ...app/workspace/search/advanced-search/search-select-ontology/search-select-ontology.component.html
  63. 0 ...app/workspace/search/advanced-search/search-select-ontology/search-select-ontology.component.scss
  64. +144 −0 .../workspace/search/advanced-search/search-select-ontology/search-select-ontology.component.spec.ts
  65. +49 −0 src/app/workspace/search/advanced-search/search-select-ontology/search-select-ontology.component.ts
  66. +28 −0 src/app/workspace/search/expert-search/expert-search.component.html
  67. +35 −0 src/app/workspace/search/expert-search/expert-search.component.scss
  68. +254 −0 src/app/workspace/search/expert-search/expert-search.component.spec.ts
  69. +141 −0 src/app/workspace/search/expert-search/expert-search.component.ts
  70. +143 −0 src/app/workspace/search/fulltext-search/fulltext-search.component.html
  71. +288 −0 src/app/workspace/search/fulltext-search/fulltext-search.component.scss
  72. +332 −0 src/app/workspace/search/fulltext-search/fulltext-search.component.spec.ts
  73. +428 −0 src/app/workspace/search/fulltext-search/fulltext-search.component.ts
  74. +42 −0 src/app/workspace/search/search-panel/search-panel.component.html
  75. +34 −0 src/app/workspace/search/search-panel/search-panel.component.scss
  76. +75 −0 src/app/workspace/search/search-panel/search-panel.component.spec.ts
  77. +143 −0 src/app/workspace/search/search-panel/search-panel.component.ts
  78. 0 src/app/{ → workspace}/search/services/advanced-search-params.service.spec.ts
  79. 0 src/app/{ → workspace}/search/services/advanced-search-params.service.ts
  80. +1,150 −0 src/app/workspace/search/services/gravsearch-generation.service.spec.ts
  81. +251 −0 src/app/workspace/search/services/gravsearch-generation.service.ts
  82. +162 −0 src/assets/style/_search.scss
@@ -1,3 +1,4 @@
/* eslint-disable max-len */
import { ClipboardModule } from '@angular/cdk/clipboard';
import { CommonModule } from '@angular/common';
import { HttpClient, HttpClientModule } from '@angular/common/http';
@@ -147,6 +148,24 @@ import { ListViewComponent } from './workspace/results/list-view/list-view.compo
import { ResourceGridComponent } from './workspace/results/list-view/resource-grid/resource-grid.component';
import { ResourceListComponent } from './workspace/results/list-view/resource-list/resource-list.component';
import { ComparisonComponent } from './workspace/comparison/comparison.component';
import { SearchPanelComponent } from './workspace/search/search-panel/search-panel.component';
import { FulltextSearchComponent } from './workspace/search/fulltext-search/fulltext-search.component';
import { ExpertSearchComponent } from './workspace/search/expert-search/expert-search.component';
import { AdvancedSearchComponent } from './workspace/search/advanced-search/advanced-search.component';
import { SearchBooleanValueComponent } from './workspace/search/advanced-search/resource-and-property-selection/search-select-property/specify-property-value/search-boolean-value/search-boolean-value.component';
import { SearchDateValueComponent } from './workspace/search/advanced-search/resource-and-property-selection/search-select-property/specify-property-value/search-date-value/search-date-value.component';
import { SearchDecimalValueComponent } from './workspace/search/advanced-search/resource-and-property-selection/search-select-property/specify-property-value/search-decimal-value/search-decimal-value.component';
import { SearchIntValueComponent } from './workspace/search/advanced-search/resource-and-property-selection/search-select-property/specify-property-value/search-int-value/search-int-value.component';
import { SearchLinkValueComponent } from './workspace/search/advanced-search/resource-and-property-selection/search-select-property/specify-property-value/search-link-value/search-link-value.component';
import { SearchListValueComponent } from './workspace/search/advanced-search/resource-and-property-selection/search-select-property/specify-property-value/search-list-value/search-list-value.component';
import { SearchDisplayListComponent } from './workspace/search/advanced-search/resource-and-property-selection/search-select-property/specify-property-value/search-list-value/search-display-list/search-display-list.component';
import { SearchTextValueComponent } from './workspace/search/advanced-search/resource-and-property-selection/search-select-property/specify-property-value/search-text-value/search-text-value.component';
import { SearchUriValueComponent } from './workspace/search/advanced-search/resource-and-property-selection/search-select-property/specify-property-value/search-uri-value/search-uri-value.component';
import { SpecifyPropertyValueComponent } from './workspace/search/advanced-search/resource-and-property-selection/search-select-property/specify-property-value/specify-property-value.component';
import { ResourceAndPropertySelectionComponent } from './workspace/search/advanced-search/resource-and-property-selection/resource-and-property-selection.component';
import { SearchSelectPropertyComponent } from './workspace/search/advanced-search/resource-and-property-selection/search-select-property/search-select-property.component';
import { SearchSelectResourceClassComponent } from './workspace/search/advanced-search/resource-and-property-selection/search-select-resource-class/search-select-resource-class.component';
import { SearchSelectOntologyComponent } from './workspace/search/advanced-search/search-select-ontology/search-select-ontology.component';

// translate: AoT requires an exported function for factories
export function httpLoaderFactory(httpClient: HttpClient) {
@@ -278,6 +297,24 @@ export function httpLoaderFactory(httpClient: HttpClient) {
ResourceGridComponent,
ResourceListComponent,
ComparisonComponent,
SearchPanelComponent,
FulltextSearchComponent,
ExpertSearchComponent,
AdvancedSearchComponent,
SearchBooleanValueComponent,
SearchDateValueComponent,
SearchDecimalValueComponent,
SearchIntValueComponent,
SearchLinkValueComponent,
SearchListValueComponent,
SearchDisplayListComponent,
SearchTextValueComponent,
SearchUriValueComponent,
SpecifyPropertyValueComponent,
ResourceAndPropertySelectionComponent,
SearchSelectPropertyComponent,
SearchSelectResourceClassComponent,
SearchSelectOntologyComponent,
],
imports: [
AppRoutingModule,
@@ -7,7 +7,7 @@ import { MatSnackBarModule } from '@angular/material/snack-bar';
import { CountQueryResponse, IFulltextSearchParams, MockResource, ReadResourceSequence, SearchEndpointV2 } from '@dasch-swiss/dsp-js';
import { of } from 'rxjs';
import { DspApiConnectionToken } from 'src/app/main/declarations/dsp-api-tokens';
import { AdvancedSearchParams, AdvancedSearchParamsService } from '../../../search/services/advanced-search-params.service';
import { AdvancedSearchParams, AdvancedSearchParamsService } from '../../search/services/advanced-search-params.service';
import { ListViewComponent, SearchParams } from './list-view.component';

/**
@@ -3,7 +3,7 @@ import { PageEvent } from '@angular/material/paginator';
import { ApiResponseError, CountQueryResponse, IFulltextSearchParams, KnoraApiConnection, ReadResourceSequence } from '@dasch-swiss/dsp-js';
import { DspApiConnectionToken } from 'src/app/main/declarations/dsp-api-tokens';
import { NotificationService } from 'src/app/main/services/notification.service';
import { AdvancedSearchParamsService } from '../../../search/services/advanced-search-params.service';
import { AdvancedSearchParamsService } from '../../search/services/advanced-search-params.service';

/**
* query: search query. It can be gravserch query or fulltext string query.
@@ -0,0 +1,23 @@
<form *ngIf="!errorMessage" [formGroup]="form" (ngSubmit)="submit()" class="dsp-form-content">

<div *ngIf="ontologiesMetadata?.ontologies.length > 0">
<app-search-select-ontology [formGroup]="form" [ontologiesMetadata]="ontologiesMetadata"
(ontologySelected)="setActiveOntology($event)"></app-search-select-ontology>
</div>

<app-resource-and-property-selection *ngIf="activeOntology !== undefined" #resAndPropSel [formGroup]="form" [activeOntology]="activeOntology" [topLevel]="true">
</app-resource-and-property-selection>

<div class="dsp-form-action">
<button class="reset" mat-button type="button" (click)="resourceAndPropertySelection?.resetForm()" [disabled]="this.activeOntology === undefined">
Reset
</button>
<span class="fill-remaining-space"></span>
<button class="advanced-search-button" mat-raised-button color="primary" type="submit" [disabled]="!formValid">
Search
</button>
</div>

</form>

<app-message *ngIf="errorMessage" [apiError]="errorMessage" [size]="'medium'"></app-message>
@@ -0,0 +1,179 @@
import { HarnessLoader } from '@angular/cdk/testing';
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
import { Component, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core';
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { FormGroup, ReactiveFormsModule } from '@angular/forms';
import { MatIconModule } from '@angular/material/icon';
import { MatSnackBarModule } from '@angular/material/snack-bar';
import { By } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { OntologiesEndpointV2, OntologiesMetadata, OntologyMetadata } from '@dasch-swiss/dsp-js';
import { of } from 'rxjs';
import { DspApiConnectionToken } from 'src/app/main/declarations/dsp-api-tokens';
import { AdvancedSearchComponent } from './advanced-search.component';

/**
* test component to simulate select ontology component.
*/
@Component({
selector: 'app-search-select-ontology',
template: ''
})
class TestSearchSelectOntologyComponent implements OnInit {

@Input() formGroup: FormGroup;

@Input() ontologiesMetadata: OntologiesMetadata;

@Output() ontologySelected = new EventEmitter<string>();

ngOnInit() {

}

}

/**
* test component to simulate select resource class and property component.
*/
@Component({
selector: 'app-resource-and-property-selection',
template: ''
})
class TestSelectResourceClassAndPropertyComponent {

@Input() formGroup: FormGroup;

@Input() activeOntology: string;

@Input() resClassRestriction?: string;

@Input() topLevel: boolean;

}

/**
* test host component to simulate parent component.
*/
@Component({
template: `
<app-advanced-search #advSearch></app-advanced-search>`
})
class TestHostComponent implements OnInit {

@ViewChild('advSearch') advancedSearch: AdvancedSearchComponent;

ngOnInit() {
}

}

describe('AdvancedSearchComponent', () => {
let testHostComponent: TestHostComponent;
let testHostFixture: ComponentFixture<TestHostComponent>;

let loader: HarnessLoader;

beforeEach(waitForAsync(() => {

const dspConnSpy = {
v2: {
onto: jasmine.createSpyObj('onto', ['getOntologiesMetadata'])
}
};

TestBed.configureTestingModule({
declarations: [
AdvancedSearchComponent,
TestHostComponent,
TestSearchSelectOntologyComponent,
TestSelectResourceClassAndPropertyComponent
],
imports: [
ReactiveFormsModule,
BrowserAnimationsModule,
MatIconModule,
MatSnackBarModule
],
providers: [
{
provide: DspApiConnectionToken,
useValue: dspConnSpy
}
]
})
.compileComponents();
}));

describe('Ontology with resources', () => {
beforeEach(() => {

const dspConnSpy = TestBed.inject(DspApiConnectionToken);

(dspConnSpy.v2.onto as jasmine.SpyObj<OntologiesEndpointV2>).getOntologiesMetadata.and.callFake(
() => {

const ontoMetadata = new OntologiesMetadata();

const anythingOnto = new OntologyMetadata();
anythingOnto.id = 'anyid';
anythingOnto.label = 'anythingOnto';

ontoMetadata.ontologies = [anythingOnto];

return of(ontoMetadata);
}
);

testHostFixture = TestBed.createComponent(TestHostComponent);
testHostComponent = testHostFixture.componentInstance;

loader = TestbedHarnessEnvironment.loader(testHostFixture);

testHostFixture.detectChanges();
});

it('should create', () => {

expect(testHostComponent).toBeTruthy();
expect(testHostComponent.advancedSearch).toBeTruthy();

});

it('should get ontologies metadata on init', () => {

const dspConnSpy = TestBed.inject(DspApiConnectionToken);

expect(testHostComponent.advancedSearch.ontologiesMetadata).toBeDefined();
expect(testHostComponent.advancedSearch.ontologiesMetadata.ontologies.length).toEqual(1);

const hostCompDe = testHostFixture.debugElement;
const selectOntoComp = hostCompDe.query(By.directive(TestSearchSelectOntologyComponent));

expect((selectOntoComp.componentInstance as TestSearchSelectOntologyComponent).ontologiesMetadata).toBeDefined();
expect((selectOntoComp.componentInstance as TestSearchSelectOntologyComponent).ontologiesMetadata.ontologies.length).toEqual(1);

expect(dspConnSpy.v2.onto.getOntologiesMetadata).toHaveBeenCalledTimes(1);

expect((selectOntoComp.componentInstance as TestSearchSelectOntologyComponent).formGroup).toBeDefined();

});

it('should set the active ontology when an ontology is selected', () => {

const hostCompDe = testHostFixture.debugElement;
const selectOntoComp = hostCompDe.query(By.directive(TestSearchSelectOntologyComponent));

(selectOntoComp.componentInstance as TestSearchSelectOntologyComponent).ontologySelected.emit('http://0.0.0.0:3333/ontology/0001/anything/v2');

testHostFixture.detectChanges();

expect(testHostComponent.advancedSearch.activeOntology).toEqual('http://0.0.0.0:3333/ontology/0001/anything/v2');

expect(testHostComponent.advancedSearch.resourceAndPropertySelection.activeOntology).toEqual('http://0.0.0.0:3333/ontology/0001/anything/v2');

});

});

});
Loading

0 comments on commit fc7ea5c

Please sign in to comment.