Sfoglia il codice sorgente

allow apps to make their own api calls

Skylsmoi 6 anni fa
parent
commit
040c7676d7

+ 15 - 6
dist/index.html Vedi File

33
     <script src="./dev/bootstrap-4.0.0-beta.2.js"></script>
33
     <script src="./dev/bootstrap-4.0.0-beta.2.js"></script>
34
 
34
 
35
     <script type='text/javascript'>
35
     <script type='text/javascript'>
36
+      const pageHtml = new appPageHtml()
37
+
38
+      /*
39
+        app: {
40
+          content: {id, type, title, status}, // version and/or text are useless for Tracim, only useful for app
41
+          appConfig: {name, componentLeft, componentRight, customClass, icon}
42
+        }
43
+      */
36
       GLOBAL_renderApp = app => {
44
       GLOBAL_renderApp = app => {
37
-        switch (app.appData.name) {
45
+        switch (app.appConfig.name) {
38
           case 'PageHtml':
46
           case 'PageHtml':
39
-            appPageHtml.renderApp('appContainer'); break
47
+            pageHtml.renderApp('appContainer', app); break
40
           case 'Thread':
48
           case 'Thread':
41
-            appThread.renderApp('appContainer'); break
49
+            appThread.renderApp('appContainer', app); break
42
         }
50
         }
43
       }
51
       }
44
 
52
 
45
-      GLOBAL_dispatchEvent = (data) => {
46
-        var event = new CustomEvent('appCustomEvent', {detail: data})
53
+      GLOBAL_dispatchEvent = (type, data) => {
54
+        var event = new CustomEvent('appCustomEvent', {type, data})
47
         document.dispatchEvent(event)
55
         document.dispatchEvent(event)
48
       }
56
       }
49
 
57
 
50
       GLOBAL_unmountApp = appName => {
58
       GLOBAL_unmountApp = appName => {
51
         switch (appName) {
59
         switch (appName) {
52
           case 'PageHtml':
60
           case 'PageHtml':
53
-            appPageHtml.hideApp('appContainer'); break
61
+            // pageHtml.hideApp('appContainer'); break
62
+            GLOBAL_dispatchEvent('PageHtml_hideApp', {})
54
           case 'Thread':
63
           case 'Thread':
55
             appThread.hideApp('appContainer'); break
64
             appThread.hideApp('appContainer'); break
56
         }
65
         }

+ 3 - 1
jsonserver/server.js Vedi File

25
   else return res.jsonp('error')
25
   else return res.jsonp('error')
26
 })
26
 })
27
 
27
 
28
-server.get('/app/file_content', (req, res) => res.jsonp(jsonDb.file_content))
28
+server.get('/app/config', (req, res) => res.jsonp(jsonDb.app_config))
29
 
29
 
30
 server.get('/user/is_logged_in', (req, res) => res.jsonp(jsonDb.user_logged))
30
 server.get('/user/is_logged_in', (req, res) => res.jsonp(jsonDb.user_logged))
31
 
31
 
32
 server.get('/workspace/:id', (req, res) => res.jsonp(jsonDb.workspace_detail))
32
 server.get('/workspace/:id', (req, res) => res.jsonp(jsonDb.workspace_detail))
33
 
33
 
34
+server.get('/workspace/:idws/content/:idc', (req, res) => res.jsonp(jsonDb.content_data))
35
+
34
 server.use(router)
36
 server.use(router)
35
 server.listen(GLOBAL_PORT, () => {
37
 server.listen(GLOBAL_PORT, () => {
36
   console.log('JSON Server is running on port : ' + GLOBAL_PORT)
38
   console.log('JSON Server is running on port : ' + GLOBAL_PORT)

+ 11 - 5
jsonserver/static_db.json Vedi File

9
       "email": "osef@algoo.fr"
9
       "email": "osef@algoo.fr"
10
     }
10
     }
11
   },
11
   },
12
-  "file_content": [{
12
+  "app_config": [{
13
     "name": "PageHtml",
13
     "name": "PageHtml",
14
     "componentLeft": "PageHtml",
14
     "componentLeft": "PageHtml",
15
     "componentRight": "Timeline",
15
     "componentRight": "Timeline",
55
         "id": 1,
55
         "id": 1,
56
         "title": "La programmation fonctionnelle",
56
         "title": "La programmation fonctionnelle",
57
         "type": "PageHtml",
57
         "type": "PageHtml",
58
-        "status": "validated",
59
-        "version": "3",
60
-        "text": "<h1>Mon titre nul</h1>Je suis le contenu de cette fameuse <b>page HTML</b><br /> sur la programmation fonctionnelle"
58
+        "status": "validated"
61
       },
59
       },
62
       {
60
       {
63
         "id": 2,
61
         "id": 2,
64
-        "title": "La prommation fonctionnelle est-elle vraiment utile ?",
62
+        "title": "La programmation fonctionnelle est-elle vraiment utile ?",
65
         "type": "Thread",
63
         "type": "Thread",
66
         "status": "current"
64
         "status": "current"
67
       },
65
       },
109
         ]
107
         ]
110
       }
108
       }
111
     ]
109
     ]
110
+  },
111
+  "content_data": {
112
+    "id": "1",
113
+    "type": "pageHtml",
114
+    "title": "La programmation fonctionnelle",
115
+    "status": "validated",
116
+    "version": "3",
117
+    "text": "<h1>Mon titre nul</h1>Je suis le contenu de cette fameuse <b>page HTML</b><br /> sur la programmation fonctionnelle"
112
   }
118
   }
113
 }
119
 }

+ 1 - 1
src/action-creator.async.js Vedi File

119
 
119
 
120
 export const getAppList = () => async dispatch => {
120
 export const getAppList = () => async dispatch => {
121
   const fetchGetAppList = await fetchWrapper({
121
   const fetchGetAppList = await fetchWrapper({
122
-    url: `http://localhost:3001/app/file_content`,
122
+    url: `http://localhost:3001/app/config`,
123
     param: {...FETCH_CONFIG, method: 'GET'},
123
     param: {...FETCH_CONFIG, method: 'GET'},
124
     actionName: APP_LIST,
124
     actionName: APP_LIST,
125
     dispatch
125
     dispatch

+ 12 - 4
src/container/WorkspaceContent.jsx Vedi File

26
     this.props.dispatch(getAppList())
26
     this.props.dispatch(getAppList())
27
   }
27
   }
28
 
28
 
29
-  handleClickFileItem = file => {
29
+  handleClickContentItem = content => {
30
+    const { workspace } = this.props
30
     GLOBAL_renderApp({
31
     GLOBAL_renderApp({
31
-      file,
32
-      appData: this.props.app[file.type]
32
+      workspace: {
33
+        id: workspace.id,
34
+        title: workspace.title
35
+      },
36
+      content,
37
+      appConfig: {
38
+        ...this.props.app[content.type],
39
+        apiUrl: 'http://localhost:3001'
40
+      }
33
     })
41
     })
34
   }
42
   }
35
 
43
 
60
                   type={c.type}
68
                   type={c.type}
61
                   icon={(app[c.type] || {icon: ''}).icon}
69
                   icon={(app[c.type] || {icon: ''}).icon}
62
                   status={c.status}
70
                   status={c.status}
63
-                  onClickItem={() => this.handleClickFileItem(c)}
71
+                  onClickItem={() => this.handleClickContentItem(c)}
64
                   key={c.id}
72
                   key={c.id}
65
                 />
73
                 />
66
               )
74
               )