From a64359b33f7c5e73efb2c3e602ebeb3ade8cc02e Mon Sep 17 00:00:00 2001 From: mdelez <60604010+mdelez@users.noreply.github.com> Date: Wed, 27 Jul 2022 14:49:46 +0200 Subject: [PATCH] feat(overview): add overview and project tile components (DEV-984) (#777) * feat(overview): add overview and project tile components * update css * feat(overview): add additional css and click events * feat(overview): add view for unknown user, add create new project button for sysadmins, add logic to redirect user to project dashboard if only member of one project * feat(project): add sidenav item to go to the projects overview * test(overview, project-tile): fix test for overview. fix and add tests for project-tile * test(overview): add tests for overview component * refactor(overview): simplify logic to use two arrays instead of three * fix(users-list): get shortcode from grandchild route in the case user is in the beta view * chore(project): adjust comment --- src/app/app-routing.module.ts | 5 + src/app/app.module.ts | 6 +- .../action/login-form/login-form.component.ts | 19 +- .../project-form/project-form.component.ts | 4 +- src/app/project/project.component.html | 19 +- src/app/project/project.component.ts | 7 + .../project-tile/project-tile.component.html | 34 +++ .../project-tile/project-tile.component.scss | 97 ++++++ .../project-tile.component.spec.ts | 166 ++++++++++ .../project-tile/project-tile.component.ts | 34 +++ .../system/projects/projects.component.html | 4 +- .../users-list/users-list.component.html | 13 +- .../users-list/users-list.component.spec.ts | 7 +- .../users/users-list/users-list.component.ts | 7 + src/app/user/overview/overview.component.html | 65 ++++ src/app/user/overview/overview.component.scss | 81 +++++ .../user/overview/overview.component.spec.ts | 287 ++++++++++++++++++ src/app/user/overview/overview.component.ts | 134 ++++++++ src/assets/style/_layout.scss | 7 +- src/assets/style/_responsive.scss | 12 +- 20 files changed, 981 insertions(+), 27 deletions(-) create mode 100644 src/app/system/project-tile/project-tile.component.html create mode 100644 src/app/system/project-tile/project-tile.component.scss create mode 100644 src/app/system/project-tile/project-tile.component.spec.ts create mode 100644 src/app/system/project-tile/project-tile.component.ts create mode 100644 src/app/user/overview/overview.component.html create mode 100644 src/app/user/overview/overview.component.scss create mode 100644 src/app/user/overview/overview.component.spec.ts create mode 100644 src/app/user/overview/overview.component.ts diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index a6ca548982..102e6a46ee 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -24,6 +24,7 @@ import { SystemComponent } from './system/system.component'; import { UsersComponent } from './system/users/users.component'; // user import { DashboardComponent } from './user/dashboard/dashboard.component'; +import { OverviewComponent } from './user/overview/overview.component'; import { UserComponent } from './user/user.component'; // search results and resource viewer import { ResourceComponent } from './workspace/resource/resource.component'; @@ -42,6 +43,10 @@ const routes: Routes = [ path: 'login', component: LoginFormComponent }, + { + path: 'overview', + component: OverviewComponent + }, { path: 'dashboard', component: DashboardComponent, diff --git a/src/app/app.module.ts b/src/app/app.module.ts index e8f68883b9..b2af2e7407 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -165,6 +165,8 @@ import { OntologyClassesComponent } from './project/beta/ontology-classes/ontolo import { OntologyClassItemComponent } from './project/beta/ontology-classes/ontology-class-item/ontology-class-item.component'; import { OntologyClassInstanceComponent } from './project/beta/ontology-classes/ontology-class-instance/ontology-class-instance.component'; import { SettingsComponent } from './project/beta/settings/settings.component'; +import { OverviewComponent } from './user/overview/overview.component'; +import { ProjectTileComponent } from './system/project-tile/project-tile.component'; // translate: AoT requires an exported function for factories export function httpLoaderFactory(httpClient: HttpClient) { @@ -316,7 +318,9 @@ export function httpLoaderFactory(httpClient: HttpClient) { OntologyClassesComponent, OntologyClassItemComponent, OntologyClassInstanceComponent, - SettingsComponent + SettingsComponent, + OverviewComponent, + ProjectTileComponent, ], imports: [ AngularSplitModule.forRoot(), diff --git a/src/app/main/action/login-form/login-form.component.ts b/src/app/main/action/login-form/login-form.component.ts index 679c83746f..d2c18f413b 100644 --- a/src/app/main/action/login-form/login-form.component.ts +++ b/src/app/main/action/login-form/login-form.component.ts @@ -1,7 +1,7 @@ import { AfterViewInit, Component, EventEmitter, Inject, Input, OnInit, Output } from '@angular/core'; import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { ActivatedRoute, Router } from '@angular/router'; -import { ApiResponseData, ApiResponseError, KnoraApiConnection, LoginResponse } from '@dasch-swiss/dsp-js'; +import { ApiResponseData, ApiResponseError, KnoraApiConnection, LoginResponse, UserResponse } from '@dasch-swiss/dsp-js'; import { DspApiConnectionToken } from '../../declarations/dsp-api-tokens'; import { ErrorHandlerService } from '../../services/error-handler.service'; import { AuthenticationService } from '../../services/authentication.service'; @@ -158,9 +158,26 @@ export class LoginFormComponent implements OnInit, AfterViewInit { this.session = this._session.getSession(); this._componentCommsService.emit(new EmitEvent(Events.loginSuccess, true)); + + // if user hit a page that requires to be logged in, they will have a returnUrl in the url this.returnUrl = this._route.snapshot.queryParams['returnUrl']; if (this.returnUrl) { this._router.navigate([this.returnUrl]); + } else if (this._route.snapshot.url.length && this._route.snapshot.url[0].path === 'login') { // if user is on /login + const username = this.session.user.name; + this._dspApiConnection.admin.usersEndpoint.getUserByUsername(username).subscribe( + (userResponse: ApiResponseData) => { + // if user is only a member of one project, redirect them to that projects dashboard + if(userResponse.body.user.projects.length === 1) { + this._router.navigateByUrl('/refresh', { skipLocationChange: true }).then( + () => this._router.navigate(['/beta/project/' + userResponse.body.user.projects[0].shortcode]) + ); + } else { // if user is a member of multiple projects, redirect them to the overview + this._router.navigateByUrl('/refresh', { skipLocationChange: true }).then( + () => this._router.navigate(['/overview']) + ); + } + }); } else { window.location.reload(); } diff --git a/src/app/project/project-form/project-form.component.ts b/src/app/project/project-form/project-form.component.ts index abe8a0d1f2..00a4e270e0 100644 --- a/src/app/project/project-form/project-form.component.ts +++ b/src/app/project/project-form/project-form.component.ts @@ -417,8 +417,8 @@ export class ProjectFormComponent implements OnInit { this.loading = false; this.closeDialog.emit(); // redirect to (new) project page - this._router.navigateByUrl('/project', { skipLocationChange: true }).then(() => - this._router.navigate(['/project/' + this.form.controls['shortcode'].value]) + this._router.navigateByUrl('/beta/project', { skipLocationChange: true }).then(() => + this._router.navigate(['/beta/project/' + this.form.controls['shortcode'].value]) ); }, (error: ApiResponseError) => { diff --git a/src/app/project/project.component.html b/src/app/project/project.component.html index 9b708ce64f..f072b95da2 100644 --- a/src/app/project/project.component.html +++ b/src/app/project/project.component.html @@ -31,7 +31,12 @@

- + + + +