Browse Source

added feature create new workspace

Skylsmoi 6 years ago
parent
commit
c69fa8c61f

+ 18 - 0
build_full_frontend.sh View File

@@ -53,6 +53,24 @@ log "cp i18next.scanner/fr/translation.json ../frontend/dist/app/thread_fr_trans
53 53
 cp i18next.scanner/fr/translation.json ../frontend/dist/app/thread_fr_translation.json
54 54
 cd -
55 55
 
56
+# app Workspace
57
+
58
+log "cd frontend_app_workspace"
59
+cd frontend_app_workspace
60
+
61
+log "npm run build$windoz # for frontend_app_workspace"
62
+npm run build$windoz
63
+
64
+log "cp dist/workspace.app.js"
65
+cp dist/workspace.app.js ../frontend/dist/app
66
+
67
+log "cp i18next.scanner/en/translation.json ../frontend/dist/app/workspace_en_translation.json"
68
+cp i18next.scanner/en/translation.json ../frontend/dist/app/workspace_en_translation.json
69
+
70
+log "cp i18next.scanner/fr/translation.json ../frontend/dist/app/workspace_fr_translation.json"
71
+cp i18next.scanner/fr/translation.json ../frontend/dist/app/workspace_fr_translation.json
72
+cd -
73
+
56 74
 # app Admin Workspace User
57 75
 
58 76
 log "cd frontend_app_admin_workspace_user"

+ 2 - 0
frontend/dist/appInterface.js View File

@@ -3,6 +3,8 @@
3 3
 
4 4
   getSelectedApp = name => {
5 5
     switch (name) {
6
+      case 'workspace':
7
+        return appWorkspace
6 8
       case 'html-document':
7 9
         return appHtmlDocument
8 10
       case 'thread':

+ 1 - 0
frontend/dist/index.html View File

@@ -51,6 +51,7 @@
51 51
     <script src='/tracim.vendor.bundle.js'></script>
52 52
     <script src='/tracim.app.entry.js'></script>
53 53
 
54
+    <script src='/app/workspace.app.js'></script>
54 55
     <script src='/app/html-document.app.js'></script>
55 56
     <script src='/app/thread.app.js'></script>
56 57
     <!-- <script src='/app/file.app.js'></script> -->

+ 35 - 14
frontend/src/container/Sidebar.jsx View File

@@ -3,6 +3,7 @@ import { connect } from 'react-redux'
3 3
 import { withRouter } from 'react-router'
4 4
 import classnames from 'classnames'
5 5
 import { translate } from 'react-i18next'
6
+import appFactory from '../appFactory.js'
6 7
 import WorkspaceListItem from '../component/Sidebar/WorkspaceListItem.jsx'
7 8
 import {
8 9
   setWorkspaceListIsOpenInSidebar,
@@ -12,7 +13,7 @@ import {
12 13
 import {
13 14
   getWorkspaceList
14 15
 } from '../action-creator.async.js'
15
-import { PAGE } from '../helper.js'
16
+import { PAGE, workspaceConfig } from '../helper.js'
16 17
 
17 18
 const qs = require('query-string')
18 19
 
@@ -23,22 +24,23 @@ class Sidebar extends React.Component {
23 24
       sidebarClose: false,
24 25
       workspaceIdInUrl: props.match.params.idws ? parseInt(props.match.params.idws) : null
25 26
     }
26
-  }
27
-
28
-  async componentDidMount () {
29
-    const { workspaceIdInUrl } = this.state
30
-    const { user, workspaceList, dispatch } = this.props
31 27
 
32
-    if (user.user_id !== -1 && workspaceList.length === 0) {
33
-      const fetchGetWorkspaceList = await dispatch(getWorkspaceList(user))
28
+    document.addEventListener('appCustomEvent', this.customEventReducer)
29
+  }
34 30
 
35
-      if (fetchGetWorkspaceList.status === 200) {
36
-        dispatch(updateWorkspaceListData(fetchGetWorkspaceList.json))
37
-        dispatch(setWorkspaceListIsOpenInSidebar(workspaceIdInUrl || fetchGetWorkspaceList.json[0].workspace_id, true))
38
-      }
31
+  customEventReducer = async ({ detail: { type, data } }) => {
32
+    switch (type) {
33
+      case 'refreshWorkspaceList':
34
+        console.log('%c<Sidebar> Custom event', 'color: #28a745', type, data)
35
+        this.loadWorkspaceList()
36
+        break
39 37
     }
40 38
   }
41 39
 
40
+  componentDidMount () {
41
+    this.loadWorkspaceList()
42
+  }
43
+
42 44
   componentDidUpdate (prevProps, prevState) {
43 45
     // console.log('%c<Sidebar> Did Update', 'color: #c17838')
44 46
     if (this.props.match.params.idws === undefined || isNaN(this.props.match.params.idws)) return
@@ -47,6 +49,20 @@ class Sidebar extends React.Component {
47 49
     if (prevState.workspaceIdInUrl !== newWorkspaceId) this.setState({workspaceIdInUrl: newWorkspaceId})
48 50
   }
49 51
 
52
+  loadWorkspaceList = async () => {
53
+    const { workspaceIdInUrl } = this.state
54
+    const { user, dispatch } = this.props
55
+
56
+    if (user.user_id !== -1) {
57
+      const fetchGetWorkspaceList = await dispatch(getWorkspaceList(user))
58
+
59
+      if (fetchGetWorkspaceList.status === 200) {
60
+        dispatch(updateWorkspaceListData(fetchGetWorkspaceList.json))
61
+        dispatch(setWorkspaceListIsOpenInSidebar(workspaceIdInUrl || fetchGetWorkspaceList.json[0].workspace_id, true))
62
+      }
63
+    }
64
+  }
65
+
50 66
   handleClickWorkspace = (idWs, newIsOpenInSidebar) => this.props.dispatch(setWorkspaceListIsOpenInSidebar(idWs, newIsOpenInSidebar))
51 67
 
52 68
   handleClickAllContent = idWs => {
@@ -70,6 +86,8 @@ class Sidebar extends React.Component {
70 86
 
71 87
   handleClickToggleSidebar = () => this.setState(prev => ({sidebarClose: !prev.sidebarClose}))
72 88
 
89
+  handleClickNewWorkspace = () => this.props.renderAppPopupCreation(workspaceConfig, this.props.user, null, null)
90
+
73 91
   render () {
74 92
     const { sidebarClose, workspaceIdInUrl } = this.state
75 93
     const { activeLang, workspaceList, t } = this.props
@@ -103,7 +121,10 @@ class Sidebar extends React.Component {
103 121
             </nav>
104 122
 
105 123
             <div className='sidebar__btnnewworkspace'>
106
-              <button className='sidebar__btnnewworkspace__btn btn btn-primary primaryColorBg primaryColorBorder primaryColorBorderDarkenHover mb-5'>
124
+              <button
125
+                className='sidebar__btnnewworkspace__btn btn btn-primary primaryColorBg primaryColorBorder primaryColorBorderDarkenHover mb-5'
126
+                onClick={this.handleClickNewWorkspace}
127
+              >
107 128
                 {t('Create a workspace')}
108 129
               </button>
109 130
             </div>
@@ -130,4 +151,4 @@ const mapStateToProps = ({ lang, user, workspace, workspaceList }) => ({
130 151
   workspace,
131 152
   workspaceList
132 153
 })
133
-export default withRouter(connect(mapStateToProps)(translate()(Sidebar)))
154
+export default withRouter(connect(mapStateToProps)(appFactory(translate()(Sidebar))))

+ 15 - 0
frontend/src/container/Tracim.jsx View File

@@ -28,6 +28,21 @@ import {
28 28
 import Cookies from 'js-cookie'
29 29
 
30 30
 class Tracim extends React.Component {
31
+  constructor (props) {
32
+    super(props)
33
+
34
+    document.addEventListener('appCustomEvent', this.customEventReducer)
35
+  }
36
+
37
+  customEventReducer = async ({ detail: { type, data } }) => {
38
+    switch (type) {
39
+      case 'redirect':
40
+        console.log('%c<Tracim> Custom event', 'color: #28a745', type, data)
41
+        this.props.history.push(data.url)
42
+        break
43
+    }
44
+  }
45
+
31 46
   async componentDidMount () {
32 47
     const { dispatch } = this.props
33 48
 

+ 9 - 0
frontend/src/helper.js View File

@@ -12,6 +12,15 @@ export const COOKIE = {
12 12
   USER_AUTH: 'user_auth'
13 13
 }
14 14
 
15
+// Côme - 2018/08/02 - shouldn't this come from api ?
16
+export const workspaceConfig = {
17
+  slug: 'workspace',
18
+  faIcon: 'space-shuttle',
19
+  hexcolor: '#7d4e24',
20
+  creationLabel: 'Create a workspace',
21
+  domContainer: 'appFeatureContainer'
22
+}
23
+
15 24
 export const PAGE = {
16 25
   HOME: '/',
17 26
   WORKSPACE: {

+ 2 - 3
frontend_app_workspace/src/container/PopupCreateWorkspace.jsx View File

@@ -10,7 +10,6 @@ import i18n from '../i18n.js'
10 10
 
11 11
 const debug = { // outdated
12 12
   config: {
13
-    // label: 'New Document',
14 13
     slug: 'workspace',
15 14
     faIcon: 'space-shuttle',
16 15
     hexcolor: '#7d4e24',
@@ -83,7 +82,7 @@ class PopupCreateWorkspace extends React.Component {
83 82
   handleValidate = async () => {
84 83
     const { loggedUser, config, newWorkspaceName } = this.state
85 84
 
86
-    const fetchSaveNewWorkspace = postWorkspace(loggedUser, config.apiUrl, config.slug, newWorkspaceName)
85
+    const fetchSaveNewWorkspace = postWorkspace(loggedUser, config.apiUrl, newWorkspaceName)
87 86
 
88 87
     handleFetchResult(await fetchSaveNewWorkspace)
89 88
       .then(resSave => {
@@ -95,7 +94,7 @@ class PopupCreateWorkspace extends React.Component {
95 94
           GLOBAL_dispatchEvent({
96 95
             type: 'redirect',
97 96
             data: {
98
-              url: `/workspaces/${resSave.json.workspace_id}`
97
+              url: `/workspaces/${resSave.body.workspace_id}/dashboard`
99 98
             }
100 99
           })
101 100
         }

+ 1 - 1
frontend_app_workspace/webpack.config.js View File

@@ -12,7 +12,7 @@ module.exports = {
12 12
     path: path.resolve(__dirname, 'dist'),
13 13
     filename: isProduction ? 'workspace.app.js' : 'workspace.app.dev.js',
14 14
     pathinfo: !isProduction,
15
-    library: isProduction ? 'workspace' : undefined,
15
+    library: isProduction ? 'appWorkspace' : undefined,
16 16
     libraryTarget: isProduction ? 'var' : undefined
17 17
   },
18 18
   externals: {},

+ 1 - 1
frontend_lib/src/component/CardPopup/CardPopupCreateContent.jsx View File

@@ -27,7 +27,7 @@ const PopupCreateContent = props => {
27 27
           <input
28 28
             type='text'
29 29
             className='createcontent__form__input'
30
-            placeHolder={props.inputPlaceholder}
30
+            placeholder={props.inputPlaceholder}
31 31
             value={props.contentName}
32 32
             onChange={props.onChangeContentName}
33 33
           />