-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #812 from geonetwork/ME/add-image-input-component
Metadata Editor: add image input component
- Loading branch information
Showing
32 changed files
with
1,086 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 0 additions & 18 deletions
18
libs/data-access/gn4/src/openapi/model/inlineObject3.api.model.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
8 changes: 8 additions & 0 deletions
8
libs/feature/editor/src/lib/components/overview-upload/overview-upload.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<gn-ui-image-input | ||
[maxSizeMB]="5" | ||
[previewUrl]="resourceUrl" | ||
[altText]="resourceFileName" | ||
(fileChange)="handleFileChange($event)" | ||
(urlChange)="handleUrlChange($event)" | ||
(delete)="handleDelete()" | ||
></gn-ui-image-input> |
91 changes: 91 additions & 0 deletions
91
libs/feature/editor/src/lib/components/overview-upload/overview-upload.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { HttpClientTestingModule } from '@angular/common/http/testing' | ||
import { ComponentFixture, TestBed } from '@angular/core/testing' | ||
import { RecordsApiService } from '@geonetwork-ui/data-access/gn4' | ||
import { TranslateModule } from '@ngx-translate/core' | ||
import { of } from 'rxjs' | ||
import { OverviewUploadComponent } from './overview-upload.component' | ||
|
||
class RecordsApiServiceMock { | ||
getAllResources = jest.fn(() => | ||
of([{ filename: 'filenameGet', url: 'urlGet' }]) | ||
) | ||
putResource = jest.fn(() => of({ filename: 'filenamePut', url: 'urlPut' })) | ||
putResourceFromURL = jest.fn(() => | ||
of({ filename: 'filenamePutUrl', url: 'urlPutUrl' }) | ||
) | ||
delResource = jest.fn(() => of(void 0)) | ||
} | ||
|
||
const metadataUuid = '8505d991-e38f-4704-a47a-e7d335dfbef5' | ||
|
||
describe('OverviewUploadComponent', () => { | ||
let component: OverviewUploadComponent | ||
let fixture: ComponentFixture<OverviewUploadComponent> | ||
let recordsApiService: RecordsApiService | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [ | ||
OverviewUploadComponent, | ||
HttpClientTestingModule, | ||
TranslateModule.forRoot(), | ||
], | ||
providers: [ | ||
{ | ||
provide: RecordsApiService, | ||
useClass: RecordsApiServiceMock, | ||
}, | ||
], | ||
}).compileComponents() | ||
recordsApiService = TestBed.inject(RecordsApiService) | ||
|
||
fixture = TestBed.createComponent(OverviewUploadComponent) | ||
component = fixture.componentInstance | ||
component.metadataUuid = metadataUuid | ||
fixture.detectChanges() | ||
}) | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy() | ||
}) | ||
|
||
it('should get all resources corresponding to the metadata UUID on init', () => { | ||
expect(recordsApiService.getAllResources).toHaveBeenCalledWith(metadataUuid) | ||
expect(component.resourceFileName).toEqual('filenameGet') | ||
expect(component.resourceUrl).toEqual('urlGet') | ||
}) | ||
|
||
it('should put the file resource on file change', () => { | ||
const someFile = new File([], 'someFile') | ||
component.handleFileChange(someFile) | ||
expect(recordsApiService.putResource).toHaveBeenCalledWith( | ||
metadataUuid, | ||
someFile, | ||
'public' | ||
) | ||
expect(component.resourceFileName).toEqual('filenamePut') | ||
expect(component.resourceUrl).toEqual('urlPut') | ||
}) | ||
|
||
it('should put the resource from URL on URL change', () => { | ||
component.handleUrlChange('someUrl') | ||
expect(recordsApiService.putResourceFromURL).toHaveBeenCalledWith( | ||
metadataUuid, | ||
'someUrl', | ||
'public' | ||
) | ||
expect(component.resourceFileName).toEqual('filenamePutUrl') | ||
expect(component.resourceUrl).toEqual('urlPutUrl') | ||
}) | ||
|
||
it('should delete the resource corresponding to the metadata UUID on delete', () => { | ||
component.resourceFileName = 'filenameDelete' | ||
component.handleDelete() | ||
expect(recordsApiService.delResource).toHaveBeenCalledWith( | ||
metadataUuid, | ||
'filenameDelete' | ||
) | ||
expect(component.resourceFileName).toBeNull() | ||
expect(component.resourceUrl).toBeNull() | ||
}) | ||
}) |
70 changes: 70 additions & 0 deletions
70
libs/feature/editor/src/lib/components/overview-upload/overview-upload.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { | ||
ChangeDetectionStrategy, | ||
ChangeDetectorRef, | ||
Component, | ||
Input, | ||
OnInit, | ||
} from '@angular/core' | ||
import { CommonModule } from '@angular/common' | ||
import { RecordsApiService } from '@geonetwork-ui/data-access/gn4' | ||
import { UiInputsModule } from '@geonetwork-ui/ui/inputs' | ||
|
||
@Component({ | ||
selector: 'gn-ui-overview-upload', | ||
standalone: true, | ||
imports: [CommonModule, UiInputsModule], | ||
templateUrl: './overview-upload.component.html', | ||
styleUrls: ['./overview-upload.component.css'], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class OverviewUploadComponent implements OnInit { | ||
@Input() metadataUuid: string | ||
|
||
resourceFileName: string | ||
resourceUrl: string | ||
|
||
constructor( | ||
private recordsApiService: RecordsApiService, | ||
private cd: ChangeDetectorRef | ||
) {} | ||
|
||
ngOnInit(): void { | ||
this.recordsApiService | ||
.getAllResources(this.metadataUuid) | ||
.subscribe((resources) => { | ||
this.resourceFileName = resources[0]?.filename | ||
this.resourceUrl = resources[0]?.url | ||
this.cd.markForCheck() | ||
}) | ||
} | ||
|
||
handleFileChange(file: File) { | ||
this.recordsApiService | ||
.putResource(this.metadataUuid, file, 'public') | ||
.subscribe((resource) => { | ||
this.resourceFileName = resource.filename | ||
this.resourceUrl = resource.url | ||
this.cd.markForCheck() | ||
}) | ||
} | ||
|
||
handleUrlChange(url: string) { | ||
this.recordsApiService | ||
.putResourceFromURL(this.metadataUuid, url, 'public') | ||
.subscribe((resource) => { | ||
this.resourceFileName = resource.filename | ||
this.resourceUrl = resource.url | ||
this.cd.markForCheck() | ||
}) | ||
} | ||
|
||
handleDelete() { | ||
this.recordsApiService | ||
.delResource(this.metadataUuid, this.resourceFileName) | ||
.subscribe(() => { | ||
this.resourceFileName = null | ||
this.resourceUrl = null | ||
this.cd.markForCheck() | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
libs/ui/elements/src/lib/thumbnail/thumbnail.component.stories.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { | ||
componentWrapperDecorator, | ||
Meta, | ||
moduleMetadata, | ||
StoryObj, | ||
} from '@storybook/angular' | ||
import { ThumbnailComponent } from './thumbnail.component' | ||
|
||
export default { | ||
title: 'Elements/ThumbnailComponent', | ||
component: ThumbnailComponent, | ||
decorators: [ | ||
moduleMetadata({ | ||
imports: [ThumbnailComponent], | ||
}), | ||
componentWrapperDecorator( | ||
(story) => `<div style="max-width: 800px">${story}</div>` | ||
), | ||
], | ||
} as Meta<ThumbnailComponent> | ||
|
||
export const Primary: StoryObj<ThumbnailComponent> = {} |
Oops, something went wrong.