Skip to content

Commit

Permalink
Implement msForceVisual style metadata property to force the switch t…
Browse files Browse the repository at this point in the history
…o visual mode (#724)
  • Loading branch information
allyoucanmap authored Jan 20, 2022
1 parent 15e9e14 commit e825651
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 11 deletions.
51 changes: 51 additions & 0 deletions geonode_mapstore_client/client/js/api/geonode/style/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright 2022, 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 {
getStyleCodeByName,
updateStyle
} from '@mapstore/framework/api/geoserver/Styles';

export function getStyleProperties({ baseUrl, styleName }) {
return import('md5').then((mod) => {
const md5 = mod.default;
return getStyleCodeByName({
baseUrl,
styleName
})
.then((style) => {
const {
msForceVisual,
...metadata
} = style?.metadata || {};
if (!msForceVisual || msForceVisual === '') {
return style;
}
// force use of visual style editor with msForceVisual
// and remove the true value
const updatedMetadata = {
...metadata,
msForceVisual: '',
msEditorType: 'visual',
msStyleJSON: '',
msMD5Hash: md5(style?.code)
};
return updateStyle({
...style,
baseUrl,
styleName,
metadata: updatedMetadata,
options: {
params: {
raw: true
}
}
}).then(() => ({ ...style, metadata: updatedMetadata }));
});
});
}
23 changes: 17 additions & 6 deletions geonode_mapstore_client/client/js/epics/gnresource.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ import {
import {
resourceToLayerConfig,
ResourceTypes,
toMapStoreMapConfig
toMapStoreMapConfig,
parseStyleName
} from '@js/utils/ResourceUtils';
import {
canAddResource,
Expand All @@ -70,7 +71,6 @@ import {
} from '@js/selectors/resource';
import { updateAdditionalLayer } from '@mapstore/framework/actions/additionallayers';
import { STYLE_OWNER_NAME } from '@mapstore/framework/utils/StyleEditorUtils';
import StylesAPI from '@mapstore/framework/api/geoserver/Styles';
import { styleServiceSelector } from '@mapstore/framework/selectors/styleeditor';
import { updateStyleService } from '@mapstore/framework/api/StyleEditor';
import { resizeMap } from '@mapstore/framework/actions/map';
Expand All @@ -79,6 +79,7 @@ import {
error as errorNotification,
success as successNotification
} from '@mapstore/framework/actions/notifications';
import { getStyleProperties } from '@js/api/geonode/style';

const resourceTypes = {
[ResourceTypes.DATASET]: {
Expand All @@ -99,11 +100,21 @@ const resourceTypes = {
return [mapConfig, gnLayer, newLayer];
}

return StylesAPI.getStylesInfo({
return getStyleProperties({
baseUrl: options?.styleService?.baseUrl,
styles: [newLayer.extendedParams.defaultStyle]
}).then((availableStyles) => {
return [mapConfig, gnLayer, { ...newLayer, availableStyles }];
styleName: parseStyleName(newLayer.extendedParams.defaultStyle)
}).then((updatedStyle) => {
return [
mapConfig,
gnLayer,
{
...newLayer,
availableStyles: [{
...updatedStyle,
...newLayer.extendedParams.defaultStyle
}]
}
];
});
})
)
Expand Down
19 changes: 14 additions & 5 deletions geonode_mapstore_client/client/js/epics/visualstyleeditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
import { REQUEST_DATASET_AVAILABLE_STYLES } from '@js/actions/visualstyleeditor';
import tinycolor from 'tinycolor2';
import { parseStyleName } from '@js/utils/ResourceUtils';
import { getStyleProperties } from '@js/api/geonode/style';

/**
* @module epics/visualstyleeditor
Expand Down Expand Up @@ -67,13 +68,21 @@ function getGnStyleQueryParams(style, styleService) {
return new Promise(resolve => resolve({ msStyleJSON, msEditorType, code }));
}

return StylesAPI.getStyleCodeByName({
return getStyleProperties({
baseUrl: styleService?.baseUrl,
styleName: parseStyleName(style)
}).then(updatedStyle => {
const { metadata = {}, code: updateStyleCode, format, languageVersion } = updatedStyle || {};
return { msEditorType: metadata?.msEditorType, msStyleJSON: metadata?.msStyleJSON, code: updateStyleCode, format, languageVersion };
}).catch(() => ({ msEditorType, msStyleJSON, code}));
})
.then(updatedStyle => {
const { metadata = {}, code: updateStyleCode, format, languageVersion } = updatedStyle || {};
return {
msEditorType: metadata?.msEditorType,
msStyleJSON: metadata?.msStyleJSON,
code: updateStyleCode,
format,
languageVersion
};
})
.catch(() => ({ msEditorType, msStyleJSON, code}));
}

function getGeoNodeStyles({ layer, styleService }) {
Expand Down
10 changes: 10 additions & 0 deletions geonode_mapstore_client/client/themes/geonode/less/ms-theme.less
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,13 @@ div#mapstore-globalspinner {
.ms-side-panel .ms-header {
box-shadow: none;
}

// missing close symbol in geocss code editor picker
.ms-inline-widget-container {
.btn.close:before {
content: "X";
}
.btn.close:hover {
color: #ffffff;
}
}

0 comments on commit e825651

Please sign in to comment.