mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-13 21:27:46 +02:00
@@ -3,17 +3,21 @@
|
||||
BitrixClient,
|
||||
BitrixEntityMapping,
|
||||
BitrixFieldMapping,
|
||||
Fields,
|
||||
performSynchronization,
|
||||
StatusValue,
|
||||
toClassRef
|
||||
} from '@hcengineering/bitrix'
|
||||
import contact from '@hcengineering/contact'
|
||||
import core, { Class, Doc, Ref, Space, WithLookup } from '@hcengineering/core'
|
||||
import core, { Class, Doc, generateId, Ref, Space, WithLookup } from '@hcengineering/core'
|
||||
import login from '@hcengineering/login'
|
||||
import { getEmbeddedLabel, getMetadata } from '@hcengineering/platform'
|
||||
import { getClient, SpaceSelect } from '@hcengineering/presentation'
|
||||
import { Button, Expandable, Icon, Label } from '@hcengineering/ui'
|
||||
import { Button, Expandable, Icon, IconAdd, IconClose, Label } from '@hcengineering/ui'
|
||||
import DropdownLabels from '@hcengineering/ui/src/components/DropdownLabels.svelte'
|
||||
import EditBox from '@hcengineering/ui/src/components/EditBox.svelte'
|
||||
import { NumberEditor } from '@hcengineering/view-resources'
|
||||
import bitrix from '../plugin'
|
||||
import FieldMappingPresenter from './FieldMappingPresenter.svelte'
|
||||
|
||||
export let mapping: WithLookup<BitrixEntityMapping>
|
||||
@@ -40,6 +44,11 @@
|
||||
loading = true
|
||||
const uploadUrl = (window.location.origin + getMetadata(login.metadata.UploadUrl)) as string
|
||||
const token = (getMetadata(login.metadata.LoginToken) as string) ?? ''
|
||||
|
||||
const mappedFilter: Record<string, any> = {}
|
||||
for (const f of filterFields) {
|
||||
mappedFilter[f.field] = f.value
|
||||
}
|
||||
try {
|
||||
await performSynchronization({
|
||||
bitrixClient,
|
||||
@@ -57,7 +66,8 @@
|
||||
monitor: (total: number) => {
|
||||
docsProcessed++
|
||||
state = `processed: ${docsProcessed}/${total ?? 1}`
|
||||
}
|
||||
},
|
||||
extraFilter: filterFields.length === 0 ? undefined : mappedFilter
|
||||
})
|
||||
} catch (err: any) {
|
||||
state = err.message
|
||||
@@ -66,6 +76,49 @@
|
||||
loading = false
|
||||
}
|
||||
}
|
||||
const fieldsKey = bitrix.class.EntityMapping + '.fields.' + mapping._id
|
||||
let filterFields: { _id: string; field: string; value: string }[] = []
|
||||
|
||||
const content = JSON.parse(localStorage.getItem(fieldsKey) ?? '[]')
|
||||
|
||||
filterFields = content.filterFields ?? []
|
||||
limit = content.limit ?? 1
|
||||
direction = content.direction ?? 'ASC'
|
||||
|
||||
$: localStorage.setItem(fieldsKey, JSON.stringify({ limit, filterFields, direction }))
|
||||
|
||||
function addFilter (): void {
|
||||
filterFields = [...filterFields, { _id: generateId(), field: '', value: ' ' }]
|
||||
}
|
||||
|
||||
let fields: Fields = {}
|
||||
bitrixClient.call(mapping.type + '.fields', {}).then((res) => {
|
||||
fields = res.result
|
||||
})
|
||||
|
||||
let statusList: StatusValue[] = []
|
||||
|
||||
bitrixClient.call('crm.status.list', {}).then((res) => {
|
||||
statusList = res.result
|
||||
})
|
||||
|
||||
$: items = Object.entries(fields).map((it) => ({
|
||||
id: it[0],
|
||||
label: `${it[1].formLabel ?? it[1].title}${it[0].startsWith('UF_') ? ' *' : ''} - ${it[0]}`
|
||||
}))
|
||||
|
||||
function updateFields (fields: Fields, statusList: StatusValue[]): void {
|
||||
// Update fields with status valies if missing.
|
||||
for (const f of Object.values(fields)) {
|
||||
if (f.type === 'crm_status') {
|
||||
f.items = statusList
|
||||
.filter((it) => it.ENTITY_ID === f.statusType)
|
||||
.map((it) => ({ ID: `${it.STATUS_ID}`, VALUE: it.NAME }))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$: updateFields(fields, statusList)
|
||||
</script>
|
||||
|
||||
<Expandable label={getEmbeddedLabel(mapping.type)}>
|
||||
@@ -102,6 +155,8 @@
|
||||
/>
|
||||
</div>
|
||||
<div class="buttons-divider" />
|
||||
<Button icon={IconAdd} on:click={addFilter} />
|
||||
<div class="buttons-divider" />
|
||||
<div class="flex-row-center">
|
||||
<div class="p-1">
|
||||
{state}
|
||||
@@ -131,3 +186,29 @@
|
||||
{/each}
|
||||
</div>
|
||||
</Expandable>
|
||||
|
||||
<div class="flex-row-center">
|
||||
{#each filterFields as field, pos}
|
||||
{@const fValue = fields[field.field]}
|
||||
<div class="item flex-row-center">
|
||||
<DropdownLabels minW0={false} label={bitrix.string.FieldMapping} {items} bind:selected={field.field} />
|
||||
{#if fValue?.type === 'crm_status' || fValue?.type === 'enumeration'}
|
||||
<DropdownLabels
|
||||
minW0={false}
|
||||
label={bitrix.string.FieldMapping}
|
||||
items={fValue.items?.map((it) => ({ id: it.ID, label: it.VALUE })) ?? []}
|
||||
bind:selected={field.value}
|
||||
/>
|
||||
{:else}
|
||||
<EditBox bind:value={field.value} />
|
||||
{/if}
|
||||
<Button
|
||||
icon={IconClose}
|
||||
on:click={() => {
|
||||
filterFields.splice(pos, 1)
|
||||
filterFields = filterFields
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user