Skip to content

Commit afdb755

Browse files
authored
Merge pull request #95 from Coding/zhengxinqi/plugin_lists_view
fixes coding/WebIDE#155
2 parents 95ba033 + ddafa46 commit afdb755

File tree

10 files changed

+164
-79
lines changed

10 files changed

+164
-79
lines changed

app/commands/commandBindings/misc.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ export default {
1919
'global:show_settings': c => {
2020
$d(Modal.showModal({type: 'Settings', position: 'center'}))
2121
},
22-
'global:show_packages': c => {
23-
$d(Modal.showModal({type: 'Packages', position: 'center'}))
24-
},
2522
'global:show_branches': () => {
2623
getComponentByName('GitBranchWidget').openGitBranches()
2724
},

app/commands/keymaps.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export default {
1616
'cmd+alt+shift+3': 'editor:split_pane_horizontal_3',
1717
'cmd+alt+4': 'editor:split_pane_vertical_4',
1818
'cmd+comma': 'global:show_settings',
19-
'cmd+0': 'global:show_packages',
2019
'alt+b': 'global:show_branches',
2120
}
2221

app/components/Modal/index.jsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import {
2323
GitRebaseInput,
2424
GitCommitDiffView,
2525
GitCheckoutView,
26-
PackageControlView
2726
} from './modals'
2827

2928
var ModalContainer = (props) => {
@@ -117,9 +116,6 @@ class Modal extends Component {
117116
case 'Settings':
118117
return <SettingsView {...this.props} />
119118

120-
case 'Packages':
121-
return <PackageControlView {...this.props} />
122-
123119
default:
124120
return content
125121
}

app/components/Package/PackageControlView.js

Lines changed: 0 additions & 67 deletions
This file was deleted.

app/components/Package/actions.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export const togglePackage = createAction(PACKAGE_TOGGLE, (pkgId, shouldEnable)
4242
})
4343
})
4444

45-
export const fetchPackage = (pkgId, pkgVersion) => (dispatch) => {
45+
export const fetchPackage = (pkgId, pkgVersion, others) => (dispatch) => {
4646
const pkgInfo = api.fetchPackageInfo(pkgId, pkgVersion).then(pkg => pkg.codingIdePackage)
4747
const pkgScript = api.fetchPackageScript(pkgId, pkgVersion)
4848
.then(script => {
@@ -52,8 +52,10 @@ export const fetchPackage = (pkgId, pkgVersion) => (dispatch) => {
5252

5353
if (window.extensions[pkgId]) dispatch(togglePackage(pkgId, false))
5454
Promise.all([pkgInfo, pkgScript]).then(([pkg, id]) => {
55+
console.log('pkg', pkg);
5556
dispatch(updateLocalPackage({
5657
...pkg,
58+
...others,
5759
enabled: Boolean(window.extensions[pkgId]),
5860
id
5961
}))
@@ -68,6 +70,6 @@ export const preloadRequirePackages = () => dispatch => {
6870
api.fetchPackageList()
6971
.then(list => list.filter(pkg => pkg.requirement === 'Required'))
7072
.then(list => list.forEach(pkg => {
71-
dispatch(fetchPackage(pkg.name, pkg.version))
73+
dispatch(fetchPackage(pkg.name, pkg.version, pkg))
7274
}))
7375
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import React, { Component, PropTypes } from 'react';
2+
import { connect } from 'react-redux';
3+
import { togglePackage, fetchPackageList } from './actions';
4+
const Card = (props) => {
5+
return (
6+
<div className="card">
7+
<div className="title">
8+
{props.name}
9+
<span>{props.version}</span>
10+
</div>
11+
<div className="desc">
12+
{props.desc}
13+
</div>
14+
<div className="author">
15+
<div className="icon"/>
16+
<div className="text">
17+
{props.author}
18+
</div>
19+
</div>
20+
<div className="buttons">
21+
<div className="label">
22+
{/*<button>settings</button>*/}
23+
{/*<button>uninstall</button>*/}
24+
{props.requirement !== 'Required' ? (
25+
<button
26+
onClick={e => props.dispatch(togglePackage(props.name, !props.enabled))}>
27+
{props.enabled
28+
? 'disable'
29+
: 'enable'}
30+
</button>
31+
) : null}
32+
</div>
33+
</div>
34+
</div>
35+
)
36+
}
37+
38+
class ExtensionList extends Component {
39+
state = {
40+
searchKey: ''
41+
}
42+
componentWillMount() {
43+
this.props.dispatch(fetchPackageList());
44+
}
45+
render() {
46+
const {data, dispatch} = this.props;
47+
return (
48+
<div className="settings-extension-container">
49+
<div>
50+
<input
51+
type="text"
52+
className="search"
53+
value={this.state.searchKey}
54+
placeholder="filter extension by name"
55+
onChange={(e) => {
56+
this.setState({searchKey: e.target.value});
57+
}}/>
58+
</div>
59+
<div className="lists">
60+
{data
61+
.filter((card) => {
62+
if (this.state.searchKey) {
63+
if (card.name.includes(this.state.searchKey)) {
64+
return true;
65+
}
66+
return false;
67+
}
68+
return true;
69+
})
70+
.map((card, idx) => (<Card {...card} dispatch={dispatch}/>))
71+
}
72+
</div>
73+
</div>
74+
);
75+
}
76+
}
77+
78+
export default connect((state) => {
79+
const {
80+
PackageState: {
81+
localPackages = {}
82+
}
83+
} = state;
84+
const data = Object
85+
.keys(localPackages)
86+
.map((key) => ({
87+
name: localPackages[key].name,
88+
desc: localPackages[key].description,
89+
author: localPackages[key].author,
90+
version: localPackages[key].version,
91+
enabled: localPackages[key].enabled,
92+
requirement: localPackages[key].requirement
93+
}))
94+
return ({data})
95+
})(ExtensionList)

app/components/Package/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
/* @flow weak */
2-
export PackageControlView from './PackageControlView'
2+
export ExtensionList from './extensionList'

app/components/Setting/index.jsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { bindActionCreators } from 'redux'
44
import { connect } from 'react-redux'
55
import cx from 'classnames'
66
import _ from 'lodash'
7+
import ExtensionList from '../Package/extensionList.js';
78

89
import * as SettingActions from './actions'
910

@@ -94,6 +95,7 @@ const EditorSettings = (props) => (
9495
)}
9596
</div>
9697
)
98+
9799
const ThemeSettings = (props) => (
98100
<div>
99101
<h2 className='settings-content-header'>Theme Settings</h2>
@@ -106,6 +108,14 @@ const ThemeSettings = (props) => (
106108
</div>
107109
)
108110

111+
const ExtensionSettings = () => (
112+
<div>
113+
<h2 className='settings-content-header'>Extension Settings</h2>
114+
<ExtensionList />
115+
</div>
116+
)
117+
118+
109119
const SettingsContent = ({ content }) => {
110120
switch (content.id) {
111121
case 'GENERAL':
@@ -115,6 +125,8 @@ const SettingsContent = ({ content }) => {
115125
return <EditorSettings {...content} />
116126
case 'THEME':
117127
return <ThemeSettings {...content} />
128+
case 'EXTENSIONS':
129+
return <ExtensionSettings />
118130
}
119131
}
120132

app/components/Setting/reducer.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export const SyntaxThemeOptions = ['default', 'neo', 'eclipse', 'monokai', 'mate
3939

4040
const SettingState = {
4141
activeTabId: 'GENERAL',
42-
tabIds: ['GENERAL', 'THEME', 'EDITOR'],
42+
tabIds: ['GENERAL', 'THEME', 'EDITOR', 'EXTENSIONS'],
4343
tabs: {
4444
THEME: {
4545
id: 'THEME',
@@ -53,6 +53,9 @@ const SettingState = {
5353
options: SyntaxThemeOptions
5454
}]
5555
},
56+
EXTENSIONS: {
57+
id: 'EXTENSIONS'
58+
},
5659
GENERAL: {
5760
id: 'GENERAL',
5861
items: [{

app/styles/core-ui/Settings.styl

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,51 @@
5555
}
5656
}
5757

58+
.settings-extension-container {
59+
width: 80%;
60+
.search {
61+
width: 100%;
62+
border: 1px solid grey;
63+
height: 30px;
64+
padding-left: 5px;
65+
}
66+
.lists {
67+
margin-top: 20px;
68+
.card {
69+
width: 100%;
70+
height: 8em;
71+
padding: 10px;
72+
border: 1px solid grey;
73+
margin-bottom: 10px;
74+
position: relative;
75+
.title {
76+
font-size: 1.5em;
77+
> span {
78+
font-size: 0.8em;
79+
margin-left: 10px;
80+
}
81+
}
82+
.desc {
83+
font-size: 1em;
84+
margin-top: 10px;
85+
font-weight: 10;
86+
}
87+
.author {
88+
margin-top: 10px;
89+
.icon {
90+
width: 10px;
91+
}
92+
.text {
93+
margin-right: 10px;
94+
}
95+
}
96+
.buttons {
97+
position: absolute;
98+
display: flex;
99+
padding: 10px;
100+
right: 0px;
101+
bottom: 0px;
102+
}
103+
}
104+
}
105+
}

0 commit comments

Comments
 (0)