1
0
Fork 0

Phi: simplify plugin json and add user plugin support

This commit is contained in:
Torsten Dreyer 2016-01-13 18:16:15 +01:00
parent cee599cd0d
commit f0588144d1
2 changed files with 28 additions and 27 deletions

View file

@ -1,45 +1,33 @@
{
"plugins": {
"Aircraft": {
"component": {
"key": "Aircraft",
"lib": "topics/Aircraft"
}
"index": 100,
"component": "topics/Aircraft"
},
"Environment": {
"component": {
"key": "Environment",
"lib": "topics/Environment"
}
"index": 200,
"component": "topics/Environment"
},
"Map": {
"component": {
"key": "Map",
"lib": "topics/Map"
}
"index": 300,
"component": "topics/Map"
},
"Tools": {
"component": {
"key": "Tools",
"lib": "topics/Tools"
}
"index": 400,
"component": "topics/Tools"
},
"Simulator": {
"component": {
"key": "Simulator",
"lib": "topics/Simulator"
}
"index": 500,
"component": "topics/Simulator"
},
"Help": {
"component": {
"key": "Help",
"lib": "topics/Help"
}
"index": 600,
"component": "topics/Help"
}
}
}

View file

@ -203,21 +203,34 @@ require([
jquery.get('/config.json', null, function(config) {
// merge user config into global config
jquery.get('/fg-home/Phi/config.json', null, function(userConfig) {
for ( var p in userConfig.plugins ) {
config.plugins[p] = userConfig.plugins[p];
}
var topics = [];
if (config && config.plugins ) {
for ( var p in config.plugins ) {
var plugin = config.plugins[p];
if (plugin.component && plugin.component.key && plugin.component.lib) {
if (false == ko.components.isRegistered(plugin.component.key)) {
ko.components.register(plugin.component.key, { require: plugin.component.lib });
if (plugin.component) {
if (false == ko.components.isRegistered(p)) {
ko.components.register(p, { require: plugin.component });
}
}
topics.push(p);
}
}
topics.sort(function(a,b) {
indexa = config.plugins[a].index || 0;
indexb = config.plugins[b].index || 0;
return indexa - indexb;
});
ko.applyBindings(new PhiViewModel(topics), document.getElementById('wrapper'));
});
});
jquery("#toolbar").click(function() {