Skip to content

Commit d7470a0

Browse files
authored
feat(project): better error handler in case a project does not exist (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
1 parent 3ec049e commit d7470a0

9 files changed

Lines changed: 32 additions & 59 deletions

File tree

‎src/app/project/board/board.component.ts‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,10 @@ export class BoardComponent implements OnInit {
100100
}
101101

102102
getProject() {
103-
// set the cache
104-
this._cache.get(this.projectcode, this._dspApiConnection.admin.projectsEndpoint.getProjectByShortcode(this.projectcode));
105-
106-
// get project data from cache
107-
this._cache.get(this.projectcode, this._dspApiConnection.admin.projectsEndpoint.getProjectByShortcode(this.projectcode)).subscribe(
108-
(response: ApiResponseData<ProjectResponse>) => {
109-
this.project = response.body.project;
103+
// get the project data from cache
104+
this._cache.get(this.projectcode).subscribe(
105+
(response: ReadProject) => {
106+
this.project = response;
110107

111108
// get project and dataset metadata from backend
112109
this.getProjectMetadata();

‎src/app/project/collaboration/collaboration.component.ts‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,10 @@ export class CollaborationComponent implements OnInit {
8585
// is the logged-in user system admin?
8686
this.sysAdmin = this.session.user.sysAdmin;
8787

88-
// set the cache
89-
this._cache.get(this.projectcode, this._dspApiConnection.admin.projectsEndpoint.getProjectByShortcode(this.projectcode));
90-
9188
// get the project data from cache
92-
this._cache.get(this.projectcode, this._dspApiConnection.admin.projectsEndpoint.getProjectByShortcode(this.projectcode)).subscribe(
93-
(response: ApiResponseData<ProjectResponse>) => {
94-
this.project = response.body.project;
89+
this._cache.get(this.projectcode).subscribe(
90+
(response: ReadProject) => {
91+
this.project = response;
9592

9693
// is logged-in user projectAdmin?
9794
this.projectAdmin = this.sysAdmin ? this.sysAdmin : this.session.user.projectAdmin.some(e => e === this.project.id);

‎src/app/project/list/list.component.spec.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { MatToolbarModule } from '@angular/material/toolbar';
1515
import { MatTooltipModule } from '@angular/material/tooltip';
1616
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
1717
import { ActivatedRoute, Router } from '@angular/router';
18-
import { ApiResponseData, DeleteListResponse, ListNodeInfo, ListsEndpointAdmin, ListsResponse, MockProjects, ProjectResponse, ProjectsEndpointAdmin } from '@dasch-swiss/dsp-js';
18+
import { ApiResponseData, DeleteListResponse, ListNodeInfo, ListsEndpointAdmin, ListsResponse, MockProjects, ProjectResponse, ProjectsEndpointAdmin, ReadProject } from '@dasch-swiss/dsp-js';
1919
import {
2020
DspActionModule,
2121
DspApiConnectionToken,
@@ -178,7 +178,7 @@ describe('ListComponent', () => {
178178

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

181-
return of(ApiResponseData.fromAjaxResponse({ response } as AjaxResponse));
181+
return of(response.project as ReadProject);
182182
}
183183
);
184184

‎src/app/project/list/list.component.ts‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,10 @@ export class ListComponent implements OnInit {
109109
// is the logged-in user system admin?
110110
this.sysAdmin = this.session.user.sysAdmin;
111111

112-
// set the cache
113-
this._cache.get(this.projectcode, this._dspApiConnection.admin.projectsEndpoint.getProjectByShortcode(this.projectcode));
114-
115112
// get the project data from cache
116-
this._cache.get(this.projectcode, this._dspApiConnection.admin.projectsEndpoint.getProjectByShortcode(this.projectcode)).subscribe(
117-
(response: ApiResponseData<ProjectResponse>) => {
118-
this.project = response.body.project;
113+
this._cache.get(this.projectcode).subscribe(
114+
(response: ReadProject) => {
115+
this.project = response;
119116

120117
// is logged-in user projectAdmin?
121118
this.projectAdmin = this.sysAdmin ? this.sysAdmin : this.session.user.projectAdmin.some(e => e === this.project.id);

‎src/app/project/ontology/ontology.component.ts‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,10 @@ export class OntologyComponent implements OnInit {
150150
// default value for projectAdmin
151151
this.projectAdmin = this.sysAdmin;
152152

153-
// set the project cache
154-
this._cache.get(this.projectCode, this._dspApiConnection.admin.projectsEndpoint.getProjectByShortcode(this.projectCode));
155-
156153
// get the project data from cache
157-
this._cache.get(this.projectCode, this._dspApiConnection.admin.projectsEndpoint.getProjectByShortcode(this.projectCode)).subscribe(
158-
(response: ApiResponseData<ProjectResponse>) => {
159-
this.project = response.body.project;
154+
this._cache.get(this.projectCode).subscribe(
155+
(response: ReadProject) => {
156+
this.project = response;
160157

161158
// is logged-in user projectAdmin?
162159
this.projectAdmin = this.sysAdmin ? this.sysAdmin : this.session.user.projectAdmin.some(e => e === this.project.id);

‎src/app/project/permission/permission.component.ts‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,10 @@ export class PermissionComponent implements OnInit {
7070
// is the logged-in user system admin?
7171
this.sysAdmin = this.session.user.sysAdmin;
7272

73-
// set the cache
74-
this._cache.get(this.projectcode, this._dspApiConnection.admin.projectsEndpoint.getProjectByShortcode(this.projectcode));
75-
7673
// get the project data from cache
77-
this._cache.get(this.projectcode, this._dspApiConnection.admin.projectsEndpoint.getProjectByShortcode(this.projectcode)).subscribe(
78-
(response: ApiResponseData<ProjectResponse>) => {
79-
this.project = response.body.project;
74+
this._cache.get(this.projectcode).subscribe(
75+
(response: ReadProject) => {
76+
this.project = response;
8077

8178
// is logged-in user projectAdmin?
8279
this.projectAdmin = this.sysAdmin ? this.sysAdmin : this.session.user.projectAdmin.some(e => e === this.project.id);

‎src/app/project/project.component.html‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212

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

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

1717
</div>
1818

1919
<ng-template #errorMsg>
2020
<div class="content large middle">
21-
<app-error *ngIf="error"></app-error>
21+
<app-error *ngIf="error" [status]="404"></app-error>
2222
</div>
2323
</ng-template>

‎src/app/project/project.component.ts‎

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { DspApiConnectionToken, Session, SessionService } from '@dasch-swiss/dsp
66
import { AppGlobal } from '../app-global';
77
import { CacheService } from '../main/cache/cache.service';
88
import { MenuItem } from '../main/declarations/menu-item';
9-
import { ErrorHandlerService } from '../main/error/error-handler.service';
109

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

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

6462
if (!this.error) {
6563
this.loading = true;
66-
// set the cache here:
67-
// current project data, project members and project groups
68-
this._cache.get(this.projectcode, this._dspApiConnection.admin.projectsEndpoint.getProjectByShortcode(this.projectcode));
69-
70-
// get information about the logged-in user, if one is logged-in
71-
if (this.session) {
72-
73-
}
74-
75-
// get the project data from cache
76-
this._cache.get(this.projectcode, this._dspApiConnection.admin.projectsEndpoint.getProjectByShortcode(this.projectcode)).subscribe(
64+
// get current project data, project members and project groups
65+
// and set the project cache here
66+
this._dspApiConnection.admin.projectsEndpoint.getProjectByShortcode(this.projectcode).subscribe(
7767
(response: ApiResponseData<ProjectResponse>) => {
7868
this.project = response.body.project;
7969

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

104-
this.loading = false;
96+
if (this._cache.has(this.projectcode)) {
97+
this.loading = false;
98+
}
10599
},
106100
(error: ApiResponseError) => {
107-
this._errorHandler.showMessage(error);
108101
this.error = true;
109102
this.loading = false;
110103
}
111104
);
112-
} else {
113-
// shortcode isn't valid
114-
// --> TODO show an error page
115105
}
116106
}
117107

‎src/app/system/users/users-list/users-list.component.ts‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,11 @@ export class UsersListComponent implements OnInit {
119119
this.sysAdmin = this.session.user.sysAdmin;
120120

121121
if (this.projectcode) {
122-
// set the cache
123-
this._cache.get(this.projectcode, this._dspApiConnection.admin.projectsEndpoint.getProjectByShortcode(this.projectcode));
124122

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

0 commit comments

Comments
 (0)