Browse Source

[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 years ago
parent
commit
be96925ae2

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

@@ -17,6 +17,8 @@ import {
17 17
   setFolderData,
18 18
   APP_LIST,
19 19
   CONTENT_TYPE_LIST,
20
+  WORKSPACE_CONTENT_ARCHIVED,
21
+  WORKSPACE_CONTENT_DELETED,
20 22
   WORKSPACE_RECENT_ACTIVITY,
21 23
   WORKSPACE_READ_STATUS
22 24
 } from './action-creator.sync.js'
@@ -332,3 +334,33 @@ export const getContentTypeList = user => dispatch => {
332 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 View File

@@ -38,6 +38,11 @@ export const WORKSPACE_CONTENT = `${WORKSPACE}/Content`
38 38
 export const setWorkspaceContentList = workspaceContentList => ({ type: `${SET}/${WORKSPACE_CONTENT}`, workspaceContentList })
39 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 46
 export const WORKSPACE_LIST = `${WORKSPACE}/List`
42 47
 export const updateWorkspaceListData = workspaceList => ({ type: `${UPDATE}/${WORKSPACE_LIST}`, workspaceList })
43 48
 export const setWorkspaceListIsOpenInSidebar = (workspaceId, isOpenInSidebar) => ({ type: `${SET}/${WORKSPACE_LIST}/isOpenInSidebar`, workspaceId, isOpenInSidebar })

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

@@ -16,11 +16,15 @@ import {
16 16
 } from 'tracim_frontend_lib'
17 17
 import {
18 18
   getWorkspaceContentList,
19
-  getFolderContent
19
+  getFolderContent,
20
+  putWorkspaceContentArchived,
21
+  putWorkspaceContentDeleted
20 22
 } from '../action-creator.async.js'
21 23
 import {
22 24
   newFlashMessage,
23
-  setWorkspaceContentList
25
+  setWorkspaceContentList,
26
+  setWorkspaceContentArchived,
27
+  setWorkspaceContentDeleted
24 28
 } from '../action-creator.sync.js'
25 29
 
26 30
 const qs = require('query-string')
@@ -125,14 +129,34 @@ class WorkspaceContent extends React.Component {
125 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 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 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 162
   handleClickFolder = folderId => {

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

@@ -3,7 +3,9 @@ import {
3 3
   UPDATE,
4 4
   WORKSPACE,
5 5
   WORKSPACE_CONTENT,
6
-  FOLDER
6
+  FOLDER,
7
+  WORKSPACE_CONTENT_ARCHIVED,
8
+  WORKSPACE_CONTENT_DELETED
7 9
 } from '../action-creator.sync.js'
8 10
 
9 11
 export default function workspaceContentList (state = [], action) {
@@ -40,6 +42,18 @@ export default function workspaceContentList (state = [], action) {
40 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 57
     default:
44 58
       return state
45 59
   }