Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Rex Dri
Rex Dri
Commits
a023e005
Unverified
Commit
a023e005
authored
Apr 25, 2020
by
Gautier D
Committed by
Florent Chehab
May 03, 2020
Browse files
refacto(frontend): removing city api call
parent
820a7491
Changes
10
Hide whitespace changes
Inline
Side-by-side
backend/backend_app/models/campus.py
View file @
a023e005
...
...
@@ -64,7 +64,7 @@ class CampusViewSet(BaseModelViewSet):
permission_classes
=
(
ReadOnly
,)
queryset
=
Campus
.
objects
.
all
()
# pylint: disable=E1101
serializer_class
=
CampusSerializer
end_point_route
=
"campuses"
end_point_route
=
"campuses
-deprecated
"
class
MainCampusViewSet
(
BaseModelViewSet
):
...
...
backend/backend_app/models/city.py
View file @
a023e005
...
...
@@ -39,4 +39,4 @@ class CityViewSet(BaseModelViewSet):
queryset
=
City
.
objects
.
all
()
# pylint: disable=E1101
serializer_class
=
CitySerializer
permission_classes
=
(
ReadOnly
,)
end_point_route
=
"cities"
end_point_route
=
"cities
-deprecated
"
frontend/src/components/app/App.jsx
View file @
a023e005
...
...
@@ -25,7 +25,7 @@ import PageAboutUnlinkedPartners from "../pages/PageAboutUnlinkedPartners";
import
PageLogout
from
"
../pages/PageLogout
"
;
import
withNetworkWrapper
,
{
NetWrapParam
}
from
"
../../hoc/withNetworkWrapper
"
;
import
UniversityService
from
"
../../services/data/UniversityService
"
;
import
CityService
from
"
../../services/data/CityService
"
;
//
import CityService from "../../services/data/CityService";
import
CountryService
from
"
../../services/data/CountryService
"
;
import
CurrencyService
from
"
../../services/data/CurrencyService
"
;
import
LanguageService
from
"
../../services/data/LanguageService
"
;
...
...
@@ -34,7 +34,7 @@ import useOnBeforeComponentMount from "../../hooks/useOnBeforeComponentMount";
const
SERVICES_TO_INITIALIZE
=
[
UniversityService
,
CityService
,
//
CityService,
CountryService
,
CurrencyService
,
LanguageService
,
...
...
@@ -104,9 +104,9 @@ App.propTypes = {};
export
default
compose
(
withNetworkWrapper
([
new
NetWrapParam
(
"
countries
"
,
"
all
"
),
new
NetWrapParam
(
"
cities
"
,
"
all
"
),
//
new NetWrapParam("cities", "all"),
new
NetWrapParam
(
"
universities
"
,
"
all
"
),
new
NetWrapParam
(
"
mainCampuses
"
,
"
all
"
),
//
new NetWrapParam("mainCampuses", "all"),
new
NetWrapParam
(
"
currencies
"
,
"
all
"
),
new
NetWrapParam
(
"
languages
"
,
"
all
"
),
new
NetWrapParam
(
"
serverModerationStatus
"
,
"
all
"
)
// not needed for server moderation status
...
...
frontend/src/components/map/BaseMap.jsx
View file @
a023e005
...
...
@@ -50,7 +50,6 @@ const ALL_MAPS = {};
* If an id is provided, the state of the map will be automatically saved and regenerated.
*/
function
BaseMap
({
id
,
universities
})
{
console
.
log
(
"
iciciciiojoij
"
,
universities
);
const
theme
=
useTheme
();
const
classes
=
useStyles
();
...
...
frontend/src/components/map/MainMap.jsx
View file @
a023e005
...
...
@@ -5,6 +5,7 @@ import BaseMap from "./BaseMap";
import
"
./map.scss
"
;
import
UniversityService
from
"
../../services/data/UniversityService
"
;
import
CountryService
from
"
../../services/data/CountryService
"
;
import
{
useSelectedUniversities
}
from
"
../../hooks/wrappers/useSelectedUniversities
"
;
const
MAIN_MAP_ID
=
uuid
();
...
...
@@ -27,7 +28,7 @@ function MainMap() {
univName
:
univ
.
name
,
univLogoUrl
:
univ
.
logo
,
cityName
:
univ
.
city
,
countryName
:
univ
.
country
,
countryName
:
CountryService
.
getCountryForCountryId
(
univ
.
country
).
name
,
main_campus_lat
:
parseFloat
(
univ
.
main_campus_lat
),
main_campus_lon
:
parseFloat
(
univ
.
main_campus_lon
),
univId
:
univ
.
id
,
...
...
frontend/src/components/university/UnivInfoProvider.jsx
View file @
a023e005
...
...
@@ -2,6 +2,7 @@ import React from "react";
import
PropTypes
from
"
prop-types
"
;
import
UnivContext
from
"
../../contexts/UnivContext
"
;
import
UniversityService
from
"
../../services/data/UniversityService
"
;
import
CountryService
from
"
../../services/data/CountryService
"
;
/**
* Univ info provider to pre-fetch some data and make it available down the tree very easily
...
...
@@ -9,21 +10,18 @@ import UniversityService from "../../services/data/UniversityService";
function
UnivInfoProvider
({
univId
,
children
})
{
const
univIdParsed
=
parseInt
(
univId
,
10
);
const
univ
=
UniversityService
.
getUniversityById
(
univIdParsed
);
const
{
city
,
country
}
=
UniversityService
.
getUnivCityAndCountry
(
univIdParsed
);
const
country
=
CountryService
.
getCountryForCountryId
(
univ
.
country
)
const
city
=
univ
.
city
const
countryId
=
country
.
id
;
const
cityId
=
city
.
id
;
return
(
<
UnivContext
.
Provider
value
=
{
{
univId
:
univIdParsed
,
countryId
,
univ
,
cityId
,
city
,
country
value
=
{
{
univId
:
univIdParsed
,
countryId
,
univ
,
city
,
country
}
}
>
{
children
}
...
...
frontend/src/components/university/modules/UniversityGeneral.jsx
View file @
a023e005
...
...
@@ -79,7 +79,7 @@ CoreComponent.propTypes = {
}).
isRequired
};
function
UniversityGeneral
({
university
,
c
ity
,
countr
y
})
{
function
UniversityGeneral
({
university
,
c
ountry
,
cit
y
})
{
return
(
<
ModuleWrapper
buildTitle
=
{
()
=>
"
Présentation
"
}
...
...
@@ -88,7 +88,7 @@ function UniversityGeneral({ university, city, country }) {
CoreComponent
=
{
props
=>
(
<
CoreComponent
{
...
props
}
cityName
=
{
city
.
name
}
cityName
=
{
city
}
countryName
=
{
country
.
name
}
/>
)
}
...
...
@@ -97,7 +97,7 @@ function UniversityGeneral({ university, city, country }) {
}
UniversityGeneral
.
propTypes
=
{
city
:
PropTypes
.
object
.
isRequired
,
city
:
PropTypes
.
string
.
isRequired
,
country
:
PropTypes
.
object
.
isRequired
,
university
:
PropTypes
.
object
.
isRequired
};
...
...
frontend/src/services/FilterService.js
View file @
a023e005
...
...
@@ -20,7 +20,7 @@ class FilterService {
universities
.
forEach
(
univ
=>
{
this
.
_universitiesCountriesCache
.
set
(
univ
.
id
,
Universit
yService
.
get
UnivCityAnd
Country
(
univ
.
id
).
country
Countr
yService
.
get
CountryFor
Country
Id
(
univ
.
country
)
);
});
...
...
frontend/src/services/data/CityService.js
View file @
a023e005
import
arrayOfInstancesToMap
from
"
../../utils/arrayOfInstancesToMap
"
;
import
{
getLatestApiReadData
}
from
"
../../hooks/useGlobalState
"
;
//
import arrayOfInstancesToMap from "../../utils/arrayOfInstancesToMap";
//
import { getLatestApiReadData } from "../../hooks/useGlobalState";
class
CityService
{
/**
* Stores the cities by its id
* @type {Map<number, object>}
* @private
*/
_citiesById
=
new
Map
();
//
class CityService {
//
/**
//
* Stores the cities by its id
//
* @type {Map<number, object>}
//
* @private
//
*/
//
_citiesById = new Map();
/**
* Must be called once before accessing other methods.
*/
initialize
()
{
const
cities
=
this
.
getCities
();
this
.
_citiesById
=
arrayOfInstancesToMap
(
cities
);
}
//
/**
//
* Must be called once before accessing other methods.
//
*/
//
initialize() {
//
const cities = this.getCities();
//
this._citiesById = arrayOfInstancesToMap(cities);
//
}
/**
* Get the city object for a city id
*
* @param {number} cityId
* @returns {Object}
*/
getCityForCityId
(
cityId
)
{
return
this
.
_citiesById
.
get
(
cityId
);
}
//
/**
//
* Get the city object for a city id
//
*
//
* @param {number} cityId
//
* @returns {Object}
//
*/
//
getCityForCityId(cityId) {
//
return this._citiesById.get(cityId);
//
}
getCities
()
{
return
getLatestApiReadData
(
"
cities-all
"
);
}
}
//
getCities() {
//
return getLatestApiReadData("cities-all");
//
}
//
}
export
default
new
CityService
();
//
export default new CityService();
frontend/src/services/data/UniversityService.js
View file @
a023e005
import
CityService
from
"
./CityService
"
;
import
CountryService
from
"
./CountryService
"
;
//
import CityService from "./CityService";
//
import CountryService from "./CountryService";
import
arrayOfInstancesToMap
from
"
../../utils/arrayOfInstancesToMap
"
;
import
{
getLatestApiReadData
}
from
"
../../hooks/useGlobalState
"
;
...
...
@@ -11,12 +11,7 @@ class UniversityService {
*/
_universitiesById
=
new
Map
();
/**
* Stores the mainCampuses by university id for quick join
* @type {Map<number, object>}
* @private
*/
_mainCampusesByUnivId
=
new
Map
();
/**
* @private
...
...
@@ -31,12 +26,6 @@ class UniversityService {
const
universities
=
this
.
getUniversities
();
this
.
_universitiesById
=
arrayOfInstancesToMap
(
universities
);
const
mainCampuses
=
this
.
getMainCampuses
();
mainCampuses
.
forEach
(
campus
=>
{
this
.
_mainCampusesByUnivId
.
set
(
campus
.
university
,
campus
);
});
this
.
_options
=
universities
.
map
(
el
=>
({
value
:
el
.
id
,
label
:
el
.
name
,
...
...
@@ -56,14 +45,6 @@ class UniversityService {
return
this
.
_options
;
}
/**
* Get the full list of main campuses in the app
* @returns {array<Object>}
*/
getMainCampuses
()
{
return
getLatestApiReadData
(
"
mainCampuses-all
"
);
}
/**
* @param {number} univId
* @returns {Object}
...
...
@@ -81,33 +62,6 @@ class UniversityService {
return
this
.
_universitiesById
.
has
(
univId
);
}
/**
* Get the campus object associated with the university given its id.
*
* @param {number} univId
* @returns {Object}
*/
getCampusForUnivId
(
univId
)
{
return
this
.
_mainCampusesByUnivId
.
get
(
univId
);
}
/**
* Function to get the city and the country of a university given a university id
*
* @param {number} univId
* @returns {object} Object with city and country instance of the university (main campus)
*/
getUnivCityAndCountry
(
univId
)
{
const
univ
=
this
.
getUniversityById
(
univId
);
const
city
=
univ
.
city
;
const
country
=
univ
.
country
;
return
{
city
,
country
};
}
/**
*
* @param {number} univId
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment