Browse Source

added mode revision

Skylsmoi 5 years ago
parent
commit
700f81124a
3 changed files with 53 additions and 23 deletions
  1. 1 1
      src/component/HtmlDocument.jsx
  2. 50 21
      src/container/HtmlDocument.jsx
  3. 2 1
      src/helper.js

+ 1 - 1
src/component/HtmlDocument.jsx View File

@@ -5,7 +5,7 @@ import { MODE } from '../helper.js'
5 5
 const HtmlDocument = props => {
6 6
   return (
7 7
     <div className='wsContentHtmlDocument__contentpage__textnote html-documents__contentpage__textnote'>
8
-      {props.mode === MODE.VIEW &&
8
+      {(props.mode === MODE.VIEW || props.mode === MODE.REVISION) &&
9 9
         <div>
10 10
           <div className='html-documents__contentpage__textnote__latestversion' dangerouslySetInnerHTML={{__html: props.version}} />
11 11
           <div className='html-documents__contentpage__textnote__text' dangerouslySetInnerHTML={{__html: props.text}} />

+ 50 - 21
src/container/HtmlDocument.jsx View File

@@ -6,7 +6,10 @@ import {
6 6
   PopinFixedHeader,
7 7
   PopinFixedOption,
8 8
   PopinFixedContent,
9
-  Timeline
9
+  Timeline,
10
+  NewVersionBtn,
11
+  ArchiveDeleteContent,
12
+  SelectStatus
10 13
 } from 'tracim_lib'
11 14
 import { FETCH_CONFIG, MODE, debug } from '../helper.js'
12 15
 import i18n from '../i18n.js'
@@ -88,15 +91,17 @@ class HtmlDocument extends React.Component {
88 91
     ])
89 92
       .then(([resComment, resRevision]) => {
90 93
         const resCommentWithProperDate = resComment.body.map(c => ({...c, created: (new Date(c.created)).toLocaleString()}))
94
+
91 95
         const revisionWithComment = resRevision.body
92
-          .map(r => ({
96
+          .map((r, i) => ({
93 97
             ...r,
94 98
             created: (new Date(r.created)).toLocaleString(),
95 99
             timelineType: 'revision',
96 100
             commentList: r.comments_ids.map(ci => ({
97 101
               timelineType: 'comment',
98 102
               ...resCommentWithProperDate.find(c => c.content_id === ci)
99
-            }))
103
+            })),
104
+            number: i + 1
100 105
           }))
101 106
           .reduce((acc, rev) => [
102 107
             ...acc,
@@ -108,8 +113,6 @@ class HtmlDocument extends React.Component {
108 113
             }))
109 114
           ], [])
110 115
 
111
-        console.log(revisionWithComment)
112
-
113 116
         this.setState({timeline: revisionWithComment})
114 117
       })
115 118
       .catch(e => {
@@ -204,9 +207,7 @@ class HtmlDocument extends React.Component {
204 207
     const fetchResultSaveEditStatus = await fetch(`${config.apiUrl}/workspaces/${content.workspace_id}/html-documents/${content.content_id}/status`, {
205 208
       ...FETCH_CONFIG,
206 209
       method: 'PUT',
207
-      body: JSON.stringify({
208
-        status: newStatus
209
-      })
210
+      body: JSON.stringify({status: newStatus})
210 211
     })
211 212
 
212 213
     handleFetchResult(fetchResultSaveEditStatus)
@@ -228,6 +229,7 @@ class HtmlDocument extends React.Component {
228 229
     //   method: 'PUT'
229 230
     // })
230 231
   }
232
+
231 233
   handleClickDelete = async () => {
232 234
     console.log('delete')
233 235
     // const { config, content } = this.state
@@ -237,8 +239,21 @@ class HtmlDocument extends React.Component {
237 239
     // })
238 240
   }
239 241
 
242
+  handleClickShowRevision = revision => {
243
+    console.log('revision', revision)
244
+    this.setState(prev => ({
245
+      content: {
246
+        ...prev.content,
247
+        label: revision.label,
248
+        raw_content: revision.raw_content,
249
+        number: revision.number
250
+      },
251
+      mode: MODE.REVISION
252
+    }))
253
+  }
254
+
240 255
   render () {
241
-    const { isVisible, loggedUser, content, timeline, newComment, timelineWysiwyg, config } = this.state
256
+    const { isVisible, loggedUser, content, timeline, newComment, timelineWysiwyg, config, mode } = this.state
242 257
 
243 258
     if (!isVisible) return null
244 259
 
@@ -252,24 +267,36 @@ class HtmlDocument extends React.Component {
252 267
           onValidateChangeTitle={this.handleSaveEditTitle}
253 268
         />
254 269
 
255
-        <PopinFixedOption
256
-          customClass={`${config.slug}`}
257
-          availableStatus={config.availableStatuses}
258
-          onClickNewVersionBtn={this.handleClickNewVersion}
259
-          onChangeStatus={this.handleChangeStatus}
260
-          selectedStatus={config.availableStatuses.find(s => s.slug === content.status)} // might be empty while api hasn't responded yet
261
-          onClickArchive={this.handleClickArchive}
262
-          onClickDelete={this.handleClickDelete}
263
-          i18n={i18n}
264
-        />
270
+        <PopinFixedOption customClass={`${config.slug}`} i18n={i18n}>
271
+          <div>
272
+            <NewVersionBtn onClickNewVersionBtn={this.handleClickNewVersion} disabled={mode === MODE.REVISION} />
273
+
274
+            <SelectStatus
275
+              selectedStatus={config.availableStatuses.find(s => s.slug === content.status)}
276
+              availableStatus={config.availableStatuses}
277
+              onChangeStatus={this.handleChangeStatus}
278
+              disabled={mode === MODE.REVISION}
279
+            />
280
+
281
+            <ArchiveDeleteContent
282
+              onClickArchiveBtn={this.handleClickArchive}
283
+              onClickDeleteBtn={this.handleClickDelete}
284
+              disabled={mode === MODE.REVISION}
285
+            />
286
+          </div>
287
+        </PopinFixedOption>
265 288
 
266 289
         <PopinFixedContent customClass={`${config.slug}__contentpage`}>
267 290
           <HtmlDocumentComponent
268
-            mode={this.state.mode}
291
+            mode={mode}
269 292
             wysiwygNewVersion={'wysiwygNewVersion'}
270 293
             onClickCloseEditMode={this.handleCloseNewVersion}
271 294
             onClickValidateBtn={this.handleSaveHtmlDocument}
272
-            version={timeline.filter(t => t.timelineType === 'revision').length}
295
+            version={
296
+              mode === MODE.REVISION
297
+                ? content.number
298
+                : timeline.filter(t => t.timelineType === 'revision').length
299
+            }
273 300
             text={content.raw_content}
274 301
             onChangeText={this.handleChangeText}
275 302
             key={'html-documents'}
@@ -280,10 +307,12 @@ class HtmlDocument extends React.Component {
280 307
             loggedUser={loggedUser}
281 308
             timelineData={timeline}
282 309
             newComment={newComment}
310
+            disableComment={mode === MODE.REVISION}
283 311
             wysiwyg={timelineWysiwyg}
284 312
             onChangeNewComment={this.handleChangeNewComment}
285 313
             onClickValidateNewCommentBtn={this.handleClickValidateNewCommentBtn}
286 314
             onClickWysiwygBtn={this.handleToggleWysiwyg}
315
+            onClickRevisionBtn={this.handleClickShowRevision}
287 316
           />
288 317
         </PopinFixedContent>
289 318
       </PopinFixed>

+ 2 - 1
src/helper.js View File

@@ -10,7 +10,8 @@ export const FETCH_CONFIG = {
10 10
 
11 11
 export const MODE = {
12 12
   VIEW: 'view',
13
-  EDIT: 'edit'
13
+  EDIT: 'edit',
14
+  REVISION: 'revision'
14 15
 }
15 16
 
16 17
 export const debug = {