Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
LHBruneton-C2C committed Sep 23, 2024
1 parent 66a3379 commit c29ab22
Show file tree
Hide file tree
Showing 24 changed files with 559 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function matchProtocol(protocol: string): ServiceProtocol {
if (/wps/i.test(protocol)) return 'wps'
if (/ogc\W*api\W*features/i.test(protocol)) return 'ogcFeatures'
if (/esri/i.test(protocol)) return 'esriRest'
return 'other'
return protocol
}

export function matchMimeType(format: string): string {
Expand Down
3 changes: 2 additions & 1 deletion libs/api/metadata-converter/src/lib/iso19139/read-parts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ export function extractDatasetOnlineResources(
)
const getIsService = pipe(
getProtocol,
map((protocol) => protocol !== 'other')
map((protocol) => protocol !== 'WWW:DOWNLOAD' && protocol !== 'WWW:LINK')
)
const getIsDownload = pipe(
combine(getIsService, getOnlineFunction, getProtocolStr),
Expand Down Expand Up @@ -381,6 +381,7 @@ export function extractDatasetOnlineResources(
mapArray(
([isService, isDownload, protocol, url, name, description, mimeType]) => {
if (isService) {
//FIXME: allow writing identifier only for wms and wfs?
const hasIdentifier = protocol === 'wms' || protocol === 'wfs'
return {
type: 'service',
Expand Down
2 changes: 1 addition & 1 deletion libs/common/domain/src/lib/model/record/metadata.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export type ServiceProtocol =
| 'wmts'
| 'esriRest'
| 'ogcFeatures'
| 'other'
| string

export type OnlineResourceType = 'service' | 'download' | 'link' | 'endpoint'

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<div class="flex flex-row justify-between mb-[16px]">
<h3 class="text-[16px] font-bold text-main mb-[12px]" translate>
editor.record.form.field.onlineResource.edit.protocol
</h3>
<span
*ngIf="protocolHint"
class="material-symbols-outlined m-2 gn-ui-icon-small"
[matTooltip]="protocolHint"
matTooltipPosition="above"
>
help
</span>
</div>
<div class="flex flex-row items-center gap-[16px] h-[48px] mb-[16px]">
<mat-radio-group
aria-labelledby="example-radio-group-label"
class="flex flex-row gap-[8px]"
[(ngModel)]="selectedProtocol"
(ngModelChange)="handleProtocolChange($event)"
>
<mat-radio-button
*ngFor="let protocolOption of protocolOptions"
[value]="protocolOption.value"
>
{{ protocolOption.label | translate }}
</mat-radio-button>
</mat-radio-group>
<gn-ui-text-input
*ngIf="selectedProtocol === 'other'"
class="grow"
[(value)]="service.accessServiceProtocol"
></gn-ui-text-input>
</div>
<gn-ui-text-input [(value)]="service.identifierInService"></gn-ui-text-input>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { ComponentFixture, TestBed } from '@angular/core/testing'
import { TranslateModule } from '@ngx-translate/core'
import { OnlineServiceResourceInputComponent } from './online-service-resource-input.component'

describe('OnlineServiceResourceInputComponent', () => {
let component: OnlineServiceResourceInputComponent
let fixture: ComponentFixture<OnlineServiceResourceInputComponent>

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [OnlineServiceResourceInputComponent, TranslateModule.forRoot()],
}).compileComponents()

fixture = TestBed.createComponent(OnlineServiceResourceInputComponent)
component = fixture.componentInstance
})

it('should create', () => {
expect(component).toBeTruthy()
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { CommonModule } from '@angular/common'
import {
ChangeDetectionStrategy,
Component,
Input,
OnChanges,
} from '@angular/core'
import { FormsModule } from '@angular/forms'
import { MatIconModule } from '@angular/material/icon'
import { MatRadioModule } from '@angular/material/radio'
import { MatTooltipModule } from '@angular/material/tooltip'
import { marker } from '@biesbjerg/ngx-translate-extract-marker'
import {
DatasetServiceDistribution,
ServiceProtocol,
} from '@geonetwork-ui/common/domain/model/record'
import { TextInputComponent } from '@geonetwork-ui/ui/inputs'
import { TranslateModule } from '@ngx-translate/core'

@Component({
selector: 'gn-ui-online-service-resource-input',
templateUrl: './online-service-resource-input.component.html',
styleUrls: ['./online-service-resource-input.component.css'],
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
imports: [
CommonModule,
MatIconModule,
MatTooltipModule,
MatRadioModule,
FormsModule,
TextInputComponent,
TranslateModule,
],
})
export class OnlineServiceResourceInputComponent implements OnChanges {
@Input() service: Omit<DatasetServiceDistribution, 'url'>
@Input() protocolHint?: string = 'toto'

selectedProtocol: ServiceProtocol | 'other'

protocolOptions: {
label: string
value: ServiceProtocol | 'other'
}[] = [
{
label: 'OGC API',
value: 'ogcFeatures',
},
{
label: 'WFS',
value: 'wfs',
},
{
label: 'WMS',
value: 'wms',
},
{
label: 'WMTS',
value: 'wmts',
},
{
label: 'WPS',
value: 'wps',
},
{
label: 'ESRI REST',
value: 'esriRest',
},
{
label: marker('editor.record.onlineResource.protocol.other'),
value: 'other',
},
]

ngOnChanges() {
this.selectedProtocol =
this.protocolOptions.find(
(option) => option.value === this.service.accessServiceProtocol
)?.value ?? 'other'
}

handleProtocolChange(protocol: ServiceProtocol | 'other') {
if (protocol === 'other') {
this.service.accessServiceProtocol = ''
} else {
this.service.accessServiceProtocol = protocol
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<gn-ui-switch-toggle
[options]="typeOptions"
(selectedValue)="onSelectedTypeChange($event.value)"
extraClasses="grow"
></gn-ui-switch-toggle>
<div class="h-[8px]"></div>
<gn-ui-file-input
*ngIf="selectedType === 'download'"
[maxSizeMB]="MAX_UPLOAD_SIZE_MB"
(fileChange)="handleFileChange($event)"
(uploadCancel)="handleUploadCancel()"
[uploadProgress]="uploadProgress"
(urlChange)="handleDownloadUrlChange($event)"
></gn-ui-file-input>
<div
*ngIf="selectedType === 'service'"
class="w-full border-2 border-dashed rounded-lg p-6 flex flex-col gap-[16px]"
>
<gn-ui-online-service-resource-input
[service]="newService"
></gn-ui-online-service-resource-input>
<span class="w-full border-b border-gray-300"></span>
<gn-ui-url-input
class="w-full"
(valueChange)="handleServiceUrlChange($event)"
></gn-ui-url-input>
</div>
<div class="h-[8px]"></div>
<gn-ui-sortable-list
[items]="notLinkResources"
(itemsOrderChange)="handleResourcesChange($event)"
[elementTemplate]="template"
>
</gn-ui-sortable-list>
<ng-template #template let-onlineResource let-index="index">
<gn-ui-online-resource-card
[onlineResource]="onlineResource"
(modifyClick)="handleResourceModify(onlineResource, index)"
></gn-ui-online-resource-card>
</ng-template>

<ng-template #dialogTemplate let-onlineResource>
<h3 class="text-[16px] font-bold text-main mb-[12px]" translate>
editor.record.form.field.onlineResource.edit.title
</h3>
<gn-ui-text-input
extraClass="mb-[16px]"
[(value)]="onlineResource.name"
></gn-ui-text-input>
<h3 class="text-[16px] font-bold text-main mb-[12px]" translate>
editor.record.form.field.onlineResource.edit.description
</h3>
<gn-ui-text-area [(value)]="onlineResource.description"></gn-ui-text-area>
<ng-container *ngIf="onlineResource.type === 'service'">
<div class="h-[8px]"></div>
<span class="w-full border-b border-gray-300"></span>
<div class="h-[8px]"></div>
<gn-ui-online-service-resource-input
[service]="onlineResource"
></gn-ui-online-service-resource-input>
</ng-container>
</ng-template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { ComponentFixture, TestBed } from '@angular/core/testing'
import { TranslateModule } from '@ngx-translate/core'
import { FormFieldOnlineResourcesComponent } from './form-field-online-resources.component'

describe('FormFieldOnlineResourcesComponent', () => {
let component: FormFieldOnlineResourcesComponent
let fixture: ComponentFixture<FormFieldOnlineResourcesComponent>

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [FormFieldOnlineResourcesComponent, TranslateModule.forRoot()],
}).compileComponents()

fixture = TestBed.createComponent(FormFieldOnlineResourcesComponent)
component = fixture.componentInstance
})

it('should create', () => {
expect(component).toBeTruthy()
})
})
Loading

0 comments on commit c29ab22

Please sign in to comment.