Skip to content
Permalink
Browse files
feat(project): better error handler in case a project does not exist (D…
…SP-1401) (#421)

* feat(project): set the project cache the correct way

* feat(project): read the project from cache

* test(project): fix bug in list component
  • Loading branch information
kilchenmann committed Apr 20, 2021
1 parent 3ec049e commit d7470a0807688ef19209f43185d6bebbe890f991
@@ -100,13 +100,10 @@ export class BoardComponent implements OnInit {
}

getProject() {
// set the cache
this._cache.get(this.projectcode, this._dspApiConnection.admin.projectsEndpoint.getProjectByShortcode(this.projectcode));

// get project data from cache
this._cache.get(this.projectcode, this._dspApiConnection.admin.projectsEndpoint.getProjectByShortcode(this.projectcode)).subscribe(
(response: ApiResponseData<ProjectResponse>) => {
this.project = response.body.project;
// get the project data from cache
this._cache.get(this.projectcode).subscribe(
(response: ReadProject) => {
this.project = response;

// get project and dataset metadata from backend
this.getProjectMetadata();
@@ -85,13 +85,10 @@ export class CollaborationComponent implements OnInit {
// is the logged-in user system admin?
this.sysAdmin = this.session.user.sysAdmin;

// set the cache
this._cache.get(this.projectcode, this._dspApiConnection.admin.projectsEndpoint.getProjectByShortcode(this.projectcode));

// get the project data from cache
this._cache.get(this.projectcode, this._dspApiConnection.admin.projectsEndpoint.getProjectByShortcode(this.projectcode)).subscribe(
(response: ApiResponseData<ProjectResponse>) => {
this.project = response.body.project;
this._cache.get(this.projectcode).subscribe(
(response: ReadProject) => {
this.project = response;

// is logged-in user projectAdmin?
this.projectAdmin = this.sysAdmin ? this.sysAdmin : this.session.user.projectAdmin.some(e => e === this.project.id);
@@ -15,7 +15,7 @@ import { MatToolbarModule } from '@angular/material/toolbar';
import { MatTooltipModule } from '@angular/material/tooltip';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { ActivatedRoute, Router } from '@angular/router';
import { ApiResponseData, DeleteListResponse, ListNodeInfo, ListsEndpointAdmin, ListsResponse, MockProjects, ProjectResponse, ProjectsEndpointAdmin } from '@dasch-swiss/dsp-js';
import { ApiResponseData, DeleteListResponse, ListNodeInfo, ListsEndpointAdmin, ListsResponse, MockProjects, ProjectResponse, ProjectsEndpointAdmin, ReadProject } from '@dasch-swiss/dsp-js';
import {
DspActionModule,
DspApiConnectionToken,
@@ -178,7 +178,7 @@ describe('ListComponent', () => {

response.project = mockProjects.body.projects[0];

return of(ApiResponseData.fromAjaxResponse({ response } as AjaxResponse));
return of(response.project as ReadProject);
}
);

@@ -109,13 +109,10 @@ export class ListComponent implements OnInit {
// is the logged-in user system admin?
this.sysAdmin = this.session.user.sysAdmin;

// set the cache
this._cache.get(this.projectcode, this._dspApiConnection.admin.projectsEndpoint.getProjectByShortcode(this.projectcode));

// get the project data from cache
this._cache.get(this.projectcode, this._dspApiConnection.admin.projectsEndpoint.getProjectByShortcode(this.projectcode)).subscribe(
(response: ApiResponseData<ProjectResponse>) => {
this.project = response.body.project;
this._cache.get(this.projectcode).subscribe(
(response: ReadProject) => {
this.project = response;

// is logged-in user projectAdmin?
this.projectAdmin = this.sysAdmin ? this.sysAdmin : this.session.user.projectAdmin.some(e => e === this.project.id);
@@ -150,13 +150,10 @@ export class OntologyComponent implements OnInit {
// default value for projectAdmin
this.projectAdmin = this.sysAdmin;

// set the project cache
this._cache.get(this.projectCode, this._dspApiConnection.admin.projectsEndpoint.getProjectByShortcode(this.projectCode));

// get the project data from cache
this._cache.get(this.projectCode, this._dspApiConnection.admin.projectsEndpoint.getProjectByShortcode(this.projectCode)).subscribe(
(response: ApiResponseData<ProjectResponse>) => {
this.project = response.body.project;
this._cache.get(this.projectCode).subscribe(
(response: ReadProject) => {
this.project = response;

// is logged-in user projectAdmin?
this.projectAdmin = this.sysAdmin ? this.sysAdmin : this.session.user.projectAdmin.some(e => e === this.project.id);
@@ -70,13 +70,10 @@ export class PermissionComponent implements OnInit {
// is the logged-in user system admin?
this.sysAdmin = this.session.user.sysAdmin;

// set the cache
this._cache.get(this.projectcode, this._dspApiConnection.admin.projectsEndpoint.getProjectByShortcode(this.projectcode));

// get the project data from cache
this._cache.get(this.projectcode, this._dspApiConnection.admin.projectsEndpoint.getProjectByShortcode(this.projectcode)).subscribe(
(response: ApiResponseData<ProjectResponse>) => {
this.project = response.body.project;
this._cache.get(this.projectcode).subscribe(
(response: ReadProject) => {
this.project = response;

// is logged-in user projectAdmin?
this.projectAdmin = this.sysAdmin ? this.sysAdmin : this.session.user.projectAdmin.some(e => e === this.project.id);
@@ -12,12 +12,12 @@

<dsp-progress-indicator *ngIf="loading"></dsp-progress-indicator>

<router-outlet></router-outlet>
<router-outlet *ngIf="!loading"></router-outlet>

</div>

<ng-template #errorMsg>
<div class="content large middle">
<app-error *ngIf="error"></app-error>
<app-error *ngIf="error" [status]="404"></app-error>
</div>
</ng-template>
@@ -6,7 +6,6 @@ import { DspApiConnectionToken, Session, SessionService } from '@dasch-swiss/dsp
import { AppGlobal } from '../app-global';
import { CacheService } from '../main/cache/cache.service';
import { MenuItem } from '../main/declarations/menu-item';
import { ErrorHandlerService } from '../main/error/error-handler.service';

@Component({
selector: 'app-project',
@@ -40,7 +39,6 @@ export class ProjectComponent implements OnInit {

constructor(
@Inject(DspApiConnectionToken) private _dspApiConnection: KnoraApiConnection,
private _errorHandler: ErrorHandlerService,
private _session: SessionService,
private _cache: CacheService,
private _route: ActivatedRoute,
@@ -63,20 +61,14 @@ export class ProjectComponent implements OnInit {

if (!this.error) {
this.loading = true;
// set the cache here:
// current project data, project members and project groups
this._cache.get(this.projectcode, this._dspApiConnection.admin.projectsEndpoint.getProjectByShortcode(this.projectcode));

// get information about the logged-in user, if one is logged-in
if (this.session) {

}

// get the project data from cache
this._cache.get(this.projectcode, this._dspApiConnection.admin.projectsEndpoint.getProjectByShortcode(this.projectcode)).subscribe(
// get current project data, project members and project groups
// and set the project cache here
this._dspApiConnection.admin.projectsEndpoint.getProjectByShortcode(this.projectcode).subscribe(
(response: ApiResponseData<ProjectResponse>) => {
this.project = response.body.project;

this._cache.set(this.projectcode, this.project);

if (!this.project.status) {
this.color = 'warn';
}
@@ -101,17 +93,15 @@ export class ProjectComponent implements OnInit {
this._cache.get('groups_of_' + this.projectcode, this._dspApiConnection.admin.groupsEndpoint.getGroups());
}

this.loading = false;
if (this._cache.has(this.projectcode)) {
this.loading = false;
}
},
(error: ApiResponseError) => {
this._errorHandler.showMessage(error);
this.error = true;
this.loading = false;
}
);
} else {
// shortcode isn't valid
// --> TODO show an error page
}
}

@@ -119,13 +119,11 @@ export class UsersListComponent implements OnInit {
this.sysAdmin = this.session.user.sysAdmin;

if (this.projectcode) {
// set the cache
this._cache.get(this.projectcode, this._dspApiConnection.admin.projectsEndpoint.getProjectByShortcode(this.projectcode));

// get project information
this._cache.get(this.projectcode, this._dspApiConnection.admin.projectsEndpoint.getProjectByShortcode(this.projectcode)).subscribe(
(response: ApiResponseData<ProjectResponse>) => {
this.project = response.body.project;
// get the project data from cache
this._cache.get(this.projectcode).subscribe(
(response: ReadProject) => {
this.project = response;
// is logged-in user projectAdmin?
this.projectAdmin = this.sysAdmin ? this.sysAdmin : this.session.user.projectAdmin.some(e => e === this.project.id);
this.loading = false;

0 comments on commit d7470a0

Please sign in to comment.