2021-08-31 10:42:40 +00:00
|
|
|
<!--
|
|
|
|
// Copyright © 2020, 2021 Anticrm Platform Contributors.
|
|
|
|
// Copyright © 2021 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">
|
2021-09-01 15:11:01 +00:00
|
|
|
import type { Ref } from '@anticrm/core'
|
|
|
|
import type { IntlString, Asset } from '@anticrm/platform'
|
|
|
|
import type { Channel, ChannelProvider } from '@anticrm/contact'
|
|
|
|
import { getClient } from '@anticrm/presentation'
|
2021-08-31 10:42:40 +00:00
|
|
|
|
2021-09-01 15:11:01 +00:00
|
|
|
import { Icon } from '@anticrm/ui'
|
|
|
|
|
|
|
|
import contact from '@anticrm/contact'
|
2021-08-31 10:42:40 +00:00
|
|
|
|
|
|
|
export let value: Channel[]
|
|
|
|
|
2021-09-01 15:11:01 +00:00
|
|
|
interface Item {
|
|
|
|
label: IntlString,
|
|
|
|
icon: Asset,
|
|
|
|
value: string
|
|
|
|
}
|
|
|
|
|
|
|
|
const client = getClient()
|
|
|
|
|
|
|
|
async function getProviders(): Promise<Map<Ref<ChannelProvider>, ChannelProvider>> {
|
|
|
|
const providers = await client.findAll(contact.class.ChannelProvider, {})
|
|
|
|
const map = new Map<Ref<ChannelProvider>, ChannelProvider>()
|
|
|
|
for (const provider of providers) { map.set(provider._id, provider) }
|
|
|
|
return map
|
|
|
|
}
|
|
|
|
|
|
|
|
async function update(value: Channel[]) {
|
|
|
|
const result = []
|
|
|
|
const map = await getProviders()
|
|
|
|
for (const item of value) {
|
|
|
|
const provider = map.get(item.provider)
|
|
|
|
if (provider) {
|
|
|
|
result.push({
|
|
|
|
label: provider.label as IntlString,
|
|
|
|
icon: provider.icon as Asset,
|
|
|
|
value: item.value,
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
console.log('provider not found: ', item.provider)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
displayItems = result
|
|
|
|
}
|
|
|
|
|
|
|
|
$: update(value)
|
|
|
|
|
|
|
|
let displayItems: Item[] = []
|
|
|
|
|
2021-08-31 10:42:40 +00:00
|
|
|
</script>
|
|
|
|
|
2021-09-01 19:08:07 +00:00
|
|
|
<div class="container">
|
|
|
|
{#each displayItems as item}
|
|
|
|
<Icon icon={item.icon} size={'medium'}/>
|
|
|
|
{/each}
|
|
|
|
</div>
|
2021-08-31 10:42:40 +00:00
|
|
|
|
2021-09-01 19:08:07 +00:00
|
|
|
<style lang="scss">
|
|
|
|
.container {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
:global(svg + svg) { margin-left: .25rem; }
|
|
|
|
}
|
|
|
|
</style>
|