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 @@ -29,7 +29,9 @@ import {
NumberEditorComponent,
EmployeeLinkEditorComponent,
PaginationFilterBaseComponent,
SmartTableToggleComponent
SmartTableToggleComponent,
NonEditableNumberEditorComponent,
JobSearchAvailabilityEditorComponent
} from '@gauzy/ui-core/shared';

/**
Expand Down Expand Up @@ -238,7 +240,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 @@ -251,7 +257,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 @@ -305,7 +315,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: SmartTableToggleComponent,
componentInitFunction: (instance: SmartTableToggleComponent, cell: Cell) => {
// Get the employee data from the cell
Expand All @@ -318,6 +328,10 @@ export class JobEmployeeComponent extends PaginationFilterBaseComponent implemen
instance.toggleChange.pipe(untilDestroyed(this)).subscribe((toggle: boolean) => {
this.updateJobSearchAvailability(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,69 @@
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) {
this._toastrService.danger(error);
}
samuelmbabhazi marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { Cell, DefaultEditor } from 'angular2-smart-table';

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

@Input() cell!: Cell;

ngOnInit() {
this.cellValue = this.cell.getValue();
}
samuelmbabhazi marked this conversation as resolved.
Show resolved Hide resolved
}
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-switch/toggle-switch.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 * 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
ToggleSwitchComponent,
TrustHtmlLinkComponent,
ValueWithUnitComponent,
VisibilityComponent
VisibilityComponent,
NonEditableNumberEditorComponent,
JobSearchAvailabilityEditorComponent
samuelmbabhazi marked this conversation as resolved.
Show resolved Hide resolved
],
exports: [
AllowScreenshotCaptureComponent,
Expand Down
Loading