Gestion des imports dans les profils
This commit is contained in:
parent
bb26fc2759
commit
996ccd90f1
|
@ -1,5 +1,8 @@
|
||||||
{
|
{
|
||||||
"items": [
|
"items": [
|
||||||
|
{
|
||||||
|
"import": "./partial-profile.json"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"label": "Level 1",
|
"label": "Level 1",
|
||||||
"icon": "chromium-browser",
|
"icon": "chromium-browser",
|
||||||
|
@ -12,15 +15,13 @@
|
||||||
{
|
{
|
||||||
"label": "Chromium Browser 1",
|
"label": "Chromium Browser 1",
|
||||||
"icon": "chromium-browser",
|
"icon": "chromium-browser",
|
||||||
"exec": "/usr/bin/chromium-browser",
|
"exec": "/usr/bin/chromium-browser"
|
||||||
"_key": "item_1444480285022_3"
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"label": "Pitaya Edit",
|
"label": "Pitaya Edit",
|
||||||
"exec": "PITAYA_MODE=edit PITAYA_AS_DESKTOP=0 npm start"
|
"exec": "PITAYA_MODE=edit PITAYA_AS_DESKTOP=0 npm start"
|
||||||
}
|
}
|
||||||
],
|
]
|
||||||
"_key": "item_1444480285022_2"
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"label": "Level 2-3",
|
"label": "Level 2-3",
|
||||||
|
@ -33,32 +34,24 @@
|
||||||
{
|
{
|
||||||
"label": "Chromium Browser 2",
|
"label": "Chromium Browser 2",
|
||||||
"icon": "chromium-browser",
|
"icon": "chromium-browser",
|
||||||
"exec": "/usr/bin/chromium-browser",
|
"exec": "/usr/bin/chromium-browser"
|
||||||
"_key": "item_1444480285022_6"
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"label": "Atom",
|
"label": "Atom",
|
||||||
"icon": "atom",
|
"icon": "atom",
|
||||||
"exec": "/usr/share/atom/atom %U",
|
"exec": "/usr/share/atom/atom %U",
|
||||||
"_key": "item_1444480288996_7",
|
|
||||||
"items": []
|
"items": []
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"label": "Firefox Developer Edition Web Browser",
|
"label": "Firefox Developer Edition Web Browser",
|
||||||
"icon": "firefox",
|
"icon": "firefox",
|
||||||
"exec": "firefox %u",
|
"exec": "firefox %u"
|
||||||
"_key": "item_1444761351301_2",
|
|
||||||
"selected": true
|
|
||||||
}
|
}
|
||||||
],
|
]
|
||||||
"_key": "item_1444480285022_5"
|
|
||||||
}
|
}
|
||||||
],
|
]
|
||||||
"_key": "item_1444480285022_4"
|
|
||||||
}
|
}
|
||||||
],
|
]
|
||||||
"_key": "item_1444480285022_1"
|
|
||||||
}
|
}
|
||||||
],
|
]
|
||||||
"_key": "item_1444480285021_0"
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"label": "Partial Level 1",
|
||||||
|
"icon": "chromium-browser",
|
||||||
|
"background": "./img/background2.jpg"
|
||||||
|
}
|
|
@ -7,7 +7,9 @@ var ItemForm = React.createClass({
|
||||||
return {
|
return {
|
||||||
label: '',
|
label: '',
|
||||||
icon: '',
|
icon: '',
|
||||||
exec: ''
|
exec: '',
|
||||||
|
import: '',
|
||||||
|
background: ''
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -19,7 +21,8 @@ var ItemForm = React.createClass({
|
||||||
label: props.item.label,
|
label: props.item.label,
|
||||||
icon: props.item.icon,
|
icon: props.item.icon,
|
||||||
exec: props.item.exec,
|
exec: props.item.exec,
|
||||||
background: props.item.background
|
background: props.item.background,
|
||||||
|
import: props.item.import
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,6 +57,11 @@ var ItemForm = React.createClass({
|
||||||
placeholder="Fond d'écran" value={state.background}
|
placeholder="Fond d'écran" value={state.background}
|
||||||
onChange={this.handleChange.bind(this, 'background')} />
|
onChange={this.handleChange.bind(this, 'background')} />
|
||||||
</div>
|
</div>
|
||||||
|
<div className="form-group">
|
||||||
|
<input type="text" className="form-control"
|
||||||
|
placeholder="Import" value={state.import}
|
||||||
|
onChange={this.handleChange.bind(this, 'import')} />
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
@ -21,7 +21,7 @@ var ProfileMenu = React.createClass({
|
||||||
var dispatch = this.props.dispatch;
|
var dispatch = this.props.dispatch;
|
||||||
this.showOpenProfileDialog()
|
this.showOpenProfileDialog()
|
||||||
.then(function(profilePath) {
|
.then(function(profilePath) {
|
||||||
if(profilePath) dispatch(actions.common.loadProfile(profilePath));
|
if(profilePath) dispatch(actions.common.loadProfile(profilePath, false));
|
||||||
})
|
})
|
||||||
;
|
;
|
||||||
},
|
},
|
||||||
|
|
|
@ -4,7 +4,7 @@ var LOAD_PROFILE = exports.LOAD_PROFILE = 'LOAD_PROFILE';
|
||||||
var LOAD_PROFILE_SUCCESS = exports.LOAD_PROFILE_SUCCESS = 'LOAD_PROFILE_SUCCESS';
|
var LOAD_PROFILE_SUCCESS = exports.LOAD_PROFILE_SUCCESS = 'LOAD_PROFILE_SUCCESS';
|
||||||
var LOAD_PROFILE_FAILED = exports.LOAD_PROFILE_FAILED = 'LOAD_PROFILE_FAILED';
|
var LOAD_PROFILE_FAILED = exports.LOAD_PROFILE_FAILED = 'LOAD_PROFILE_FAILED';
|
||||||
|
|
||||||
exports.loadProfile = function(profilePath) {
|
exports.loadProfile = function(profilePath, withImports) {
|
||||||
|
|
||||||
return function(dispatch, getState) {
|
return function(dispatch, getState) {
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ exports.loadProfile = function(profilePath) {
|
||||||
|
|
||||||
Util.Logger.info('Loading profile "%s"', profilePath);
|
Util.Logger.info('Loading profile "%s"', profilePath);
|
||||||
|
|
||||||
return Util.System.loadJSON(profilePath)
|
return Util.Profile.load(profilePath, withImports)
|
||||||
.then(function(profile) {
|
.then(function(profile) {
|
||||||
Util.Logger.info('Profile loaded.');
|
Util.Logger.info('Profile loaded.');
|
||||||
dispatch({ type: LOAD_PROFILE_SUCCESS, profile: profile });
|
dispatch({ type: LOAD_PROFILE_SUCCESS, profile: profile });
|
||||||
|
|
|
@ -6,3 +6,4 @@ exports.Tree = require('./tree');
|
||||||
exports.Const = require('./const');
|
exports.Const = require('./const');
|
||||||
exports.Promises = require('./promises');
|
exports.Promises = require('./promises');
|
||||||
exports.App = require('./app');
|
exports.App = require('./app');
|
||||||
|
exports.Profile = require('./profile');
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
var RecursiveIterator = require('recursive-iterator');
|
||||||
|
var System = require('./system');
|
||||||
|
var Logger = require('./logger');
|
||||||
|
var _ = require('lodash');
|
||||||
|
var path = require('path');
|
||||||
|
|
||||||
|
// Load a profile file with imports
|
||||||
|
exports.load = function(profileUrl, withImports) {
|
||||||
|
|
||||||
|
withImports = withImports || true;
|
||||||
|
|
||||||
|
// Load root profile
|
||||||
|
return System.loadJSON(profileUrl)
|
||||||
|
.then(function(profile) {
|
||||||
|
|
||||||
|
if(!withImports) {
|
||||||
|
return profile;
|
||||||
|
}
|
||||||
|
|
||||||
|
var promises = [];
|
||||||
|
|
||||||
|
// Search for imports
|
||||||
|
var iterator = new RecursiveIterator(profile);
|
||||||
|
|
||||||
|
for(var node, item = iterator.next(); !item.done; item = iterator.next()) {
|
||||||
|
node = item.value.node;
|
||||||
|
// For each import found, load the partial and "mount" it on the current item
|
||||||
|
if(node.import) {
|
||||||
|
Logger.info('Loading import "%s"', path.resolve(node.import));
|
||||||
|
p = exports.load(node.import)
|
||||||
|
.then(_mountImport.bind(node))
|
||||||
|
;
|
||||||
|
promises.push(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// When all imports are loaded, return the complete profile
|
||||||
|
return Promise.all(promises)
|
||||||
|
.then(function() {
|
||||||
|
return profile;
|
||||||
|
})
|
||||||
|
;
|
||||||
|
|
||||||
|
})
|
||||||
|
;
|
||||||
|
|
||||||
|
// Internal method, extend "this" (the mount point) with the partial profile
|
||||||
|
function _mountImport(importProfile) {
|
||||||
|
_.extend(this, importProfile);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
|
@ -0,0 +1,19 @@
|
||||||
|
var Profile = require('../src/util/profile');
|
||||||
|
|
||||||
|
var ProfileSuite = module.exports = {};
|
||||||
|
|
||||||
|
ProfileSuite.loadProfileWithImport = function(test) {
|
||||||
|
|
||||||
|
Profile.load(__dirname+'/../default-profile.json')
|
||||||
|
.then(function(profile) {
|
||||||
|
console.log('%j', profile);
|
||||||
|
test.ok(profile.items[0].label === "Partial Level 1", "It should have loaded the partial import !");
|
||||||
|
test.done();
|
||||||
|
})
|
||||||
|
.catch(function(err) {
|
||||||
|
test.ifError(err);
|
||||||
|
test.done();
|
||||||
|
})
|
||||||
|
;
|
||||||
|
|
||||||
|
};
|
Loading…
Reference in New Issue