Lead actions (#2096)

Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
Andrey Sobolev 2022-06-16 23:42:37 +07:00 committed by GitHub
parent 4e6317655a
commit e661fb1a87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 102 additions and 16 deletions

View File

@ -231,6 +231,54 @@ export function createModel (builder: Builder): void {
builder.mixin(lead.mixin.Customer, core.class.Mixin, view.mixin.ObjectFactory, {
component: lead.component.CreateCustomer
})
builder.createDoc(
view.class.ActionCategory,
core.space.Model,
{ label: lead.string.LeadApplication, visible: true },
lead.category.Lead
)
createAction(builder, {
action: view.actionImpl.ShowPopup,
actionProps: {
component: lead.component.CreateLead,
_id: 'customer',
element: 'top',
props: {
preserveCustomer: true
}
},
label: lead.string.CreateLead,
icon: lead.icon.Lead,
input: 'focus',
category: lead.category.Lead,
target: contact.class.Person,
context: { mode: ['context', 'browser'] },
override: [lead.action.CreateGlobalLead]
})
createAction(
builder,
{
action: view.actionImpl.ShowPopup,
actionProps: {
component: lead.component.CreateLead,
element: 'top'
},
label: lead.string.CreateLead,
icon: lead.icon.Lead,
keyBinding: [],
input: 'none',
category: lead.category.Lead,
target: core.class.Doc,
context: {
mode: ['workbench', 'browser'],
application: lead.app.Lead
}
},
lead.action.CreateGlobalLead
)
}
export { leadOperation } from './migration'

View File

@ -21,7 +21,7 @@ import type { IntlString } from '@anticrm/platform'
import { mergeIds } from '@anticrm/platform'
import { KanbanTemplate } from '@anticrm/task'
import type { AnyComponent } from '@anticrm/ui'
import { Viewlet } from '@anticrm/view'
import { Action, ActionCategory, Viewlet } from '@anticrm/view'
export default mergeIds(leadId, lead, {
string: {
@ -53,5 +53,11 @@ export default mergeIds(leadId, lead, {
viewlet: {
TableCustomer: '' as Ref<Viewlet>,
TableLead: '' as Ref<Viewlet>
},
category: {
Lead: '' as Ref<ActionCategory>
},
action: {
CreateGlobalLead: '' as Ref<Action>
}
})

View File

@ -1,7 +1,7 @@
{
"string": {
"CreateFunnel": "Create funnel",
"CreateLead": "Create lead",
"CreateFunnel": "New Funnel",
"CreateLead": "New Lead",
"Funnel": "Funnel",
"FunnelName": "Funnel name",
"Funnels": "Funnels",

View File

@ -20,17 +20,17 @@
import { OK, Status } from '@anticrm/platform'
import { Card, getClient, SpaceSelector, UserBox } from '@anticrm/presentation'
import task, { calcRank } from '@anticrm/task'
import { EditBox, Status as StatusControl } from '@anticrm/ui'
import { createFocusManager, EditBox, FocusHandler, Label, Status as StatusControl } from '@anticrm/ui'
import { createEventDispatcher } from 'svelte'
import lead from '../plugin'
export let space: Ref<Space>
export let customer: Ref<Contact> | null = null
export let preserveCustomer = false
let _space = space
const status: Status = OK
let customer: Ref<Contact> | null = null
let title: string = ''
const dispatch = createEventDispatcher()
@ -38,9 +38,15 @@
const leadId = generateId() as Ref<Lead>
export function canClose (): boolean {
return title !== ''
return (preserveCustomer || customer === undefined) && title === ''
}
$: client.findAll(lead.class.Funnel, {}).then((r) => {
if (r.find((it) => it._id === _space) === undefined) {
_space = r.shift()?._id as Ref<Space>
}
})
async function createLead () {
const state = await client.findOne(task.class.State, { space: _space })
if (state === undefined) {
@ -86,8 +92,12 @@
await client.addCollection(lead.class.Lead, _space, customer!, lead.mixin.Customer, 'leads', value, leadId)
dispatch('close')
}
const manager = createFocusManager()
</script>
<FocusHandler {manager} />
<Card
label={lead.string.CreateLead}
okAction={createLead}
@ -107,8 +117,27 @@
}}
/>
</svelte:fragment>
<svelte:fragment slot="title">
<div class="flex-row-center gap-2">
{#if preserveCustomer}
<UserBox
readonly
_class={contact.class.Contact}
options={{ sort: { modifiedOn: -1 } }}
excluded={[]}
label={lead.string.Leads}
placeholder={lead.string.Leads}
bind:value={customer}
kind={'no-border'}
size={'small'}
/>
{/if}
<Label label={lead.string.CreateLead} />
</div>
</svelte:fragment>
<StatusControl slot="error" {status} />
<EditBox
focusIndex={1}
label={lead.string.LeadName}
bind:value={title}
icon={lead.icon.Lead}
@ -117,14 +146,17 @@
focus
/>
<svelte:fragment slot="pool">
<UserBox
_class={contact.class.Contact}
label={lead.string.Customer}
placeholder={lead.string.SelectCustomer}
bind:value={customer}
kind={'no-border'}
size={'small'}
create={{ component: lead.component.CreateCustomer, label: lead.string.CreateCustomer }}
/>
{#if !preserveCustomer}
<UserBox
focusIndex={2}
_class={contact.class.Contact}
label={lead.string.Customer}
placeholder={lead.string.SelectCustomer}
bind:value={customer}
kind={'no-border'}
size={'small'}
create={{ component: lead.component.CreateCustomer, label: lead.string.CreateCustomer }}
/>
{/if}
</svelte:fragment>
</Card>