GEOLYTIX / xyz

An open source javascript framework for spatial data and application interfaces.
MIT License
87 stars 25 forks source link

Locations Delete #1290

Closed simon-leech closed 3 months ago

simon-leech commented 4 months ago

This PR addresses issue https://github.com/GEOLYTIX/xyz/issues/1289

It provides a locations_delete query. Which is similar to location_delete except it takes filter as a parameter to enable multiple locations to be deleted.

This must only be able to be called as layer query. Therefore, this query must have _.layer as a parameter or it will throw an error.


simon-leech commented 4 months ago

I have created a sample plugin here to test this query


mapp.ui.layers.panels.MultipleLocationsDelete = (layer) => {

    layer.MultipleLocationsDelete = mapp.utils.html.node`
      <button
        data-id="delete-locations"
          class="flat wide bold primary-colour"
          onclick=${deleteLocations}>${layer.MultipleLocationsDelete?.btn_label || mapp.dictionary.confirm_delete}`;

    async function deleteLocations() {
        // Run the query to delete the locations
        const locationDelete = await mapp.utils.xhr(`${mapp.host}/api/query?` +
            mapp.utils.paramString({
                template: 'locations_delete',
                locale: layer.mapview.locale.key,
                layer: layer.key,
                table: layer.table,
                filter: layer.filter?.current
            }));

        // If error, show the error message
        if (locationDelete instanceof Error) {
            alert('Error deleting locations')
        }

        // Reload the layer to show the changes
        layer.reload();

        // Alert the user that the locations have been deleted
        alert('Locations deleted')

    }

    return layer.MultipleLocationsDelete
}

To test it add this to a layer.

  "MultipleLocationsDelete": {
          "btn_label": "Delete Multiple Locations"
        },
sonarcloud[bot] commented 4 months ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud