Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added table of content to open layer details in map view. #1661

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 34 additions & 0 deletions geonode_mapstore_client/client/js/actions/gnresource.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@

export const RESOURCE_LOADING = 'GEONODE:RESOURCE_LOADING';
export const SET_RESOURCE = 'GEONODE:SET_RESOURCE';
export const SET_LAYER_RESOURCE = 'GEONODE:SET_LAYER_RESOURCE';
export const RESOURCE_ERROR = 'GEONODE:RESOURCE_ERROR';
export const UPDATE_RESOURCE_PROPERTIES = 'GEONODE:UPDATE_RESOURCE_PROPERTIES';
export const UPDATE_LAYER_RESOURCE_PROPERTIES = 'GEONODE:UPDATE_LAYER_RESOURCE_PROPERTIES';
export const SET_RESOURCE_TYPE = 'GEONODE:SET_RESOURCE_TYPE';
export const SET_NEW_RESOURCE = 'GEONODE:SET_NEW_RESOURCE';
export const SET_RESOURCE_ID = 'GEONODE:SET_RESOURCE_ID';
Expand All @@ -23,6 +25,7 @@ export const SET_SELECTED_DATASET_PERMISSIONS = "GEONODE:SET_SELECTED_DATASET_PE
export const REQUEST_RESOURCE_CONFIG = 'GEONODE:REQUEST_RESOURCE_CONFIG';
export const REQUEST_NEW_RESOURCE_CONFIG = 'GEONODE:REQUEST_NEW_RESOURCE_CONFIG';
export const LOADING_RESOURCE_CONFIG = 'GEONODE:LOADING_RESOURCE_CONFIG';
export const LOADING_LAYER_RESOURCE_CONFIG = 'GEONODE:LOADING_LAYER_RESOURCE_CONFIG';
export const RESET_RESOURCE_STATE = 'GEONODE:RESET_RESOURCE_STATE';
export const RESOURCE_CONFIG_ERROR = 'GEONODE:RESOURCE_CONFIG_ERROR';
export const SET_RESOURCE_COMPACT_PERMISSIONS = 'GEONODE:SET_RESOURCE_COMPACT_PERMISSIONS';
Expand Down Expand Up @@ -67,6 +70,26 @@ export function setResource(data, pending) {
};
}

/**
* Restores resource from the state
* @param {object} data resource data object
* @param {object} pending declare if the request is still pending
*/
export function setLayerResource(data, pending) {
return {
type: SET_LAYER_RESOURCE,
data,
pending
};
}

export function loadingLayerResourceConfig(loading) {
return {
type: LOADING_LAYER_RESOURCE_CONFIG,
loading
};
}

/**
* Set the resource in the state
* @param {object} data resource data object
Expand Down Expand Up @@ -156,6 +179,17 @@ export function updateResourceProperties(properties) {
};
}

/**
* Update resource properties
* @param {object} properties resource properties to override
*/
export function updateLayerResourceProperties(properties) {
return {
type: UPDATE_LAYER_RESOURCE_PROPERTIES,
properties
};
}

/**
* Set the current resource as new
*/
Expand Down
6 changes: 3 additions & 3 deletions geonode_mapstore_client/client/js/epics/gnresource.js
Original file line number Diff line number Diff line change
Expand Up @@ -639,9 +639,9 @@ export const gnManageLinkedResource = (action$, store) =>
message: `gnviewer.linkedResource.message.success.${processType}`}
))
)).catch(() => Observable.of(errorNotification({
title: "gnviewer.linkedResource.title",
message: `gnviewer.linkedResource.message.failure.${processType}`
})))
title: "gnviewer.linkedResource.title",
message: `gnviewer.linkedResource.message.failure.${processType}`
})))
.let(wrapStartStop(
setControlProperty(processType, 'loading', true),
setControlProperty(processType, 'loading', false)
Expand Down
32 changes: 25 additions & 7 deletions geonode_mapstore_client/client/js/epics/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ import Rx from "rxjs";
import { setEditPermissionStyleEditor, INIT_STYLE_SERVICE } from "@mapstore/framework/actions/styleeditor";
import { getSelectedLayer, layersSelector } from "@mapstore/framework/selectors/layers";
import { getConfigProp } from "@mapstore/framework/utils/ConfigUtils";
import { getDatasetByName, getDatasetsByName } from '@js/api/geonode/v2';
import { getDatasetByName, getDatasetsByName, getResourceByTypeAndByPk } from '@js/api/geonode/v2';
import { MAP_CONFIG_LOADED } from '@mapstore/framework/actions/config';
import { setPermission } from '@mapstore/framework/actions/featuregrid';
import { SELECT_NODE, updateNode, ADD_LAYER } from '@mapstore/framework/actions/layers';
import { setSelectedDatasetPermissions } from '@js/actions/gnresource';
import { setSelectedDatasetPermissions, setLayerResource, loadingLayerResourceConfig } from '@js/actions/gnresource';
import { updateMapLayoutEpic as msUpdateMapLayoutEpic } from '@mapstore/framework/epics/maplayout';
import { wrapStartStop } from "@mapstore/framework/observables/epics";

// We need to include missing epics. The plugins that normally include this epic is not used.

Expand All @@ -37,15 +38,32 @@ export const gnCheckSelectedDatasetPermissions = (action$, { getState } = {}) =>
.switchMap(() => {
const state = getState() || {};
const layer = getSelectedLayer(state);
const layerResourceId = layer?.extendedParams?.pk;
const permissions = layer?.perms || [];
const canEditStyles = permissions.includes("change_dataset_style");
const canEdit = permissions.includes("change_dataset_data");
const actions = [
setPermission({canEdit}),
setEditPermissionStyleEditor(canEditStyles),
setSelectedDatasetPermissions(permissions)
];
if (layer && layerResourceId) {
return Rx.Observable.defer(() =>
getResourceByTypeAndByPk('dataset', layerResourceId)
.then((layerDataset) => layerDataset)
.catch(() => [])
).switchMap((layerDataset) =>
Rx.Observable.of(
setLayerResource(layerDataset),
...actions
)
).let(wrapStartStop(
loadingLayerResourceConfig(true),
loadingLayerResourceConfig(false)
));
}
return layer
? Rx.Observable.of(
setPermission({canEdit}),
setEditPermissionStyleEditor(canEditStyles),
setSelectedDatasetPermissions(permissions)
)
? Rx.Observable.of(...actions)
: Rx.Observable.of(
setPermission({canEdit: false}),
setEditPermissionStyleEditor(false),
Expand Down
45 changes: 45 additions & 0 deletions geonode_mapstore_client/client/js/epics/layerdetailViewer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2023, GeoSolutions Sas.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/

import { Observable } from 'rxjs';
import isEmpty from 'lodash/isEmpty';
import { getLinkedResourcesByPk } from '@js/api/geonode/v2';
import {
updateLayerResourceProperties,
SET_LAYER_RESOURCE
} from '@js/actions/gnresource';
import { getLayerResourceData } from '@js/selectors/resource';

/**
* Get linked resources for layer
*/
export const gnGetLayerLinkedResources = (action$, store) =>
action$.ofType(SET_LAYER_RESOURCE)
.filter((action) =>
!action.pending && action.data?.pk && isEmpty(getLayerResourceData(store.getState())?.linkedResources)
)
.switchMap((action) =>
Observable.defer(() =>
getLinkedResourcesByPk(action.data.pk)
.then((linkedResources) => {
const linkedTo = linkedResources.linked_to ?? [];
const linkedBy = linkedResources.linked_by ?? [];
return isEmpty(linkedTo) && isEmpty(linkedBy) ? {} : ({ linkedTo, linkedBy });
})
.catch(() => [])
).switchMap((linkedResources) =>
Observable.of(
updateLayerResourceProperties({linkedResources})
)
)
);


export default {
gnGetLayerLinkedResources
};