2021-08-07 14:49:14 +00:00
|
|
|
//
|
|
|
|
// Copyright © 2020, 2021 Anticrm Platform Contributors.
|
|
|
|
// Copyright © 2021 Hardcore Engineering Inc.
|
2021-12-07 09:05:52 +00:00
|
|
|
//
|
2021-08-07 14:49:14 +00:00
|
|
|
// 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
|
2021-12-07 09:05:52 +00:00
|
|
|
//
|
2021-08-07 14:49:14 +00:00
|
|
|
// 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.
|
2021-12-07 09:05:52 +00:00
|
|
|
//
|
2021-08-07 14:49:14 +00:00
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
//
|
|
|
|
|
2022-08-22 01:03:32 +00:00
|
|
|
import { Channel, Contact, Employee, formatName } from '@anticrm/contact'
|
2022-09-09 03:44:33 +00:00
|
|
|
import { Class, Client, DocumentQuery, Ref, RelatedDocument, WithLookup } from '@anticrm/core'
|
2022-08-22 01:03:32 +00:00
|
|
|
import { leaveWorkspace } from '@anticrm/login-resources'
|
2022-01-21 09:05:55 +00:00
|
|
|
import { Resources } from '@anticrm/platform'
|
2022-06-29 05:51:29 +00:00
|
|
|
import { Avatar, getClient, MessageBox, ObjectSearchResult, UserInfo } from '@anticrm/presentation'
|
|
|
|
import { showPopup } from '@anticrm/ui'
|
2022-01-31 09:06:30 +00:00
|
|
|
import Channels from './components/Channels.svelte'
|
2022-08-22 01:03:32 +00:00
|
|
|
import ChannelsDropdown from './components/ChannelsDropdown.svelte'
|
2022-02-22 09:09:13 +00:00
|
|
|
import ChannelsEditor from './components/ChannelsEditor.svelte'
|
2021-08-31 10:42:40 +00:00
|
|
|
import ChannelsPresenter from './components/ChannelsPresenter.svelte'
|
2022-02-07 09:03:14 +00:00
|
|
|
import ChannelsView from './components/ChannelsView.svelte'
|
2022-01-21 09:05:55 +00:00
|
|
|
import ContactPresenter from './components/ContactPresenter.svelte'
|
|
|
|
import Contacts from './components/Contacts.svelte'
|
2022-08-22 01:03:32 +00:00
|
|
|
import CreateEmployee from './components/CreateEmployee.svelte'
|
2021-12-06 10:07:08 +00:00
|
|
|
import CreateOrganization from './components/CreateOrganization.svelte'
|
|
|
|
import CreateOrganizations from './components/CreateOrganizations.svelte'
|
2022-01-21 09:05:55 +00:00
|
|
|
import CreatePerson from './components/CreatePerson.svelte'
|
|
|
|
import CreatePersons from './components/CreatePersons.svelte'
|
2022-08-22 01:03:32 +00:00
|
|
|
import EditMember from './components/EditMember.svelte'
|
2022-01-21 09:05:55 +00:00
|
|
|
import EditOrganization from './components/EditOrganization.svelte'
|
|
|
|
import EditPerson from './components/EditPerson.svelte'
|
2022-08-22 01:03:32 +00:00
|
|
|
import EmployeeAccountPresenter from './components/EmployeeAccountPresenter.svelte'
|
|
|
|
import EmployeeArrayEditor from './components/EmployeeArrayEditor.svelte'
|
2022-09-14 04:53:48 +00:00
|
|
|
import AccountArrayEditor from './components/AccountArrayEditor.svelte'
|
2022-08-22 01:03:32 +00:00
|
|
|
import EmployeeBrowser from './components/EmployeeBrowser.svelte'
|
|
|
|
import EmployeeEditor from './components/EmployeeEditor.svelte'
|
|
|
|
import EmployeePresenter from './components/EmployeePresenter.svelte'
|
|
|
|
import MemberPresenter from './components/MemberPresenter.svelte'
|
|
|
|
import Members from './components/Members.svelte'
|
|
|
|
import OrganizationEditor from './components/OrganizationEditor.svelte'
|
2022-01-21 09:05:55 +00:00
|
|
|
import OrganizationPresenter from './components/OrganizationPresenter.svelte'
|
2022-08-22 01:03:32 +00:00
|
|
|
import PersonEditor from './components/PersonEditor.svelte'
|
2022-01-21 09:05:55 +00:00
|
|
|
import PersonPresenter from './components/PersonPresenter.svelte'
|
2021-12-06 10:07:08 +00:00
|
|
|
import SocialEditor from './components/SocialEditor.svelte'
|
2022-01-21 09:05:55 +00:00
|
|
|
import contact from './plugin'
|
2021-12-07 09:05:52 +00:00
|
|
|
|
2022-05-12 07:05:26 +00:00
|
|
|
export {
|
|
|
|
Channels,
|
|
|
|
ChannelsEditor,
|
|
|
|
ContactPresenter,
|
|
|
|
ChannelsView,
|
|
|
|
ChannelsDropdown,
|
2022-06-07 04:10:34 +00:00
|
|
|
EmployeePresenter,
|
2022-07-01 15:22:58 +00:00
|
|
|
PersonPresenter,
|
2022-06-10 16:10:15 +00:00
|
|
|
EmployeeBrowser,
|
2022-06-29 05:51:29 +00:00
|
|
|
MemberPresenter,
|
|
|
|
EmployeeEditor
|
2022-05-12 07:05:26 +00:00
|
|
|
}
|
2021-08-07 14:49:14 +00:00
|
|
|
|
2022-09-09 03:44:33 +00:00
|
|
|
const toObjectSearchResult = (e: WithLookup<Contact>): ObjectSearchResult => ({
|
|
|
|
doc: e,
|
|
|
|
title: formatName(e.name),
|
|
|
|
icon: Avatar,
|
|
|
|
iconProps: { size: 'x-small', avatar: e.avatar },
|
|
|
|
component: UserInfo,
|
|
|
|
componentProps: { size: 'x-small' }
|
|
|
|
})
|
|
|
|
|
2022-04-29 05:27:17 +00:00
|
|
|
async function queryContact (
|
|
|
|
_class: Ref<Class<Contact>>,
|
|
|
|
client: Client,
|
2022-09-09 03:44:33 +00:00
|
|
|
search: string,
|
|
|
|
filter?: { in?: RelatedDocument[], nin?: RelatedDocument[] }
|
2022-04-29 05:27:17 +00:00
|
|
|
): Promise<ObjectSearchResult[]> {
|
2022-09-09 03:44:33 +00:00
|
|
|
const q: DocumentQuery<Contact> = { name: { $like: `%${search}%` } }
|
|
|
|
if (filter?.in !== undefined || filter?.nin !== undefined) {
|
|
|
|
q._id = {}
|
|
|
|
if (filter.in !== undefined) {
|
|
|
|
q._id.$in = filter.in?.map((it) => it._id as Ref<Contact>)
|
|
|
|
}
|
|
|
|
if (filter.nin !== undefined) {
|
|
|
|
q._id.$nin = filter.nin?.map((it) => it._id as Ref<Contact>)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (await client.findAll(_class, q, { limit: 200 })).map(toObjectSearchResult)
|
2022-01-21 09:05:55 +00:00
|
|
|
}
|
|
|
|
|
2022-06-29 05:51:29 +00:00
|
|
|
async function kickEmployee (doc: Employee): Promise<void> {
|
|
|
|
const client = getClient()
|
|
|
|
const email = await client.findOne(contact.class.EmployeeAccount, { employee: doc._id })
|
|
|
|
if (email === undefined) return
|
|
|
|
showPopup(
|
|
|
|
MessageBox,
|
|
|
|
{
|
|
|
|
label: contact.string.KickEmployee,
|
|
|
|
message: contact.string.KickEmployeeDescr
|
|
|
|
},
|
|
|
|
undefined,
|
|
|
|
(res?: boolean) => {
|
|
|
|
if (res === true) {
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
|
|
leaveWorkspace(email.email)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
2022-08-22 01:03:32 +00:00
|
|
|
async function openChannelURL (doc: Channel): Promise<void> {
|
|
|
|
if (doc.value.startsWith('http://') || doc.value.startsWith('https://')) {
|
|
|
|
window.open(doc.value)
|
|
|
|
}
|
|
|
|
}
|
2022-06-29 05:51:29 +00:00
|
|
|
|
2021-12-07 09:05:52 +00:00
|
|
|
export default async (): Promise<Resources> => ({
|
2022-06-29 05:51:29 +00:00
|
|
|
actionImpl: {
|
2022-08-22 01:03:32 +00:00
|
|
|
KickEmployee: kickEmployee,
|
|
|
|
OpenChannel: openChannelURL
|
2022-06-29 05:51:29 +00:00
|
|
|
},
|
2021-08-07 14:49:14 +00:00
|
|
|
component: {
|
2022-05-06 17:48:43 +00:00
|
|
|
PersonEditor,
|
2022-03-17 09:39:57 +00:00
|
|
|
OrganizationEditor,
|
2021-12-07 09:05:52 +00:00
|
|
|
ContactPresenter,
|
2021-08-31 10:42:40 +00:00
|
|
|
PersonPresenter,
|
2021-12-06 10:07:08 +00:00
|
|
|
OrganizationPresenter,
|
|
|
|
ChannelsPresenter,
|
|
|
|
CreatePerson,
|
|
|
|
CreateOrganization,
|
|
|
|
EditPerson,
|
|
|
|
EditOrganization,
|
|
|
|
CreatePersons,
|
|
|
|
CreateOrganizations,
|
2022-01-11 09:05:53 +00:00
|
|
|
SocialEditor,
|
2022-03-10 09:04:08 +00:00
|
|
|
Contacts,
|
2022-05-12 07:05:26 +00:00
|
|
|
EmployeeAccountPresenter,
|
2022-06-07 04:10:34 +00:00
|
|
|
EmployeePresenter,
|
|
|
|
Members,
|
|
|
|
MemberPresenter,
|
2022-06-08 13:55:01 +00:00
|
|
|
EditMember,
|
2022-06-29 05:51:29 +00:00
|
|
|
EmployeeArrayEditor,
|
2022-06-30 10:26:31 +00:00
|
|
|
EmployeeEditor,
|
2022-09-14 04:53:48 +00:00
|
|
|
CreateEmployee,
|
|
|
|
AccountArrayEditor
|
2022-01-21 09:05:55 +00:00
|
|
|
},
|
|
|
|
completion: {
|
2022-09-09 03:44:33 +00:00
|
|
|
EmployeeQuery: async (
|
|
|
|
client: Client,
|
|
|
|
query: string,
|
|
|
|
filter?: { in?: RelatedDocument[], nin?: RelatedDocument[] }
|
|
|
|
) => await queryContact(contact.class.Employee, client, query, filter),
|
|
|
|
PersonQuery: async (client: Client, query: string, filter?: { in?: RelatedDocument[], nin?: RelatedDocument[] }) =>
|
|
|
|
await queryContact(contact.class.Person, client, query, filter),
|
|
|
|
OrganizationQuery: async (
|
|
|
|
client: Client,
|
|
|
|
query: string,
|
|
|
|
filter?: { in?: RelatedDocument[], nin?: RelatedDocument[] }
|
|
|
|
) => await queryContact(contact.class.Organization, client, query, filter)
|
2021-12-07 09:05:52 +00:00
|
|
|
}
|
2021-08-07 14:49:14 +00:00
|
|
|
})
|