Skip to content

Commit 43fee0b

Browse files
committed
admin display
1 parent 2794820 commit 43fee0b

13 files changed

Lines changed: 119 additions & 25 deletions

File tree

client/src/MapStore.ts

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ export default class MapStore {
3434

3535
public static proModeButtonEnabled = ref(true);
3636

37-
public static displayConfiguration: Ref<DisplayConfiguration> = ref({ default_displayed_layers: [], enabled_ui: ['Collections', 'Datasets', 'Metadata'], default_tab: 'Scenarios' });
37+
public static displayConfiguration: Ref<DisplayConfiguration> = ref(
38+
{ default_displayed_layers: [], enabled_ui: ['Collections', 'Datasets', 'Metadata'], default_tab: 'Scenarios' },
39+
);
3840

3941
// Ability to toggle proMode so Staff users can see what other users see.
4042
public static proMode = computed(() => MapStore.userIsStaff.value && MapStore.proModeButtonEnabled.value);
@@ -106,14 +108,57 @@ export default class MapStore {
106108
MapStore.mapLayersByDataset[datasetId] = await UVdatApi.getDatasetLayers(datasetId);
107109
}
108110

109-
public static async getDisplayConfiguration() {
111+
public static async getDisplayConfiguration(initial = false) {
110112
MapStore.displayConfiguration.value = await UVdatApi.getDisplayConfiguration();
113+
// Loading first time process default map layers
114+
if (initial && MapStore.displayConfiguration.value.default_displayed_layers.length) {
115+
const datasetIds = MapStore.displayConfiguration.value.default_displayed_layers.map((item) => item.dataset_id);
116+
const datasetIdLayers = await UVdatApi.getDatasetsLayers(datasetIds);
117+
const layerByDataset: Record<number, (VectorMapLayer | RasterMapLayer | NetCDFData)[]> = {};
118+
const toggleLayers: (VectorMapLayer | RasterMapLayer | NetCDFLayer)[] = [];
119+
const enabledLayers = MapStore.displayConfiguration.value.default_displayed_layers;
120+
datasetIdLayers.forEach((item) => {
121+
if (item.dataset_id !== undefined) {
122+
if (layerByDataset[item.dataset_id] === undefined) {
123+
layerByDataset[item.dataset_id] = [];
124+
}
125+
layerByDataset[item.dataset_id].push(item);
126+
}
127+
enabledLayers.forEach((enabledLayer) => {
128+
if (item.type === 'netcdf') {
129+
if (enabledLayer.dataset_id === item.dataset_id) {
130+
const netCDFLayers = ((item as NetCDFData).layers);
131+
for (let i = 0; i < netCDFLayers.length; i += 1) {
132+
const layer = netCDFLayers[i];
133+
if (layer.id === enabledLayer.id) {
134+
toggleLayers.push(layer);
135+
}
136+
}
137+
}
138+
} else if (
139+
enabledLayer.type === item.type
140+
&& enabledLayer.id === item.id
141+
&& enabledLayer.dataset_id === item.dataset_id) {
142+
toggleLayers.push(item);
143+
}
144+
});
145+
});
146+
Object.keys(layerByDataset).forEach((datasetIdKey) => {
147+
const datasetId = parseInt(datasetIdKey, 10);
148+
if (!Number.isNaN(datasetId)) {
149+
MapStore.mapLayersByDataset[datasetId] = layerByDataset[datasetId];
150+
}
151+
});
152+
// Now we enable these default layers
153+
return toggleLayers;
154+
}
155+
return [];
111156
}
112157

113158
public static mapLayerFeatureGraphs = computed(() => {
114159
const foundMapLayerFeatureGraphs: { name: string, id: number; graphs: VectorFeatureTableGraph[] }[] = [];
115160
MapStore.selectedVectorMapLayers.value.forEach((item) => {
116-
if (item.default_style.mapLayerFeatureTableGraphs && item.default_style.mapLayerFeatureTableGraphs.length) {
161+
if (item.default_style?.mapLayerFeatureTableGraphs && item.default_style.mapLayerFeatureTableGraphs.length) {
117162
foundMapLayerFeatureGraphs.push({
118163
name: item.name,
119164
id: item.id,
@@ -140,7 +185,7 @@ export default class MapStore {
140185
public static mapLayerVectorSearchable = computed(() => {
141186
const foundMapLayerSearchable: { name: string, id: number; searchSettings: SearchableVectorData }[] = [];
142187
MapStore.selectedVectorMapLayers.value.forEach((item) => {
143-
if (item.default_style.searchableVectorFeatureData) {
188+
if (item.default_style?.searchableVectorFeatureData) {
144189
foundMapLayerSearchable.push({
145190
name: item.name,
146191
id: item.id,

client/src/api/UVDATApi.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,12 @@ export default class UVdatApi {
452452
return (await UVdatApi.apiClient.get(`/datasets/${datasetId}/map_layers`)).data;
453453
}
454454

455+
public static async getDatasetsLayers(datasetIds: number[]): Promise<(VectorMapLayer | RasterMapLayer | NetCDFData)[]> {
456+
const params = new URLSearchParams();
457+
datasetIds.forEach((item) => params.append('datasetIds', item.toString()));
458+
return (await UVdatApi.apiClient.get('/datasets/map_layers', { params })).data;
459+
}
460+
455461
public static async getProcessingTasks(): Promise<ProcessingTask[]> {
456462
return (await UVdatApi.apiClient.get('/processing-tasks')).data;
457463
}

client/src/components/Map.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,8 @@ export default defineComponent({
237237
watch(
238238
MapStore.hoveredFeatures,
239239
() => {
240-
if (map.value && (MapStore.mapLayerFeatureGraphsVisible.value || MapStore.activeSideBarCard.value === 'searchableVectors')) {
240+
if (map.value
241+
&& (MapStore.mapLayerFeatureGraphsVisible.value || MapStore.activeSideBarCard.value === 'searchableVectors')) {
241242
updateSelected(map.value);
242243
}
243244
},

client/src/components/VectorFeatureSearch/Editor/VectorFeatureSearchEditor.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<!-- eslint-disable vue/max-len -->
12
<script lang="ts">
23
import {
34
Ref, computed, defineComponent, onMounted, ref,

client/src/components/VectorFeatureSearch/VectorFeatureSearch.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<!-- eslint-disable vue/max-len -->
12
<!-- eslint-disable vuejs-accessibility/mouse-events-have-key-events -->
23
<!-- eslint-disable vuejs-accessibility/mouse-events-have-key-events -->
34
<script lang="ts">

client/src/map/mapFilters.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import MapStore from '../MapStore';
1818

1919
const getLayerDefaultFilter = (type: AnnotationTypes, layer?: VectorMapLayer) => {
2020
let drawPoints = false;
21-
if (type === 'circle' && layer?.default_style.layers && layer.default_style.layers.line) {
21+
if (type === 'circle' && layer?.default_style?.layers && layer.default_style.layers.line) {
2222
if (layer.default_style.layers.line !== true) {
2323
drawPoints = !!layer.default_style.layers.line.drawPoints;
2424
}

client/src/map/mapVectorLayers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ const toggleVectorMapLayers = (map: maplibregl.Map) => {
293293
if (MapStore.visibleMapLayers.value.has(`${layer.type}_${layer.id}`)) {
294294
// eslint-disable-next-line @typescript-eslint/no-use-before-define
295295
updateVectorLayer(layer);
296-
if (layer?.default_style.searchableVectorFeatureData) {
296+
if (layer?.default_style?.searchableVectorFeatureData) {
297297
if (layer.default_style.searchableVectorFeatureData.display.autoOpenSideBar) {
298298
if (MapStore.activeSideBarCard.value !== 'searchableVectors') {
299299
MapStore.toggleContext('searchableVectors');

client/src/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -905,14 +905,14 @@ export interface SearchableVectorFeatureResponse {
905905
export interface DisplayConfiguration {
906906
enabled_ui: ('Scenarios' | 'Collections' | 'Datasets' | 'Metadata')[];
907907
default_tab: 'Scenarios' | 'Collections' | 'Datasets' | 'Metadata';
908-
default_displayed_layers: Array<{ type: AbstractMapLayer['type']; id: number; name: string }>;
908+
default_displayed_layers: Array<{ type: AbstractMapLayer['type']; id: number; dataset_id: number; name: string }>;
909909
}
910910

911911
export interface AbstractMapLayerListItem {
912912
id: number;
913913
name: string;
914914
type: AbstractMapLayer['type'];
915-
datset_id: number;
915+
dataset_id: number;
916916
file_item: { id: number, name: string }[];
917917
processing_tasks?: null | ProcessingTask[]
918918
}

client/src/views/Admin/DisplayAdmin.vue

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default defineComponent({
1919
onMounted(async () => {
2020
config.value = await UVdatApi.getDisplayConfiguration();
2121
layers.value = await UVdatApi.getMapLayerAll();
22-
selectedLayers.value = config.value.default_displayed_layers.map((item) => (`${item.type}_${item.id}`));
22+
selectedLayers.value = config.value.default_displayed_layers.map((item) => (`${item.type}_${item.id}_${item.dataset_id}`));
2323
});
2424
2525
watch(() => config.value?.enabled_ui, (newVal) => {
@@ -31,7 +31,7 @@ export default defineComponent({
3131
const availableLayers = computed(() => {
3232
if (layers.value) {
3333
return layers.value.map((item) => ({
34-
id: item.id, name: item.name, type: item.type, index: `${item.type}_${item.id}`,
34+
id: item.id, name: item.name, dataset_id: item.dataset_id, type: item.type, index: `${item.type}_${item.id}_${item.dataset_id}`,
3535
}));
3636
}
3737
return [];
@@ -44,7 +44,9 @@ export default defineComponent({
4444
selectedLayers.value.forEach((item) => {
4545
const data = availableLayers.value.find((layer) => layer.index === item);
4646
if (data) {
47-
config.value?.default_displayed_layers.push({ id: data.id, name: data.name, type: data.type });
47+
config.value?.default_displayed_layers.push({
48+
id: data.id, name: data.name, dataset_id: data.dataset_id, type: data.type,
49+
});
4850
}
4951
});
5052
await UVdatApi.updateDisplayConfiguration(config.value);
@@ -101,8 +103,8 @@ export default defineComponent({
101103
clearable
102104
closable-chips
103105
>
104-
<template #chip="{ item }">
105-
<v-chip>
106+
<template #chip="{ props, item }">
107+
<v-chip v-bind="props">
106108
{{ item.raw.name }}:{{ item.raw.type }}
107109
</v-chip>
108110
</template>

client/src/views/HomePage.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import Charts from '../components/Charts/Charts.vue';
1515
import MapLayerTableGraph from '../components/TabularData/MapLayerTableGraph.vue';
1616
import UVdatApi from '../api/UVDATApi';
1717
import VectorFeatureSearch from '../components/VectorFeatureSearch/VectorFeatureSearch.vue';
18+
// eslint-disable-next-line import/no-cycle
19+
import { toggleLayerSelection } from '../map/mapLayers';
1820
1921
export default defineComponent({
2022
components: {
@@ -46,7 +48,10 @@ export default defineComponent({
4648
}
4749
};
4850
49-
onMounted(() => MapStore.getDisplayConfiguration());
51+
onMounted(async () => {
52+
const layers = await MapStore.getDisplayConfiguration(true);
53+
layers.forEach((layer) => toggleLayerSelection(layer));
54+
});
5055
5156
watch(MapStore.userIsStaff, () => {
5257
if (!MapStore.userIsStaff.value) {

0 commit comments

Comments
 (0)