mirror of
https://github.com/hcengineering/platform.git
synced 2025-02-02 08:51:11 +00:00
e958388e4c
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
124 lines
3.8 KiB
Svelte
124 lines
3.8 KiB
Svelte
<!--
|
|
// Copyright © 2020 Anticrm Platform Contributors.
|
|
//
|
|
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License. You may
|
|
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
//
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
-->
|
|
<script lang="ts">
|
|
import type { Employee } from '@anticrm/contact'
|
|
import contact from '@anticrm/contact'
|
|
import type { Ref, Space } from '@anticrm/core'
|
|
import { OK, Severity, Status } from '@anticrm/platform'
|
|
import { Card, getClient, UserBox } from '@anticrm/presentation'
|
|
import type { Candidate } from '@anticrm/recruit'
|
|
import type { SpaceWithStates } from '@anticrm/task'
|
|
import task from '@anticrm/task'
|
|
import { Grid, Status as StatusControl } from '@anticrm/ui'
|
|
import { createEventDispatcher } from 'svelte'
|
|
import recruit from '../plugin'
|
|
|
|
export let space: Ref<SpaceWithStates>
|
|
export let candidate: Ref<Candidate>
|
|
export let assignee: Ref<Employee>
|
|
|
|
export let preserveCandidate = false
|
|
|
|
let status: Status = OK
|
|
let _space = space
|
|
|
|
const dispatch = createEventDispatcher()
|
|
const client = getClient()
|
|
|
|
export function canClose (): boolean {
|
|
return candidate === undefined && assignee === undefined
|
|
}
|
|
|
|
async function createApplication () {
|
|
const state = await client.findOne(task.class.State, { space: _space })
|
|
if (state === undefined) {
|
|
throw new Error('create application: state not found')
|
|
}
|
|
const sequence = await client.findOne(task.class.Sequence, { attachedTo: recruit.class.Applicant })
|
|
if (sequence === undefined) {
|
|
throw new Error('sequence object not found')
|
|
}
|
|
const incResult = await client.updateDoc(
|
|
task.class.Sequence,
|
|
task.space.Sequence,
|
|
sequence._id,
|
|
{
|
|
$inc: { sequence: 1 }
|
|
},
|
|
true
|
|
)
|
|
const id = await client.addCollection(
|
|
recruit.class.Applicant,
|
|
_space,
|
|
candidate,
|
|
recruit.class.Candidate,
|
|
'applications',
|
|
{
|
|
state: state._id,
|
|
doneState: null,
|
|
number: incResult.object.sequence,
|
|
assignee: assignee
|
|
}
|
|
)
|
|
}
|
|
|
|
async function validate (candidate: Ref<Candidate>, space: Ref<Space>) {
|
|
if (candidate === undefined) {
|
|
status = new Status(Severity.INFO, recruit.status.CandidateRequired, {})
|
|
} else {
|
|
if (space === undefined) {
|
|
status = new Status(Severity.INFO, recruit.status.VacancyRequired, {})
|
|
} else {
|
|
const applicants = await client.findAll(recruit.class.Applicant, { space, attachedTo: candidate })
|
|
if (applicants.length > 0) {
|
|
status = new Status(Severity.ERROR, recruit.status.ApplicationExists, {})
|
|
} else {
|
|
status = OK
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
$: validate(candidate, _space)
|
|
</script>
|
|
|
|
<Card
|
|
label={'Create Application'}
|
|
okAction={createApplication}
|
|
canSave={status.severity === Severity.OK}
|
|
spaceClass={recruit.class.Vacancy}
|
|
spaceLabel={'Vacancy'}
|
|
spacePlaceholder={'Select vacancy'}
|
|
bind:space={_space}
|
|
on:close={() => {
|
|
dispatch('close')
|
|
}}
|
|
>
|
|
<StatusControl slot="error" {status} />
|
|
<Grid column={1} rowGap={1.75}>
|
|
{#if !preserveCandidate}
|
|
<UserBox _class={recruit.class.Candidate} title="Candidate" caption="Candidates" bind:value={candidate} />
|
|
{/if}
|
|
<UserBox
|
|
_class={contact.class.Employee}
|
|
title="Assigned recruiter"
|
|
caption="Recruiters"
|
|
bind:value={assignee}
|
|
allowDeselect
|
|
titleDeselect={'Unassign recruiter'}
|
|
/>
|
|
</Grid>
|
|
</Card>
|