Skip to content

Commit

Permalink
FEATURE: PrimaryToolbar component to create nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
dimaip committed Oct 12, 2017
1 parent 6cd5db7 commit 1abc4ab
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 43 deletions.
8 changes: 8 additions & 0 deletions Configuration/Settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,11 @@ Neos:
javascript:
'Psmb.CreateNodeButton:CreateNodeView':
resource: resource://Psmb.CreateNodeButton/Public/JavaScript/CreateNodeView/Plugin.js
frontendConfiguration:
'Psmb.CreateNodeButton':
enabled: false
# Possible values are `before`, `into` and `after`
position: 'into'
# type: 'Set.Your:DocumentNodeType'
# referenceNodePath: '/sites/site/to-set'
placeholder: 'Enter title...'
30 changes: 20 additions & 10 deletions Resources/Private/CreateNodeView/src/CreateNodeView.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {selectors, actions} from '@neos-project/neos-ui-redux-store';
import {neos} from '@neos-project/neos-ui-decorators';

@neos(globalRegistry => ({
i18nRegistry: globalRegistry.get('i18n')
i18nRegistry: globalRegistry.get('i18n'),
options: globalRegistry.get('frontendConfiguration').get('Psmb.CreateNodeButton')
}))
@connect($transform({
siteNodeContextPath: $get('cr.nodes.siteNode')
Expand All @@ -21,7 +22,8 @@ export default class CreateNodeView extends Component {
options: PropTypes.shape({
type: PropTypes.string.isRequired,
position: PropTypes.string.isRequired,
referenceNodePath: PropTypes.string.isRequired
referenceNodePath: PropTypes.string.isRequired,
placeholder: PropTypes.string.isRequired
}),
persistChanges: PropTypes.func.isRequired
};
Expand All @@ -48,14 +50,22 @@ export default class CreateNodeView extends Component {
}

render() {
return (
<div style={{display: 'flex'}}>
<TextInput
onChange={title => this.setState({title})}
value={this.state.title}
/>
<Button style="brand" onClick={() => this.createNode()}>{this.props.i18nRegistry.translate('Psmb.CreateNodeButton:Main:create')}</Button>
const placeholder = this.props.options.placeholder || '';
return this.props.options.enabled ? (
<div style={{display: 'inline-block'}}>
<div style={{display: 'flex'}}>
<TextInput
onChange={title => this.setState({title})}
value={this.state.title}
placeholder={placeholder}
/>
<Button style="lighter" onClick={() => this.createNode()}>{this.props.i18nRegistry.translate('Psmb.CreateNodeButton:Main:create')}</Button>
</div>
</div>
);
) : null;
}
}

export const CreateNodeContainer = neos(globalRegistry => ({
options: globalRegistry.get('frontendConfiguration').get('Psmb.CreateNodeButton')
}))(CreateNodeView);
6 changes: 4 additions & 2 deletions Resources/Private/CreateNodeView/src/manifest.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import manifest from '@neos-project/neos-ui-extensibility';
import CreateNodeView from './CreateNodeView';
import CreateNodeView, {CreateNodeContainer} from './CreateNodeView';

manifest('Psmb.CreateNodeButton:CreateNodeView', {}, globalRegistry => {
const viewsRegistry = globalRegistry.get('inspector').get('views');
const containerRegistry = globalRegistry.get('containers');
containerRegistry.set('PrimaryToolbar/Left/CreateNode', CreateNodeContainer, 'after PrimaryToolbar/Left/EditModePanelToggler');

const viewsRegistry = globalRegistry.get('inspector').get('views');
viewsRegistry.set('Psmb.CreateNodeButton/Views/CreateNodeView', {
component: CreateNodeView
});
Expand Down
75 changes: 45 additions & 30 deletions Resources/Public/JavaScript/CreateNodeView/Plugin.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1abc4ab

Please sign in to comment.