Skip to content

Commit

Permalink
fix(activate/deactivate project): subscribe to the observable to trig…
Browse files Browse the repository at this point in the history
…ger the response

Need to subscribe to trigger the request, otherwise it will not be sent. The request is lazy. Fix also for activating the project.
  • Loading branch information
domsteinbach committed Nov 14, 2023
1 parent 45bc211 commit a465d68
Showing 1 changed file with 22 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import {
EventEmitter,
Inject,
Input,
OnDestroy,
OnInit,
Output,
Output
} from '@angular/core';
import { MatDialog, MatDialogConfig } from '@angular/material/dialog';
import {ActivatedRoute, Router} from '@angular/router';
Expand All @@ -29,14 +30,13 @@ import { SortingService } from '@dsp-app/src/app/main/services/sorting.service';
import { ProjectService } from '@dsp-app/src/app/workspace/resource/services/project.service';
import {SortProp} from "@dsp-app/src/app/main/action/sort-button/sort-button.component";
import {Subscription} from "rxjs";
import {tap} from "rxjs/operators";

@Component({
selector: 'app-projects-list',
templateUrl: './projects-list.component.html',
styleUrls: ['./projects-list.component.scss'],
})
export class ProjectsListComponent implements OnInit {
export class ProjectsListComponent implements OnInit, OnDestroy {
// list of users: status active or inactive (deleted)
@Input() status: boolean;

Expand All @@ -49,6 +49,9 @@ export class ProjectsListComponent implements OnInit {
// in case of modification
@Output() refreshParent: EventEmitter<void> = new EventEmitter<void>();

deactivateSubscription: Subscription;
activateSubscription: Subscription;

// loading for progess indicator
loading: boolean;

Expand Down Expand Up @@ -168,6 +171,7 @@ export class ProjectsListComponent implements OnInit {
const dialogRef = this._dialog.open(DialogComponent, dialogConfig);

dialogRef.afterClosed().subscribe((response) => {
console.log('Dialog was closed', response);
if (response === true) {
// get the mode
switch (mode) {
Expand Down Expand Up @@ -195,18 +199,16 @@ export class ProjectsListComponent implements OnInit {
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
this.deactivateSubscription = this._dspApiConnection.admin.projectsEndpoint
.deleteProject(id)
.pipe(
tap((response: ApiResponseData<ProjectResponse>) => {
.subscribe((response: ApiResponseData<ProjectResponse>) => {
this._applicationStateService.set(uuid, response.body.project);
this.refreshParent.emit();
},
(error: ApiResponseError) => {
this._errorHandler.showMessage(error);
}
)
);
);
}

activateProject(id: string) {
Expand All @@ -216,18 +218,25 @@ export class ProjectsListComponent implements OnInit {

const uuid = this._projectService.iriToUuid(id);

this._dspApiConnection.admin.projectsEndpoint
this.activateSubscription = this._dspApiConnection.admin.projectsEndpoint
.updateProject(id, data)
.pipe(
tap((response: ApiResponseData<ProjectResponse>) => {
.subscribe((response: ApiResponseData<ProjectResponse>) => {
this._applicationStateService.set(uuid, response.body.project);
this.refreshParent.emit();

},
(error: ApiResponseError) => {
this._errorHandler.showMessage(error);
}
)
);
);
}

ngOnDestroy() {
if (this.deactivateSubscription) {
this.deactivateSubscription.unsubscribe();
}
if (this.activateSubscription) {
this.activateSubscription.unsubscribe();
}
}
}

0 comments on commit a465d68

Please sign in to comment.