Skip to content

Commit

Permalink
- Merge with "rest_api_v2_geonode_spa_homepage" branch
Browse files Browse the repository at this point in the history
  • Loading branch information
afabiani committed Dec 3, 2020
1 parent 1e19708 commit be6c15d
Show file tree
Hide file tree
Showing 57 changed files with 4,106 additions and 16,577 deletions.
11 changes: 0 additions & 11 deletions changelog.html

This file was deleted.

2 changes: 1 addition & 1 deletion geonode_mapstore_client/client/MapStore2
Submodule MapStore2 updated 190 files
85 changes: 85 additions & 0 deletions geonode_mapstore_client/client/home.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{% load static from staticfiles %}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,300;0,400;0,700;1,300;1,400;1,700&display=swap" rel="stylesheet">
<title>{{ SITE_NAME }}</title>
<link rel="shortcut icon" href="{% static 'geonode/img/favicon.ico' %}" />
<style>
.gn-main-loader-container {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
font-size: 14px;
flex-direction: column;
}
.gn-main-loader-content {
position: relative;
font-size: inherit;
}
.gn-main-loader {
border-radius: 50%;
width: 12em;
height: 12em;
box-sizing: border-box;
border: 1em solid rgba(119,119,119, 0.2);
border-left: 1em solid #777777;
-webkit-animation: gn-main-loader-animation 1.1s infinite linear;
animation: gn-main-loader-animation 1.1s infinite linear;
}
.gn-main-loader-text {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 1.5em;
text-align: center;
font-family: 'Montserrat', sans-serif;
}
@-webkit-keyframes gn-main-loader-animation {
0% {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
@keyframes gn-main-loader-animation {
0% {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
</style>
</head>
<body>
<script>
window.__GEONODE_PAGE_CONFIG__ = {
languageCode: '{{ LANGUAGE_CODE }}'
}
</script>
<div id="container">
<div class="gn-main-loader-container">
<div class="gn-main-loader-content">
<div class="gn-main-loader"></div>
<div class="gn-main-loader-text"></div>
</div>
</div>
</div>
<script id="gn-script" src="/static/mapstore/dist/gn-home.js"></script>
</body>
</html>
85 changes: 84 additions & 1 deletion geonode_mapstore_client/client/js/api/geonode/v1/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,89 @@ export const getResourceByPk = (pk) => {
.then(({ data }) => ({ pk: data.id, ...data }));
};

export const autocomplete = (params) => {
const { endpointAutocomplete = '/base/autocomplete_response' } = getConfigProp('geoNodeApi') || {};
return axios.get(endpointAutocomplete, { params })
.then(({ data }) => {
return {
suggestions: (data?.results || [])
.map(({ id, text }) => {
return {
id,
label: text,
value: text
};
})
};
});
};

export const getUserInfo = () => {
const { endpointV1 = '/api' } = getConfigProp('geoNodeApi') || {};
return axios.get(`${endpointV1}/o/v4/userinfo`)
.then(({ data }) => data);
};

export const getCategories = ({ q, ...params }) => {
const { endpointV1 = '/api' } = getConfigProp('geoNodeApi') || {};
return axios.get(`${endpointV1}/categories`, {
params: {
limit: 30,
...params,
identifier__icontains: q
}
})
.then(({ data }) => {
return data?.objects || [];
});
};

export const getKeywords = ({ q, ...params }) => {
const { endpointV1 = '/api' } = getConfigProp('geoNodeApi') || {};
return axios.get(`${endpointV1}/keywords`, {
params: {
limit: 30,
...params,
slug__icontains: q
}
})
.then(({ data }) => {
return data?.objects || [];
});
};

export const getRegions = ({ q, ...params }) => {
const { endpointV1 = '/api' } = getConfigProp('geoNodeApi') || {};
return axios.get(`${endpointV1}/regions`, {
params: {
limit: 30,
...params,
name__icontains: q
}
})
.then(({ data }) => {
return data?.objects || [];
});
};

export const getOwners = ({ q, ...params }) => {
const { endpointV1 = '/api' } = getConfigProp('geoNodeApi') || {};
return axios.get(`${endpointV1}/owners`, {
params: {
limit: 30,
...params,
username__icontains: q
}
})
.then(({ data }) => {
return data?.objects || [];
});
};

export default {
getResourceByPk
getResourceByPk,
getCategories,
getKeywords,
getRegions,
getOwners
};
130 changes: 98 additions & 32 deletions geonode_mapstore_client/client/js/api/geonode/v2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,32 @@ import {
setRequestOptions,
getRequestOptions
} from '@js/utils/APIUtils';
import mergeWith from 'lodash/mergeWith';
import isArray from 'lodash/isArray';
import isString from 'lodash/isString';
import castArray from 'lodash/castArray';
import { getUserInfo } from '@js/api/geonode/v1';
import { getConfigProp } from '@mapstore/framework/utils/ConfigUtils';

let endpoints = {
// default values
'base_resources': '/api/v2/base_resources',
'documents': '/api/v2/documents',
'layers': '/api/v2/layers',
'maps': '/api/v2/maps',
'geoapps': '/api/v2/geoapps',
'geostories': '/api/v2/geostories',
'documents': '/api/v2/documents'
'users': '/api/v2/users'
};

const RESOURCES = 'base_resources';
const DOCUMENTS = 'documents';
// const LAYERS = 'layers';
const MAPS = 'maps';
const GEOAPPS = 'geoapps';
const GEOSTORIES = 'geostories';
const USERS = 'users';
// const GROUPS = 'groups';
// const LAYERS = 'layers';
const MAPS = 'maps';
const DOCUMENTS = 'documents';
// const USERS = 'users';

const requestOptions = (name, requestFunc) => {
const options = getRequestOptions(name);
Expand All @@ -50,6 +56,26 @@ const requestOptions = (name, requestFunc) => {
return requestFunc(options);
};

// some fields such as search_fields does not support the array notation `key[]=value1&key[]=value2`
// this function will parse all values included array in the `key=value1&key=value2` format
function addQueryString(requestUrl, params) {
if (!params) {
return requestUrl;
}
const queryString = Object.keys(params)
.reduce((str, key, idx) => {
const start = idx === 0 ? '?' : '&';
const values = castArray(params[key]);
if (values.length > 1) {
return str + values.reduce((valStr, value, jdx) => {
return valStr + (jdx === 0 ? start : '&') + key + '=' + value;
}, '');
}
return str + start + key + '=' + values[0];
}, '');
return `${requestUrl}${queryString}`;
}

export const setEndpoints = (data) => {
endpoints = data;
};
Expand All @@ -62,21 +88,51 @@ export const getEndpoints = () => {
});
};

function mergeCustomQuery(params, customQuery) {
if (customQuery) {
return mergeWith(
{ ...params },
{ ...customQuery },
(objValue, srcValue) => {
if (isArray(objValue) && isArray(srcValue)) {
return [...objValue, ...srcValue];
}
if (isString(objValue) && isArray(srcValue)) {
return [objValue, ...srcValue];
}
if (isArray(objValue) && isString(srcValue)) {
return [...objValue, srcValue];
}
if (isString(objValue) && isString(srcValue)) {
return [ objValue, srcValue ];
}
return undefined; // eslint-disable-line consistent-return
}
);
}
return params;
}

export const getResources = ({
q,
pageSize = 20,
page = 1,
sort,
f,
...params
}) => {
return requestOptions(RESOURCES, () => axios.get(parseDevHostname(endpoints[RESOURCES]), {
const { query: customQuery } = (getConfigProp('menuFilters') || [])
.find(({ id }) => f === id) || {};

return requestOptions(RESOURCES, () => axios.get(parseDevHostname(
addQueryString(endpoints[RESOURCES], q && {
search: q,
search_fields: ['title', 'abstract']
})
), {
params: {
...params,
...mergeCustomQuery(params, customQuery),
...(sort && { sort: isArray(sort) ? sort : [ sort ]}),
...(q && {
search: q,
search_fields: ['title', 'abstract']
}),
page,
page_size: pageSize
}
Expand All @@ -92,26 +148,6 @@ export const getResources = ({
}));
};

// some fields such as search_fields does not support the array notation `key[]=value1&key[]=value2`
// this function will parse all values included array in the `key=value1&key=value2` format
function addQueryString(requestUrl, params) {
if (!params) {
return requestUrl;
}
const queryString = Object.keys(params)
.reduce((str, key, idx) => {
const start = idx === 0 ? '?' : '&';
const values = castArray(params[key]);
if (values.length > 1) {
return str + values.reduce((valStr, value, jdx) => {
return valStr + (jdx === 0 ? start : '&') + key + '=' + value;
}, '');
}
return str + start + key + '=' + values[0];
}, '');
return `${requestUrl}${queryString}`;
}

export const getMaps = ({
q,
pageSize = 20,
Expand Down Expand Up @@ -216,6 +252,33 @@ export const updateGeoStory = (pk, body) => {
.then(({ data }) => data.geostory);
};

export const getUserByPk = (pk) => {
return axios.get(parseDevHostname(`${endpoints[USERS]}/${pk}`))
.then(({ data }) => data.user);
};

export const getAccountInfo = () => {
return getUserInfo()
.then((info) => {
return getUserByPk(info.sub)
.then((user) => ({
...user,
info,
// TODO: remove when the href is provided by the server
hrefProfile: `/people/profile/${user.username}/`
}))
.catch(() => ({ info }));
})
.catch(() => null);
};

export const getConfiguration = (configUrl) => {
return axios.get(configUrl)
.then(({ data }) => {
return data;
});
};

export default {
getEndpoints,
getResources,
Expand All @@ -224,5 +287,8 @@ export default {
createGeoStory,
updateGeoStory,
getMaps,
getDocumentsByDocType
getDocumentsByDocType,
getUserByPk,
getAccountInfo,
getConfiguration
};
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ function ErrorFallback({
return (
<div
style={{
position: 'relative',
position: 'fixed',
top: 0,
left: 0,
width: '100%',
height: '100%',
display: 'flex',
Expand Down
Loading

0 comments on commit be6c15d

Please sign in to comment.