Browse Source

allow apps to make their own api calls

Skylsmoi 6 years ago
parent
commit
040c7676d7

+ 15 - 6
dist/index.html View File

@@ -33,24 +33,33 @@
33 33
     <script src="./dev/bootstrap-4.0.0-beta.2.js"></script>
34 34
 
35 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 44
       GLOBAL_renderApp = app => {
37
-        switch (app.appData.name) {
45
+        switch (app.appConfig.name) {
38 46
           case 'PageHtml':
39
-            appPageHtml.renderApp('appContainer'); break
47
+            pageHtml.renderApp('appContainer', app); break
40 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 55
         document.dispatchEvent(event)
48 56
       }
49 57
 
50 58
       GLOBAL_unmountApp = appName => {
51 59
         switch (appName) {
52 60
           case 'PageHtml':
53
-            appPageHtml.hideApp('appContainer'); break
61
+            // pageHtml.hideApp('appContainer'); break
62
+            GLOBAL_dispatchEvent('PageHtml_hideApp', {})
54 63
           case 'Thread':
55 64
             appThread.hideApp('appContainer'); break
56 65
         }

+ 3 - 1
jsonserver/server.js View File

@@ -25,12 +25,14 @@ server.post('/user/login', (req, res) => {
25 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 30
 server.get('/user/is_logged_in', (req, res) => res.jsonp(jsonDb.user_logged))
31 31
 
32 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 36
 server.use(router)
35 37
 server.listen(GLOBAL_PORT, () => {
36 38
   console.log('JSON Server is running on port : ' + GLOBAL_PORT)

+ 11 - 5
jsonserver/static_db.json View File

@@ -9,7 +9,7 @@
9 9
       "email": "osef@algoo.fr"
10 10
     }
11 11
   },
12
-  "file_content": [{
12
+  "app_config": [{
13 13
     "name": "PageHtml",
14 14
     "componentLeft": "PageHtml",
15 15
     "componentRight": "Timeline",
@@ -55,13 +55,11 @@
55 55
         "id": 1,
56 56
         "title": "La programmation fonctionnelle",
57 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 61
         "id": 2,
64
-        "title": "La prommation fonctionnelle est-elle vraiment utile ?",
62
+        "title": "La programmation fonctionnelle est-elle vraiment utile ?",
65 63
         "type": "Thread",
66 64
         "status": "current"
67 65
       },
@@ -109,5 +107,13 @@
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 View File

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

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

@@ -26,10 +26,18 @@ class WorkspaceContent extends React.Component {
26 26
     this.props.dispatch(getAppList())
27 27
   }
28 28
 
29
-  handleClickFileItem = file => {
29
+  handleClickContentItem = content => {
30
+    const { workspace } = this.props
30 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,7 +68,7 @@ class WorkspaceContent extends React.Component {
60 68
                   type={c.type}
61 69
                   icon={(app[c.type] || {icon: ''}).icon}
62 70
                   status={c.status}
63
-                  onClickItem={() => this.handleClickFileItem(c)}
71
+                  onClickItem={() => this.handleClickContentItem(c)}
64 72
                   key={c.id}
65 73
                 />
66 74
               )