Skip to content
index.js 10.2 KiB
Newer Older
const BASE_API_URL = process.env.VUE_APP_API_BASE_URL;
import axios from 'axios';

function apiRequest(options, showLoading = true, handleValidationErrors = false) {
  if (showLoading) {
    loading(true);
  }
  return new Promise((resolve, reject) => {
    axios(options)
        if (handleValidationErrors && error.response && error.response.status === 400) {
          reject(error.response.data);
        } else {
          dispatchApiErrorEvent(error);
        }
      });
  });
}

function dispatchApiErrorEvent(error) {
  let event = new CustomEvent('apiError');
  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';
  }
Sonia Zorba's avatar
Sonia Zorba committed
  event.message = {
    title: error.error || 'Error',
Sonia Zorba's avatar
Sonia Zorba committed
  };
/* For loading animation */
function loading(value) {
  let event = new CustomEvent('loading');
  event.value = value;
  document.dispatchEvent(event);
}

export default {
  fetchHomePageModel(input) {
    let url = BASE_API_URL +
      'ui/home?groupId=' + input.selectedGroupId +
      '&paginatorPageSize=' + input.paginatorPageSize +
      '&paginatorPage=' + input.paginatorPage;
      headers: {
        'Content-Type': 'application/json',
        'Accept': 'application/json',
  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;
    }
      method: 'GET',
      headers: {
        'Content-Type': 'application/json',
        'Accept': 'application/json',
  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;
    }
      method: 'GET',
      headers: {
        'Content-Type': 'application/json',
        'Accept': 'application/json',
  fetchMembersPanel(input) {
    let url = BASE_API_URL +
      'ui/members?groupId=' + input.selectedGroupId +
      '&paginatorPageSize=' + input.paginatorPageSize +
      '&paginatorPage=' + input.paginatorPage;
      method: 'GET',
      headers: {
        'Content-Type': 'application/json',
        'Accept': 'application/json',
  fetchPermissionsPanel(input) {
    let url = BASE_API_URL +
      'ui/permissions?groupId=' + input.selectedGroupId +
      '&paginatorPageSize=' + input.paginatorPageSize +
      '&paginatorPage=' + input.paginatorPage;
        'Content-Type': 'application/json',
        'Accept': 'application/json',
  addGroup(newGroupName, leaf, input) {
    let url = BASE_API_URL + 'ui/group';
      headers: {
        'Content-Type': 'application/json',
        'Accept': 'application/json',
        newGroupName: newGroupName,
        parentGroupId: input.selectedGroupId,
        paginatorPageSize: input.paginatorPageSize,
        paginatorPage: input.paginatorPage,
        searchFilter: input.searchFilter,
        leaf: leaf
  updateGroup(groupId, newGroupName, leaf, input) {
    let url = BASE_API_URL + 'ui/group/' + groupId;
      headers: {
        'Content-Type': 'application/json',
        'Accept': 'application/json',
        leaf: leaf,
        paginatorPageSize: input.paginatorPageSize,
        paginatorPage: input.paginatorPage,
        searchFilter: input.searchFilter
  removeGroup(groupId, input) {
    let url = BASE_API_URL + 'ui/group/' + groupId +
      '?paginatorPageSize=' + input.paginatorPageSize +
      '&paginatorPage=' + input.paginatorPage;
    if (input.searchFilter !== null) {
      url += '&searchFilter=' + input.searchFilter;
    }
      headers: {
        'Content-Type': 'application/json',
        'Accept': 'application/json',
  searchUser(searchInput) {
    let url = BASE_API_URL + 'ui/users?search=' + searchInput;
Sonia Zorba's avatar
Sonia Zorba committed
      method: 'GET',
Sonia Zorba's avatar
Sonia Zorba committed
      headers: {
        'Accept': 'application/json',
  addPermission(userId, permission, input, override) {
    let url = BASE_API_URL + 'ui/permission';
      headers: {
        'Content-Type': 'application/json',
        'Accept': 'application/json',
        groupId: input.selectedGroupId,
        userId: userId,
        permission: permission,
        paginatorPageSize: input.paginatorPageSize,
        paginatorPage: input.paginatorPage
    let url = BASE_API_URL + 'ui/permission';

    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
      }
  getPermission(groupId, userId) {
    let url = BASE_API_URL + 'ui/permission?groupId=' + groupId + '&userId=' + userId;
      headers: {
        'Content-Type': 'application/json',
        'Accept': 'application/json',
  addMember(userId, permission, input) {
    let url = BASE_API_URL + 'ui/member';
      headers: {
        'Content-Type': 'application/json',
        'Accept': 'application/json',
        groupId: input.selectedGroupId,
        userId: userId,
        permission: permission,
        paginatorPageSize: input.paginatorPageSize,
        paginatorPage: input.paginatorPage
  removeMember(userId, removeAlsoPermission, input) {
    let url = BASE_API_URL + 'ui/member' +
      '?groupId=' + input.selectedGroupId +
      '&userId=' + userId +
      '&removeAlsoPermission=' + removeAlsoPermission +
      '&paginatorPageSize=' + input.paginatorPageSize +
      '&paginatorPage=' + input.paginatorPage;
      headers: {
        'Content-Type': 'application/json',
        'Accept': 'application/json',
  removePermission(userId, input) {
    let url = BASE_API_URL + 'ui/permission' +
      '?groupId=' + input.selectedGroupId +
      '&userId=' + userId +
      '&paginatorPageSize=' + input.paginatorPageSize +
      '&paginatorPage=' + input.paginatorPage;
      headers: {
        'Content-Type': 'application/json',
        'Accept': 'application/json',
Sonia Zorba's avatar
Sonia Zorba committed
  },
  search(input) {
    let url = BASE_API_URL + 'ui/search?query=' + input.genericSearch.filter +
      '&paginatorPage=' + input.genericSearch.paginatorPage +
      '&paginatorPageSize=' + input.genericSearch.paginatorPageSize +
      '&users=' + input.genericSearch.users + "&groups=" + input.genericSearch.groups;
Sonia Zorba's avatar
Sonia Zorba committed

Sonia Zorba's avatar
Sonia Zorba committed
      method: 'GET',
Sonia Zorba's avatar
Sonia Zorba committed
      headers: {
        'Content-Type': 'application/json',
        'Accept': 'application/json',
Sonia Zorba's avatar
Sonia Zorba committed
      }
    });
  },
  openUserSearchResult(userId) {
    let url = BASE_API_URL + 'ui/search/user/' + userId;
Sonia Zorba's avatar
Sonia Zorba committed

Sonia Zorba's avatar
Sonia Zorba committed
      method: 'GET',
Sonia Zorba's avatar
Sonia Zorba committed
      headers: {
        'Content-Type': 'application/json',
        'Accept': 'application/json',
Sonia Zorba's avatar
Sonia Zorba committed
      }
    });
    let url = BASE_API_URL + 'ui/keepAlive';
      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'
      }
    });