-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TSK-1015: Bitrix Create Vacancy/Application
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
- Loading branch information
Showing
16 changed files
with
381 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
plugins/bitrix-resources/src/components/mappings/CreateHRApplicationMapping.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<script lang="ts"> | ||
import { | ||
BitrixEntityMapping, | ||
BitrixFieldMapping, | ||
CreateHRApplication, | ||
Fields, | ||
MappingOperation | ||
} from '@hcengineering/bitrix' | ||
import { AnyAttribute } from '@hcengineering/core' | ||
import { getEmbeddedLabel } from '@hcengineering/platform' | ||
import { getClient } from '@hcengineering/presentation' | ||
import task from '@hcengineering/task' | ||
import { DropdownLabels, DropdownTextItem } from '@hcengineering/ui' | ||
import { ObjectBox } from '@hcengineering/view-resources' | ||
import bitrix from '../../plugin' | ||
import recruit from '@hcengineering/recruit' | ||
export let mapping: BitrixEntityMapping | ||
export let fields: Fields = {} | ||
export let attribute: AnyAttribute | ||
export let field: BitrixFieldMapping | undefined | ||
let stateField = (field?.operation as CreateHRApplication)?.stateField | ||
let vacancyField = (field?.operation as CreateHRApplication)?.vacancyField | ||
let defaultTemplate = (field?.operation as CreateHRApplication)?.defaultTemplate | ||
const client = getClient() | ||
export async function save (): Promise<void> { | ||
if (field !== undefined) { | ||
await client.update(field, { | ||
operation: { | ||
kind: MappingOperation.CreateHRApplication, | ||
stateField, | ||
vacancyField, | ||
defaultTemplate | ||
} | ||
}) | ||
} else { | ||
await client.addCollection(bitrix.class.FieldMapping, mapping.space, mapping._id, mapping._class, 'fields', { | ||
ofClass: attribute.attributeOf, | ||
attributeName: attribute.name, | ||
operation: { | ||
kind: MappingOperation.CreateHRApplication, | ||
stateField, | ||
vacancyField, | ||
defaultTemplate | ||
} | ||
}) | ||
} | ||
} | ||
function getItems (fields: Fields): DropdownTextItem[] { | ||
return Object.entries(fields).map((it) => ({ | ||
id: it[0], | ||
label: `${it[1].formLabel ?? it[1].title}${it[0].startsWith('UF_') ? ' *' : ''}` | ||
})) | ||
} | ||
$: items = getItems(fields) | ||
</script> | ||
|
||
<div class="flex-col flex-wrap"> | ||
<div class="flex-row-center gap-2"> | ||
<div class="flex-col w-120"> | ||
<DropdownLabels minW0={false} label={getEmbeddedLabel('Vacancy field')} {items} bind:selected={vacancyField} /> | ||
<DropdownLabels minW0={false} label={getEmbeddedLabel('State field')} {items} bind:selected={stateField} /> | ||
<ObjectBox | ||
label={getEmbeddedLabel('Template')} | ||
searchField={'title'} | ||
_class={task.class.KanbanTemplate} | ||
docQuery={{ space: recruit.space.VacancyTemplates }} | ||
bind:value={defaultTemplate} | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<style lang="scss"> | ||
.pattern { | ||
margin: 0.5rem; | ||
padding: 0.5rem; | ||
flex-shrink: 0; | ||
border: 1px dashed var(--accent-color); | ||
border-radius: 0.25rem; | ||
font-weight: 500; | ||
font-size: 0.75rem; | ||
// text-transform: uppercase; | ||
color: var(--accent-color); | ||
&:hover { | ||
color: var(--caption-color); | ||
} | ||
} | ||
</style> |
37 changes: 37 additions & 0 deletions
37
plugins/bitrix-resources/src/components/mappings/CreateHRApplicationPresenter.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<script lang="ts"> | ||
import { BitrixEntityMapping, BitrixFieldMapping, CreateHRApplication } from '@hcengineering/bitrix' | ||
import task from '@hcengineering/task' | ||
import { ObjectPresenter } from '@hcengineering/view-resources' | ||
export let mapping: BitrixEntityMapping | ||
export let value: BitrixFieldMapping | ||
$: op = value.operation as CreateHRApplication | ||
</script> | ||
|
||
<div class="flex flex-wrap"> | ||
<div class="pattern flex-row-center gap-2"> | ||
{mapping.bitrixFields[op.vacancyField]?.filterLabel} -> {mapping.bitrixFields[op.stateField]?.filterLabel} | ||
<span class="p-1">-></span> | ||
<ObjectPresenter objectId={op.defaultTemplate} _class={task.class.KanbanTemplate} /> | ||
</div> | ||
</div> | ||
|
||
<style lang="scss"> | ||
.pattern { | ||
margin: 0.1rem; | ||
padding: 0.3rem; | ||
flex-shrink: 0; | ||
border: 1px dashed var(--accent-color); | ||
border-radius: 0.25rem; | ||
font-weight: 500; | ||
font-size: 0.75rem; | ||
// text-transform: uppercase; | ||
color: var(--accent-color); | ||
&:hover { | ||
color: var(--caption-color); | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { Organization } from '@hcengineering/contact' | ||
import core, { Account, Client, Doc, Ref, SortingOrder, TxOperations } from '@hcengineering/core' | ||
import recruit, { Vacancy } from '@hcengineering/recruit' | ||
import task, { KanbanTemplate, State, calcRank, createKanban } from '@hcengineering/task' | ||
|
||
export async function createVacancy ( | ||
rawClient: Client, | ||
name: string, | ||
templateId: Ref<KanbanTemplate>, | ||
account: Ref<Account>, | ||
company?: Ref<Organization> | ||
): Promise<Ref<Vacancy>> { | ||
const client = new TxOperations(rawClient, account) | ||
const template = await client.findOne(task.class.KanbanTemplate, { _id: templateId }) | ||
if (template === undefined) { | ||
throw Error(`Failed to find target kanban template: ${templateId}`) | ||
} | ||
|
||
const sequence = await client.findOne(task.class.Sequence, { attachedTo: recruit.class.Vacancy }) | ||
if (sequence === undefined) { | ||
throw new Error('sequence object not found') | ||
} | ||
|
||
const incResult = await client.update(sequence, { $inc: { sequence: 1 } }, true) | ||
|
||
const id = await client.createDoc(recruit.class.Vacancy, core.space.Space, { | ||
name, | ||
description: template.shortDescription ?? '', | ||
fullDescription: template.description, | ||
private: false, | ||
archived: false, | ||
company, | ||
number: (incResult as any).object.sequence, | ||
members: [] | ||
}) | ||
|
||
await createKanban(client, id, templateId) | ||
return id | ||
} | ||
|
||
export async function createApplication ( | ||
client: TxOperations, | ||
selectedState: State, | ||
_space: Ref<Vacancy>, | ||
doc: Doc | ||
): Promise<void> { | ||
if (selectedState === undefined) { | ||
throw new Error(`Please select initial state:${_space}`) | ||
} | ||
const state = await client.findOne(task.class.State, { space: _space, _id: selectedState?._id }) | ||
if (state === undefined) { | ||
throw new Error(`create application: state not found space:${_space}`) | ||
} | ||
const sequence = await client.findOne(task.class.Sequence, { attachedTo: recruit.class.Applicant }) | ||
if (sequence === undefined) { | ||
throw new Error('sequence object not found') | ||
} | ||
|
||
const lastOne = await client.findOne(recruit.class.Applicant, {}, { sort: { rank: SortingOrder.Descending } }) | ||
const incResult = await client.update(sequence, { $inc: { sequence: 1 } }, true) | ||
|
||
await client.addCollection(recruit.class.Applicant, _space, doc._id, recruit.mixin.Candidate, 'applications', { | ||
state: state._id, | ||
doneState: null, | ||
number: (incResult as any).object.sequence, | ||
assignee: null, | ||
rank: calcRank(lastOne, undefined), | ||
startDate: null, | ||
dueDate: null, | ||
createOn: Date.now() | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.