Created
November 9, 2013 21:57
-
-
Save jbavari/7390568 to your computer and use it in GitHub Desktop.
Quick set of files for our states of our app and the grunt task to print them off to command line
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
print_state_diagram: { | |
options: { | |
stdout: true | |
}, | |
command: function() { | |
// var states_chart = grunt.file.read('states.js'); | |
var glob = require('./states.js'); | |
var states = glob.states; | |
grunt.log.writeln("Total number of states: " + states.length + "\n"); | |
for(stateKey in states) { | |
var state = states[stateKey]; | |
var stateEvents = state['events']; | |
grunt.log.writeln("State: " + state.name); | |
if(state.page) { | |
grunt.log.writeln("Page it directs to: " + state.page); | |
} | |
grunt.log.writeln(""); | |
grunt.log.writeln(" Events: "); | |
for(event in stateEvents) { | |
grunt.log.writeln(" " + event + " -> " + stateEvents[event]); | |
} | |
grunt.log.writeln(""); | |
} | |
var commands = []; | |
commands.push("echo '" + states[0].name + "'"); | |
return commands; | |
} | |
} |
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
exports.states = [ | |
{ | |
'name': 'initial', | |
'initial': true, | |
'page': 'index.html', | |
'events': { | |
'deviceready': 'deviceready_nogps_notonline', | |
'checkonline': 'deviceready_nogps_online', | |
'locationreceived': 'deviceready_gps_notonline' | |
} | |
}, | |
{ | |
'name': 'deviceready_nogps_notonline', | |
'events': { | |
'checkonline': 'deviceready_nogps_online', | |
'locationreceived': 'deviceready_gps_notonline' | |
} | |
}, | |
{ | |
'name': 'deviceready_nogps_online', | |
'events': { | |
'locationreceived': 'event_selection' | |
} | |
}, | |
{ | |
'name': 'deviceready_gps_notonline', | |
'events': { | |
'checkonline': 'event_selection' | |
} | |
}, | |
{ | |
'name': 'event_selection', | |
'page': 'mainPage.html', | |
'decideAction': function() { | |
app.log("DecideAction on event_selection"); | |
// if(!app.user) { | |
// app.stateMachine.consumeEvent('setUpCurrentEvent'); | |
// } | |
}, | |
'events': { | |
'setUpCurrentEvent': 'login', | |
'addcheckeduser': 'checkeduser' | |
} | |
}, | |
{ | |
'name': 'checkeduser', | |
'decideAction': function() { | |
app.log("DecideAction on checkeduser state - here logic goes to check the state."); | |
//Check if module has supporter | |
// if(app.moduleManager.HasSupporter() == true && (!app.user || !app.stateManager.supporterSet(app.currEvent.id))) { | |
// app.stateManager.consumeEvent('need_participation_type'); | |
// // app.changePage("supporter.html", { transition: "none"}); | |
// } | |
if(app.moduleManager.HasSupporter() == true && !app.stateManager.supporterSet(app.currEvent.id)) { | |
app.stateMachine.consumeEvent('need_participation_type'); | |
// } //else if(app.stateManager.isSupporter()) { | |
// app.changePage("loginNoSocial.html", { transition: "none"}); | |
//app.stateManager.consumeEvent('login_no_fb'); | |
} else if(app.moduleManager.HasAdditionalLogin() == true && !app.stateManager.isSupporter()) { | |
// app.changePage("additionalLogin.html", { transition: "none"}); | |
app.stateMachine.consumeEvent('need_additional_login'); | |
} else { | |
app.stateMachine.consumeEvent('check_event_status'); | |
} | |
}, | |
'events': { | |
'need_participation_type': 'select_participation', | |
'need_additional_login': 'additional_login', | |
'check_event_status': 'check_event_status' | |
} | |
}, | |
{ | |
'name': 'select_participation', | |
'decideAction': function() { | |
app.log("State Machine - decideAction - select_participation"); | |
}, | |
'events': { | |
} | |
}, | |
{ | |
'name': 'additional_login', | |
'decideAction': function() { | |
app.log("State Machine - decideAction - additional_login"); | |
}, | |
'events': { | |
'valid_additional': 'select_participation', | |
'invalid': 'additional_login' | |
} | |
}, | |
{ | |
'name': 'check_event_status', | |
'decideAction': function() { | |
app.log("states.js - decideAction on state check_event_status."); | |
if(app.currEventStatus() == "After" || app.stateManager.hasCompletedEvent(app.currEvent.id) == true) { | |
// app.changePage("takeActions.html", { transition: "none"}); | |
app.stateMachine.consumeEvent('after_event'); | |
} | |
else if(app.currEventStatus() == "Active" || app.stateManager.isSupporter()) { | |
// app.goToEventParticipation(); | |
app.stateManager.consumeEvent('current_event'); | |
} | |
else { | |
// app.changePage("countdown.html", { transition: "none"}); | |
app.stateManager.consumeEvent('after_event'); | |
} | |
}, | |
'events': { | |
'before_event': 'before_event', | |
'current_event': 'current_event', | |
'after_event': 'after_or_completed_event', | |
'completed_event': 'after_or_completed_event' | |
} | |
}, | |
{ | |
'name': 'after_or_completed_event', | |
'events': { | |
} | |
}, | |
{ | |
'name': 'before_event', | |
'decideAction': function() { | |
}, | |
'events': { | |
} | |
}, | |
{ | |
'name': 'current_event', | |
'decideAction': function() { | |
if(app.stateManager.hasCompletedEvent(app.currEvent.id) == true) { | |
if(app.stateManager.userHandoff(app.currEvent.id) == true) { | |
app.stateManager.consumeEvent('current_event_handoff'); // Completed event, handoff needed | |
} else { | |
app.stateManager.consumeEvent('completed_event'); //Take Actions page. | |
} | |
} else if (app.locationManager.isTrackingPosition() == true) { // Havent completed, are we broadcasting? | |
app.stateManager.consumeEvent('tracking_event'); // Progress page - counter and broadcast | |
// app.changePage("handoff.html", { transition: "none"}); | |
} else if(app.stateManager.userReady(app.currEvent.id) == true && !app.moduleManager.HasHandoff()) { | |
// app.changePage("progress.html", { transition: "none"}); | |
app.stateManager.consumeEvent('tracking_event'); | |
} else { | |
// app.changePage("countdown.html", { transition: "none"}); | |
app.stateManager.consumeEvent('countdown'); | |
} | |
}, | |
'events': { | |
'tracking_event': 'broadcasting', | |
'current_event_handoff': 'handoff', | |
'completed_event': 'completed_event', | |
'countdown': 'countdown' | |
} | |
}, | |
{ | |
'name': 'broadcasting', | |
'events': { | |
'complete_broadcasting': 'completed_event', | |
'pause_broadcasting': 'paused_broadcast' | |
} | |
}, | |
{ | |
'name': 'handoff', | |
'events': { | |
'begin_broadcasting': 'broadcasting' | |
} | |
}, | |
{ | |
'name': 'completed_event', | |
'events': { | |
} | |
}, | |
{ | |
'name': 'countdown', | |
'events': { | |
'ready': 'broadcasting' | |
} | |
}, | |
{ | |
'name': 'need_participation_type', | |
'decideAction': function() { | |
}, | |
'events': { | |
} | |
}, | |
{ | |
'name': 'select_participation', | |
'page': 'supporter.html', | |
'events': { | |
} | |
}, | |
{ | |
'name': 'login', | |
'page': 'login.html', | |
'events': { | |
'addcheckeduser': 'checkeduser', | |
'login_without_fb': 'login_no_fb' | |
} | |
}, | |
{ | |
'name': 'login_fb', | |
'page': 'login.html', | |
'events': { | |
'logging_in': 'logging_in' | |
} | |
}, | |
{ | |
'name': 'logging_in', | |
'events': { | |
'checking_user': 'checking_user' | |
} | |
}, | |
{ | |
'name': 'login_no_fb', | |
'events': { | |
'logging_in_no_fb': 'logging_in_no_fb' | |
} | |
}, | |
{ | |
'name': 'loggin_in', | |
'events': { | |
'checkuser': 'checking_user' | |
} | |
}, | |
{ | |
'name': 'checking_user', | |
'events': { | |
'checkevent': 'checkevent' | |
} | |
} | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment