2021-08-07 17:03:06 +00:00
|
|
|
//
|
|
|
|
// Copyright © 2020 Anticrm Platform Contributors.
|
2021-11-18 12:48:05 +00:00
|
|
|
//
|
2021-08-07 17:03:06 +00:00
|
|
|
// 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
|
2021-11-18 12:48:05 +00:00
|
|
|
//
|
2021-08-07 17:03:06 +00:00
|
|
|
// 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.
|
2021-11-18 12:48:05 +00:00
|
|
|
//
|
2021-08-07 17:03:06 +00:00
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
//
|
|
|
|
|
2021-12-20 09:37:15 +00:00
|
|
|
import type { Client, Doc } from '@anticrm/core'
|
2022-02-22 09:09:13 +00:00
|
|
|
import { getMetadata, IntlString, OK, Resources, Severity, Status, translate } from '@anticrm/platform'
|
|
|
|
import { Applicant, Vacancy } from '@anticrm/recruit'
|
2022-01-11 09:05:53 +00:00
|
|
|
import { showPopup } from '@anticrm/ui'
|
2021-09-11 09:32:01 +00:00
|
|
|
import ApplicationPresenter from './components/ApplicationPresenter.svelte'
|
2021-12-15 09:15:43 +00:00
|
|
|
import Applications from './components/Applications.svelte'
|
2022-01-11 09:05:53 +00:00
|
|
|
import ApplicationsPresenter from './components/ApplicationsPresenter.svelte'
|
2022-01-06 11:38:40 +00:00
|
|
|
import Candidates from './components/Candidates.svelte'
|
2022-01-11 09:05:53 +00:00
|
|
|
import CreateApplication from './components/CreateApplication.svelte'
|
|
|
|
import CreateCandidate from './components/CreateCandidate.svelte'
|
|
|
|
import CreateVacancy from './components/CreateVacancy.svelte'
|
|
|
|
import EditApplication from './components/EditApplication.svelte'
|
|
|
|
import EditVacancy from './components/EditVacancy.svelte'
|
|
|
|
import KanbanCard from './components/KanbanCard.svelte'
|
|
|
|
import TemplatesIcon from './components/TemplatesIcon.svelte'
|
2021-12-20 09:37:15 +00:00
|
|
|
import recruit from './plugin'
|
2022-01-21 09:05:55 +00:00
|
|
|
import { ObjectSearchResult } from '@anticrm/presentation'
|
|
|
|
import task from '@anticrm/task'
|
|
|
|
import ApplicationItem from './components/ApplicationItem.svelte'
|
2022-02-11 09:19:21 +00:00
|
|
|
import VacancyPresenter from './components/VacancyPresenter.svelte'
|
2022-02-16 09:02:31 +00:00
|
|
|
import SkillsView from './components/SkillsView.svelte'
|
2022-02-22 09:09:13 +00:00
|
|
|
import login from '@anticrm/login'
|
|
|
|
import workbench from '@anticrm/workbench'
|
|
|
|
import view from '@anticrm/view'
|
2021-09-25 18:33:36 +00:00
|
|
|
|
2021-11-18 12:48:05 +00:00
|
|
|
async function createApplication (object: Doc): Promise<void> {
|
2021-09-25 18:33:36 +00:00
|
|
|
showPopup(CreateApplication, { candidate: object._id, preserveCandidate: true })
|
|
|
|
}
|
|
|
|
|
2021-12-20 09:37:15 +00:00
|
|
|
export async function applicantValidator (applicant: Applicant, client: Client): Promise<Status> {
|
|
|
|
if (applicant.attachedTo === undefined) {
|
|
|
|
return new Status(Severity.INFO, recruit.status.CandidateRequired, {})
|
|
|
|
}
|
|
|
|
if (applicant.space === undefined) {
|
|
|
|
return new Status(Severity.INFO, recruit.status.VacancyRequired, {})
|
|
|
|
}
|
|
|
|
const applicants = await client.findAll(recruit.class.Applicant, {
|
|
|
|
space: applicant.space,
|
|
|
|
attachedTo: applicant.attachedTo
|
|
|
|
})
|
|
|
|
if (applicants.filter((p) => p._id !== applicant._id).length > 0) {
|
|
|
|
return new Status(Severity.ERROR, recruit.status.ApplicationExists, {})
|
|
|
|
}
|
|
|
|
return OK
|
|
|
|
}
|
|
|
|
|
2022-01-21 09:05:55 +00:00
|
|
|
export async function queryApplication (client: Client, search: string): Promise<ObjectSearchResult[]> {
|
|
|
|
const _class = recruit.class.Applicant
|
|
|
|
const cl = client.getHierarchy().getClass(_class)
|
|
|
|
const shortLabel = (await translate(cl.shortLabel ?? '' as IntlString, {})).toUpperCase()
|
|
|
|
|
|
|
|
// Check number pattern
|
|
|
|
|
|
|
|
const sequence = (await client.findOne(task.class.Sequence, { attachedTo: _class }))?.sequence ?? 0
|
|
|
|
|
|
|
|
const named = new Map((await client.findAll(_class, { $search: search }, { limit: 200 })).map(e => [e._id, e]))
|
|
|
|
const nids: number[] = []
|
|
|
|
if (sequence > 0) {
|
|
|
|
for (let n = 0; n < sequence; n++) {
|
|
|
|
const v = `${n}`
|
|
|
|
if (v.includes(search)) {
|
|
|
|
nids.push(n)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const numbered = await client.findAll<Applicant>(_class, { number: { $in: nids } }, { limit: 200 })
|
|
|
|
for (const d of numbered) {
|
|
|
|
if (!named.has(d._id)) {
|
|
|
|
named.set(d._id, d)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Array.from(named.values()).map(e => ({
|
|
|
|
doc: e,
|
|
|
|
title: `${shortLabel}-${e.number}`,
|
|
|
|
icon: task.icon.Task,
|
|
|
|
component: ApplicationItem
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
|
2021-11-18 12:48:05 +00:00
|
|
|
export default async (): Promise<Resources> => ({
|
2021-09-25 18:33:36 +00:00
|
|
|
actionImpl: {
|
|
|
|
CreateApplication: createApplication
|
|
|
|
},
|
2021-12-20 09:37:15 +00:00
|
|
|
validator: {
|
|
|
|
ApplicantValidator: applicantValidator
|
|
|
|
},
|
2021-08-07 17:03:06 +00:00
|
|
|
component: {
|
|
|
|
CreateVacancy,
|
|
|
|
CreateApplication,
|
2021-12-17 09:04:49 +00:00
|
|
|
EditApplication,
|
2021-09-08 11:24:49 +00:00
|
|
|
KanbanCard,
|
2021-09-26 11:18:19 +00:00
|
|
|
ApplicationPresenter,
|
2021-12-02 09:09:37 +00:00
|
|
|
ApplicationsPresenter,
|
2021-12-14 09:24:14 +00:00
|
|
|
EditVacancy,
|
2021-12-15 09:15:43 +00:00
|
|
|
TemplatesIcon,
|
2022-01-06 11:38:40 +00:00
|
|
|
Applications,
|
2022-01-11 09:05:53 +00:00
|
|
|
Candidates,
|
2022-02-11 09:19:21 +00:00
|
|
|
CreateCandidate,
|
2022-02-16 09:02:31 +00:00
|
|
|
VacancyPresenter,
|
|
|
|
SkillsView
|
2022-01-21 09:05:55 +00:00
|
|
|
},
|
|
|
|
completion: {
|
|
|
|
ApplicationQuery: async (client: Client, query: string) => await queryApplication(client, query)
|
2021-11-18 12:48:05 +00:00
|
|
|
}
|
2021-08-07 17:03:06 +00:00
|
|
|
})
|