2022-03-04 09:01:46 +00:00
|
|
|
<!--
|
|
|
|
// Copyright © 2022 Hardcore Engineering Inc.
|
|
|
|
//
|
|
|
|
// 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-05-13 06:38:54 +00:00
|
|
|
import core, { Doc, DocumentQuery, Ref } from '@anticrm/core'
|
2022-03-04 09:01:46 +00:00
|
|
|
import { createQuery } from '@anticrm/presentation'
|
2022-04-27 14:29:11 +00:00
|
|
|
import { Vacancy } from '@anticrm/recruit'
|
2022-05-12 09:40:22 +00:00
|
|
|
import { Button, getCurrentLocation, Icon, IconAdd, Label, navigate, SearchEdit, showPopup } from '@anticrm/ui'
|
2022-05-04 08:08:12 +00:00
|
|
|
import { TableBrowser } from '@anticrm/view-resources'
|
2022-03-04 09:01:46 +00:00
|
|
|
import recruit from '../plugin'
|
|
|
|
import CreateVacancy from './CreateVacancy.svelte'
|
|
|
|
|
|
|
|
function action (vacancy: Ref<Vacancy>): void {
|
|
|
|
const loc = getCurrentLocation()
|
|
|
|
loc.path[2] = vacancy
|
|
|
|
loc.path.length = 3
|
|
|
|
navigate(loc)
|
|
|
|
}
|
|
|
|
|
|
|
|
let search: string = ''
|
|
|
|
let resultQuery: DocumentQuery<Doc> = {}
|
2022-03-22 09:13:17 +00:00
|
|
|
|
2022-04-27 14:29:11 +00:00
|
|
|
$: resultQuery = search === '' ? {} : { $search: search }
|
2022-03-04 09:01:46 +00:00
|
|
|
|
2022-04-29 05:27:17 +00:00
|
|
|
type ApplicationInfo = { count: number; modifiedOn: number }
|
2022-03-15 09:01:49 +00:00
|
|
|
let applications: Map<Ref<Vacancy>, ApplicationInfo> | undefined
|
2022-03-04 09:01:46 +00:00
|
|
|
|
|
|
|
const applicantQuery = createQuery()
|
2022-04-27 14:29:11 +00:00
|
|
|
$: applicantQuery.query(
|
2022-04-29 05:27:17 +00:00
|
|
|
recruit.class.Applicant,
|
|
|
|
{},
|
2022-04-27 14:29:11 +00:00
|
|
|
(res) => {
|
|
|
|
const result = new Map<Ref<Vacancy>, ApplicationInfo>()
|
2022-03-04 09:01:46 +00:00
|
|
|
|
2022-04-27 14:29:11 +00:00
|
|
|
for (const d of res) {
|
|
|
|
const v = result.get(d.space) ?? { count: 0, modifiedOn: 0 }
|
|
|
|
v.count++
|
|
|
|
v.modifiedOn = Math.max(v.modifiedOn, d.modifiedOn)
|
|
|
|
result.set(d.space, v)
|
|
|
|
}
|
2022-03-04 09:01:46 +00:00
|
|
|
|
2022-04-27 14:29:11 +00:00
|
|
|
applications = result
|
2022-04-29 05:27:17 +00:00
|
|
|
},
|
|
|
|
{
|
2022-04-27 14:29:11 +00:00
|
|
|
projection: {
|
|
|
|
_id: 1,
|
|
|
|
modifiedOn: 1,
|
|
|
|
space: 1
|
2022-03-04 09:01:46 +00:00
|
|
|
}
|
2022-04-27 14:29:11 +00:00
|
|
|
}
|
|
|
|
)
|
2022-03-04 09:01:46 +00:00
|
|
|
|
2022-04-19 09:38:31 +00:00
|
|
|
function showCreateDialog () {
|
2022-04-13 04:25:59 +00:00
|
|
|
showPopup(CreateVacancy, { space: recruit.space.CandidatesPublic }, 'top')
|
2022-03-04 09:01:46 +00:00
|
|
|
}
|
2022-04-29 05:27:17 +00:00
|
|
|
const applicationSorting = (a: Doc, b: Doc) =>
|
|
|
|
(applications?.get(b._id as Ref<Vacancy>)?.count ?? 0) - (applications?.get(a._id as Ref<Vacancy>)?.count ?? 0) ?? 0
|
|
|
|
const modifiedSorting = (a: Doc, b: Doc) =>
|
|
|
|
(applications?.get(b._id as Ref<Vacancy>)?.modifiedOn ?? 0) -
|
|
|
|
(applications?.get(a._id as Ref<Vacancy>)?.modifiedOn ?? 0) ?? 0
|
2022-03-04 09:01:46 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<div class="ac-header full">
|
|
|
|
<div class="ac-header__wrap-title">
|
|
|
|
<div class="ac-header__icon"><Icon icon={recruit.icon.Vacancy} size={'small'} /></div>
|
|
|
|
<span class="ac-header__title"><Label label={recruit.string.Vacancies} /></span>
|
|
|
|
</div>
|
|
|
|
<SearchEdit
|
|
|
|
bind:value={search}
|
2022-04-27 14:29:11 +00:00
|
|
|
on:change={(e) => {
|
|
|
|
search = e.detail
|
2022-03-04 09:01:46 +00:00
|
|
|
}}
|
|
|
|
/>
|
2022-04-19 09:38:31 +00:00
|
|
|
<Button icon={IconAdd} label={recruit.string.VacancyCreateLabel} kind={'primary'} on:click={showCreateDialog} />
|
2022-03-04 09:01:46 +00:00
|
|
|
</div>
|
2022-05-12 09:40:22 +00:00
|
|
|
<TableBrowser
|
|
|
|
_class={recruit.class.Vacancy}
|
|
|
|
config={[
|
|
|
|
{
|
|
|
|
key: '',
|
|
|
|
presenter: recruit.component.VacancyItemPresenter,
|
|
|
|
label: recruit.string.Vacancy,
|
|
|
|
sortingKey: 'name',
|
|
|
|
props: { action }
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: '',
|
|
|
|
presenter: recruit.component.VacancyCountPresenter,
|
|
|
|
label: recruit.string.Applications,
|
|
|
|
props: { applications },
|
|
|
|
sortingKey: '@applications',
|
|
|
|
sortingFunction: applicationSorting
|
|
|
|
},
|
|
|
|
'$lookup.company',
|
|
|
|
'location',
|
|
|
|
'description',
|
|
|
|
{
|
|
|
|
key: '',
|
|
|
|
presenter: recruit.component.VacancyModifiedPresenter,
|
|
|
|
label: core.string.Modified,
|
|
|
|
props: { applications },
|
|
|
|
sortingKey: 'modifiedOn',
|
|
|
|
sortingFunction: modifiedSorting
|
|
|
|
}
|
|
|
|
]}
|
|
|
|
query={{
|
|
|
|
...resultQuery,
|
|
|
|
archived: false
|
|
|
|
}}
|
|
|
|
showNotification
|
|
|
|
/>
|