Skip to content

Commit

Permalink
Merge pull request #1052 from geonetwork/ME-no-attachement-upload-to-…
Browse files Browse the repository at this point in the history
…draft-only

Editor: No attachement upload to draft only
  • Loading branch information
Angi-Kinas authored Dec 12, 2024
2 parents bef577f + 8827faa commit decc890
Show file tree
Hide file tree
Showing 30 changed files with 295 additions and 148 deletions.
46 changes: 46 additions & 0 deletions apps/metadata-editor-e2e/src/e2e/record-actions.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,52 @@ describe('record-actions', () => {
.should('contain.text', 'Next')
})

it('the created record should not allow upload of resources and show info message as it was not saved yet', () => {
// first page
cy.get('gn-ui-form-field-overviews')
.find('gn-ui-image-input')
.find('input')
.should('be.disabled')
cy.get('gn-ui-form-field-overviews')
.children()
.find('[data-test="disabled-message"]')
.should(
'contain.text',
' This field will be enabled once the data has been published '
)

// second page
cy.get('[data-test="previousNextPageButtons"]')
.children()
.eq(1)
.should('contain.text', 'Next')
.click()
cy.get('gn-ui-form-field-online-resources')
.find('gn-ui-switch-toggle')
.find('mat-button-toggle-group')
.find('button')
.should('be.disabled')
cy.get('gn-ui-file-input').find('input').should('be.disabled')
cy.get('gn-ui-form-field-online-resources')
.children()
.find('div')
.should(
'contain.text',
' This field will be enabled once the data has been published '
)

cy.get('gn-ui-form-field-online-link-resources')
.find('input')
.should('be.disabled')
cy.get('gn-ui-form-field-online-link-resources')
.children()
.find('div')
.should(
'contain.text',
' This field will be enabled once the data has been published '
)
})

it('back navigation should go to search after creating a record', () => {
cy.go('back')
cy.url().should('include', '/catalog/search')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ <h3 class="text-[16px] font-bold text-main mb-[12px]" translate>
aria-labelledby="example-radio-group-label"
class="flex flex-row gap-[8px]"
[(ngModel)]="service.accessServiceProtocol"
[disabled]="disabled"
>
<mat-radio-button
*ngFor="let protocolOption of protocolOptions"
Expand All @@ -28,4 +29,5 @@ <h3 class="text-[16px] font-bold text-main mb-[12px]" translate>
<gn-ui-text-input
[(value)]="service.identifierInService"
data-cy="identifier-in-service"
[disabled]="disabled"
></gn-ui-text-input>
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { TranslateModule } from '@ngx-translate/core'
export class OnlineServiceResourceInputComponent implements OnChanges {
@Input() service: Omit<DatasetServiceDistribution, 'url'>
@Input() protocolHint?: string
@Input() disabled? = false

selectedProtocol: ServiceProtocol

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

<ng-template #noContact>
<div
class="p-4 border border-primary bg-primary-lightest rounded-lg"
class="p-4 text-sm border border-primary bg-primary-lightest rounded-lg"
translate
>
editor.record.form.field.contacts.noContact
Expand Down
Original file line number Diff line number Diff line change
@@ -1,44 +1,58 @@
<gn-ui-file-input
[maxSizeMB]="MAX_UPLOAD_SIZE_MB"
(fileChange)="handleFileChange($event)"
(uploadCancel)="handleUploadCancel()"
[uploadProgress]="uploadProgress"
(urlChange)="handleUrlChange($event)"
></gn-ui-file-input>
<div class="h-[8px]"></div>
<gn-ui-sortable-list
[items]="linkResources"
(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>
<div class="flex flex-col">
<gn-ui-file-input
[maxSizeMB]="MAX_UPLOAD_SIZE_MB"
(fileChange)="handleFileChange($event)"
(uploadCancel)="handleUploadCancel()"
[uploadProgress]="uploadProgress"
(urlChange)="handleUrlChange($event)"
[disabled]="disabled$ | async"
></gn-ui-file-input>
<div class="h-[8px]"></div>
<gn-ui-sortable-list
[items]="linkResources"
(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>
<div class="flex flex-col gap-[16px]">
<div>
<h3 class="text-[16px] font-bold text-main mb-[12px]" translate>
editor.record.form.field.onlineResource.edit.title
</h3>
<gn-ui-text-input [(value)]="onlineResource.name"></gn-ui-text-input>
<ng-template #dialogTemplate let-onlineResource>
<div class="flex flex-col gap-[16px]">
<div>
<h3 class="text-[16px] font-bold text-main mb-[12px]" translate>
editor.record.form.field.onlineResource.edit.title
</h3>
<gn-ui-text-input [(value)]="onlineResource.name"></gn-ui-text-input>
</div>
<div>
<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>
</div>
<span class="w-full border-b border-gray-300"></span>
<gn-ui-url-input
class="w-full"
[disabled]="true"
[value]="onlineResource.url"
[showUploadButton]="false"
[disabled]="disabled$ | async"
></gn-ui-url-input>
</div>
<div>
<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>
</div>
<span class="w-full border-b border-gray-300"></span>
<gn-ui-url-input
class="w-full"
[disabled]="true"
[value]="onlineResource.url"
[showUploadButton]="false"
></gn-ui-url-input>
</ng-template>
<div
*ngIf="disabled$ | async"
class="p-4 text-sm border border-primary bg-primary-lightest rounded-lg"
translate
data-testid="disabled-message"
>
editor.record.form.field.draft.only.disabled
</div>
</ng-template>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { MatDialog, MatDialogRef } from '@angular/material/dialog'
import { OnlineLinkResource } from '@geonetwork-ui/common/domain/model/record'
import { ModalDialogComponent } from '@geonetwork-ui/ui/layout'
import { ChangeDetectorRef } from '@angular/core'
import { EditorFacade } from '../../../../+state/editor.facade'

let uploadSubject: Subject<any>

Expand All @@ -38,6 +39,10 @@ export class MatDialogMock {
}))
}

class EditorFacadeMock {
alreadySavedOnce$ = new BehaviorSubject(false)
}

describe('FormFieldOnlineLinkResourcesComponent', () => {
let component: FormFieldOnlineLinkResourcesComponent
let fixture: ComponentFixture<FormFieldOnlineLinkResourcesComponent>
Expand Down Expand Up @@ -65,6 +70,7 @@ describe('FormFieldOnlineLinkResourcesComponent', () => {
detectChanges: jest.fn(),
}),
MockProvider(MatDialog, MatDialogMock, 'useClass'),
MockProvider(EditorFacade, EditorFacadeMock, 'useClass'),
],
}).compileComponents()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ import {
import { NotificationsService } from '@geonetwork-ui/feature/notifications'
import { TranslateModule, TranslateService } from '@ngx-translate/core'
import { PlatformServiceInterface } from '@geonetwork-ui/common/domain/platform.service.interface'
import { Subscription } from 'rxjs'
import { map, Subscription } from 'rxjs'
import { MatDialog } from '@angular/material/dialog'
import { MAX_UPLOAD_SIZE_MB } from '../../../../fields.config'
import { EditorFacade } from '../../../../+state/editor.facade'

@Component({
selector: 'gn-ui-form-field-online-link-resources',
Expand Down Expand Up @@ -68,12 +69,17 @@ export class FormFieldOnlineLinkResourcesComponent {

protected MAX_UPLOAD_SIZE_MB = MAX_UPLOAD_SIZE_MB

disabled$ = this.editorFacade.alreadySavedOnce$.pipe(
map((alreadySavedOnce) => !alreadySavedOnce)
)

constructor(
private notificationsService: NotificationsService,
private translateService: TranslateService,
private platformService: PlatformServiceInterface,
private cd: ChangeDetectorRef,
private dialog: MatDialog
private dialog: MatDialog,
private editorFacade: EditorFacade
) {}

handleFileChange(file: File) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,72 +1,88 @@
<gn-ui-switch-toggle
[options]="typeOptions"
(selectedValue)="onSelectedTypeChange($event.value)"
extraClasses="grow text-sm"
data-cy="online-resources-type"
></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"
[urlCanParse]="true"
(uploadClick)="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>
<div class="flex flex-col gap-[16px]">
<div>
<h3 class="text-[16px] font-bold text-main mb-[12px]" translate>
editor.record.form.field.onlineResource.edit.title
</h3>
<gn-ui-text-input [(value)]="onlineResource.name"></gn-ui-text-input>
</div>
<div>
<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>
</div>
<ng-container *ngIf="onlineResource.type === 'service'">
<span class="w-full border-b border-gray-300"></span>
<gn-ui-online-service-resource-input
[service]="onlineResource"
></gn-ui-online-service-resource-input>
</ng-container>
<div class="flex flex-col">
<gn-ui-switch-toggle
[options]="typeOptions"
(selectedValue)="onSelectedTypeChange($event.value)"
extraClasses="grow text-sm"
data-cy="online-resources-type"
[disabled]="disabled$ | async"
></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)"
[disabled]="disabled$ | async"
></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"
[disabled]="disabled$ | async"
></gn-ui-online-service-resource-input>
<span class="w-full border-b border-gray-300"></span>
<gn-ui-url-input
class="w-full"
[disabled]="true"
[value]="onlineResource.url"
[showUploadButton]="false"
(uploadClick)="handleServiceUrlChange($event)"
[disabled]="disabled$ | async"
></gn-ui-url-input>
</div>
</ng-template>
<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>
<div class="flex flex-col gap-[16px]">
<div>
<h3 class="text-[16px] font-bold text-main mb-[12px]" translate>
editor.record.form.field.onlineResource.edit.title
</h3>
<gn-ui-text-input [(value)]="onlineResource.name"></gn-ui-text-input>
</div>
<div>
<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>
</div>
<ng-container *ngIf="onlineResource.type === 'service'">
<span class="w-full border-b border-gray-300"></span>
<gn-ui-online-service-resource-input
[service]="onlineResource"
[disabled]="disabled$ | async"
></gn-ui-online-service-resource-input>
</ng-container>
<span class="w-full border-b border-gray-300"></span>
<gn-ui-url-input
class="w-full"
[disabled]="true"
[value]="onlineResource.url"
[showUploadButton]="false"
></gn-ui-url-input>
</div>
</ng-template>
<div
*ngIf="disabled$ | async"
class="p-4 text-sm border border-primary bg-primary-lightest rounded-lg"
translate
data-test="disabled-message"
>
editor.record.form.field.draft.only.disabled
</div>
</div>
Loading

0 comments on commit decc890

Please sign in to comment.