Edit: ajout bouton supression item

This commit is contained in:
William Petit 2015-10-10 18:44:31 +02:00
parent 2b419997f1
commit 2d003fb75c
6 changed files with 46 additions and 8 deletions

View File

@ -35,7 +35,7 @@ Vous pouvez configurer le comportement de Pitaya en passant des variables d'envi
npm run build npm run build
``` ```
Un dossier `pitaya-<version>-<target>-<arch>` sera créé dans le répertoire `./build`. Celui ci contient tous les fichiers nécessaires à l'application. Un dossier `pitaya-<target>-<arch>` sera créé dans le répertoire `./build`. Celui ci contient tous les fichiers nécessaires à l'application.
## Comment contribuer ## Comment contribuer

View File

@ -1,3 +1,4 @@
/* jhsint node:true, jsx: true */
var React = require('react'); var React = require('react');
var connect = require('react-redux').connect; var connect = require('react-redux').connect;
var actions = require('../../store/actions'); var actions = require('../../store/actions');
@ -31,9 +32,8 @@ var ProfileMenu = React.createClass({
var profile = this.props.profile; var profile = this.props.profile;
var profilePath = this.props.profilePath; var profilePath = this.props.profilePath;
var promise = profilePath ? Promise.resolve(profilePath) : this.showSaveProfileDialog(); this.showSaveProfileDialog(profilePath)
.then(function(profilePath) {
promise.then(function(profilePath) {
if(profilePath) dispatch(actions.edit.saveProfile(profilePath, profile)); if(profilePath) dispatch(actions.edit.saveProfile(profilePath, profile));
}); });
@ -56,12 +56,13 @@ var ProfileMenu = React.createClass({
}, },
showSaveProfileDialog: function() { showSaveProfileDialog: function(defaultPath) {
return new Promise(function(resolve) { return new Promise(function(resolve) {
dialog.showSaveDialog( dialog.showSaveDialog(
{ {
title: 'Éditer un profil', defaultPath: defaultPath,
title: 'Enregistrer un profil',
filters: [ {name: 'Profils Pitaya', extensions: ['json'] } ] filters: [ {name: 'Profils Pitaya', extensions: ['json'] } ]
}, },
function(file) { function(file) {

View File

@ -17,6 +17,7 @@ var TreeNode = React.createClass({
selectedItem={this.props.selectedItem} selectedItem={this.props.selectedItem}
onItemClicked={this.props.onItemClicked} onItemClicked={this.props.onItemClicked}
onItemMoved={this.props.onItemMoved} onItemMoved={this.props.onItemMoved}
onItemRemoved={this.props.onItemRemoved}
theme={this.props.theme} /> theme={this.props.theme} />
</li> </li>
); );
@ -66,6 +67,7 @@ var ProfileTree = React.createClass({
selectedItem={this.props.selectedItem} selectedItem={this.props.selectedItem}
onItemClicked={this.onItemSelected} onItemClicked={this.onItemSelected}
onItemMoved={this.onItemMoved} onItemMoved={this.onItemMoved}
onItemRemoved={this.onItemRemoved}
theme={this.props.theme} /> theme={this.props.theme} />
); );
}, },
@ -76,6 +78,10 @@ var ProfileTree = React.createClass({
onItemSelected: function(selectedItem) { onItemSelected: function(selectedItem) {
this.props.dispatch(actions.edit.selectProfileItem(selectedItem)); this.props.dispatch(actions.edit.selectProfileItem(selectedItem));
},
onItemRemoved: function(selectedItem) {
this.props.dispatch(actions.edit.removeProfileItem(selectedItem));
} }
}); });

View File

@ -30,6 +30,9 @@ var TreeItem = React.createClass({
<div className={classes} style={style} onClick={this.handleClick}> <div className={classes} style={style} onClick={this.handleClick}>
{appIcon} {appIcon}
<span className="app-label">{data.label}</span> <span className="app-label">{data.label}</span>
<button type="button" className="close pull-right" onClick={this.handleRemoveClick}>
<span>&times;</span>
</button>
</div> </div>
)); ));
@ -38,6 +41,11 @@ var TreeItem = React.createClass({
handleClick: function(evt) { handleClick: function(evt) {
evt.preventDefault(); evt.preventDefault();
this.props.onItemClicked(this.props.data); this.props.onItemClicked(this.props.data);
},
handleRemoveClick: function(evt) {
evt.preventDefault();
this.props.onItemRemoved(this.props.data);
} }
}); });

View File

@ -12,6 +12,7 @@ var SAVE_PROFILE_FAILED = exports.SAVE_PROFILE_FAILED = 'SAVE_PROFILE_FAILED';
var MOVE_PROFILE_ITEM = exports.MOVE_PROFILE_ITEM = 'MOVE_PROFILE_ITEM'; var MOVE_PROFILE_ITEM = exports.MOVE_PROFILE_ITEM = 'MOVE_PROFILE_ITEM';
var ADD_PROFILE_ITEM = exports.ADD_PROFILE_ITEM = 'ADD_PROFILE_ITEM'; var ADD_PROFILE_ITEM = exports.ADD_PROFILE_ITEM = 'ADD_PROFILE_ITEM';
var REMOVE_PROFILE_ITEM = exports.REMOVE_PROFILE_ITEM = 'REMOVE_PROFILE_ITEM';
var USE_ICON_THEME = exports.USE_ICON_THEME = 'USE_ICON_THEME'; var USE_ICON_THEME = exports.USE_ICON_THEME = 'USE_ICON_THEME';
var SELECT_PROFILE_ITEM = exports.SELECT_PROFILE_ITEM = 'SELECT_PROFILE_ITEM'; var SELECT_PROFILE_ITEM = exports.SELECT_PROFILE_ITEM = 'SELECT_PROFILE_ITEM';
var UPDATE_PROFILE_ITEM = exports.UPDATE_PROFILE_ITEM = 'UPDATE_PROFILE_ITEM'; var UPDATE_PROFILE_ITEM = exports.UPDATE_PROFILE_ITEM = 'UPDATE_PROFILE_ITEM';
@ -71,6 +72,13 @@ exports.moveProfileItem = function(movedItem, targetItem) {
}; };
}; };
exports.removeProfileItem = function(removedItem) {
return {
type: REMOVE_PROFILE_ITEM,
removedItem: removedItem
};
};
exports.addProfileItem = function(newItem, targetItem) { exports.addProfileItem = function(newItem, targetItem) {
return { return {
type: ADD_PROFILE_ITEM, type: ADD_PROFILE_ITEM,

View File

@ -14,6 +14,9 @@ module.exports = function(oldProfile, action) {
case actions.edit.MOVE_PROFILE_ITEM: case actions.edit.MOVE_PROFILE_ITEM:
return moveProfileItem(oldProfile, action.movedItem, action.targetItem); return moveProfileItem(oldProfile, action.movedItem, action.targetItem);
case actions.edit.REMOVE_PROFILE_ITEM:
return removeProfileItem(oldProfile, action.removedItem);
case actions.edit.ADD_PROFILE_ITEM: case actions.edit.ADD_PROFILE_ITEM:
return addProfileItem(oldProfile, action.newItem, action.targetItem); return addProfileItem(oldProfile, action.newItem, action.targetItem);
@ -48,6 +51,18 @@ function updateProfileItem(oldProfile, targetItem, key, value) {
return newProfile; return newProfile;
} }
function removeProfileItem(oldProfile, removedItem) {
var newProfile = _.cloneDeep(oldProfile);
var parent = tree.find(newProfile, removedItem).parent;
parent.items = _.reject(parent.items, function(item) {
return _.isEqual(item, removedItem);
});
return newProfile;
}
function moveProfileItem(oldProfile, movedItem, targetItem) { function moveProfileItem(oldProfile, movedItem, targetItem) {