Add getViewsByMciCode()

* Store MCI code in View when created from MCI
* Allow retrieval by MCI code
This commit is contained in:
Bryan Ashby 2018-01-31 22:38:02 -07:00
parent cb8d331415
commit d244cd25fa
2 changed files with 24 additions and 6 deletions

View File

@ -199,5 +199,9 @@ MCIViewFactory.prototype.createFromMCI = function(mci) {
break;
}
if(view) {
view.mciCode = mci.code;
}
return view;
};

View File

@ -140,9 +140,9 @@ function ViewController(options) {
};
this.createViewsFromMCI = function(mciMap, cb) {
async.each(Object.keys(mciMap), function entry(name, nextItem) {
var mci = mciMap[name];
var view = self.mciViewFactory.createFromMCI(mci);
async.each(Object.keys(mciMap), (name, nextItem) => {
const mci = mciMap[name];
const view = self.mciViewFactory.createFromMCI(mci);
if(view) {
if(false === self.noInput) {
@ -152,11 +152,11 @@ function ViewController(options) {
self.addView(view);
}
nextItem(null);
return nextItem(null);
},
function complete(err) {
err => {
self.setViewOrder();
cb(err);
return cb(err);
});
};
@ -426,6 +426,20 @@ ViewController.prototype.getView = function(id) {
return this.views[id];
};
ViewController.prototype.getViewsByMciCode = function(mciCode) {
if(!Array.isArray(mciCode)) {
mciCode = [ mciCode ];
}
const views = [];
_.each(this.views, v => {
if(mciCode.includes(v.mciCode)) {
views.push(v);
}
});
return views;
};
ViewController.prototype.getFocusedView = function() {
return this.focusedView;
};