Browse Source

added handling of status change

Skylsmoi 5 years ago
parent
commit
f8625a2d29
3 changed files with 70 additions and 33 deletions
  1. 0 32
      dist/index.html
  2. 44 0
      src/container/HtmlDocument.jsx
  3. 26 1
      src/helper.js

+ 0 - 32
dist/index.html View File

@@ -20,38 +20,6 @@
20 20
   <script src='./html-documents.app.dev.js'></script>
21 21
 
22 22
   <script type='text/javascript'>
23
-    GLOBAL_renderApp = app => {
24
-      switch (app.appData.name) {
25
-        case 'PageHtml':
26
-          appPageHtml.renderApp('appContainer'); break
27
-        case 'Thread':
28
-          appThread.renderApp('appContainer'); break
29
-      }
30
-    }
31
-
32
-    GLOBAL_dispatchEvent = (data) => {
33
-      var event = new CustomEvent('appCustomEvent', {detail: data})
34
-      document.dispatchEvent(event)
35
-    }
36
-
37
-    GLOBAL_unmountApp = () => {
38
-      switch (appName) {
39
-        case 'PageHtml':
40
-          appPageHtml.hideApp('appContainer'); break
41
-        case 'Thread':
42
-          appThread.hideApp('appContainer'); break
43
-      }
44
-    }
45
-
46
-    // only usefull if app doesn't handle fileContent himself
47
-    GLOBAL_handleRequireRedraw = () => {
48
-      var rez = appA.destroyApp('app')
49
-      if (rez) GLOBAL_drawApp('redraw')
50
-      else console.log('Erreur, failed at destroying app')
51
-    }
52
-  </script>
53
-
54
-  <script type='text/javascript'>
55 23
     // appPageHtml.renderApp('content')
56 24
   </script>
57 25
 </body>

+ 44 - 0
src/container/HtmlDocument.jsx View File

@@ -195,6 +195,45 @@ class HtmlDocument extends React.Component {
195 195
       })
196 196
   }
197 197
 
198
+  handleChangeStatus = async newStatus => {
199
+    const { config, content } = this.state
200
+
201
+    const fetchResultSaveEditStatus = await fetch(`${config.apiUrl}/workspaces/${content.workspace_id}/html-documents/${content.content_id}/status`, {
202
+      ...FETCH_CONFIG,
203
+      method: 'PUT',
204
+      body: JSON.stringify({
205
+        status: newStatus
206
+      })
207
+    })
208
+
209
+    handleFetchResult(fetchResultSaveEditStatus)
210
+      .then(resSave => {
211
+        if (resSave.status !== 204) { // 204 no content so dont take status from resSave.apiResponse.status
212
+          console.warn('Error saving html-document comment. Result:', resSave, 'content:', content, 'config:', config)
213
+        } else {
214
+          this.loadContent()
215
+        }
216
+      })
217
+  }
218
+
219
+  handleClickArchive = async () => {
220
+    console.log('archive')
221
+    // const { config, content } = this.state
222
+    //
223
+    // const fetchResultArchive = await fetch(`${config.apiUrl}/workspaces/${content.workspace_id}/contents/${content.content_id}/archive`, {
224
+    //   ...FETCH_CONFIG,
225
+    //   method: 'PUT'
226
+    // })
227
+  }
228
+  handleClickDelete = async () => {
229
+    console.log('delete')
230
+    // const { config, content } = this.state
231
+    // const fetchResultDelete = await fetch(`${config.apiUrl}/workspaces/${content.workspace_id}/contents/${content.content_id}/delete`, {
232
+    //   ...FETCH_CONFIG,
233
+    //   method: 'PUT'
234
+    // })
235
+  }
236
+
198 237
   render () {
199 238
     const { isVisible, loggedUser, content, timeline, newComment, config } = this.state
200 239
 
@@ -212,7 +251,12 @@ class HtmlDocument extends React.Component {
212 251
 
213 252
         <PopinFixedOption
214 253
           customClass={`${config.slug}`}
254
+          availableStatus={config.availableStatuses}
215 255
           onClickNewVersionBtn={this.handleClickNewVersion}
256
+          onChangeStatus={this.handleChangeStatus}
257
+          selectedStatus={config.availableStatuses.find(s => s.slug === content.status)} // peut être vide avant que api reponde
258
+          onClickArchive={this.handleClickArchive}
259
+          onClickDelete={this.handleClickDelete}
216 260
           i18n={i18n}
217 261
         />
218 262
 

+ 26 - 1
src/helper.js View File

@@ -27,7 +27,32 @@ export const debug = {
27 27
       'Accept': 'application/json',
28 28
       'Content-Type': 'application/json'
29 29
       // 'Authorization': 'Basic ' + btoa(`${'admin@admin.admin'}:${'admin@admin.admin'}`)
30
-    }
30
+    },
31
+    availableStatuses: [{
32
+      label: 'Open',
33
+      slug: 'open',
34
+      faIcon: 'square-o',
35
+      hexcolor: '#3f52e3',
36
+      globalStatus: 'open'
37
+    }, {
38
+      label: 'Validated',
39
+      slug: 'closed-validated',
40
+      faIcon: 'check-square-o',
41
+      hexcolor: '#008000',
42
+      globalStatus: 'closed'
43
+    }, {
44
+      label: 'Cancelled',
45
+      slug: 'closed-unvalidated',
46
+      faIcon: 'close',
47
+      hexcolor: '#f63434',
48
+      globalStatus: 'closed'
49
+    }, {
50
+      label: 'Deprecated',
51
+      slug: 'closed-deprecated',
52
+      faIcon: 'warning',
53
+      hexcolor: '#ababab',
54
+      globalStatus: 'closed'
55
+    }]
31 56
   },
32 57
   loggedUser: { // @FIXME this object is outdated
33 58
     user_id: 5,