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] Employee Fields Edition on Job Page #8462

Merged
merged 9 commits into from
Oct 21, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ import {
NumberEditorComponent,
EmployeeLinkEditorComponent,
PaginationFilterBaseComponent,
SmartTableToggleComponent,
NonEditableNumberEditorComponent,
JobSearchAvailabilityEditorComponent
ToggleSwitcherComponent
} from '@gauzy/ui-core/shared';

Expand Down Expand Up @@ -240,7 +243,11 @@ export class JobEmployeeComponent extends PaginationFilterBaseComponent implemen
width: '10%', // The width of the column
isSortable: false, // Indicates whether the column is sortable
isEditable: false, // Indicates whether the column is editable
valuePrepareFunction: (rawValue: any) => rawValue || 0
valuePrepareFunction: (rawValue: any) => rawValue || 0,
editor: {
type: 'custom',
component: NonEditableNumberEditorComponent
}
rahul-rocket marked this conversation as resolved.
Show resolved Hide resolved
});

// Register the data table column
Expand All @@ -253,7 +260,11 @@ export class JobEmployeeComponent extends PaginationFilterBaseComponent implemen
width: '10%', // The width of the column
isSortable: false, // Indicates whether the column is sortable
isEditable: false, // Indicates whether the column is editable
valuePrepareFunction: (rawValue: any) => rawValue || 0
valuePrepareFunction: (rawValue: any) => rawValue || 0,
editor: {
type: 'custom',
component: NonEditableNumberEditorComponent
}
rahul-rocket marked this conversation as resolved.
Show resolved Hide resolved
});

// Register the data table column
Expand Down Expand Up @@ -307,7 +318,7 @@ export class JobEmployeeComponent extends PaginationFilterBaseComponent implemen
type: 'custom', // The type of the column
width: '20%', // The width of the column
isSortable: false, // Indicates whether the column is sortable
isEditable: false, // Indicates whether the column is editable
isEditable: true, // Indicates whether the column is editable
samuelmbabhazi marked this conversation as resolved.
Show resolved Hide resolved
renderComponent: ToggleSwitcherComponent,
componentInitFunction: (instance: ToggleSwitcherComponent, cell: Cell) => {
// Get the employee data from the cell
Expand All @@ -323,6 +334,10 @@ export class JobEmployeeComponent extends PaginationFilterBaseComponent implemen
// Call the JobSearchStoreService to update the job search availability
this._jobSearchStoreService.updateJobSearchAvailability(this.organization, employee, toggle);
});
},
editor: {
type: 'custom',
component: JobSearchAvailabilityEditorComponent
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export * from './number-editor.component';
export * from './employee-link-editor.component';
export * from './job-search-availability-editor.component';
export * from './non-editable-number-editor.component';
samuelmbabhazi marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { IEmployee } from '@gauzy/contracts';
import { JobService, ToastrService } from '@gauzy/ui-core/core';
import { Cell, DefaultEditor } from 'angular2-smart-table';
import { BehaviorSubject, Observable } from 'rxjs';

@Component({
template: `<div>
<nb-toggle
[checked]="checked$ | async"
(checkedChange)="onCheckedChange($event)"
triggerParentClick
></nb-toggle>
</div>`
})
export class JobSearchAvailabilityEditorComponent extends DefaultEditor implements OnInit {
private _checked$: BehaviorSubject<boolean> = new BehaviorSubject(false);
@Input() cell!: Cell;
@Output() toggleChange: EventEmitter<boolean> = new EventEmitter();

constructor(private readonly _jobService: JobService, private readonly _toastrService: ToastrService) {
super();
}

public get checked$(): Observable<boolean> {
return this._checked$.asObservable();
}

ngOnInit() {
if (this.cell) {
const employee: IEmployee = this.cell.getRow()?.getData();
if (employee) {
this.value = employee.isJobSearchActive; // Initialize the toggle value
}
}
}

@Input() public set value(checked: boolean) {
this._checked$.next(checked);
}

onCheckedChange(isChecked: boolean) {
this.toggleChange.emit(isChecked); // Emit the toggle change event
this._checked$.next(isChecked);
this.updateJobSearchAvailability(isChecked); // Update job search availability
}

async updateJobSearchAvailability(isJobSearchActive: boolean): Promise<void> {
if (!this.cell) return; // Ensure 'cell' is available
const employee: IEmployee = this.cell.getRow()?.getData();
if (!employee) return; // Ensure employee data is available

try {
await this._jobService.updateJobSearchStatus(employee.id, {
isJobSearchActive,
organizationId: employee.organizationId,
tenantId: employee.tenantId
});

const toastrMessageKey = isJobSearchActive
? 'TOASTR.MESSAGE.EMPLOYEE_JOB_STATUS_ACTIVE'
: 'TOASTR.MESSAGE.EMPLOYEE_JOB_STATUS_INACTIVE';

this._toastrService.success(toastrMessageKey, { name: employee.fullName });
} catch (error) {
const errorMessage = error?.message || 'An error occurred while updating the job search availability.';
this._toastrService.danger(errorMessage);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Component, Input, OnInit } from '@angular/core';
import { Cell, DefaultEditor } from 'angular2-smart-table';

@Component({
template: `
<div>
{{ cellValue }}
</div>
`
})
export class NonEditableNumberEditorComponent extends DefaultEditor implements OnInit {
cellValue!: string | number;

@Input() cell!: Cell;

ngOnInit() {
const value = this.cell.getValue();
if (value === null || value === undefined) {
console.warn('Cell value is null or undefined');
this.cellValue = '';
} else if (typeof value === 'number' || typeof value === 'string') {
this.cellValue = value;
} else {
console.error('Unexpected cell value type:', typeof value);
this.cellValue = '';
}
}
}
2 changes: 2 additions & 0 deletions packages/ui-core/shared/src/lib/table-components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export * from './document-date/document-date.component';
export * from './document-url/document-url.component';
export * from './editors/number-editor.component';
export * from './editors/employee-link-editor.component';
export * from './editors/job-search-availability-editor.component';
export * from './email/email.component';
export * from './employee-links/employee-links.component';
export * from './employee-with-links/employee-with-links.component';
Expand Down Expand Up @@ -39,6 +40,7 @@ export * from './toggle-switcher/toggle-switcher.component';
export * from './trust-html/trust-html.component';
export * from './value-with-units/value-with-units.component';
export * from './visibility/visibility.component';
export * from './editors/non-editable-number-editor.component';

// Export the table components main module
export * from './table-components.module';
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import { NbIconModule, NbTooltipModule, NbBadgeModule, NbToggleModule, NbButtonM
import { TranslateModule } from '@ngx-translate/core';
import { ComponentsModule } from '../components/components.module';
import { PipesModule } from '../pipes/pipes.module';
import { EmployeeLinkEditorComponent, NumberEditorComponent } from './editors';
import {
EmployeeLinkEditorComponent,
JobSearchAvailabilityEditorComponent,
NonEditableNumberEditorComponent,
NumberEditorComponent
} from './editors';
import { AllowScreenshotCaptureComponent } from './allow-screenshot-capture/allow-screenshot-capture.component';
import { AssignedToComponent } from './assigned-to/assigned-to.component';
import { ClickableLinkComponent } from './clickable-link/clickable-link.component';
Expand Down Expand Up @@ -104,7 +109,9 @@ import { TaskBadgeViewComponentModule } from '../tasks/task-badge-view/task-badg
ToggleSwitcherComponent,
TrustHtmlLinkComponent,
ValueWithUnitComponent,
VisibilityComponent
VisibilityComponent,
NonEditableNumberEditorComponent,
JobSearchAvailabilityEditorComponent
samuelmbabhazi marked this conversation as resolved.
Show resolved Hide resolved
],
exports: [
AllowScreenshotCaptureComponent,
Expand All @@ -129,6 +136,8 @@ import { TaskBadgeViewComponentModule } from '../tasks/task-badge-view/task-badg
InvoiceTotalValueComponent,
NotesWithTagsComponent,
NumberEditorComponent,
JobSearchAvailabilityEditorComponent,
NonEditableNumberEditorComponent,
OrganizationWithTagsComponent,
PhoneUrlComponent,
PictureNameTagsComponent,
Expand Down
Loading