Newer
Older
Sonia Zorba
committed
const BASE_API_URL = process.env.VUE_APP_API_BASE_URL;
function apiRequest(url, options) {
Sonia Zorba
committed
loading(true);
return new Promise((resolve, reject) => {
.then(response => {
Sonia Zorba
committed
loading(false);
if([200, 201, 204, 400].includes(response.status)) { // valid status codes
resolve(response.json());
} else {
response.json().then(jsonValue => dispatchApiErrorEvent(jsonValue));
}
})
.catch(error => {
Sonia Zorba
committed
loading(false);
dispatchApiErrorEvent(error);
});
});
}
function dispatchApiErrorEvent(error) {
let message;
if(error.message) {
message = error.message;
} else {
message = 'Generic error';
}
let event = new CustomEvent('apiError');
event.message = message;
document.dispatchEvent(event);
}
Sonia Zorba
committed
/* For loading animation */
function loading(value) {
let event = new CustomEvent('loading');
event.value = value;
document.dispatchEvent(event);
}
Sonia Zorba
committed
fetchHomePageModel (input) {
let url = BASE_API_URL
+ 'home?groupId=' + input.selectedGroupId
+ '&paginatorPageSize=' + input.paginatorPageSize
+ '&paginatorPage=' + input.paginatorPage;
return apiRequest(url, {
method: 'GET',
cache: 'no-cache',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
}
});
},
let url = BASE_API_URL
+ 'groups?groupId=' + input.selectedGroupId
+ '&paginatorPageSize=' + input.paginatorPageSize
+ '&paginatorPage=' + input.paginatorPage
+ '&onlyPanel=false';
if(input.searchFilter !== null) {
url += '&searchFilter=' + input.searchFilter;
}
return apiRequest(url, {
method: 'GET',
cache: 'no-cache',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
}
});
},
fetchGroupsPanel (input) {
let url = BASE_API_URL
+ 'groups?groupId=' + input.selectedGroupId
+ '&paginatorPageSize=' + input.paginatorPageSize
+ '&paginatorPage=' + input.paginatorPage
+ '&onlyPanel=true';
if(input.searchFilter !== null) {
url += '&searchFilter=' + input.searchFilter;
}
return apiRequest(url, {
method: 'GET',
cache: 'no-cache',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
}
});
},
fetchMembersPanel (input) {
let url = BASE_API_URL
+ 'members?groupId=' + input.selectedGroupId
+ '&paginatorPageSize=' + input.paginatorPageSize
+ '&paginatorPage=' + input.paginatorPage;
return apiRequest(url, {
method: 'GET',
cache: 'no-cache',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
}
});
},
fetchPermissionsPanel (input) {
let url = BASE_API_URL
+ 'permissions?groupId=' + input.selectedGroupId
+ '&paginatorPageSize=' + input.paginatorPageSize
Sonia Zorba
committed
+ '&paginatorPage=' + input.paginatorPage;
return apiRequest(url, {
method: 'GET',
cache: 'no-cache',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
});
},
addGroup (newGroupName, input) {
let url = BASE_API_URL + 'group';
return apiRequest(url, {
method: 'POST',
cache: 'no-cache',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
body: JSON.stringify({
newGroupName: newGroupName,
parentGroupId: input.selectedGroupId,
paginatorPageSize: input.paginatorPageSize,
paginatorPage: input.paginatorPage,
searchFilter: input.searchFilter
})
});
},
renameGroup (groupId, newGroupName, input) {
let url = BASE_API_URL + 'group/' + groupId;
return apiRequest(url, {
method: 'PUT',
cache: 'no-cache',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
body: JSON.stringify({
newGroupName: newGroupName,
paginatorPageSize: input.paginatorPageSize,
paginatorPage: input.paginatorPage,
searchFilter: input.searchFilter
})
});
},
removeGroup (groupId, input) {
let url = BASE_API_URL + 'group/' + groupId
+ '?paginatorPageSize=' + input.paginatorPageSize
+ '&paginatorPage=' + input.paginatorPage;
if(input.searchFilter !== null) {
url += '&searchFilter=' + input.searchFilter;
}
return apiRequest(url, {
method: 'DELETE',
cache: 'no-cache',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
}
});
},
searchUser (searchInput) {
let url = BASE_API_URL + 'users?search=' + searchInput;
return apiRequest(url, {
method: 'GET',
cache: 'no-cache',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
}
});
},
addPermission (userId, permission, input) {
let url = BASE_API_URL + 'permission';
return apiRequest(url, {
method: 'POST',
cache: 'no-cache',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
body: JSON.stringify({
groupId: input.selectedGroupId,
userId: userId,
permission: permission,
paginatorPageSize: input.paginatorPageSize,
paginatorPage: input.paginatorPage
})
});
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
},
getPermission (groupId, userId) {
let url = BASE_API_URL + 'permission?groupId=' + groupId + '&userId=' + userId;
return apiRequest(url, {
method: 'GET',
cache: 'no-cache',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
}
});
},
addMember (userId, permission, input) {
let url = BASE_API_URL + 'member';
return apiRequest(url, {
method: 'POST',
cache: 'no-cache',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
body: JSON.stringify({
groupId: input.selectedGroupId,
userId: userId,
permission: permission,
paginatorPageSize: input.paginatorPageSize,
paginatorPage: input.paginatorPage
})
});
},
removeMember (userId, removeAlsoPermission, input) {
let url = BASE_API_URL + 'member'
+ '?groupId=' + input.selectedGroupId
+ '&userId=' + userId
+ '&removeAlsoPermission=' + removeAlsoPermission
+ '&paginatorPageSize=' + input.paginatorPageSize
+ '&paginatorPage=' + input.paginatorPage;
return apiRequest(url, {
method: 'DELETE',
cache: 'no-cache',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
}
});
},
removePermission (userId, input) {
let url = BASE_API_URL + 'permission'
+ '?groupId=' + input.selectedGroupId
+ '&userId=' + userId
+ '&paginatorPageSize=' + input.paginatorPageSize
+ '&paginatorPage=' + input.paginatorPage;
return apiRequest(url, {
method: 'DELETE',
cache: 'no-cache',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
}
});