Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(resource): new date picker (DEV-112) #532

Merged
merged 45 commits into from Oct 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
23a097c
refactor(app): sort imports
kilchenmann Sep 10, 2021
b298877
feat(resource): init new date picker
kilchenmann Sep 10, 2021
aca3ed5
style(date): display a date period in a different way
kilchenmann Sep 10, 2021
4d30663
style(date): overwrite material style
kilchenmann Sep 10, 2021
5fd9e86
style(date): clean up style in date picker
kilchenmann Sep 11, 2021
974809c
refactor(date): make lint happy
kilchenmann Sep 11, 2021
c096656
chore(date): no console error in case of missing date
kilchenmann Sep 12, 2021
e7d3fc9
feat(date): real date picker with islamic calendar support
kilchenmann Sep 12, 2021
90a8c3b
feat(date): get current day in all calendars
kilchenmann Sep 12, 2021
9ed150c
style(date): better date formatting
kilchenmann Sep 24, 2021
137dd1b
feat(date): another date picker
kilchenmann Sep 24, 2021
fec5862
feat(date): using new date picker
kilchenmann Sep 24, 2021
5a87a29
refactor(date): remove previous date picker
kilchenmann Sep 24, 2021
23b21a0
Merge branch 'main' into wip/dsp-1769-date-picker
kilchenmann Sep 24, 2021
b0285d3
fix(app): add date picker
kilchenmann Sep 24, 2021
57ee26e
feat(date): update value
kilchenmann Sep 27, 2021
dba2953
feat(date): create new value
kilchenmann Sep 27, 2021
b0bb4ed
refactor(date): clean up code
kilchenmann Sep 27, 2021
414996c
refactor(date): make tslint happy
kilchenmann Sep 27, 2021
fa4776d
feat(date): display date
kilchenmann Sep 27, 2021
5e593a7
test(date): fix date pipe test
kilchenmann Sep 27, 2021
27cc517
test(date): fix tests of new date picker
kilchenmann Sep 28, 2021
1b2286c
test(date): fix tests of new date picker
kilchenmann Oct 5, 2021
c20596d
Merge branch 'main' into wip/dsp-1769-date-picker
kilchenmann Oct 5, 2021
926b9bb
refactor(resource): remove unnecessary console.log
kilchenmann Oct 5, 2021
94d7407
style(date): display date in a nice way
kilchenmann Oct 5, 2021
9ebdf11
fix(date): fix date picker close process
kilchenmann Oct 5, 2021
ccc7970
feat(date): new date value handler for periods
kilchenmann Oct 5, 2021
d6b9610
feat(date): handle period date values
kilchenmann Oct 5, 2021
c2ab6b2
fix(date): date picker for single date and date range
kilchenmann Oct 6, 2021
a9251b1
test(date): fix test in new date value comp
kilchenmann Oct 6, 2021
7f258de
test(date): fix knora date pipe
kilchenmann Oct 6, 2021
86454c7
test(date): add tests and fix issues
kilchenmann Oct 6, 2021
afca80b
fix(date): fix issue in date-picker
kilchenmann Oct 7, 2021
6c5f932
feat(date): use new date picker in res instance form
kilchenmann Oct 7, 2021
317ea05
test(date): more tests in date value handler
kilchenmann Oct 7, 2021
1cd915a
style(date): clean up date picker design
kilchenmann Oct 8, 2021
525db9e
Merge branch 'main' into wip/dsp-1769-date-picker
kilchenmann Oct 8, 2021
64b74f0
fix(date): disable period toggle button if start date is not valid
kilchenmann Oct 8, 2021
c83fafb
chore(date): do not predefine date in end date
kilchenmann Oct 8, 2021
e5e3da3
feat(search): use date picker in advanced search
kilchenmann Oct 13, 2021
18c8e4b
refactor(value): clean up code
kilchenmann Oct 13, 2021
966e8f0
fix(date): resolve ngAfterViewChecked issue
kilchenmann Oct 13, 2021
1b55e75
Merge branch 'main' into wip/dsp-1769-date-picker
kilchenmann Oct 13, 2021
03ca930
Merge branch 'main' into wip/dsp-1769-date-picker
kilchenmann Oct 14, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/app/app.module.ts
Expand Up @@ -138,6 +138,9 @@ import { TextValueAsXMLComponent } from './workspace/resource/values/text-value/
import { TimeInputComponent } from './workspace/resource/values/time-value/time-input/time-input.component';
import { TimeValueComponent } from './workspace/resource/values/time-value/time-value.component';
import { UriValueComponent } from './workspace/resource/values/uri-value/uri-value.component';
import { DatePickerComponent } from './workspace/resource/values/yet-another-date-value/date-picker/date-picker.component';
import { DateValueHandlerComponent } from './workspace/resource/values/yet-another-date-value/date-value-handler/date-value-handler.component';
import { YetAnotherDateValueComponent } from './workspace/resource/values/yet-another-date-value/yet-another-date-value.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';
Expand All @@ -152,6 +155,7 @@ import { SearchIntValueComponent } from './workspace/search/advanced-search/reso
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 { 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 { SearchListValueComponent } from './workspace/search/advanced-search/resource-and-property-selection/search-select-property/specify-property-value/search-list-value/search-list-value.component';
import { SearchResourceComponent } from './workspace/search/advanced-search/resource-and-property-selection/search-select-property/specify-property-value/search-resource/search-resource.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';
Expand All @@ -160,7 +164,6 @@ import { SearchSelectOntologyComponent } from './workspace/search/advanced-searc
import { ExpertSearchComponent } from './workspace/search/expert-search/expert-search.component';
import { FulltextSearchComponent } from './workspace/search/fulltext-search/fulltext-search.component';
import { SearchPanelComponent } from './workspace/search/search-panel/search-panel.component';
import { SearchResourceComponent } from './workspace/search/advanced-search/resource-and-property-selection/search-select-property/specify-property-value/search-resource/search-resource.component';

// translate: AoT requires an exported function for factories
export function httpLoaderFactory(httpClient: HttpClient) {
Expand Down Expand Up @@ -197,7 +200,9 @@ export function httpLoaderFactory(httpClient: HttpClient) {
DateEditComponent,
DateInputComponent,
DateInputTextComponent,
DatePickerComponent,
DateValueComponent,
DateValueHandlerComponent,
DecimalValueComponent,
DialogComponent,
DialogHeaderComponent,
Expand Down Expand Up @@ -273,6 +278,7 @@ export function httpLoaderFactory(httpClient: HttpClient) {
SearchLinkValueComponent,
SearchListValueComponent,
SearchPanelComponent,
SearchResourceComponent,
SearchSelectOntologyComponent,
SearchSelectPropertyComponent,
SearchSelectResourceClassComponent,
Expand Down Expand Up @@ -311,7 +317,7 @@ export function httpLoaderFactory(httpClient: HttpClient) {
UsersComponent,
UsersListComponent,
VisualizerComponent,
SearchResourceComponent,
YetAnotherDateValueComponent,
],
imports: [
AngularSplitModule.forRoot(),
Expand Down
8 changes: 4 additions & 4 deletions src/app/main/pipes/formatting/knoradate.pipe.spec.ts
Expand Up @@ -47,11 +47,11 @@ describe('KnoradatePipe', () => {

dateWithDisplayOptions = pipe.transform(date, 'dd.MM.YYYY', 'calendar');

expect(dateWithDisplayOptions).toEqual('04.07.1776 GREGORIAN');
expect(dateWithDisplayOptions).toEqual('04.07.1776 Gregorian');

dateWithDisplayOptions = pipe.transform(date, 'dd.MM.YYYY', 'all');

expect(dateWithDisplayOptions).toEqual('04.07.1776 AD GREGORIAN');
expect(dateWithDisplayOptions).toEqual('04.07.1776 Gregorian');
});

it ('should return a string with the desired display options for a date without era', () => {
Expand All @@ -63,11 +63,11 @@ describe('KnoradatePipe', () => {

dateWithDisplayOptions = pipe.transform(date, 'dd.MM.YYYY', 'calendar');

expect(dateWithDisplayOptions).toEqual('04.07.1441 ISLAMIC');
expect(dateWithDisplayOptions).toEqual('04.07.1441 Islamic');

dateWithDisplayOptions = pipe.transform(date, 'dd.MM.YYYY', 'all');

expect(dateWithDisplayOptions).toEqual('04.07.1441 ISLAMIC');
expect(dateWithDisplayOptions).toEqual('04.07.1441 Islamic');
});

it ('should return a string with only the month and the year', () => {
Expand Down
27 changes: 22 additions & 5 deletions src/app/main/pipes/formatting/knoradate.pipe.ts
Expand Up @@ -6,9 +6,9 @@ import { KnoraDate } from '@dasch-swiss/dsp-js';
})
export class KnoraDatePipe implements PipeTransform {

transform(date: KnoraDate, format?: string, displayOptions?: 'era' | 'calendar' | 'all'): string {
transform(date: KnoraDate, format?: string, displayOptions?: 'era' | 'calendar' | 'calendarOnly' | 'all'): string {
if (!(date instanceof KnoraDate)) {
console.error('Non-KnoraDate provided. Expected a valid KnoraDate');
// console.error('Non-KnoraDate provided. Expected a valid KnoraDate');
return '';
}

Expand All @@ -34,11 +34,17 @@ export class KnoraDatePipe implements PipeTransform {
addDisplayOptions(date: KnoraDate, value: string, options: string): string {
switch (options) {
case 'era':
return value + (date.era !== 'noEra' ? ' ' + date.era : '');
// displays date with era; era only in case of BCE
return value + (date.era === 'noEra' ? '' : ((date.era === 'BCE' || date.era === 'AD') ? ' ' + date.era : ''));
case 'calendar':
return value + ' ' + date.calendar;
// displays date without era but with calendar type
return value + ' ' + this._titleCase(date.calendar);
case 'calendarOnly':
// displays only the selected calendar type without any data
return this._titleCase(date.calendar);
case 'all':
return value + (date.era !== 'noEra' ? ' ' + date.era : '') + ' ' + date.calendar;
// displays date with era (only as BCE) and selected calendar type
return value + (date.era === 'noEra' ? '' : (date.era === 'BCE' ? ' ' + date.era : '')) + ' ' + this._titleCase(date.calendar);
}
}

Expand Down Expand Up @@ -79,4 +85,15 @@ export class KnoraDatePipe implements PipeTransform {
}
}

/**
* returns a string in Title Case format
* It's needed to transform a calendar name e.g. 'GREGORIAN' into 'Gregorian'
*
* @param str
* @returns string
*/
private _titleCase(str: string): string {
return str.split(' ').map(w => w[0].toUpperCase() + w.substr(1).toLowerCase()).join(' ');
}

}
Expand Up @@ -14,7 +14,7 @@
<app-geoname-value #createVal *ngSwitchCase="constants.GeonameValue" [mode]="mode"></app-geoname-value>
<app-link-value #createVal *ngSwitchCase="constants.LinkValue" [mode]="mode"
[parentResource]="parentResource" [propIri]="resourcePropertyDefinition.id"></app-link-value>
<app-date-value #createVal *ngSwitchCase="constants.DateValue" [mode]="mode"></app-date-value>
<app-yet-another-date-value #createVal *ngSwitchCase="constants.DateValue" [mode]="mode"></app-yet-another-date-value>
<app-list-value #createVal *ngSwitchCase="constants.ListValue" [mode]="mode"
[propertyDef]="resourcePropertyDefinition"></app-list-value>
</span>
Expand Down
Expand Up @@ -19,7 +19,8 @@
<app-geoname-value class="parent-value-component" #displayVal *ngSwitchCase="constants.GeonameValue" [mode]="mode" [displayValue]="$any(displayValue)"></app-geoname-value>
<app-link-value class="parent-value-component" #displayVal *ngSwitchCase="constants.LinkValue" [mode]="mode" [displayValue]="$any(displayValue)"
[parentResource]="parentResource" [propIri]="displayValue.property" (referredResourceClicked)="referredResourceClicked.emit($event)" (referredResourceHovered)="referredResourceHovered.emit($event)"></app-link-value>
<app-date-value class="parent-value-component" #displayVal *ngSwitchCase="constants.DateValue" [mode]="mode" [displayValue]="$any(displayValue)" [displayOptions]="dateDisplayOptions" [labels]="showDateLabels" [ontologyDateFormat]="dateFormat"></app-date-value>
<!-- <app-date-value class="parent-value-component" #displayVal *ngSwitchCase="constants.DateValue" [mode]="mode" [displayValue]="$any(displayValue)" [displayOptions]="dateDisplayOptions" [labels]="showDateLabels" [ontologyDateFormat]="dateFormat"></app-date-value> -->
<app-yet-another-date-value class="parent-value-component" #displayVal *ngSwitchCase="constants.DateValue" [mode]="mode" [displayValue]="$any(displayValue)" [ontologyDateFormat]="dateFormat"></app-yet-another-date-value>
<app-list-value class="parent-value-component" #displayVal *ngSwitchCase="constants.ListValue" [mode]="mode" [displayValue]="$any(displayValue)"
[propertyDef]="$any(parentResource.entityInfo.properties[displayValue.property])"></app-list-value>
<span *ngSwitchDefault>{{displayValue.strval}}</span>
Expand Down
Expand Up @@ -239,6 +239,7 @@ export class DisplayEditComponent implements OnInit {
mergeMap((res: WriteValueResponse) => this._dspApiConnection.v2.values.getValue(this.parentResource.id, res.uuid))
).subscribe(
(res2: ReadResource) => {

this._valueOperationEventService.emit(
new EmitEvent(Events.ValueUpdated, new UpdatedEventValues(
this.displayValue, res2.getValues(this.displayValue.property)[0])));
Expand Down
Expand Up @@ -444,8 +444,6 @@ describe('ResourceInstanceFormComponent', () => {

const selectOntoComp = resourceInstanceFormComponentDe.query(By.directive(MockSelectOntologyComponent));

console.log('ontos: ', (selectOntoComp.componentInstance as MockSelectOntologyComponent).ontologiesMetadata.ontologies);

expect((selectOntoComp.componentInstance as MockSelectOntologyComponent).ontologiesMetadata.ontologies.length).toEqual(11);

expect(dspConnSpy.v2.onto.getOntologiesByProjectIri).toHaveBeenCalledTimes(1);
Expand Down
Expand Up @@ -11,7 +11,7 @@
<app-geoname-value #createVal *ngSwitchCase="constants.GeonameValue" [mode]="mode" [valueRequiredValidator]="isRequiredProp" [parentForm]="parentForm" [formName]="formName"></app-geoname-value>
<app-link-value #createVal *ngSwitchCase="constants.LinkValue" [mode]="mode" [valueRequiredValidator]="isRequiredProp" [parentForm]="parentForm" [formName]="formName"
[parentResource]="parentResource" [propIri]="property.id"></app-link-value>
<app-date-value #createVal *ngSwitchCase="constants.DateValue" [mode]="mode" [valueRequiredValidator]="isRequiredProp" [parentForm]="parentForm" [formName]="formName"></app-date-value>
<app-yet-another-date-value #createVal *ngSwitchCase="constants.DateValue" [mode]="mode" [valueRequiredValidator]="isRequiredProp" [parentForm]="parentForm" [formName]="formName"></app-yet-another-date-value>
<app-list-value #createVal *ngSwitchCase="constants.ListValue" [mode]="mode" [valueRequiredValidator]="isRequiredProp" [parentForm]="parentForm" [formName]="formName"
[propertyDef]="property"></app-list-value>
<span *ngSwitchDefault>
Expand Down
Expand Up @@ -3,19 +3,19 @@
<!-- Date period -->
<span *ngIf="valueFormControl.value?.end; else date">
<span class="rm-value date-start">
<span *ngIf="labels">Period Start: </span>
<!-- <span *ngIf="labels">Period Start: </span> -->
{{valueFormControl.value?.start | knoraDate:ontologyDateFormat:displayOptions}}
</span>
<span class="rm-value date-end">
<span *ngIf="labels">Period End: </span>
<span *ngIf="labels"> &mdash; </span>
{{valueFormControl.value?.end | knoraDate:ontologyDateFormat:displayOptions}}
</span>
</span>

<!-- Only one date -->
<ng-template #date>
<span class="rm-value">
<span *ngIf="labels">Date: </span>
<!-- <span *ngIf="labels">Date: </span> -->
{{valueFormControl.value | knoraDate:ontologyDateFormat:displayOptions}}
</span>
</ng-template>
Expand Down
@@ -0,0 +1,126 @@
<div [formGroup]="dateForm" class="date-picker-container">
<mat-form-field class="hidden">
<input matInput [formControlName]="'knoraDate'" [errorStateMatcher]="matcher" readonly/>
</mat-form-field>
<mat-form-field [floatLabel]="'always'" class="child-input-component date-picker-value" [matMenuTriggerFor]="datePicker">
<mat-label>{{ calendar | titlecase }}</mat-label>
<input matInput
class="date-picker-input date"
[formControlName]="'date'"
placeholder="Click to select a date"
autocomplete="off"
readonly />
<mat-icon matSuffix class="link">event</mat-icon>
<!-- <mat-error *ngIf="dateForm.controls.date.hasError('required')">
Date is <strong>required</strong>
</mat-error> -->
</mat-form-field>
</div>


<!-- <mat-form-field class="date" [matMenuTriggerFor]="datePicker">
<mat-label>{{calendar}} {{era}}</mat-label>
<input matInput class="link" autocomplete="off" readonly placeholder="dd/mm/yyyy or mm/yyyy or yyyy" [value]="date | knoraDate">
<mat-icon matSuffix class="link">event</mat-icon>
</mat-form-field> -->
<!-- <button mat-button [matMenuTriggerFor]="menu">Menu</button> -->
<mat-menu #datePicker="matMenu" [formGroup]="form" class="date-picker">

<div class="date-picker-content" (click)="$event.stopPropagation()" (keydown)="$event.stopPropagation()">


<!-- select calendar and button to close date picker -->
<div class="calendar-selector panel">
<mat-form-field class="calendar" floatLabel="never">
<mat-label>Calendar</mat-label>
<mat-select formControlName="calendar" class="center">
<mat-option *ngFor="let cal of calendars; let i = index" [value]="cal">
{{cal | titlecase}}
</mat-option>
</mat-select>
</mat-form-field>
<span class="fill-remaining-space"></span>
<div class="action">
<!-- go to the current date -->
<button mat-button (click)=setToday()>Today</button>
<!-- submit button (which is needed if date doesn't have precision on an exact day) -->
<button mat-icon-button color="primary" [disabled]="!form.valid" (click)="setDate(day); closeDatePicker()">
<mat-icon>done</mat-icon>
</button>
</div>
</div>

<!-- panel with month (incl. navigation), year and era -->
<div class="month-year-selector panel">
<!-- select month -->
<mat-form-field class="month" floatLabel="never" [class.larger]="calendar === 'ISLAMIC'">
<mat-label>Month</mat-label>
<mat-select formControlName="month" class="center">
<mat-option>-- None --</mat-option>
<mat-option *ngFor="let month of months; let i = index" [value]="i + 1">
<span *ngIf="calendar !== 'ISLAMIC'">{{month[0]}}</span>
<span *ngIf="calendar === 'ISLAMIC'">{{month[1]}}</span>
</mat-option>
</mat-select>
</mat-form-field>
<!-- set year incl. era -->
<mat-form-field class="year" floatLabel="never" [class.withButtonToggle]="calendar !== 'ISLAMIC'">
<mat-label>Year *</mat-label>
<input matInput type="number" formControlName="year" min="1" class="center">
<mat-error *ngIf="formErrors.year">
{{ formErrors.year }}
</mat-error>
<!-- <button mat-flat-button matSuffix (click)="switchEra()" [attr.aria-label]="'Switch era'"
[attr.aria-pressed]="ce">
{{ce ? 'CE' : 'BCE'}}
</button> -->
<mat-button-toggle-group *ngIf="calendar !== 'ISLAMIC'" class="era suffix-toggle-group" matSuffix
formControlName="era" aria-label="Define era">
<mat-button-toggle value="CE">CE</mat-button-toggle>
<mat-button-toggle value="BCE">BCE</mat-button-toggle>
</mat-button-toggle-group>
</mat-form-field>

<!-- hidden slide toggle to know about era changed -->
<!-- <mat-slide-toggle formControlName="era">CE</mat-slide-toggle> -->
</div>

<!-- select day -->
<div class="day-selector panel" [class.disabled]="disableDaySelector">

<div>
<p *ngIf="era === 'CE'" class="week-days">
<span *ngFor="let d of weekDays" class="day">{{d}}</span>
</p>
<p *ngIf="era === 'BCE'" class="mat-caption center">
<!-- <mat-icon>warn</mat-icon> -->
Attention: Date <strong>before common era</strong>.
</p>
</div>
<div *ngFor="let week of weeks; let last = last" class="week">
<span *ngFor="let d of week" class="day" [class.selected]="d === day">
<!-- the following span is only a placeholder to set the position of the first day to the correct column-->
<span *ngIf="d === 0"></span>
<span *ngIf="d > 0" class="selectable link" [class.disabled]="disableDaySelector"
(click)="!disableDaySelector && setDate(d); closeDatePicker()">{{d}}</span>
</span>
<!-- add not interested button at the end, if you want precision on year and month only -->
<span *ngIf="(last && week.length < 7)" class="day">
<span class="selectable link" [class.disabled]="disableDaySelector" (click)="!disableDaySelector && setDate(); closeDatePicker()">
<mat-icon>not_interested</mat-icon>
</span>
</span>
</div>
<!-- add not interested button at the end, if you want precision on year and month only;
if the month ends on a Sunday, we have to add an additional line to get the not-interested option -->
<div class="week" *ngIf="weeks[weeks.length - 1].length === 7">
<span class="day">
<span class="selectable link" [class.disabled]="disableDaySelector" (click)="!disableDaySelector && setDate(); closeDatePicker()">
<mat-icon>not_interested</mat-icon>
</span>
</span>
</div>
</div>
</div>

</mat-menu>