diff --git a/src/app/project/board/board.component.ts b/src/app/project/board/board.component.ts index 09ce08658d..48947edf65 100644 --- a/src/app/project/board/board.component.ts +++ b/src/app/project/board/board.component.ts @@ -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) => { - 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(); diff --git a/src/app/project/collaboration/collaboration.component.ts b/src/app/project/collaboration/collaboration.component.ts index 5d76ef2ff3..30935ab5e6 100644 --- a/src/app/project/collaboration/collaboration.component.ts +++ b/src/app/project/collaboration/collaboration.component.ts @@ -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) => { - 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); diff --git a/src/app/project/list/list.component.spec.ts b/src/app/project/list/list.component.spec.ts index cfdb21a448..87107b283f 100644 --- a/src/app/project/list/list.component.spec.ts +++ b/src/app/project/list/list.component.spec.ts @@ -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); } ); diff --git a/src/app/project/list/list.component.ts b/src/app/project/list/list.component.ts index 34054b65db..9dc7fa9fef 100644 --- a/src/app/project/list/list.component.ts +++ b/src/app/project/list/list.component.ts @@ -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) => { - 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); diff --git a/src/app/project/ontology/ontology.component.ts b/src/app/project/ontology/ontology.component.ts index d119aa428f..75abde78d9 100644 --- a/src/app/project/ontology/ontology.component.ts +++ b/src/app/project/ontology/ontology.component.ts @@ -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) => { - 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); diff --git a/src/app/project/permission/permission.component.ts b/src/app/project/permission/permission.component.ts index 5c2b0abf6d..7450d42c2f 100644 --- a/src/app/project/permission/permission.component.ts +++ b/src/app/project/permission/permission.component.ts @@ -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) => { - 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); diff --git a/src/app/project/project.component.html b/src/app/project/project.component.html index 2636e84339..86d15fa40e 100644 --- a/src/app/project/project.component.html +++ b/src/app/project/project.component.html @@ -12,12 +12,12 @@ - +
- +
diff --git a/src/app/project/project.component.ts b/src/app/project/project.component.ts index 8200bea447..0f97397391 100644 --- a/src/app/project/project.component.ts +++ b/src/app/project/project.component.ts @@ -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) => { 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 } } diff --git a/src/app/system/users/users-list/users-list.component.ts b/src/app/system/users/users-list/users-list.component.ts index 14a97bb5de..b1980f73a5 100644 --- a/src/app/system/users/users-list/users-list.component.ts +++ b/src/app/system/users/users-list/users-list.component.ts @@ -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) => { - 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;