-
Notifications
You must be signed in to change notification settings - Fork 22
feat(registry-resources): resources ui draft #195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
60fd268
feat(registry-resources): resources ui draft
kpetrov24exoft 5f64001
feat(registry-resources): added resource dialog
d433280
feat(registry-resources): add, delete, update, responsivness
kpetrov24exoft d4d9131
Merge branch 'main' of https://github.com/CenterForOpenScience/angula…
kpetrov24exoft db9700e
fix(registry-resources): minor fix
kpetrov24exoft eb8b1d7
fix(registry-resources): fixes
kpetrov24exoft ac8fba6
fix(registry-resource): resource-form, fixes
kpetrov24exoft 906919f
fix(registry-resources): doi validation
kpetrov24exoft 0c1ccfe
Merge remote-tracking branch 'origin/main' into feat/245-registry-res…
nsemets 1ac8301
fix(resources): fixed some code
nsemets File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
48 changes: 48 additions & 0 deletions
48
src/app/features/registry/components/add-resource-dialog/add-resource-dialog.component.html
This file contains hidden or 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,48 @@ | ||
| @if (isCurrentResourceLoading() || isResourceConfirming()) { | ||
| <osf-loading-spinner></osf-loading-spinner> | ||
| } @else if (isPreviewMode() && currentResource()) { | ||
| <form class="flex flex-column gap-4" [formGroup]="form"> | ||
| <p>{{ 'resources.check' | translate }}</p> | ||
|
|
||
| @let resourceType = currentResource()?.type; | ||
| @let iconName = resourceType === 'analytic_code' ? 'code' : resourceType; | ||
| @let icon = `assets/icons/colored/${iconName}-colored.svg`; | ||
| @let resourceName = resourceType === RegistryResourceType.Code ? 'Analytic Code' : resourceType; | ||
|
|
||
| <div class="flex align-content-end gap-3 content"> | ||
| <img [src]="icon" alt="resource-type icon" class="align-self-start" /> | ||
| <div class="flex flex-column gap-3 mt-1"> | ||
| <div class="flex flex-column gap-2"> | ||
| <h2>{{ resourceName }}</h2> | ||
| <a [href]="'https://doi/' + currentResource()?.pid">https://doi/{{ currentResource()?.pid }}</a> | ||
| </div> | ||
| <p>{{ currentResource()?.description }}</p> | ||
| </div> | ||
| </div> | ||
|
|
||
| <div class="flex justify-content-between w-full gap-1"> | ||
| <p-button | ||
| class="btn-full-width" | ||
| [label]="'common.buttons.edit' | translate" | ||
| severity="info" | ||
| (click)="backToEdit()" | ||
| /> | ||
| <p-button | ||
| class="btn-full-width" | ||
| [label]="'resources.add' | translate" | ||
| severity="primary" | ||
| (onClick)="onAddResource()" | ||
| /> | ||
| </div> | ||
| </form> | ||
| } @else { | ||
| <osf-resource-form | ||
| [formGroup]="form" | ||
| [showCancelButton]="true" | ||
| [showPreviewButton]="false" | ||
| [cancelButtonLabel]="'common.buttons.cancel'" | ||
| [primaryButtonLabel]="'common.buttons.preview'" | ||
| (cancelClicked)="closeDialog()" | ||
| (submitClicked)="previewResource()" | ||
| /> | ||
| } |
8 changes: 8 additions & 0 deletions
8
src/app/features/registry/components/add-resource-dialog/add-resource-dialog.component.scss
This file contains hidden or 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 @@ | ||
| .content { | ||
| overflow: hidden; | ||
| text-overflow: clip; | ||
| white-space: wrap; | ||
| word-wrap: break-word; | ||
| overflow-wrap: break-word; | ||
| word-break: break-word; | ||
| } |
22 changes: 22 additions & 0 deletions
22
...pp/features/registry/components/add-resource-dialog/add-resource-dialog.component.spec.ts
This file contains hidden or 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 { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
|
||
| import { AddResourceDialogComponent } from './add-resource-dialog.component'; | ||
|
|
||
| describe('AddResourceDialogComponent', () => { | ||
| let component: AddResourceDialogComponent; | ||
| let fixture: ComponentFixture<AddResourceDialogComponent>; | ||
|
|
||
| beforeEach(async () => { | ||
| await TestBed.configureTestingModule({ | ||
| imports: [AddResourceDialogComponent], | ||
| }).compileComponents(); | ||
|
|
||
| fixture = TestBed.createComponent(AddResourceDialogComponent); | ||
| component = fixture.componentInstance; | ||
| fixture.detectChanges(); | ||
| }); | ||
|
|
||
| it('should create', () => { | ||
| expect(component).toBeTruthy(); | ||
| }); | ||
| }); |
121 changes: 121 additions & 0 deletions
121
src/app/features/registry/components/add-resource-dialog/add-resource-dialog.component.ts
This file contains hidden or 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,121 @@ | ||
| import { createDispatchMap, select } from '@ngxs/store'; | ||
|
|
||
| import { TranslatePipe, TranslateService } from '@ngx-translate/core'; | ||
|
|
||
| import { Button } from 'primeng/button'; | ||
| import { DynamicDialogConfig, DynamicDialogRef } from 'primeng/dynamicdialog'; | ||
|
|
||
| import { finalize, take } from 'rxjs'; | ||
|
|
||
| import { ChangeDetectionStrategy, Component, inject, signal } from '@angular/core'; | ||
| import { FormControl, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms'; | ||
|
|
||
| import { LoadingSpinnerComponent } from '@osf/shared/components'; | ||
| import { InputLimits } from '@osf/shared/constants'; | ||
| import { RegistryResourceType } from '@osf/shared/enums'; | ||
| import { SelectOption } from '@osf/shared/models'; | ||
| import { CustomValidators } from '@osf/shared/utils'; | ||
|
|
||
| import { resourceTypeOptions } from '../../constants'; | ||
| import { AddResource, ConfirmAddResource } from '../../models'; | ||
| import { | ||
| ConfirmAddRegistryResource, | ||
| PreviewRegistryResource, | ||
| RegistryResourcesSelectors, | ||
| SilentDelete, | ||
| } from '../../store/registry-resources'; | ||
| import { ResourceFormComponent } from '../resource-form/resource-form.component'; | ||
|
|
||
| @Component({ | ||
| selector: 'osf-add-resource-dialog', | ||
| imports: [Button, TranslatePipe, ReactiveFormsModule, LoadingSpinnerComponent, ResourceFormComponent], | ||
| templateUrl: './add-resource-dialog.component.html', | ||
| styleUrl: './add-resource-dialog.component.scss', | ||
| changeDetection: ChangeDetectionStrategy.OnPush, | ||
| }) | ||
| export class AddResourceDialogComponent { | ||
| protected readonly dialogRef = inject(DynamicDialogRef); | ||
| protected readonly currentResource = select(RegistryResourcesSelectors.getCurrentResource); | ||
| protected readonly isCurrentResourceLoading = select(RegistryResourcesSelectors.isCurrentResourceLoading); | ||
| private translateService = inject(TranslateService); | ||
|
|
||
| private dialogConfig = inject(DynamicDialogConfig); | ||
| private registryId: string = this.dialogConfig.data.id; | ||
|
|
||
| protected inputLimits = InputLimits; | ||
| protected isResourceConfirming = signal(false); | ||
|
|
||
| protected form = new FormGroup({ | ||
| pid: new FormControl<string | null>('', [CustomValidators.requiredTrimmed(), CustomValidators.doiValidator]), | ||
| resourceType: new FormControl<string | null>('', [Validators.required]), | ||
| description: new FormControl<string | null>(''), | ||
| }); | ||
|
|
||
| private readonly actions = createDispatchMap({ | ||
| previewResource: PreviewRegistryResource, | ||
| confirmAddResource: ConfirmAddRegistryResource, | ||
| deleteResource: SilentDelete, | ||
| }); | ||
|
|
||
| public resourceOptions = signal<SelectOption[]>(resourceTypeOptions); | ||
| public isPreviewMode = signal<boolean>(false); | ||
|
|
||
| protected readonly RegistryResourceType = RegistryResourceType; | ||
|
|
||
| previewResource(): void { | ||
| if (this.form.invalid) { | ||
| return; | ||
| } | ||
|
|
||
| const addResource: AddResource = { | ||
| pid: this.form.controls['pid'].value ?? '', | ||
| resource_type: this.form.controls['resourceType'].value ?? '', | ||
| description: this.form.controls['description'].value ?? '', | ||
| }; | ||
|
|
||
| const currentResource = this.currentResource(); | ||
| if (!currentResource) { | ||
| throw new Error(this.translateService.instant('resources.errors.noCurrentResource')); | ||
| } | ||
|
|
||
| this.actions.previewResource(currentResource.id, addResource).subscribe(() => { | ||
| this.isPreviewMode.set(true); | ||
| }); | ||
| } | ||
|
|
||
| backToEdit() { | ||
| this.isPreviewMode.set(false); | ||
| } | ||
|
|
||
| onAddResource() { | ||
| const addResource: ConfirmAddResource = { | ||
| finalized: true, | ||
| }; | ||
| const currentResource = this.currentResource(); | ||
|
|
||
| if (!currentResource) { | ||
| throw new Error(this.translateService.instant('resources.errors.noRegistryId')); | ||
| } | ||
|
|
||
| this.isResourceConfirming.set(true); | ||
| this.actions | ||
| .confirmAddResource(addResource, currentResource.id, this.registryId) | ||
| .pipe( | ||
| take(1), | ||
| finalize(() => { | ||
| this.dialogRef.close(true); | ||
| this.isResourceConfirming.set(false); | ||
| }) | ||
| ) | ||
| .subscribe({}); | ||
| } | ||
|
|
||
| closeDialog(): void { | ||
| this.dialogRef.close(); | ||
| const currentResource = this.currentResource(); | ||
| if (!currentResource) { | ||
| throw new Error(this.translateService.instant('resources.errors.noRegistryId')); | ||
| } | ||
| this.actions.deleteResource(currentResource.id); | ||
| } | ||
| } |
13 changes: 13 additions & 0 deletions
13
...app/features/registry/components/edit-resource-dialog/edit-resource-dialog.component.html
This file contains hidden or 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,13 @@ | ||
| @if (isCurrentResourceLoading()) { | ||
| <osf-loading-spinner></osf-loading-spinner> | ||
| } @else { | ||
| <osf-resource-form | ||
| [formGroup]="form" | ||
| [showCancelButton]="true" | ||
| [showPreviewButton]="false" | ||
| [cancelButtonLabel]="'common.buttons.cancel'" | ||
| [primaryButtonLabel]="'common.buttons.save'" | ||
| (cancelClicked)="dialogRef.close()" | ||
| (submitClicked)="save()" | ||
| /> | ||
| } |
Empty file.
22 changes: 22 additions & 0 deletions
22
.../features/registry/components/edit-resource-dialog/edit-resource-dialog.component.spec.ts
This file contains hidden or 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 { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
|
||
| import { EditResourceDialogComponent } from './edit-resource-dialog.component'; | ||
|
|
||
| describe('EditResourceDialogComponent', () => { | ||
| let component: EditResourceDialogComponent; | ||
| let fixture: ComponentFixture<EditResourceDialogComponent>; | ||
|
|
||
| beforeEach(async () => { | ||
| await TestBed.configureTestingModule({ | ||
| imports: [EditResourceDialogComponent], | ||
| }).compileComponents(); | ||
|
|
||
| fixture = TestBed.createComponent(EditResourceDialogComponent); | ||
| component = fixture.componentInstance; | ||
| fixture.detectChanges(); | ||
| }); | ||
|
|
||
| it('should create', () => { | ||
| expect(component).toBeTruthy(); | ||
| }); | ||
| }); |
78 changes: 78 additions & 0 deletions
78
src/app/features/registry/components/edit-resource-dialog/edit-resource-dialog.component.ts
This file contains hidden or 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,78 @@ | ||
| import { createDispatchMap, select } from '@ngxs/store'; | ||
|
|
||
| import { TranslateService } from '@ngx-translate/core'; | ||
|
|
||
| import { DynamicDialogConfig, DynamicDialogRef } from 'primeng/dynamicdialog'; | ||
|
|
||
| import { finalize, take } from 'rxjs'; | ||
|
|
||
| import { ChangeDetectionStrategy, Component, inject } from '@angular/core'; | ||
| import { FormControl, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms'; | ||
|
|
||
| import { LoadingSpinnerComponent } from '@osf/shared/components'; | ||
| import { CustomValidators } from '@osf/shared/utils'; | ||
|
|
||
| import { AddResource, RegistryResource } from '../../models'; | ||
| import { RegistryResourcesSelectors, UpdateResource } from '../../store/registry-resources'; | ||
| import { ResourceFormComponent } from '../resource-form/resource-form.component'; | ||
|
|
||
| @Component({ | ||
| selector: 'osf-edit-resource-dialog', | ||
| imports: [LoadingSpinnerComponent, ReactiveFormsModule, ResourceFormComponent], | ||
| templateUrl: './edit-resource-dialog.component.html', | ||
| styleUrl: './edit-resource-dialog.component.scss', | ||
| changeDetection: ChangeDetectionStrategy.OnPush, | ||
| }) | ||
| export class EditResourceDialogComponent { | ||
| protected readonly dialogRef = inject(DynamicDialogRef); | ||
| protected readonly isCurrentResourceLoading = select(RegistryResourcesSelectors.isCurrentResourceLoading); | ||
| private translateService = inject(TranslateService); | ||
|
|
||
| private dialogConfig = inject(DynamicDialogConfig); | ||
| private registryId: string = this.dialogConfig.data.id; | ||
| private resource: RegistryResource = this.dialogConfig.data.resource as RegistryResource; | ||
|
|
||
| protected form = new FormGroup({ | ||
| pid: new FormControl<string | null>('', [CustomValidators.requiredTrimmed(), CustomValidators.doiValidator]), | ||
| resourceType: new FormControl<string | null>('', [Validators.required]), | ||
| description: new FormControl<string | null>(''), | ||
| }); | ||
|
|
||
| private readonly actions = createDispatchMap({ | ||
| updateResource: UpdateResource, | ||
| }); | ||
|
|
||
| constructor() { | ||
| this.form.patchValue({ | ||
| pid: this.resource.pid || '', | ||
| resourceType: this.resource.type || '', | ||
| description: this.resource.description || '', | ||
| }); | ||
| } | ||
|
|
||
| save() { | ||
| if (this.form.invalid) { | ||
| return; | ||
| } | ||
|
|
||
| const addResource: AddResource = { | ||
| pid: this.form.controls['pid'].value ?? '', | ||
| resource_type: this.form.controls['resourceType'].value ?? '', | ||
| description: this.form.controls['description'].value ?? '', | ||
| }; | ||
|
|
||
| if (!this.resource.id) { | ||
| throw new Error(this.translateService.instant('resources.errors.noRegistryId')); | ||
| } | ||
|
|
||
| this.actions | ||
| .updateResource(this.registryId, this.resource.id, addResource) | ||
| .pipe( | ||
| take(1), | ||
| finalize(() => { | ||
| this.dialogRef.close(true); | ||
| }) | ||
| ) | ||
| .subscribe(); | ||
| } | ||
| } |
This file contains hidden or 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 |
|---|---|---|
| @@ -1,4 +1,7 @@ | ||
| export * from './add-resource-dialog/add-resource-dialog.component'; | ||
| export * from './edit-resource-dialog/edit-resource-dialog.component'; | ||
| export * from './registration-links-card/registration-links-card.component'; | ||
| export * from './registry-revisions/registry-revisions.component'; | ||
| export * from './registry-statuses/registry-statuses.component'; | ||
| export * from './resource-form/resource-form.component'; | ||
| export * from './withdraw-dialog/withdraw-dialog.component'; |
42 changes: 42 additions & 0 deletions
42
src/app/features/registry/components/resource-form/resource-form.component.html
This file contains hidden or 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,42 @@ | ||
| <form class="flex flex-column gap-4" [formGroup]="formGroup()" (ngSubmit)="handleSubmit()"> | ||
| <osf-text-input | ||
| [control]="getControl('pid')" | ||
| [label]="'DOI'" | ||
| [placeholder]="'https://doi.org/'" | ||
| [maxLength]="inputLimits.name.maxLength" | ||
| > | ||
| @if (getControl('pid').hasError('invalidDoi')) { | ||
| <span>{{ 'resources.errors.doiValidation' | translate }}</span> | ||
| } | ||
| </osf-text-input> | ||
|
|
||
| <osf-form-select | ||
| [fullWidth]="true" | ||
| [options]="resourceOptions()" | ||
| [appendTo]="'body'" | ||
| [control]="getControl('resourceType')" | ||
| [placeholder]="'resources.selectAResourceType'" | ||
| /> | ||
|
|
||
| <div> | ||
| <label [for]="'coi-reason'">{{ 'resources.descriptionLabel' | translate }}</label> | ||
| <textarea class="w-full" pTextarea id="coi-reason" [rows]="3" [formControl]="getControl('description')"></textarea> | ||
| </div> | ||
|
|
||
| <div class="flex justify-content-between w-full gap-1"> | ||
| @if (showCancelButton()) { | ||
| <p-button | ||
| class="btn-full-width" | ||
| [label]="cancelButtonLabel() | translate" | ||
| severity="info" | ||
| (click)="handleCancel()" | ||
| /> | ||
| } | ||
| <p-button | ||
| class="btn-full-width" | ||
| [label]="primaryButtonLabel() | translate" | ||
| (onClick)="handleSubmit()" | ||
| [disabled]="formGroup().invalid" | ||
| /> | ||
| </div> | ||
| </form> |
Empty file.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.