Skip to content

Commit

Permalink
feat(project): better error handler in case a project does not exist …
Browse files Browse the repository at this point in the history
…(DSP-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 d7470a0
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 59 deletions.
11 changes: 4 additions & 7 deletions src/app/project/board/board.component.ts
Expand Up @@ -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();
Expand Down
9 changes: 3 additions & 6 deletions src/app/project/collaboration/collaboration.component.ts
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/app/project/list/list.component.spec.ts
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
);

Expand Down
9 changes: 3 additions & 6 deletions src/app/project/list/list.component.ts
Expand Up @@ -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);
Expand Down
9 changes: 3 additions & 6 deletions src/app/project/ontology/ontology.component.ts
Expand Up @@ -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);
Expand Down
9 changes: 3 additions & 6 deletions src/app/project/permission/permission.component.ts
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/app/project/project.component.html
Expand Up @@ -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>
26 changes: 8 additions & 18 deletions src/app/project/project.component.ts
Expand Up @@ -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',
Expand Down Expand Up @@ -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,
Expand All @@ -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';
}
Expand All @@ -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
}
}

Expand Down
10 changes: 4 additions & 6 deletions src/app/system/users/users-list/users-list.component.ts
Expand Up @@ -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;
Expand Down

0 comments on commit d7470a0

Please sign in to comment.