mirror of
https://github.com/ever-co/ever-gauzy.git
synced 2026-10-02 01:54:50 +08:00
fix: ensure project module list updates on create, update, and delete
This commit is contained in:
+18
-1
@@ -1,6 +1,6 @@
|
||||
import { HttpClient, HttpErrorResponse, HttpParams } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable, throwError } from 'rxjs';
|
||||
import { BehaviorSubject, Observable, throwError } from 'rxjs';
|
||||
import { IOrganizationProjectModule, IPagination, ID, IOrganizationProjectModuleFindInput } from '@gauzy/contracts';
|
||||
import { API_PREFIX, toParams } from '@gauzy/ui-core/common';
|
||||
import { catchError } from 'rxjs/operators';
|
||||
@@ -13,10 +13,27 @@ import { ToastrService } from '../notification';
|
||||
export class OrganizationProjectModuleService extends CrudService<IOrganizationProjectModule> {
|
||||
private static readonly API_URL = `${API_PREFIX}/organization-project-modules`;
|
||||
|
||||
/**
|
||||
* BehaviorSubject to notify components when project modules are updated.
|
||||
* This ensures that all components displaying modules stay synchronized.
|
||||
*/
|
||||
private moduleUpdatedSubject = new BehaviorSubject<void>(null);
|
||||
/**
|
||||
* Observable that components can subscribe to for module update notifications.
|
||||
*/
|
||||
moduleUpdated$ = this.moduleUpdatedSubject.asObservable();
|
||||
|
||||
constructor(http: HttpClient, private readonly toastrService: ToastrService) {
|
||||
super(http, OrganizationProjectModuleService.API_URL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notifies subscribers that a module update has occurred.
|
||||
*/
|
||||
notifyModuleUpdated(): void {
|
||||
this.moduleUpdatedSubject.next();
|
||||
}
|
||||
|
||||
getAllModulesByProjectId(
|
||||
where: IOrganizationProjectModuleFindInput,
|
||||
relations: string[] = []
|
||||
|
||||
+1
-1
@@ -210,7 +210,7 @@ export class ProjectModuleMutationComponent extends TranslationBaseComponent imp
|
||||
this.translateService.instant('TOASTR.TITLE.SUCCESS')
|
||||
);
|
||||
}
|
||||
|
||||
this.organizationProjectModuleService.notifyModuleUpdated();
|
||||
// Close the dialog and return the created/updated module
|
||||
this.dialogRef.close(module);
|
||||
} catch (error) {
|
||||
|
||||
+14
-15
@@ -12,12 +12,12 @@ import {
|
||||
ToggleSwitcherComponent,
|
||||
DateViewComponent,
|
||||
EmployeesMergedTeamsComponent,
|
||||
EmployeeWithLinksComponent,
|
||||
EmployeeWithLinksComponent
|
||||
} from '../../table-components';
|
||||
import { DeleteConfirmationComponent } from '../../user/forms/delete-confirmation/delete-confirmation.component';
|
||||
import { ProjectModuleMutationComponent } from '../project-module-mutation/project-module-mutation.component';
|
||||
|
||||
@UntilDestroy({ checkProperties: true})
|
||||
@UntilDestroy({ checkProperties: true })
|
||||
@Component({
|
||||
selector: 'ngx-project-module-table',
|
||||
templateUrl: './project-module-table.component.html',
|
||||
@@ -57,6 +57,7 @@ export class ProjectModuleTableComponent extends TranslationBaseComponent implem
|
||||
|
||||
ngOnInit() {
|
||||
this._applyTranslationOnSmartTable();
|
||||
this._subscribeToModuleUpdates();
|
||||
this._loadSmartTableSettings();
|
||||
}
|
||||
|
||||
@@ -123,7 +124,7 @@ export class ProjectModuleTableComponent extends TranslationBaseComponent implem
|
||||
|
||||
// Update the module's isFavorite status
|
||||
instance.onSwitched.subscribe((toggle: boolean) => {
|
||||
this.updateModule(module.id, { ...module,isFavorite:toggle});
|
||||
this.updateModule(module.id, { ...module, isFavorite: toggle });
|
||||
});
|
||||
}
|
||||
},
|
||||
@@ -213,23 +214,12 @@ export class ProjectModuleTableComponent extends TranslationBaseComponent implem
|
||||
* Opens the edit dialog for the selected project module.
|
||||
*/
|
||||
async onEditProjectModuleDialog() {
|
||||
const dialogRef = this.dialogService.open(ProjectModuleMutationComponent, {
|
||||
this.dialogService.open(ProjectModuleMutationComponent, {
|
||||
context: {
|
||||
projectModule: this.selectedItem,
|
||||
createModule: false
|
||||
}
|
||||
});
|
||||
|
||||
dialogRef.onClose.subscribe({
|
||||
next: (result) => {
|
||||
if (result) {
|
||||
this.loadModules();
|
||||
}
|
||||
},
|
||||
error: (err) => {
|
||||
console.error('Error in dialog onClose:', err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -286,4 +276,13 @@ export class ProjectModuleTableComponent extends TranslationBaseComponent implem
|
||||
.map((member: IOrganizationProjectModuleEmployee) => member.employee)
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Subscribes to module updates and automatically reloads the table when changes occur.
|
||||
*/
|
||||
private _subscribeToModuleUpdates(): void {
|
||||
this.organizationProjectModuleService.moduleUpdated$
|
||||
.pipe(untilDestroyed(this))
|
||||
.subscribe(() => this.loadModules());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user