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