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">
|
2022-01-06 11:38:40 +00:00
|
|
|
|
import attachment from '@anticrm/attachment'
|
|
|
|
|
import contact, { combineName, Person } from '@anticrm/contact'
|
2022-01-11 09:05:53 +00:00
|
|
|
|
import type { Data, MixinData, Ref } from '@anticrm/core'
|
2021-09-10 16:59:11 +00:00
|
|
|
|
import { generateId } from '@anticrm/core'
|
2022-01-12 09:52:22 +00:00
|
|
|
|
import { getResource, setPlatformStatus, unknownError } from '@anticrm/platform'
|
2022-01-14 09:06:32 +00:00
|
|
|
|
import presentation, { EditableAvatar, Card, Channels, getClient, PDFViewer } from '@anticrm/presentation'
|
2021-08-31 14:54:47 +00:00
|
|
|
|
import type { Candidate } from '@anticrm/recruit'
|
2022-01-06 11:38:40 +00:00
|
|
|
|
import { CircleButton, EditBox, IconAdd, IconFile as FileIcon, Label, Link, showPopup, Spinner } from '@anticrm/ui'
|
|
|
|
|
import { createEventDispatcher } from 'svelte'
|
|
|
|
|
import recruit from '../plugin'
|
|
|
|
|
import FileUpload from './icons/FileUpload.svelte'
|
2021-09-22 14:06:21 +00:00
|
|
|
|
import YesNo from './YesNo.svelte'
|
|
|
|
|
|
2021-10-01 12:28:52 +00:00
|
|
|
|
let firstName = ''
|
|
|
|
|
let lastName = ''
|
|
|
|
|
|
2022-01-06 11:38:40 +00:00
|
|
|
|
export function canClose (): boolean {
|
2021-12-03 09:03:28 +00:00
|
|
|
|
return firstName === '' && lastName === '' && resume.uuid === undefined
|
2021-10-12 10:11:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-01 12:28:52 +00:00
|
|
|
|
const object: Candidate = {} as Candidate
|
2021-08-07 17:03:06 +00:00
|
|
|
|
|
2022-01-06 11:38:40 +00:00
|
|
|
|
const resume = {} as {
|
2021-08-30 17:50:33 +00:00
|
|
|
|
name: string
|
|
|
|
|
uuid: string
|
|
|
|
|
size: number
|
|
|
|
|
type: string
|
2021-10-27 14:41:54 +00:00
|
|
|
|
lastModified: number
|
2021-08-30 17:50:33 +00:00
|
|
|
|
}
|
2021-08-07 17:03:06 +00:00
|
|
|
|
|
2021-08-30 10:17:15 +00:00
|
|
|
|
const dispatch = createEventDispatcher()
|
2021-08-07 17:03:06 +00:00
|
|
|
|
const client = getClient()
|
2021-09-15 17:03:34 +00:00
|
|
|
|
const candidateId = generateId()
|
2021-08-07 17:03:06 +00:00
|
|
|
|
|
2022-01-06 11:38:40 +00:00
|
|
|
|
async function createCandidate () {
|
2022-01-12 09:52:22 +00:00
|
|
|
|
const uploadFile = await getResource(attachment.helper.UploadFile)
|
2022-01-14 09:05:24 +00:00
|
|
|
|
const avatarProp = avatar !== undefined
|
|
|
|
|
? { avatar: await uploadFile(avatar) }
|
|
|
|
|
: {}
|
2022-01-06 11:38:40 +00:00
|
|
|
|
const candidate: Data<Person> = {
|
2021-10-01 12:28:52 +00:00
|
|
|
|
name: combineName(firstName, lastName),
|
2021-09-10 16:59:11 +00:00
|
|
|
|
city: object.city,
|
2022-01-12 09:52:22 +00:00
|
|
|
|
channels: object.channels,
|
2022-01-14 09:05:24 +00:00
|
|
|
|
...avatarProp
|
2022-01-06 11:38:40 +00:00
|
|
|
|
}
|
|
|
|
|
const candidateData: MixinData<Person, Candidate> = {
|
|
|
|
|
title: object.title,
|
2021-10-04 15:46:06 +00:00
|
|
|
|
onsite: object.onsite,
|
|
|
|
|
remote: object.remote
|
2021-09-15 17:03:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-11 09:05:53 +00:00
|
|
|
|
const id = await client.createDoc(contact.class.Person, contact.space.Contacts, candidate, candidateId)
|
|
|
|
|
await client.createMixin(id as Ref<Person>, contact.class.Person, contact.space.Contacts, recruit.mixin.Candidate, candidateData)
|
2022-01-06 11:38:40 +00:00
|
|
|
|
|
2021-08-30 17:50:33 +00:00
|
|
|
|
console.log('resume name', resume.name)
|
|
|
|
|
|
2021-10-27 14:41:54 +00:00
|
|
|
|
if (resume.uuid !== undefined) {
|
2022-01-11 09:05:53 +00:00
|
|
|
|
client.addCollection(attachment.class.Attachment, contact.space.Contacts, id, contact.class.Person, 'attachments', {
|
2021-10-27 14:41:54 +00:00
|
|
|
|
name: resume.name,
|
|
|
|
|
file: resume.uuid,
|
|
|
|
|
size: resume.size,
|
|
|
|
|
type: resume.type,
|
|
|
|
|
lastModified: resume.lastModified
|
|
|
|
|
})
|
|
|
|
|
}
|
2021-08-30 10:17:15 +00:00
|
|
|
|
|
|
|
|
|
dispatch('close')
|
2021-08-07 17:03:06 +00:00
|
|
|
|
}
|
2021-08-30 10:17:15 +00:00
|
|
|
|
|
2021-09-10 06:41:22 +00:00
|
|
|
|
let inputFile: HTMLInputElement
|
2021-09-10 16:59:11 +00:00
|
|
|
|
let loading = false
|
2021-10-27 14:41:54 +00:00
|
|
|
|
let dragover = false
|
2021-09-10 16:59:11 +00:00
|
|
|
|
|
2022-01-06 11:38:40 +00:00
|
|
|
|
async function createAttachment (file: File) {
|
2021-09-10 16:59:11 +00:00
|
|
|
|
loading = true
|
|
|
|
|
try {
|
2022-01-12 09:52:22 +00:00
|
|
|
|
const uploadFile = await getResource(attachment.helper.UploadFile)
|
|
|
|
|
|
2022-01-20 09:27:41 +00:00
|
|
|
|
resume.uuid = await uploadFile(file, {
|
|
|
|
|
space: contact.space.Contacts,
|
|
|
|
|
attachedTo: candidateId
|
|
|
|
|
})
|
2021-09-10 16:59:11 +00:00
|
|
|
|
resume.name = file.name
|
|
|
|
|
resume.size = file.size
|
|
|
|
|
resume.type = file.type
|
2021-10-27 14:41:54 +00:00
|
|
|
|
resume.lastModified = file.lastModified
|
2021-09-10 16:59:11 +00:00
|
|
|
|
|
|
|
|
|
console.log('uploaded file uuid', resume.uuid)
|
2021-09-15 17:03:34 +00:00
|
|
|
|
} catch (err: any) {
|
|
|
|
|
setPlatformStatus(unknownError(err))
|
2021-09-10 16:59:11 +00:00
|
|
|
|
} finally {
|
|
|
|
|
loading = false
|
2021-09-10 14:26:16 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-09-10 16:59:11 +00:00
|
|
|
|
|
2022-01-06 11:38:40 +00:00
|
|
|
|
function drop (event: DragEvent) {
|
2021-10-27 14:41:54 +00:00
|
|
|
|
dragover = false
|
|
|
|
|
const droppedFile = event.dataTransfer?.files[0]
|
|
|
|
|
if (droppedFile !== undefined) { createAttachment(droppedFile) }
|
2022-01-06 11:38:40 +00:00
|
|
|
|
}
|
2021-10-27 14:41:54 +00:00
|
|
|
|
|
2022-01-06 11:38:40 +00:00
|
|
|
|
function fileSelected () {
|
2021-09-10 16:59:11 +00:00
|
|
|
|
console.log(inputFile.files)
|
|
|
|
|
const file = inputFile.files?.[0]
|
|
|
|
|
if (file !== undefined) { createAttachment(file) }
|
|
|
|
|
}
|
2022-01-12 09:52:22 +00:00
|
|
|
|
|
|
|
|
|
let avatar: File | undefined
|
|
|
|
|
|
|
|
|
|
function onAvatarDone (e: any) {
|
|
|
|
|
const { file } = e.detail
|
|
|
|
|
|
|
|
|
|
avatar = file
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-07 17:03:06 +00:00
|
|
|
|
</script>
|
|
|
|
|
|
2021-09-10 06:41:22 +00:00
|
|
|
|
<!-- <DialogHeader {space} {object} {newValue} {resume} create={true} on:save={createCandidate}/> -->
|
|
|
|
|
|
2022-01-14 09:06:32 +00:00
|
|
|
|
<Card label={recruit.string.CreateCandidate}
|
2021-09-10 06:41:22 +00:00
|
|
|
|
okAction={createCandidate}
|
2021-10-01 12:28:52 +00:00
|
|
|
|
canSave={firstName.length > 0 && lastName.length > 0}
|
2022-01-11 09:05:53 +00:00
|
|
|
|
space={contact.space.Contacts}
|
2021-09-10 06:41:22 +00:00
|
|
|
|
on:close={() => { dispatch('close') }}>
|
|
|
|
|
|
2021-10-13 08:39:26 +00:00
|
|
|
|
<!-- <StatusComponent slot="error" status={{ severity: Severity.ERROR, code: 'Can’t save the object because it already exists' }} /> -->
|
2021-09-22 14:06:21 +00:00
|
|
|
|
<div class="flex-row-center">
|
2021-11-10 20:10:11 +00:00
|
|
|
|
<div class="mr-4">
|
2022-01-12 09:52:22 +00:00
|
|
|
|
<EditableAvatar avatar={object.avatar} size={'large'} on:done={onAvatarDone}/>
|
2021-09-10 06:41:22 +00:00
|
|
|
|
</div>
|
|
|
|
|
<div class="flex-col">
|
2021-10-27 14:18:00 +00:00
|
|
|
|
<div class="fs-title"><EditBox placeholder="John" maxWidth="10rem" bind:value={firstName}/></div>
|
|
|
|
|
<div class="fs-title mb-1"><EditBox placeholder="Appleseed" maxWidth="10rem" bind:value={lastName}/></div>
|
2021-11-17 15:20:30 +00:00
|
|
|
|
<div class="small-text"><EditBox placeholder="Title" maxWidth="10rem" bind:value={object.title}/></div>
|
|
|
|
|
<div class="small-text"><EditBox placeholder="Location" maxWidth="10rem" bind:value={object.city}/></div>
|
2021-09-10 06:41:22 +00:00
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2021-10-27 14:18:00 +00:00
|
|
|
|
|
|
|
|
|
<div class="flex-row-center channels">
|
|
|
|
|
{#if !object.channels || object.channels.length === 0}
|
2021-12-06 10:07:08 +00:00
|
|
|
|
<CircleButton icon={IconAdd} size={'small'} transparent on:click={(ev) => showPopup(contact.component.SocialEditor, { values: object.channels ?? [] }, ev.target, (result) => { object.channels = result })} />
|
2022-01-14 09:06:32 +00:00
|
|
|
|
<span><Label label={presentation.string.AddSocialLinks} /></span>
|
2021-10-27 14:18:00 +00:00
|
|
|
|
{:else}
|
|
|
|
|
<Channels value={object.channels} size={'small'} />
|
2021-11-25 11:09:37 +00:00
|
|
|
|
<div class="ml-1">
|
2022-01-12 09:01:54 +00:00
|
|
|
|
<CircleButton icon={contact.icon.Edit} size={'small'} transparent on:click={(ev) => showPopup(contact.component.SocialEditor, { values: object.channels ?? [] }, ev.target, (result) => { object.channels = result })} />
|
2021-11-25 11:09:37 +00:00
|
|
|
|
</div>
|
2021-10-27 14:18:00 +00:00
|
|
|
|
{/if}
|
|
|
|
|
</div>
|
|
|
|
|
|
2021-12-08 09:24:24 +00:00
|
|
|
|
<div class="flex-center resume" class:solid={dragover || resume.uuid}
|
2021-10-27 14:41:54 +00:00
|
|
|
|
on:dragover|preventDefault={ () => { dragover = true } }
|
|
|
|
|
on:dragleave={ () => { dragover = false } }
|
|
|
|
|
on:drop|preventDefault|stopPropagation={drop}>
|
2021-10-27 14:18:00 +00:00
|
|
|
|
{#if resume.uuid}
|
2021-12-08 09:23:12 +00:00
|
|
|
|
<Link label={resume.name} href={'#'} icon={FileIcon} maxLenght={16} on:click={ () => { showPopup(PDFViewer, { file: resume.uuid, name: resume.name }, 'right') } }/>
|
2021-10-27 14:18:00 +00:00
|
|
|
|
{:else}
|
|
|
|
|
{#if loading}
|
|
|
|
|
<Link label={'Uploading...'} href={'#'} icon={Spinner} disabled />
|
|
|
|
|
{:else}
|
|
|
|
|
<Link label={'Add or drop resume'} href={'#'} icon={FileUpload} on:click={ () => { inputFile.click() } } />
|
|
|
|
|
{/if}
|
|
|
|
|
<input bind:this={inputFile} type="file" name="file" id="file" style="display: none" on:change={fileSelected}/>
|
|
|
|
|
{/if}
|
|
|
|
|
</div>
|
|
|
|
|
|
2021-10-13 08:39:26 +00:00
|
|
|
|
<div class="separator" />
|
2021-09-22 14:06:21 +00:00
|
|
|
|
<div class="flex-col locations">
|
2022-01-14 09:06:32 +00:00
|
|
|
|
<span><Label label={recruit.string.WorkLocationPreferences} /></span>
|
|
|
|
|
<div class="row"><Label label={recruit.string.Onsite} /><YesNo bind:value={object.onsite} /></div>
|
|
|
|
|
<div class="row"><Label label={recruit.string.Remote} /><YesNo bind:value={object.remote} /></div>
|
2021-09-22 14:06:21 +00:00
|
|
|
|
</div>
|
2021-09-10 06:41:22 +00:00
|
|
|
|
</Card>
|
|
|
|
|
|
|
|
|
|
<style lang="scss">
|
2021-10-27 14:18:00 +00:00
|
|
|
|
.channels {
|
|
|
|
|
margin-top: 1.25rem;
|
|
|
|
|
span { margin-left: .5rem; }
|
2021-09-10 06:41:22 +00:00
|
|
|
|
}
|
2021-10-27 14:18:00 +00:00
|
|
|
|
|
2021-09-22 14:06:21 +00:00
|
|
|
|
.locations {
|
|
|
|
|
span {
|
|
|
|
|
margin-bottom: .125rem;
|
|
|
|
|
font-weight: 500;
|
|
|
|
|
font-size: .75rem;
|
|
|
|
|
color: var(--theme-content-accent-color);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.row {
|
|
|
|
|
display: flex;
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
align-items: center;
|
|
|
|
|
margin-top: .75rem;
|
|
|
|
|
color: var(--theme-caption-color);
|
|
|
|
|
}
|
2021-09-10 06:41:22 +00:00
|
|
|
|
}
|
2021-10-27 14:18:00 +00:00
|
|
|
|
|
2021-10-13 08:39:26 +00:00
|
|
|
|
.separator {
|
|
|
|
|
margin: 1rem 0;
|
|
|
|
|
height: 1px;
|
|
|
|
|
background-color: var(--theme-card-divider);
|
|
|
|
|
}
|
2021-10-27 14:18:00 +00:00
|
|
|
|
|
|
|
|
|
.resume {
|
|
|
|
|
margin-top: 1rem;
|
|
|
|
|
padding: .75rem;
|
2021-12-08 09:24:24 +00:00
|
|
|
|
background: var(--theme-zone-bg);
|
|
|
|
|
border: 1px dashed var(--theme-zone-border);
|
2021-10-27 14:18:00 +00:00
|
|
|
|
border-radius: .5rem;
|
|
|
|
|
backdrop-filter: blur(10px);
|
|
|
|
|
&.solid { border-style: solid; }
|
|
|
|
|
}
|
2021-09-10 06:41:22 +00:00
|
|
|
|
</style>
|