From dcae360b0660549cfd89acbf02618080569cbd69 Mon Sep 17 00:00:00 2001 From: NazarMykhalkevych Date: Wed, 30 Jul 2025 23:31:05 +0300 Subject: [PATCH 1/3] feat(regiestries): refactored wiki components --- .../registry-wiki.component.html | 44 +++++++++++++++++++ .../registry-wiki.component.scss | 0 .../registry-wiki.component.spec.ts | 22 ++++++++++ .../registry-wiki/registry-wiki.component.ts | 29 ++++++++++++ 4 files changed, 95 insertions(+) create mode 100644 src/app/features/registry/pages/registry-wiki/registry-wiki.component.html create mode 100644 src/app/features/registry/pages/registry-wiki/registry-wiki.component.scss create mode 100644 src/app/features/registry/pages/registry-wiki/registry-wiki.component.spec.ts create mode 100644 src/app/features/registry/pages/registry-wiki/registry-wiki.component.ts diff --git a/src/app/features/registry/pages/registry-wiki/registry-wiki.component.html b/src/app/features/registry/pages/registry-wiki/registry-wiki.component.html new file mode 100644 index 000000000..b06aae7a1 --- /dev/null +++ b/src/app/features/registry/pages/registry-wiki/registry-wiki.component.html @@ -0,0 +1,44 @@ + + + + + + + +
+ + +
diff --git a/src/app/features/registry/pages/registry-wiki/registry-wiki.component.scss b/src/app/features/registry/pages/registry-wiki/registry-wiki.component.scss new file mode 100644 index 000000000..e69de29bb diff --git a/src/app/features/registry/pages/registry-wiki/registry-wiki.component.spec.ts b/src/app/features/registry/pages/registry-wiki/registry-wiki.component.spec.ts new file mode 100644 index 000000000..27f113fbe --- /dev/null +++ b/src/app/features/registry/pages/registry-wiki/registry-wiki.component.spec.ts @@ -0,0 +1,22 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { RegistryWikiComponent } from './registry-wiki.component'; + +describe('RegistryWikiComponent', () => { + let component: RegistryWikiComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [RegistryWikiComponent], + }).compileComponents(); + + fixture = TestBed.createComponent(RegistryWikiComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/features/registry/pages/registry-wiki/registry-wiki.component.ts b/src/app/features/registry/pages/registry-wiki/registry-wiki.component.ts new file mode 100644 index 000000000..52407ea14 --- /dev/null +++ b/src/app/features/registry/pages/registry-wiki/registry-wiki.component.ts @@ -0,0 +1,29 @@ +import { select } from '@ngxs/store'; + +import { TranslatePipe } from '@ngx-translate/core'; + +import { Button } from 'primeng/button'; +import { ButtonGroup } from 'primeng/buttongroup'; + +import { ChangeDetectionStrategy, Component } from '@angular/core'; + +import { SubHeaderComponent } from '@osf/shared/components'; +import { WikiModes } from '@osf/shared/models'; +import { WikiSelectors } from '@osf/shared/stores'; + +@Component({ + selector: 'osf-registry-wiki', + imports: [SubHeaderComponent, Button, ButtonGroup, TranslatePipe], + templateUrl: './registry-wiki.component.html', + styleUrl: './registry-wiki.component.scss', + changeDetection: ChangeDetectionStrategy.OnPush, +}) +export class RegistryWikiComponent { + WikiModes = WikiModes; + protected wikiModes = select(WikiSelectors.getWikiModes); + + toggleMode(mode: WikiModes) { + // this.actions.toggleMode(mode); + console.log(`Toggling mode to: ${mode}`); + } +} From d69c2051b64f38ea90d3e63c8ec90ff64b18805a Mon Sep 17 00:00:00 2001 From: NazarMykhalkevych Date: Wed, 30 Jul 2025 23:36:45 +0300 Subject: [PATCH 2/3] feat(regiestries): refactored wiki components --- .../core/constants/ngxs-states.constant.ts | 3 +- .../overview-wiki/overview-wiki.component.ts | 2 +- .../overview/project-overview.component.ts | 6 +- .../features/project/wiki/services/index.ts | 1 - .../features/project/wiki/wiki.component.ts | 26 +++--- src/app/features/registry/registry.routes.ts | 5 ++ src/app/shared/components/index.ts | 1 + .../add-wiki-dialog.component.html | 0 .../add-wiki-dialog.component.scss | 0 .../add-wiki-dialog.component.spec.ts | 0 .../add-wiki-dialog.component.ts | 18 ++-- .../compare-section.component.html | 0 .../compare-section.component.scss | 0 .../compare-section.component.spec.ts | 0 .../compare-section.component.ts | 2 +- .../edit-section/edit-section.component.html | 0 .../edit-section/edit-section.component.scss | 0 .../edit-section.component.spec.ts | 0 .../edit-section/edit-section.component.ts | 0 src/app/shared/components/wiki/index.ts | 6 ++ .../view-section/view-section.component.html | 0 .../view-section/view-section.component.scss | 0 .../view-section.component.spec.ts | 0 .../view-section/view-section.component.ts | 3 +- .../wiki}/wiki-list/wiki-list.component.html | 0 .../wiki}/wiki-list/wiki-list.component.scss | 0 .../wiki-list/wiki-list.component.spec.ts | 0 .../wiki}/wiki-list/wiki-list.component.ts | 3 +- .../wiki-syntax-help-dialog.component.html | 0 .../wiki-syntax-help-dialog.component.scss | 0 .../wiki-syntax-help-dialog.component.spec.ts | 0 .../wiki-syntax-help-dialog.component.ts | 0 .../mappers => shared/mappers/wiki}/index.ts | 0 .../mappers/wiki}/wiki.mapper.ts | 2 +- src/app/shared/models/index.ts | 1 + .../models => shared/models/wiki}/index.ts | 0 .../models/wiki}/wiki.model.ts | 0 .../models/wiki}/wikiMenu.model.ts | 0 .../models/wiki}/wikiType.model.ts | 0 src/app/shared/services/index.ts | 1 + .../wiki => shared}/services/wiki.service.ts | 86 +++++++++++-------- src/app/shared/stores/index.ts | 1 + .../store => shared/stores/wiki}/index.ts | 0 .../stores/wiki}/wiki.actions.ts | 26 ++++-- .../stores/wiki}/wiki.model.ts | 8 +- .../stores/wiki}/wiki.selectors.ts | 12 +-- .../stores/wiki}/wiki.state.ts | 52 +++++------ 47 files changed, 154 insertions(+), 111 deletions(-) delete mode 100644 src/app/features/project/wiki/services/index.ts rename src/app/{features/project/wiki/components => shared/components/wiki}/add-wiki-dialog/add-wiki-dialog.component.html (100%) rename src/app/{features/project/wiki/components => shared/components/wiki}/add-wiki-dialog/add-wiki-dialog.component.scss (100%) rename src/app/{features/project/wiki/components => shared/components/wiki}/add-wiki-dialog/add-wiki-dialog.component.spec.ts (100%) rename src/app/{features/project/wiki/components => shared/components/wiki}/add-wiki-dialog/add-wiki-dialog.component.ts (78%) rename src/app/{features/project/wiki/components => shared/components/wiki}/compare-section/compare-section.component.html (100%) rename src/app/{features/project/wiki/components => shared/components/wiki}/compare-section/compare-section.component.scss (100%) rename src/app/{features/project/wiki/components => shared/components/wiki}/compare-section/compare-section.component.spec.ts (100%) rename src/app/{features/project/wiki/components => shared/components/wiki}/compare-section/compare-section.component.ts (97%) rename src/app/{features/project/wiki/components => shared/components/wiki}/edit-section/edit-section.component.html (100%) rename src/app/{features/project/wiki/components => shared/components/wiki}/edit-section/edit-section.component.scss (100%) rename src/app/{features/project/wiki/components => shared/components/wiki}/edit-section/edit-section.component.spec.ts (100%) rename src/app/{features/project/wiki/components => shared/components/wiki}/edit-section/edit-section.component.ts (100%) create mode 100644 src/app/shared/components/wiki/index.ts rename src/app/{features/project/wiki/components => shared/components/wiki}/view-section/view-section.component.html (100%) rename src/app/{features/project/wiki/components => shared/components/wiki}/view-section/view-section.component.scss (100%) rename src/app/{features/project/wiki/components => shared/components/wiki}/view-section/view-section.component.spec.ts (100%) rename src/app/{features/project/wiki/components => shared/components/wiki}/view-section/view-section.component.ts (97%) rename src/app/{features/project/wiki/components => shared/components/wiki}/wiki-list/wiki-list.component.html (100%) rename src/app/{features/project/wiki/components => shared/components/wiki}/wiki-list/wiki-list.component.scss (100%) rename src/app/{features/project/wiki/components => shared/components/wiki}/wiki-list/wiki-list.component.spec.ts (100%) rename src/app/{features/project/wiki/components => shared/components/wiki}/wiki-list/wiki-list.component.ts (97%) rename src/app/{features/project/wiki/components => shared/components/wiki}/wiki-syntax-help-dialog/wiki-syntax-help-dialog.component.html (100%) rename src/app/{features/project/wiki/components => shared/components/wiki}/wiki-syntax-help-dialog/wiki-syntax-help-dialog.component.scss (100%) rename src/app/{features/project/wiki/components => shared/components/wiki}/wiki-syntax-help-dialog/wiki-syntax-help-dialog.component.spec.ts (100%) rename src/app/{features/project/wiki/components => shared/components/wiki}/wiki-syntax-help-dialog/wiki-syntax-help-dialog.component.ts (100%) rename src/app/{features/project/wiki/mappers => shared/mappers/wiki}/index.ts (100%) rename src/app/{features/project/wiki/mappers => shared/mappers/wiki}/wiki.mapper.ts (98%) rename src/app/{features/project/wiki/models => shared/models/wiki}/index.ts (100%) rename src/app/{features/project/wiki/models => shared/models/wiki}/wiki.model.ts (100%) rename src/app/{features/project/wiki/models => shared/models/wiki}/wikiMenu.model.ts (100%) rename src/app/{features/project/wiki/models => shared/models/wiki}/wikiType.model.ts (100%) rename src/app/{features/project/wiki => shared}/services/wiki.service.ts (53%) rename src/app/{features/project/wiki/store => shared/stores/wiki}/index.ts (100%) rename src/app/{features/project/wiki/store => shared/stores/wiki}/wiki.actions.ts (77%) rename src/app/{features/project/wiki/store => shared/stores/wiki}/wiki.model.ts (69%) rename src/app/{features/project/wiki/store => shared/stores/wiki}/wiki.selectors.ts (88%) rename src/app/{features/project/wiki/store => shared/stores/wiki}/wiki.state.ts (87%) diff --git a/src/app/core/constants/ngxs-states.constant.ts b/src/app/core/constants/ngxs-states.constant.ts index 1ddf3f7c2..1fc6a949c 100644 --- a/src/app/core/constants/ngxs-states.constant.ts +++ b/src/app/core/constants/ngxs-states.constant.ts @@ -4,11 +4,10 @@ import { MeetingsState } from '@osf/features/meetings/store'; import { ProjectMetadataState } from '@osf/features/project/metadata/store'; import { ProjectOverviewState } from '@osf/features/project/overview/store'; import { RegistrationsState } from '@osf/features/project/registrations/store'; -import { WikiState } from '@osf/features/project/wiki/store/wiki.state'; import { AccountSettingsState } from '@osf/features/settings/account-settings/store/account-settings.state'; import { DeveloperAppsState } from '@osf/features/settings/developer-apps/store'; import { NotificationSubscriptionState } from '@osf/features/settings/notifications/store'; -import { AddonsState, InstitutionsState } from '@shared/stores'; +import { AddonsState, InstitutionsState, WikiState } from '@shared/stores'; import { LicensesState } from '@shared/stores/licenses'; import { RegionsState } from '@shared/stores/regions'; diff --git a/src/app/features/project/overview/components/overview-wiki/overview-wiki.component.ts b/src/app/features/project/overview/components/overview-wiki/overview-wiki.component.ts index 55245fb21..26e3d8e85 100644 --- a/src/app/features/project/overview/components/overview-wiki/overview-wiki.component.ts +++ b/src/app/features/project/overview/components/overview-wiki/overview-wiki.component.ts @@ -6,7 +6,7 @@ import { Skeleton } from 'primeng/skeleton'; import { ChangeDetectionStrategy, Component } from '@angular/core'; -import { WikiSelectors } from '@osf/features/project/wiki/store'; +import { WikiSelectors } from '@osf/shared/stores'; import { MarkdownComponent, TruncatedTextComponent } from '@shared/components'; @Component({ diff --git a/src/app/features/project/overview/project-overview.component.ts b/src/app/features/project/overview/project-overview.component.ts index d869bb6c2..13b5debd0 100644 --- a/src/app/features/project/overview/project-overview.component.ts +++ b/src/app/features/project/overview/project-overview.component.ts @@ -13,9 +13,7 @@ import { ClearCollections } from '@osf/features/collections/store/collections'; import { LoadingSpinnerComponent, ResourceMetadataComponent, SubHeaderComponent } from '@shared/components'; import { ResourceType } from '@shared/enums'; import { MapProjectOverview } from '@shared/mappers/resource-overview.mappers'; -import { GetAllNodeLinks, GetBookmarksCollectionId, GetLinkedResources } from '@shared/stores'; - -import { ClearWiki, GetHomeWiki } from '../wiki/store'; +import { ClearWiki, GetAllNodeLinks, GetBookmarksCollectionId, GetHomeWiki, GetLinkedResources } from '@shared/stores'; import { LinkedResourcesComponent, @@ -97,7 +95,7 @@ export class ProjectOverviewComponent implements OnInit { if (projectId) { this.actions.getProject(projectId); this.actions.getBookmarksId(); - this.actions.getHomeWiki(projectId); + this.actions.getHomeWiki(ResourceType.Project, projectId); this.actions.getComponents(projectId); this.actions.getNodeLinks(projectId); this.actions.getLinkedProjects(projectId); diff --git a/src/app/features/project/wiki/services/index.ts b/src/app/features/project/wiki/services/index.ts deleted file mode 100644 index 054b651c3..000000000 --- a/src/app/features/project/wiki/services/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './wiki.service'; diff --git a/src/app/features/project/wiki/wiki.component.ts b/src/app/features/project/wiki/wiki.component.ts index f9bcd216e..ab373007a 100644 --- a/src/app/features/project/wiki/wiki.component.ts +++ b/src/app/features/project/wiki/wiki.component.ts @@ -11,15 +11,16 @@ import { ChangeDetectionStrategy, Component, inject } from '@angular/core'; import { takeUntilDestroyed, toSignal } from '@angular/core/rxjs-interop'; import { ActivatedRoute, Router } from '@angular/router'; -import { SubHeaderComponent } from '@osf/shared/components'; +import { + CompareSectionComponent, + EditSectionComponent, + SubHeaderComponent, + ViewSectionComponent, + WikiListComponent, +} from '@osf/shared/components'; +import { ResourceType } from '@osf/shared/enums'; +import { WikiModes } from '@osf/shared/models'; import { ToastService } from '@osf/shared/services'; - -import { CompareSectionComponent } from './components/compare-section/compare-section.component'; -import { EditSectionComponent } from './components/edit-section/edit-section.component'; -import { ViewSectionComponent } from './components/view-section/view-section.component'; -import { WikiListComponent } from './components/wiki-list/wiki-list.component'; -import { WikiSelectors } from './store/wiki.selectors'; -import { WikiModes } from './models'; import { CreateWiki, CreateWikiVersion, @@ -34,7 +35,8 @@ import { SetCurrentWiki, ToggleMode, UpdateWikiPreviewContent, -} from './store'; + WikiSelectors, +} from '@osf/shared/stores'; const HomeWikiName = 'Home'; @@ -94,7 +96,7 @@ export class WikiComponent { constructor() { this.actions - .getWikiList(this.projectId()) + .getWikiList(ResourceType.Project, this.projectId()) .pipe( takeUntilDestroyed(), tap(() => { @@ -102,13 +104,13 @@ export class WikiComponent { this.navigateToWiki(this.wikiList()?.[0]?.id || ''); } if (!this.wikiList()?.length) { - this.actions.createWiki(this.projectId(), HomeWikiName); + this.actions.createWiki(ResourceType.Project, this.projectId(), HomeWikiName); } }) ) .subscribe(); - this.actions.getComponentsWikiList(this.projectId()); + this.actions.getComponentsWikiList(ResourceType.Project, this.projectId()); this.route.queryParams .pipe( diff --git a/src/app/features/registry/registry.routes.ts b/src/app/features/registry/registry.routes.ts index e83315faa..9f2fafa6c 100644 --- a/src/app/features/registry/registry.routes.ts +++ b/src/app/features/registry/registry.routes.ts @@ -86,6 +86,11 @@ export const registryRoutes: Routes = [ ), providers: [provideStates([RegistryResourcesState])], }, + { + path: 'wiki', + loadComponent: () => + import('./pages/registry-wiki/registry-wiki.component').then((c) => c.RegistryWikiComponent), + }, ], }, ]; diff --git a/src/app/shared/components/index.ts b/src/app/shared/components/index.ts index 0ece2d97d..47b95dc18 100644 --- a/src/app/shared/components/index.ts +++ b/src/app/shared/components/index.ts @@ -40,3 +40,4 @@ export { TextInputComponent } from './text-input/text-input.component'; export { ToastComponent } from './toast/toast.component'; export { TruncatedTextComponent } from './truncated-text/truncated-text.component'; export { ViewOnlyTableComponent } from './view-only-table/view-only-table.component'; +export * from './wiki'; diff --git a/src/app/features/project/wiki/components/add-wiki-dialog/add-wiki-dialog.component.html b/src/app/shared/components/wiki/add-wiki-dialog/add-wiki-dialog.component.html similarity index 100% rename from src/app/features/project/wiki/components/add-wiki-dialog/add-wiki-dialog.component.html rename to src/app/shared/components/wiki/add-wiki-dialog/add-wiki-dialog.component.html diff --git a/src/app/features/project/wiki/components/add-wiki-dialog/add-wiki-dialog.component.scss b/src/app/shared/components/wiki/add-wiki-dialog/add-wiki-dialog.component.scss similarity index 100% rename from src/app/features/project/wiki/components/add-wiki-dialog/add-wiki-dialog.component.scss rename to src/app/shared/components/wiki/add-wiki-dialog/add-wiki-dialog.component.scss diff --git a/src/app/features/project/wiki/components/add-wiki-dialog/add-wiki-dialog.component.spec.ts b/src/app/shared/components/wiki/add-wiki-dialog/add-wiki-dialog.component.spec.ts similarity index 100% rename from src/app/features/project/wiki/components/add-wiki-dialog/add-wiki-dialog.component.spec.ts rename to src/app/shared/components/wiki/add-wiki-dialog/add-wiki-dialog.component.spec.ts diff --git a/src/app/features/project/wiki/components/add-wiki-dialog/add-wiki-dialog.component.ts b/src/app/shared/components/wiki/add-wiki-dialog/add-wiki-dialog.component.ts similarity index 78% rename from src/app/features/project/wiki/components/add-wiki-dialog/add-wiki-dialog.component.ts rename to src/app/shared/components/wiki/add-wiki-dialog/add-wiki-dialog.component.ts index 1aff949e5..9a1822440 100644 --- a/src/app/features/project/wiki/components/add-wiki-dialog/add-wiki-dialog.component.ts +++ b/src/app/shared/components/wiki/add-wiki-dialog/add-wiki-dialog.component.ts @@ -10,11 +10,11 @@ import { FormControl, FormGroup, ReactiveFormsModule, Validators } from '@angula import { TextInputComponent } from '@osf/shared/components'; import { InputLimits } from '@osf/shared/constants'; +import { ResourceType } from '@osf/shared/enums'; import { ToastService } from '@osf/shared/services'; +import { CreateWiki, WikiSelectors } from '@osf/shared/stores'; import { CustomValidators } from '@osf/shared/utils'; -import { CreateWiki, WikiSelectors } from '../../store'; - @Component({ selector: 'osf-add-wiki-dialog-component', imports: [Button, ReactiveFormsModule, TranslatePipe, TextInputComponent], @@ -41,12 +41,14 @@ export class AddWikiDialogComponent { submitForm(): void { if (this.addWikiForm.valid) { - this.actions.createWiki(this.config.data.projectId, this.addWikiForm.value.name ?? '').subscribe({ - next: (res) => { - this.toastService.showSuccess('project.wiki.addWikiSuccess'); - this.dialogRef.close(res); - }, - }); + this.actions + .createWiki(ResourceType.Project, this.config.data.projectId, this.addWikiForm.value.name ?? '') + .subscribe({ + next: (res) => { + this.toastService.showSuccess('project.wiki.addWikiSuccess'); + this.dialogRef.close(res); + }, + }); } } } diff --git a/src/app/features/project/wiki/components/compare-section/compare-section.component.html b/src/app/shared/components/wiki/compare-section/compare-section.component.html similarity index 100% rename from src/app/features/project/wiki/components/compare-section/compare-section.component.html rename to src/app/shared/components/wiki/compare-section/compare-section.component.html diff --git a/src/app/features/project/wiki/components/compare-section/compare-section.component.scss b/src/app/shared/components/wiki/compare-section/compare-section.component.scss similarity index 100% rename from src/app/features/project/wiki/components/compare-section/compare-section.component.scss rename to src/app/shared/components/wiki/compare-section/compare-section.component.scss diff --git a/src/app/features/project/wiki/components/compare-section/compare-section.component.spec.ts b/src/app/shared/components/wiki/compare-section/compare-section.component.spec.ts similarity index 100% rename from src/app/features/project/wiki/components/compare-section/compare-section.component.spec.ts rename to src/app/shared/components/wiki/compare-section/compare-section.component.spec.ts diff --git a/src/app/features/project/wiki/components/compare-section/compare-section.component.ts b/src/app/shared/components/wiki/compare-section/compare-section.component.ts similarity index 97% rename from src/app/features/project/wiki/components/compare-section/compare-section.component.ts rename to src/app/shared/components/wiki/compare-section/compare-section.component.ts index 901b1130f..4c466f3c2 100644 --- a/src/app/features/project/wiki/components/compare-section/compare-section.component.ts +++ b/src/app/shared/components/wiki/compare-section/compare-section.component.ts @@ -7,7 +7,7 @@ import { Skeleton } from 'primeng/skeleton'; import { ChangeDetectionStrategy, Component, computed, effect, input, output } from '@angular/core'; import { FormsModule } from '@angular/forms'; -import { WikiVersion } from '../../models'; +import { WikiVersion } from '@osf/shared/models'; import * as Diff from 'diff'; diff --git a/src/app/features/project/wiki/components/edit-section/edit-section.component.html b/src/app/shared/components/wiki/edit-section/edit-section.component.html similarity index 100% rename from src/app/features/project/wiki/components/edit-section/edit-section.component.html rename to src/app/shared/components/wiki/edit-section/edit-section.component.html diff --git a/src/app/features/project/wiki/components/edit-section/edit-section.component.scss b/src/app/shared/components/wiki/edit-section/edit-section.component.scss similarity index 100% rename from src/app/features/project/wiki/components/edit-section/edit-section.component.scss rename to src/app/shared/components/wiki/edit-section/edit-section.component.scss diff --git a/src/app/features/project/wiki/components/edit-section/edit-section.component.spec.ts b/src/app/shared/components/wiki/edit-section/edit-section.component.spec.ts similarity index 100% rename from src/app/features/project/wiki/components/edit-section/edit-section.component.spec.ts rename to src/app/shared/components/wiki/edit-section/edit-section.component.spec.ts diff --git a/src/app/features/project/wiki/components/edit-section/edit-section.component.ts b/src/app/shared/components/wiki/edit-section/edit-section.component.ts similarity index 100% rename from src/app/features/project/wiki/components/edit-section/edit-section.component.ts rename to src/app/shared/components/wiki/edit-section/edit-section.component.ts diff --git a/src/app/shared/components/wiki/index.ts b/src/app/shared/components/wiki/index.ts new file mode 100644 index 000000000..79047f684 --- /dev/null +++ b/src/app/shared/components/wiki/index.ts @@ -0,0 +1,6 @@ +export * from './add-wiki-dialog/add-wiki-dialog.component'; +export * from './compare-section/compare-section.component'; +export * from './edit-section/edit-section.component'; +export * from './view-section/view-section.component'; +export * from './wiki-list/wiki-list.component'; +export * from './wiki-syntax-help-dialog/wiki-syntax-help-dialog.component'; diff --git a/src/app/features/project/wiki/components/view-section/view-section.component.html b/src/app/shared/components/wiki/view-section/view-section.component.html similarity index 100% rename from src/app/features/project/wiki/components/view-section/view-section.component.html rename to src/app/shared/components/wiki/view-section/view-section.component.html diff --git a/src/app/features/project/wiki/components/view-section/view-section.component.scss b/src/app/shared/components/wiki/view-section/view-section.component.scss similarity index 100% rename from src/app/features/project/wiki/components/view-section/view-section.component.scss rename to src/app/shared/components/wiki/view-section/view-section.component.scss diff --git a/src/app/features/project/wiki/components/view-section/view-section.component.spec.ts b/src/app/shared/components/wiki/view-section/view-section.component.spec.ts similarity index 100% rename from src/app/features/project/wiki/components/view-section/view-section.component.spec.ts rename to src/app/shared/components/wiki/view-section/view-section.component.spec.ts diff --git a/src/app/features/project/wiki/components/view-section/view-section.component.ts b/src/app/shared/components/wiki/view-section/view-section.component.ts similarity index 97% rename from src/app/features/project/wiki/components/view-section/view-section.component.ts rename to src/app/shared/components/wiki/view-section/view-section.component.ts index 65e1d89b2..c742fd91b 100644 --- a/src/app/features/project/wiki/components/view-section/view-section.component.ts +++ b/src/app/shared/components/wiki/view-section/view-section.component.ts @@ -8,8 +8,7 @@ import { ChangeDetectionStrategy, Component, computed, effect, input, output, si import { FormsModule } from '@angular/forms'; import { MarkdownComponent } from '@osf/shared/components'; - -import { WikiVersion } from '../../models'; +import { WikiVersion } from '@osf/shared/models'; @Component({ selector: 'osf-view-section', diff --git a/src/app/features/project/wiki/components/wiki-list/wiki-list.component.html b/src/app/shared/components/wiki/wiki-list/wiki-list.component.html similarity index 100% rename from src/app/features/project/wiki/components/wiki-list/wiki-list.component.html rename to src/app/shared/components/wiki/wiki-list/wiki-list.component.html diff --git a/src/app/features/project/wiki/components/wiki-list/wiki-list.component.scss b/src/app/shared/components/wiki/wiki-list/wiki-list.component.scss similarity index 100% rename from src/app/features/project/wiki/components/wiki-list/wiki-list.component.scss rename to src/app/shared/components/wiki/wiki-list/wiki-list.component.scss diff --git a/src/app/features/project/wiki/components/wiki-list/wiki-list.component.spec.ts b/src/app/shared/components/wiki/wiki-list/wiki-list.component.spec.ts similarity index 100% rename from src/app/features/project/wiki/components/wiki-list/wiki-list.component.spec.ts rename to src/app/shared/components/wiki/wiki-list/wiki-list.component.spec.ts diff --git a/src/app/features/project/wiki/components/wiki-list/wiki-list.component.ts b/src/app/shared/components/wiki/wiki-list/wiki-list.component.ts similarity index 97% rename from src/app/features/project/wiki/components/wiki-list/wiki-list.component.ts rename to src/app/shared/components/wiki/wiki-list/wiki-list.component.ts index 147feed49..9f024e438 100644 --- a/src/app/features/project/wiki/components/wiki-list/wiki-list.component.ts +++ b/src/app/shared/components/wiki/wiki-list/wiki-list.component.ts @@ -10,10 +10,9 @@ import { Skeleton } from 'primeng/skeleton'; import { ChangeDetectionStrategy, Component, computed, inject, input, output, signal } from '@angular/core'; import { Router, RouterModule } from '@angular/router'; +import { ComponentWiki, Wiki, WikiItemType, WikiMenuItem } from '@osf/shared/models'; import { CustomConfirmationService } from '@osf/shared/services'; -import { Wiki, WikiItemType, WikiMenuItem } from '../../models'; -import { ComponentWiki } from '../../store'; import { AddWikiDialogComponent } from '../add-wiki-dialog/add-wiki-dialog.component'; @Component({ diff --git a/src/app/features/project/wiki/components/wiki-syntax-help-dialog/wiki-syntax-help-dialog.component.html b/src/app/shared/components/wiki/wiki-syntax-help-dialog/wiki-syntax-help-dialog.component.html similarity index 100% rename from src/app/features/project/wiki/components/wiki-syntax-help-dialog/wiki-syntax-help-dialog.component.html rename to src/app/shared/components/wiki/wiki-syntax-help-dialog/wiki-syntax-help-dialog.component.html diff --git a/src/app/features/project/wiki/components/wiki-syntax-help-dialog/wiki-syntax-help-dialog.component.scss b/src/app/shared/components/wiki/wiki-syntax-help-dialog/wiki-syntax-help-dialog.component.scss similarity index 100% rename from src/app/features/project/wiki/components/wiki-syntax-help-dialog/wiki-syntax-help-dialog.component.scss rename to src/app/shared/components/wiki/wiki-syntax-help-dialog/wiki-syntax-help-dialog.component.scss diff --git a/src/app/features/project/wiki/components/wiki-syntax-help-dialog/wiki-syntax-help-dialog.component.spec.ts b/src/app/shared/components/wiki/wiki-syntax-help-dialog/wiki-syntax-help-dialog.component.spec.ts similarity index 100% rename from src/app/features/project/wiki/components/wiki-syntax-help-dialog/wiki-syntax-help-dialog.component.spec.ts rename to src/app/shared/components/wiki/wiki-syntax-help-dialog/wiki-syntax-help-dialog.component.spec.ts diff --git a/src/app/features/project/wiki/components/wiki-syntax-help-dialog/wiki-syntax-help-dialog.component.ts b/src/app/shared/components/wiki/wiki-syntax-help-dialog/wiki-syntax-help-dialog.component.ts similarity index 100% rename from src/app/features/project/wiki/components/wiki-syntax-help-dialog/wiki-syntax-help-dialog.component.ts rename to src/app/shared/components/wiki/wiki-syntax-help-dialog/wiki-syntax-help-dialog.component.ts diff --git a/src/app/features/project/wiki/mappers/index.ts b/src/app/shared/mappers/wiki/index.ts similarity index 100% rename from src/app/features/project/wiki/mappers/index.ts rename to src/app/shared/mappers/wiki/index.ts diff --git a/src/app/features/project/wiki/mappers/wiki.mapper.ts b/src/app/shared/mappers/wiki/wiki.mapper.ts similarity index 98% rename from src/app/features/project/wiki/mappers/wiki.mapper.ts rename to src/app/shared/mappers/wiki/wiki.mapper.ts index 069a7f432..e02ed964c 100644 --- a/src/app/features/project/wiki/mappers/wiki.mapper.ts +++ b/src/app/shared/mappers/wiki/wiki.mapper.ts @@ -7,7 +7,7 @@ import { WikiGetResponse, WikiVersion, WikiVersionJsonApi, -} from '../models'; +} from '@osf/shared/models'; export class WikiMapper { static fromCreateWikiResponse(response: WikiGetResponse): Wiki { diff --git a/src/app/shared/models/index.ts b/src/app/shared/models/index.ts index 33f9c295b..731f5a1f0 100644 --- a/src/app/shared/models/index.ts +++ b/src/app/shared/models/index.ts @@ -45,3 +45,4 @@ export * from './tutorial-step.model'; export * from './user'; export * from './validation-params.model'; export * from './view-only-links'; +export * from './wiki'; diff --git a/src/app/features/project/wiki/models/index.ts b/src/app/shared/models/wiki/index.ts similarity index 100% rename from src/app/features/project/wiki/models/index.ts rename to src/app/shared/models/wiki/index.ts diff --git a/src/app/features/project/wiki/models/wiki.model.ts b/src/app/shared/models/wiki/wiki.model.ts similarity index 100% rename from src/app/features/project/wiki/models/wiki.model.ts rename to src/app/shared/models/wiki/wiki.model.ts diff --git a/src/app/features/project/wiki/models/wikiMenu.model.ts b/src/app/shared/models/wiki/wikiMenu.model.ts similarity index 100% rename from src/app/features/project/wiki/models/wikiMenu.model.ts rename to src/app/shared/models/wiki/wikiMenu.model.ts diff --git a/src/app/features/project/wiki/models/wikiType.model.ts b/src/app/shared/models/wiki/wikiType.model.ts similarity index 100% rename from src/app/features/project/wiki/models/wikiType.model.ts rename to src/app/shared/models/wiki/wikiType.model.ts diff --git a/src/app/shared/services/index.ts b/src/app/shared/services/index.ts index be5219379..fc5aa6a57 100644 --- a/src/app/shared/services/index.ts +++ b/src/app/shared/services/index.ts @@ -16,3 +16,4 @@ export { SearchService } from './search.service'; export { SubjectsService } from './subjects.service'; export { ToastService } from './toast.service'; export { ViewOnlyLinksService } from './view-only-links.service'; +export { WikiService } from './wiki.service'; diff --git a/src/app/features/project/wiki/services/wiki.service.ts b/src/app/shared/services/wiki.service.ts similarity index 53% rename from src/app/features/project/wiki/services/wiki.service.ts rename to src/app/shared/services/wiki.service.ts index c326ca2c2..26567502c 100644 --- a/src/app/features/project/wiki/services/wiki.service.ts +++ b/src/app/shared/services/wiki.service.ts @@ -7,9 +7,11 @@ import { inject, Injectable } from '@angular/core'; import { JsonApiResponse } from '@core/models'; import { JsonApiService } from '@osf/core/services'; -import { WikiMapper } from '../mappers'; +import { ResourceType } from '../enums'; +import { WikiMapper } from '../mappers/wiki'; import { ComponentsWikiJsonApiResponse, + ComponentWiki, HomeWikiJsonApiResponse, Wiki, WikiGetResponse, @@ -17,7 +19,6 @@ import { WikiVersion, WikiVersionJsonApiResponse, } from '../models'; -import { ComponentWiki } from '../store'; import { environment } from 'src/environments/environment'; @@ -25,8 +26,24 @@ import { environment } from 'src/environments/environment'; providedIn: 'root', }) export class WikiService { - readonly #jsonApiService = inject(JsonApiService); - readonly #http = inject(HttpClient); + private readonly jsonApiService = inject(JsonApiService); + readonly http = inject(HttpClient); + + private readonly urlMap = new Map([ + [ResourceType.Project, 'nodes'], + [ResourceType.Registration, 'registrations'], + ]); + + private getBaseUrl(resourceType: ResourceType, resourceId: string): string { + const baseUrl = `${environment.apiUrl}`; + const resourcePath = this.urlMap.get(resourceType); + + if (!resourcePath) { + throw new Error(`Unsupported resource type: ${resourceType}`); + } + + return `${baseUrl}/${resourcePath}/${resourceId}/wikis`; + } createWiki(projectId: string, name: string): Observable { const body = { @@ -37,7 +54,7 @@ export class WikiService { }, }, }; - return this.#jsonApiService + return this.jsonApiService .post>(environment.apiUrl + `/nodes/${projectId}/wikis/`, body) .pipe( map((response) => { @@ -47,42 +64,43 @@ export class WikiService { } deleteWiki(wikiId: string): Observable { - return this.#jsonApiService.delete(environment.apiUrl + `/wikis/${wikiId}/`); + return this.jsonApiService.delete(environment.apiUrl + `/wikis/${wikiId}/`); } - getHomeWiki(projectId: string): Observable { + getHomeWiki(resourceType: ResourceType, resourceId: string): Observable { + const baseUrl = this.getBaseUrl(resourceType, resourceId); const params: Record = { 'filter[name]': 'home', }; - return this.#jsonApiService - .get(environment.apiUrl + `/nodes/${projectId}/wikis/`, params) - .pipe( - map((response) => { - const homeWiki = response.data.find((wiki) => wiki.attributes.name.toLocaleLowerCase() === 'home'); - if (!homeWiki) { - return ''; - } - const wiki = WikiMapper.fromGetHomeWikiResponse(homeWiki); - return wiki.downloadLink; - }), - switchMap((downloadLink) => { - if (!downloadLink) { - return of(''); - } - return this.#http.get(downloadLink, { responseType: 'text' }); - }) - ); + return this.jsonApiService.get(baseUrl, params).pipe( + map((response) => { + const homeWiki = response.data.find((wiki) => wiki.attributes.name.toLocaleLowerCase() === 'home'); + if (!homeWiki) { + return ''; + } + const wiki = WikiMapper.fromGetHomeWikiResponse(homeWiki); + return wiki.downloadLink; + }), + switchMap((downloadLink) => { + if (!downloadLink) { + return of(''); + } + return this.http.get(downloadLink, { responseType: 'text' }); + }) + ); } - getWikiList(projectId: string): Observable { - return this.#jsonApiService - .get(environment.apiUrl + `/nodes/${projectId}/wikis/`) + getWikiList(resourceType: ResourceType, resourceId: string): Observable { + const baseUrl = this.getBaseUrl(resourceType, resourceId); + return this.jsonApiService + .get(baseUrl) .pipe(map((response) => response.data.map((wiki) => WikiMapper.fromGetWikiResponse(wiki)))); } - getComponentsWikiList(projectId: string): Observable { - return this.#jsonApiService - .get(environment.apiUrl + `/nodes/${projectId}/children/?embed=wikis`) + getComponentsWikiList(resourceType: ResourceType, resourceId: string): Observable { + const resourcePath = this.urlMap.get(resourceType); + return this.jsonApiService + .get(environment.apiUrl + `/${resourcePath}/${resourceId}/children/?embed=wikis`) .pipe(map((response) => response.data.map((component) => WikiMapper.fromGetComponentsWikiResponse(component)))); } @@ -91,7 +109,7 @@ export class WikiService { embed: 'user', 'fields[users]': 'full_name', }; - return this.#jsonApiService + return this.jsonApiService .get(environment.apiUrl + `/wikis/${wikiId}/versions/`, params) .pipe( map((response) => { @@ -109,7 +127,7 @@ export class WikiService { }, }, }; - return this.#jsonApiService + return this.jsonApiService .post>(environment.apiUrl + `/wikis/${wikiId}/versions/`, body) .pipe( map((response) => { @@ -119,7 +137,7 @@ export class WikiService { } getWikiVersionContent(wikiId: string, versionId: string): Observable { - return this.#http.get(environment.apiUrl + `/wikis/${wikiId}/versions/${versionId}/content/`, { + return this.http.get(environment.apiUrl + `/wikis/${wikiId}/versions/${versionId}/content/`, { responseType: 'text', }); } diff --git a/src/app/shared/stores/index.ts b/src/app/shared/stores/index.ts index 4e519e0a1..2f04bbd80 100644 --- a/src/app/shared/stores/index.ts +++ b/src/app/shared/stores/index.ts @@ -9,3 +9,4 @@ export * from './node-links'; export * from './projects'; export * from './subjects'; export * from './view-only-links'; +export * from './wiki'; diff --git a/src/app/features/project/wiki/store/index.ts b/src/app/shared/stores/wiki/index.ts similarity index 100% rename from src/app/features/project/wiki/store/index.ts rename to src/app/shared/stores/wiki/index.ts diff --git a/src/app/features/project/wiki/store/wiki.actions.ts b/src/app/shared/stores/wiki/wiki.actions.ts similarity index 77% rename from src/app/features/project/wiki/store/wiki.actions.ts rename to src/app/shared/stores/wiki/wiki.actions.ts index 80120530f..ccf9bb1b2 100644 --- a/src/app/features/project/wiki/store/wiki.actions.ts +++ b/src/app/shared/stores/wiki/wiki.actions.ts @@ -1,10 +1,12 @@ -import { WikiModes } from '../models'; +import { ResourceType } from '@osf/shared/enums'; +import { WikiModes } from '@osf/shared/models'; export class CreateWiki { static readonly type = '[Wiki] Create Wiki'; constructor( - public projectId: string, + public resourceType: ResourceType, + public resourceId: string, public name: string ) {} } @@ -17,7 +19,10 @@ export class DeleteWiki { export class GetHomeWiki { static readonly type = '[Wiki] Get Home Wiki'; - constructor(public projectId: string) {} + constructor( + public resourceType: ResourceType, + public resourceId: string + ) {} } export class ClearWiki { @@ -27,19 +32,28 @@ export class ClearWiki { export class GetWikiList { static readonly type = '[Wiki] Get Wiki List'; - constructor(public projectId: string) {} + constructor( + public resourceType: ResourceType, + public resourceId: string + ) {} } export class GetComponentsWikiList { static readonly type = '[Wiki] Get Components Wiki List'; - constructor(public projectId: string) {} + constructor( + public resourceType: ResourceType, + public resourceId: string + ) {} } export class GetWikiModes { static readonly type = '[Wiki] Get Wiki Modes'; - constructor(public projectId: string) {} + constructor( + public resourceType: ResourceType, + public resourceId: string + ) {} } export class ToggleMode { diff --git a/src/app/features/project/wiki/store/wiki.model.ts b/src/app/shared/stores/wiki/wiki.model.ts similarity index 69% rename from src/app/features/project/wiki/store/wiki.model.ts rename to src/app/shared/stores/wiki/wiki.model.ts index 9ddaaffba..e12507297 100644 --- a/src/app/features/project/wiki/store/wiki.model.ts +++ b/src/app/shared/stores/wiki/wiki.model.ts @@ -1,6 +1,4 @@ -import { AsyncStateModel } from '@osf/shared/models'; - -import { Wiki, WikiVersion } from '../models'; +import { AsyncStateModel, Wiki, WikiVersion } from '@osf/shared/models'; export interface WikiModesStateModel { view: boolean; @@ -17,8 +15,8 @@ export interface ComponentWiki { export interface WikiStateModel { homeWikiContent: AsyncStateModel; wikiModes: WikiModesStateModel; - projectWikiList: AsyncStateModel; - projectComponentsWikiList: AsyncStateModel; + wikiList: AsyncStateModel; + componentsWikiList: AsyncStateModel; currentWikiId: string; previewContent: string; wikiVersions: AsyncStateModel; diff --git a/src/app/features/project/wiki/store/wiki.selectors.ts b/src/app/shared/stores/wiki/wiki.selectors.ts similarity index 88% rename from src/app/features/project/wiki/store/wiki.selectors.ts rename to src/app/shared/stores/wiki/wiki.selectors.ts index fcfd8237f..0d5dc024c 100644 --- a/src/app/features/project/wiki/store/wiki.selectors.ts +++ b/src/app/shared/stores/wiki/wiki.selectors.ts @@ -1,6 +1,6 @@ import { Selector } from '@ngxs/store'; -import { Wiki, WikiVersion } from '../models'; +import { Wiki, WikiVersion } from '@osf/shared/models'; import { ComponentWiki, WikiModesStateModel, WikiStateModel } from './wiki.model'; import { WikiState } from './wiki.state'; @@ -23,27 +23,27 @@ export class WikiSelectors { @Selector([WikiState]) static getWikiList(state: WikiStateModel): Wiki[] { - return state.projectWikiList.data; + return state.wikiList.data; } @Selector([WikiState]) static getWikiListLoading(state: WikiStateModel): boolean { - return state.projectWikiList.isLoading; + return state.wikiList.isLoading; } @Selector([WikiState]) static getComponentsWikiList(state: WikiStateModel): ComponentWiki[] { - return state.projectComponentsWikiList.data; + return state.componentsWikiList.data; } @Selector([WikiState]) static getComponentsWikiListLoading(state: WikiStateModel): boolean { - return state.projectComponentsWikiList.isLoading; + return state.componentsWikiList.isLoading; } @Selector([WikiState]) static getWikiSubmitting(state: WikiStateModel): boolean { - return state.projectWikiList.isSubmitting ?? false; + return state.wikiList.isSubmitting ?? false; } @Selector([WikiState]) diff --git a/src/app/features/project/wiki/store/wiki.state.ts b/src/app/shared/stores/wiki/wiki.state.ts similarity index 87% rename from src/app/features/project/wiki/store/wiki.state.ts rename to src/app/shared/stores/wiki/wiki.state.ts index 1545ab7fc..c10607a81 100644 --- a/src/app/features/project/wiki/store/wiki.state.ts +++ b/src/app/shared/stores/wiki/wiki.state.ts @@ -4,7 +4,7 @@ import { catchError, map, tap, throwError } from 'rxjs'; import { Injectable } from '@angular/core'; -import { WikiService } from '../services'; +import { WikiService } from '@osf/shared/services'; import { ClearWiki, @@ -34,13 +34,13 @@ const DefaultState: WikiStateModel = { edit: false, compare: false, }, - projectWikiList: { + wikiList: { data: [], isLoading: false, error: null, isSubmitting: false, }, - projectComponentsWikiList: { + componentsWikiList: { data: [], isLoading: false, error: null, @@ -76,17 +76,17 @@ export class WikiState { createWiki(ctx: StateContext, action: CreateWiki) { const state = ctx.getState(); ctx.patchState({ - projectWikiList: { - ...state.projectWikiList, + wikiList: { + ...state.wikiList, isSubmitting: true, }, }); - return this.wikiService.createWiki(action.projectId, action.name).pipe( + return this.wikiService.createWiki(action.resourceId, action.name).pipe( tap((wiki) => { ctx.patchState({ - projectWikiList: { - ...state.projectWikiList, - data: [...state.projectWikiList.data, wiki], + wikiList: { + ...state.wikiList, + data: [...state.wikiList.data, wiki], isSubmitting: false, }, currentWikiId: wiki.id, @@ -100,8 +100,8 @@ export class WikiState { deleteWiki(ctx: StateContext, action: DeleteWiki) { const state = ctx.getState(); ctx.patchState({ - projectWikiList: { - ...state.projectWikiList, + wikiList: { + ...state.wikiList, isSubmitting: true, isLoading: true, }, @@ -109,9 +109,9 @@ export class WikiState { return this.wikiService.deleteWiki(action.wikiId).pipe( tap(() => { - const updatedList = state.projectWikiList.data.filter((wiki) => wiki.id !== action.wikiId); + const updatedList = state.wikiList.data.filter((wiki) => wiki.id !== action.wikiId); ctx.patchState({ - projectWikiList: { + wikiList: { data: updatedList, isSubmitting: false, error: null, @@ -135,7 +135,7 @@ export class WikiState { }, }); - return this.wikiService.getHomeWiki(action.projectId).pipe( + return this.wikiService.getHomeWiki(action.resourceType, action.resourceId).pipe( tap((content) => { ctx.patchState({ homeWikiContent: { @@ -154,8 +154,8 @@ export class WikiState { ctx.patchState({ homeWikiContent: { ...DefaultState.homeWikiContent }, wikiModes: { ...DefaultState.wikiModes }, - projectWikiList: { ...DefaultState.projectWikiList }, - projectComponentsWikiList: { ...DefaultState.projectComponentsWikiList }, + wikiList: { ...DefaultState.wikiList }, + componentsWikiList: { ...DefaultState.componentsWikiList }, currentWikiId: DefaultState.currentWikiId, previewContent: DefaultState.previewContent, wikiVersions: { ...DefaultState.wikiVersions }, @@ -181,17 +181,17 @@ export class WikiState { getWikiList(ctx: StateContext, action: GetWikiList) { const state = ctx.getState(); ctx.patchState({ - projectWikiList: { - ...state.projectWikiList, + wikiList: { + ...state.wikiList, isLoading: true, error: null, }, }); - return this.wikiService.getWikiList(action.projectId).pipe( + return this.wikiService.getWikiList(action.resourceType, action.resourceId).pipe( tap((list) => { ctx.patchState({ - projectWikiList: { + wikiList: { data: [...list], isLoading: false, error: null, @@ -208,17 +208,17 @@ export class WikiState { const state = ctx.getState(); ctx.patchState({ - projectComponentsWikiList: { - ...state.projectComponentsWikiList, + componentsWikiList: { + ...state.componentsWikiList, isLoading: true, error: null, }, }); - return this.wikiService.getComponentsWikiList(action.projectId).pipe( + return this.wikiService.getComponentsWikiList(action.resourceType, action.resourceId).pipe( tap((componentsWiki) => { ctx.patchState({ - projectComponentsWikiList: { + componentsWikiList: { data: [...componentsWiki], isLoading: false, error: null, @@ -257,8 +257,8 @@ export class WikiState { isLoading: false, error: error.message, }, - projectWikiList: { - ...ctx.getState().projectWikiList, + wikiList: { + ...ctx.getState().wikiList, isLoading: false, isSubmitting: false, error: error.message, From d94651e53810c68ec395ccc8bbf00a08e187a8bd Mon Sep 17 00:00:00 2001 From: NazarMykhalkevych Date: Thu, 31 Jul 2025 01:06:38 +0300 Subject: [PATCH 3/3] feat(registries): wiki for registration --- .../features/project/wiki/wiki.component.html | 2 +- .../registry-wiki.component.html | 18 +-- .../registry-wiki/registry-wiki.component.ts | 107 ++++++++++++++++-- .../add-wiki-dialog.component.ts | 2 +- .../view-section/view-section.component.ts | 10 +- .../wiki/wiki-list/wiki-list.component.html | 23 ++-- .../wiki/wiki-list/wiki-list.component.ts | 5 +- 7 files changed, 135 insertions(+), 32 deletions(-) diff --git a/src/app/features/project/wiki/wiki.component.html b/src/app/features/project/wiki/wiki.component.html index a0d11613f..203c5004c 100644 --- a/src/app/features/project/wiki/wiki.component.html +++ b/src/app/features/project/wiki/wiki.component.html @@ -21,7 +21,7 @@
- - + }
diff --git a/src/app/features/registry/pages/registry-wiki/registry-wiki.component.ts b/src/app/features/registry/pages/registry-wiki/registry-wiki.component.ts index 52407ea14..e434e95ca 100644 --- a/src/app/features/registry/pages/registry-wiki/registry-wiki.component.ts +++ b/src/app/features/registry/pages/registry-wiki/registry-wiki.component.ts @@ -1,29 +1,122 @@ -import { select } from '@ngxs/store'; +import { createDispatchMap, select } from '@ngxs/store'; import { TranslatePipe } from '@ngx-translate/core'; import { Button } from 'primeng/button'; import { ButtonGroup } from 'primeng/buttongroup'; -import { ChangeDetectionStrategy, Component } from '@angular/core'; +import { filter, map, mergeMap, tap } from 'rxjs'; -import { SubHeaderComponent } from '@osf/shared/components'; +import { ChangeDetectionStrategy, Component, inject } from '@angular/core'; +import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; +import { ActivatedRoute, Router } from '@angular/router'; + +import { + CompareSectionComponent, + SubHeaderComponent, + ViewSectionComponent, + WikiListComponent, +} from '@osf/shared/components'; +import { ResourceType } from '@osf/shared/enums'; import { WikiModes } from '@osf/shared/models'; -import { WikiSelectors } from '@osf/shared/stores'; +import { + GetCompareVersionContent, + GetWikiContent, + GetWikiList, + GetWikiVersionContent, + GetWikiVersions, + SetCurrentWiki, + ToggleMode, + WikiSelectors, +} from '@osf/shared/stores'; @Component({ selector: 'osf-registry-wiki', - imports: [SubHeaderComponent, Button, ButtonGroup, TranslatePipe], + imports: [ + SubHeaderComponent, + Button, + ButtonGroup, + TranslatePipe, + WikiListComponent, + ViewSectionComponent, + CompareSectionComponent, + ], templateUrl: './registry-wiki.component.html', styleUrl: './registry-wiki.component.scss', changeDetection: ChangeDetectionStrategy.OnPush, }) export class RegistryWikiComponent { + private readonly route = inject(ActivatedRoute); + private readonly router = inject(Router); + WikiModes = WikiModes; protected wikiModes = select(WikiSelectors.getWikiModes); + protected previewContent = select(WikiSelectors.getPreviewContent); + protected versionContent = select(WikiSelectors.getWikiVersionContent); + protected compareVersionContent = select(WikiSelectors.getCompareVersionContent); + protected isWikiListLoading = select(WikiSelectors.getWikiListLoading || WikiSelectors.getComponentsWikiListLoading); + protected wikiList = select(WikiSelectors.getWikiList); + protected currentWikiId = select(WikiSelectors.getCurrentWikiId); + protected wikiVersions = select(WikiSelectors.getWikiVersions); + protected isWikiVersionLoading = select(WikiSelectors.getWikiVersionsLoading); + + readonly resourceId = this.route.parent?.snapshot.params['id']; + + protected actions = createDispatchMap({ + toggleMode: ToggleMode, + getWikiContent: GetWikiContent, + getWikiList: GetWikiList, + setCurrentWiki: SetCurrentWiki, + getWikiVersions: GetWikiVersions, + getWikiVersionContent: GetWikiVersionContent, + getCompareVersionContent: GetCompareVersionContent, + }); + + protected wikiIdFromQueryParams = this.route.snapshot.queryParams['wiki']; + + constructor() { + this.actions + .getWikiList(ResourceType.Registration, this.resourceId) + .pipe( + takeUntilDestroyed(), + tap(() => { + if (!this.wikiIdFromQueryParams) { + this.navigateToWiki(this.wikiList()?.[0]?.id || ''); + } + }) + ) + .subscribe(); + + this.route.queryParams + .pipe( + takeUntilDestroyed(), + map((params) => params['wiki']), + filter((wikiId) => wikiId), + tap((wikiId) => { + this.actions.setCurrentWiki(wikiId); + }), + mergeMap((wikiId) => this.actions.getWikiVersions(wikiId)) + ) + .subscribe(); + } toggleMode(mode: WikiModes) { - // this.actions.toggleMode(mode); - console.log(`Toggling mode to: ${mode}`); + this.actions.toggleMode(mode); + } + + onSelectVersion(versionId: string) { + this.actions.getWikiVersionContent(this.currentWikiId(), versionId); + } + + onSelectCompareVersion(versionId: string) { + this.actions.getCompareVersionContent(this.currentWikiId(), versionId); + } + + private navigateToWiki(wiki: string) { + this.router.navigate([], { + relativeTo: this.route, + queryParams: { wiki }, + queryParamsHandling: 'merge', + }); } } diff --git a/src/app/shared/components/wiki/add-wiki-dialog/add-wiki-dialog.component.ts b/src/app/shared/components/wiki/add-wiki-dialog/add-wiki-dialog.component.ts index 9a1822440..911610efe 100644 --- a/src/app/shared/components/wiki/add-wiki-dialog/add-wiki-dialog.component.ts +++ b/src/app/shared/components/wiki/add-wiki-dialog/add-wiki-dialog.component.ts @@ -42,7 +42,7 @@ export class AddWikiDialogComponent { submitForm(): void { if (this.addWikiForm.valid) { this.actions - .createWiki(ResourceType.Project, this.config.data.projectId, this.addWikiForm.value.name ?? '') + .createWiki(ResourceType.Project, this.config.data.resourceId, this.addWikiForm.value.name ?? '') .subscribe({ next: (res) => { this.toastService.showSuccess('project.wiki.addWikiSuccess'); diff --git a/src/app/shared/components/wiki/view-section/view-section.component.ts b/src/app/shared/components/wiki/view-section/view-section.component.ts index c742fd91b..b0371ada9 100644 --- a/src/app/shared/components/wiki/view-section/view-section.component.ts +++ b/src/app/shared/components/wiki/view-section/view-section.component.ts @@ -18,6 +18,7 @@ import { WikiVersion } from '@osf/shared/models'; changeDetection: ChangeDetectionStrategy.OnPush, }) export class ViewSectionComponent { + viewOnly = input(false); isLoading = input(false); previewContent = input.required(); versions = input.required(); @@ -48,8 +49,13 @@ export class ViewSectionComponent { constructor() { effect(() => { - this.versions(); - this.selectedVersion.set(null); + const versions = this.versions(); + if (versions?.length && this.viewOnly()) { + this.selectedVersion.set(versions[0]?.id || null); + this.selectVersion.emit(versions[0]?.id); + } else { + this.selectedVersion.set(null); + } }); } diff --git a/src/app/shared/components/wiki/wiki-list/wiki-list.component.html b/src/app/shared/components/wiki/wiki-list/wiki-list.component.html index d3e9340ac..4d77cf662 100644 --- a/src/app/shared/components/wiki/wiki-list/wiki-list.component.html +++ b/src/app/shared/components/wiki/wiki-list/wiki-list.component.html @@ -17,6 +17,7 @@ icon="fas fa-plus" severity="success" outlined + [disabled]="viewOnly()" (click)="openAddWikiDialog()" /> - @if (!isHomeWikiSelected() || !list().length) { - - + @if (!viewOnly()) { + @if (!isHomeWikiSelected() || !list().length) { + + + } }
diff --git a/src/app/shared/components/wiki/wiki-list/wiki-list.component.ts b/src/app/shared/components/wiki/wiki-list/wiki-list.component.ts index 9f024e438..ab9bcc24c 100644 --- a/src/app/shared/components/wiki/wiki-list/wiki-list.component.ts +++ b/src/app/shared/components/wiki/wiki-list/wiki-list.component.ts @@ -24,7 +24,8 @@ import { AddWikiDialogComponent } from '../add-wiki-dialog/add-wiki-dialog.compo providers: [DialogService], }) export class WikiListComponent { - readonly projectId = input.required(); + readonly viewOnly = input(false); + readonly resourceId = input.required(); readonly list = input.required(); readonly isLoading = input(false); readonly componentsList = input.required(); @@ -89,7 +90,7 @@ export class WikiListComponent { header: this.translateService.instant('project.wiki.addNewWiki'), modal: true, data: { - projectId: this.projectId(), + resourceId: this.resourceId(), }, }); dialogRef.onClose.subscribe(() => {