Skip to content

Commit

Permalink
Merge pull request #55 from IGNF/Api_telechargement
Browse files Browse the repository at this point in the history
Api telechargement
  • Loading branch information
mmohadIGN authored Sep 6, 2024
2 parents 511597c + bfd5848 commit bf2944b
Show file tree
Hide file tree
Showing 124 changed files with 2,291 additions and 1,193 deletions.
2 changes: 1 addition & 1 deletion apps/datahub-e2e/src/e2e/datasetDetailPage.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ describe('record with file distributions', () => {
.click()
})

it('should display the distributions by priority', () => {
it('should display the onlineResources by priority', () => {
cy.get('@previewSection')
.find('gn-ui-dropdown-selector')
.last()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,20 @@
<div class="bg-primary-opacity-10 py-8">
<div class="flex flex-col px-4 gap-8 container-lg lg:mx-auto">
<div class="flex flex-wrap justify-between sm:mb-2 ng-star-inserted">
<p class="text-[21px] text-title font-title" translate>
<p
class="text-[21px] text-title font-title"
*ngIf="selectedApiLink?.accessServiceProtocol !== 'GPFDL'"
translate
>
record.metadata.api.form.title
</p>
<p
class="text-[21px] text-title font-title"
*ngIf="selectedApiLink?.accessServiceProtocol === 'GPFDL'"
translate
>
record.metadata.api.form.title.gpf
</p>
<button
type="button"
class="flex items-center gap-0.5 text-primary group"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { RecordDownloadsComponent } from './record-downloads.component'
import { Component, Input, NO_ERRORS_SCHEMA } from '@angular/core'
import { By } from '@angular/platform-browser'
import { DataService } from '@geonetwork-ui/feature/dataviz'
import { DatasetDistribution } from '@geonetwork-ui/common/domain/model/record'
import { DatasetOnlineResource } from '@geonetwork-ui/common/domain/model/record'
import { MdViewFacade } from '@geonetwork-ui/feature/record'

// This is used to work around a very weird bug when comparing URL objects would fail
Expand Down Expand Up @@ -77,7 +77,7 @@ class DataServiceMock {
template: '<div></div>',
})
export class MockDownloadsListItemComponent {
@Input() link: DatasetDistribution
@Input() link: DatasetOnlineResource
}

@Component({
Expand Down Expand Up @@ -146,7 +146,7 @@ describe('DataDownloadsComponent', () => {
})
it('emits the other links', fakeAsync(() => {
let downloadLinks = []
component.links$.subscribe((links: DatasetDistribution[]) => {
component.links$.subscribe((links: DatasetOnlineResource[]) => {
downloadLinks = links
})
tick(200)
Expand Down Expand Up @@ -174,7 +174,7 @@ describe('DataDownloadsComponent', () => {
fixture.detectChanges()
})
it('emits no links', () => {
component.links$.subscribe((links: DatasetDistribution[]) => {
component.links$.subscribe((links: DatasetOnlineResource[]) => {
expect(links).toEqual([])
})
})
Expand Down Expand Up @@ -245,7 +245,7 @@ describe('DataDownloadsComponent', () => {
})
it('emits download links once per format', fakeAsync(() => {
let downloadLinks = []
component.links$.subscribe((links: DatasetDistribution[]) => {
component.links$.subscribe((links: DatasetOnlineResource[]) => {
downloadLinks = links
})
tick(200)
Expand Down Expand Up @@ -387,7 +387,7 @@ describe('DataDownloadsComponent', () => {
})
it('sorts links', fakeAsync(() => {
let downloadLinks = []
component.links$.subscribe((links: DatasetDistribution[]) => {
component.links$.subscribe((links: DatasetOnlineResource[]) => {
downloadLinks = links
})
tick(200)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getFileFormat, getLinkPriority } from '@geonetwork-ui/util/shared'
import { combineLatest, of } from 'rxjs'
import { catchError, map, switchMap } from 'rxjs/operators'
import {
DatasetDistribution,
DatasetOnlineResource,
DatasetServiceDistribution,
} from '@geonetwork-ui/common/domain/model/record'
import { MdViewFacade } from '@geonetwork-ui/feature/record'
Expand Down Expand Up @@ -61,11 +61,11 @@ export class RecordDownloadsComponent {
.pipe(
catchError((e) => {
this.error = e.message
return [of([] as DatasetDistribution[])]
return [of([] as DatasetOnlineResource[])]
})
)
)
: [of([] as DatasetDistribution[])]),
: [of([] as DatasetOnlineResource[])]),
...(ogcLinks.length > 0
? ogcLinks.map((link) =>
this.dataService
Expand All @@ -77,7 +77,7 @@ export class RecordDownloadsComponent {
return Promise.resolve([])
})
)
: [of([] as DatasetDistribution[])]),
: [of([] as DatasetOnlineResource[])]),
]).pipe(
map(flattenArray),
map(removeLinksWithUnknownFormat),
Expand Down Expand Up @@ -113,6 +113,8 @@ const removeDuplicateLinks = (downloadLinks) =>
)

const sortLinks = (allLinks) =>
allLinks.sort((a: DatasetDistribution, b: DatasetDistribution): number => {
return getLinkPriority(b) - getLinkPriority(a)
})
allLinks.sort(
(a: DatasetOnlineResource, b: DatasetOnlineResource): number => {
return getLinkPriority(b) - getLinkPriority(a)
}
)
Original file line number Diff line number Diff line change
Expand Up @@ -362,15 +362,15 @@
[(fieldValue)]="record.distributions"
[itemTemplate]="distributionTpl"
(confirm)="emitChangedRecord()"
[defaultItem]="getDistributionForType('download')"
[defaultItem]="getOnlineResourceForType('download')"
>
<ng-template #distributionTpl let-get="getValue" let-set="setValue">
<gn-ui-record-field-group label="Distribution">
<gn-ui-record-field-simple
label="Type"
[options]="['service', 'download', 'link']"
[fieldValue]="get().type"
(fieldValueChange)="set(getDistributionForType($event))"
(fieldValueChange)="set(getOnlineResourceForType($event))"
(confirm)="emitChangedRecord()"
></gn-ui-record-field-simple>
<gn-ui-record-field-simple
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ import {
} from '@angular/core'
import {
CatalogRecord,
DatasetDistribution,
DatasetDistributionType,
DatasetRecord,
OnlineResource,
OnlineResourceType,
RecordKind,
RecordStatusValues,
RoleValues,
ServiceOnlineResource,
ServiceOnlineResourceType,
ServiceRecord,
} from '@geonetwork-ui/common/domain/model/record'

Expand Down Expand Up @@ -51,7 +49,7 @@ export class RecordFormComponent implements AfterViewInit {
this.recordChanged.emit(this.record)
}

getDistributionForType(type: DatasetDistributionType): DatasetDistribution {
getOnlineResourceForType(type: OnlineResourceType): OnlineResource {
switch (type) {
case 'download':
return {
Expand All @@ -64,26 +62,14 @@ export class RecordFormComponent implements AfterViewInit {
url: new URL('', window.location.toString()),
accessServiceProtocol: 'other',
}
case 'link':
default:
return {
type: 'link',
url: new URL('', window.location.toString()),
}
}
}

getOnlineResourceForType(
type: ServiceOnlineResourceType
): ServiceOnlineResource {
switch (type) {
case 'endpoint':
return {
type,
endpointUrl: new URL('', window.location.toString()),
protocol: 'other',
}
case 'link':
default:
return {
type,
url: new URL('', window.location.toString()),
Expand Down Expand Up @@ -113,6 +99,7 @@ export class RecordFormComponent implements AfterViewInit {
otherConstraints: hasPrevious ? [...this.record.otherConstraints] : [],
keywords: hasPrevious ? this.record.keywords : [],
topics: hasPrevious ? this.record.topics : [],
onlineResources: [],
}
if (kind === 'dataset') {
this.record = {
Expand All @@ -122,15 +109,13 @@ export class RecordFormComponent implements AfterViewInit {
updateFrequency: 'unknown',
lineage: '',
overviews: [],
distributions: [],
spatialExtents: [],
temporalExtents: [],
} as DatasetRecord
} else {
this.record = {
...record,
kind: 'service',
onlineResources: [],
} as ServiceRecord
}
this.recordChanged.emit(this.record)
Expand Down
58 changes: 55 additions & 3 deletions apps/metadata-editor-e2e/src/e2e/edit.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,68 @@ describe('editor form', () => {
})
})
})
describe('attached resources', () => {
beforeEach(() => {
cy.get('@resourcePageSelectorButton').click()
})
it('adds, modifies, deletes a resource', () => {
// original item count
cy.get(
'gn-ui-form-field-online-link-resources gn-ui-online-resource-card'
).should('have.length', 7)
// upload readme file
cy.get('gn-ui-form-field-online-link-resources label').selectFile(
'src/fixtures/readme.txt'
)
cy.get(
'gn-ui-form-field-online-link-resources gn-ui-online-resource-card'
).should('have.length', 8)
cy.get(
'gn-ui-form-field-online-link-resources gn-ui-online-resource-card'
)
.eq(7)
.as('readmeLink')
cy.get('@readmeLink')
.find('[data-test=card-title]')
.invoke('text')
.invoke('trim')
.should('eql', 'readme.txt')
// open modify dialog
cy.get('@readmeLink').find('button[data-test=card-modify]').click()
cy.get('gn-ui-modal-dialog gn-ui-text-input')
.find('input')
.type('{selectall}{del}new title!')
cy.get('gn-ui-modal-dialog gn-ui-text-area')
.find('textarea')
.type('new description')
cy.get('gn-ui-modal-dialog [data-cy=confirm-button]').click()
cy.get('@readmeLink')
.find('[data-test=card-title]')
.invoke('text')
.invoke('trim')
.should('eql', 'new title!')
cy.get('@readmeLink').scrollIntoView()
cy.screenshot({ capture: 'viewport' })
// delete item
cy.get(
'gn-ui-form-field-online-link-resources gn-ui-sortable-list [data-cy=remove-item]'
)
.eq(7)
.click()
// original item count
cy.get(
'gn-ui-form-field-online-link-resources gn-ui-online-resource-card'
).should('have.length', 7)
})
})
})

describe('date range in sortable list', () => {
it('should keep the date picker open when selecting the start date of a range', () => {
// add a date range
cy.get('gn-ui-form-field-temporal-extents gn-ui-button').eq(1).click()
// open the date picker
cy.get(
'gn-ui-form-field-temporal-extents-range mat-datepicker-toggle'
).click()
cy.get('gn-ui-form-field-temporal-extents mat-datepicker-toggle').click()
// select a date
cy.get('mat-calendar').contains('1').click()
// the date picker should still be open
Expand Down
1 change: 1 addition & 0 deletions apps/metadata-editor-e2e/src/fixtures/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is a sample file that will be attached to a resource for demonstration purposes.
5 changes: 5 additions & 0 deletions apps/metadata-editor/src/app/edit/edit-page.component.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
:host {
--gn-ui-text-input-rounded: 8px;
--gn-ui-text-input-padding: 14px;
}

.card {
@apply border border-gray-200 rounded-md bg-white;
}
Expand Down
2 changes: 1 addition & 1 deletion apps/metadata-editor/src/app/new-record.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class NewRecordResolver {
kind: 'dataset',
status: 'ongoing',
lineage: '',
distributions: [],
onlineResources: [],
spatialExtents: [],
temporalExtents: [],
} as CatalogRecord
Expand Down
6 changes: 3 additions & 3 deletions apps/webcomponents/src/app/components/base.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { Configuration, SearchApiService } from '@geonetwork-ui/data-access/gn4'
import { SearchFacade } from '@geonetwork-ui/feature/search'
import { TranslateService } from '@ngx-translate/core'
import { firstValueFrom } from 'rxjs'
import { DatasetDistribution } from '@geonetwork-ui/common/domain/model/record'
import { DatasetOnlineResource } from '@geonetwork-ui/common/domain/model/record'
import { RecordsRepositoryInterface } from '@geonetwork-ui/common/domain/repository/records-repository.interface'
import { OverlayContainer } from '@angular/cdk/overlay'
import { WebcomponentOverlayContainer } from '../webcomponent-overlay-container'
Expand Down Expand Up @@ -115,12 +115,12 @@ export class BaseComponent implements OnChanges, OnInit {
async getRecordLink(
uuid: string,
usages: LinkUsage[]
): Promise<DatasetDistribution | null> {
): Promise<DatasetOnlineResource | null> {
const record = await firstValueFrom(this.recordsRepository.getRecord(uuid))
if (record?.kind !== 'dataset') {
return null
}
const dataLinks = record.distributions.filter((link) =>
const dataLinks = record.onlineResources.filter((link) =>
usages.some((usage) => this.linkClassifier.hasUsage(link, usage))
)
return dataLinks[0]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import { SearchFacade, SearchService } from '@geonetwork-ui/feature/search'
import { BaseComponent } from '../base.component'
import { LinkUsage } from '@geonetwork-ui/util/shared'
import { DatasetDistribution } from '@geonetwork-ui/common/domain/model/record'
import { DatasetOnlineResource } from '@geonetwork-ui/common/domain/model/record'

@Component({
selector: 'wc-gn-dataset-view-chart',
Expand All @@ -29,7 +29,7 @@ export class GnDatasetViewChartComponent
@Input() xProperty: string
@Input() yProperty: string
@Input() chartType: string
link: DatasetDistribution
link: DatasetOnlineResource
constructor(injector: Injector, private changeDetector: ChangeDetectorRef) {
super(injector)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { MdViewFacade } from '@geonetwork-ui/feature/record'
import { SearchFacade } from '@geonetwork-ui/feature/search'
import { BaseComponent } from '../base.component'
import { LinkUsage } from '@geonetwork-ui/util/shared'
import { DatasetDistribution } from '@geonetwork-ui/common/domain/model/record'
import { DatasetOnlineResource } from '@geonetwork-ui/common/domain/model/record'

@Component({
selector: 'wc-gn-dataset-view-map',
Expand All @@ -30,7 +30,7 @@ export class GnDatasetViewMapComponent extends BaseComponent implements OnInit {
super(injector)
}
@Input() datasetId: string
link: DatasetDistribution
link: DatasetOnlineResource
async init() {
super.init()
this.mdViewFacade.loadFull(this.datasetId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import { SearchFacade, SearchService } from '@geonetwork-ui/feature/search'
import { BaseComponent } from '../base.component'
import { LinkUsage } from '@geonetwork-ui/util/shared'
import { DatasetDistribution } from '@geonetwork-ui/common/domain/model/record'
import { DatasetOnlineResource } from '@geonetwork-ui/common/domain/model/record'

@Component({
selector: 'wc-gn-dataset-view-table',
Expand All @@ -25,7 +25,7 @@ export class GnDatasetViewTableComponent
implements OnInit
{
@Input() datasetId!: string
link: DatasetDistribution
link: DatasetOnlineResource
constructor(injector: Injector, private changeDetector: ChangeDetectorRef) {
super(injector)
}
Expand Down
Loading

0 comments on commit bf2944b

Please sign in to comment.