Newer
Older
Sonia Zorba
committed
const BASE_API_URL = process.env.VUE_APP_API_BASE_URL;
Sonia Zorba
committed
import axios from 'axios';
function apiRequest(options, showLoading = true, handleValidationErrors = false) {
if (showLoading) {
loading(true);
}
Sonia Zorba
committed
return new Promise((resolve, reject) => {
axios(options)
.then(response => {
Sonia Zorba
committed
if (response.status === 204) {
resolve({});
} else {
Sonia Zorba
committed
resolve(response.data);
}
Sonia Zorba
committed
loading(false);
})
.catch(error => {
if (handleValidationErrors && error.response && error.response.status === 400) {
Sonia Zorba
committed
reject(error.response.data);
} else {
dispatchApiErrorEvent(error);
}
Sonia Zorba
committed
loading(false);
});
});
}
function dispatchApiErrorEvent(error) {
let event = new CustomEvent('apiError');
Sonia Zorba
committed
let errorMessage;
if (error.response && error.response.data && error.response.data.message) {
errorMessage = error.response.data.message;
} else if (error.message) {
errorMessage = error.message;
} else {
errorMessage = 'Unknown error';
}
event.message = {
title: error.error || 'Error',
Sonia Zorba
committed
body: errorMessage
document.dispatchEvent(event);
}
Sonia Zorba
committed
/* For loading animation */
function loading(value) {
let event = new CustomEvent('loading');
event.value = value;
document.dispatchEvent(event);
}
fetchHomePageModel(input) {
let url = BASE_API_URL +
'ui/home?groupId=' + input.selectedGroupId +
'&paginatorPageSize=' + input.paginatorPageSize +
'&paginatorPage=' + input.paginatorPage;
Sonia Zorba
committed
return apiRequest({
Sonia Zorba
committed
method: 'GET',
Sonia Zorba
committed
url: url,
withCredentials: true,
Sonia Zorba
committed
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
Sonia Zorba
committed
'Cache-Control': 'no-cache'
Sonia Zorba
committed
}
});
},
fetchGroupsTab(input) {
let url = BASE_API_URL +
'ui/groups?groupId=' + input.selectedGroupId +
'&paginatorPageSize=' + input.paginatorPageSize +
'&paginatorPage=' + input.paginatorPage +
'&onlyPanel=false';
if (input.searchFilter !== null) {
url += '&searchFilter=' + input.searchFilter;
}
Sonia Zorba
committed
return apiRequest({
Sonia Zorba
committed
url: url,
withCredentials: true,
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
Sonia Zorba
committed
'Cache-Control': 'no-cache'
fetchGroupsPanel(input) {
let url = BASE_API_URL +
'ui/groups?groupId=' + input.selectedGroupId +
'&paginatorPageSize=' + input.paginatorPageSize +
'&paginatorPage=' + input.paginatorPage +
'&onlyPanel=true';
if (input.searchFilter !== null) {
url += '&searchFilter=' + input.searchFilter;
}
Sonia Zorba
committed
return apiRequest({
Sonia Zorba
committed
url: url,
withCredentials: true,
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
Sonia Zorba
committed
'Cache-Control': 'no-cache'
fetchMembersPanel(input) {
let url = BASE_API_URL +
'ui/members?groupId=' + input.selectedGroupId +
'&paginatorPageSize=' + input.paginatorPageSize +
'&paginatorPage=' + input.paginatorPage;
Sonia Zorba
committed
return apiRequest({
Sonia Zorba
committed
url: url,
withCredentials: true,
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
Sonia Zorba
committed
'Cache-Control': 'no-cache'
fetchPermissionsPanel(input) {
let url = BASE_API_URL +
'ui/permissions?groupId=' + input.selectedGroupId +
'&paginatorPageSize=' + input.paginatorPageSize +
'&paginatorPage=' + input.paginatorPage;
Sonia Zorba
committed
return apiRequest({
method: 'GET',
Sonia Zorba
committed
url: url,
withCredentials: true,
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
Sonia Zorba
committed
'Cache-Control': 'no-cache'
});
},
let url = BASE_API_URL + 'ui/group';
Sonia Zorba
committed
return apiRequest({
method: 'POST',
Sonia Zorba
committed
url: url,
withCredentials: true,
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
Sonia Zorba
committed
'Cache-Control': 'no-cache'
},
Sonia Zorba
committed
data: {
newGroupName: newGroupName,
parentGroupId: input.selectedGroupId,
paginatorPageSize: input.paginatorPageSize,
searchFilter: input.searchFilter,
leaf: leaf
Sonia Zorba
committed
}
}, true, true);
},
updateGroup(groupId, newGroupName, leaf, input) {
let url = BASE_API_URL + 'ui/group/' + groupId;
Sonia Zorba
committed
return apiRequest({
method: 'PUT',
Sonia Zorba
committed
url: url,
withCredentials: true,
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
Sonia Zorba
committed
'Cache-Control': 'no-cache'
},
Sonia Zorba
committed
data: {
newGroupName: newGroupName,
paginatorPageSize: input.paginatorPageSize,
paginatorPage: input.paginatorPage,
searchFilter: input.searchFilter
Sonia Zorba
committed
}
}, true, true);
},
let url = BASE_API_URL + 'ui/group/' + groupId +
'?paginatorPageSize=' + input.paginatorPageSize +
'&paginatorPage=' + input.paginatorPage;
if (input.searchFilter !== null) {
url += '&searchFilter=' + input.searchFilter;
}
Sonia Zorba
committed
return apiRequest({
method: 'DELETE',
Sonia Zorba
committed
url: url,
withCredentials: true,
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
Sonia Zorba
committed
'Cache-Control': 'no-cache'
}
});
let url = BASE_API_URL + 'ui/users?search=' + searchInput;
Sonia Zorba
committed
return apiRequest({
Sonia Zorba
committed
url: url,
withCredentials: true,
Sonia Zorba
committed
'Cache-Control': 'no-cache'
Sonia Zorba
committed
addPermission(userId, permission, input, override) {
let url = BASE_API_URL + 'ui/permission';
Sonia Zorba
committed
return apiRequest({
Sonia Zorba
committed
url: url,
withCredentials: true,
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
Sonia Zorba
committed
'Cache-Control': 'no-cache'
Sonia Zorba
committed
data: {
groupId: input.selectedGroupId,
userId: userId,
permission: permission,
Sonia Zorba
committed
override: override,
paginatorPageSize: input.paginatorPageSize,
paginatorPage: input.paginatorPage
Sonia Zorba
committed
}
});
},
updatePermission(groupId, userId, permission) {
let url = BASE_API_URL + 'ui/permission';
Sonia Zorba
committed
return apiRequest({
method: 'PUT',
url: url,
withCredentials: true,
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Cache-Control': 'no-cache'
},
data: {
groupId: groupId,
userId: userId,
permission: permission
}
let url = BASE_API_URL + 'ui/permission?groupId=' + groupId + '&userId=' + userId;
Sonia Zorba
committed
return apiRequest({
method: 'GET',
Sonia Zorba
committed
url: url,
withCredentials: true,
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
Sonia Zorba
committed
'Cache-Control': 'no-cache'
}
});
},
addMember(userId, permission, input) {
let url = BASE_API_URL + 'ui/member';
Sonia Zorba
committed
return apiRequest({
method: 'POST',
Sonia Zorba
committed
url: url,
withCredentials: true,
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
Sonia Zorba
committed
'Cache-Control': 'no-cache'
Sonia Zorba
committed
data: {
groupId: input.selectedGroupId,
userId: userId,
permission: permission,
paginatorPageSize: input.paginatorPageSize,
paginatorPage: input.paginatorPage
Sonia Zorba
committed
}
removeMember(userId, removeAlsoPermission, input) {
let url = BASE_API_URL + 'ui/member' +
'?groupId=' + input.selectedGroupId +
'&userId=' + userId +
'&removeAlsoPermission=' + removeAlsoPermission +
'&paginatorPageSize=' + input.paginatorPageSize +
'&paginatorPage=' + input.paginatorPage;
Sonia Zorba
committed
return apiRequest({
method: 'DELETE',
Sonia Zorba
committed
url: url,
withCredentials: true,
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
Sonia Zorba
committed
'Cache-Control': 'no-cache'
}
});
},
removePermission(userId, input) {
let url = BASE_API_URL + 'ui/permission' +
'?groupId=' + input.selectedGroupId +
'&userId=' + userId +
'&paginatorPageSize=' + input.paginatorPageSize +
'&paginatorPage=' + input.paginatorPage;
Sonia Zorba
committed
return apiRequest({
method: 'DELETE',
Sonia Zorba
committed
url: url,
withCredentials: true,
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
Sonia Zorba
committed
'Cache-Control': 'no-cache'
let url = BASE_API_URL + 'ui/search?query=' + input.genericSearch.filter +
Sonia Zorba
committed
'&paginatorPage=' + input.genericSearch.paginatorPage +
'&paginatorPageSize=' + input.genericSearch.paginatorPageSize +
'&users=' + input.genericSearch.users + "&groups=" + input.genericSearch.groups;
Sonia Zorba
committed
return apiRequest({
Sonia Zorba
committed
url: url,
withCredentials: true,
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
Sonia Zorba
committed
'Cache-Control': 'no-cache'
let url = BASE_API_URL + 'ui/search/user/' + userId;
Sonia Zorba
committed
return apiRequest({
Sonia Zorba
committed
url: url,
withCredentials: true,
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
Sonia Zorba
committed
'Cache-Control': 'no-cache'
},
keepAlive() {
let url = BASE_API_URL + 'ui/keepAlive';
Sonia Zorba
committed
return apiRequest({
method: 'GET',
Sonia Zorba
committed
url: url,
withCredentials: true,
headers: {
'Cache-Control': 'no-cache'
}
},
deleteInvitedRegistration(requestId, groupId) {
let url = BASE_API_URL + 'ui/registration?' +
'request_id=' + requestId + '&group_id=' + groupId;
return apiRequest({
method: 'DELETE',
url: url,
withCredentials: true,
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Cache-Control': 'no-cache'
}
});