Skip to content

Commit

Permalink
feat: add hr template
Browse files Browse the repository at this point in the history
  • Loading branch information
nichenqin committed Oct 9, 2024
1 parent f10d4c2 commit d8803f7
Show file tree
Hide file tree
Showing 9 changed files with 178 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
</script>

<div data-field-id={field.id.value} data-field-type={field.type} class="flex items-center justify-between gap-1">
<div class="flex items-center gap-1">
<div class="flex items-center gap-1 overflow-hidden">
<FieldIcon {field} type={field.type} class="h-4 w-4" />
<span>
<span class="truncate" title={field.name.value} data-field-name={field.name.value} data-field-id={field.id.value}>
{field.name.value}
</span>
</div>
Expand Down
80 changes: 40 additions & 40 deletions packages/persistence/src/template/template-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: `
// <h1>Streamline Your Human Resource Management with UnDB's HR Management Template</h1>
// <h2>Comprehensive HR Management Features</h2>
// <p>UnDB's HR Management template offers a powerful set of tools to enhance your human resource management:</p>
// <ul>
// <li>Employee Management: Easily create, assign, and monitor employee records</li>
// <li>Department Organization: Efficiently structure and manage company departments</li>
// <li>Payroll Administration: Track and manage employee compensation, including salaries, bonuses, and benefits</li>
// <li>Performance Evaluation: Set up and conduct regular performance reviews and goal-setting sessions</li>
// <li>Time Off Management: Streamline the process of requesting, approving, and tracking employee leave</li>
// <li>Recruitment and Onboarding: Manage job postings, applications, and new employee onboarding processes</li>
// <li>Training and Development: Plan and track employee training programs and career development initiatives</li>
// <li>Compliance Management: Ensure adherence to labor laws and company policies</li>
// <li>Reporting and Analytics: Generate insightful reports on various HR metrics for data-driven decision making</li>
// </ul>
// <h2>Benefits of Using UnDB's HR Management Template</h2>
// <p>Implementing our HR Management template can bring numerous advantages to your organization:</p>
// <ul>
// <li>Increased Efficiency: Automate routine HR tasks and streamline workflows</li>
// <li>Improved Data Accuracy: Centralize employee information and reduce errors in record-keeping</li>
// <li>Enhanced Employee Experience: Provide self-service options for employees to access their information</li>
// <li>Better Decision Making: Leverage HR analytics to make informed strategic decisions</li>
// <li>Scalability: Easily adapt the template to your growing organization's needs</li>
// <li>Cost Savings: Reduce administrative overhead and optimize resource allocation</li>
// </ul>
// <p>Start transforming your HR processes today with UnDB's comprehensive HR Management template!</p>
// `,
// 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: `
<h1>Streamline Your Human Resource Management with UnDB's HR Management Template</h1>
<h2>Comprehensive HR Management Features</h2>
<p>UnDB's HR Management template offers a powerful set of tools to enhance your human resource management:</p>
<ul>
<li>Employee Management: Easily create, assign, and monitor employee records</li>
<li>Department Organization: Efficiently structure and manage company departments</li>
<li>Payroll Administration: Track and manage employee compensation, including salaries, bonuses, and benefits</li>
<li>Performance Evaluation: Set up and conduct regular performance reviews and goal-setting sessions</li>
<li>Time Off Management: Streamline the process of requesting, approving, and tracking employee leave</li>
<li>Recruitment and Onboarding: Manage job postings, applications, and new employee onboarding processes</li>
<li>Training and Development: Plan and track employee training programs and career development initiatives</li>
<li>Compliance Management: Ensure adherence to labor laws and company policies</li>
<li>Reporting and Analytics: Generate insightful reports on various HR metrics for data-driven decision making</li>
</ul>
<h2>Benefits of Using UnDB's HR Management Template</h2>
<p>Implementing our HR Management template can bring numerous advantages to your organization:</p>
<ul>
<li>Increased Efficiency: Automate routine HR tasks and streamline workflows</li>
<li>Improved Data Accuracy: Centralize employee information and reduce errors in record-keeping</li>
<li>Enhanced Employee Experience: Provide self-service options for employees to access their information</li>
<li>Better Decision Making: Leverage HR analytics to make informed strategic decisions</li>
<li>Scalability: Easily adapt the template to your growing organization's needs</li>
<li>Cost Savings: Reduce administrative overhead and optimize resource allocation</li>
</ul>
<p>Start transforming your HR processes today with UnDB's comprehensive HR Management template!</p>
`,
template: {
type: "base",
template: templates.hr as IBaseTemplateDTO,
},
},
]

if (env.NODE_ENV === "development") {
Expand Down
3 changes: 3 additions & 0 deletions packages/table/src/dto/create-table.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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(),
Expand Down
22 changes: 22 additions & 0 deletions packages/table/src/modules/schema/schema.vo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,28 @@ export class Schema extends ValueObject<Field[]> {
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])
}
Expand Down
4 changes: 4 additions & 0 deletions packages/table/src/table.do.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ export class TableDo extends AggregateRoot<ITableEvents> {

#createReferenceField = createReferenceField

reorderFields(fieldsOrder: string[]) {
this.schema = this.schema.reorderFields(fieldsOrder)
}

getOrderedFields(formId?: FormId, viewId?: string): Field[] {
const fields = this.schema.fields
if (formId) {
Expand Down
6 changes: 6 additions & 0 deletions packages/table/src/table.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
2 changes: 2 additions & 0 deletions packages/template/src/dto/template-schema.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
createTablesUrlFieldDTO,
createTablesUserFieldDTO,
createViewWithoutNameDTO,
fieldId,
fieldName,
flattenCreateRecordDTO,
formName,
Expand Down Expand Up @@ -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(),

Expand Down
1 change: 1 addition & 0 deletions packages/template/src/template.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export class TemplateFactory {
name,
schema,
spaceId,
fieldsOrder: table.fieldsOrder,

views,
forms,
Expand Down
103 changes: 98 additions & 5 deletions packages/template/src/templates/hr.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -310,6 +358,7 @@
]
},
"Payroll": {
"fieldsOrder": ["Employee Name", "Employee", "Month", "Amount", "Bonus", "Deductions", "Net Pay"],
"schema": {
"Employee Name": {
"id": "employee_name",
Expand Down Expand Up @@ -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"
}
Expand Down Expand Up @@ -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"],
Expand Down Expand Up @@ -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",
Expand All @@ -569,7 +662,7 @@
"id": "reviewer",
"type": "reference",
"option": {
"createSymmetricField": true,
"createSymmetricField": false,
"foreignTable": {
"tableName": "Employees"
}
Expand Down

0 comments on commit d8803f7

Please sign in to comment.