forked from geosolutions-it/geonode-mapstore-client
-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adapt style editor component to fit inside the dataset style editor p…
…age (#537)
- Loading branch information
1 parent
039764d
commit f0e977b
Showing
16 changed files
with
790 additions
and
32 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
geonode_mapstore_client/client/js/actions/visualstyleeditor.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright 2020, 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. | ||
*/ | ||
|
||
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 { | ||
type: REQUEST_DATASET_AVAILABLE_STYLES, | ||
layer, | ||
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 | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
geonode_mapstore_client/client/js/epics/visualstyleeditor.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* Copyright 2021, 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 { getDatasetByName } from '@js/api/geonode/v2'; | ||
import { updateNode } from '@mapstore/framework/actions/layers'; | ||
import { updateStatus } from '@mapstore/framework/actions/styleeditor'; | ||
import { setControlProperty } from '@mapstore/framework/actions/controls'; | ||
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 { | ||
CREATE_GEONODE_STYLE, | ||
DELETE_GEONODE_STYLE, | ||
REQUEST_DATASET_AVAILABLE_STYLES | ||
} from '@js/actions/visualstyleeditor'; | ||
|
||
export const gnRequestDatasetAvailableStyles = (action$, store) => | ||
action$.ofType(REQUEST_DATASET_AVAILABLE_STYLES) | ||
.switchMap((action) => { | ||
if (action?.layer?.availableStyles && !action?.options?.forceUpdate) { | ||
return Observable.of( | ||
setControlProperty('visualStyleEditor', 'enabled', true), | ||
updateAdditionalLayer(action.layer.id, STYLE_OWNER_NAME, 'override', {}), | ||
updateStatus('edit') | ||
); | ||
} | ||
const state = store.getState(); | ||
const styleService = action?.options?.styleService || styleServiceSelector(state); | ||
return Observable.concat( | ||
Observable.of(setControlProperty('visualStyleEditor', 'enabled', true)), | ||
Observable.defer(() => getDatasetByName(action?.layer?.name)) | ||
.switchMap((gnLayer) => { | ||
return Observable.defer(() => StylesAPI.getStylesInfo({ | ||
baseUrl: styleService?.baseUrl, | ||
styles: (gnLayer?.styles || []).map((style) => ({ | ||
title: style.sld_title, | ||
name: style.workspace ? `${style.workspace}:${style.name}` : style.name | ||
})) | ||
})) | ||
.switchMap((availableStyles) => { | ||
return Observable.of( | ||
updateNode(action.layer.id, 'layer', { availableStyles }), | ||
updateAdditionalLayer(action.layer.id, STYLE_OWNER_NAME, 'override', {}), | ||
updateStatus('edit') | ||
); | ||
}); | ||
}) | ||
); | ||
}); | ||
|
||
export const gnCreateStyle = (action$) => | ||
action$.ofType(CREATE_GEONODE_STYLE) | ||
.switchMap(() => { | ||
return Observable.empty(); | ||
/* | ||
const state = store.getState(); | ||
const styleService = action?.options?.styleService || styleServiceSelector(state); | ||
const editorMetadata = { | ||
msStyleJSON: null, | ||
msEditorType: 'visual' | ||
}; | ||
const metadata = { | ||
title: action.title, | ||
description: '', | ||
...editorMetadata | ||
}; | ||
return Observable.defer( | ||
() => StylesAPI.createStyle({ | ||
baseUrl: styleService?.baseUrl, | ||
code: '@mode \'Flat\'; @styleTitle \'' + action.title + '\'; \n* {\n\tfill: #ff0000;\n}\n', | ||
format: 'css', | ||
styleName: 'geonode:' + action.title.toLowerCase().replace(/\W/g, '') + '_' + Math.random(), | ||
metadata | ||
}) | ||
) | ||
.switchMap(() => { | ||
return Observable.empty(); | ||
}); | ||
*/ | ||
}); | ||
|
||
export const gnDeleteStyle = (action$) => | ||
action$.ofType(DELETE_GEONODE_STYLE) | ||
.switchMap(() => { | ||
return Observable.empty(); | ||
}); | ||
|
||
export default { | ||
gnCreateStyle, | ||
gnDeleteStyle, | ||
gnRequestDatasetAvailableStyles | ||
}; |
Oops, something went wrong.