helper.js 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. import i18n from './i18n.js'
  2. import Cookies from 'js-cookie'
  3. const configEnv = require('../configEnv.json')
  4. export const FETCH_CONFIG = {
  5. headers: {
  6. 'Accept': 'application/json',
  7. 'Content-Type': 'application/json'
  8. },
  9. apiUrl: configEnv.apiUrl,
  10. mockApiUrl: 'http://localhost:3001' // @todo: better to use one url only and use proxy on mock api to point to real api (if implemented)
  11. }
  12. export const COOKIE = {
  13. USER_LOGIN: 'user_login',
  14. USER_AUTH: 'user_auth'
  15. }
  16. export const setCookie = (login, password, expires = undefined) => {
  17. const auth = btoa(`${login}:${password}`)
  18. if (expires) {
  19. Cookies.set(COOKIE.USER_LOGIN, login, {expires})
  20. Cookies.set(COOKIE.USER_AUTH, auth, {expires})
  21. } else {
  22. Cookies.set(COOKIE.USER_LOGIN, login)
  23. Cookies.set(COOKIE.USER_AUTH, auth)
  24. }
  25. return auth
  26. }
  27. // Côme - 2018/08/02 - shouldn't this come from api ?
  28. export const workspaceConfig = {
  29. slug: 'workspace',
  30. faIcon: 'bank',
  31. hexcolor: '#7d4e24',
  32. creationLabel: i18n.t('Create a workspace'),
  33. domContainer: 'appFeatureContainer'
  34. }
  35. export const PAGE = {
  36. HOME: '/',
  37. WORKSPACE: {
  38. ROOT: '/workspaces',
  39. DASHBOARD: (idws = ':idws') => `/workspaces/${idws}/dashboard`,
  40. NEW: (idws, type) => `/workspaces/${idws}/contents/${type}/new`,
  41. CALENDAR: (idws = ':idws') => `/workspaces/${idws}/calendar`,
  42. CONTENT_LIST: (idws = ':idws') => `/workspaces/${idws}/contents`,
  43. CONTENT: (idws = ':idws', type = ':type', idcts = ':idcts') => `/workspaces/${idws}/contents/${type}/${idcts}`,
  44. ADMIN: (idws = ':idws') => `/workspaces/${idws}/admin`
  45. },
  46. LOGIN: '/login',
  47. ACCOUNT: '/account',
  48. ADMIN: {
  49. ROOT: '/admin',
  50. WORKSPACE: '/admin/workspace',
  51. USER: '/admin/user'
  52. }
  53. }
  54. export const ROLE = [{
  55. id: 1,
  56. slug: 'reader',
  57. faIcon: 'eye',
  58. hexcolor: '#15d948',
  59. label: i18n.t('Reader')
  60. }, {
  61. id: 2,
  62. slug: 'contributor',
  63. faIcon: 'pencil',
  64. hexcolor: '#3145f7',
  65. label: i18n.t('Contributor')
  66. }, {
  67. id: 4,
  68. slug: 'content-manager',
  69. faIcon: 'graduation-cap',
  70. hexcolor: '#f2af2d',
  71. label: i18n.t('Content manager')
  72. }, {
  73. id: 8,
  74. slug: 'workspace-manager',
  75. faIcon: 'gavel',
  76. hexcolor: '#ed0007',
  77. label: i18n.t('Workspace manager')
  78. }]
  79. export const findIdRoleUserWorkspace = (idUser, memberList, roleList) => {
  80. const myself = memberList.find(u => u.id === idUser) || {role: 'reader'}
  81. return (roleList.find(r => myself.role === r.slug) || {id: 1}).id
  82. }
  83. // Côme - 2018/08/21 - useful ?
  84. export const ROLE2 = {
  85. reader: {
  86. id: 1,
  87. sluf: 'reader',
  88. faIcon: 'eye',
  89. hexcolor: '#15D948',
  90. label: i18n.t('Reader')
  91. },
  92. contributor: {
  93. id: 2,
  94. slug: 'contributor',
  95. faIcon: 'pencil',
  96. hexcolor: '#3145f7',
  97. label: i18n.t('Contributor')
  98. },
  99. contentManager: {
  100. id: 4,
  101. slug: 'content-manager',
  102. faIcon: 'graduation-cap',
  103. hexcolor: '#f2af2d',
  104. label: i18n.t('Content manager')
  105. },
  106. workspaceManager: {
  107. id: 8,
  108. slug: 'workspace-manager',
  109. faIcon: 'gavel',
  110. hexcolor: '#ed0007',
  111. label: i18n.t('Workspace manager')
  112. }
  113. }
  114. export const PROFILE = {
  115. ADMINISTRATOR: {
  116. id: 1,
  117. slug: 'administrators',
  118. faIcon: 'rocket',
  119. hexcolor: '#123456',
  120. label: i18n.t('Administrator')
  121. },
  122. MANAGER: {
  123. id: 2,
  124. slug: 'managers',
  125. faIcon: 'car',
  126. hexcolor: '#654321',
  127. label: i18n.t('Manager')
  128. },
  129. USER: {
  130. id: 4,
  131. slug: 'users',
  132. faIcon: 'bicycle',
  133. hexcolor: '#123123',
  134. label: i18n.t('User')
  135. }
  136. }
  137. export const handleRouteFromApi = route => route.startsWith('/#') ? route.slice(2) : route