Skip to content

Commit

Permalink
add create map button to dataset page (#549)
Browse files Browse the repository at this point in the history
  • Loading branch information
allyoucanmap authored Oct 26, 2021
1 parent 15f3949 commit c53f196
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 11 deletions.
36 changes: 31 additions & 5 deletions geonode_mapstore_client/client/js/epics/gnresource.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,33 @@ const resourceTypes = {
);
}),
newResourceObservable: (options) =>
Observable.defer(() => getNewMapConfiguration())
.switchMap((response) => {
Observable.defer(() => axios.all([
getNewMapConfiguration(),
...(options?.query?.['gn-dataset']
? [ getDatasetByPk(options.query['gn-dataset']) ]
: [])
]))
.switchMap(([ response, gnLayer ]) => {
const mapConfig = options.data || response;
const newLayer = gnLayer ? resourceToLayerConfig(gnLayer) : null;
const { minx, miny, maxx, maxy } = newLayer?.bbox?.bounds || {};
const extent = newLayer?.bbox?.bounds && [ minx, miny, maxx, maxy ];
return Observable.of(
configureMap(options.data || response),
configureMap(newLayer
? {
...mapConfig,
map: {
...mapConfig?.map,
layers: [
...(mapConfig?.map?.layers || []),
newLayer
]
}
}
: mapConfig),
...(extent
? [ setControlProperty('fitBounds', 'geometry', extent) ]
: []),
setControlProperty('toolbar', 'expanded', false)
);
})
Expand Down Expand Up @@ -244,7 +267,8 @@ export const gnViewerRequestNewResourceConfig = (action$, store) =>
action$.ofType(REQUEST_NEW_RESOURCE_CONFIG)
.switchMap((action) => {
const { newResourceObservable } = resourceTypes[action.resourceType] || {};
if (!canAddResource(store.getState())) {
const state = store.getState();
if (!canAddResource(state)) {
const formattedUrl = url.format({
...window.location,
pathname: '/account/login/',
Expand All @@ -256,6 +280,8 @@ export const gnViewerRequestNewResourceConfig = (action$, store) =>
return Observable.empty();
}

const { query = {} } = url.parse(state?.router?.location?.search, true) || {};

if (!newResourceObservable) {
return Observable.of(
...getResetActions(),
Expand All @@ -270,7 +296,7 @@ export const gnViewerRequestNewResourceConfig = (action$, store) =>
setNewResource(),
setResourceType(action.resourceType)
),
newResourceObservable({}),
newResourceObservable({ query }),
Observable.of(
setControlProperty('pendingChanges', 'value', null),
loadingResourceConfig(false)
Expand Down
3 changes: 2 additions & 1 deletion geonode_mapstore_client/client/js/hooks/useLazyPlugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function useLazyPlugins({
}) {

const [plugins, setPlugins] = useState({});
const [pending, setPending] = useState(false);
const [pending, setPending] = useState(true);

const pluginsKeys = pluginsConfig
.map(({ name }) => name + 'Plugin')
Expand Down Expand Up @@ -137,6 +137,7 @@ function useLazyPlugins({
});
} else {
setPlugins(storedPlugins);
setPending(false);
}
}, [ pluginsString ]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,12 @@
"type": "plugin",
"name": "Share"
},
{
"type": "link",
"href": "{'#/map/new?gn-dataset=' + (state('gnResourceData') || {}).pk}",
"labelId": "gnviewer.createMap",
"disableIf": "{!context.resourceHasPermission(state('gnResourceData'), 'change_resourcebase')}"
},
{
"type": "divider",
"authenticated": true
Expand Down Expand Up @@ -2098,6 +2104,9 @@
"measurementAnnotationEdit": false,
"geodesic": false
}
},
{
"name": "FitBounds"
}
],
"geostory_viewer": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@
"warningGeoLimitsSaveTitle": "Unvollständiger Speichervorgang",
"warningGeoLimitsSaveMessage": "Es war nicht möglich die neuen Geolimits zu aktualisieren",
"saveMapThumbnail": "Klicken Sie hier, um die Karte als Bild festzulegen",
"templates": "Vorlagen"
"templates": "Vorlagen",
"createMap": "Karte Erstellen"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@
"warningGeoLimitsSaveTitle": "Incomplete saving process",
"warningGeoLimitsSaveMessage": "It was not possible to update the new geo limits",
"saveMapThumbnail": "Click to set the map as an image",
"templates": "Templates"
"templates": "Templates",
"createMap": "Create Map"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@
"warningGeoLimitsSaveTitle": "Proceso de guardado incompleto",
"warningGeoLimitsSaveMessage": "No fue posible actualizar los nuevos límites geográficos",
"saveMapThumbnail": "Haga clic para configurar el mapa como una imagen",
"templates": "Plantillas"
"templates": "Plantillas",
"createMap": "Crear Mapa"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@
"warningGeoLimitsSaveTitle": "Processus de sauvegarde incomplet",
"warningGeoLimitsSaveMessage": "Il n'a pas été possible de mettre à jour les nouvelles limites géographiques",
"saveMapThumbnail": "Cliquez pour définir la carte comme une image",
"templates": "Modèles"
"templates": "Modèles",
"createMap": "Créer une Carte"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@
"warningGeoLimitsSaveTitle": "Processo di salvataggio incompleto",
"warningGeoLimitsSaveMessage": "Non è stato possibile aggiornare i nuovi limiti geografici",
"saveMapThumbnail": "Clicca per impostare la mappa come immagine",
"templates": "Modelli"
"templates": "Modelli",
"createMap": "Crea Mappa"
}
}
}

0 comments on commit c53f196

Please sign in to comment.