2021-08-07 17:03:06 +00:00
|
|
|
<!--
|
|
|
|
// 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 { createEventDispatcher } from 'svelte'
|
2021-10-06 12:35:09 +00:00
|
|
|
import type { Ref, Space, SpaceWithStates } from '@anticrm/core'
|
2021-09-16 09:46:04 +00:00
|
|
|
import { Status, OK, Severity } from '@anticrm/platform'
|
2021-09-22 11:15:25 +00:00
|
|
|
import { DatePicker, EditBox, Tabs, Section, Grid, Status as StatusControl } from '@anticrm/ui'
|
2021-09-08 16:16:07 +00:00
|
|
|
import { UserBox, Card, UserInfo, Avatar } from '@anticrm/presentation'
|
2021-09-06 08:30:31 +00:00
|
|
|
import type { Employee, Person } from '@anticrm/contact'
|
2021-09-16 09:46:04 +00:00
|
|
|
import type { Candidate } from '@anticrm/recruit'
|
2021-08-07 17:03:06 +00:00
|
|
|
import Address from './icons/Address.svelte'
|
|
|
|
import Attachment from './icons/Attachment.svelte'
|
|
|
|
|
|
|
|
import { getClient } from '@anticrm/presentation'
|
|
|
|
|
2021-09-05 12:03:33 +00:00
|
|
|
import core from '@anticrm/core'
|
2021-08-07 17:03:06 +00:00
|
|
|
import recruit from '../plugin'
|
2021-09-06 08:30:31 +00:00
|
|
|
import contact from '@anticrm/contact'
|
2021-10-08 14:49:46 +00:00
|
|
|
import view from '@anticrm/view'
|
2021-08-07 17:03:06 +00:00
|
|
|
|
2021-10-06 12:35:09 +00:00
|
|
|
export let space: Ref<SpaceWithStates>
|
2021-12-10 08:42:05 +00:00
|
|
|
export let candidate: Ref<Candidate>
|
|
|
|
export let employee: Ref<Employee>
|
2021-08-07 17:03:06 +00:00
|
|
|
|
2021-09-08 15:36:04 +00:00
|
|
|
export let preserveCandidate = false
|
|
|
|
|
2021-09-16 09:46:04 +00:00
|
|
|
let status: Status = OK
|
2021-09-09 07:54:52 +00:00
|
|
|
let _space = space
|
|
|
|
|
2021-08-07 17:03:06 +00:00
|
|
|
const dispatch = createEventDispatcher()
|
|
|
|
const client = getClient()
|
|
|
|
|
2021-11-29 11:32:17 +00:00
|
|
|
export function canClose (): boolean {
|
2021-10-13 09:06:35 +00:00
|
|
|
return candidate === undefined && employee === undefined
|
|
|
|
}
|
|
|
|
|
2021-11-29 11:32:17 +00:00
|
|
|
async function createApplication () {
|
2021-10-10 14:48:16 +00:00
|
|
|
const state = await client.findOne(core.class.State, { space: _space })
|
|
|
|
if (state === undefined) {
|
|
|
|
throw new Error('create application: state not found')
|
|
|
|
}
|
2021-10-23 10:09:39 +00:00
|
|
|
const sequence = await client.findOne(view.class.Sequence, { attachedTo: recruit.class.Applicant })
|
|
|
|
if (sequence === undefined) {
|
|
|
|
throw new Error('sequence object not found')
|
2021-10-14 08:43:55 +00:00
|
|
|
}
|
2021-12-03 10:16:16 +00:00
|
|
|
const incResult = await client.updateDoc(
|
|
|
|
view.class.Sequence,
|
|
|
|
view.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,
|
2021-12-14 09:24:14 +00:00
|
|
|
doneState: null,
|
2021-12-03 10:16:16 +00:00
|
|
|
number: incResult.object.sequence,
|
|
|
|
employee: employee
|
|
|
|
}
|
|
|
|
)
|
2021-08-07 17:03:06 +00:00
|
|
|
}
|
2021-09-03 09:41:21 +00:00
|
|
|
|
2021-11-29 11:32:17 +00:00
|
|
|
async function validate (candidate: Ref<Candidate>, space: Ref<Space>) {
|
2021-12-10 08:42:05 +00:00
|
|
|
if (candidate == undefined) {
|
2021-09-16 09:46:04 +00:00
|
|
|
status = new Status(Severity.INFO, recruit.status.CandidateRequired, {})
|
|
|
|
} else {
|
|
|
|
if (space === undefined) {
|
|
|
|
status = new Status(Severity.INFO, recruit.status.VacancyRequired, {})
|
|
|
|
} else {
|
2021-11-29 11:32:17 +00:00
|
|
|
const applicants = await client.findAll(recruit.class.Applicant, { space, attachedTo: candidate })
|
2021-09-16 09:46:04 +00:00
|
|
|
if (applicants.length > 0) {
|
2021-11-29 11:32:17 +00:00
|
|
|
status = new Status(Severity.ERROR, recruit.status.ApplicationExists, {})
|
2021-09-16 09:46:04 +00:00
|
|
|
} else {
|
|
|
|
status = OK
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$: validate(candidate, _space)
|
2021-08-07 17:03:06 +00:00
|
|
|
</script>
|
|
|
|
|
2021-12-03 10:16:16 +00:00
|
|
|
<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')
|
|
|
|
}}
|
|
|
|
>
|
2021-10-13 20:04:18 +00:00
|
|
|
<StatusControl slot="error" {status} />
|
2021-09-03 15:39:10 +00:00
|
|
|
<Grid column={1} rowGap={1.75}>
|
2021-09-08 15:36:04 +00:00
|
|
|
{#if !preserveCandidate}
|
2021-12-03 10:16:16 +00:00
|
|
|
<UserBox _class={recruit.class.Candidate} title="Candidate" caption="Candidates" bind:value={candidate} />
|
2021-09-08 15:36:04 +00:00
|
|
|
{/if}
|
2021-12-03 10:16:16 +00:00
|
|
|
<UserBox
|
|
|
|
_class={contact.class.Employee}
|
|
|
|
title="Assigned recruiter"
|
|
|
|
caption="Recruiters"
|
|
|
|
bind:value={employee}
|
|
|
|
allowDeselect
|
|
|
|
titleDeselect={'Unassign recruiter'}
|
|
|
|
/>
|
2021-09-03 13:59:05 +00:00
|
|
|
</Grid>
|
|
|
|
</Card>
|