Skylsmoi преди 6 години
родител
ревизия
700f81124a
променени са 3 файла, в които са добавени 53 реда и са изтрити 23 реда
  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 Целия файл

5
 const HtmlDocument = props => {
5
 const HtmlDocument = props => {
6
   return (
6
   return (
7
     <div className='wsContentHtmlDocument__contentpage__textnote html-documents__contentpage__textnote'>
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
         <div>
9
         <div>
10
           <div className='html-documents__contentpage__textnote__latestversion' dangerouslySetInnerHTML={{__html: props.version}} />
10
           <div className='html-documents__contentpage__textnote__latestversion' dangerouslySetInnerHTML={{__html: props.version}} />
11
           <div className='html-documents__contentpage__textnote__text' dangerouslySetInnerHTML={{__html: props.text}} />
11
           <div className='html-documents__contentpage__textnote__text' dangerouslySetInnerHTML={{__html: props.text}} />

+ 50 - 21
src/container/HtmlDocument.jsx Целия файл

6
   PopinFixedHeader,
6
   PopinFixedHeader,
7
   PopinFixedOption,
7
   PopinFixedOption,
8
   PopinFixedContent,
8
   PopinFixedContent,
9
-  Timeline
9
+  Timeline,
10
+  NewVersionBtn,
11
+  ArchiveDeleteContent,
12
+  SelectStatus
10
 } from 'tracim_lib'
13
 } from 'tracim_lib'
11
 import { FETCH_CONFIG, MODE, debug } from '../helper.js'
14
 import { FETCH_CONFIG, MODE, debug } from '../helper.js'
12
 import i18n from '../i18n.js'
15
 import i18n from '../i18n.js'
88
     ])
91
     ])
89
       .then(([resComment, resRevision]) => {
92
       .then(([resComment, resRevision]) => {
90
         const resCommentWithProperDate = resComment.body.map(c => ({...c, created: (new Date(c.created)).toLocaleString()}))
93
         const resCommentWithProperDate = resComment.body.map(c => ({...c, created: (new Date(c.created)).toLocaleString()}))
94
+
91
         const revisionWithComment = resRevision.body
95
         const revisionWithComment = resRevision.body
92
-          .map(r => ({
96
+          .map((r, i) => ({
93
             ...r,
97
             ...r,
94
             created: (new Date(r.created)).toLocaleString(),
98
             created: (new Date(r.created)).toLocaleString(),
95
             timelineType: 'revision',
99
             timelineType: 'revision',
96
             commentList: r.comments_ids.map(ci => ({
100
             commentList: r.comments_ids.map(ci => ({
97
               timelineType: 'comment',
101
               timelineType: 'comment',
98
               ...resCommentWithProperDate.find(c => c.content_id === ci)
102
               ...resCommentWithProperDate.find(c => c.content_id === ci)
99
-            }))
103
+            })),
104
+            number: i + 1
100
           }))
105
           }))
101
           .reduce((acc, rev) => [
106
           .reduce((acc, rev) => [
102
             ...acc,
107
             ...acc,
108
             }))
113
             }))
109
           ], [])
114
           ], [])
110
 
115
 
111
-        console.log(revisionWithComment)
112
-
113
         this.setState({timeline: revisionWithComment})
116
         this.setState({timeline: revisionWithComment})
114
       })
117
       })
115
       .catch(e => {
118
       .catch(e => {
204
     const fetchResultSaveEditStatus = await fetch(`${config.apiUrl}/workspaces/${content.workspace_id}/html-documents/${content.content_id}/status`, {
207
     const fetchResultSaveEditStatus = await fetch(`${config.apiUrl}/workspaces/${content.workspace_id}/html-documents/${content.content_id}/status`, {
205
       ...FETCH_CONFIG,
208
       ...FETCH_CONFIG,
206
       method: 'PUT',
209
       method: 'PUT',
207
-      body: JSON.stringify({
208
-        status: newStatus
209
-      })
210
+      body: JSON.stringify({status: newStatus})
210
     })
211
     })
211
 
212
 
212
     handleFetchResult(fetchResultSaveEditStatus)
213
     handleFetchResult(fetchResultSaveEditStatus)
228
     //   method: 'PUT'
229
     //   method: 'PUT'
229
     // })
230
     // })
230
   }
231
   }
232
+
231
   handleClickDelete = async () => {
233
   handleClickDelete = async () => {
232
     console.log('delete')
234
     console.log('delete')
233
     // const { config, content } = this.state
235
     // const { config, content } = this.state
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
   render () {
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
     if (!isVisible) return null
258
     if (!isVisible) return null
244
 
259
 
252
           onValidateChangeTitle={this.handleSaveEditTitle}
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
         <PopinFixedContent customClass={`${config.slug}__contentpage`}>
289
         <PopinFixedContent customClass={`${config.slug}__contentpage`}>
267
           <HtmlDocumentComponent
290
           <HtmlDocumentComponent
268
-            mode={this.state.mode}
291
+            mode={mode}
269
             wysiwygNewVersion={'wysiwygNewVersion'}
292
             wysiwygNewVersion={'wysiwygNewVersion'}
270
             onClickCloseEditMode={this.handleCloseNewVersion}
293
             onClickCloseEditMode={this.handleCloseNewVersion}
271
             onClickValidateBtn={this.handleSaveHtmlDocument}
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
             text={content.raw_content}
300
             text={content.raw_content}
274
             onChangeText={this.handleChangeText}
301
             onChangeText={this.handleChangeText}
275
             key={'html-documents'}
302
             key={'html-documents'}
280
             loggedUser={loggedUser}
307
             loggedUser={loggedUser}
281
             timelineData={timeline}
308
             timelineData={timeline}
282
             newComment={newComment}
309
             newComment={newComment}
310
+            disableComment={mode === MODE.REVISION}
283
             wysiwyg={timelineWysiwyg}
311
             wysiwyg={timelineWysiwyg}
284
             onChangeNewComment={this.handleChangeNewComment}
312
             onChangeNewComment={this.handleChangeNewComment}
285
             onClickValidateNewCommentBtn={this.handleClickValidateNewCommentBtn}
313
             onClickValidateNewCommentBtn={this.handleClickValidateNewCommentBtn}
286
             onClickWysiwygBtn={this.handleToggleWysiwyg}
314
             onClickWysiwygBtn={this.handleToggleWysiwyg}
315
+            onClickRevisionBtn={this.handleClickShowRevision}
287
           />
316
           />
288
         </PopinFixedContent>
317
         </PopinFixedContent>
289
       </PopinFixed>
318
       </PopinFixed>

+ 2 - 1
src/helper.js Целия файл

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