|
@@ -14,20 +14,20 @@ import i18n from '../i18n.js'
|
14
|
14
|
|
15
|
15
|
const debug = {
|
16
|
16
|
config: {
|
17
|
|
- name: 'PageHtml',
|
18
|
|
- label: {
|
19
|
|
- fr: 'Page Html',
|
20
|
|
- en: 'Html page'
|
21
|
|
- },
|
22
|
|
- componentLeft: 'PageHtml',
|
23
|
|
- componentRight: 'Timeline',
|
24
|
|
- customClass: 'wsContentPageHtml',
|
25
|
|
- icon: 'fa fa-file-text-o',
|
26
|
|
- color: '#fdfdfd',
|
|
17
|
+ label: 'Text Document',
|
|
18
|
+ slug: 'page',
|
|
19
|
+ faIcon: 'file-text-o',
|
|
20
|
+ hexcolor: '#3f52e3',
|
|
21
|
+ creationLabel: 'Write a document',
|
27
|
22
|
domContainer: 'appContainer',
|
28
|
|
- mockApiUrl: 'http://localhost:3001'
|
|
23
|
+ apiUrl: 'localhost:6543/api/v2',
|
|
24
|
+ mockApiUrl: 'localhost:3001',
|
|
25
|
+ apiHeader: {
|
|
26
|
+ 'Accept': 'application/json',
|
|
27
|
+ 'Content-Type': 'application/json'
|
|
28
|
+ // 'Authorization': 'Basic ' + btoa(`${'admin@admin.admin'}:${'admin@admin.admin'}`)
|
|
29
|
+ }
|
29
|
30
|
},
|
30
|
|
- contentAction: 'showContent',
|
31
|
31
|
loggedUser: {
|
32
|
32
|
id: 5,
|
33
|
33
|
username: 'Smoi',
|
|
@@ -37,17 +37,31 @@ const debug = {
|
37
|
37
|
avatar: 'https://avatars3.githubusercontent.com/u/11177014?s=460&v=4'
|
38
|
38
|
},
|
39
|
39
|
content: {
|
40
|
|
- id: -1,
|
41
|
|
- type: 'pageHtml',
|
42
|
|
- title: 'Test debug pageHtml',
|
43
|
|
- status: 'validated',
|
44
|
|
- version: 'version n°1',
|
45
|
|
- text: 'This is the default pageHtml content for debug purpose',
|
46
|
|
- workspace: {
|
47
|
|
- id: -1,
|
48
|
|
- title: 'Test debug workspace',
|
49
|
|
- ownerId: 5
|
50
|
|
- }
|
|
40
|
+ author: {
|
|
41
|
+ avatar_url: null,
|
|
42
|
+ public_name: 'Global manager',
|
|
43
|
+ user_id: 1
|
|
44
|
+ },
|
|
45
|
+ content_id: -1,
|
|
46
|
+ content_type: 'page',
|
|
47
|
+ created: '2018-06-18T14:59:26Z',
|
|
48
|
+ current_revision_id: 11,
|
|
49
|
+ is_archived: false,
|
|
50
|
+ is_deleted: false,
|
|
51
|
+ label: 'Current Menu',
|
|
52
|
+ last_modifier: {
|
|
53
|
+ avatar_url: null,
|
|
54
|
+ public_name: 'Global manager',
|
|
55
|
+ user_id: 1
|
|
56
|
+ },
|
|
57
|
+ modified: '2018-06-18T14:59:26Z',
|
|
58
|
+ parent_id: 2,
|
|
59
|
+ raw_content: '<div>bonjour, je suis un lapin.</div>',
|
|
60
|
+ show_in_ui: true,
|
|
61
|
+ slug: 'current-menu',
|
|
62
|
+ status: 'open',
|
|
63
|
+ sub_content_types: ['thread', 'page', 'file', 'folder'],
|
|
64
|
+ workspace_id: 1
|
51
|
65
|
},
|
52
|
66
|
timeline: timelineDebugData
|
53
|
67
|
}
|
|
@@ -56,7 +70,7 @@ class pageHtml extends React.Component {
|
56
|
70
|
constructor (props) {
|
57
|
71
|
super(props)
|
58
|
72
|
this.state = {
|
59
|
|
- appName: 'PageHtml',
|
|
73
|
+ appName: 'page',
|
60
|
74
|
isVisible: true,
|
61
|
75
|
config: props.data ? props.data.config : debug.config,
|
62
|
76
|
loggedUser: props.data ? props.data.loggedUser : debug.loggedUser,
|
|
@@ -70,37 +84,67 @@ class pageHtml extends React.Component {
|
70
|
84
|
|
71
|
85
|
customEventReducer = ({ detail: { type, data } }) => { // action: { type: '', data: {} }
|
72
|
86
|
switch (type) {
|
73
|
|
- case 'PageHtml_showApp':
|
|
87
|
+ case 'page_showApp':
|
74
|
88
|
this.setState({isVisible: true})
|
75
|
89
|
break
|
76
|
|
- case 'PageHtml_hideApp':
|
|
90
|
+ case 'page_hideApp':
|
77
|
91
|
this.setState({isVisible: false})
|
78
|
92
|
break
|
|
93
|
+ case 'page_reloadContent':
|
|
94
|
+ this.setState({content: data})
|
79
|
95
|
}
|
80
|
96
|
}
|
81
|
97
|
|
82
|
|
- async componentDidMount () {
|
|
98
|
+ componentDidMount () {
|
|
99
|
+ console.log('pageHtml did mount')
|
|
100
|
+ if (this.state.content.content_id === -1) return // debug case
|
|
101
|
+
|
|
102
|
+ this.loadContent()
|
|
103
|
+ // wysiwyg()
|
|
104
|
+ }
|
|
105
|
+
|
|
106
|
+ componentDidUpdate (prevProps, prevState) {
|
|
107
|
+ console.log('pageHtml did update', prevState, this.state)
|
|
108
|
+ if (!prevState.content || !this.state.content) return
|
|
109
|
+
|
|
110
|
+ if (prevState.content.content_id !== this.state.content.content_id) {
|
|
111
|
+ this.loadContent()
|
|
112
|
+ }
|
|
113
|
+ }
|
|
114
|
+
|
|
115
|
+ loadContent = async () => {
|
|
116
|
+ console.log('loadContent')
|
83
|
117
|
const { content, config } = this.state
|
84
|
|
- if (content.id === '-1') return // debug case
|
85
|
118
|
|
86
|
|
- const fetchResultPageHtml = await fetch(`${config.mockApiUrl}/workspace/${content.workspace.id}/content/${content.id}`, {
|
|
119
|
+ const fetchResultPageHtml = await fetch(`${config.apiUrl}/workspaces/${content.workspace_id}/html-documents/${content.content_id}`, {
|
87
|
120
|
...FETCH_CONFIG,
|
88
|
121
|
method: 'GET'
|
89
|
122
|
})
|
90
|
|
- const fetchResultTimeline = await fetch(`${config.mockApiUrl}/workspace/${content.workspace.id}/content/${content.id}/timeline`, {
|
|
123
|
+ const fetchResultTimeline = await fetch(`${config.apiUrl}/workspaces/${content.workspace_id}/contents/${content.content_id}/comments`, {
|
91
|
124
|
...FETCH_CONFIG,
|
92
|
125
|
method: 'GET'
|
93
|
126
|
})
|
94
|
127
|
|
95
|
|
- fetchResultPageHtml.json = await handleFetchResult(fetchResultPageHtml)
|
96
|
|
- fetchResultTimeline.json = await handleFetchResult(fetchResultTimeline)
|
97
|
|
-
|
98
|
|
- this.setState({
|
99
|
|
- content: fetchResultPageHtml.json,
|
100
|
|
- timeline: fetchResultTimeline.json
|
101
|
|
- })
|
102
|
|
-
|
103
|
|
- // wysiwyg()
|
|
128
|
+ // Promise.all([
|
|
129
|
+ // handleFetchResult(fetchResultPageHtml),
|
|
130
|
+ // handleFetchResult(fetchResultTimeline)
|
|
131
|
+ // ])
|
|
132
|
+ // .then(([resPageHtml, resTimeline]) => {
|
|
133
|
+ // this.setState({
|
|
134
|
+ // content: resPageHtml,
|
|
135
|
+ // timeline: resTimeline
|
|
136
|
+ // })
|
|
137
|
+ // })
|
|
138
|
+ handleFetchResult(fetchResultPageHtml)
|
|
139
|
+ .then(resPageHtml => this.setState({content: resPageHtml}))
|
|
140
|
+ .catch(e => console.log('Error loading content.', e))
|
|
141
|
+
|
|
142
|
+ handleFetchResult(fetchResultTimeline)
|
|
143
|
+ .then(resTimeline => this.setState({timeline: resTimeline}))
|
|
144
|
+ .catch(e => {
|
|
145
|
+ console.log('Error loading Timeline.', e)
|
|
146
|
+ this.setState({timeline: []})
|
|
147
|
+ })
|
104
|
148
|
}
|
105
|
149
|
|
106
|
150
|
handleClickBtnCloseApp = () => {
|
|
@@ -124,32 +168,32 @@ class pageHtml extends React.Component {
|
124
|
168
|
if (!isVisible) return null
|
125
|
169
|
|
126
|
170
|
return (
|
127
|
|
- <PopinFixed customClass={`${config.customClass}`}>
|
|
171
|
+ <PopinFixed customClass={`${config.slug}`}>
|
128
|
172
|
<PopinFixedHeader
|
129
|
|
- customClass={`${config.customClass}`}
|
130
|
|
- icon={config.icon}
|
131
|
|
- name={content.title}
|
|
173
|
+ customClass={`${config.slug}`}
|
|
174
|
+ icon={config.faIcon}
|
|
175
|
+ name={content.label}
|
132
|
176
|
onClickCloseBtn={this.handleClickBtnCloseApp}
|
133
|
177
|
onChangeTitle={this.handleChangeTitle}
|
134
|
178
|
/>
|
135
|
179
|
|
136
|
180
|
<PopinFixedOption
|
137
|
|
- customClass={`${config.customClass}`}
|
|
181
|
+ customClass={`${config.slug}`}
|
138
|
182
|
onClickNewVersionBtn={this.handleClickNewVersion}
|
139
|
183
|
i18n={i18n}
|
140
|
184
|
/>
|
141
|
185
|
|
142
|
|
- <PopinFixedContent customClass={`${config.customClass}__contentpage`}>
|
|
186
|
+ <PopinFixedContent customClass={`${config.slug}__contentpage`}>
|
143
|
187
|
<PageHtmlComponent
|
144
|
188
|
mode={this.state.mode}
|
145
|
189
|
onClickCloseEditMode={this.handleCloseNewVersion}
|
146
|
|
- version={content.version}
|
147
|
|
- text={content.text}
|
148
|
|
- key={'PageHtml'}
|
|
190
|
+ version={content.current_revision_id}
|
|
191
|
+ text={content.raw_content}
|
|
192
|
+ key={'html-documents'}
|
149
|
193
|
/>
|
150
|
194
|
|
151
|
195
|
<Timeline
|
152
|
|
- customClass={`${config.customClass}__contentpage`}
|
|
196
|
+ customClass={`${config.slug}__contentpage`}
|
153
|
197
|
loggedUser={loggedUser}
|
154
|
198
|
timelineData={timeline}
|
155
|
199
|
/>
|