Skip to content

Commit c018569

Browse files
author
Yang Zhen
committed
Add default workspace
1 parent d4164f1 commit c018569

File tree

12 files changed

+176
-6
lines changed

12 files changed

+176
-6
lines changed

app/backendAPI/workspaceAPI.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,7 @@ export function requestCollaborator () {
5656
export function execShellCommand (command) {
5757
return request.post(`/tty/${config.spaceKey}/exec`, { command })
5858
}
59+
60+
export function getWorkspaceList () {
61+
return request.get('/workspaces?page=0&size=5&sort=lastModifiedDate,desc')
62+
}

app/commands/commandBindings/file.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ export function openFileWithEncoding ({ path, editor = {}, others = {}, allGroup
9191
})
9292
}
9393

94+
function createTab ({ icon, type }) {
95+
TabStore.createTab({
96+
icon,
97+
type,
98+
})
99+
}
100+
94101
function createFileWithContent (content) {
95102
return function createFileAtPath (path) {
96103
if (content) {
@@ -268,6 +275,13 @@ const fileCommands = {
268275
},
269276

270277
// 'file:unsaved_files_list':
278+
'file:open_welcome': (c) => {
279+
TabStore.createTab({
280+
icon: 'fa fa-info-circle',
281+
type: 'welcome',
282+
title: 'Welcome',
283+
})
284+
}
271285
}
272286

273287
export default fileCommands

app/components/Tab/TabContainer.jsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { TabBar, TabContent, TabContentItem } from 'commons/Tab'
77
import Editor from 'components/Editor'
88
import { TablessCodeEditor } from 'components/Editor/components/CodeEditor'
99
import i18n from 'utils/createI18n'
10+
import WelcomePage from './WelcomePage'
1011

1112
const contextMenuItems = [
1213
{
@@ -55,7 +56,7 @@ class TabContainer extends Component {
5556
<TabContent tabGroup={tabGroup} >
5657
{tabGroup.tabs.length ? tabGroup.tabs.map(tab =>
5758
<TabContentItem key={tab.id} tab={tab} >
58-
<Editor tab={tab} active={tab.isActive} />
59+
{this.renderContent(tab)}
5960
</TabContentItem>
6061
)
6162
: <TabContentItem tab={{ isActive: true }}>
@@ -66,6 +67,13 @@ class TabContainer extends Component {
6667
</div>
6768
)
6869
}
70+
71+
renderContent (tab) {
72+
if (tab.type === 'welcome') {
73+
return <WelcomePage />
74+
}
75+
return <Editor tab={tab} active={tab.isActive} />
76+
}
6977
}
7078

7179
export default TabContainer

app/components/Tab/WelcomePage.jsx

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
import _ from 'lodash'
2+
import React, { Component } from 'react'
3+
import PropTypes from 'prop-types'
4+
import cx from 'classnames'
5+
import { observer, inject } from 'mobx-react'
6+
import { observable } from 'mobx'
7+
import dispatchCommand from 'commands/dispatchCommand'
8+
import api from '../../backendAPI'
9+
10+
@observer
11+
class WelcomePage extends Component {
12+
constructor (props) {
13+
super(props)
14+
this.state = observable({
15+
recentList: []
16+
})
17+
}
18+
componentWillMount () {
19+
this.loadRecentWS()
20+
}
21+
22+
render () {
23+
return (
24+
<div className='welcome-page'>
25+
<h1>Coding WebIDE</h1>
26+
<div className='subtitle'>Coding Anytime Anywhere</div>
27+
28+
<h2>Start</h2>
29+
<div className='block start-block'>
30+
<div className='link-item'>
31+
<a href='#' onClick={this.createNewFile}>New File...</a>
32+
</div>
33+
<div className='link-item'>
34+
<a href='#' onClick={this.createNewFolder}>New Folder...</a>
35+
</div>
36+
</div>
37+
38+
<h2>Recent</h2>
39+
<div className='block recent-block'>
40+
{this.renderRecentItem()}
41+
</div>
42+
43+
<h2>Help</h2>
44+
<div className='block help-block'>
45+
<div className='link-item'>
46+
<a href='https://coding.net/help/doc/webide/' target='blank'>Document</a>
47+
</div>
48+
<div className='link-item'>
49+
<a href='https://coding.net/feedback' target='blank'>Feedback</a>
50+
</div>
51+
</div>
52+
</div>
53+
)
54+
}
55+
renderRecentItem () {
56+
return (
57+
<div className='recent-list'>
58+
{
59+
this.state.recentList.map((recentItem) => {
60+
return (
61+
<div className='recent-item' key={recentItem.name}>
62+
<a href={recentItem.link}>{recentItem.name}</a>
63+
</div>
64+
)
65+
})
66+
}
67+
</div>
68+
)
69+
}
70+
createNewFile (e) {
71+
e.preventDefault()
72+
dispatchCommand('file:new_file')
73+
}
74+
createNewFolder (e) {
75+
e.preventDefault()
76+
dispatchCommand('file:new_folder')
77+
}
78+
loadRecentWS () {
79+
api.getWorkspaceList().then((res) => {
80+
if (res.contents && res.contents.length > 0) {
81+
const recentList = []
82+
res.contents.forEach((ws) => {
83+
let name = ''
84+
if (ws.defaultWorkspace) {
85+
name = 'Default'
86+
} else {
87+
name = `${ws.project.ownerName}/${ws.project.name}`
88+
}
89+
const wsItem = {
90+
name,
91+
icon: '',
92+
link: `/ws/${ws.spaceKey}`,
93+
command: () => {
94+
window.open(`/ws/${ws.spaceKey}`)
95+
},
96+
}
97+
recentList.push(wsItem)
98+
})
99+
100+
this.state.recentList = recentList
101+
}
102+
})
103+
}
104+
105+
}
106+
107+
export default WelcomePage

app/components/Tab/state.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class Tab extends BaseTab {
1919
this.editorProps = props.editor
2020
this.update(props)
2121
this.saveFileList()
22+
this.type = props.type
2223
autorun(() => {
2324
if (!this.file) return
2425
this.flags.modified = !this.file.isSynced

app/containers/Root/actions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ export const initState = () => (dispatch) => {
2222
if (spaceKey) config.spaceKey = spaceKey
2323
}
2424
window.ide = ide
25-
dispatch({ type: INIT_STATE })
25+
// dispatch({ type: INIT_STATE })
2626
}

app/containers/Root/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Root extends Component {
1313
dispatch: PropTypes.func
1414
}
1515
componentWillMount () {
16-
this.props.dispatch(initState()) // initLifecycle_2
16+
// this.props.dispatch(initState()) // initLifecycle_2
1717
}
1818
render () {
1919
return <IDE />

app/styles/core-ui/Welcome.styl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
.welcome-page {
2+
color: $text-color;
3+
padding: 10px 40px;
4+
h1 {
5+
font-weight: normal;
6+
padding: 0;
7+
margin: 0;
8+
}
9+
.subtitle {
10+
font-size: 1.4em;
11+
padding-top: 10px;
12+
color: $text-color-subtle;
13+
padding-bottom: 40px;
14+
}
15+
h2 {
16+
font-weight: normal;
17+
padding: 0;
18+
margin: 0;
19+
font-size: 1.2em;
20+
padding-bottom: 6px;
21+
}
22+
.block {
23+
padding-bottom: 40px;
24+
}
25+
.link-item {
26+
27+
}
28+
}

app/styles/core-ui/index.styl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@
2222
@import "./Editor";
2323
@import "./Offline";
2424
@import "./FileList";
25-
@import "./Tooltip"
25+
@import "./Tooltip";
26+
@import "./Welcome";

app/styles/dark/index.styl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414
@import './styles/filelist';
1515
@import './styles/base';
1616

17-
1817
// 插件用样式
1918
@import './styles/weapp';
2019
@import './styles/collaborators';
2120
@import './styles/env';
2221
@import './styles/access';
2322
@import './styles/java';
23+
24+
@import './styles/welcome';

0 commit comments

Comments
 (0)