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

[Doumentation] Verify extensibility of Search plugin services configuration #438

Merged
merged 2 commits into from
Aug 19, 2021

Conversation

luorlandini
Copy link

in PR:

  • add documentation in the read me on how to extend the configuration for a plugin and link specific configuration of MapStore framework
  • verify configurability of Search plugin in a custom geonode-project

@luorlandini luorlandini added the enhancement New feature or request label Aug 18, 2021
@luorlandini luorlandini self-assigned this Aug 18, 2021
README.md Outdated
}
}

return localConfig
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Proposal:

  1. Please don't remove the previous example but we could add a list of snippet examples where this should be update plugin configuration
  2. Add also the example for enable plugin (copy from here https://github.com/GeoNode/geonode-mapstore-client/tree/3.3.x#customization-via-configurationstemplates)

Below a refactor to include the logic in a function


  • update plugin configuration
{% extends 'geonode-mapstore-client/_geonode_config.html' %}
{% block override_local_config %}
<script>
    window.__GEONODE_CONFIG__.overrideLocalConfig = function(localConfig, _) {
        /**
        * this is an example of function used to merge new plugin configuration in the default localConfig
        * if match the plugin name for the GeoNode section, extend or override it
        * if the plugin is new, add it to localConfig
        * Note: you can create your on function or manipulate the localConfig to get your expected final configuration
        * @param {object} config localConfig to update
        * @param {string[]} options.pages array of page keys to target
        * @param {string} options.name name of plugin
        * @param {object} options.cfg new cfg to apply
        */
        function mergePluginConfig(config, options) {
            var pages = options.pages;
            var pluginName = options.name;
            var pluginCfg = options.cfg;
            for (var j = 0; j < pages.length; j++ ) {
                var page = pages[j];
                var plugins = config.plugins[page];
                var merged = false;
                for (var i = 0; i < config.plugins[page].length; i++ ) {
                    var plugin = plugins[i];
                    if (plugin.name === pluginName) {
                        plugin.cfg = _.merge(plugin.cfg, pluginCfg);
                        merged = true;
                        break;
                    }
                }
                if (!merged) {
                    plugins.push({
                        name: pluginName,
                        cfg: pluginCfg
                    })
                }
            }
        }

        mergePluginConfig(localConfig, {
            pages: [ 'map_edit', 'map_view' ], 
            name: 'Search',
            cfg: {
                "searchOptions": {
                    "services": [
                        // { "type": "nominatim", "priority": 5 }, // default service
                        {
                            "type": "wfs",
                            "priority": 3,
                            "displayName": "${properties.propToDisplay}",
                            "subTitle": " (a subtitle for the results coming from this service [ can contain expressions like ${properties.propForSubtitle}])",
                            "options": {
                                "url": "{state('settings') && state('settings').geoserverUrl ? state('settings').geoserverUrl + '/wfs' : '/geoserver/wfs'}",
                                "typeName": "workspace:layer",
                                "queriableAttributes": [
                                    "attribute_to_query"
                                ],
                                "sortBy": "id",
                                "srsName": "EPSG:4326",
                                "maxFeatures": 20,
                                "blacklist": [
                                    "... an array of strings to exclude from  the final search filter "
                                ]
                            }
                        }
                    ]
                }
            }
        });
        return localConfig;
    };
</script>
{% endblock %}

@allyoucanmap allyoucanmap merged commit 9152f87 into GeoNode:master Aug 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants