diff --git a/plugins/calendar-resources/src/components/Events.svelte b/plugins/calendar-resources/src/components/Events.svelte index f41e0b76d7..c9bfc1e191 100644 --- a/plugins/calendar-resources/src/components/Events.svelte +++ b/plugins/calendar-resources/src/components/Events.svelte @@ -30,7 +30,7 @@ TabList } from '@hcengineering/ui' import view, { Viewlet, ViewletPreference } from '@hcengineering/view' - import { FilterButton, getViewOptions, ViewletSettingButton } from '@hcengineering/view-resources' + import { FilterButton, getViewOptions, setActiveViewletId, ViewletSettingButton } from '@hcengineering/view-resources' import calendar from '../plugin' import { deviceOptionsStore as deviceInfo } from '@hcengineering/ui' @@ -56,6 +56,7 @@ viewlets = res if (selectedViewlet === undefined || res.findIndex((p) => p._id === selectedViewlet?._id) === -1) { selectedViewlet = res[0] + setActiveViewletId(selectedViewlet._id) } }, { lookup: { descriptor: view.class.ViewletDescriptor } } diff --git a/plugins/contact-resources/src/components/Contacts.svelte b/plugins/contact-resources/src/components/Contacts.svelte index 3e40664609..c972bf4568 100644 --- a/plugins/contact-resources/src/components/Contacts.svelte +++ b/plugins/contact-resources/src/components/Contacts.svelte @@ -22,6 +22,7 @@ ActionContext, FilterButton, getViewOptions, + setActiveViewletId, TableBrowser, ViewletSettingButton } from '@hcengineering/view-resources' @@ -51,6 +52,7 @@ .then((res) => { viewlet = res if (res !== undefined) { + setActiveViewletId(res._id) preferenceQuery.query( view.class.ViewletPreference, { diff --git a/plugins/contact-resources/src/components/Members.svelte b/plugins/contact-resources/src/components/Members.svelte index d2666d3f7a..77faf8dd5a 100644 --- a/plugins/contact-resources/src/components/Members.svelte +++ b/plugins/contact-resources/src/components/Members.svelte @@ -18,7 +18,7 @@ import { createQuery, getClient, UsersPopup, IconMembersOutline } from '@hcengineering/presentation' import { Button, IconAdd, Label, showPopup, Icon } from '@hcengineering/ui' import view, { Viewlet, ViewletPreference } from '@hcengineering/view' - import { getViewOptions, Table, ViewletSettingButton } from '@hcengineering/view-resources' + import { getViewOptions, setActiveViewletId, Table, ViewletSettingButton } from '@hcengineering/view-resources' import contact from '../plugin' export let objectId: Ref @@ -76,6 +76,7 @@ .then((res) => { descr = res if (res !== undefined) { + setActiveViewletId(res._id) preferenceQuery.query( view.class.ViewletPreference, { diff --git a/plugins/document-resources/src/components/Documents.svelte b/plugins/document-resources/src/components/Documents.svelte index ee1b9d176b..f45ed23466 100644 --- a/plugins/document-resources/src/components/Documents.svelte +++ b/plugins/document-resources/src/components/Documents.svelte @@ -24,6 +24,7 @@ ActionContext, FilterButton, getViewOptions, + setActiveViewletId, TableBrowser, ViewletSettingButton } from '@hcengineering/view-resources' @@ -53,6 +54,7 @@ .then((res) => { viewlet = res if (res !== undefined) { + setActiveViewletId(res._id) preferenceQuery.query( view.class.ViewletPreference, { diff --git a/plugins/hr-resources/src/components/DepartmentStaff.svelte b/plugins/hr-resources/src/components/DepartmentStaff.svelte index 181e55263a..3e631feacd 100644 --- a/plugins/hr-resources/src/components/DepartmentStaff.svelte +++ b/plugins/hr-resources/src/components/DepartmentStaff.svelte @@ -19,7 +19,7 @@ import { createQuery, getClient, UsersPopup } from '@hcengineering/presentation' import { Button, eventToHTMLElement, IconAdd, Label, Scroller, showPopup } from '@hcengineering/ui' import view, { Viewlet, ViewletPreference } from '@hcengineering/view' - import { getViewOptions, Table, ViewletSettingButton } from '@hcengineering/view-resources' + import { getViewOptions, setActiveViewletId, Table, ViewletSettingButton } from '@hcengineering/view-resources' import hr from '../plugin' import { addMember } from '../utils' @@ -77,6 +77,7 @@ .then((res) => { descr = res if (res !== undefined) { + setActiveViewletId(res._id) preferenceQuery.query( view.class.ViewletPreference, { diff --git a/plugins/hr-resources/src/components/schedule/MonthTableView.svelte b/plugins/hr-resources/src/components/schedule/MonthTableView.svelte index 653371ac28..971aaf0d69 100644 --- a/plugins/hr-resources/src/components/schedule/MonthTableView.svelte +++ b/plugins/hr-resources/src/components/schedule/MonthTableView.svelte @@ -20,7 +20,7 @@ import { createQuery, getClient } from '@hcengineering/presentation' import { Button, Label, Loading, Scroller, tableSP } from '@hcengineering/ui' import view, { BuildModelKey, Viewlet, ViewletPreference } from '@hcengineering/view' - import { getViewOptions, Table, ViewletSettingButton } from '@hcengineering/view-resources' + import { getViewOptions, setActiveViewletId, Table, ViewletSettingButton } from '@hcengineering/view-resources' import hr from '../../plugin' import { EmployeeReports, @@ -182,6 +182,7 @@ .then((res) => { descr = res if (res !== undefined) { + setActiveViewletId(res._id) preferenceQuery.query( view.class.ViewletPreference, { diff --git a/plugins/recruit-resources/src/components/Vacancies.svelte b/plugins/recruit-resources/src/components/Vacancies.svelte index f12132e7a9..23bc4bab08 100644 --- a/plugins/recruit-resources/src/components/Vacancies.svelte +++ b/plugins/recruit-resources/src/components/Vacancies.svelte @@ -18,7 +18,13 @@ import { Vacancy } from '@hcengineering/recruit' import { Button, Icon, IconAdd, Label, Loading, SearchEdit, showPopup } from '@hcengineering/ui' import view, { BuildModelKey, Viewlet, ViewletPreference } from '@hcengineering/view' - import { FilterButton, getViewOptions, TableBrowser, ViewletSettingButton } from '@hcengineering/view-resources' + import { + FilterButton, + getViewOptions, + setActiveViewletId, + TableBrowser, + ViewletSettingButton + } from '@hcengineering/view-resources' import recruit from '../plugin' import CreateVacancy from './CreateVacancy.svelte' import { deviceOptionsStore as deviceInfo } from '@hcengineering/ui' @@ -104,6 +110,7 @@ .then((res) => { descr = res if (res !== undefined) { + setActiveViewletId(res._id) preferenceQuery.query( view.class.ViewletPreference, { diff --git a/plugins/tracker-resources/src/components/issues/IssuesHeader.svelte b/plugins/tracker-resources/src/components/issues/IssuesHeader.svelte index a35ac61bfa..33315ca2cb 100644 --- a/plugins/tracker-resources/src/components/issues/IssuesHeader.svelte +++ b/plugins/tracker-resources/src/components/issues/IssuesHeader.svelte @@ -50,6 +50,7 @@ if (result.detail !== undefined) { if (viewlet?._id === result.detail.id) return viewlet = viewlets.find((vl) => vl._id === result.detail.id) + console.log('set viewlet by issue headed') if (viewlet) setActiveViewletId(viewlet._id) } }} diff --git a/plugins/tracker-resources/src/components/issues/IssuesView.svelte b/plugins/tracker-resources/src/components/issues/IssuesView.svelte index d2858555de..5590a79b13 100644 --- a/plugins/tracker-resources/src/components/issues/IssuesView.svelte +++ b/plugins/tracker-resources/src/components/issues/IssuesView.svelte @@ -5,7 +5,7 @@ import { Issue, IssueStatus, Team } from '@hcengineering/tracker' import { Button, IconDetails, IconDetailsFilled } from '@hcengineering/ui' import view, { Viewlet } from '@hcengineering/view' - import { FilterBar, getActiveViewletId, getViewOptions } from '@hcengineering/view-resources' + import { FilterBar, getActiveViewletId, getViewOptions, setActiveViewletId } from '@hcengineering/view-resources' import ViewletSettingButton from '@hcengineering/view-resources/src/components/ViewletSettingButton.svelte' import tracker from '../../plugin' import IssuesContent from './IssuesContent.svelte' @@ -45,6 +45,7 @@ ) const _id = getActiveViewletId() viewlet = viewlets.find((viewlet) => viewlet._id === _id) || viewlets[0] + setActiveViewletId(viewlet._id) } $: if (!label && title) { translate(title, {}).then((res) => { @@ -118,7 +119,7 @@ - (resultQuery = e.detail)} /> + (resultQuery = e.detail)} />
{#if viewlet && _teams && issueStatuses} diff --git a/plugins/tracker-resources/src/components/templates/IssueTemplatesView.svelte b/plugins/tracker-resources/src/components/templates/IssueTemplatesView.svelte index b22f42d418..605ce4f5ed 100644 --- a/plugins/tracker-resources/src/components/templates/IssueTemplatesView.svelte +++ b/plugins/tracker-resources/src/components/templates/IssueTemplatesView.svelte @@ -5,7 +5,7 @@ import { IssueTemplate } from '@hcengineering/tracker' import { Button, IconAdd, IconDetails, IconDetailsFilled, showPopup } from '@hcengineering/ui' import view, { Viewlet } from '@hcengineering/view' - import { FilterBar, getActiveViewletId, getViewOptions } from '@hcengineering/view-resources' + import { FilterBar, getActiveViewletId, getViewOptions, setActiveViewletId } from '@hcengineering/view-resources' import ViewletSettingButton from '@hcengineering/view-resources/src/components/ViewletSettingButton.svelte' import tracker from '../../plugin' import IssuesHeader from '../issues/IssuesHeader.svelte' @@ -47,6 +47,7 @@ ) const _id = getActiveViewletId() viewlet = viewlets.find((viewlet) => viewlet._id === _id) || viewlets[0] + setActiveViewletId(viewlet._id) } $: if (!label && title) { translate(title, {}).then((res) => { @@ -105,7 +106,12 @@ - (resultQuery = e.detail)} /> + (resultQuery = e.detail)} +/>
{#if viewlet && viewOptions} diff --git a/plugins/view-resources/src/components/filter/FilterBar.svelte b/plugins/view-resources/src/components/filter/FilterBar.svelte index c220be3a08..0bff4eb126 100644 --- a/plugins/view-resources/src/components/filter/FilterBar.svelte +++ b/plugins/view-resources/src/components/filter/FilterBar.svelte @@ -17,7 +17,7 @@ import { getResource } from '@hcengineering/platform' import { getClient } from '@hcengineering/presentation' import { Button, eventToHTMLElement, getCurrentLocation, IconAdd, locationToUrl, showPopup } from '@hcengineering/ui' - import { Filter } from '@hcengineering/view' + import { Filter, ViewOptions } from '@hcengineering/view' import { createEventDispatcher } from 'svelte' import { filterStore } from '../../filter' import view from '../../plugin' @@ -27,6 +27,7 @@ export let _class: Ref> export let query: DocumentQuery + export let viewOptions: ViewOptions | undefined = undefined const client = getClient() const hierarchy = client.getHierarchy() @@ -79,7 +80,7 @@ } async function saveFilteredView () { - showPopup(FilterSave, {}) + showPopup(FilterSave, { viewOptions }) } let loading = false diff --git a/plugins/view-resources/src/components/filter/FilterSave.svelte b/plugins/view-resources/src/components/filter/FilterSave.svelte index b1980653ca..c17f29fac2 100644 --- a/plugins/view-resources/src/components/filter/FilterSave.svelte +++ b/plugins/view-resources/src/components/filter/FilterSave.svelte @@ -5,25 +5,28 @@ import preference from '@hcengineering/preference' import { createEventDispatcher } from 'svelte' import { filterStore } from '../../filter' + import { ViewOptions } from '@hcengineering/view' + import { Doc, Ref } from '@hcengineering/core' + import { getActiveViewletId } from '../../utils' + + export let viewOptions: ViewOptions | undefined = undefined let filterName = '' const client = getClient() - function getFilteredViewData () { + async function saveFilter () { const loc = getCurrentLocation() loc.fragment = undefined loc.query = undefined const filters = JSON.stringify($filterStore) - return { + await client.createDoc(view.class.FilteredView, preference.space.Preference, { name: filterName, location: loc, filters, - attachedTo: loc.path[2] - } - } - - async function saveFilter () { - await client.createDoc(view.class.FilteredView, preference.space.Preference, getFilteredViewData()) + attachedTo: loc.path[2] as Ref, + viewOptions, + viewletId: getActiveViewletId() + }) } const dispatch = createEventDispatcher() diff --git a/plugins/view-resources/src/utils.ts b/plugins/view-resources/src/utils.ts index 5f43151d77..89b29d6159 100644 --- a/plugins/view-resources/src/utils.ts +++ b/plugins/view-resources/src/utils.ts @@ -34,6 +34,7 @@ import { AnyComponent, ErrorPresenter, getCurrentLocation, + Location, getPlatformColorForText, locationToUrl } from '@hcengineering/ui' @@ -474,16 +475,16 @@ export function isCollectionAttr (hierarchy: Hierarchy, key: KeyedAttribute): bo return hierarchy.isDerived(key.attr.type._class, core.class.Collection) } -function makeViewletKey (): string { - const loc = getCurrentLocation() +function makeViewletKey (loc?: Location): string { + loc = loc ?? getCurrentLocation() loc.fragment = undefined loc.query = undefined return 'viewlet' + locationToUrl(loc) } -export function setActiveViewletId (viewletId: Ref | null): void { - const key = makeViewletKey() - if (viewletId !== null) { +export function setActiveViewletId (viewletId: Ref | null, loc?: Location): void { + const key = makeViewletKey(loc) + if (viewletId !== null && viewletId !== undefined) { localStorage.setItem(key, viewletId) } else { localStorage.removeItem(key) diff --git a/plugins/view-resources/src/viewOptions.ts b/plugins/view-resources/src/viewOptions.ts index efacf8ee44..5e572a3755 100644 --- a/plugins/view-resources/src/viewOptions.ts +++ b/plugins/view-resources/src/viewOptions.ts @@ -17,25 +17,25 @@ export function isDropdownType (viewOption: ViewOptionModel): viewOption is Drop return viewOption.type === 'dropdown' } -function makeViewOptionsKey (prefix: string): string { +function makeViewOptionsKey (viewlet: Viewlet): string { + const prefix = viewlet?._id + (viewlet?.variant !== undefined ? `-${viewlet.variant}` : '') const loc = getCurrentLocation() loc.fragment = undefined loc.query = undefined return `viewOptions:${prefix}:${locationToUrl(loc)}` } -function _setViewOptions (prefix: string, options: ViewOptions): void { - const key = makeViewOptionsKey(prefix) +function _setViewOptions (viewlet: Viewlet, options: ViewOptions): void { + const key = makeViewOptionsKey(viewlet) localStorage.setItem(key, JSON.stringify(options)) } export function setViewOptions (viewlet: Viewlet, options: ViewOptions): void { - const viewletKey = viewlet?._id + (viewlet?.variant !== undefined ? `-${viewlet.variant}` : '') - _setViewOptions(viewletKey, options) + _setViewOptions(viewlet, options) } -function _getViewOptions (prefix: string): ViewOptions | null { - const key = makeViewOptionsKey(prefix) +function _getViewOptions (viewlet: Viewlet): ViewOptions | null { + const key = makeViewOptionsKey(viewlet) const options = localStorage.getItem(key) if (options === null) return null return JSON.parse(options) @@ -45,6 +45,5 @@ export function getViewOptions (viewlet: Viewlet | undefined, defaults = defaulO if (viewlet === undefined) { return { ...defaults } } - const viewletKey = viewlet?._id + (viewlet?.variant !== undefined ? `-${viewlet.variant}` : '') - return _getViewOptions(viewletKey) ?? defaults + return _getViewOptions(viewlet) ?? defaults } diff --git a/plugins/view/src/index.ts b/plugins/view/src/index.ts index 5c325ec87c..7c746b2b9f 100644 --- a/plugins/view/src/index.ts +++ b/plugins/view/src/index.ts @@ -82,6 +82,8 @@ export interface FilteredView extends Preference { name: string location: PlatformLocation filters: string + viewOptions?: ViewOptions + viewletId?: Ref | null } /** diff --git a/plugins/workbench-resources/src/components/Navigator.svelte b/plugins/workbench-resources/src/components/Navigator.svelte index 55c8c22adf..fa22aebb3b 100644 --- a/plugins/workbench-resources/src/components/Navigator.svelte +++ b/plugins/workbench-resources/src/components/Navigator.svelte @@ -13,26 +13,22 @@ // limitations under the License. --> {#if model} @@ -166,20 +145,7 @@ {/if} {#if specials.length > 0}{/if} - {#if filteredViews && filteredViews.length > 0} - - {#each filteredViews as fV} - { - navigate(fV.location) - $filterStore = JSON.parse(fV.filters) - }} - actions={() => removeAction(fV)} - /> - {/each} - - {/if} + {#if starred.length} {/if} diff --git a/plugins/workbench-resources/src/components/SavedView.svelte b/plugins/workbench-resources/src/components/SavedView.svelte new file mode 100644 index 0000000000..dec5ae094d --- /dev/null +++ b/plugins/workbench-resources/src/components/SavedView.svelte @@ -0,0 +1,57 @@ + + +{#if filteredViews && filteredViews.length > 0} + + {#each filteredViews as fv} + load(fv)} actions={() => removeAction(fv)} /> + {/each} + +{/if} diff --git a/plugins/workbench-resources/src/components/SpaceContent.svelte b/plugins/workbench-resources/src/components/SpaceContent.svelte index bd914441d1..8fecaa1620 100644 --- a/plugins/workbench-resources/src/components/SpaceContent.svelte +++ b/plugins/workbench-resources/src/components/SpaceContent.svelte @@ -18,7 +18,7 @@ import { IntlString } from '@hcengineering/platform' import { createQuery } from '@hcengineering/presentation' import { AnyComponent, Component, Loading } from '@hcengineering/ui' - import view, { Viewlet, ViewletPreference } from '@hcengineering/view' + import view, { Viewlet, ViewletPreference, ViewOptions } from '@hcengineering/view' import { FilterBar } from '@hcengineering/view-resources' export let _class: Ref> @@ -27,6 +27,7 @@ export let viewlet: WithLookup | undefined export let createItemDialog: AnyComponent | undefined export let createItemLabel: IntlString | undefined + export let viewOptions: ViewOptions const preferenceQuery = createQuery() let preference: ViewletPreference | undefined @@ -56,7 +57,7 @@ {#if loading} {:else} - (resultQuery = e.detail)} /> + (resultQuery = e.detail)} /> | undefined export let createItemDialog: AnyComponent | undefined @@ -38,6 +41,7 @@ export let viewlet: WithLookup | undefined export let viewlets: WithLookup[] = [] export let _class: Ref> | undefined = undefined + export let viewOptions: ViewOptions const client = getClient() const hierarchy = client.getHierarchy() @@ -79,6 +83,7 @@ const _id = getActiveViewletId() const index = viewlets.findIndex((p) => p._id === (viewlet?._id ?? _id)) viewlet = index === -1 ? viewlets[0] : viewlets[index] + setActiveViewletId(viewlet._id) } $: viewslist = viewlets.map((views) => { return { @@ -89,8 +94,6 @@ }) $: twoRows = $deviceInfo.twoRows - - $: viewOptions = getViewOptions(viewlet)
@@ -130,6 +133,7 @@ on:select={(result) => { if (result.detail !== undefined) { viewlet = viewlets.find((vl) => vl._id === result.detail.id) + console.log('set viewlet by space headed') if (viewlet) setActiveViewletId(viewlet._id) } }} diff --git a/plugins/workbench-resources/src/components/SpaceView.svelte b/plugins/workbench-resources/src/components/SpaceView.svelte index 31577d3acd..790489fc7d 100644 --- a/plugins/workbench-resources/src/components/SpaceView.svelte +++ b/plugins/workbench-resources/src/components/SpaceView.svelte @@ -18,7 +18,7 @@ import { getClient } from '@hcengineering/presentation' import { AnyComponent, Component } from '@hcengineering/ui' import view, { Viewlet } from '@hcengineering/view' - import { getActiveViewletId } from '@hcengineering/view-resources' + import { getActiveViewletId, getViewOptions } from '@hcengineering/view-resources' import type { ViewConfiguration } from '@hcengineering/workbench' import SpaceContent from './SpaceContent.svelte' import SpaceHeader from './SpaceHeader.svelte' @@ -79,6 +79,8 @@ function setViewlet (e: CustomEvent>) { viewlet = e.detail } + + $: viewOptions = getViewOptions(viewlet) {#if _class && space} @@ -95,9 +97,10 @@ {viewlets} {createItemDialog} {createItemLabel} + {viewOptions} bind:search bind:viewlet /> {/if} - + {/if} diff --git a/plugins/workbench-resources/src/components/SpecialView.svelte b/plugins/workbench-resources/src/components/SpecialView.svelte index 9ff3e63a14..bc9e6eab36 100644 --- a/plugins/workbench-resources/src/components/SpecialView.svelte +++ b/plugins/workbench-resources/src/components/SpecialView.svelte @@ -29,7 +29,13 @@ showPopup } from '@hcengineering/ui' import view, { Viewlet, ViewletDescriptor, ViewletPreference } from '@hcengineering/view' - import { FilterBar, FilterButton, getViewOptions, ViewletSettingButton } from '@hcengineering/view-resources' + import { + FilterBar, + FilterButton, + getViewOptions, + setActiveViewletId, + ViewletSettingButton + } from '@hcengineering/view-resources' export let _class: Ref> export let space: Ref | undefined = undefined @@ -71,6 +77,7 @@ .then((res) => { viewlet = res if (res !== undefined) { + setActiveViewletId(res._id) preferenceQuery.query( view.class.ViewletPreference, { @@ -120,6 +127,7 @@ { resultQuery = e.detail }}