Bläddra i källkod

workspace content now handles unique depth of folder

Skylsmoi 6 år sedan
förälder
incheckning
8dc29c4dd2

+ 9 - 0
jsonserver/server.js Visa fil

56
   Object.assign({}, jsonDb.workspace_detail, {content: shuffle(jsonDb.workspace_detail.content)}, {id: req.params.id})
56
   Object.assign({}, jsonDb.workspace_detail, {content: shuffle(jsonDb.workspace_detail.content)}, {id: req.params.id})
57
 ))
57
 ))
58
 
58
 
59
+server.get('/workspace/:idws/folder/:idf', (req, res) => {
60
+  switch (req.params.idf) {
61
+    case '3':
62
+      return res.jsonp(jsonDb.folder_content_3)
63
+    case '11':
64
+      return res.jsonp(jsonDb.folder_content_11)
65
+  }
66
+})
67
+
59
 server.get('/user/:id/roles', (req, res) => res.jsonp(jsonDb.user_role))
68
 server.get('/user/:id/roles', (req, res) => res.jsonp(jsonDb.user_role))
60
 
69
 
61
 server.get('/timezone', (req, res) => res.jsonp(timezoneDb.timezone))
70
 server.get('/timezone', (req, res) => res.jsonp(timezoneDb.timezone))

+ 45 - 43
jsonserver/static_db.json Visa fil

151
         "workspace_id": 1,
151
         "workspace_id": 1,
152
         "title": "Programmation objet",
152
         "title": "Programmation objet",
153
         "type": "folder",
153
         "type": "folder",
154
-        "content": [
155
-          {
156
-            "id": 4,
157
-            "parent_id": 3,
158
-            "workspace_id": 1,
159
-            "title": "des trucs de backend",
160
-            "type": "File",
161
-            "status": "outdated"
162
-          },
163
-          {
164
-            "id": 5,
165
-            "parent_id": 3,
166
-            "workspace_id": 1,
167
-            "title": "on s'emmerde",
168
-            "type": "PageHtml",
169
-            "status": "outdated"
170
-          },
171
-          {
172
-            "id": 11,
173
-            "parent_id": 3,
174
-            "workspace_id": 1,
175
-            "title": "Hidden features",
176
-            "type": "folder",
177
-            "content": [
178
-              {
179
-                "id": 12,
180
-                "parent_id": 11,
181
-                "workspace_id": 1,
182
-                "title": "flatMap",
183
-                "type": "PageHtml",
184
-                "status": "current"
185
-              },
186
-              {
187
-                "id": 13,
188
-                "parent_id": 11,
189
-                "workspace_id": 1,
190
-                "title": "c'est tout pété",
191
-                "type": "Issue",
192
-                "status": "current"
193
-              }
194
-            ]
195
-          }
196
-        ]
154
+        "content": []
197
       }
155
       }
198
     ]
156
     ]
199
   },
157
   },
158
+  "folder_content_3": [
159
+    {
160
+      "id": 4,
161
+      "parent_id": 3,
162
+      "workspace_id": 1,
163
+      "title": "des trucs de backend",
164
+      "type": "File",
165
+      "status": "outdated"
166
+    },
167
+    {
168
+      "id": 5,
169
+      "parent_id": 3,
170
+      "workspace_id": 1,
171
+      "title": "on s'emmerde",
172
+      "type": "PageHtml",
173
+      "status": "outdated"
174
+    },
175
+    {
176
+      "id": 11,
177
+      "parent_id": 3,
178
+      "workspace_id": 1,
179
+      "title": "Hidden features",
180
+      "type": "folder",
181
+      "content": []
182
+    }
183
+  ],
184
+  "folder_content_11": [
185
+    {
186
+      "id": 12,
187
+      "parent_id": 11,
188
+      "workspace_id": 1,
189
+      "title": "flatMap",
190
+      "type": "PageHtml",
191
+      "status": "current"
192
+    },
193
+    {
194
+      "id": 13,
195
+      "parent_id": 11,
196
+      "workspace_id": 1,
197
+      "title": "c'est tout pété",
198
+      "type": "Issue",
199
+      "status": "current"
200
+    }
201
+  ],
200
   "timeline": [{
202
   "timeline": [{
201
     "id": 0,
203
     "id": 0,
202
     "type": "message",
204
     "type": "message",

+ 14 - 1
src/action-creator.async.js Visa fil

15
   setWorkspaceData,
15
   setWorkspaceData,
16
   WORKSPACE_LIST,
16
   WORKSPACE_LIST,
17
   updateWorkspaceListData,
17
   updateWorkspaceListData,
18
+  FOLDER,
19
+  setFolderData,
18
   APP_LIST,
20
   APP_LIST,
19
-  setAppList, setWorkspaceListIsOpenInSidebar
21
+  setAppList,
22
+  setWorkspaceListIsOpenInSidebar
20
 } from './action-creator.sync.js'
23
 } from './action-creator.sync.js'
21
 
24
 
22
 /*
25
 /*
166
   if (fetchGetWorkspaceContent.status === 200) dispatch(setWorkspaceData(fetchGetWorkspaceContent.json, filterStr))
169
   if (fetchGetWorkspaceContent.status === 200) dispatch(setWorkspaceData(fetchGetWorkspaceContent.json, filterStr))
167
 }
170
 }
168
 
171
 
172
+export const getFolderContent = (workspaceId, folderId) => async dispatch => {
173
+  const fetchGetFolderContent = await fetchWrapper({
174
+    url: `${FETCH_CONFIG.apiUrl}/workspace/${workspaceId}/folder/${folderId}`,
175
+    param: {...FETCH_CONFIG.header, method: 'GET'},
176
+    actionName: `${WORKSPACE}/${FOLDER}`,
177
+    dispatch
178
+  })
179
+  if (fetchGetFolderContent.status === 200) dispatch(setFolderData(folderId, fetchGetFolderContent.json))
180
+}
181
+
169
 export const getAppList = () => async dispatch => {
182
 export const getAppList = () => async dispatch => {
170
   const fetchGetAppList = await fetchWrapper({
183
   const fetchGetAppList = await fetchWrapper({
171
     url: `${FETCH_CONFIG.apiUrl}/app/config`,
184
     url: `${FETCH_CONFIG.apiUrl}/app/config`,

+ 3 - 0
src/action-creator.sync.js Visa fil

15
 export const setWorkspaceData = (workspace, filterStr = '') => ({ type: `Set/${WORKSPACE}`, workspace, filterStr })
15
 export const setWorkspaceData = (workspace, filterStr = '') => ({ type: `Set/${WORKSPACE}`, workspace, filterStr })
16
 export const updateWorkspaceFilter = filterList => ({ type: `Update/${WORKSPACE}/Filter`, filterList })
16
 export const updateWorkspaceFilter = filterList => ({ type: `Update/${WORKSPACE}/Filter`, filterList })
17
 
17
 
18
+export const FOLDER = 'Folder'
19
+export const setFolderData = (folderId, content) => ({ type: `Set/${WORKSPACE}/${FOLDER}/Content`, folderId, content })
20
+
18
 export const WORKSPACE_LIST = 'WorkspaceList'
21
 export const WORKSPACE_LIST = 'WorkspaceList'
19
 export const updateWorkspaceListData = workspaceList => ({ type: `Update/${WORKSPACE_LIST}`, workspaceList })
22
 export const updateWorkspaceListData = workspaceList => ({ type: `Update/${WORKSPACE_LIST}`, workspaceList })
20
 export const setWorkspaceListIsOpenInSidebar = (workspaceId, isOpenInSidebar) => ({ type: `Set/${WORKSPACE_LIST}/isOpenInSidebar`, workspaceId, isOpenInSidebar })
23
 export const setWorkspaceListIsOpenInSidebar = (workspaceId, isOpenInSidebar) => ({ type: `Set/${WORKSPACE_LIST}/isOpenInSidebar`, workspaceId, isOpenInSidebar })

+ 11 - 3
src/component/Workspace/Folder.jsx Visa fil

14
     }
14
     }
15
   }
15
   }
16
 
16
 
17
-  handleClickToggleFolder = () => this.setState({open: !this.state.open})
17
+  handleClickToggleFolder = () => {
18
+    !this.state.open && this.props.folderData.content.length === 0 && this.props.onClickFolder(this.props.folderData.id)
19
+    this.setState({open: !this.state.open})
20
+  }
18
 
21
 
19
   handleClickNewFile = e => {
22
   handleClickNewFile = e => {
20
     e.stopPropagation() // because we have a link inside a link (togler and newFile)
23
     e.stopPropagation() // because we have a link inside a link (togler and newFile)
22
   }
25
   }
23
 
26
 
24
   render () {
27
   render () {
25
-    const { app, folderData: { title, content }, onClickItem, isLast, t } = this.props
28
+    const { app, folderData: { title, content }, onClickItem, onClickFolder, isLast, t } = this.props
29
+
26
     return (
30
     return (
27
       <div className={classnames('folder', {'active': this.state.open, 'item-last': isLast})}>
31
       <div className={classnames('folder', {'active': this.state.open, 'item-last': isLast})}>
28
         <div className='folder__header' onClick={this.handleClickToggleFolder}>
32
         <div className='folder__header' onClick={this.handleClickToggleFolder}>
60
               app={app}
64
               app={app}
61
               folderData={c}
65
               folderData={c}
62
               onClickItem={onClickItem}
66
               onClickItem={onClickItem}
67
+              onClickFolder={onClickFolder}
63
               isLast={isLast}
68
               isLast={isLast}
64
               t={t}
69
               t={t}
65
               key={c.id}
70
               key={c.id}
87
     title: PropTypes.string.isRequired,
92
     title: PropTypes.string.isRequired,
88
     content: PropTypes.array
93
     content: PropTypes.array
89
   }),
94
   }),
90
-  app: PropTypes.object
95
+  app: PropTypes.object,
96
+  onClickItem: PropTypes.func.isRequired,
97
+  onClickFolder: PropTypes.func.isRequired,
98
+  isLast: PropTypes.bool.isRequired
91
 }
99
 }

+ 7 - 1
src/container/WorkspaceContent.jsx Visa fil

11
 import DropdownCreateButton from '../component/common/Input/DropdownCreateButton.jsx'
11
 import DropdownCreateButton from '../component/common/Input/DropdownCreateButton.jsx'
12
 import {
12
 import {
13
   getAppList,
13
   getAppList,
14
-  getWorkspaceContent
14
+  getWorkspaceContent,
15
+  getFolderContent
15
 } from '../action-creator.async.js'
16
 } from '../action-creator.async.js'
16
 
17
 
17
 class WorkspaceContent extends React.Component {
18
 class WorkspaceContent extends React.Component {
42
     // dispatch(setActiveFileContentActive(content))
43
     // dispatch(setActiveFileContentActive(content))
43
   }
44
   }
44
 
45
 
46
+  handleClickFolder = folderId => {
47
+    this.props.dispatch(getFolderContent(this.props.workspace.id, folderId))
48
+  }
49
+
45
   filterWorkspaceContent = (contentList, filter) => filter.length === 0
50
   filterWorkspaceContent = (contentList, filter) => filter.length === 0
46
     ? contentList
51
     ? contentList
47
     : contentList.filter(c => c.type === 'folder' || filter.includes(c.type)) // keep unfiltered files and folders
52
     : contentList.filter(c => c.type === 'folder' || filter.includes(c.type)) // keep unfiltered files and folders
76
                     app={app}
81
                     app={app}
77
                     folderData={c}
82
                     folderData={c}
78
                     onClickItem={this.handleClickContentItem}
83
                     onClickItem={this.handleClickContentItem}
84
+                    onClickFolder={this.handleClickFolder}
79
                     isLast={i === filteredWorkspaceContent.length - 1}
85
                     isLast={i === filteredWorkspaceContent.length - 1}
80
                     key={c.id}
86
                     key={c.id}
81
                   />
87
                   />

+ 16 - 1
src/reducer/workspace.js Visa fil

1
 import {
1
 import {
2
-  WORKSPACE
2
+  WORKSPACE,
3
+  FOLDER
3
 } from '../action-creator.sync.js'
4
 } from '../action-creator.sync.js'
4
 
5
 
5
 const serializeWorkspace = data => ({
6
 const serializeWorkspace = data => ({
26
     case `Update/${WORKSPACE}/Filter`:
27
     case `Update/${WORKSPACE}/Filter`:
27
       return {...state, filter: action.filterList}
28
       return {...state, filter: action.filterList}
28
 
29
 
30
+    case `Set/${WORKSPACE}/${FOLDER}/Content`:
31
+      const setFolderContent = (contentItem, action) => {
32
+        if (contentItem.id === action.folderId) return {...contentItem, content: action.content}
33
+
34
+        if (contentItem.type === 'folder') return {...contentItem, content: contentItem.content.map(c => setFolderContent(c, action))}
35
+
36
+        return contentItem
37
+      }
38
+
39
+      return {
40
+        ...state,
41
+        content: state.content.map(c => setFolderContent(c, action))
42
+      }
43
+
29
     default:
44
     default:
30
       return state
45
       return state
31
   }
46
   }