Sfoglia il codice sorgente

[https://github.com/tracim/tracim/issues/639 and https://github.com/tracim/tracim/issues/640] pluged archive and delete on submenu action of content list

Skylsmoi 5 anni fa
parent
commit
be96925ae2

+ 32 - 0
frontend/src/action-creator.async.js Vedi File

17
   setFolderData,
17
   setFolderData,
18
   APP_LIST,
18
   APP_LIST,
19
   CONTENT_TYPE_LIST,
19
   CONTENT_TYPE_LIST,
20
+  WORKSPACE_CONTENT_ARCHIVED,
21
+  WORKSPACE_CONTENT_DELETED,
20
   WORKSPACE_RECENT_ACTIVITY,
22
   WORKSPACE_RECENT_ACTIVITY,
21
   WORKSPACE_READ_STATUS
23
   WORKSPACE_READ_STATUS
22
 } from './action-creator.sync.js'
24
 } from './action-creator.sync.js'
332
     dispatch
334
     dispatch
333
   })
335
   })
334
 }
336
 }
337
+
338
+export const putWorkspaceContentArchived = (user, idWorkspace, idContent) => dispatch => {
339
+  return fetchWrapper({
340
+    url: `${FETCH_CONFIG.apiUrl}/workspaces/${idWorkspace}/contents/${idContent}/archive`,
341
+    param: {
342
+      headers: {
343
+        ...FETCH_CONFIG.headers,
344
+        'Authorization': 'Basic ' + user.auth
345
+      },
346
+      method: 'PUT'
347
+    },
348
+    actionName: WORKSPACE_CONTENT_ARCHIVED,
349
+    dispatch
350
+  })
351
+}
352
+
353
+export const putWorkspaceContentDeleted = (user, idWorkspace, idContent) => dispatch => {
354
+  return fetchWrapper({
355
+    url: `${FETCH_CONFIG.apiUrl}/workspaces/${idWorkspace}/contents/${idContent}/delete`,
356
+    param: {
357
+      headers: {
358
+        ...FETCH_CONFIG.headers,
359
+        'Authorization': 'Basic ' + user.auth
360
+      },
361
+      method: 'PUT'
362
+    },
363
+    actionName: WORKSPACE_CONTENT_DELETED,
364
+    dispatch
365
+  })
366
+}

+ 5 - 0
frontend/src/action-creator.sync.js Vedi File

38
 export const setWorkspaceContentList = workspaceContentList => ({ type: `${SET}/${WORKSPACE_CONTENT}`, workspaceContentList })
38
 export const setWorkspaceContentList = workspaceContentList => ({ type: `${SET}/${WORKSPACE_CONTENT}`, workspaceContentList })
39
 export const updateWorkspaceFilter = filterList => ({ type: `${UPDATE}/${WORKSPACE}/Filter`, filterList })
39
 export const updateWorkspaceFilter = filterList => ({ type: `${UPDATE}/${WORKSPACE}/Filter`, filterList })
40
 
40
 
41
+export const WORKSPACE_CONTENT_ARCHIVED = `${WORKSPACE_CONTENT}/Archived`
42
+export const WORKSPACE_CONTENT_DELETED = `${WORKSPACE_CONTENT}/Deleted`
43
+export const setWorkspaceContentArchived = (idWorkspace, idContent) => ({ type: `${SET}/${WORKSPACE_CONTENT_ARCHIVED}`, idWorkspace, idContent })
44
+export const setWorkspaceContentDeleted = (idWorkspace, idContent) => ({ type: `${SET}/${WORKSPACE_CONTENT_DELETED}`, idWorkspace, idContent })
45
+
41
 export const WORKSPACE_LIST = `${WORKSPACE}/List`
46
 export const WORKSPACE_LIST = `${WORKSPACE}/List`
42
 export const updateWorkspaceListData = workspaceList => ({ type: `${UPDATE}/${WORKSPACE_LIST}`, workspaceList })
47
 export const updateWorkspaceListData = workspaceList => ({ type: `${UPDATE}/${WORKSPACE_LIST}`, workspaceList })
43
 export const setWorkspaceListIsOpenInSidebar = (workspaceId, isOpenInSidebar) => ({ type: `${SET}/${WORKSPACE_LIST}/isOpenInSidebar`, workspaceId, isOpenInSidebar })
48
 export const setWorkspaceListIsOpenInSidebar = (workspaceId, isOpenInSidebar) => ({ type: `${SET}/${WORKSPACE_LIST}/isOpenInSidebar`, workspaceId, isOpenInSidebar })

+ 30 - 6
frontend/src/container/WorkspaceContent.jsx Vedi File

16
 } from 'tracim_frontend_lib'
16
 } from 'tracim_frontend_lib'
17
 import {
17
 import {
18
   getWorkspaceContentList,
18
   getWorkspaceContentList,
19
-  getFolderContent
19
+  getFolderContent,
20
+  putWorkspaceContentArchived,
21
+  putWorkspaceContentDeleted
20
 } from '../action-creator.async.js'
22
 } from '../action-creator.async.js'
21
 import {
23
 import {
22
   newFlashMessage,
24
   newFlashMessage,
23
-  setWorkspaceContentList
25
+  setWorkspaceContentList,
26
+  setWorkspaceContentArchived,
27
+  setWorkspaceContentDeleted
24
 } from '../action-creator.sync.js'
28
 } from '../action-creator.sync.js'
25
 
29
 
26
 const qs = require('query-string')
30
 const qs = require('query-string')
125
     console.log('%c<WorkspaceContent> download nyi', 'color: #c17838', content)
129
     console.log('%c<WorkspaceContent> download nyi', 'color: #c17838', content)
126
   }
130
   }
127
 
131
 
128
-  handleClickArchiveContentItem = (e, content) => {
132
+  handleClickArchiveContentItem = async (e, content) => {
133
+    const { props, state } = this
134
+
129
     e.stopPropagation()
135
     e.stopPropagation()
130
-    console.log('%c<WorkspaceContent> archive nyi', 'color: #c17838', content)
136
+
137
+    const fetchPutContentArchived = await props.dispatch(putWorkspaceContentArchived(props.user, content.idWorkspace, content.id))
138
+    switch (fetchPutContentArchived.status) {
139
+      case 204:
140
+        props.dispatch(setWorkspaceContentArchived(content.idWorkspace, content.id))
141
+        this.loadContentList(state.workspaceIdInUrl)
142
+        break
143
+      default: props.dispatch(newFlashMessage(props.t('Error while archiving document')))
144
+    }
131
   }
145
   }
132
 
146
 
133
-  handleClickDeleteContentItem = (e, content) => {
147
+  handleClickDeleteContentItem = async (e, content) => {
148
+    const { props, state } = this
149
+
134
     e.stopPropagation()
150
     e.stopPropagation()
135
-    console.log('%c<WorkspaceContent> delete nyi', 'color: #c17838', content)
151
+
152
+    const fetchPutContentDeleted = await props.dispatch(putWorkspaceContentDeleted(props.user, content.idWorkspace, content.id))
153
+    switch (fetchPutContentDeleted.status) {
154
+      case 204:
155
+        props.dispatch(setWorkspaceContentDeleted(content.idWorkspace, content.id))
156
+        this.loadContentList(state.workspaceIdInUrl)
157
+        break
158
+      default: props.dispatch(newFlashMessage(props.t('Error while deleting document')))
159
+    }
136
   }
160
   }
137
 
161
 
138
   handleClickFolder = folderId => {
162
   handleClickFolder = folderId => {

+ 15 - 1
frontend/src/reducer/workspaceContentList.js Vedi File

3
   UPDATE,
3
   UPDATE,
4
   WORKSPACE,
4
   WORKSPACE,
5
   WORKSPACE_CONTENT,
5
   WORKSPACE_CONTENT,
6
-  FOLDER
6
+  FOLDER,
7
+  WORKSPACE_CONTENT_ARCHIVED,
8
+  WORKSPACE_CONTENT_DELETED
7
 } from '../action-creator.sync.js'
9
 } from '../action-creator.sync.js'
8
 
10
 
9
 export default function workspaceContentList (state = [], action) {
11
 export default function workspaceContentList (state = [], action) {
40
         content: state.content.map(c => setFolderContent(c, action))
42
         content: state.content.map(c => setFolderContent(c, action))
41
       }
43
       }
42
 
44
 
45
+    case `${SET}/${WORKSPACE_CONTENT_ARCHIVED}`:
46
+      return state.map(wsc => wsc.idWorkspace === action.idWorkspace && wsc.id === action.idContent
47
+        ? {...wsc, isArchived: true}
48
+        : wsc
49
+      )
50
+
51
+    case `${SET}/${WORKSPACE_CONTENT_DELETED}`:
52
+      return state.map(wsc => wsc.idWorkspace === action.idWorkspace && wsc.id === action.idContent
53
+        ? {...wsc, isDeleted: true}
54
+        : wsc
55
+      )
56
+
43
     default:
57
     default:
44
       return state
58
       return state
45
   }
59
   }