From d8803f7062ccfbdbfcadebde6375b8e263661ef8 Mon Sep 17 00:00:00 2001 From: nichenqin Date: Wed, 9 Oct 2024 15:02:22 +0800 Subject: [PATCH] feat: add hr template --- .../blocks/grid-view/grid-view-header.svelte | 4 +- .../persistence/src/template/template-data.ts | 80 +++++++------- packages/table/src/dto/create-table.dto.ts | 3 + .../table/src/modules/schema/schema.vo.ts | 22 ++++ packages/table/src/table.do.ts | 4 + packages/table/src/table.factory.ts | 6 + .../template/src/dto/template-schema.dto.ts | 2 + packages/template/src/template.factory.ts | 1 + packages/template/src/templates/hr.base.json | 103 +++++++++++++++++- 9 files changed, 178 insertions(+), 47 deletions(-) diff --git a/apps/frontend/src/lib/components/blocks/grid-view/grid-view-header.svelte b/apps/frontend/src/lib/components/blocks/grid-view/grid-view-header.svelte index 25eff5236..e95f9a0db 100644 --- a/apps/frontend/src/lib/components/blocks/grid-view/grid-view-header.svelte +++ b/apps/frontend/src/lib/components/blocks/grid-view/grid-view-header.svelte @@ -13,9 +13,9 @@
-
+
- + {field.name.value}
diff --git a/packages/persistence/src/template/template-data.ts b/packages/persistence/src/template/template-data.ts index b6d6e6d2c..052f95665 100644 --- a/packages/persistence/src/template/template-data.ts +++ b/packages/persistence/src/template/template-data.ts @@ -236,46 +236,46 @@ export const templateData: ITemplateDTO[] = [ template: templates.socialMediaContent as IBaseTemplateDTO, }, }, - // { - // id: "6ba7b815-9dad-11d1-80b4-00c04fd430c8", - // icon: "👨‍👧‍👦", - // name: "Human Resource Management", - // categories: ["hr"], - // cover: getTemplateImage("hr", "cover.jpg"), - // images: [getTemplateImage("hr", "image1.png"), getTemplateImage("hr", "image2.png")], - // description: "A template for managing human resources, including employees, positions, and departments.", - // detail: ` - //

Streamline Your Human Resource Management with UnDB's HR Management Template

- //

Comprehensive HR Management Features

- //

UnDB's HR Management template offers a powerful set of tools to enhance your human resource management:

- //
    - //
  • Employee Management: Easily create, assign, and monitor employee records
  • - //
  • Department Organization: Efficiently structure and manage company departments
  • - //
  • Payroll Administration: Track and manage employee compensation, including salaries, bonuses, and benefits
  • - //
  • Performance Evaluation: Set up and conduct regular performance reviews and goal-setting sessions
  • - //
  • Time Off Management: Streamline the process of requesting, approving, and tracking employee leave
  • - //
  • Recruitment and Onboarding: Manage job postings, applications, and new employee onboarding processes
  • - //
  • Training and Development: Plan and track employee training programs and career development initiatives
  • - //
  • Compliance Management: Ensure adherence to labor laws and company policies
  • - //
  • Reporting and Analytics: Generate insightful reports on various HR metrics for data-driven decision making
  • - //
- //

Benefits of Using UnDB's HR Management Template

- //

Implementing our HR Management template can bring numerous advantages to your organization:

- //
    - //
  • Increased Efficiency: Automate routine HR tasks and streamline workflows
  • - //
  • Improved Data Accuracy: Centralize employee information and reduce errors in record-keeping
  • - //
  • Enhanced Employee Experience: Provide self-service options for employees to access their information
  • - //
  • Better Decision Making: Leverage HR analytics to make informed strategic decisions
  • - //
  • Scalability: Easily adapt the template to your growing organization's needs
  • - //
  • Cost Savings: Reduce administrative overhead and optimize resource allocation
  • - //
- //

Start transforming your HR processes today with UnDB's comprehensive HR Management template!

- // `, - // template: { - // type: "base", - // template: templates.hr as IBaseTemplateDTO, - // }, - // }, + { + id: "6ba7b815-9dad-11d1-80b4-00c04fd430c8", + icon: "👨‍👧‍👦", + name: "Human Resource Management", + categories: ["hr"], + cover: getTemplateImage("hr", "cover.jpg"), + images: [getTemplateImage("hr", "image1.png"), getTemplateImage("hr", "image2.png")], + description: "A template for managing human resources, including employees, positions, and departments.", + detail: ` +

Streamline Your Human Resource Management with UnDB's HR Management Template

+

Comprehensive HR Management Features

+

UnDB's HR Management template offers a powerful set of tools to enhance your human resource management:

+
    +
  • Employee Management: Easily create, assign, and monitor employee records
  • +
  • Department Organization: Efficiently structure and manage company departments
  • +
  • Payroll Administration: Track and manage employee compensation, including salaries, bonuses, and benefits
  • +
  • Performance Evaluation: Set up and conduct regular performance reviews and goal-setting sessions
  • +
  • Time Off Management: Streamline the process of requesting, approving, and tracking employee leave
  • +
  • Recruitment and Onboarding: Manage job postings, applications, and new employee onboarding processes
  • +
  • Training and Development: Plan and track employee training programs and career development initiatives
  • +
  • Compliance Management: Ensure adherence to labor laws and company policies
  • +
  • Reporting and Analytics: Generate insightful reports on various HR metrics for data-driven decision making
  • +
+

Benefits of Using UnDB's HR Management Template

+

Implementing our HR Management template can bring numerous advantages to your organization:

+
    +
  • Increased Efficiency: Automate routine HR tasks and streamline workflows
  • +
  • Improved Data Accuracy: Centralize employee information and reduce errors in record-keeping
  • +
  • Enhanced Employee Experience: Provide self-service options for employees to access their information
  • +
  • Better Decision Making: Leverage HR analytics to make informed strategic decisions
  • +
  • Scalability: Easily adapt the template to your growing organization's needs
  • +
  • Cost Savings: Reduce administrative overhead and optimize resource allocation
  • +
+

Start transforming your HR processes today with UnDB's comprehensive HR Management template!

+ `, + template: { + type: "base", + template: templates.hr as IBaseTemplateDTO, + }, + }, ] if (env.NODE_ENV === "development") { diff --git a/packages/table/src/dto/create-table.dto.ts b/packages/table/src/dto/create-table.dto.ts index e0acaf2ba..b81f2fc8c 100644 --- a/packages/table/src/dto/create-table.dto.ts +++ b/packages/table/src/dto/create-table.dto.ts @@ -4,6 +4,8 @@ import { z } from "@undb/zod" import { createFormDTO } from "../modules/forms/dto/create-form.dto" import { createRecordDTO } from "../modules/records/record/dto/create-record.dto" import { createSchemaDTO, createTablesSchemaDTO } from "../modules/schema/dto/create-schema.dto" +import { fieldId } from "../modules/schema/fields/field-id.vo" +import { fieldName } from "../modules/schema/fields/field-name.vo" import { createViewDTO } from "../modules/views/dto/create-view.dto" import { tableId } from "../table-id.vo" import { tableName } from "../table-name.vo" @@ -15,6 +17,7 @@ export const createTableDTO = z.object({ spaceId: spaceIdSchema, schema: createSchemaDTO, + fieldsOrder: z.array(fieldName.or(fieldId)).optional(), views: createViewDTO.array().optional(), forms: createFormDTO.array().optional(), diff --git a/packages/table/src/modules/schema/schema.vo.ts b/packages/table/src/modules/schema/schema.vo.ts index cd5030a62..f6c5f9500 100644 --- a/packages/table/src/modules/schema/schema.vo.ts +++ b/packages/table/src/modules/schema/schema.vo.ts @@ -82,6 +82,28 @@ export class Schema extends ValueObject { return new WithNewFieldSpecification(field) } + reorderFields(fieldsOrder: string[]): Schema { + const orderedFields: Field[] = [] + const fieldSet = new Set(fieldsOrder) + + // 首先添加按照 fieldsOrder 排序的字段 + for (const idOrName of fieldsOrder) { + const field = this.fieldMapById.get(idOrName) || this.fieldMapByName.get(idOrName) + if (field) { + orderedFields.push(field) + } + } + + // 添加未在 fieldsOrder 中指定的字段 + for (const field of this.fields) { + if (!fieldSet.has(field.id.value) && !fieldSet.has(field.name.value)) { + orderedFields.push(field) + } + } + + return new Schema(orderedFields) + } + createField(field: Field) { return new Schema([...this.fields, field]) } diff --git a/packages/table/src/table.do.ts b/packages/table/src/table.do.ts index 6f4ecb9b3..b855cdbc9 100644 --- a/packages/table/src/table.do.ts +++ b/packages/table/src/table.do.ts @@ -83,6 +83,10 @@ export class TableDo extends AggregateRoot { #createReferenceField = createReferenceField + reorderFields(fieldsOrder: string[]) { + this.schema = this.schema.reorderFields(fieldsOrder) + } + getOrderedFields(formId?: FormId, viewId?: string): Field[] { const fields = this.schema.fields if (formId) { diff --git a/packages/table/src/table.factory.ts b/packages/table/src/table.factory.ts index c2d40e03a..bb2a88a2e 100644 --- a/packages/table/src/table.factory.ts +++ b/packages/table/src/table.factory.ts @@ -162,6 +162,12 @@ export class TableFactory { } } + for (const { table, dto } of tables) { + if (Array.isArray(dto.fieldsOrder)) { + table.reorderFields(dto.fieldsOrder) + } + } + return tables.map(({ table, dto }) => { const records = dto.records?.map((record) => RecordDO.create(table, record)) ?? [] return { table, records } diff --git a/packages/template/src/dto/template-schema.dto.ts b/packages/template/src/dto/template-schema.dto.ts index 0f05f4efc..f9f8c5c3a 100644 --- a/packages/template/src/dto/template-schema.dto.ts +++ b/packages/template/src/dto/template-schema.dto.ts @@ -20,6 +20,7 @@ import { createTablesUrlFieldDTO, createTablesUserFieldDTO, createViewWithoutNameDTO, + fieldId, fieldName, flattenCreateRecordDTO, formName, @@ -59,6 +60,7 @@ const templateFormDTO = z.record(formName, createFormWithoutNameDTO) const basicTemplateTableDTO = z.object({ id: tableId.optional(), schema: templateSchemaDTO, + fieldsOrder: z.array(fieldName.or(fieldId)).optional(), views: tempalteViewDTO.optional(), forms: templateFormDTO.optional(), diff --git a/packages/template/src/template.factory.ts b/packages/template/src/template.factory.ts index a7388025e..50b2642b9 100644 --- a/packages/template/src/template.factory.ts +++ b/packages/template/src/template.factory.ts @@ -50,6 +50,7 @@ export class TemplateFactory { name, schema, spaceId, + fieldsOrder: table.fieldsOrder, views, forms, diff --git a/packages/template/src/templates/hr.base.json b/packages/template/src/templates/hr.base.json index 8f85b23d6..c2820766d 100644 --- a/packages/template/src/templates/hr.base.json +++ b/packages/template/src/templates/hr.base.json @@ -2,6 +2,24 @@ "Human Resource Management": { "tables": { "Employees": { + "fieldsOrder": [ + "Name", + "Position", + "Department", + "Department Name", + "Manage Department", + "Manage Department Name", + "Start Date", + "Salary", + "Reports To", + "Manager Name", + "Subordinates", + "Subordinates Count", + "Subordinates Name", + "Email", + "Phone", + "Employment Status" + ], "schema": { "Name": { "id": "name", @@ -128,6 +146,24 @@ "fn": "lookup" } }, + "Subordinates Count": { + "id": "subordinates_count", + "type": "rollup", + "option": { + "referenceFieldId": "subordinates", + "rollupFieldId": "id", + "fn": "count" + } + }, + "Subordinates Name": { + "id": "subordinates_name", + "type": "rollup", + "option": { + "referenceFieldId": "subordinates", + "rollupFieldId": "name", + "fn": "lookup" + } + }, "Email": { "id": "email", "type": "email", @@ -198,7 +234,8 @@ "start_date": "2023-01-15", "salary": 70000, "email": "alice@example.com", - "employment_status": "full_time" + "employment_status": "full_time", + "phone": "123-456-7890" }, { "id": "EMP002", @@ -209,7 +246,8 @@ "salary": 90000, "reports_to": ["EMP003"], "email": "bob@example.com", - "employment_status": "full_time" + "employment_status": "full_time", + "phone": "234-567-8901" }, { "id": "EMP003", @@ -219,11 +257,21 @@ "start_date": "2021-03-10", "salary": 60000, "email": "carol@example.com", - "employment_status": "full_time" + "employment_status": "full_time", + "phone": "345-678-9012" } ] }, "Departments": { + "fieldsOrder": [ + "Department Name", + "Manager", + "Manager Name", + "Budget", + "Location", + "Employees", + "Employees Count" + ], "schema": { "Department Name": { "id": "department_name", @@ -310,6 +358,7 @@ ] }, "Payroll": { + "fieldsOrder": ["Employee Name", "Employee", "Month", "Amount", "Bonus", "Deductions", "Net Pay"], "schema": { "Employee Name": { "id": "employee_name", @@ -408,12 +457,13 @@ ] }, "Time Off Requests": { + "fieldsOrder": ["Employee Name", "Employee", "Start Date", "End Date", "Type", "Status", "Reason"], "schema": { "Employee": { "id": "employee", "type": "reference", "option": { - "createSymmetricField": true, + "createSymmetricField": false, "foreignTable": { "tableName": "Employees" } @@ -519,6 +569,38 @@ } } }, + "forms": { + "Time Off Request Form": { + "fields": [ + { + "fieldId": "employee", + "hidden": false, + "required": true + }, + { + "fieldId": "start_date", + "hidden": false, + "required": true + }, + { + "fieldId": "end_date", + "hidden": false, + "required": true + }, + { + "fieldId": "type", + "hidden": false, + "defaultValue": "vacation", + "required": true + }, + { + "fieldId": "reason", + "hidden": false, + "required": true + } + ] + } + }, "records": [ { "employee": ["EMP001"], @@ -547,6 +629,17 @@ ] }, "Performance Reviews": { + "fieldsOrder": [ + "Employee Name", + "Performance Rating", + "Employee", + "Review Date", + "Reviewer", + "Reviewer Name", + "Comments", + "Goals", + "Next Review Date" + ], "schema": { "Employee": { "id": "employee", @@ -569,7 +662,7 @@ "id": "reviewer", "type": "reference", "option": { - "createSymmetricField": true, + "createSymmetricField": false, "foreignTable": { "tableName": "Employees" }