Skip to content

Commit

Permalink
wip: Refactor catalog based panel #919
Browse files Browse the repository at this point in the history
  • Loading branch information
cnouguier committed Aug 5, 2024
1 parent e8ebf1b commit aacee68
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 129 deletions.
112 changes: 77 additions & 35 deletions map/client/components/catalog/KLayersPanel.vue
Original file line number Diff line number Diff line change
@@ -1,53 +1,79 @@
<template>
<KScrollArea :maxHeight="scrollAreaMaxHeight" :style="panelStyle">
<q-list dense bordered>
<slot name="header" />
<!-- Orphan layers -->
<k-layers-selector
:layers="orphanLayers"
:options="{ hideIfEmpty: true }"
/>
<!-- Categorized layers -->
<template v-for="category in filteredCategories">
<q-expansion-item
v-if="isVisible(category)"
:key="getId(category)"
:id="getId(category)"
:header-class="getHeaderClass(category)"
:icon="getIcon(category)"
:label="$t(category.name)"
:default-opened="getDefaultOpened(category)"
expand-separator>
<component
:is="category.componentInstance"
:layers="layersByCategory[category.name]"
:forecastModels="forecastModels"
:options="category.options || category">
</component>
</q-expansion-item>
</template>
<slot name="footer" />
</q-list>
</KScrollArea>
<div class="fit column">
<!--
Header
-->
<div class="q-pr-xs q-pb-xs">
<slot name="header">
<KPanel
:content="header"
:class="headerClass"
/>
<q-separator inset v-if="header"/>
</slot>
</div>
<!--
Content
-->
<q-scroll-area class="col">
<q-list dense>
<!-- Orphan layers -->
<KLayersSelector
:layers="orphanLayers"
:options="{ hideIfEmpty: true }"
/>
<!-- Categorized layers -->
<template v-for="category in filteredCategories">
<q-expansion-item
v-if="isVisible(category)"
:key="getId(category)"
:id="getId(category)"
:header-class="getHeaderClass(category)"
:icon="getIcon(category)"
:label="$t(category.name)"
:default-opened="getDefaultOpened(category)"
expand-separator>
<component
:is="category.componentInstance"
:layers="layersByCategory[category.name]"
:forecastModels="forecastModels"
:options="category.options || category">
</component>
</q-expansion-item>
</template>
</q-list>
</q-scroll-area>
<!--
Footer
-->
<!--
Footer
-->
<div>
<slot name="footer">
<q-separator inset v-if="footer"/>
<KPanel
:content="footer"
:class="footerClass"
/>
</slot>
</div>
</div>
</template>

<script>
import sift from 'sift'
import _ from 'lodash'
import { loadComponent } from '../../../../core/client/utils'
import { getLayersByCategory, getOrphanLayers } from '../../utils'
import { KScrollArea } from '../../../../core/client/components'
import { catalogPanel } from '../../mixins'
import { useProject } from '../../composables'
import KLayersSelector from './KLayersSelector.vue'
export default {
name: 'k-layers-panel',
components: {
KScrollArea,
KLayersSelector
},
mixins: [catalogPanel],
props: {
layers: {
type: [Object, Array],
Expand All @@ -68,7 +94,23 @@ export default {
forecastModels: {
type: Array,
default: () => []
}
},
header: {
type: [Array, Object],
default: () => null
},
headerClass: {
type: String,
default: undefined
},
footer: {
type: [Array, Object],
default: () => null
},
footerClass: {
type: String,
default: undefined
}
},
inheritAttrs: false,
computed: {
Expand Down
52 changes: 19 additions & 33 deletions map/client/components/catalog/KProjectsPanel.vue
Original file line number Diff line number Diff line change
@@ -1,43 +1,33 @@
<template>
<q-list dense bordered>
<div class="no-padding" :style="panelStyle">
<q-resize-observer @resize="onResized" />
<KPanel
id="favorite-views-toolbar"
:content="toolbar"
class="no-wrap q-pl-sm q-pr-md"
/>
<KColumn
class="q-pl-sm"
service="projects"
:renderer="projectRenderer"
:nbItemsPerPage="20"
:append-items="true"
:base-query="baseQuery"
:filter-query="filter.query"
:height="scrollAreaMaxHeight - 100"
:width="scrollAreaMaxWidth - 50"
:dense="true"
@selection-changed="onProjectSelected"
/>
</div>
</q-list>
<div class="fit column">
<KCollection
service="projects"
:renderer="projectRenderer"
:nb-items-per-page="20"
:append-items="true"
:base-query="baseQuery"
:filter-query="filter.query"
:dense="true"
:header="toolbar"
header-class="justify-between"
@selection-changed="onProjectSelected"
class="q-pl-sm col"
/>
</div>
</template>

<script>
import logger from 'loglevel'
import { Filter, Sorter, utils, i18n } from '../../../../core/client'
import { KColumn, KPanel, KAction } from '../../../../core/client/components'
import { catalogPanel } from '../../mixins'
import { KCollection, KPanel, KAction } from '../../../../core/client/components'
export default {
name: 'k-projects-panel',
components: {
KColumn,
KCollection,
KPanel,
KAction
},
mixins: [catalogPanel],
inject: ['kActivity'],
computed: {
baseQuery () {
Expand All @@ -48,9 +38,7 @@ export default {
{
id: 'projects-filter',
component: 'collection/KFilter',
class: 'full-width'
},
{ component: 'QSpace' },
{
component: 'collection/KSorter',
id: 'projects-sorter',
Expand Down Expand Up @@ -94,11 +82,12 @@ export default {
}
return {
scrollAreaMaxWidth: 0,
scrollAreaMaxHeight: 0,
filter: Filter.get(),
sorter: Sorter.get(),
projectRenderer: {
component: 'catalog/KProjectSelector',
class: 'q-pt-xs q-pb-xs q-pr-xs',
class: 'col-12',
actions: projectActions
}
}
Expand Down Expand Up @@ -144,9 +133,6 @@ export default {
})
if (!result.ok) return false
await this.$api.getService('projects').remove(project._id)
},
onResized (size) {
this.scrollAreaMaxWidth = size.width
}
}
}
Expand Down
52 changes: 18 additions & 34 deletions map/client/components/catalog/KViewsPanel.vue
Original file line number Diff line number Diff line change
@@ -1,45 +1,35 @@
<template>
<q-list dense bordered>
<div class="no-padding" :style="panelStyle">
<q-resize-observer @resize="onResized" />
<KPanel
id="favorite-views-toolbar"
:content="toolbar"
class="no-wrap q-pl-sm q-pr-md"
/>
<KColumn
class="q-pl-sm"
service="catalog"
:renderer="viewRenderer"
:nbItemsPerPage="20"
:append-items="true"
:base-query="baseQuery"
:filter-query="filterQuery"
@selection-changed="onViewSelected"
:height="scrollAreaMaxHeight - 100"
:width="scrollAreaMaxWidth"
:dense="true"
/>
</div>
</q-list>
<div class="fit column">
<KCollection
service="catalog"
:renderer="viewRenderer"
:nb-items-per-page="20"
:append-items="true"
:base-query="baseQuery"
:filter-query="filterQuery"
:dense="true"
:header="toolbar"
header-class="justify-between"
@selection-changed="onViewSelected"
class="q-pl-sm col"
/>
</div>
</template>

<script>
import _ from 'lodash'
import logger from 'loglevel'
import { Filter, Sorter, utils, i18n } from '../../../../core/client'
import { KColumn, KPanel, KAction } from '../../../../core/client/components'
import { catalogPanel } from '../../mixins'
import { KCollection, KPanel, KAction } from '../../../../core/client/components'
import { useProject } from '../../composables'
export default {
name: 'k-views-panel',
components: {
KColumn,
KCollection,
KPanel,
KAction
},
mixins: [catalogPanel],
inject: ['kActivity'],
data () {
const viewActions = []
Expand All @@ -60,12 +50,11 @@ export default {
})
}
return {
scrollAreaMaxWidth: 0,
filter: Filter.get(),
sorter: Sorter.get(),
viewRenderer: {
component: 'catalog/KViewSelector',
class: 'q-pt-xs q-pb-xs q-pr-xs',
class: 'col-12',
actions: viewActions
}
}
Expand All @@ -84,9 +73,7 @@ export default {
{
id: 'views-filter',
component: 'collection/KFilter',
class: 'full-width'
},
{ component: 'QSpace' },
{
component: 'collection/KSorter',
id: 'views-sorter',
Expand Down Expand Up @@ -141,9 +128,6 @@ export default {
})
if (!result.ok) return false
await this.$api.getService('catalog').remove(view._id)
},
onResized (size) {
this.scrollAreaMaxWidth = size.width
}
},
// Should be used with <Suspense> to ensure the project is loaded upfront
Expand Down
1 change: 0 additions & 1 deletion map/client/mixins/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export * from './mixin.activity.js'
export * from './mixin.catalog-panel.js'
export * from './mixin.context.js'
export * from './mixin.feature-selection.js'
export * from './mixin.feature-service.js'
Expand Down
26 changes: 0 additions & 26 deletions map/client/mixins/mixin.catalog-panel.js

This file was deleted.

0 comments on commit aacee68

Please sign in to comment.