Select email sender (#2679)

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov 2023-02-22 14:35:27 +06:00 committed by GitHub
parent a5d261bed0
commit 64bb9db646
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 293 additions and 45 deletions

View File

@ -144,7 +144,8 @@ export function createModel (builder: Builder): void {
description: gmail.string.IntegrationDescription,
icon: gmail.component.IconGmail,
createComponent: gmail.component.Connect,
onDisconnect: gmail.handler.DisconnectHandler
onDisconnect: gmail.handler.DisconnectHandler,
configureComponent: gmail.component.Configure
},
gmail.integrationType.Gmail
)

View File

@ -14,7 +14,7 @@
//
import activity from '@hcengineering/activity'
import { Domain, DOMAIN_MODEL, Ref } from '@hcengineering/core'
import { Account, Domain, DOMAIN_MODEL, Ref } from '@hcengineering/core'
import { Builder, Mixin, Model } from '@hcengineering/model'
import core, { TClass, TConfiguration, TDoc } from '@hcengineering/model-core'
import view, { createAction } from '@hcengineering/model-view'
@ -43,6 +43,7 @@ export class TIntegration extends TDoc implements Integration {
type!: Ref<IntegrationType>
disabled!: boolean
value!: string
shared!: Ref<Account>[]
}
@Model(setting.class.SettingsCategory, core.class.Doc, DOMAIN_MODEL)
export class TSettingsCategory extends TDoc implements SettingsCategory {
@ -70,6 +71,7 @@ export class TIntegrationType extends TDoc implements IntegrationType {
createComponent!: AnyComponent
reconnectComponent?: AnyComponent
onDisconnect!: Handler
configureComponent?: AnyComponent
}
@Mixin(setting.mixin.Editable, core.class.Class)

View File

@ -1,13 +1,30 @@
<!--
// Copyright © 2023 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">
import contact, { Employee, EmployeeAccount } from '@hcengineering/contact'
import core, { Account, Ref } from '@hcengineering/core'
import { IntlString } from '@hcengineering/platform'
import { createQuery, getClient, UserBoxList } from '@hcengineering/presentation'
import { ButtonKind } from '@hcengineering/ui'
export let label: IntlString
export let value: Ref<Account>[]
export let onChange: (refs: Ref<Account>[]) => void
export let readonly = false
export let kind: ButtonKind = 'link'
export let excludeItems: Ref<Account>[] | undefined = undefined
let timer: any
const client = getClient()
@ -28,15 +45,38 @@
accounts = res
})
const excludedQuery = createQuery()
let excluded: Account[] = []
$: if (excludeItems !== undefined && excludeItems.length > 0) {
excludedQuery.query(core.class.Account, { _id: { $in: excludeItems } }, (res) => {
excluded = res
})
} else {
excludedQuery.unsubscribe()
excluded = []
}
$: employess = accounts.map((it) => (it as EmployeeAccount).employee)
$: docQuery =
excluded.length > 0
? {
active: true,
_id: { $nin: excluded.map((p) => (p as EmployeeAccount).employee) }
}
: {
active: true
}
</script>
<UserBoxList
items={employess}
{label}
{readonly}
{docQuery}
on:update={onUpdate}
kind={'link'}
size={'medium'}
justify={'left'}
width={'100%'}

View File

@ -0,0 +1,65 @@
<!--
// Copyright © 2023 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">
import { Employee, EmployeeAccount } from '@hcengineering/contact'
import { Account, DocumentQuery, Ref } from '@hcengineering/core'
import { IntlString } from '@hcengineering/platform'
import { createQuery, UserBox } from '@hcengineering/presentation'
import { ButtonKind, ButtonSize } from '@hcengineering/ui'
import { createEventDispatcher } from 'svelte'
import contact from '../plugin'
export let label: IntlString = contact.string.Employee
export let value: Ref<Account> | null | undefined
export let docQuery: DocumentQuery<Account> = {}
export let kind: ButtonKind = 'no-border'
export let size: ButtonSize = 'small'
const query = createQuery()
let accounts: EmployeeAccount[] = []
query.query<EmployeeAccount>(contact.class.EmployeeAccount, docQuery as DocumentQuery<EmployeeAccount>, (res) => {
accounts = res
map = new Map(res.map((p) => [p.employee, p._id]))
})
let map: Map<Ref<Employee>, Ref<Account>> = new Map()
$: employees = accounts.map((p) => p.employee)
$: selectedEmp = value && accounts.find((p) => p._id === value)?.employee
const dispatch = createEventDispatcher()
function change (e: CustomEvent<Ref<Employee> | null>) {
if (e.detail === null) {
dispatch('change', null)
} else {
const account = map.get(e.detail)
dispatch('change', account)
}
}
</script>
<UserBox
_class={contact.class.Employee}
docQuery={{ _id: { $in: employees } }}
showNavigate={false}
{kind}
{size}
{label}
value={selectedEmp}
on:change={change}
/>

View File

@ -55,6 +55,7 @@ import ContactRefPresenter from './components/ContactRefPresenter.svelte'
import PersonRefPresenter from './components/PersonRefPresenter.svelte'
import EmployeeRefPresenter from './components/EmployeeRefPresenter.svelte'
import ChannelFilter from './components/ChannelFilter.svelte'
import AccountBox from './components/AccountBox.svelte'
import contact from './plugin'
import {
employeeSort,
@ -80,7 +81,9 @@ export {
EmployeeAccountRefPresenter,
MembersPresenter,
EditPerson,
EmployeeRefPresenter
EmployeeRefPresenter,
AccountArrayEditor,
AccountBox
}
const toObjectSearchResult = (e: WithLookup<Contact>): ObjectSearchResult => ({

View File

@ -30,6 +30,8 @@
"Email": "Email",
"Status": "Status",
"EmailPlaceholder": "john.appleseed@apple.com",
"WrtieEmail": "Wrtie Email"
"WrtieEmail": "Wrtie Email",
"Shared": "Shared",
"AvailableTo": "Available to"
}
}

View File

@ -30,6 +30,8 @@
"Email": "Email",
"Status": "Статус",
"EmailPlaceholder": "john.appleseed@apple.com",
"WrtieEmail": "Написать Email"
"WrtieEmail": "Написать Email",
"Shared": "Публичный",
"AvailableTo": "Доступен для"
}
}

View File

@ -41,6 +41,7 @@
"@hcengineering/contact": "^0.6.11",
"@hcengineering/setting": "^0.6.2",
"@hcengineering/chunter": "^0.6.2",
"@hcengineering/contact-resources": "^0.6.0",
"@hcengineering/chunter-resources": "^0.6.0",
"@hcengineering/notification-resources": "^0.6.0",
"@hcengineering/attachment": "^0.6.1",

View File

@ -0,0 +1,76 @@
<!--
// Copyright © 2023 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">
import { AccountArrayEditor } from '@hcengineering/contact-resources'
import { Account, getCurrentAccount, Ref } from '@hcengineering/core'
import presentation, { Card, getClient } from '@hcengineering/presentation'
import { Integration } from '@hcengineering/setting'
import { Grid, Label, Toggle } from '@hcengineering/ui'
import { createEventDispatcher } from 'svelte'
import gmail from '../plugin'
export let integration: Integration
let shared = (integration.shared?.length ?? 0) > 0
const client = getClient()
async function change (shared: Ref<Account>[]) {
await client.update(integration, {
shared
})
}
async function disable () {
if (shared === false) {
await change([])
}
}
const dispatch = createEventDispatcher()
const me = getCurrentAccount()._id
</script>
<Card
label={gmail.string.Shared}
okAction={() => {
dispatch('close')
}}
canSave={true}
fullSize
okLabel={presentation.string.Ok}
on:close={() => dispatch('close')}
>
<div style="width: 25rem;">
<Grid rowGap={1}>
<div>
<Label label={gmail.string.Shared} />
</div>
<Toggle bind:on={shared} on:change={disable} />
{#if shared}
<div>
<Label label={gmail.string.AvailableTo} />
</div>
<AccountArrayEditor
kind={'secondary'}
label={gmail.string.AvailableTo}
excludeItems={[me]}
value={integration.shared ?? []}
onChange={(res) => change(res)}
/>
{/if}
</Grid>
</div>
</Card>

View File

@ -0,0 +1,37 @@
<!--
// Copyright © 2023 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">
import { AccountBox } from '@hcengineering/contact-resources'
import { Account, Ref } from '@hcengineering/core'
import { Integration } from '@hcengineering/setting'
import { ButtonKind, ButtonSize } from '@hcengineering/ui'
export let integrations: Integration[]
export let selected: Integration | undefined
export let kind: ButtonKind = 'link'
export let size: ButtonSize = 'small'
$: ids = Array.from(new Set(integrations.map((p) => p.space as string as Ref<Account>)))
function change (e: CustomEvent<Ref<Account> | null>) {
if (e.detail === null) {
selected = undefined
} else {
selected = integrations.find((p) => (p.space as string as Ref<Account>) === e.detail)
}
}
</script>
<AccountBox value={selected?.modifiedBy} {kind} {size} docQuery={{ _id: { $in: ids } }} on:change={change} />

View File

@ -15,7 +15,7 @@
-->
<script lang="ts">
import contact, { Channel, formatName } from '@hcengineering/contact'
import { Class, Doc, getCurrentAccount, Ref, Space } from '@hcengineering/core'
import { Class, Doc, getCurrentAccount, Ref } from '@hcengineering/core'
import { SharedMessage } from '@hcengineering/gmail'
import { NotificationClientImpl } from '@hcengineering/notification-resources'
import { getResource } from '@hcengineering/platform'
@ -28,6 +28,7 @@
import Chats from './Chats.svelte'
import Connect from './Connect.svelte'
import FullMessage from './FullMessage.svelte'
import IntegrationSelector from './IntegrationSelector.svelte'
import NewMessage from './NewMessage.svelte'
export let _id: Ref<Doc>
@ -38,7 +39,8 @@
let currentMessage: SharedMessage | undefined = undefined
let channel: Channel | undefined = undefined
const notificationClient = NotificationClientImpl.getClient()
let integration: Integration | undefined
let integrations: Integration[] = []
let selectedIntegration: Integration | undefined = undefined
const channelQuery = createQuery()
const dispatch = createEventDispatcher()
@ -76,7 +78,7 @@
}
const settingsQuery = createQuery()
const accountId = getCurrentAccount()._id
const me = getCurrentAccount()._id
let templateProvider: TemplateDataProvider | undefined
@ -88,15 +90,14 @@
templateProvider?.destroy()
})
$: templateProvider && integration && templateProvider.set(setting.templateFieldCategory.Integration, integration)
$: templateProvider &&
selectedIntegration &&
templateProvider.set(setting.templateFieldCategory.Integration, selectedIntegration)
settingsQuery.query(
setting.class.Integration,
{ type: gmail.integrationType.Gmail, space: accountId as string as Ref<Space> },
(res) => {
integration = res[0]
}
)
settingsQuery.query(setting.class.Integration, { type: gmail.integrationType.Gmail, disabled: false }, (res) => {
integrations = res.filter((p) => (p.space as string) === me || p.shared?.includes(me))
selectedIntegration = integrations.find((p) => (p.space as string) === me) ?? integrations[0]
})
</script>
{#if channel && object}
@ -123,7 +124,7 @@
</svelte:fragment>
<svelte:fragment slot="utils">
{#if !integration}
{#if integrations.length === 0}
<Button
label={gmail.string.Connect}
kind={'primary'}
@ -131,15 +132,18 @@
showPopup(Connect, {}, eventToHTMLElement(e))
}}
/>
{:else}
<Label label={gmail.string.From} />
<IntegrationSelector bind:selected={selectedIntegration} {integrations} />
{/if}
</svelte:fragment>
{#if newMessage}
<NewMessage {object} {channel} {currentMessage} on:close={back} />
{#if newMessage && selectedIntegration}
<NewMessage {object} {channel} {currentMessage} {selectedIntegration} on:close={back} />
{:else if currentMessage}
<FullMessage {currentMessage} bind:newMessage on:close={back} />
{:else}
<Chats {object} {channel} bind:newMessage enabled={integration !== undefined} on:select={selectHandler} />
<Chats {object} {channel} bind:newMessage enabled={integrations.length > 0} on:select={selectHandler} />
{/if}
</Panel>
{/if}

View File

@ -16,11 +16,12 @@
import attachmentP, { Attachment } from '@hcengineering/attachment'
import { AttachmentPresenter } from '@hcengineering/attachment-resources'
import contact, { Channel, Contact, formatName } from '@hcengineering/contact'
import { Data, generateId } from '@hcengineering/core'
import { Account, Data, generateId, Ref } from '@hcengineering/core'
import { NewMessage, SharedMessage } from '@hcengineering/gmail'
import { NotificationClientImpl } from '@hcengineering/notification-resources'
import { getResource, setPlatformStatus, unknownError } from '@hcengineering/platform'
import { createQuery, getClient } from '@hcengineering/presentation'
import { Integration } from '@hcengineering/setting'
import templates, { TemplateDataProvider } from '@hcengineering/templates'
import { StyledTextEditor } from '@hcengineering/text-editor'
import { Button, EditBox, IconArrowLeft, IconAttachment, Label, Scroller } from '@hcengineering/ui'
@ -31,6 +32,7 @@
export let object: Contact
export let channel: Channel
export let currentMessage: SharedMessage | undefined
export let selectedIntegration: Integration
const client = getClient()
const notificationClient = NotificationClientImpl.getClient()
let objectId = generateId()
@ -65,6 +67,7 @@
{
...obj,
attachments: attachments.length,
from: selectedIntegration.space as string as Ref<Account>,
copy: copy
.split(',')
.map((m) => m.trim())

View File

@ -16,11 +16,13 @@
import attachmentP, { Attachment } from '@hcengineering/attachment'
import { AttachmentPresenter } from '@hcengineering/attachment-resources'
import contact, { Channel, Contact, formatName } from '@hcengineering/contact'
import { generateId, getCurrentAccount, Ref, Space, toIdMap } from '@hcengineering/core'
import { Account, generateId, getCurrentAccount, Ref, toIdMap } from '@hcengineering/core'
import { NotificationClientImpl } from '@hcengineering/notification-resources'
import { getResource, setPlatformStatus, unknownError } from '@hcengineering/platform'
import setting, { Integration } from '@hcengineering/setting'
import { createQuery, getClient } from '@hcengineering/presentation'
import setting, { Integration } from '@hcengineering/setting'
import templates, { TemplateDataProvider } from '@hcengineering/templates'
import { StyledTextEditor } from '@hcengineering/text-editor'
import {
Button,
EditBox,
@ -34,9 +36,8 @@
} from '@hcengineering/ui'
import { createEventDispatcher, onDestroy } from 'svelte'
import plugin from '../plugin'
import templates, { TemplateDataProvider } from '@hcengineering/templates'
import Connect from './Connect.svelte'
import { StyledTextEditor } from '@hcengineering/text-editor'
import IntegrationSelector from './IntegrationSelector.svelte'
export let value: Contact[] | Contact
const contacts = Array.isArray(value) ? value : [value]
@ -69,7 +70,7 @@
async function sendMsg () {
const templateProvider = (await getResource(templates.function.GetTemplateDataProvider))()
if (templateProvider === undefined) return
if (templateProvider === undefined || selectedIntegration === undefined) return
for (const channel of channels) {
const target = contacts.find((p) => p._id === channel.attachedTo)
if (target === undefined) continue
@ -80,6 +81,7 @@
content: message,
to: channel.value,
status: 'new',
from: selectedIntegration.space as string as Ref<Account>,
copy: copy
.split(',')
.map((m) => m.trim())
@ -185,10 +187,11 @@
}
const settingsQuery = createQuery()
const accountId = getCurrentAccount()._id
const me = getCurrentAccount()._id
let templateProvider: TemplateDataProvider | undefined
let integration: Integration | undefined
let integrations: Integration[] = []
let selectedIntegration: Integration | undefined = undefined
getResource(templates.function.GetTemplateDataProvider).then((p) => {
templateProvider = p()
@ -198,15 +201,14 @@
templateProvider?.destroy()
})
$: templateProvider && integration && templateProvider.set(setting.templateFieldCategory.Integration, integration)
$: templateProvider &&
selectedIntegration &&
templateProvider.set(setting.templateFieldCategory.Integration, selectedIntegration)
settingsQuery.query(
setting.class.Integration,
{ type: plugin.integrationType.Gmail, space: accountId as string as Ref<Space> },
(res) => {
integration = res[0]
}
)
settingsQuery.query(setting.class.Integration, { type: plugin.integrationType.Gmail, disabled: false }, (res) => {
integrations = res.filter((p) => (p.space as string) === me || p.shared?.includes(me))
selectedIntegration = integrations.find((p) => (p.space as string) === me) ?? integrations[0]
})
</script>
<Panel
@ -231,7 +233,7 @@
</svelte:fragment>
<svelte:fragment slot="utils">
{#if !integration}
{#if integrations.length === 0}
<Button
label={plugin.string.Connect}
kind={'primary'}
@ -239,6 +241,9 @@
showPopup(Connect, {}, eventToHTMLElement(e))
}}
/>
{:else}
<Label label={plugin.string.From} />
<IntegrationSelector bind:selected={selectedIntegration} {integrations} />
{/if}
</svelte:fragment>
@ -276,7 +281,7 @@
inputFile.click()
}}
/>
{#if integration}
{#if selectedIntegration}
<Button
label={plugin.string.Send}
size={'small'}

View File

@ -22,13 +22,15 @@ import IconGmail from './components/icons/GmailColor.svelte'
import TxSharedCreate from './components/activity/TxSharedCreate.svelte'
import { concatLink } from '@hcengineering/core'
import NewMessages from './components/NewMessages.svelte'
import Configure from './components/Configure.svelte'
export default async (): Promise<Resources> => ({
component: {
Main,
Connect,
IconGmail,
NewMessages
NewMessages,
Configure
},
activity: {
TxSharedCreate

View File

@ -39,6 +39,8 @@ export default mergeIds(gmailId, gmail, {
Cancel: '' as IntlString,
SubjectPlaceholder: '' as IntlString,
CopyPlaceholder: '' as IntlString,
WrtieEmail: '' as IntlString
WrtieEmail: '' as IntlString,
Shared: '' as IntlString,
AvailableTo: '' as IntlString
}
})

View File

@ -15,7 +15,7 @@
import { plugin } from '@hcengineering/platform'
import type { Plugin } from '@hcengineering/platform'
import type { Doc, Ref, Class, Space, AttachedDoc, Timestamp } from '@hcengineering/core'
import type { Doc, Ref, Class, Space, AttachedDoc, Timestamp, Account } from '@hcengineering/core'
import type { AnyComponent } from '@hcengineering/ui'
import type { IntegrationType, Handler } from '@hcengineering/setting'
import { Channel } from '@hcengineering/contact'
@ -50,6 +50,7 @@ export interface BaseMessage extends Doc {
*/
export interface NewMessage extends BaseMessage {
status: 'new' | 'sent'
from?: Ref<Account>
}
/**
@ -85,7 +86,8 @@ export default plugin(gmailId, {
Main: '' as AnyComponent,
Connect: '' as AnyComponent,
IconGmail: '' as AnyComponent,
NewMessages: '' as AnyComponent
NewMessages: '' as AnyComponent,
Configure: '' as AnyComponent
},
integrationType: {
Gmail: '' as Ref<IntegrationType>

View File

@ -69,7 +69,7 @@
"HideAttribute": "Спрятать",
"Visibility": "Видимость",
"Hidden": "Спрятанный",
"Configure": "Настроить...",
"Configure": "Настроить",
"InviteSettings": "Настройки приглашений в пространство"
}
}

View File

@ -13,7 +13,7 @@
// limitations under the License.
//
import type { Class, Configuration, Doc, Mixin, Ref, Space } from '@hcengineering/core'
import type { Account, Class, Configuration, Doc, Mixin, Ref, Space } from '@hcengineering/core'
import type { Plugin } from '@hcengineering/platform'
import { Asset, IntlString, plugin, Resource } from '@hcengineering/platform'
import { AnyComponent } from '@hcengineering/ui'
@ -46,6 +46,7 @@ export interface Integration extends Doc {
type: Ref<IntegrationType>
disabled: boolean
value: string
shared?: Ref<Account>[]
}
/**