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(dsp-app): ontology loading, ontology clases refresh, reloads proj… #1346

Merged
merged 5 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
@@ -1,4 +1,4 @@
import { ChangeDetectionStrategy, Component, Input, OnInit } from '@angular/core';
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
import { ClassDefinition, Constants } from '@dasch-swiss/dsp-js';
import { SortingService } from '@dasch-swiss/vre/shared/app-helper-services';

Expand All @@ -8,27 +8,27 @@ import { SortingService } from '@dasch-swiss/vre/shared/app-helper-services';
templateUrl: './ontology-classes.component.html',
styleUrls: ['./ontology-classes.component.scss'],
})
export class OntologyClassesComponent implements OnInit {
export class OntologyClassesComponent {
@Input() resClasses: ClassDefinition[];

@Input() projectMember: boolean;

classesToDisplay: ClassDefinition[] = [];

constructor(private _sortingService: SortingService) {}

ngOnInit(): void {
// display only the classes which are not a subClass of Standoff and sort them by label
// display only the classes which are not a subClass of Standoff and sort them by label
get classesToDisplay(): ClassDefinition[] {
const classesToDisplay = [];
this.resClasses.forEach(resClass => {
if (resClass.subClassOf.length) {
const splittedSubClass = resClass.subClassOf[0].split('#');
if (!splittedSubClass[0].includes(Constants.StandoffOntology) && !splittedSubClass[1].includes('Standoff')) {
this.classesToDisplay.push(resClass);
classesToDisplay.push(resClass);
}
}
});
this.classesToDisplay = this._sortingService.keySortByAlphabetical(this.classesToDisplay, 'label');

return this._sortingService.keySortByAlphabetical(classesToDisplay, 'label');
}

constructor(private _sortingService: SortingService) {}

trackByFn = (index: number, item: ClassDefinition) => `${index}-${item.id}`;
}
30 changes: 11 additions & 19 deletions apps/dsp-app/src/app/project/project-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,15 @@ export class ProjectBase implements OnInit, OnDestroy {
if (!this.project || this.project.id !== this.projectIri || !projectMembers) {
// get current project data, project members and project groups
// and set the project state here
this._actions$
.pipe(ofActionSuccessful(LoadProjectsAction))
.pipe(take(1))
.subscribe(() => this.setProjectData());
this._store.dispatch([new LoadProjectsAction(), new LoadProjectMembershipAction(this.projectUuid)]);
} else if (!this.isOntologiesAvailable()) {
this._store.dispatch(new LoadProjectOntologiesAction(this.projectUuid));
}
},
complete: () => {
this._actions$
.pipe(ofActionSuccessful(LoadProjectsAction))
.pipe(take(1))
.subscribe(() => this.setProjectData());
},
});
}

Expand All @@ -126,18 +124,12 @@ export class ProjectBase implements OnInit, OnDestroy {

private isOntologiesAvailable(): boolean {
const currentProjectOntologies = this._store.selectSnapshot(OntologiesSelectors.currentProjectOntologies);
let result = true;

this.project.ontologies.forEach(ontoIri => {
if (
!currentProjectOntologies ||
currentProjectOntologies.length === 0 ||
!currentProjectOntologies.find(o => o.id === ontoIri)
) {
result = false;
}
});

return result;
return (
currentProjectOntologies &&
currentProjectOntologies.length > 0 &&
currentProjectOntologies.some(o =>
this.project.ontologies.some(ontoName => o.id.split('/').find(x => x === ontoName.split('/').pop()))
)
);
}
}
12 changes: 10 additions & 2 deletions libs/vre/shared/app-session/src/lib/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import {
ClearListsAction,
ClearOntologiesAction,
ClearProjectsAction,
LoadProjectsAction,
LogUserOutAction,
} from '@dasch-swiss/vre/shared/app-state';
import { Store } from '@ngxs/store';
import { Actions, Store, ofActionSuccessful } from '@ngxs/store';
import jwt_decode, { JwtPayload } from 'jwt-decode';
import { Observable, of, throwError } from 'rxjs';
import { catchError, map, switchMap, take, takeLast, tap } from 'rxjs/operators';
Expand All @@ -27,6 +28,7 @@ export class AuthService {

constructor(
private store: Store,
private _actions: Actions,
private router: Router // private intervalWrapper: IntervalWrapperService
) {
// check if the (possibly) existing session is still valid and if not, destroy it
Expand Down Expand Up @@ -176,14 +178,20 @@ export class AuthService {

doLogoutUser() {
this.removeTokens();
this._actions
.pipe(ofActionSuccessful(ClearProjectsAction))
.pipe(take(1))
.subscribe(() => {
this.store.dispatch(new LoadProjectsAction());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you load projects when user logs out ?

this.router.navigate([RouteConstants.home], { replaceUrl: true });
});
this.store.dispatch([
new LogUserOutAction(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we not call this line anymore ?

new ClearProjectsAction(),
new ClearListsAction(),
new ClearOntologiesAction(),
]);
clearTimeout(this.tokenRefreshIntervalId);
this.router.navigate([RouteConstants.home], { replaceUrl: true });
}

isLoggedIn() {
Expand Down