Skip to content
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

fix: Project initialisation from url #1306

Merged
merged 3 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { SplitSize } from '@dsp-app/src/app/workspace/results/results.component'
import { ProjectBase } from '../../project-base';
import { Actions, Store } from '@ngxs/store';
import { Title } from '@angular/platform-browser';
import { CurrentProjectSelectors, OntologiesSelectors, UserSelectors } from '@dasch-swiss/vre/shared/app-state';
import { OntologiesSelectors, UserSelectors } from '@dasch-swiss/vre/shared/app-state';
import { AuthService } from '@dasch-swiss/vre/shared/app-session';

@Component({
Expand Down Expand Up @@ -61,7 +61,6 @@ export class OntologyClassInstanceComponent extends ProjectBase implements OnIni
}

ngOnInit() {
super.ngOnInit();
this._route.params.subscribe((params) => {
this.initProject(params);
});
Expand Down Expand Up @@ -92,17 +91,14 @@ export class OntologyClassInstanceComponent extends ProjectBase implements OnIni
}

private initProject(params: Params): void {
const currentProject = this._store.selectSnapshot(CurrentProjectSelectors.project);
const shortcode = currentProject.shortcode;
const iriBase = this._ontologyService.getIriBaseUrl();

const ontologyName = params[RouteConstants.ontoParameter];
const className = params[RouteConstants.classParameter];

// get the resource ids from the route. Do not use the RouteConstants ontology route constant here,
// because the ontology and class ids are not defined within the apps domain. They are defined by
// the api and can not be changed generically via route constants.
this.ontoId = `${iriBase}/ontology/${shortcode}/${ontologyName}/v2`;
this.ontoId = `${iriBase}/ontology/${this.projectUuid}/${ontologyName}/v2`;
this.classId = `${this.ontoId}#${className}`;

this.instanceId = params[RouteConstants.instanceParameter];
Expand Down Expand Up @@ -131,7 +127,7 @@ export class OntologyClassInstanceComponent extends ProjectBase implements OnIni
}
} else {
// get the single resource instance
this.resourceIri = `${this._acs.dspAppConfig.iriBase}/${shortcode}/${this.instanceId}`;
this.resourceIri = `${this._acs.dspAppConfig.iriBase}/${this.projectUuid}/${this.instanceId}`;
}
} else {
// display all resource instances of this resource class
Expand Down
17 changes: 7 additions & 10 deletions apps/dsp-app/src/app/project/project-base.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ChangeDetectorRef, Directive, OnDestroy, OnInit } from '@angular/core';
import { ActivatedRoute, NavigationEnd, Router } from '@angular/router';
import { ReadProject, ReadUser } from '@dasch-swiss/dsp-js';
import { CurrentProjectSelectors, LoadProjectAction, LoadProjectOntologiesAction, ProjectsSelectors, UserSelectors } from '@dasch-swiss/vre/shared/app-state';
import { CurrentProjectSelectors, LoadProjectAction, LoadProjectOntologiesAction, UserSelectors } from '@dasch-swiss/vre/shared/app-state';
import { Actions, Select, Store, ofActionSuccessful } from '@ngxs/store';
import { Observable, Subject, combineLatest } from 'rxjs';
import { filter, map, take, takeUntil } from 'rxjs/operators';
Expand Down Expand Up @@ -54,6 +54,8 @@ export class ProjectBase implements OnInit, OnDestroy {
ngOnInit(): void {
this.project = this._store.selectSnapshot(CurrentProjectSelectors.project);
if (this.projectUuid && (!this.project || this.project.id !== this.projectIri)) {
// get current project data, project members and project groups
// and set the project state here
this.loadProject();
}
}
Expand All @@ -73,15 +75,10 @@ export class ProjectBase implements OnInit, OnDestroy {
}

private loadProject(): void {
const isProjectsLoading = this._store.selectSnapshot(ProjectsSelectors.isProjectsLoading);
// get current project data, project members and project groups
// and set the project state here
if (!isProjectsLoading) {
this._store.dispatch(new LoadProjectAction(this.projectUuid, true));
this._actions$.pipe(ofActionSuccessful(LoadProjectAction))
.pipe(take(1))
.subscribe(() => this.setProjectData());
}
this._store.dispatch(new LoadProjectAction(this.projectUuid, true));
this._actions$.pipe(ofActionSuccessful(LoadProjectAction))
.pipe(take(1))
.subscribe(() => this.setProjectData());
}

private setProjectData(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
Inject,
Input,
OnChanges,
OnDestroy,
OnInit,
Output,
} from '@angular/core';
Expand All @@ -24,8 +25,8 @@ import {
Events,
} from '@dsp-app/src/app/main/services/component-communication-event.service';
import { NotificationService } from '@dasch-swiss/vre/shared/app-notification';
import { of, Subscription } from 'rxjs';
import { map } from 'rxjs/operators';
import { of, Subject, Subscription } from 'rxjs';
import { map, takeUntil } from 'rxjs/operators';
import { ActivatedRoute, Router } from '@angular/router';

/**
Expand Down Expand Up @@ -82,7 +83,9 @@ export interface CheckboxUpdate {
templateUrl: './list-view.component.html',
styleUrls: ['./list-view.component.scss'],
})
export class ListViewComponent implements OnChanges, OnInit {
export class ListViewComponent implements OnChanges, OnInit, OnDestroy {
private ngUnsubscribe: Subject<void> = new Subject<void>();

@Input() search: SearchParams;

/**
Expand Down Expand Up @@ -156,6 +159,11 @@ export class ListViewComponent implements OnChanges, OnInit {
this._doSearch();
}

ngOnDestroy() {
this.ngUnsubscribe.next();
this.ngUnsubscribe.complete();
}

// the child component send the selected resources to the parent of this component directly;
// but when this component is initialized, it should select the first item in the list and
// emit this selected resource to the parent.
Expand Down Expand Up @@ -240,6 +248,7 @@ export class ListViewComponent implements OnChanges, OnInit {
index,
this.search.filter
)
.pipe(takeUntil(this.ngUnsubscribe))
.subscribe(
(count: CountQueryResponse) => {
this.numberOfAllResults = count.numberOfResults;
Expand Down Expand Up @@ -269,6 +278,7 @@ export class ListViewComponent implements OnChanges, OnInit {
// perform full text search
this._dspApiConnection.v2.search
.doFulltextSearch(this.search.query, index, this.search.filter)
.pipe(takeUntil(this.ngUnsubscribe))
.subscribe(
(response: ReadResourceSequence) => {
// if the response does not contain any resources even though the search count is greater than 0,
Expand All @@ -293,34 +303,28 @@ export class ListViewComponent implements OnChanges, OnInit {
);

// request the count query if the page index is zero otherwise it is already stored in the numberOfAllResults
const numberOfAllResults$ =
index !== 0
const numberOfAllResults$ = index !== 0
? of(this.numberOfAllResults)
: this._dspApiConnection.v2.search
.doExtendedSearchCountQuery(this.search.query)
.pipe(takeUntil(this.ngUnsubscribe))
.pipe(
map((count: CountQueryResponse) => {
this.numberOfAllResults =
count.numberOfResults;
this.currentRangeEnd =
this.numberOfAllResults > 25
? 25
: this.numberOfAllResults;
if (this.numberOfAllResults === 0) {
this._notification.openSnackBar(
'No resources to display.'
);
this.emitSelectedResources();
this.resources = undefined;
this.loading = false;
this._cd.markForCheck();
}

return count.numberOfResults;
this.numberOfAllResults = count.numberOfResults;
this.currentRangeEnd = this.numberOfAllResults > 25 ? 25 : this.numberOfAllResults;
if (this.numberOfAllResults === 0) {
this._notification.openSnackBar('No resources to display.');
this.emitSelectedResources();
this.resources = undefined;
this.loading = false;
this._cd.markForCheck();
}

return count.numberOfResults;
})
);

numberOfAllResults$.subscribe(
numberOfAllResults$.pipe(takeUntil(this.ngUnsubscribe)).subscribe(
(numberOfAllResults: number) => {
if (this.search.query !== undefined) {
// build the gravsearch query
Expand All @@ -333,6 +337,7 @@ export class ListViewComponent implements OnChanges, OnInit {

this._dspApiConnection.v2.search
.doExtendedSearch(gravsearch)
.pipe(takeUntil(this.ngUnsubscribe))
.subscribe(
(response: ReadResourceSequence) => {
// if the response does not contain any resources even the search count is greater than 0,
Expand Down