-
-
Save dbleier/aadd33871757872d7273 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Map from 'can/map/'; | |
import List from 'can/list/'; | |
import 'can/map/define/'; | |
import { Config } from 'menuboard-manager/config/config/'; | |
import { Storage } from 'menuboard-manager/utils/storage/'; | |
import Sign from 'menuboard-manager/models/sign'; | |
import Presentation from 'menuboard-manager/models/presentation'; | |
import Parser from 'menuboard-manager/utils/parser/'; | |
export const SignController = Map.extend({ | |
define: { | |
signPromise: { | |
get() { | |
return Sign.getList({mac: this.attr('mac')}); | |
} | |
}, | |
sign: { | |
get(last, set) { | |
var self = this; | |
this.attr('signPromise').then(function(s) { | |
var sign = s[0], actpres, curpres; | |
// 1st check if there is only 1 active presentation, | |
// if only 1 presentation exists at all, use it regardless | |
// whether it is marked active or not (better than a blank screen) | |
if(sign.presentations.length === 1) { | |
// don't need to worry about scheduling or any other multi-presention logic | |
curpres = self.processPresentation(sign.presentations[0]); | |
new Presentation({id: curpres.id, data: curpres}).save(); | |
self.attr('currentPresentation', curpres.id); | |
set(sign); | |
} else { | |
actpres = sign.presentations.filter(function(pres) { | |
return pres.props.active; | |
}); | |
if(!actpres.length) { | |
// no active presentations, throw error... | |
} else if(actpres.length === 1) { | |
// only 1 active presentation, treat like only presentation | |
curpres = self.processPresentation(actpres[0]); | |
new Presentation({id: curpres.id, data: curpres}).save(); | |
self.attr('currentPresentation', curpres.id); | |
set(sign); | |
} else { | |
// multiple presentations, need to check scheduling, etc. | |
} | |
} | |
}); | |
} | |
}, | |
currentPresentation: { | |
}, | |
mac: { | |
get() { | |
var mac = Storage.get('mac'); | |
if(!mac) { | |
if(Config().attr('isLFD')) { | |
// running on monitor, get from SEF plugin | |
} else { | |
// running in browser, use preset value (for now) | |
mac = 'a4be90d1'; | |
} | |
} | |
return mac; | |
} | |
} | |
}, | |
processPresentation(pres) { | |
var processed = Parser.parsePresentation(pres); | |
return processed; | |
} | |
}); | |
export default SignController; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here is the unit test calling the code where set is undefined