Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: removing/adding users from/to project, project activation/deactivation. #1302

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { SortingService } from '@dasch-swiss/vre/shared/app-helper-services';
import { ProjectService } from '@dasch-swiss/vre/shared/app-helper-services';
import {SortProp} from "@dsp-app/src/app/main/action/sort-button/sort-button.component";
import {Observable, Subject, combineLatest} from "rxjs";
import {map, takeUntil, tap} from "rxjs/operators";
import {map, take, takeUntil, tap} from "rxjs/operators";
import { Select } from '@ngxs/store';
import { ProjectsSelectors, UserSelectors } from '@dasch-swiss/vre/shared/app-state';

Expand Down Expand Up @@ -206,19 +206,12 @@ export class ProjectsListComponent implements OnInit, OnDestroy {
}

deactivateProject(id: string) {
const uuid = this._projectService.iriToUuid(id);
// the deleteProject() method in js-lib sets the project's status to false, it is not actually deleted

this._dspApiConnection.admin.projectsEndpoint
.deleteProject(id)
.pipe(
tap((response: ApiResponseData<ProjectResponse>) => {
this.refreshParent.emit(); //TODO Soft or Hard refresh ?
},
(error: ApiResponseError) => {
this._errorHandler.showMessage(error);
})
);
this._dspApiConnection.admin.projectsEndpoint.deleteProject(id)
.pipe(take(1))
.subscribe(response => {
this.refreshParent.emit(); //TODO Soft or Hard refresh ?
});
}

activateProject(id: string) {
Expand All @@ -228,13 +221,9 @@ export class ProjectsListComponent implements OnInit, OnDestroy {

this._dspApiConnection.admin.projectsEndpoint
.updateProject(id, data)
.pipe(
tap((response: ApiResponseData<ProjectResponse>) => {
this.refreshParent.emit();
},
(error: ApiResponseError) => {
this._errorHandler.showMessage(error);
})
);
.pipe(take(1))
.subscribe(response => {
this.refreshParent.emit(); //TODO Soft or Hard refresh ?
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,9 @@ export class UsersListComponent implements OnInit {
switch (mode) {
case 'removeFromProject':
this._store.dispatch(new RemoveUserFromProjectAction(user.id, this.project.id));
this._actions$.pipe(ofActionSuccessful(SetUserAction))
this._actions$.pipe(ofActionSuccessful(LoadProjectMembersAction))
.pipe(take(1))
.subscribe(() => {
this._store.dispatch(new LoadProjectMembersAction(this.projectUuid));
this.refreshParent.emit();
});
break;
Expand Down
13 changes: 5 additions & 8 deletions apps/dsp-app/src/app/user/overview/overview.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@
</div>
</div>
<div class="project-tiles">
<div
*ngFor="let proj of allProjects$ | async"
class="project-tile-container"
>
<div *ngFor="let proj of allProjects$ | async; trackBy: trackByFn" class="project-tile-container">
<app-project-tile
[project]="proj"
[sysAdmin]="true"
Expand All @@ -33,15 +30,15 @@
</div>
</div>
<!-- user is logged in and not a system admin -->
<div *ngIf="(isSysAdmin$ | async) === false && (user$ | async | isFalsy)">
<div *ngIf="(isSysAdmin$ | async) === false && (user$ | async)">
<div class="title-bar">
<div class="title">
<p>My Projects</p>
</div>
</div>
<div class="project-tiles">
<div
*ngFor="let userProj of userActiveProjects$ | async"
*ngFor="let userProj of userActiveProjects$ | async; trackBy: trackByFn"
class="project-tile-container"
>
<app-project-tile
Expand All @@ -57,7 +54,7 @@
</div>
<div class="project-tiles">
<div
*ngFor="let otherProj of userOtherActiveProjects$ | async"
*ngFor="let otherProj of userOtherActiveProjects$ | async; trackBy: trackByFn"
class="project-tile-container"
>
<app-project-tile
Expand All @@ -78,7 +75,7 @@
</div>
<div class="project-tiles">
<div
*ngFor="let proj of allActiveProjects$ | async"
*ngFor="let proj of allActiveProjects$ | async; trackBy: trackByFn"
class="project-tile-container"
>
<app-project-tile
Expand Down
5 changes: 4 additions & 1 deletion apps/dsp-app/src/app/user/overview/overview.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, OnInit } from '@angular/core';
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
import { Title } from '@angular/platform-browser';
import { Router } from '@angular/router';
import {
Expand All @@ -11,6 +11,7 @@ import { Observable } from 'rxjs';
import { LoadProjectsAction, ProjectsSelectors, UserSelectors } from '@dasch-swiss/vre/shared/app-state';

@Component({
changeDetection: ChangeDetectionStrategy.OnPush,
selector: 'app-overview',
templateUrl: './overview.component.html',
styleUrls: ['./overview.component.scss'],
Expand Down Expand Up @@ -42,4 +43,6 @@ export class OverviewComponent implements OnInit {
createNewProject() {
this._router.navigate([RouteConstants.newProjectRelative]);
}

trackByFn = (index: number, item: StoredProject) => `${index}-${item.id}`;
}
3 changes: 0 additions & 3 deletions apps/dsp-app/src/app/user/user-form/user-form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,6 @@ export class UserFormComponent implements OnInit, OnChanges {
// if a projectUuid exists, add the user to the project
const projectIri = this._projectService.uuidToIri(this.projectUuid);
this._store.dispatch(new AddUserToProjectMembershipAction(this.user.id, projectIri));
this._actions$.pipe(ofActionSuccessful(SetUserAction))
.pipe(take(1))
.subscribe(() => this._store.dispatch(new LoadProjectMembersAction(projectIri)));
}

this.closeDialog.emit(this.user);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class ClearProjectsAction {

export class RemoveUserFromProjectAction {
static readonly type = '[Projects] Remove User From Project';
constructor(public userId: string, public projectId: string) {}
constructor(public userId: string, public projectIri: string) {}
}

export class AddUserToProjectMembershipAction {
Expand Down
14 changes: 10 additions & 4 deletions libs/vre/shared/app-state/src/lib/projects/projects.state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,19 +142,22 @@ export class ProjectsState {
@Action(RemoveUserFromProjectAction)
removeUserFromProject(
ctx: StateContext<ProjectsStateModel>,
{ userId, projectId }: RemoveUserFromProjectAction
{ userId, projectIri }: RemoveUserFromProjectAction
) {
ctx.patchState({ isLoading: true });
return this._dspApiConnection.admin.usersEndpoint
.removeUserFromProjectMembership(userId, projectId)
.removeUserFromProjectMembership(userId, projectIri)
.pipe(
take(1),
map((response: ApiResponseData<UserResponse> | ApiResponseError) => {
return response as ApiResponseData<UserResponse>;
}),
tap({
next: (response: ApiResponseData<UserResponse>) => {
ctx.dispatch(new SetUserAction(response.body.user));
ctx.dispatch([
new SetUserAction(response.body.user),
new LoadProjectMembersAction(projectIri)
]);
ctx.patchState({ isLoading: false });
},
error: (error) => {
Expand All @@ -179,7 +182,10 @@ export class ProjectsState {
}),
tap({
next: (response: ApiResponseData<UserResponse>) => {
ctx.dispatch(new SetUserAction(response.body.user));
ctx.dispatch([
new SetUserAction(response.body.user),
new LoadProjectMembersAction(projectIri)
]);
ctx.patchState({ isLoading: false });
},
error: (error) => {
Expand Down