Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
jami-jams
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
jami-jams
Commits
5ad9c4d2
Commit
5ad9c4d2
authored
4 years ago
by
William Enright
Committed by
Adrien Béraud
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Improved data loading on user profile page with Promises
Change-Id: I44f0b809a9add9ec5195a58e1dba8961e925bd53
parent
257a7e43
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
jams-server/src/main/resources/webapp/js/api.js
+56
-50
56 additions, 50 deletions
jams-server/src/main/resources/webapp/js/api.js
with
56 additions
and
50 deletions
jams-server/src/main/resources/webapp/js/api.js
+
56
−
50
View file @
5ad9c4d2
...
...
@@ -58,71 +58,77 @@ var api_path_get_user_search = '/api/admin/users';
function
ajaxApiCall
(
api_path
,
request_type
,
data
,
credentials
,
callBackFunction
,
async
)
{
// build AJAX call
var
ajax
=
{
url
:
url_path
+
"
:
"
+
url_port
+
api_path
,
type
:
request_type
,
crossDomain
:
true
,
dataType
:
"
json
"
,
success
:
function
(
data
,
statusCode
,
jqXHR
)
{
callBackFunction
(
data
,
statusCode
,
jqXHR
);
},
error
:
function
(
data
,
statusCode
,
jqXHR
)
{
callBackFunction
(
data
,
statusCode
,
jqXHR
);
}};
// pass credentials in the header
if
(
credentials
)
{
ajax
[
'
headers
'
]
=
{
"
Authorization
"
:
"
Basic
"
+
btoa
(
credentials
[
"
username
"
]
+
'
:
'
+
credentials
[
"
password
"
]),
}
}
if
(
window
.
localStorage
.
getItem
(
'
access_token
'
))
{
return
new
Promise
(
function
(
resolve
)
{
var
ajax
=
{
url
:
url_path
+
"
:
"
+
url_port
+
api_path
,
type
:
request_type
,
crossDomain
:
true
,
dataType
:
"
json
"
,
success
:
function
(
data
,
statusCode
,
jqXHR
)
{
callBackFunction
(
data
,
statusCode
,
jqXHR
);
},
error
:
function
(
data
,
statusCode
,
jqXHR
)
{
callBackFunction
(
data
,
statusCode
,
jqXHR
);
}
};
var
jwt
=
localStorage
.
getItem
(
'
access_token
'
);
ajax
[
'
headers
'
]
=
{
"
Authorization
"
:
"
Bearer
"
+
jwt
,
// pass credentials in the header
if
(
credentials
)
{
ajax
[
'
headers
'
]
=
{
"
Authorization
"
:
"
Basic
"
+
btoa
(
credentials
[
"
username
"
]
+
'
:
'
+
credentials
[
"
password
"
]),
}
}
}
// pass data in the header
if
(
data
)
{
if
(
api_path
==
api_path_get_user_directory_search
||
api_path
==
api_path_get_auth_user_search
||
(
api_path
==
api_path_post_create_user
&&
request_type
==
'
POST
'
)
||
api_path
==
api_path_post_update_user
||
api_path
==
api_path_get_auth_devices
||
api_path
==
api_path_post_configuration_change_password
)
isSearch
=
true
;
if
(
window
.
localStorage
.
getItem
(
'
access_token
'
))
{
// search dataType
if
(
isSearch
)
{
ajax
[
'
data
'
]
=
data
;
var
jwt
=
localStorage
.
getItem
(
'
access_token
'
);
ajax
[
'
headers
'
]
=
{
"
Authorization
"
:
"
Bearer
"
+
jwt
,
}
}
else
{
if
(
window
.
localStorage
.
getItem
(
'
access_token
'
))
{
var
jwt
=
localStorage
.
getItem
(
'
access_token
'
);
// pass data in the header
if
(
data
)
{
if
(
api_path
==
api_path_get_user_directory_search
||
api_path
==
api_path_get_auth_user_search
||
api_path
==
api_path_get_user_search
||
(
api_path
==
api_path_post_create_user
&&
request_type
==
'
POST
'
)
||
api_path
==
api_path_post_update_user
||
api_path
==
api_path_get_auth_devices
||
api_path
==
api_path_post_configuration_change_password
)
isSearch
=
true
;
// search dataType
if
(
isSearch
)
{
ajax
[
'
data
'
]
=
data
;
}
else
{
if
(
window
.
localStorage
.
getItem
(
'
access_token
'
))
{
var
jwt
=
localStorage
.
getItem
(
'
access_token
'
);
ajax
[
'
headers
'
]
=
{
"
Authorization
"
:
"
Bearer
"
+
jwt
,
}
}
else
{
ajax
[
'
headers
'
]
=
{
"
Content-type
"
:
"
application/json
"
ajax
[
'
headers
'
]
=
{
"
Authorization
"
:
"
Bearer
"
+
jwt
,
}
}
else
{
ajax
[
'
headers
'
]
=
{
"
Content-type
"
:
"
application/json
"
}
}
ajax
[
'
data
'
]
=
JSON
.
stringify
(
data
);
}
}
ajax
[
'
data
'
]
=
JSON
.
stringify
(
data
);
// async
if
(
!
async
)
{
ajax
[
'
async
'
]
=
async
;
}
}
// async
i
f
(
!
async
)
{
ajax
[
'
async
'
]
=
async
;
}
$
.
ajax
(
ajax
);
i
sSearch
=
false
;
resolve
(
data
)
;
}
);
$
.
ajax
(
ajax
);
isSearch
=
false
;
return
data
;
}
function
setJWT
(
value
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment