mirror of
https://github.com/hcengineering/platform.git
synced 2024-12-23 11:31:57 +03:00
Change logic of PTO and etc creation in calendar (#2473)
Signed-off-by: Denis Maslennikov <denis.maslennikov@gmail.com>
This commit is contained in:
parent
d19022a73b
commit
5a891aa686
@ -16,7 +16,7 @@
|
||||
import { AttachmentStyledBox } from '@hcengineering/attachment-resources'
|
||||
import calendar from '@hcengineering/calendar'
|
||||
import { Employee } from '@hcengineering/contact'
|
||||
import core, { generateId, Ref } from '@hcengineering/core'
|
||||
import core, { DocumentQuery, generateId, Ref } from '@hcengineering/core'
|
||||
import { Request, RequestType, Staff } from '@hcengineering/hr'
|
||||
import { translate } from '@hcengineering/platform'
|
||||
import { Card, createQuery, EmployeeBox, getClient } from '@hcengineering/presentation'
|
||||
@ -28,6 +28,7 @@
|
||||
export let staff: Staff
|
||||
export let date: Date
|
||||
export let readonly: boolean
|
||||
export let docQuery: DocumentQuery<Employee> | undefined
|
||||
|
||||
let description: string = ''
|
||||
let employee: Ref<Employee> = staff._id
|
||||
@ -94,6 +95,7 @@
|
||||
bind:value={employee}
|
||||
{readonly}
|
||||
showNavigate={false}
|
||||
{docQuery}
|
||||
/>
|
||||
</svelte:fragment>
|
||||
<DropdownLabelsIntl
|
||||
|
@ -14,8 +14,8 @@
|
||||
-->
|
||||
<script lang="ts">
|
||||
import { CalendarMode } from '@hcengineering/calendar-resources'
|
||||
import { Employee } from '@hcengineering/contact'
|
||||
import { Ref } from '@hcengineering/core'
|
||||
import { Employee, EmployeeAccount } from '@hcengineering/contact'
|
||||
import { getCurrentAccount, Ref } from '@hcengineering/core'
|
||||
import type { Department, Request, RequestType, Staff } from '@hcengineering/hr'
|
||||
import { createQuery } from '@hcengineering/presentation'
|
||||
import { Label } from '@hcengineering/ui'
|
||||
@ -44,6 +44,8 @@
|
||||
const lq = createQuery()
|
||||
const typeQuery = createQuery()
|
||||
const staffQuery = createQuery()
|
||||
const currentEmployee = (getCurrentAccount() as EmployeeAccount).employee
|
||||
|
||||
let staff: Staff[] = []
|
||||
let types: Map<Ref<RequestType>, RequestType> = new Map<Ref<RequestType>, RequestType>()
|
||||
|
||||
@ -77,6 +79,9 @@
|
||||
return res
|
||||
}
|
||||
|
||||
let departmentStaff: Staff[]
|
||||
let editableList: Ref<Employee>[] = []
|
||||
|
||||
function update (departments: Ref<Department>[], startDate: Date, endDate: Date) {
|
||||
lq.query(
|
||||
hr.class.Request,
|
||||
@ -103,14 +108,33 @@
|
||||
|
||||
$: update(departments, startDate, endDate)
|
||||
|
||||
function getTeamLead (_id: Ref<Department>): Ref<Employee> | undefined {
|
||||
const department = departmentById.get(_id)
|
||||
if (department === undefined) return
|
||||
if (department.teamLead != null) return department.teamLead
|
||||
return getTeamLead(department.space)
|
||||
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)
|
||||
}
|
||||
editableList = [...new Set(editableList)]
|
||||
}
|
||||
|
||||
$: departmentStaff = staff.filter((p) => departments.includes(p.department) || employeeRequests.has(p._id))
|
||||
function updateStaff (staff: Staff[], departments: Ref<Department>[], employeeRequests: Map<Ref<Staff>, Request[]>) {
|
||||
departmentStaff = staff.filter((p) => departments.includes(p.department) || employeeRequests.has(p._id))
|
||||
updateEditableList()
|
||||
}
|
||||
|
||||
$: updateStaff(staff, departments, employeeRequests)
|
||||
|
||||
const reportQuery = createQuery()
|
||||
|
||||
@ -150,15 +174,7 @@
|
||||
<YearView {departmentStaff} {employeeRequests} {types} {currentDate} />
|
||||
{:else if mode === CalendarMode.Month}
|
||||
{#if display === 'chart'}
|
||||
<MonthView
|
||||
{departmentStaff}
|
||||
{employeeRequests}
|
||||
{types}
|
||||
{startDate}
|
||||
teamLead={getTeamLead(department)}
|
||||
{currentDate}
|
||||
{timeReports}
|
||||
/>
|
||||
<MonthView {departmentStaff} {employeeRequests} {types} {startDate} {editableList} {currentDate} {timeReports} />
|
||||
{:else if display === 'stats'}
|
||||
<MonthTableView {departmentStaff} {employeeRequests} {types} {currentDate} {timeReports} />
|
||||
{/if}
|
||||
|
@ -13,10 +13,10 @@
|
||||
// limitations under the License.
|
||||
-->
|
||||
<script lang="ts">
|
||||
import { Employee, EmployeeAccount } from '@hcengineering/contact'
|
||||
import { Employee } from '@hcengineering/contact'
|
||||
import { EmployeePresenter } from '@hcengineering/contact-resources'
|
||||
import contact from '@hcengineering/contact-resources/src/plugin'
|
||||
import { getCurrentAccount, Ref } from '@hcengineering/core'
|
||||
import { Ref } from '@hcengineering/core'
|
||||
import type { Request, RequestType, Staff } from '@hcengineering/hr'
|
||||
import {
|
||||
areDatesEqual,
|
||||
@ -46,13 +46,13 @@
|
||||
export let departmentStaff: Staff[]
|
||||
|
||||
export let employeeRequests: Map<Ref<Staff>, Request[]>
|
||||
export let teamLead: Ref<Employee> | undefined
|
||||
export let editableList: Ref<Employee>[]
|
||||
export let types: Map<Ref<RequestType>, RequestType>
|
||||
export let timeReports: Map<Ref<Employee>, EmployeeReports>
|
||||
|
||||
const todayDate = new Date()
|
||||
|
||||
function getRequests (date: Date, employee?: Ref<Staff>): Request[] {
|
||||
function getRequests (employeeRequests: Map<Ref<Staff>, Request[]>, date: Date, employee?: Ref<Staff>): Request[] {
|
||||
let requests = undefined
|
||||
if (employee) {
|
||||
requests = employeeRequests.get(employee)
|
||||
@ -72,32 +72,25 @@
|
||||
}
|
||||
|
||||
function createRequest (e: MouseEvent, date: Date, staff: Staff): void {
|
||||
const readonly: boolean = teamLead !== currentEmployee
|
||||
let editStaff: Staff | undefined = staff
|
||||
if (readonly) {
|
||||
editStaff = departmentStaff.find((p) => p._id === currentEmployee)
|
||||
if (!editStaff) {
|
||||
return
|
||||
}
|
||||
}
|
||||
if (!isEditable(staff)) return
|
||||
const readonly = editableList.length === 1
|
||||
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
showPopup(
|
||||
CreateRequest,
|
||||
{
|
||||
staff: editStaff,
|
||||
staff,
|
||||
date,
|
||||
readonly
|
||||
readonly,
|
||||
docQuery: { active: true, $search: editableList.join(' | ') }
|
||||
},
|
||||
eventToHTMLElement(e)
|
||||
)
|
||||
}
|
||||
|
||||
const currentEmployee = (getCurrentAccount() as EmployeeAccount).employee
|
||||
|
||||
function isEditable (employee: Staff): boolean {
|
||||
if (employee._id === currentEmployee) return true
|
||||
return teamLead === currentEmployee
|
||||
return editableList.includes(employee._id)
|
||||
}
|
||||
|
||||
function getEndDate (date: Date): number {
|
||||
@ -181,7 +174,7 @@
|
||||
</td>
|
||||
{#each values as value, i}
|
||||
{@const date = getDay(startDate, value)}
|
||||
{@const requests = getRequests(date, employee._id)}
|
||||
{@const requests = getRequests(employeeRequests, date, employee._id)}
|
||||
{@const editable = isEditable(employee)}
|
||||
{@const tooltipValue = getTooltip(requests)}
|
||||
{@const ww = findReports(employee, date, timeReports)}
|
||||
@ -230,7 +223,7 @@
|
||||
</td>
|
||||
{#each values as value, i}
|
||||
{@const date = getDay(startDate, value)}
|
||||
{@const requests = getRequests(date)}
|
||||
{@const requests = getRequests(employeeRequests, date)}
|
||||
<td
|
||||
class="p-1 text-center summary"
|
||||
class:hovered={i === hoveredIndex}
|
||||
|
Loading…
Reference in New Issue
Block a user