Skip to content

Commit

Permalink
improve visual style editor style and support for md5 comparison (#722)
Browse files Browse the repository at this point in the history
  • Loading branch information
allyoucanmap authored Jan 20, 2022
1 parent bbb9a12 commit 40e2d7e
Show file tree
Hide file tree
Showing 16 changed files with 112 additions and 267 deletions.
2 changes: 1 addition & 1 deletion geonode_mapstore_client/client/MapStore2
Submodule MapStore2 updated 287 files
18 changes: 0 additions & 18 deletions geonode_mapstore_client/client/js/actions/visualstyleeditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
*/

export const REQUEST_DATASET_AVAILABLE_STYLES = 'GEONODE:REQUEST_DATASET_AVAILABLE_STYLES';
export const CREATE_GEONODE_STYLE = 'GEONODE:CREATE_GEONODE_STYLE';
export const DELETE_GEONODE_STYLE = 'GEONODE:DELETE_GEONODE_STYLE';

export function requestDatasetAvailableStyles(layer, options) {
return {
Expand All @@ -17,19 +15,3 @@ export function requestDatasetAvailableStyles(layer, options) {
options
};
}

export function createGeoNodeStyle(title, options) {
return {
type: CREATE_GEONODE_STYLE,
title,
options
};
}

export function deleteGeoNodeStyle(styleName, options) {
return {
type: DELETE_GEONODE_STYLE,
styleName,
options
};
}
92 changes: 7 additions & 85 deletions geonode_mapstore_client/client/js/epics/visualstyleeditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,11 @@ import { STYLE_OWNER_NAME } from '@mapstore/framework/utils/StyleEditorUtils';
import StylesAPI from '@mapstore/framework/api/geoserver/Styles';
import {
styleServiceSelector,
getUpdatedLayer,
geometryTypeSelector
getUpdatedLayer
} from '@mapstore/framework/selectors/styleeditor';
import {
CREATE_GEONODE_STYLE,
DELETE_GEONODE_STYLE,
REQUEST_DATASET_AVAILABLE_STYLES
} from '@js/actions/visualstyleeditor';
import { saveDirectContent } from '@js/actions/gnsave';
import { REQUEST_DATASET_AVAILABLE_STYLES } from '@js/actions/visualstyleeditor';
import tinycolor from 'tinycolor2';
import { parseStyleName, parseMetadata } from '@js/utils/ResourceUtils';
import { parseStyleName } from '@js/utils/ResourceUtils';

/**
* @module epics/visualstyleeditor
Expand Down Expand Up @@ -76,10 +70,9 @@ function getGnStyleQueryParams(style, styleService) {
return StylesAPI.getStyleCodeByName({
baseUrl: styleService?.baseUrl,
styleName: parseStyleName(style)
}).then(updatedStyles => {
const { metadata = {}, code: updateStyleCode, format, languageVersion } = updatedStyles || {};
const metadataObj = parseMetadata(metadata);
return { msEditorType: metadataObj?.msEditorType, msStyleJSON: metadataObj?.msStyleJSON, code: updateStyleCode, format, languageVersion };
}).then(updatedStyle => {
const { metadata = {}, code: updateStyleCode, format, languageVersion } = updatedStyle || {};
return { msEditorType: metadata?.msEditorType, msStyleJSON: metadata?.msStyleJSON, code: updateStyleCode, format, languageVersion };
}).catch(() => ({ msEditorType, msStyleJSON, code}));
}

Expand All @@ -106,6 +99,7 @@ function getGeoNodeStyles({ layer, styleService }) {
format: (code && format) ? format : 'css',
styleName,
metadata,
options: { params: { raw: true } },
...((code && format) && { languageVersion })
})
.then(() => {
Expand Down Expand Up @@ -145,76 +139,6 @@ export const gnRequestDatasetAvailableStyles = (action$, store) =>
);
});

export const gnCreateStyle = (action$, store) =>
action$.ofType(CREATE_GEONODE_STYLE)
.switchMap((action) => {
const state = store.getState();
const styleService = action?.options?.styleService || styleServiceSelector(state);
const styleName = getStyleId({ name: action.title.toLowerCase().replace(/\W/g, '') });
const layer = action.layer || getUpdatedLayer(state);
const format = 'css';
const metadata = {
title: action.title,
description: '',
msStyleJSON: null,
msEditorType: 'visual',
gnLayerName: layer.name,
gnDatasetPk: layer?.extendedParams?.mapLayer?.dataset?.pk
};
const geometryType = geometryTypeSelector(state);
return Observable.defer(
() => StylesAPI.createStyle({
baseUrl: styleService?.baseUrl,
code: getBaseCSSStyle({ type: geometryType, title: action.title }),
format,
styleName,
metadata
})
)
.switchMap(() => {
return Observable.of(
updateNode(layer.id, 'layer', { availableStyles: [...layer.availableStyles, { format, metadata, name: styleName, title: action.title }] }),
updateAdditionalLayer(layer.id, STYLE_OWNER_NAME, 'override', {}),
updateSettingsParams({ style: styleName }, true),
updateStatus('edit'),
saveDirectContent()
);
});
});

export const gnDeleteStyle = (action$, store) =>
action$.ofType(DELETE_GEONODE_STYLE)
.switchMap((action) => {
const state = store.getState();
const styleService = action?.options?.styleService || styleServiceSelector(state);
const layer = action.layer || getUpdatedLayer(state);

const completeDeleteProcess = () => {
const newAvailableStyles = (layer.availableStyles || []).filter(({ name }) => name !== action.styleName);
return Observable.of(
updateNode(layer.id, 'layer', { availableStyles: newAvailableStyles }),
updateAdditionalLayer(layer.id, STYLE_OWNER_NAME, 'override', {}),
updateSettingsParams({ style: newAvailableStyles?.[0]?.name || '' }, true),
updateStatus('edit'),
saveDirectContent()
);
};

return Observable.defer(() =>
Observable.defer(() =>
StylesAPI.deleteStyle({
baseUrl: styleService?.baseUrl,
styleName: action.styleName
})
))
.switchMap(() => {
return completeDeleteProcess();
})
.catch(() => {
return completeDeleteProcess();
});
});

export const gnUpdateStyleInfoOnSave = (action$, store) =>
action$.ofType(UPDATE_STYLE_CODE)
.switchMap(() => {
Expand All @@ -224,8 +148,6 @@ export const gnUpdateStyleInfoOnSave = (action$, store) =>
});

export default {
gnCreateStyle,
gnDeleteStyle,
gnRequestDatasetAvailableStyles,
gnUpdateStyleInfoOnSave
};
Loading

0 comments on commit 40e2d7e

Please sign in to comment.