Skip to content
Permalink
Browse files
refactor(resource): migrate viewer from UI-lib (DSP-1850) (#504)
* refactor(resource): migrates directives from ui-lib to resources directory

* refactor(resource): migrates services from ui-lib to resources directory

* refactor(viewer): migrates:
 - boolean-value comp
 - color-value comp
 - date-value comp
 - jdndatepicker directive
 - custom-regex
 - value-error-state-matcher

* fix: adds ColorPickerModule to AppModule imports

* refactor(viewer): migrates:
 - decimal-value comp
 - geoname-value comp
 - int-value comp
 - interval-value comp
 - link-value comp
 - list-value comp
 - text-value comp
 - time-value comp
 - uri-value comp

* refactor(viewer): migrates operations components from viewer module

* fix(github-ci): specify timezone for unit tests

* refactor(viewer): migrates list-view comp

* fix: fix app.module imports

* chore(workspace): move multiple-resource-view from dsp-ui (DSP-1857)

Co-authored-by: André Kilchenmann <github@milchkannen.ch>
  • Loading branch information
mdelez and kilchenmann committed Aug 31, 2021
1 parent 725c45e commit b742a987e2293bdc18bcf14e1b1174ee1f5c8180
Showing with 18,795 additions and 20 deletions.
  1. +2 −0 .github/workflows/main.yml
  2. +7 −8 package-lock.json
  3. +66 −0 src/app/app.module.ts
  4. +49 −8 src/app/main/directive/base-value.directive.ts
  5. +48 −0 src/app/search/services/advanced-search-params.service.spec.ts
  6. +53 −0 src/app/search/services/advanced-search-params.service.ts
  7. +20 −0 src/app/workspace/comparison/comparison.component.html
  8. +4 −0 src/app/workspace/comparison/comparison.component.scss
  9. +74 −0 src/app/workspace/comparison/comparison.component.spec.ts
  10. +55 −0 src/app/workspace/comparison/comparison.component.ts
  11. +124 −0 src/app/workspace/resource/directives/drag-drop.directive.spec.ts
  12. +34 −0 src/app/workspace/resource/directives/drag-drop.directive.ts
  13. +134 −0 src/app/workspace/resource/directives/text-value-html-link.directive.spec.ts
  14. +44 −0 src/app/workspace/resource/directives/text-value-html-link.directive.ts
  15. +38 −0 src/app/workspace/resource/operations/add-value/add-value.component.html
  16. +1 −0 src/app/workspace/resource/operations/add-value/add-value.component.scss
  17. +322 −0 src/app/workspace/resource/operations/add-value/add-value.component.spec.ts
  18. +159 −0 src/app/workspace/resource/operations/add-value/add-value.component.ts
  19. +76 −0 src/app/workspace/resource/operations/display-edit/display-edit.component.html
  20. +1 −0 src/app/workspace/resource/operations/display-edit/display-edit.component.scss
  21. +1,199 −0 src/app/workspace/resource/operations/display-edit/display-edit.component.spec.ts
  22. +396 −0 src/app/workspace/resource/operations/display-edit/display-edit.component.ts
  23. +9 −1 src/app/workspace/resource/properties/properties.component.ts
  24. +1 −1 src/app/workspace/resource/representation/upload/upload.component.html
  25. +370 −0 src/app/workspace/resource/services/geoname.service.spec.ts
  26. +126 −0 src/app/workspace/resource/services/geoname.service.ts
  27. +100 −0 src/app/workspace/resource/services/upload-file.service.spec.ts
  28. +46 −0 src/app/workspace/resource/services/upload-file.service.ts
  29. +49 −0 src/app/workspace/resource/services/user.service.spec.ts
  30. +28 −0 src/app/workspace/resource/services/user.service.ts
  31. +57 −0 src/app/workspace/resource/services/value-operation-event.service.spec.ts
  32. +68 −0 src/app/workspace/resource/services/value-operation-event.service.ts
  33. +334 −0 src/app/workspace/resource/services/value.service.spec.ts
  34. +215 −0 src/app/workspace/resource/services/value.service.ts
  35. +27 −0 src/app/workspace/resource/values/boolean-value/boolean-value.component.html
  36. +1 −0 src/app/workspace/resource/values/boolean-value/boolean-value.component.scss
  37. +350 −0 src/app/workspace/resource/values/boolean-value/boolean-value.component.spec.ts
  38. +123 −0 src/app/workspace/resource/values/boolean-value/boolean-value.component.ts
  39. +22 −0 src/app/workspace/resource/values/color-value/color-picker/color-picker.component.html
  40. +3 −0 src/app/workspace/resource/values/color-value/color-picker/color-picker.component.scss
  41. +98 −0 src/app/workspace/resource/values/color-value/color-picker/color-picker.component.spec.ts
  42. +187 −0 src/app/workspace/resource/values/color-value/color-picker/color-picker.component.ts
  43. +43 −0 src/app/workspace/resource/values/color-value/color-value.component.html
  44. +25 −0 src/app/workspace/resource/values/color-value/color-value.component.scss
  45. +463 −0 src/app/workspace/resource/values/color-value/color-value.component.spec.ts
  46. +159 −0 src/app/workspace/resource/values/color-value/color-value.component.ts
  47. +27 −0 src/app/workspace/resource/values/custom-regex.ts
  48. +4 −0 src/app/workspace/resource/values/date-value/calendar-header/calendar-header.component.html
  49. +6 −0 src/app/workspace/resource/values/date-value/calendar-header/calendar-header.component.scss
  50. +149 −0 src/app/workspace/resource/values/date-value/calendar-header/calendar-header.component.spec.ts
  51. +85 −0 src/app/workspace/resource/values/date-value/calendar-header/calendar-header.component.ts
  52. +41 −0 src/app/workspace/resource/values/date-value/date-input-text/date-edit/date-edit.component.html
  53. +9 −0 src/app/workspace/resource/values/date-value/date-input-text/date-edit/date-edit.component.scss
  54. +498 −0 src/app/workspace/resource/values/date-value/date-input-text/date-edit/date-edit.component.spec.ts
  55. +389 −0 src/app/workspace/resource/values/date-value/date-input-text/date-edit/date-edit.component.ts
  56. +51 −0 src/app/workspace/resource/values/date-value/date-input-text/date-input-text.component.html
  57. +17 −0 src/app/workspace/resource/values/date-value/date-input-text/date-input-text.component.scss
  58. +423 −0 src/app/workspace/resource/values/date-value/date-input-text/date-input-text.component.spec.ts
  59. +308 −0 src/app/workspace/resource/values/date-value/date-input-text/date-input-text.component.ts
  60. +50 −0 src/app/workspace/resource/values/date-value/date-input/date-input.component.html
  61. +18 −0 src/app/workspace/resource/values/date-value/date-input/date-input.component.scss
  62. +341 −0 src/app/workspace/resource/values/date-value/date-input/date-input.component.spec.ts
  63. +350 −0 src/app/workspace/resource/values/date-value/date-input/date-input.component.ts
  64. +57 −0 src/app/workspace/resource/values/date-value/date-value.component.html
  65. +17 −0 src/app/workspace/resource/values/date-value/date-value.component.scss
  66. +652 −0 src/app/workspace/resource/values/date-value/date-value.component.spec.ts
  67. +199 −0 src/app/workspace/resource/values/date-value/date-value.component.ts
  68. +36 −0 src/app/workspace/resource/values/decimal-value/decimal-value.component.html
  69. +1 −0 src/app/workspace/resource/values/decimal-value/decimal-value.component.scss
  70. +343 −0 src/app/workspace/resource/values/decimal-value/decimal-value.component.spec.ts
  71. +116 −0 src/app/workspace/resource/values/decimal-value/decimal-value.component.ts
  72. +43 −0 src/app/workspace/resource/values/geoname-value/geoname-value.component.html
  73. +35 −0 src/app/workspace/resource/values/geoname-value/geoname-value.component.scss
  74. +424 −0 src/app/workspace/resource/values/geoname-value/geoname-value.component.spec.ts
  75. +177 −0 src/app/workspace/resource/values/geoname-value/geoname-value.component.ts
  76. +36 −0 src/app/workspace/resource/values/int-value/int-value.component.html
  77. +17 −0 src/app/workspace/resource/values/int-value/int-value.component.scss
  78. +353 −0 src/app/workspace/resource/values/int-value/int-value.component.spec.ts
  79. +118 −0 src/app/workspace/resource/values/int-value/int-value.component.ts
  80. +20 −0 src/app/workspace/resource/values/interval-value/interval-input/interval-input.component.html
  81. +1 −0 src/app/workspace/resource/values/interval-value/interval-input/interval-input.component.scss
  82. +200 −0 src/app/workspace/resource/values/interval-value/interval-input/interval-input.component.spec.ts
  83. +236 −0 src/app/workspace/resource/values/interval-value/interval-input/interval-input.component.ts
  84. +31 −0 src/app/workspace/resource/values/interval-value/interval-value.component.html
  85. +17 −0 src/app/workspace/resource/values/interval-value/interval-value.component.scss
  86. +509 −0 src/app/workspace/resource/values/interval-value/interval-value.component.spec.ts
  87. +131 −0 src/app/workspace/resource/values/interval-value/interval-value.component.ts
  88. +116 −0 src/app/workspace/resource/values/jdn-datepicker-directive/jdndatepicker.directive.spec.ts
  89. +48 −0 src/app/workspace/resource/values/jdn-datepicker-directive/jdndatepicker.directive.ts
  90. +39 −0 src/app/workspace/resource/values/link-value/link-value.component.html
  91. +1 −0 src/app/workspace/resource/values/link-value/link-value.component.scss
  92. +643 −0 src/app/workspace/resource/values/link-value/link-value.component.spec.ts
  93. +206 −0 src/app/workspace/resource/values/link-value/link-value.component.ts
  94. +54 −0 src/app/workspace/resource/values/list-value/list-value.component.html
  95. +1 −0 src/app/workspace/resource/values/list-value/list-value.component.scss
  96. +291 −0 src/app/workspace/resource/values/list-value/list-value.component.spec.ts
  97. +167 −0 src/app/workspace/resource/values/list-value/list-value.component.ts
  98. +16 −0 src/app/workspace/resource/values/list-value/subList-value/sublist-value.component.html
  99. 0 src/app/workspace/resource/values/list-value/subList-value/sublist-value.component.scss
  100. +166 −0 src/app/workspace/resource/values/list-value/subList-value/sublist-value.component.spec.ts
  101. +23 −0 src/app/workspace/resource/values/list-value/subList-value/sublist-value.component.ts
  102. +4 −0 src/app/workspace/resource/values/text-value/text-value-as-html/text-value-as-html.component.html
  103. +1 −0 src/app/workspace/resource/values/text-value/text-value-as-html/text-value-as-html.component.scss
  104. +147 −0 src/app/workspace/resource/values/text-value/text-value-as-html/text-value-as-html.component.spec.ts
  105. +56 −0 src/app/workspace/resource/values/text-value/text-value-as-html/text-value-as-html.component.ts
  106. +33 −0 ...app/workspace/resource/values/text-value/text-value-as-string/text-value-as-string.component.html
  107. +1 −0 ...app/workspace/resource/values/text-value/text-value-as-string/text-value-as-string.component.scss
  108. +581 −0 .../workspace/resource/values/text-value/text-value-as-string/text-value-as-string.component.spec.ts
  109. +120 −0 src/app/workspace/resource/values/text-value/text-value-as-string/text-value-as-string.component.ts
  110. +36 −0 src/app/workspace/resource/values/text-value/text-value-as-xml/text-value-as-xml.component.html
  111. +5 −0 src/app/workspace/resource/values/text-value/text-value-as-xml/text-value-as-xml.component.scss
  112. +546 −0 src/app/workspace/resource/values/text-value/text-value-as-xml/text-value-as-xml.component.spec.ts
  113. +256 −0 src/app/workspace/resource/values/text-value/text-value-as-xml/text-value-as-xml.component.ts
  114. +24 −0 src/app/workspace/resource/values/time-value/time-input/time-input.component.html
  115. +1 −0 src/app/workspace/resource/values/time-value/time-input/time-input.component.scss
  116. +222 −0 src/app/workspace/resource/values/time-value/time-input/time-input.component.spec.ts
  117. +280 −0 src/app/workspace/resource/values/time-value/time-input/time-input.component.ts
  118. +31 −0 src/app/workspace/resource/values/time-value/time-value.component.html
  119. +17 −0 src/app/workspace/resource/values/time-value/time-value.component.scss
  120. +431 −0 src/app/workspace/resource/values/time-value/time-value.component.spec.ts
  121. +120 −0 src/app/workspace/resource/values/time-value/time-value.component.ts
  122. +38 −0 src/app/workspace/resource/values/uri-value/uri-value.component.html
  123. +1 −0 src/app/workspace/resource/values/uri-value/uri-value.component.scss
  124. +371 −0 src/app/workspace/resource/values/uri-value/uri-value.component.spec.ts
  125. +112 −0 src/app/workspace/resource/values/uri-value/uri-value.component.ts
  126. +9 −0 src/app/workspace/resource/values/value-error-state-matcher.ts
  127. +70 −0 src/app/workspace/results/list-view/list-view.component.html
  128. +45 −0 src/app/workspace/results/list-view/list-view.component.scss
  129. +230 −0 src/app/workspace/results/list-view/list-view.component.spec.ts
  130. +259 −0 src/app/workspace/results/list-view/list-view.component.ts
  131. +15 −0 src/app/workspace/results/list-view/list-view.service.spec.ts
  132. +85 −0 src/app/workspace/results/list-view/list-view.service.ts
  133. +38 −0 src/app/workspace/results/list-view/resource-grid/resource-grid.component.html
  134. +79 −0 src/app/workspace/results/list-view/resource-grid/resource-grid.component.scss
  135. +96 −0 src/app/workspace/results/list-view/resource-grid/resource-grid.component.spec.ts
  136. +58 −0 src/app/workspace/results/list-view/resource-grid/resource-grid.component.ts
  137. +35 −0 src/app/workspace/results/list-view/resource-list/resource-list.component.html
  138. +49 −0 src/app/workspace/results/list-view/resource-list/resource-list.component.scss
  139. +99 −0 src/app/workspace/results/list-view/resource-list/resource-list.component.spec.ts
  140. +63 −0 src/app/workspace/results/list-view/resource-list/resource-list.component.ts
  141. +2 −2 src/app/workspace/results/results.component.html
  142. +13 −0 src/assets/style/_config.scss
@@ -26,6 +26,8 @@ jobs:
run: ./find-ignored-tests.sh
- name: Run unit tests
run: npm run test-ci
env:
TZ: Europe/Zurich
- name: Run e2e tests
run: |
npm run webdriver-update

Some generated files are not rendered by default. Learn more.

@@ -114,6 +114,39 @@ import { KnoraDatePipe } from './main/pipes/formatting/knoradate.pipe';
import { LinkifyPipe } from './main/pipes/string-transformation/linkify.pipe';
import { StringifyStringLiteralPipe } from './main/pipes/string-transformation/stringify-string-literal.pipe';
import { TruncatePipe } from './main/pipes/string-transformation/truncate.pipe';
import { DragDropDirective } from './workspace/resource/directives/drag-drop.directive';
import { TextValueHtmlLinkDirective } from './workspace/resource/directives/text-value-html-link.directive';
import { BooleanValueComponent } from './workspace/resource/values/boolean-value/boolean-value.component';
import { ColorValueComponent } from './workspace/resource/values/color-value/color-value.component';
import { ColorPickerComponent } from './workspace/resource/values/color-value/color-picker/color-picker.component';
import { JDNDatepickerDirective } from './workspace/resource/values/jdn-datepicker-directive/jdndatepicker.directive';
import { DateValueComponent } from './workspace/resource/values/date-value/date-value.component';
import { CalendarHeaderComponent } from './workspace/resource/values/date-value/calendar-header/calendar-header.component';
import { DateInputComponent } from './workspace/resource/values/date-value/date-input/date-input.component';
import { DateInputTextComponent } from './workspace/resource/values/date-value/date-input-text/date-input-text.component';
import { DateEditComponent } from './workspace/resource/values/date-value/date-input-text/date-edit/date-edit.component';
import { ColorPickerModule } from 'ngx-color-picker';
import { DecimalValueComponent } from './workspace/resource/values/decimal-value/decimal-value.component';
import { GeonameValueComponent } from './workspace/resource/values/geoname-value/geoname-value.component';
import { IntValueComponent } from './workspace/resource/values/int-value/int-value.component';
import { IntervalValueComponent } from './workspace/resource/values/interval-value/interval-value.component';
import { IntervalInputComponent } from './workspace/resource/values/interval-value/interval-input/interval-input.component';
import { LinkValueComponent } from './workspace/resource/values/link-value/link-value.component';
import { ListValueComponent } from './workspace/resource/values/list-value/list-value.component';
import { SublistValueComponent } from './workspace/resource/values/list-value/subList-value/sublist-value.component';
import { TextValueAsHtmlComponent } from './workspace/resource/values/text-value/text-value-as-html/text-value-as-html.component';
import { TextValueAsStringComponent } from './workspace/resource/values/text-value/text-value-as-string/text-value-as-string.component';
import { TextValueAsXMLComponent } from './workspace/resource/values/text-value/text-value-as-xml/text-value-as-xml.component';
import { CKEditorModule } from '@ckeditor/ckeditor5-angular';
import { TimeValueComponent } from './workspace/resource/values/time-value/time-value.component';
import { TimeInputComponent } from './workspace/resource/values/time-value/time-input/time-input.component';
import { UriValueComponent } from './workspace/resource/values/uri-value/uri-value.component';
import { AddValueComponent } from './workspace/resource/operations/add-value/add-value.component';
import { DisplayEditComponent } from './workspace/resource/operations/display-edit/display-edit.component';
import { ListViewComponent } from './workspace/results/list-view/list-view.component';
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';

// translate: AoT requires an exported function for factories
export function httpLoaderFactory(httpClient: HttpClient) {
@@ -214,13 +247,46 @@ export function httpLoaderFactory(httpClient: HttpClient) {
LinkifyPipe,
StringifyStringLiteralPipe,
TruncatePipe,
DragDropDirective,
TextValueHtmlLinkDirective,
BooleanValueComponent,
ColorValueComponent,
ColorPickerComponent,
JDNDatepickerDirective,
DateValueComponent,
CalendarHeaderComponent,
DateInputComponent,
DateInputTextComponent,
DateEditComponent,
DecimalValueComponent,
GeonameValueComponent,
IntValueComponent,
IntervalValueComponent,
IntervalInputComponent,
LinkValueComponent,
ListValueComponent,
SublistValueComponent,
TextValueAsHtmlComponent,
TextValueAsStringComponent,
TextValueAsXMLComponent,
TimeValueComponent,
TimeInputComponent,
UriValueComponent,
AddValueComponent,
DisplayEditComponent,
ListViewComponent,
ResourceGridComponent,
ResourceListComponent,
ComparisonComponent,
],
imports: [
AppRoutingModule,
AngularSplitModule.forRoot(),
BrowserAnimationsModule,
BrowserModule,
CKEditorModule,
ClipboardModule,
ColorPickerModule,
CommonModule,
DspActionModule,
DspCoreModule,
@@ -6,7 +6,6 @@ import { Subscription } from 'rxjs';
@Directive()
export abstract class BaseValueDirective {


/**
* value to be displayed, if any.
*/
@@ -17,6 +16,21 @@ export abstract class BaseValueDirective {
*/
@Input() mode: 'read' | 'update' | 'create' | 'search';

/**
* parent FormGroup that contains all child FormGroups
*/
@Input() parentForm?: FormGroup;

/**
* name of the FormGroup, used to add to the parentForm because the name needs to be unique
*/
@Input() formName = 'Untitled FormGroup';

/**
* controls if the value should be required.
*/
@Input() valueRequiredValidator = true;

shouldShowComment = false;

/**
@@ -67,7 +81,7 @@ export abstract class BaseValueDirective {
=> ValidatorFn = (initValue: any, initComment: string, commentFormControl: FormControl): ValidatorFn => (control: AbstractControl): { [key: string]: any } | null => {

const invalid = this.standardValueComparisonFunc(initValue, control.value)
&& (initComment === commentFormControl.value || (initComment === null && commentFormControl.value === ''));
&& (initComment === commentFormControl.value || (initComment === null && commentFormControl.value === ''));

return invalid ? { valueNotChanged: { value: control.value } } : null;
};
@@ -107,8 +121,11 @@ export abstract class BaseValueDirective {
this.valueFormControl.setValidators([Validators.required, this.standardValidatorFunc(initialValue, initialComment, this.commentFormControl)].concat(this.customValidators));
} else {
// console.log('reset read/create validators');
this.valueFormControl.setValidators([Validators.required].concat(this.customValidators));

if (this.valueRequiredValidator) {
this.valueFormControl.setValidators([Validators.required].concat(this.customValidators));
} else {
this.valueFormControl.setValidators(this.customValidators);
}
}

this.valueFormControl.updateValueAndValidity();
@@ -138,6 +155,31 @@ export abstract class BaseValueDirective {
this.shouldShowComment = !this.shouldShowComment;
}

/**
* add the value components FormGroup to a parent FormGroup if one is defined
*/
addToParentFormGroup(name: string, form: FormGroup) {
if (this.parentForm) {
this.parentForm.addControl(name, form);
}
}

/**
* remove the value components FormGroup from a parent FormGroup if one is defined
*/
removeFromParentFormGroup(name: string) {
if (this.parentForm) {
this.parentForm.removeControl(name);
}
}

/**
* checks if the value is empty.
*/
isEmptyVal(): boolean {
return this.valueFormControl.value === null || this.valueFormControl.value === '';
}

/**
* returns the initially given value set via displayValue.
* Returns null if no value was given.
@@ -151,10 +193,9 @@ export abstract class BaseValueDirective {
abstract getNewValue(): CreateValue | false;

/**
* returns a value that is to be updated.
* Returns false if invalid.
*/
* returns a value that is to be updated.
* Returns false if invalid.
*/
abstract getUpdatedValue(): UpdateValue | false;


}
@@ -0,0 +1,48 @@
import { TestBed } from '@angular/core/testing';

import { AdvancedSearchParams, AdvancedSearchParamsService } from './advanced-search-params.service';

describe('SearchParamsService', () => {
let service: AdvancedSearchParamsService;

beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(AdvancedSearchParamsService);
});

it('should be created', () => {
expect(service).toBeTruthy();
});

it('should return false when initialized', () => {
const searchParams: AdvancedSearchParams = service.getSearchParams();

expect(searchParams.generateGravsearch(0)).toBeFalsy();
});

it('should set the parameters of an advanced search', () => {
const testMethod1 = (offset: number) => 'test1';

service.changeSearchParamsMsg(new AdvancedSearchParams(testMethod1));

const searchParams: AdvancedSearchParams = service.getSearchParams();

expect(searchParams.generateGravsearch(0)).toEqual('test1');

// check if value is still present
expect(searchParams.generateGravsearch(0)).toEqual('test1');

const testMethod2 = (offset: number) => 'test2';

service.changeSearchParamsMsg(new AdvancedSearchParams(testMethod2));

const searchParams2: AdvancedSearchParams = service.getSearchParams();

expect(searchParams2.generateGravsearch(0)).toEqual('test2');

// check if value is still present
expect(searchParams2.generateGravsearch(0)).toEqual('test2');

});

});
@@ -0,0 +1,53 @@
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs';

/*
* represents the parameters of an advanced search.
*/
export class AdvancedSearchParams {

/**
*
* @param generateGravsearch a function that generates a Gravsearch query.
*
* The function takes the offset
* as a parameter and returns a Gravsearch query string.
* Returns false if not set correctly (init state).
*/
constructor(public generateGravsearch: (offset: number) => string | boolean) {

}

}

@Injectable({
providedIn: 'root'
})
export class AdvancedSearchParamsService {

private _currentSearchParams;

constructor() {
// init with a dummy function that returns false
// if the application is reloaded, this will be returned
this._currentSearchParams = new BehaviorSubject<AdvancedSearchParams>(new AdvancedSearchParams((offset: number) => false));
}

/**
* updates the parameters of an advanced search.
*
* @param searchParams new advanced search params.
*/
changeSearchParamsMsg(searchParams: AdvancedSearchParams): void {
this._currentSearchParams.next(searchParams);
}

/**
* gets the search params of an advanced search.
*
*/
getSearchParams(): AdvancedSearchParams {
return this._currentSearchParams.getValue();
}

}
Loading

0 comments on commit b742a98

Please sign in to comment.