mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-24 01:07:50 +00:00
HR managers (#2721)
Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
parent
013c09ada2
commit
da6c2eda0a
models/hr/src
plugins
hr-assets/lang
hr-resources/src
hr/src
@ -83,6 +83,9 @@ export class TDepartment extends TSpace implements Department {
|
||||
|
||||
@Prop(ArrOf(TypeRef(contact.class.Contact)), hr.string.Subscribers)
|
||||
subscribers?: Arr<Ref<Contact>>
|
||||
|
||||
@Prop(ArrOf(TypeRef(contact.class.Employee)), hr.string.Managers)
|
||||
managers!: Arr<Ref<Employee>>
|
||||
}
|
||||
|
||||
@Model(hr.class.DepartmentMember, contact.class.EmployeeAccount)
|
||||
|
@ -15,9 +15,9 @@
|
||||
|
||||
import { Employee } from '@hcengineering/contact'
|
||||
import { DOMAIN_TX, TxCollectionCUD, TxCreateDoc, TxOperations, TxUpdateDoc } from '@hcengineering/core'
|
||||
import { Request, TzDate } from '@hcengineering/hr'
|
||||
import { Department, Request, TzDate } from '@hcengineering/hr'
|
||||
import { MigrateOperation, MigrationClient, MigrationUpgradeClient } from '@hcengineering/model'
|
||||
import core from '@hcengineering/model-core'
|
||||
import core, { DOMAIN_SPACE } from '@hcengineering/model-core'
|
||||
import hr, { DOMAIN_HR } from './index'
|
||||
|
||||
async function createSpace (tx: TxOperations): Promise<void> {
|
||||
@ -34,7 +34,8 @@ async function createSpace (tx: TxOperations): Promise<void> {
|
||||
private: false,
|
||||
archived: false,
|
||||
members: [],
|
||||
teamLead: null
|
||||
teamLead: null,
|
||||
managers: []
|
||||
},
|
||||
hr.ids.Head
|
||||
)
|
||||
@ -147,9 +148,35 @@ async function migrateTime (client: MigrationClient): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
async function fillManagers (client: MigrationClient): Promise<void> {
|
||||
await client.update<Department>(
|
||||
DOMAIN_SPACE,
|
||||
{
|
||||
_class: hr.class.Department,
|
||||
managers: { $exists: false }
|
||||
},
|
||||
{
|
||||
managers: []
|
||||
}
|
||||
)
|
||||
|
||||
await client.update<TxCreateDoc<Department>>(
|
||||
DOMAIN_TX,
|
||||
{
|
||||
_class: core.class.TxCreateDoc,
|
||||
objectClass: hr.class.Department,
|
||||
'attributes.managers': { $exists: false }
|
||||
},
|
||||
{
|
||||
'attributes.managers': []
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
export const hrOperation: MigrateOperation = {
|
||||
async migrate (client: MigrationClient): Promise<void> {
|
||||
await migrateTime(client)
|
||||
await fillManagers(client)
|
||||
},
|
||||
async upgrade (client: MigrationUpgradeClient): Promise<void> {
|
||||
const tx = new TxOperations(client, core.account.System)
|
||||
|
@ -46,6 +46,7 @@
|
||||
"Title": "Title",
|
||||
"Description": "Description",
|
||||
"MarkAsPublicHoliday": "Mark as public holiday",
|
||||
"EditPublicHoliday": "Edit public holiday"
|
||||
"EditPublicHoliday": "Edit public holiday",
|
||||
"Managers": "Managers"
|
||||
}
|
||||
}
|
||||
|
@ -46,6 +46,7 @@
|
||||
"Description": "Описание",
|
||||
"PublicHoliday": "Праздничный день",
|
||||
"MarkAsPublicHoliday": "Отметить как праздничный день",
|
||||
"EditPublicHoliday": "Редактировать праздничный день"
|
||||
"EditPublicHoliday": "Редактировать праздничный день",
|
||||
"Managers": "Менеджера"
|
||||
}
|
||||
}
|
||||
|
@ -40,7 +40,8 @@
|
||||
private: false,
|
||||
archived: false,
|
||||
members: [],
|
||||
teamLead: lead
|
||||
teamLead: lead,
|
||||
managers: []
|
||||
})
|
||||
|
||||
dispatch('close', id)
|
||||
|
@ -121,33 +121,70 @@
|
||||
|
||||
$: updateRequest(reqests, startDate, endDate)
|
||||
|
||||
function updateEditableList () {
|
||||
editableList = []
|
||||
departmentById.forEach((department) => {
|
||||
if (department.teamLead === currentEmployee) {
|
||||
const departmentIds = [department._id]
|
||||
departmentIds.concat(getDescendants(department._id, descendants)).forEach((id) => {
|
||||
editableList.push(
|
||||
...Array.from(
|
||||
departmentStaff.filter((p) => p.department === id),
|
||||
(s) => s._id
|
||||
)
|
||||
)
|
||||
})
|
||||
}
|
||||
})
|
||||
if (departmentStaff.filter((p) => p._id === currentEmployee).length > 0) {
|
||||
editableList.push(currentEmployee)
|
||||
function pushChilds (
|
||||
department: Ref<Department>,
|
||||
departmentStaff: Staff[],
|
||||
descendants: Map<Ref<Department>, Department[]>
|
||||
): void {
|
||||
const staff = departmentStaff.filter((p) => p.department === department)
|
||||
editableList.push(...staff.map((p) => p._id))
|
||||
const desc = descendants.get(department) ?? []
|
||||
for (const des of desc) {
|
||||
pushChilds(des._id, departmentStaff, descendants)
|
||||
}
|
||||
editableList = [...new Set(editableList)]
|
||||
}
|
||||
|
||||
function updateStaff (staff: Staff[], departments: Ref<Department>[], employeeRequests: Map<Ref<Staff>, Request[]>) {
|
||||
function isEditable (department: Department): boolean {
|
||||
return department.teamLead === currentEmployee || department.managers.includes(currentEmployee)
|
||||
}
|
||||
|
||||
function checkDepartmentEditable (
|
||||
departmentById: Map<Ref<Department>, Department>,
|
||||
department: Ref<Department>,
|
||||
departmentStaff: Staff[],
|
||||
descendants: Map<Ref<Department>, Department[]>
|
||||
) {
|
||||
const dep = departmentById.get(department)
|
||||
if (dep !== undefined && isEditable(dep)) {
|
||||
pushChilds(dep._id, departmentStaff, descendants)
|
||||
} else {
|
||||
const descendantDepartments = descendants.get(department)
|
||||
if (descendantDepartments !== undefined) {
|
||||
for (const department of descendantDepartments) {
|
||||
if (isEditable(department)) {
|
||||
pushChilds(department._id, departmentStaff, descendants)
|
||||
} else {
|
||||
checkDepartmentEditable(departmentById, department._id, departmentStaff, descendants)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function updateEditableList (
|
||||
departmentById: Map<Ref<Department>, Department>,
|
||||
department: Ref<Department>,
|
||||
departmentStaff: Staff[],
|
||||
descendants: Map<Ref<Department>, Department[]>
|
||||
) {
|
||||
editableList = [currentEmployee]
|
||||
checkDepartmentEditable(departmentById, department, departmentStaff, descendants)
|
||||
editableList = editableList
|
||||
}
|
||||
|
||||
function updateStaff (
|
||||
staff: Staff[],
|
||||
departments: Ref<Department>[],
|
||||
employeeRequests: Map<Ref<Staff>, Request[]>,
|
||||
department: Ref<Department>,
|
||||
descendants: Map<Ref<Department>, Department[]>,
|
||||
departmentById: Map<Ref<Department>, Department>
|
||||
) {
|
||||
departmentStaff = staff.filter((p) => departments.includes(p.department) || employeeRequests.has(p._id))
|
||||
updateEditableList()
|
||||
updateEditableList(departmentById, department, departmentStaff, descendants)
|
||||
}
|
||||
|
||||
$: updateStaff(staff, departments, employeeRequests)
|
||||
$: updateStaff(staff, departments, employeeRequests, department, descendants, departmentById)
|
||||
|
||||
const reportQuery = createQuery()
|
||||
|
||||
|
@ -50,6 +50,7 @@ export default mergeIds(hrId, hr, {
|
||||
Title: '' as IntlString,
|
||||
Description: '' as IntlString,
|
||||
MarkAsPublicHoliday: '' as IntlString,
|
||||
EditPublicHoliday: '' as IntlString
|
||||
EditPublicHoliday: '' as IntlString,
|
||||
Managers: '' as IntlString
|
||||
}
|
||||
})
|
||||
|
@ -32,6 +32,7 @@ export interface Department extends Space {
|
||||
channels?: number
|
||||
members: Arr<Ref<DepartmentMember>>
|
||||
subscribers?: Arr<Ref<Contact>>
|
||||
managers: Arr<Ref<Employee>>
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user