2022-03-23 09:03:41 +00:00
|
|
|
<!--
|
|
|
|
// Copyright © 2022 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">
|
2022-09-21 08:08:25 +00:00
|
|
|
import { Event } from '@hcengineering/calendar'
|
|
|
|
import { Class, DocumentQuery, Ref, Space, WithLookup } from '@hcengineering/core'
|
|
|
|
import { Asset, IntlString } from '@hcengineering/platform'
|
|
|
|
import { createQuery } from '@hcengineering/presentation'
|
2022-05-12 09:40:22 +00:00
|
|
|
import {
|
|
|
|
AnyComponent,
|
|
|
|
Button,
|
2022-06-15 12:00:32 +00:00
|
|
|
Component,
|
2022-05-12 09:40:22 +00:00
|
|
|
Icon,
|
|
|
|
IconAdd,
|
|
|
|
Label,
|
2022-06-15 12:00:32 +00:00
|
|
|
Loading,
|
2022-05-12 09:40:22 +00:00
|
|
|
SearchEdit,
|
|
|
|
showPopup,
|
2022-06-20 14:11:14 +00:00
|
|
|
TabList
|
2022-09-21 08:08:25 +00:00
|
|
|
} from '@hcengineering/ui'
|
|
|
|
import view, { Viewlet, ViewletPreference } from '@hcengineering/view'
|
|
|
|
import { FilterButton, ViewletSettingButton } from '@hcengineering/view-resources'
|
2022-03-23 09:03:41 +00:00
|
|
|
import calendar from '../plugin'
|
2022-10-04 15:49:11 +00:00
|
|
|
import { deviceOptionsStore as deviceInfo } from '@hcengineering/ui'
|
2022-03-23 09:03:41 +00:00
|
|
|
|
2022-06-15 12:00:32 +00:00
|
|
|
export let _class: Ref<Class<Event>> = calendar.class.Event
|
|
|
|
export let space: Ref<Space> | undefined = undefined
|
2022-03-23 09:03:41 +00:00
|
|
|
export let query: DocumentQuery<Event> = {}
|
|
|
|
|
2022-05-12 09:40:22 +00:00
|
|
|
export let viewIcon: Asset = calendar.icon.Calendar
|
|
|
|
export let viewLabel: IntlString = calendar.string.Events
|
|
|
|
|
2022-06-15 12:00:32 +00:00
|
|
|
export let createComponent: AnyComponent | undefined = calendar.component.CreateEvent
|
|
|
|
export let createLabel: IntlString | undefined = calendar.string.CreateEvent
|
2022-03-23 09:03:41 +00:00
|
|
|
|
2022-06-15 12:00:32 +00:00
|
|
|
const viewletQuery = createQuery()
|
2022-03-23 09:03:41 +00:00
|
|
|
let search = ''
|
|
|
|
let resultQuery: DocumentQuery<Event> = {}
|
|
|
|
|
2022-06-15 12:00:32 +00:00
|
|
|
let viewlets: WithLookup<Viewlet>[] = []
|
|
|
|
viewletQuery.query(
|
|
|
|
view.class.Viewlet,
|
|
|
|
{ attachTo: _class },
|
|
|
|
(res) => {
|
|
|
|
viewlets = res
|
|
|
|
if (selectedViewlet === undefined || res.findIndex((p) => p._id === selectedViewlet?._id) === -1) {
|
|
|
|
selectedViewlet = res[0]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{ lookup: { descriptor: view.class.ViewletDescriptor } }
|
|
|
|
)
|
|
|
|
|
2022-03-23 09:03:41 +00:00
|
|
|
function updateResultQuery (search: string): void {
|
|
|
|
resultQuery = search === '' ? { ...query } : { ...query, $search: search }
|
|
|
|
}
|
|
|
|
|
|
|
|
$: updateResultQuery(search)
|
|
|
|
|
2022-05-12 09:40:22 +00:00
|
|
|
function showCreateDialog () {
|
|
|
|
if (createComponent === undefined) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
showPopup(createComponent, {}, 'top')
|
|
|
|
}
|
2022-06-15 12:00:32 +00:00
|
|
|
|
|
|
|
let selectedViewlet: WithLookup<Viewlet> | undefined
|
|
|
|
|
|
|
|
const preferenceQuery = createQuery()
|
|
|
|
let preference: ViewletPreference | undefined
|
|
|
|
let loading = true
|
|
|
|
|
|
|
|
$: selectedViewlet &&
|
|
|
|
preferenceQuery.query(
|
|
|
|
view.class.ViewletPreference,
|
|
|
|
{
|
|
|
|
attachedTo: selectedViewlet._id
|
|
|
|
},
|
|
|
|
(res) => {
|
|
|
|
preference = res[0]
|
|
|
|
loading = false
|
|
|
|
},
|
|
|
|
{ limit: 1 }
|
|
|
|
)
|
2022-06-20 14:11:14 +00:00
|
|
|
$: viewslist = viewlets.map((views) => {
|
|
|
|
return {
|
|
|
|
id: views._id,
|
|
|
|
icon: views.$lookup?.descriptor?.icon,
|
|
|
|
tooltip: views.$lookup?.descriptor?.label
|
|
|
|
}
|
|
|
|
})
|
2022-10-04 15:49:11 +00:00
|
|
|
|
2022-10-24 10:26:56 +00:00
|
|
|
$: twoRows = $deviceInfo.twoRows
|
2022-03-23 09:03:41 +00:00
|
|
|
</script>
|
|
|
|
|
2022-10-04 15:49:11 +00:00
|
|
|
<div class="ac-header withSettings" class:full={!twoRows} class:mini={twoRows}>
|
|
|
|
<div class:ac-header-full={!twoRows} class:flex-between={twoRows}>
|
|
|
|
<div class="ac-header__wrap-title mr-3">
|
|
|
|
<div class="ac-header__icon"><Icon icon={viewIcon} size={'small'} /></div>
|
|
|
|
<span class="ac-header__title"><Label label={viewLabel} /></span>
|
|
|
|
<div class="ml-4"><FilterButton {_class} /></div>
|
|
|
|
</div>
|
2022-03-23 09:03:41 +00:00
|
|
|
|
2022-10-04 15:49:11 +00:00
|
|
|
<SearchEdit
|
|
|
|
bind:value={search}
|
|
|
|
on:change={() => {
|
|
|
|
updateResultQuery(search)
|
2022-06-20 14:11:14 +00:00
|
|
|
}}
|
|
|
|
/>
|
2022-10-04 15:49:11 +00:00
|
|
|
</div>
|
|
|
|
<div class="ac-header-full" class:secondRow={twoRows}>
|
|
|
|
<Button icon={IconAdd} label={createLabel} kind={'primary'} size={'small'} on:click={showCreateDialog} />
|
|
|
|
|
|
|
|
{#if viewlets.length > 1}
|
|
|
|
<TabList
|
|
|
|
items={viewslist}
|
|
|
|
multiselect={false}
|
|
|
|
selected={selectedViewlet?._id}
|
|
|
|
kind={'secondary'}
|
|
|
|
size={'small'}
|
|
|
|
on:select={(result) => {
|
|
|
|
if (result.detail !== undefined) selectedViewlet = viewlets.find((vl) => vl._id === result.detail.id)
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
{/if}
|
|
|
|
<ViewletSettingButton viewlet={selectedViewlet} />
|
|
|
|
</div>
|
2022-03-23 09:03:41 +00:00
|
|
|
</div>
|
|
|
|
|
2022-06-15 12:00:32 +00:00
|
|
|
{#if selectedViewlet?.$lookup?.descriptor?.component}
|
|
|
|
{#if loading}
|
|
|
|
<Loading />
|
|
|
|
{:else}
|
|
|
|
<Component
|
|
|
|
is={selectedViewlet.$lookup?.descriptor?.component}
|
|
|
|
props={{
|
|
|
|
_class,
|
|
|
|
space,
|
|
|
|
options: selectedViewlet.options,
|
|
|
|
config: preference?.config ?? selectedViewlet.config,
|
|
|
|
viewlet: selectedViewlet,
|
|
|
|
query: resultQuery,
|
|
|
|
search,
|
|
|
|
createComponent
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
{/if}
|
2022-03-23 09:03:41 +00:00
|
|
|
{/if}
|