geonetwork-ui 2.11.0-dev.2478042b2 → 2.11.0-dev.4c200c0a1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/fesm2022/geonetwork-ui.mjs +596 -183
- package/fesm2022/geonetwork-ui.mjs.map +1 -1
- package/index.d.ts +133 -31
- package/index.d.ts.map +1 -1
- package/package.json +2 -1
- package/src/libs/api/repository/src/lib/gn4/elasticsearch/elasticsearch.service.ts +47 -7
- package/src/libs/common/domain/src/lib/model/search/filter.model.ts +13 -1
- package/src/libs/feature/map/src/lib/add-layer-from-file/add-layer-from-file.component.html +1 -0
- package/src/libs/feature/notifications/src/lib/notifications.service.ts +6 -4
- package/src/libs/feature/router/src/lib/default/state/query-params.utils.ts +1 -1
- package/src/libs/feature/search/src/lib/filter-dropdown/filter-dropdown.component.html +9 -4
- package/src/libs/feature/search/src/lib/filter-dropdown/filter-dropdown.component.ts +46 -19
- package/src/libs/feature/search/src/lib/search-filters-summary-item/search-filters-summary-item.component.ts +17 -8
- package/src/libs/feature/search/src/lib/utils/service/fields.service.ts +3 -1
- package/src/libs/feature/search/src/lib/utils/service/fields.ts +27 -2
- package/src/libs/ui/inputs/src/index.ts +2 -0
- package/src/libs/ui/inputs/src/lib/date-adapter.providers.ts +30 -0
- package/src/libs/ui/inputs/src/lib/date-picker/date-picker.component.ts +3 -24
- package/src/libs/ui/inputs/src/lib/date-range-dropdown/date-range-dropdown.component.css +37 -3
- package/src/libs/ui/inputs/src/lib/date-range-dropdown/date-range-dropdown.component.html +135 -16
- package/src/libs/ui/inputs/src/lib/date-range-dropdown/date-range-dropdown.component.ts +166 -29
- package/src/libs/ui/inputs/src/lib/date-range-picker/date-range-picker.component.ts +3 -7
- package/src/libs/ui/inputs/src/lib/drag-and-drop-file-input/drag-and-drop-file-input.component.css +1 -0
- package/src/libs/ui/inputs/src/lib/drag-and-drop-file-input/drag-and-drop-file-input.component.html +20 -7
- package/src/libs/ui/inputs/src/lib/drag-and-drop-file-input/drag-and-drop-file-input.component.ts +46 -5
- package/src/libs/ui/inputs/src/lib/dropdown-multiselect/dropdown-multiselect.component.html +1 -1
- package/src/libs/ui/inputs/src/lib/spatial-extent-dropdown/spatial-extent-dropdown.component.css +0 -0
- package/src/libs/ui/inputs/src/lib/spatial-extent-dropdown/spatial-extent-dropdown.component.html +117 -0
- package/src/libs/ui/inputs/src/lib/spatial-extent-dropdown/spatial-extent-dropdown.component.ts +191 -0
- package/src/libs/ui/map/src/lib/components/map-container/map-container.component.ts +6 -5
- package/src/libs/util/app-config/src/lib/app-config.ts +3 -0
- package/src/libs/util/app-config/src/lib/model.ts +1 -0
- package/src/libs/util/shared/src/index.ts +1 -0
- package/src/libs/util/shared/src/lib/autofocus.directive.ts +26 -0
- package/src/libs/util/shared/src/lib/services/date.service.ts +3 -3
- package/src/libs/util/shared/src/lib/utils/file.ts +15 -0
- package/src/libs/util/shared/src/lib/utils/geojson.ts +8 -0
- package/src/libs/util/shared/src/lib/utils/index.ts +1 -0
- package/tailwind.base.css +5 -0
- package/translations/de.json +12 -2
- package/translations/en.json +11 -1
- package/translations/es.json +10 -0
- package/translations/fr.json +12 -2
- package/translations/it.json +10 -0
- package/translations/nl.json +10 -0
- package/translations/pt.json +10 -0
- package/translations/sk.json +10 -0
|
@@ -18,10 +18,12 @@ export class NotificationsService {
|
|
|
18
18
|
error && console.error(error)
|
|
19
19
|
const id = Math.floor(Math.random() * 1000000)
|
|
20
20
|
this.notifications$.next([...this.notifications$.value, { ...content, id }])
|
|
21
|
-
if (typeof timeoutMs
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
if (typeof timeoutMs !== 'undefined') {
|
|
22
|
+
setTimeout(() => {
|
|
23
|
+
this.removeNotificationById(id)
|
|
24
|
+
}, timeoutMs)
|
|
25
|
+
}
|
|
26
|
+
return id
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
removeNotificationById(id: number) {
|
|
@@ -22,7 +22,7 @@ export function flattenQueryParams(
|
|
|
22
22
|
const start = (flattened[key] as DateRange).start
|
|
23
23
|
const end = (flattened[key] as DateRange).end
|
|
24
24
|
flattened[key] = [
|
|
25
|
-
`${start ? formatDate(start) : ''}..${formatDate(end)
|
|
25
|
+
`${start ? formatDate(start) : ''}..${end ? formatDate(end) : ''}`,
|
|
26
26
|
]
|
|
27
27
|
}
|
|
28
28
|
}
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
@if (fieldType === 'dateRange') {
|
|
2
2
|
<gn-ui-date-range-dropdown
|
|
3
3
|
[title]="title"
|
|
4
|
-
[
|
|
5
|
-
|
|
6
|
-
(startDateChange)="onStartDateChange($event)"
|
|
7
|
-
(endDateChange)="onEndDateChange($event)"
|
|
4
|
+
[dateRange]="(selectedDateRange$ | async) ?? {}"
|
|
5
|
+
(dateRangeChange)="onDateRangeChange($event)"
|
|
8
6
|
></gn-ui-date-range-dropdown>
|
|
7
|
+
} @else if (fieldType === 'spatialExtent') {
|
|
8
|
+
<gn-ui-spatial-extent-dropdown
|
|
9
|
+
[title]="title"
|
|
10
|
+
[maxFileSizeMb]="spatialExtentMaxFileSize"
|
|
11
|
+
(bboxChange)="onBboxChange($event)"
|
|
12
|
+
(errorChange)="onSpatialExtentError($event)"
|
|
13
|
+
></gn-ui-spatial-extent-dropdown>
|
|
9
14
|
} @else {
|
|
10
15
|
<gn-ui-dropdown-multiselect
|
|
11
16
|
class="w-full"
|
|
@@ -9,6 +9,8 @@ import {
|
|
|
9
9
|
Choice,
|
|
10
10
|
DateRangeDropdownComponent,
|
|
11
11
|
DropdownMultiselectComponent,
|
|
12
|
+
SpatialExtentDropdownComponent,
|
|
13
|
+
SpatialExtentDropdownError,
|
|
12
14
|
} from '../../../../../../libs/ui/inputs/src'
|
|
13
15
|
import { Observable, of, switchMap } from 'rxjs'
|
|
14
16
|
import { catchError, filter, map, startWith } from 'rxjs/operators'
|
|
@@ -22,6 +24,10 @@ import {
|
|
|
22
24
|
} from '../utils/service/fields'
|
|
23
25
|
import { DateRange } from '../../../../../../libs/api/repository/src'
|
|
24
26
|
import { CommonModule } from '@angular/common'
|
|
27
|
+
import { BoundingBox } from '../../../../../../libs/util/shared/src'
|
|
28
|
+
import { NotificationsService } from '../../../../../../libs/feature/notifications/src'
|
|
29
|
+
import { TranslateService } from '@ngx-translate/core'
|
|
30
|
+
import { getOptionalSearchConfig } from '../../../../../../libs/util/app-config/src'
|
|
25
31
|
|
|
26
32
|
@Component({
|
|
27
33
|
selector: 'gn-ui-filter-dropdown',
|
|
@@ -33,18 +39,23 @@ import { CommonModule } from '@angular/common'
|
|
|
33
39
|
CommonModule,
|
|
34
40
|
DateRangeDropdownComponent,
|
|
35
41
|
DropdownMultiselectComponent,
|
|
42
|
+
SpatialExtentDropdownComponent,
|
|
36
43
|
],
|
|
37
44
|
})
|
|
38
45
|
export class FilterDropdownComponent implements OnInit {
|
|
39
46
|
private searchFacade = inject(SearchFacade)
|
|
40
47
|
private searchService = inject(SearchService)
|
|
41
48
|
private fieldsService = inject(FieldsService)
|
|
49
|
+
private notificationsService = inject(NotificationsService)
|
|
50
|
+
private translateService = inject(TranslateService)
|
|
42
51
|
|
|
43
52
|
@Input() fieldName: string
|
|
44
53
|
@Input() title: string
|
|
45
54
|
|
|
55
|
+
spatialExtentMaxFileSize =
|
|
56
|
+
getOptionalSearchConfig()?.SPATIAL_EXTENT_MAX_FILE_SIZE
|
|
57
|
+
|
|
46
58
|
fieldType: FieldType
|
|
47
|
-
dateRange: DateRange
|
|
48
59
|
choices$: Observable<Choice[]>
|
|
49
60
|
selected$ = this.searchFacade.searchFilters$.pipe(
|
|
50
61
|
switchMap((filters) =>
|
|
@@ -57,7 +68,7 @@ export class FilterDropdownComponent implements OnInit {
|
|
|
57
68
|
) as Observable<FieldValue[]>
|
|
58
69
|
|
|
59
70
|
selectedDateRange$ = this.selected$.pipe(
|
|
60
|
-
map((
|
|
71
|
+
map((selected) => (Array.isArray(selected) ? {} : (selected as DateRange)))
|
|
61
72
|
) as Observable<DateRange>
|
|
62
73
|
|
|
63
74
|
onSelectedValues(values: unknown[]) {
|
|
@@ -66,6 +77,33 @@ export class FilterDropdownComponent implements OnInit {
|
|
|
66
77
|
.subscribe((filters) => this.searchService.updateFilters(filters))
|
|
67
78
|
}
|
|
68
79
|
|
|
80
|
+
private spatialExtentErrorNotificationId: number | null = null
|
|
81
|
+
|
|
82
|
+
onBboxChange(bbox: BoundingBox | null) {
|
|
83
|
+
console.log(bbox)
|
|
84
|
+
this.clearSpatialExtentErrorNotification()
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
onSpatialExtentError(error: SpatialExtentDropdownError) {
|
|
88
|
+
this.clearSpatialExtentErrorNotification()
|
|
89
|
+
this.spatialExtentErrorNotificationId =
|
|
90
|
+
this.notificationsService.showNotification({
|
|
91
|
+
type: 'error',
|
|
92
|
+
title: this.translateService.instant(
|
|
93
|
+
'search.filters.spatialExtent.error.title'
|
|
94
|
+
),
|
|
95
|
+
text: this.translateService.instant(error.key, error.params),
|
|
96
|
+
})
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
private clearSpatialExtentErrorNotification() {
|
|
100
|
+
if (this.spatialExtentErrorNotificationId === null) return
|
|
101
|
+
this.notificationsService.removeNotificationById(
|
|
102
|
+
this.spatialExtentErrorNotificationId
|
|
103
|
+
)
|
|
104
|
+
this.spatialExtentErrorNotificationId = null
|
|
105
|
+
}
|
|
106
|
+
|
|
69
107
|
ngOnInit() {
|
|
70
108
|
this.fieldType = this.fieldsService.getFieldType(this.fieldName)
|
|
71
109
|
this.choices$ = this.fieldsService.getAvailableValues(this.fieldName).pipe(
|
|
@@ -80,22 +118,11 @@ export class FilterDropdownComponent implements OnInit {
|
|
|
80
118
|
)
|
|
81
119
|
}
|
|
82
120
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
if (!end) return
|
|
90
|
-
this.dateRange = { ...this.dateRange, end }
|
|
91
|
-
if (this.dateRange.start && this.dateRange.end) {
|
|
92
|
-
this.fieldsService
|
|
93
|
-
.buildFiltersFromFieldValues({
|
|
94
|
-
[this.fieldName]: this.dateRange,
|
|
95
|
-
})
|
|
96
|
-
.subscribe((filters) => {
|
|
97
|
-
return this.searchService.updateFilters(filters)
|
|
98
|
-
})
|
|
99
|
-
}
|
|
121
|
+
onDateRangeChange(dateRange: DateRange) {
|
|
122
|
+
this.fieldsService
|
|
123
|
+
.buildFiltersFromFieldValues({
|
|
124
|
+
[this.fieldName]: dateRange,
|
|
125
|
+
})
|
|
126
|
+
.subscribe((filters) => this.searchService.updateFilters(filters))
|
|
100
127
|
}
|
|
101
128
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Component, Input, OnInit, inject } from '@angular/core'
|
|
2
|
-
import { CommonModule
|
|
2
|
+
import { CommonModule } from '@angular/common'
|
|
3
3
|
import {
|
|
4
4
|
catchError,
|
|
5
5
|
firstValueFrom,
|
|
@@ -15,12 +15,14 @@ import { FieldType, FieldValue } from '../utils/service/fields'
|
|
|
15
15
|
import { SearchFacade } from '../state/search.facade'
|
|
16
16
|
import { SearchService } from '../utils/service/search.service'
|
|
17
17
|
import { FieldsService } from '../utils/service/fields.service'
|
|
18
|
-
import { formatUserInfo } from '../../../../../../libs/util/shared/src'
|
|
18
|
+
import { DateService, formatUserInfo } from '../../../../../../libs/util/shared/src'
|
|
19
19
|
import { marker } from '@biesbjerg/ngx-translate-extract-marker'
|
|
20
20
|
|
|
21
21
|
marker('search.filters.summaryLabel.user')
|
|
22
22
|
marker('search.filters.summaryLabel.changeDate')
|
|
23
23
|
|
|
24
|
+
const OPEN_BOUND = '…'
|
|
25
|
+
|
|
24
26
|
interface DisplayedValue {
|
|
25
27
|
label: string
|
|
26
28
|
value: FieldValue | DateRange
|
|
@@ -32,13 +34,12 @@ interface DisplayedValue {
|
|
|
32
34
|
imports: [CommonModule, BadgeComponent],
|
|
33
35
|
templateUrl: './search-filters-summary-item.component.html',
|
|
34
36
|
styleUrls: ['./search-filters-summary-item.component.css'],
|
|
35
|
-
providers: [DatePipe],
|
|
36
37
|
})
|
|
37
38
|
export class SearchFiltersSummaryItemComponent implements OnInit {
|
|
38
39
|
private searchFacade = inject(SearchFacade)
|
|
39
40
|
private searchService = inject(SearchService)
|
|
40
41
|
private fieldsService = inject(FieldsService)
|
|
41
|
-
private
|
|
42
|
+
private dateService = inject(DateService)
|
|
42
43
|
private translate = inject(TranslateService)
|
|
43
44
|
|
|
44
45
|
@Input() fieldName: string
|
|
@@ -82,12 +83,10 @@ export class SearchFiltersSummaryItemComponent implements OnInit {
|
|
|
82
83
|
getReadableValues(fieldValues: FieldValue[] | DateRange[]): DisplayedValue[] {
|
|
83
84
|
return fieldValues.map((value) => {
|
|
84
85
|
if (this.fieldType === 'dateRange') {
|
|
86
|
+
const { start, end } = value as DateRange
|
|
85
87
|
return {
|
|
86
88
|
value,
|
|
87
|
-
label: `${this.
|
|
88
|
-
value.start,
|
|
89
|
-
'dd.MM.yyyy'
|
|
90
|
-
)} - ${this.datePipe.transform(value.end, 'dd.MM.yyyy')}`,
|
|
89
|
+
label: `${this.formatBound(start)} - ${this.formatBound(end)}`,
|
|
91
90
|
}
|
|
92
91
|
} else if (this.fieldName === 'user') {
|
|
93
92
|
return { value, label: formatUserInfo(value) }
|
|
@@ -97,6 +96,16 @@ export class SearchFiltersSummaryItemComponent implements OnInit {
|
|
|
97
96
|
})
|
|
98
97
|
}
|
|
99
98
|
|
|
99
|
+
private formatBound(date: Date | undefined): string {
|
|
100
|
+
return date
|
|
101
|
+
? this.dateService.formatDate(date, {
|
|
102
|
+
day: '2-digit',
|
|
103
|
+
month: '2-digit',
|
|
104
|
+
year: 'numeric',
|
|
105
|
+
})
|
|
106
|
+
: OPEN_BOUND
|
|
107
|
+
}
|
|
108
|
+
|
|
100
109
|
async removeFilterValue(fieldValue: FieldValue | DateRange) {
|
|
101
110
|
const currentFieldValues: DisplayedValue[] = await firstValueFrom(
|
|
102
111
|
this.fieldValues$
|
|
@@ -2,6 +2,7 @@ import { Injectable, Injector, inject } from '@angular/core'
|
|
|
2
2
|
import {
|
|
3
3
|
AbstractSearchField,
|
|
4
4
|
AvailableServicesField,
|
|
5
|
+
BoundingBoxSearchField,
|
|
5
6
|
DateRangeSearchField,
|
|
6
7
|
FieldValue,
|
|
7
8
|
FullTextSearchField,
|
|
@@ -42,7 +43,7 @@ marker('search.filters.producerOrg')
|
|
|
42
43
|
marker('search.filters.publisherOrg')
|
|
43
44
|
marker('search.filters.user')
|
|
44
45
|
marker('search.filters.changeDate')
|
|
45
|
-
|
|
46
|
+
marker('search.filters.spatialExtent')
|
|
46
47
|
@Injectable({
|
|
47
48
|
providedIn: 'root',
|
|
48
49
|
})
|
|
@@ -95,6 +96,7 @@ export class FieldsService {
|
|
|
95
96
|
user: new UserSearchField(this.injector),
|
|
96
97
|
changeDate: new DateRangeSearchField('changeDate', this.injector, 'desc'),
|
|
97
98
|
availableServices: new AvailableServicesField(this.injector),
|
|
99
|
+
spatialExtent: new BoundingBoxSearchField('spatialExtent', this.injector),
|
|
98
100
|
} as Record<string, AbstractSearchField>
|
|
99
101
|
|
|
100
102
|
get supportedFields() {
|
|
@@ -20,10 +20,14 @@ import {
|
|
|
20
20
|
isDateRange,
|
|
21
21
|
METADATA_LANGUAGE,
|
|
22
22
|
} from '../../../../../../../libs/api/repository/src'
|
|
23
|
-
import {
|
|
23
|
+
import {
|
|
24
|
+
BoundingBox,
|
|
25
|
+
formatUserInfo,
|
|
26
|
+
isBoundingBox,
|
|
27
|
+
} from '../../../../../../../libs/util/shared/src'
|
|
24
28
|
import { PossibleResourceTypes } from '../../../../../../../libs/api/metadata-converter/src'
|
|
25
29
|
|
|
26
|
-
export type FieldType = 'values' | 'dateRange'
|
|
30
|
+
export type FieldType = 'values' | 'dateRange' | 'spatialExtent'
|
|
27
31
|
|
|
28
32
|
export type FieldValue = string | number
|
|
29
33
|
export interface FieldAvailableValue {
|
|
@@ -431,6 +435,27 @@ export class DateRangeSearchField extends SimpleSearchField {
|
|
|
431
435
|
}
|
|
432
436
|
}
|
|
433
437
|
|
|
438
|
+
export class BoundingBoxSearchField extends SimpleSearchField {
|
|
439
|
+
getAvailableValues(): Observable<FieldAvailableValue[]> {
|
|
440
|
+
return of([])
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
getFiltersForValues(values: FieldValue[]): Observable<FieldFilters> {
|
|
444
|
+
return of({
|
|
445
|
+
[this.esFieldName]: values.map(Number) as BoundingBox,
|
|
446
|
+
})
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
getValuesForFilter(filters: FieldFilters): Observable<FieldValue[]> {
|
|
450
|
+
const filter = filters[this.esFieldName]
|
|
451
|
+
return of(isBoundingBox(filter) ? filter : [])
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
getType(): FieldType {
|
|
455
|
+
return 'spatialExtent'
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
|
|
434
459
|
marker('search.filters.availableServices.view')
|
|
435
460
|
marker('search.filters.availableServices.download')
|
|
436
461
|
|
|
@@ -4,6 +4,7 @@ export * from './lib/button/button.component'
|
|
|
4
4
|
export * from './lib/check-toggle/check-toggle.component'
|
|
5
5
|
export * from './lib/checkbox/checkbox.component'
|
|
6
6
|
export * from './lib/copy-text-button/copy-text-button.component'
|
|
7
|
+
export * from './lib/date-adapter.providers'
|
|
7
8
|
export * from './lib/date-picker/date-picker.component'
|
|
8
9
|
export * from './lib/date-range-dropdown/date-range-dropdown.component'
|
|
9
10
|
export * from './lib/date-range-picker/date-range-picker.component'
|
|
@@ -25,3 +26,4 @@ export * from './lib/url-input/url-input.component'
|
|
|
25
26
|
export * from './lib/viewport-intersector/viewport-intersector.component'
|
|
26
27
|
export * from './lib/search-feature-catalog/search-feature-catalog.component'
|
|
27
28
|
export * from './lib/date-range-inputs/date-range-inputs.component'
|
|
29
|
+
export * from './lib/spatial-extent-dropdown/spatial-extent-dropdown.component'
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { inject, Provider } from '@angular/core'
|
|
2
|
+
import {
|
|
3
|
+
DateAdapter,
|
|
4
|
+
MAT_DATE_FORMATS,
|
|
5
|
+
MAT_DATE_LOCALE,
|
|
6
|
+
} from '@angular/material/core'
|
|
7
|
+
import {
|
|
8
|
+
DateFnsAdapter,
|
|
9
|
+
MAT_DATE_FNS_FORMATS,
|
|
10
|
+
} from '@angular/material-date-fns-adapter'
|
|
11
|
+
import { enUS } from 'date-fns/locale/en-US'
|
|
12
|
+
import { DateService } from '../../../../../libs/util/shared/src'
|
|
13
|
+
|
|
14
|
+
export function provideLocalizedDateAdapter(): Provider[] {
|
|
15
|
+
return [
|
|
16
|
+
{ provide: MAT_DATE_LOCALE, useValue: enUS },
|
|
17
|
+
{ provide: MAT_DATE_FORMATS, useValue: MAT_DATE_FNS_FORMATS },
|
|
18
|
+
{
|
|
19
|
+
provide: DateAdapter,
|
|
20
|
+
useFactory: () => {
|
|
21
|
+
const dateService = inject(DateService)
|
|
22
|
+
const adapter = new DateFnsAdapter()
|
|
23
|
+
dateService
|
|
24
|
+
.getDateFnsLocale()
|
|
25
|
+
.then((locale) => adapter.setLocale(locale))
|
|
26
|
+
return adapter
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
]
|
|
30
|
+
}
|
|
@@ -2,15 +2,9 @@ import {
|
|
|
2
2
|
ChangeDetectionStrategy,
|
|
3
3
|
Component,
|
|
4
4
|
EventEmitter,
|
|
5
|
-
inject,
|
|
6
5
|
Input,
|
|
7
6
|
Output,
|
|
8
7
|
} from '@angular/core'
|
|
9
|
-
import {
|
|
10
|
-
DateAdapter,
|
|
11
|
-
MAT_DATE_LOCALE,
|
|
12
|
-
MatNativeDateModule,
|
|
13
|
-
} from '@angular/material/core'
|
|
14
8
|
import { MatDatepickerModule } from '@angular/material/datepicker'
|
|
15
9
|
import { ButtonComponent } from '../button/button.component'
|
|
16
10
|
import {
|
|
@@ -19,7 +13,7 @@ import {
|
|
|
19
13
|
provideNgIconsConfig,
|
|
20
14
|
} from '@ng-icons/core'
|
|
21
15
|
import { iconoirCalendar } from '@ng-icons/iconoir'
|
|
22
|
-
import {
|
|
16
|
+
import { provideLocalizedDateAdapter } from '../date-adapter.providers'
|
|
23
17
|
|
|
24
18
|
@Component({
|
|
25
19
|
selector: 'gn-ui-date-picker',
|
|
@@ -27,31 +21,16 @@ import { TranslateService } from '@ngx-translate/core'
|
|
|
27
21
|
styleUrls: ['./date-picker.component.css'],
|
|
28
22
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
29
23
|
standalone: true,
|
|
30
|
-
imports: [
|
|
31
|
-
MatNativeDateModule,
|
|
32
|
-
MatDatepickerModule,
|
|
33
|
-
ButtonComponent,
|
|
34
|
-
NgIconComponent,
|
|
35
|
-
],
|
|
24
|
+
imports: [MatDatepickerModule, ButtonComponent, NgIconComponent],
|
|
36
25
|
providers: [
|
|
37
26
|
provideIcons({ iconoirCalendar }),
|
|
38
27
|
provideNgIconsConfig({
|
|
39
28
|
size: '1.5rem',
|
|
40
29
|
}),
|
|
41
|
-
|
|
42
|
-
provide: MAT_DATE_LOCALE,
|
|
43
|
-
useFactory: (locale: string) => locale,
|
|
44
|
-
},
|
|
30
|
+
provideLocalizedDateAdapter(),
|
|
45
31
|
],
|
|
46
32
|
})
|
|
47
33
|
export class DatePickerComponent {
|
|
48
|
-
private dateAdapter = inject<DateAdapter<Date>>(DateAdapter)
|
|
49
|
-
private translate = inject(TranslateService)
|
|
50
|
-
|
|
51
34
|
@Input() date: Date
|
|
52
35
|
@Output() dateChange = new EventEmitter<Date>()
|
|
53
|
-
|
|
54
|
-
constructor() {
|
|
55
|
-
this.dateAdapter.setLocale(this.translate.getCurrentLang())
|
|
56
|
-
}
|
|
57
36
|
}
|
|
@@ -1,5 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
mat-calendar {
|
|
2
|
+
width: 100%;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.calendar {
|
|
6
|
+
display: grid;
|
|
7
|
+
grid-template-rows: 1fr;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.calendar > mat-calendar {
|
|
11
|
+
min-height: 0;
|
|
12
|
+
overflow: hidden;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.calendar.expand {
|
|
16
|
+
animation: open 200ms ease-out;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.calendar.collapse {
|
|
20
|
+
animation: open 200ms ease-in reverse;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@keyframes open {
|
|
24
|
+
from {
|
|
25
|
+
grid-template-rows: 0fr;
|
|
26
|
+
opacity: 0;
|
|
27
|
+
}
|
|
28
|
+
to {
|
|
29
|
+
grid-template-rows: 1fr;
|
|
30
|
+
opacity: 1;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
@media (prefers-reduced-motion: reduce) {
|
|
35
|
+
.calendar.expand,
|
|
36
|
+
.calendar.collapse {
|
|
37
|
+
animation-duration: 1ms;
|
|
4
38
|
}
|
|
5
39
|
}
|
|
@@ -1,30 +1,149 @@
|
|
|
1
1
|
<gn-ui-button
|
|
2
2
|
type="outline"
|
|
3
3
|
extraClass="bg-background w-full !p-[8px] !pl-[16px]"
|
|
4
|
-
|
|
4
|
+
[title]="title"
|
|
5
|
+
(buttonClick)="openOverlay()"
|
|
6
|
+
cdkOverlayOrigin
|
|
7
|
+
#overlayOrigin="cdkOverlayOrigin"
|
|
5
8
|
>
|
|
6
9
|
<div class="grow flex items-center mr-2 gap-2 overflow-hidden">
|
|
7
10
|
<div class="text-left font-medium truncate py-1">
|
|
8
11
|
{{ title }}
|
|
9
12
|
</div>
|
|
13
|
+
@if (selectedDatesCount) {
|
|
14
|
+
<div
|
|
15
|
+
class="gn-ui-multiselect-counter shrink-0 rounded-full font-bold text-[12px] w-5 h-5 flex items-center justify-center mr-1 selected-count"
|
|
16
|
+
>
|
|
17
|
+
{{ selectedDatesCount }}
|
|
18
|
+
</div>
|
|
19
|
+
}
|
|
10
20
|
</div>
|
|
21
|
+
<button
|
|
22
|
+
class="h-6 w-6 flex items-center justify-center"
|
|
23
|
+
data-test="dropdown-clear"
|
|
24
|
+
>
|
|
25
|
+
@if (selectedDatesCount && !overlayOpen) {
|
|
26
|
+
<ng-icon
|
|
27
|
+
class="shrink-0 opacity-40 hover:opacity-80 transition-colors clear-btn"
|
|
28
|
+
(click)="clearDates($event)"
|
|
29
|
+
name="matClose"
|
|
30
|
+
></ng-icon>
|
|
31
|
+
}
|
|
32
|
+
</button>
|
|
11
33
|
<ng-icon
|
|
12
|
-
|
|
34
|
+
data-test="dropdown-toggle"
|
|
35
|
+
[name]="overlayOpen ? 'matExpandLess' : 'matExpandMore'"
|
|
13
36
|
class="shrink-0 opacity-40"
|
|
14
37
|
>
|
|
15
38
|
</ng-icon>
|
|
16
39
|
</gn-ui-button>
|
|
17
|
-
|
|
18
|
-
<
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
40
|
+
|
|
41
|
+
<ng-template
|
|
42
|
+
cdkConnectedOverlay
|
|
43
|
+
cdkConnectedOverlayHasBackdrop
|
|
44
|
+
cdkConnectedOverlayBackdropClass="cdk-overlay-transparent-backdrop"
|
|
45
|
+
[cdkConnectedOverlayOrigin]="overlayOrigin"
|
|
46
|
+
[cdkConnectedOverlayOpen]="overlayOpen"
|
|
47
|
+
[cdkConnectedOverlayPositions]="overlayPositions"
|
|
48
|
+
[cdkConnectedOverlayScrollStrategy]="scrollStrategy"
|
|
49
|
+
(overlayOutsideClick)="closeOverlay()"
|
|
50
|
+
(detach)="closeOverlay()"
|
|
51
|
+
>
|
|
52
|
+
<div
|
|
53
|
+
class="w-[296px] flex flex-col gap-2 bg-white border border-gray-400 rounded px-4 py-3 shadow-lg text-main text-[16px] leading-[24px]"
|
|
54
|
+
data-test="date-range-panel"
|
|
55
|
+
>
|
|
56
|
+
<div class="flex flex-col justify-center border-b border-gray-300 pb-1">
|
|
57
|
+
<ng-container
|
|
58
|
+
[ngTemplateOutlet]="boundRow"
|
|
59
|
+
[ngTemplateOutletContext]="{
|
|
60
|
+
bound: 'start',
|
|
61
|
+
label: 'daterange.filter.from',
|
|
62
|
+
date: startDate,
|
|
63
|
+
}"
|
|
64
|
+
></ng-container>
|
|
65
|
+
@if (expandedBound === 'start') {
|
|
66
|
+
<div class="calendar" animate.enter="expand" animate.leave="collapse">
|
|
67
|
+
<mat-calendar
|
|
68
|
+
data-test="start-date-calendar"
|
|
69
|
+
[selected]="startDate"
|
|
70
|
+
[startAt]="startDate ?? endDate"
|
|
71
|
+
[maxDate]="endDate"
|
|
72
|
+
(selectedChange)="setStartDate($event)"
|
|
73
|
+
></mat-calendar>
|
|
74
|
+
</div>
|
|
75
|
+
}
|
|
76
|
+
</div>
|
|
77
|
+
<div class="flex flex-col justify-center">
|
|
78
|
+
<ng-container
|
|
79
|
+
[ngTemplateOutlet]="boundRow"
|
|
80
|
+
[ngTemplateOutletContext]="{
|
|
81
|
+
bound: 'end',
|
|
82
|
+
label: 'daterange.filter.to',
|
|
83
|
+
date: endDate,
|
|
84
|
+
}"
|
|
85
|
+
></ng-container>
|
|
86
|
+
@if (expandedBound === 'end') {
|
|
87
|
+
<div class="calendar" animate.enter="expand" animate.leave="collapse">
|
|
88
|
+
<mat-calendar
|
|
89
|
+
data-test="end-date-calendar"
|
|
90
|
+
[selected]="endDate"
|
|
91
|
+
[startAt]="endDate ?? startDate"
|
|
92
|
+
[minDate]="startDate"
|
|
93
|
+
(selectedChange)="setEndDate($event)"
|
|
94
|
+
></mat-calendar>
|
|
95
|
+
</div>
|
|
96
|
+
}
|
|
97
|
+
</div>
|
|
98
|
+
</div>
|
|
99
|
+
</ng-template>
|
|
100
|
+
|
|
101
|
+
<ng-template #boundRow let-bound="bound" let-label="label" let-date="date">
|
|
102
|
+
<div class="flex items-center gap-1 w-full">
|
|
103
|
+
<span class="w-[80px] shrink-0" [translate]="label"></span>
|
|
104
|
+
<div
|
|
105
|
+
class="flex-1 min-w-0 flex items-center gap-1 border rounded-lg px-2 py-1 transition-colors"
|
|
106
|
+
[class]="
|
|
107
|
+
invalidBounds[bound]
|
|
108
|
+
? 'border-red-400 text-red-800 focus-within:border-red-800 hover:border-red-800'
|
|
109
|
+
: 'border-gray-400 focus-within:border-main hover:border-main'
|
|
110
|
+
"
|
|
111
|
+
>
|
|
112
|
+
<ng-icon
|
|
113
|
+
name="iconoirCalendar"
|
|
114
|
+
class="shrink-0"
|
|
115
|
+
aria-hidden="true"
|
|
116
|
+
></ng-icon>
|
|
117
|
+
<input
|
|
118
|
+
type="text"
|
|
119
|
+
inputmode="numeric"
|
|
120
|
+
autocomplete="off"
|
|
121
|
+
[gnUiAutofocus]="bound === expandedBound"
|
|
122
|
+
class="min-w-0 grow bg-transparent focus:outline-none"
|
|
123
|
+
[value]="date ? formatDate(date) : ''"
|
|
124
|
+
[placeholder]="'daterange.filter.datePlaceholder' | translate"
|
|
125
|
+
[attr.aria-label]="label | translate"
|
|
126
|
+
[attr.aria-invalid]="invalidBounds[bound] || null"
|
|
127
|
+
[attr.data-test]="bound + '-date-input'"
|
|
128
|
+
(change)="onDateInput(bound, $event)"
|
|
129
|
+
(blur)="normalizeDateInput(bound, $event)"
|
|
130
|
+
(click)="expandedBound !== bound && toggleBound(bound)"
|
|
131
|
+
/>
|
|
132
|
+
</div>
|
|
133
|
+
<div class="shrink-0 flex items-center justify-end">
|
|
134
|
+
<gn-ui-button
|
|
135
|
+
type="light"
|
|
136
|
+
[style.--gn-ui-button-padding]="0"
|
|
137
|
+
[style.--gn-ui-button-width]="'24px'"
|
|
138
|
+
[style.--gn-ui-button-height]="'24px'"
|
|
139
|
+
[attr.aria-expanded]="expandedBound === bound"
|
|
140
|
+
[attr.data-test]="bound + '-date-toggle'"
|
|
141
|
+
(buttonClick)="toggleBound(bound)"
|
|
142
|
+
>
|
|
143
|
+
<ng-icon
|
|
144
|
+
[name]="expandedBound === bound ? 'matExpandLess' : 'matExpandMore'"
|
|
145
|
+
></ng-icon>
|
|
146
|
+
</gn-ui-button>
|
|
147
|
+
</div>
|
|
148
|
+
</div>
|
|
149
|
+
</ng-template>
|