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">
|
2021-12-15 09:04:43 +00:00
|
|
|
import type { Employee } from '@anticrm/contact'
|
|
|
|
import contact from '@anticrm/contact'
|
2021-12-20 09:37:15 +00:00
|
|
|
import { Account, Class, Client, Doc, generateId, Ref, SortingOrder } from '@anticrm/core'
|
|
|
|
import { getResource, OK, Resource, Severity, Status } from '@anticrm/platform'
|
2021-12-15 09:04:43 +00:00
|
|
|
import { Card, getClient, UserBox } from '@anticrm/presentation'
|
2021-12-20 09:37:15 +00:00
|
|
|
import type { Applicant, Candidate } from '@anticrm/recruit'
|
2021-12-21 09:09:46 +00:00
|
|
|
import { calcRank, SpaceWithStates, State } from '@anticrm/task'
|
2021-12-15 09:04:43 +00:00
|
|
|
import task from '@anticrm/task'
|
|
|
|
import { Grid, Status as StatusControl } from '@anticrm/ui'
|
|
|
|
import { createEventDispatcher } from 'svelte'
|
2021-08-07 17:03:06 +00:00
|
|
|
import recruit from '../plugin'
|
2021-12-20 09:37:15 +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>
|
2021-12-15 09:04:43 +00:00
|
|
|
export let assignee: 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-12-20 09:37:15 +00:00
|
|
|
|
|
|
|
const doc: Applicant = {
|
|
|
|
state: '' as Ref<State>,
|
|
|
|
doneState: null,
|
|
|
|
number: 0,
|
|
|
|
assignee: assignee,
|
|
|
|
rank: '',
|
|
|
|
attachedTo: candidate,
|
|
|
|
attachedToClass: recruit.class.Candidate,
|
|
|
|
_class: recruit.class.Applicant,
|
|
|
|
space: space,
|
|
|
|
_id: generateId(),
|
|
|
|
collection: 'applications',
|
|
|
|
modifiedOn: Date.now(),
|
|
|
|
modifiedBy: '' as Ref<Account>
|
|
|
|
}
|
2021-09-09 07:54:52 +00:00
|
|
|
|
2021-08-07 17:03:06 +00:00
|
|
|
const dispatch = createEventDispatcher()
|
|
|
|
const client = getClient()
|
2021-12-20 09:37:15 +00:00
|
|
|
const hierarchy = client.getHierarchy()
|
2021-08-07 17:03:06 +00:00
|
|
|
|
2021-11-29 11:32:17 +00:00
|
|
|
export function canClose (): boolean {
|
2021-12-15 09:04:43 +00:00
|
|
|
return candidate === undefined && assignee === undefined
|
2021-10-13 09:06:35 +00:00
|
|
|
}
|
|
|
|
|
2021-11-29 11:32:17 +00:00
|
|
|
async function createApplication () {
|
2021-12-20 09:37:15 +00:00
|
|
|
const state = await client.findOne(task.class.State, { space: doc.space })
|
2021-10-10 14:48:16 +00:00
|
|
|
if (state === undefined) {
|
|
|
|
throw new Error('create application: state not found')
|
|
|
|
}
|
2021-12-15 09:04:43 +00:00
|
|
|
const sequence = await client.findOne(task.class.Sequence, { attachedTo: recruit.class.Applicant })
|
2021-10-23 10:09:39 +00:00
|
|
|
if (sequence === undefined) {
|
|
|
|
throw new Error('sequence object not found')
|
2021-10-14 08:43:55 +00:00
|
|
|
}
|
2021-12-17 09:08:37 +00:00
|
|
|
|
|
|
|
const lastOne = await client.findOne(
|
|
|
|
recruit.class.Applicant,
|
|
|
|
{ state: state._id },
|
|
|
|
{ sort: { rank: SortingOrder.Descending } }
|
|
|
|
)
|
2021-12-03 10:16:16 +00:00
|
|
|
const incResult = await client.updateDoc(
|
2021-12-15 09:04:43 +00:00
|
|
|
task.class.Sequence,
|
|
|
|
task.space.Sequence,
|
2021-12-03 10:16:16 +00:00
|
|
|
sequence._id,
|
|
|
|
{
|
|
|
|
$inc: { sequence: 1 }
|
|
|
|
},
|
|
|
|
true
|
|
|
|
)
|
2021-12-17 09:08:37 +00:00
|
|
|
await client.addCollection(
|
2021-12-03 10:16:16 +00:00
|
|
|
recruit.class.Applicant,
|
2021-12-20 09:37:15 +00:00
|
|
|
doc.space,
|
|
|
|
doc.attachedTo,
|
2021-12-03 10:16:16 +00:00
|
|
|
recruit.class.Candidate,
|
|
|
|
'applications',
|
|
|
|
{
|
|
|
|
state: state._id,
|
2021-12-14 09:24:14 +00:00
|
|
|
doneState: null,
|
2021-12-20 09:37:15 +00:00
|
|
|
number: (incResult as any).object.sequence,
|
|
|
|
assignee: doc.assignee,
|
2021-12-17 09:08:37 +00:00
|
|
|
rank: calcRank(lastOne, undefined)
|
2021-12-03 10:16:16 +00:00
|
|
|
}
|
|
|
|
)
|
2021-08-07 17:03:06 +00:00
|
|
|
}
|
2021-09-03 09:41:21 +00:00
|
|
|
|
2021-12-20 09:37:15 +00:00
|
|
|
async function invokeValidate (
|
|
|
|
action: Resource<<T extends Doc>(doc: T, client: Client) => Promise<Status>>
|
|
|
|
): Promise<Status> {
|
|
|
|
const impl = await getResource(action)
|
|
|
|
return await impl(doc, client)
|
|
|
|
}
|
|
|
|
|
|
|
|
async function validate (doc: Applicant, _class: Ref<Class<Doc>>): Promise<void> {
|
|
|
|
const clazz = hierarchy.getClass(_class)
|
|
|
|
const validatorMixin = hierarchy.as(clazz, view.mixin.ObjectValidator)
|
|
|
|
if (validatorMixin?.validator != null) {
|
|
|
|
status = await invokeValidate(validatorMixin.validator)
|
|
|
|
} else if (clazz.extends != null) {
|
|
|
|
await validate(doc, clazz.extends)
|
2021-09-16 09:46:04 +00:00
|
|
|
} else {
|
2021-12-20 09:37:15 +00:00
|
|
|
status = OK
|
2021-09-16 09:46:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-20 09:37:15 +00:00
|
|
|
$: validate(doc, doc._class)
|
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'}
|
2021-12-20 09:37:15 +00:00
|
|
|
bind:space={doc.space}
|
2021-12-03 10:16:16 +00:00
|
|
|
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-20 09:37:15 +00:00
|
|
|
<UserBox _class={recruit.class.Candidate} title="Candidate" caption="Candidates" bind:value={doc.attachedTo} />
|
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"
|
2021-12-20 09:37:15 +00:00
|
|
|
bind:value={doc.assignee}
|
2021-12-03 10:16:16 +00:00
|
|
|
allowDeselect
|
|
|
|
titleDeselect={'Unassign recruiter'}
|
|
|
|
/>
|
2021-09-03 13:59:05 +00:00
|
|
|
</Grid>
|
|
|
|
</Card>
|