mirror of
https://github.com/hcengineering/platform.git
synced 2024-11-22 11:42:30 +03:00
Candidate link resolver (#3003)
This commit is contained in:
parent
359c1a81bc
commit
7f68032397
@ -747,6 +747,10 @@ export function createModel (builder: Builder): void {
|
||||
encode: recruit.function.GetObjectLinkFragment
|
||||
})
|
||||
|
||||
builder.mixin(recruit.mixin.Candidate, core.class.Class, view.mixin.LinkProvider, {
|
||||
encode: recruit.function.GetCandidateLinkFragment
|
||||
})
|
||||
|
||||
builder.createDoc(
|
||||
view.class.ActionCategory,
|
||||
core.space.Model,
|
||||
|
@ -40,6 +40,7 @@ export default mergeIds(recruitId, recruit, {
|
||||
},
|
||||
function: {
|
||||
GetObjectLinkFragment: '' as Resource<(doc: Doc, props: Record<string, any>) => Promise<Location>>,
|
||||
GetCandidateLinkFragment: '' as Resource<(doc: Doc, props: Record<string, any>) => Promise<Location>>,
|
||||
GetObjectLink: '' as Resource<(doc: Doc, props: Record<string, any>) => Promise<string>>
|
||||
},
|
||||
string: {
|
||||
|
@ -65,6 +65,7 @@ import VacancyTemplateEditor from './components/VacancyTemplateEditor.svelte'
|
||||
import recruit from './plugin'
|
||||
import {
|
||||
getAppTitle,
|
||||
getCandidateLink,
|
||||
getRevTitle,
|
||||
getSequenceId,
|
||||
getSequenceLink,
|
||||
@ -336,7 +337,8 @@ export default async (): Promise<Resources> => ({
|
||||
HasNoActiveApplicant: hasNoActiveApplicant,
|
||||
NoneApplications: noneApplicant,
|
||||
GetObjectLink: objectLinkProvider,
|
||||
GetObjectLinkFragment: getSequenceLink
|
||||
GetObjectLinkFragment: getSequenceLink,
|
||||
GetCandidateLinkFragment: getCandidateLink
|
||||
},
|
||||
resolver: {
|
||||
Location: resolveLocation
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { Class, Client, Doc, Ref } from '@hcengineering/core'
|
||||
import { getClient } from '@hcengineering/presentation'
|
||||
import { Applicant, recruitId, Review, Vacancy } from '@hcengineering/recruit'
|
||||
import { Applicant, Candidate, recruitId, Review, Vacancy } from '@hcengineering/recruit'
|
||||
import { getCurrentLocation, getPanelURI, Location, ResolvedLocation } from '@hcengineering/ui'
|
||||
import view from '@hcengineering/view'
|
||||
import { workbenchId } from '@hcengineering/workbench'
|
||||
@ -31,9 +31,38 @@ export async function resolveLocation (loc: Location): Promise<ResolvedLocation
|
||||
// shortlink
|
||||
if (isShortId(shortLink)) {
|
||||
return await generateLocation(loc, shortLink)
|
||||
} else {
|
||||
return await generateCandidateLink(loc, shortLink)
|
||||
}
|
||||
}
|
||||
|
||||
async function generateCandidateLink (loc: Location, _id: string): Promise<ResolvedLocation | undefined> {
|
||||
const client = getClient()
|
||||
const hierarchy = client.getHierarchy()
|
||||
|
||||
const doc = await client.findOne(recruit.mixin.Candidate, { _id: _id as Ref<Candidate> })
|
||||
if (doc === undefined) {
|
||||
console.error(`Could not find candidate with id ${_id}.`)
|
||||
return undefined
|
||||
}
|
||||
const appComponent = loc.path[0] ?? ''
|
||||
const workspace = loc.path[1] ?? ''
|
||||
const targetClass = hierarchy.getClass(recruit.mixin.Candidate)
|
||||
const panelComponent = hierarchy.as(targetClass, view.mixin.ObjectPanel)
|
||||
const component = panelComponent.component ?? view.component.EditDoc
|
||||
const defaultPath = [appComponent, workspace, recruitId, 'talents']
|
||||
|
||||
return {
|
||||
loc: {
|
||||
path: [appComponent, workspace],
|
||||
fragment: getPanelURI(component, doc._id, recruit.mixin.Candidate, 'content')
|
||||
},
|
||||
shouldNavigate: false,
|
||||
defaultLocation: {
|
||||
path: defaultPath,
|
||||
fragment: getPanelURI(component, doc._id, recruit.mixin.Candidate, 'content')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function generateLocation (loc: Location, shortLink: string): Promise<ResolvedLocation | undefined> {
|
||||
@ -97,6 +126,17 @@ export async function getSequenceLink (doc: RecruitDocument): Promise<Location>
|
||||
return loc
|
||||
}
|
||||
|
||||
export async function getCandidateLink (doc: Candidate): Promise<Location> {
|
||||
const loc = getCurrentLocation()
|
||||
loc.path.length = 2
|
||||
loc.fragment = undefined
|
||||
loc.query = undefined
|
||||
loc.path[2] = recruitId
|
||||
loc.path[3] = doc._id
|
||||
|
||||
return loc
|
||||
}
|
||||
|
||||
async function getTitle<T extends RecruitDocument> (
|
||||
client: Client,
|
||||
ref: Ref<T>,
|
||||
|
@ -843,7 +843,7 @@ export async function getObjectLinkFragment (
|
||||
props: Record<string, any> = {},
|
||||
component: AnyComponent = view.component.EditDoc
|
||||
): Promise<Location> {
|
||||
const provider = hierarchy.classHierarchyMixin(object._class, view.mixin.LinkProvider)
|
||||
const provider = hierarchy.classHierarchyMixin(Hierarchy.mixinOrClass(object), view.mixin.LinkProvider)
|
||||
if (provider?.encode !== undefined) {
|
||||
const f = await getResource(provider.encode)
|
||||
const res = await f(object, props)
|
||||
|
Loading…
Reference in New Issue
Block a user