Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Genesys PGR
Genesys Website
Commits
83aa6264
Commit
83aa6264
authored
Oct 03, 2018
by
Matija Obreza
Browse files
Refactored code to get rid of wrappers to access_token
parent
e45b5a45
Changes
34
Hide whitespace changes
Inline
Side-by-side
entrypoints/client.tsx
View file @
83aa6264
...
...
@@ -18,6 +18,7 @@ import getDir from '../server/middleware/detectDirection';
// JSS & MUI
import
{
MuiThemeProvider
}
from
'
@material-ui/core/styles
'
;
import
theme
from
'
ui/theme
'
;
import
{
configureBackendApi
}
from
'
utilities/requestUtils
'
;
declare
const
__PRELOADED_STATE__
:
any
;
...
...
@@ -33,6 +34,9 @@ const detectedLang = initialLanguage ? initialLanguage : detectLocaleFromPath(vi
const
historyOptions
=
{
basename
:
detectedLang
!==
'
en
'
?
`
${
virtualPath
}
/
${
detectedLang
}
`
:
`
${
virtualPath
}
`
};
const
history
=
createHistory
(
historyOptions
);
// Configure axios for client
configureBackendApi
({
apiUrl
:
`
${
virtualPath
}
/proxy`
});
const
initialState
=
__PRELOADED_STATE__
===
undefined
?
{}
:
__PRELOADED_STATE__
;
const
store
=
composeEnhancers
(
applyMiddleware
(
thunk
,
routerMiddleware
(
history
)))(
createStore
)(
rootReducer
,
initialState
);
...
...
server/index.ts
View file @
83aa6264
import
{
configureBackendApi
}
from
'
utilities/requestUtils
'
;
/**
* Start the frontend server
*/
le
t
server
=
require
(
'
./server
'
).
default
;
cons
t
server
=
require
(
'
./server
'
).
default
;
const
PORT
=
process
.
env
.
PORT
||
3000
;
// Configure axios for server
configureBackendApi
({
apiUrl
:
`http://localhost:
${
PORT
}
/proxy`
});
// start server on PORT
server
.
listen
(
PORT
,
()
=>
{
console
.
log
(
'
HTTP server listening on:
'
+
PORT
);
...
...
server/middleware/prerenderer.tsx
View file @
83aa6264
...
...
@@ -26,7 +26,7 @@ import detectLocaleFromPath from './detectLocaleFromPath';
import
getDir
from
'
./detectDirection
'
;
import
config
from
'
../config
'
;
import
checkAuthToken
from
'
./checkAuthToken
'
;
import
{
configure
}
from
'
actions/applicationConfig
'
;
import
{
configure
}
from
'
actions/applicationConfig
'
;
const
prerenderer
=
(
html
,
errHtml
)
=>
(
req
,
res
)
=>
{
console
.
log
(
'
Init prerenderer, request url:
'
,
req
.
url
);
...
...
@@ -36,6 +36,7 @@ const prerenderer = (html, errHtml) => (req, res) => {
const
store
=
createStore
(
rootReducer
,
{}
as
any
,
applyMiddleware
(
thunk
,
routerMiddleware
(
createMemoryHistory
)));
// Only send public data to client
store
.
dispatch
(
configure
({
frontendPath
:
config
.
frontendPath
,
apiUrl
:
config
.
apiUrl
,
googleClientId
:
config
.
googleClientId
}));
console
.
log
(
`Processing request`
,
req
.
_parsedOriginalUrl
);
const
pathname
=
req
.
_parsedOriginalUrl
.
pathname
;
const
search
=
req
.
_parsedOriginalUrl
.
search
;
...
...
src/accessions/actions/public.ts
View file @
83aa6264
...
...
@@ -8,8 +8,9 @@ import AccessionFilter from 'model/AccessionFilter';
import
AccessionDetails
from
'
model/AccessionDetails
'
;
import
AccessionMapInfo
from
'
model/AccessionMapInfo
'
;
import
{
list
as
listAccessions
,
getDetailsByUuid
,
getDetailsByDoi
,
listOverview
as
listAccessionOverview
,
toUUID
,
mapInfo
}
from
'
service/genesys/actions/accessionService
'
;
import
{
RECEIVE_ACCESSIONS
,
RECEIVE_ACCESSION
,
RECEIVE_ACCESSION_OVERVIEW
,
APPEND_ACCESSIONS
,
RECEIVE_ACCESSION_MAPINFO
}
from
'
accessions/constants
'
;
import
AccessionService
from
'
service/genesys/AccessionService
'
;
import
{
AccessionIdentifier
}
from
'
model/dataset.model
'
;
const
receiveAccessions
=
(
paged
:
FilteredPage
<
Accession
>
,
error
=
null
)
=>
({
type
:
RECEIVE_ACCESSIONS
,
...
...
@@ -36,7 +37,14 @@ const receiveAccession = (accession: AccessionDetails, error = null) => ({
payload
:
{
accession
,
error
},
});
export
{
listAccessions
as
listAccessionsPromise
,
toUUID
as
toUUIDPromise
};
export
const
toUUIDPromise
=
(
identifiers
:
AccessionIdentifier
[])
=>
(
dispatch
,
getState
):
Promise
<
Map
<
string
,
AccessionIdentifier
>>
=>
{
return
AccessionService
.
toUUID
(
identifiers
);
};
export
const
listAccessionsPromise
=
(
filter
:
string
|
AccessionFilter
,
page
:
IPageRequest
)
=>
(
dispatch
,
getState
):
Promise
<
FilteredPage
<
Accession
>>
=>
{
return
AccessionService
.
list
(
filter
,
page
);
};
export
const
updateRoute
=
(
paged
:
FilteredPage
<
Accession
>
,
path
:
string
=
'
/a
'
)
=>
(
dispatch
)
=>
{
const
qs
=
{
...
...
@@ -53,7 +61,7 @@ export const updateRoute2 = (filterCode: string, path: string = '/a', qs?: any)
export
const
applyFilters
=
(
filters
:
string
|
AccessionFilter
,
page
:
IPageRequest
=
{
page
:
0
})
=>
(
dispatch
)
=>
{
console
.
log
(
'
Applying new filter
'
,
filters
);
return
dispatch
(
listAccessions
(
filters
,
page
)
)
return
AccessionService
.
list
(
filters
,
page
)
.
then
((
paged
)
=>
{
dispatch
(
receiveAccessions
(
paged
));
dispatch
(
updateRoute
(
paged
));
...
...
@@ -65,7 +73,7 @@ export const applyFilters = (filters: string | AccessionFilter, page: IPageReque
export
const
applyOverviewFilters
=
(
filters
:
string
|
AccessionFilter
,
page
:
IPageRequest
=
{
page
:
0
})
=>
(
dispatch
)
=>
{
console
.
log
(
'
Applying new filter
'
,
filters
);
return
dispatch
(
listAccession
Overview
(
filters
)
)
return
AccessionService
.
list
Overview
(
filters
)
.
then
((
overview
)
=>
{
dispatch
(
receiveAccessionOverview
(
overview
));
dispatch
(
updateRoute2
(
overview
.
filterCode
,
'
/a/overview
'
));
...
...
@@ -76,7 +84,7 @@ export const applyOverviewFilters = (filters: string | AccessionFilter, page: IP
};
export
const
loadAccessionsOverviewPage
=
(
filterCode
:
string
)
=>
(
dispatch
)
=>
{
return
dispatch
(
listAccession
Overview
(
filterCode
)
)
return
AccessionService
.
list
Overview
(
filterCode
)
.
then
((
paged
)
=>
{
dispatch
(
receiveAccessionOverview
(
paged
));
}).
catch
((
error
)
=>
{
...
...
@@ -86,7 +94,7 @@ export const loadAccessionsOverviewPage = (filterCode: string) => (dispatch) =>
};
export
const
loadAccessionsMapInfo
=
(
filters
:
string
|
AccessionFilter
)
=>
(
dispatch
)
=>
{
return
dispatch
(
mapInfo
(
filters
)
)
return
AccessionService
.
mapInfo
(
filters
)
.
then
((
mapInfo
:
AccessionMapInfo
)
=>
{
dispatch
(
receiveAccessionMapInfo
(
mapInfo
));
dispatch
(
updateRoute2
(
mapInfo
.
filterCode
,
'
/a/map
'
));
...
...
@@ -98,7 +106,7 @@ export const loadAccessionsMapInfo = (filters: string | AccessionFilter) => (dis
export
const
loadAccessionsPage
=
(
page
:
IPageRequest
)
=>
(
dispatch
,
getState
)
=>
{
const
filterCode
=
getState
().
accessions
.
public
.
paged
.
filterCode
;
return
dispatch
(
listAccessions
(
filterCode
,
page
)
)
return
AccessionService
.
list
(
filterCode
,
page
)
.
then
((
paged
)
=>
{
if
(
paged
.
number
===
0
)
{
dispatch
(
receiveAccessions
(
paged
));
...
...
@@ -113,10 +121,10 @@ export const loadAccessionsPage = (page: IPageRequest) => (dispatch, getState) =
};
export
const
loadAccession
=
({
uuid
,
doi
}:
{
uuid
?:
string
,
doi
?:
string
})
=>
(
dispatch
)
=>
{
const
loader
=
doi
?
getDetailsByDoi
:
getDetailsByUuid
;
const
loader
=
doi
?
AccessionService
.
getDetailsByDoi
:
AccessionService
.
getDetailsByUuid
;
const
lookup
=
doi
?
doi
:
uuid
;
return
dispatch
(
loader
(
lookup
)
)
return
loader
(
lookup
)
.
then
((
accession
)
=>
{
dispatch
(
receiveAccession
(
accession
));
}).
catch
((
error
)
=>
{
...
...
@@ -126,7 +134,7 @@ export const loadAccession = ({ uuid, doi }: { uuid?: string, doi?: string }) =>
};
export
const
overviewAccessions
=
(
filterCode
:
string
)
=>
(
dispatch
)
=>
{
return
dispatch
(
listAccession
Overview
(
filterCode
)
)
return
AccessionService
.
list
Overview
(
filterCode
)
.
then
((
overview
)
=>
{
dispatch
(
receiveAccessionOverview
(
overview
));
}).
catch
((
error
)
=>
{
...
...
src/actions/login.ts
View file @
83aa6264
...
...
@@ -5,6 +5,7 @@ import { clearCookies, saveCookies } from 'utilities';
import
{
ROLE_CLIENT
}
from
'
constants/userRoles
'
;
import
{
log
}
from
'
utilities/debug
'
;
import
{
loginUser
}
from
'
user/actions/public
'
;
import
{
configureBackendApi
}
from
'
utilities/requestUtils
'
;
export
function
checkAccessTokens
(
dispatch
)
{
const
cookieToken
:
string
=
typeof
window
!==
'
undefined
'
&&
cookies
.
get
(
'
access_token
'
);
...
...
@@ -45,6 +46,8 @@ function loginAppRequest() {
}
function
loginApp
(
d
)
{
// console.log('Login app', d);
configureBackendApi
({
accessToken
:
d
.
access_token
});
return
{
type
:
Constants
.
LOGIN_APP
,
authorities
:
[
ROLE_CLIENT
],
...
...
src/actions/permission.ts
View file @
83aa6264
...
...
@@ -4,7 +4,7 @@ import {SidPermissions} from 'model/acl.model';
export
const
permissions
=
(
clazz
:
string
,
id
:
number
)
=>
(
dispatch
,
getState
)
=>
{
return
PermissionService
.
permissions
(
getState
().
login
.
access_token
,
clazz
,
id
)
return
PermissionService
.
permissions
(
clazz
,
id
)
.
catch
((
error
)
=>
{
log
(
'
Error
'
,
error
);
});
...
...
@@ -12,7 +12,7 @@ export const permissions = (clazz: string, id: number) => (dispatch, getState) =
export
const
addPermission
=
(
clazz
:
string
,
id
:
number
,
sidPermissions
:
SidPermissions
)
=>
(
dispatch
,
getState
)
=>
{
return
PermissionService
.
addPermission
(
getState
().
login
.
access_token
,
clazz
,
id
,
sidPermissions
)
return
PermissionService
.
addPermission
(
clazz
,
id
,
sidPermissions
)
.
catch
((
error
)
=>
{
log
(
'
Error
'
,
error
);
});
...
...
@@ -20,7 +20,7 @@ export const addPermission = (clazz: string, id: number, sidPermissions: SidPerm
export
const
autocomplete
=
(
term
:
string
)
=>
(
dispatch
,
getState
)
=>
{
return
PermissionService
.
autocomplete
(
getState
().
login
.
access_token
,
term
)
return
PermissionService
.
autocomplete
(
term
)
.
catch
((
error
)
=>
{
log
(
'
Error
'
,
error
);
});
...
...
src/actions/serverInfo.ts
View file @
83aa6264
...
...
@@ -4,9 +4,7 @@ import {InfoService} from 'service/InfoService';
import
ServerInfo
from
'
model/serverinfo.model
'
;
export
const
serverInfoRequest
=
()
=>
(
dispatch
,
getState
):
Promise
<
ServerInfo
>
=>
{
const
token
=
getState
().
login
.
access_token
;
return
InfoService
.
getServerInfo
(
token
)
return
InfoService
.
getServerInfo
()
.
then
((
data
)
=>
dispatch
(
getServerInfo
(
data
)))
.
catch
((
error
)
=>
log
(
'
Error
'
,
error
));
};
...
...
src/constants/apiURLS.ts
View file @
83aa6264
const
origin
=
typeof
window
!==
'
undefined
'
?
// if we're on the client
window
.
document
.
baseURI
.
replace
(
window
.
location
.
origin
,
''
).
replace
(
/
\/
$/
,
''
)
// or on the server
:
'
http://localhost:3000
'
;
export
const
API_ROOT
=
`
${
origin
}
/proxy`
;
export
const
API_ROOT
=
''
;
export
const
API_BASE_URL
=
`
${
API_ROOT
}
/api/v0`
;
export
const
APIv1_BASE_URL
=
`
${
API_ROOT
}
/api/v1`
;
export
const
SERVER_INFO_URL
=
`
${
API_ROOT
}
/api/v1/info/version`
;
export
const
LOGIN_URL
=
`
${
API_ROOT
}
/oauth/token`
;
export
const
LOGOUT_URL
=
`
${
API_BASE_URL
}
/me/logout`
;
export
const
GET_USER_PROFILE_URL
=
`
${
API_BASE_URL
}
/me/profile`
;
export
const
CHANGE_USER_PASSWORD_URL
=
`
${
API_BASE_URL
}
/me/password`
;
export
const
CHECK_TOKEN_URL
=
`
${
API_ROOT
}
/oauth/check_token`
;
export
const
VERIFY_GOOGLE_TOKEN_URL
=
`
${
API_ROOT
}
/google/verify-token`
;
src/crop/actions/public.ts
View file @
83aa6264
...
...
@@ -17,7 +17,7 @@ export const loadCrops = (forceReload: boolean = false) => (dispatch, getState)
const
isDataStale
=
Date
.
now
()
-
timeSinceLastFetch
>
LOAD_CROPS_CACHE_IDLE
;
if
(
isDataStale
||
forceReload
)
{
return
CropService
.
listCrops
(
getState
().
login
.
access_token
)
return
CropService
.
listCrops
()
.
then
((
list
)
=>
{
dispatch
(
receiveCrops
(
list
));
})
...
...
@@ -29,7 +29,7 @@ export const loadCrops = (forceReload: boolean = false) => (dispatch, getState)
export
const
saveCrop
=
(
crop
:
Crop
)
=>
(
dispatch
,
getState
)
=>
{
return
CropService
.
saveCrop
(
getState
().
login
.
access_token
,
crop
)
return
CropService
.
saveCrop
(
crop
)
.
then
(()
=>
{
dispatch
(
loadCrops
(
true
));
}).
catch
((
error
)
=>
{
...
...
@@ -38,7 +38,7 @@ export const saveCrop = (crop: Crop) => (dispatch, getState) => {
};
export
const
deleteCrop
=
(
crop
:
Crop
)
=>
(
dispatch
,
getState
)
=>
{
return
CropService
.
deleteCrop
(
getState
().
login
.
access_token
,
crop
.
shortName
)
return
CropService
.
deleteCrop
(
crop
.
shortName
)
.
then
(()
=>
{
dispatch
(
loadCrops
(
true
));
})
...
...
src/institutes/actions/dashboard.ts
View file @
83aa6264
// Actions
import
{
get
,
list
as
listInstitutes
}
from
'
service/genesys/actions/instituteService
'
;
// Constants
import
{
DASHBOARD_APPEND_INSTITUTES
,
DASHBOARD_RECEIVE_INSTITUTE
,
DASHBOARD_RECEIVE_INSTITUTES
}
from
'
institutes/constants
'
;
...
...
@@ -7,6 +5,7 @@ import {DASHBOARD_APPEND_INSTITUTES, DASHBOARD_RECEIVE_INSTITUTE, DASHBOARD_RECE
// Model
import
FilteredPage
,
{
IPageRequest
}
from
'
model/FilteredPage
'
;
import
FaoInstitute
from
'
model/FaoInstitute
'
;
import
InstituteService
from
'
service/genesys/InstituteService
'
;
const
receiveInstitutes
=
(
paged
:
FilteredPage
<
FaoInstitute
>
,
error
=
null
)
=>
({
type
:
DASHBOARD_RECEIVE_INSTITUTES
,
...
...
@@ -25,7 +24,7 @@ const receiveInstitute = (institute: FaoInstitute, error = null) => ({
export
const
loadInstitutesPage
=
(
page
:
IPageRequest
)
=>
(
dispatch
,
getState
)
=>
{
const
filterCode
=
getState
().
institutes
.
paged
.
filterCode
;
return
dispatch
(
listInstitutes
(
filterCode
,
page
)
)
return
InstituteService
.
list
(
filterCode
,
page
)
.
then
((
paged
)
=>
{
if
(
paged
.
number
===
0
)
{
dispatch
(
receiveInstitutes
(
paged
));
...
...
@@ -39,7 +38,7 @@ export const loadInstitutesPage = (page: IPageRequest) => (dispatch, getState) =
};
export
const
loadInstitute
=
(
code
:
string
)
=>
(
dispatch
)
=>
{
return
dispatch
(
get
(
code
)
)
return
InstituteService
.
get
(
code
)
.
then
((
institute
)
=>
{
dispatch
(
receiveInstitute
(
institute
));
}).
catch
((
error
)
=>
{
...
...
src/institutes/actions/public.ts
View file @
83aa6264
import
{
list
as
listInstitutes
,
get
}
from
'
service/genesys/actions/instituteService
'
;
import
navigateTo
from
'
actions/navigation
'
;
import
{
APPEND_INSTITUTES
,
RECEIVE_INSTITUTE
,
RECEIVE_INSTITUTES
}
from
'
institutes/constants
'
;
...
...
@@ -6,6 +5,7 @@ import {APPEND_INSTITUTES, RECEIVE_INSTITUTE, RECEIVE_INSTITUTES} from 'institut
import
FaoInstitute
from
'
model/FaoInstitute
'
;
import
FaoInstituteFilter
from
'
model/FaoInstituteFilter
'
;
import
FilteredPage
,
{
IPageRequest
}
from
'
model/FilteredPage
'
;
import
InstituteService
from
'
service/genesys/InstituteService
'
;
const
receiveInstitutes
=
(
paged
:
FilteredPage
<
FaoInstitute
>
,
error
=
null
)
=>
({
type
:
RECEIVE_INSTITUTES
,
...
...
@@ -30,12 +30,13 @@ export const updateRoute = (paged: FilteredPage<FaoInstitute>) => (dispatch) =>
dispatch
(
navigateTo
(
paged
.
filterCode
?
`/wiews/
${
paged
.
filterCode
}
`
:
'
/wiews
'
,
qs
));
};
export
{
listInstitutes
as
listInstitutesPromise
};
export
const
listInstitutesPromise
=
(
filter
:
string
|
FaoInstituteFilter
,
page
:
IPageRequest
)
=>
(
dispatch
,
getState
):
Promise
<
FilteredPage
<
FaoInstitute
>>
=>
{
return
InstituteService
.
list
(
filter
,
page
);
};
export
const
applyFilters
=
(
filters
:
string
|
FaoInstituteFilter
,
page
:
IPageRequest
=
{
page
:
0
})
=>
(
dispatch
)
=>
{
console
.
log
(
'
Applying new filter
'
,
filters
);
return
dispatch
(
listInstitutes
(
filters
,
page
)
)
return
InstituteService
.
list
(
filters
,
page
)
.
then
((
paged
)
=>
{
dispatch
(
receiveInstitutes
(
paged
));
dispatch
(
updateRoute
(
paged
));
...
...
@@ -47,7 +48,7 @@ export const applyFilters = (filters: string | FaoInstituteFilter, page: IPageRe
export
const
loadInstitutesPage
=
(
page
:
IPageRequest
)
=>
(
dispatch
,
getState
)
=>
{
const
filterCode
=
getState
().
institutes
.
paged
.
filterCode
;
return
dispatch
(
listInstitutes
(
filterCode
,
page
)
)
return
InstituteService
.
list
(
filterCode
,
page
)
.
then
((
paged
)
=>
{
if
(
paged
.
number
===
0
)
{
dispatch
(
receiveInstitutes
(
paged
));
...
...
@@ -62,7 +63,7 @@ export const loadInstitutesPage = (page: IPageRequest) => (dispatch, getState) =
};
export
const
loadInstitute
=
(
code
:
string
)
=>
(
dispatch
)
=>
{
return
dispatch
(
get
(
code
)
)
return
InstituteService
.
get
(
code
)
.
then
((
institute
)
=>
{
dispatch
(
receiveInstitute
(
institute
));
}).
catch
((
error
)
=>
{
...
...
src/repository/actions/admin.ts
View file @
83aa6264
...
...
@@ -29,7 +29,7 @@ const receiveGallery = (gallery: ImageGallery, error = null) => ({
// Get folder details
export
const
getFolder
=
(
path
:
string
=
'
/
'
)
=>
(
dispatch
,
getState
)
=>
{
return
RepositoryService
.
getFolder
(
getState
().
login
.
access_token
,
normalize
(
path
))
return
RepositoryService
.
getFolder
(
normalize
(
path
))
.
then
((
folder
:
FolderDetails
)
=>
{
dispatch
(
receiveFolder
(
folder
));
})
...
...
@@ -41,7 +41,7 @@ export const getFolder = (path: string = '/') => (dispatch, getState) => {
// Get folder details
export
const
deleteFolder
=
(
path
:
string
)
=>
(
dispatch
,
getState
)
=>
{
return
RepositoryService
.
deleteFolder
(
getState
().
login
.
access_token
,
normalize
(
path
))
return
RepositoryService
.
deleteFolder
(
normalize
(
path
))
.
then
((
folder
:
RepositoryFolder
)
=>
{
console
.
log
(
`Folder deleted
${
path
}
`
,
folder
);
return
true
;
...
...
@@ -55,7 +55,7 @@ export const deleteFolder = (path: string) => (dispatch, getState) => {
// Upload file
export
const
uploadFile
=
(
path
:
string
,
file
:
File
)
=>
(
dispatch
,
getState
)
=>
{
return
RepositoryService
.
uploadFile
(
getState
().
login
.
access_token
,
normalize
(
path
),
file
)
return
RepositoryService
.
uploadFile
(
normalize
(
path
),
file
)
.
then
((
file
:
RepositoryFile
)
=>
{
dispatch
(
getFolder
(
file
.
folder
.
path
));
})
...
...
@@ -67,7 +67,7 @@ export const uploadFile = (path: string, file: File) => (dispatch, getState) =>
// Image gallery
export
const
getGallery
=
(
path
:
string
)
=>
(
dispatch
,
getState
)
=>
{
return
RepositoryService
.
getGallery
(
getState
().
login
.
access_token
,
normalize
(
path
))
return
RepositoryService
.
getGallery
(
normalize
(
path
))
.
then
((
gallery
:
ImageGallery
)
=>
{
dispatch
(
receiveGallery
(
gallery
));
})
...
...
@@ -81,7 +81,7 @@ export const createGallery = (path: string, title: string, description?: string)
const
gallery
:
ImageGallery
=
new
ImageGallery
();
gallery
.
title
=
title
;
gallery
.
description
=
description
;
return
RepositoryService
.
createGallery
(
getState
().
login
.
access_token
,
normalize
(
path
),
gallery
)
return
RepositoryService
.
createGallery
(
normalize
(
path
),
gallery
)
.
then
((
gallery
:
ImageGallery
)
=>
{
console
.
log
(
`Gallery created at
${
path
}
`
,
gallery
);
dispatch
(
receiveGallery
(
null
));
...
...
@@ -95,7 +95,7 @@ export const createGallery = (path: string, title: string, description?: string)
// Get folder details
export
const
removeGallery
=
(
path
:
string
)
=>
(
dispatch
,
getState
)
=>
{
return
RepositoryService
.
removeGallery
(
getState
().
login
.
access_token
,
normalize
(
path
))
return
RepositoryService
.
removeGallery
(
normalize
(
path
))
.
then
((
gallery
:
ImageGallery
)
=>
{
console
.
log
(
`Gallery deleted
${
path
}
`
,
gallery
);
dispatch
(
receiveGallery
(
null
));
...
...
src/requests/actions/admin.ts
View file @
83aa6264
import
*
as
_
from
'
lodash
'
;
import
{
getRequest
,
listRequests
,
sendValidationEmail
,
recheckPid
,
validateRequest
}
from
'
service/genesys/actions/requestService
'
;
// constants
import
{
ADMIN_APPEND_MATERIAL_REQUESTS
,
ADMIN_RECEIVE_MATERIAL_REQUEST
,
ADMIN_RECEIVE_MATERIAL_REQUESTS
}
from
'
requests/constants
'
;
...
...
@@ -7,6 +6,8 @@ import {ADMIN_APPEND_MATERIAL_REQUESTS, ADMIN_RECEIVE_MATERIAL_REQUEST, ADMIN_RE
// models
import
MaterialRequest
from
'
model/MaterialRequest
'
;
import
FilteredPage
,
{
IPageRequest
}
from
'
model/FilteredPage
'
;
import
RequestService
from
'
service/genesys/RequestService
'
;
import
MaterialRequestFilter
from
'
model/MaterialRequestFilter
'
;
const
receiveRequests
=
(
paged
:
FilteredPage
<
MaterialRequest
>
,
error
=
null
)
=>
({
...
...
@@ -38,10 +39,12 @@ const refreshRequestPID = (request: MaterialRequest) => (dispatch, getState) =>
}
};
export
{
listRequests
as
listMaterialRequestsPromise
};
export
const
listMaterialRequestsPromise
=
(
filter
:
string
|
MaterialRequestFilter
,
page
:
IPageRequest
)
=>
(
dispatch
,
getState
):
Promise
<
FilteredPage
<
MaterialRequest
>>
=>
{
return
RequestService
.
list
(
filter
,
page
);
};
export
const
listMaterialRequests
=
(
page
:
IPageRequest
)
=>
(
dispatch
)
=>
{
return
dispatch
(
listRequests
(
null
,
page
)
)
return
RequestService
.
list
(
null
,
page
)
.
then
((
page
)
=>
{
if
(
page
.
number
===
0
)
{
dispatch
(
receiveRequests
(
page
));
...
...
@@ -55,7 +58,7 @@ export const listMaterialRequests = (page: IPageRequest) => (dispatch) => {
};
export
const
loadMaterialRequest
=
(
uuid
:
string
)
=>
(
dispatch
)
=>
{
return
dispatch
(
getRequest
(
uuid
)
)
return
RequestService
.
getRequest
(
uuid
)
.
then
((
request
)
=>
{
dispatch
(
receiveRequest
(
request
));
})
...
...
@@ -65,7 +68,7 @@ export const loadMaterialRequest = (uuid: string) => (dispatch) => {
};
export
const
recheckPidAction
=
(
uuid
:
string
)
=>
(
dispatch
)
=>
{
return
dispatch
(
recheckPid
(
uuid
)
)
return
RequestService
.
recheckPid
(
uuid
)
.
then
((
request
)
=>
{
dispatch
(
receiveRequest
(
request
));
dispatch
(
refreshRequestPID
(
request
));
...
...
@@ -77,7 +80,7 @@ export const recheckPidAction = (uuid: string) => (dispatch) => {
export
const
validateRequestAction
=
(
uuid
:
string
)
=>
(
dispatch
)
=>
{
return
dispatch
(
validateRequest
(
uuid
)
)
return
RequestService
.
validateRequest
(
uuid
)
.
then
((
request
)
=>
{
dispatch
(
receiveRequest
(
request
));
})
...
...
@@ -87,7 +90,7 @@ export const validateRequestAction = (uuid: string) => (dispatch) => {
};
export
const
sendValidationEmailAction
=
(
uuid
:
string
)
=>
(
dispatch
)
=>
{
return
dispatch
(
sendValidationEmail
(
uuid
)
)
return
RequestService
.
sendValidationEmail
(
uuid
)
.
then
((
request
)
=>
{
dispatch
(
receiveRequest
(
request
));
})
...
...
src/service/CropService.ts
View file @
83aa6264
import
*
as
UrlTemplate
from
'
url-template
'
;
import
authenticatedRequest
from
'
utilities/requestUtils
'
;
import
{
API_ROOT
}
from
'
constants/apiURLS
'
;
import
{
axiosBackend
}
from
'
utilities/requestUtils
'
;
import
Crop
from
'
model/Crop
'
;
const
URL_LIST_CROPS
=
UrlTemplate
.
parse
(
`
${
API_ROOT
}
/api/v0/crops`
);
const
URL_SAVE_CROP
=
`
${
API_ROOT
}
/api/v0/crops/save`
;
const
URL_DELETE_CROP
=
UrlTemplate
.
parse
(
`
${
API_ROOT
}
/api/v0/crops/{shortName}`
);
const
URL_LIST_CROPS
=
UrlTemplate
.
parse
(
`/api/v0/crops`
);
const
URL_SAVE_CROP
=
`/api/v0/crops/save`
;
const
URL_DELETE_CROP
=
UrlTemplate
.
parse
(
`/api/v0/crops/{shortName}`
);
export
class
CropService
{
...
...
@@ -15,13 +14,13 @@ export class CropService {
*
* @param authToken Authorization token
*/
public
static
listCrops
(
authToken
:
string
):
Promise
<
Crop
[]
>
{
public
static
listCrops
():
Promise
<
Crop
[]
>
{
const
apiUrl
=
URL_LIST_CROPS
.
expand
();
// console.log(`Fetching from ${apiUrl}`);
const
content
=
{
/* No content in request body */
};
return
a
uthenticatedRequest
(
authToken
,
{
return
a
xiosBackend
.
request
(
{
url
:
apiUrl
,
method
:
'
GET
'
,
...
content
,
...
...
@@ -34,13 +33,13 @@ export class CropService {
* @param authToken Authorization token
* @param cropJson cropJson
*/
public
static
saveCrop
(
authToken
:
string
,
cropJson
:
Crop
):
Promise
<
Crop
>
{
public
static
saveCrop
(
cropJson
:
Crop
):
Promise
<
Crop
>
{
const
apiUrl
=
URL_SAVE_CROP
;
// console.log(`Fetching from ${apiUrl}`);
const
content
=
{
data
:
cropJson
};
return
a
uthenticatedRequest
(
authToken
,
{
return
a
xiosBackend
.
request
(
{
url
:
apiUrl
,
method
:
'
PUT
'
,
...
content
,
...
...
@@ -53,13 +52,13 @@ export class CropService {
* @param authToken Authorization token
* @param shortName shortName
*/
public
static
deleteCrop
(
authToken
:
string
,
shortName
:
string
):
Promise
<
Crop
>
{
public
static
deleteCrop
(
shortName
:
string
):
Promise
<
Crop
>
{
const
apiUrl
=
URL_DELETE_CROP
.
expand
({
shortName
});
// console.log(`Fetching from ${apiUrl}`);
const
content
=
{
/* No content in request body */
};
return
a
uthenticatedRequest
(
authToken
,
{
return
a
xiosBackend
.
request
(
{
url
:
apiUrl
,
method
:
'
DELETE
'
,
...
content
,
...
...
src/service/InfoService.ts
View file @
83aa6264
import
ServerInfo
from
'
model/serverinfo.model
'
;
import
{
SERVER_INFO_URL
}
from
'
constants/apiURLS
'
;
import
authenticatedRequest
from
'
utilities/requestUtils
'
;
import
{
axiosBackend
}
from
'
utilities/requestUtils
'
;
export
const
SERVER_INFO_URL
=
`/api/v1/info/version`
;
export
class
InfoService
{
public
static
getServerInfo
(
token
:
string
):
Promise
<
ServerInfo
>
{
return
a
uthenticatedRequest
(
token
,
{
public
static
getServerInfo
():
Promise
<
ServerInfo
>
{
return
a
xiosBackend
.
request
(
{
url
:
SERVER_INFO_URL
,
method
:
'
GET
'
,
}).
then
(({
data
})
=>
data
as
ServerInfo
);
...
...
src/service/LoginService.ts
View file @
83aa6264
import
axios
from
'
axio
s
'
;
import
{
axios
Backend
}
from
'
utilities/requestUtil
s
'
;
// import FormData from 'form-data'; // it's in the browser
import
authenticatedRequest
from
'
utilities/requestUtils
'
;
import
{
API_ROOT
,
LOGIN_URL
,
CHECK_TOKEN_URL
,
VERIFY_GOOGLE_TOKEN_URL
}
from
'
constants/apiURLS
'
;
const
URL_LOGOUT
=
`
${
API_ROOT
}
/api/v0/me/logout
`
;
const
LOGIN_URL
=
`/oauth/token`
;
const
URL_LOGOUT
=
`/api/v0/me/logout`
;
// const LOGOUT_URL = `${API_BASE_URL}/me/logout`
;
export
const
CHECK_TOKEN_URL
=
`/oauth/check_token
`
;
export
const
VERIFY_GOOGLE_TOKEN_URL
=
`/google/verify-token`
;
export
class
LoginService
{
public
static
loginApp
()
{
return
axios
.
post
(
LOGIN_URL
,
null
,
{
return
axios
Backend
.
post
(
LOGIN_URL
,
null
,
{
params
:
{
grant_type
:
'
client_credentials
'
,
},
...
...
@@ -22,7 +22,7 @@ export class LoginService {
const
form
=
new
FormData
();
form
.
append
(
'
username
'
,
username
);
form
.
append
(
'
password
'
,
password
);
return
axios
.
post
(
LOGIN_URL
,
form
,
{
return
axios
Backend
.
post
(
LOGIN_URL
,
form
,
{
// headers: {
// 'Content-Type': 'application/x-www-form-urlencoded',
// },
...
...
@@ -44,7 +44,7 @@ export class LoginService {
// console.log(`Fetching from ${apiUrl}`);
const
content
=
{
/* No content in request body */
};
return
a
uthenticatedRequest
(
authToken
,
{
return
a
xiosBackend
.
request
(
{
url
:
apiUrl
,
method
:
'
POST
'
,
...
content
,
...
...
@@ -52,7 +52,7 @@ export class LoginService {
}
public
static
checkToken
(
token
:
string
)
{
return
axios
.
get
(
CHECK_TOKEN_URL
,
{
return
axios
Backend
.
get
(
CHECK_TOKEN_URL
,
{
params
:
{
token
,
},
...
...
@@ -63,7 +63,7 @@ export class LoginService {
}
public
static
verifyGoogleToken
(
token
:
string
,
accessToken
)
{
return
a
uthenticatedRequest
(
token
,
{
return
a
xiosBackend
.
request
(
{
url
:
VERIFY_GOOGLE_TOKEN_URL
,
method
:
'
GET
'
,
params
:
{
...
...
src/service/PermissionService.ts
View file @
83aa6264
import
{
AclObjectIdentity
,
SidPermissions
}
from
'
model/acl.model
'
;
import
authenticatedRequest
from
'
utilities/requestUtils
'
;
import
{
axiosBackend
}
from
'
utilities/requestUtils
'
;
import
{
APIv1_BASE_URL
}
from
'
constants/apiURLS
'
;
// import {log} from 'utilities/debug';
...
...
@@ -7,17 +7,17 @@ const API_URL = `${APIv1_BASE_URL}/permission`;
export
class
PermissionService
{
public
static
permissions
(
token
:
string
,
clazz
:
string
,
id
:
number
):
Promise
<
AclObjectIdentity
>
{
public
static
permissions
(
clazz
:
string
,
id
:
number
):
Promise
<
AclObjectIdentity
>
{