Skip to content

Commit

Permalink
use new state obj to track startup
Browse files Browse the repository at this point in the history
  • Loading branch information
dshuffma-ibm committed Jul 16, 2017
1 parent 1ebd862 commit 883bfd1
Show file tree
Hide file tree
Showing 11 changed files with 348 additions and 203 deletions.
38 changes: 24 additions & 14 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ var enrollObj = null;
var marbles_lib = null;
process.env.marble_company = helper.getCompanyName();

var start_up_states = {
checklist: { state: 'waiting', step: 'step1' },
enrolling: { state: 'waiting', step: 'step2' },
find_chaincode: { state: 'waiting', step: 'step3' },
register_owners: { state: 'waiting', step: 'step4' },
};

// ------------- Bluemix Detection ------------- //
if (process.env.VCAP_APPLICATION) {
host = '0.0.0.0'; //overwrite defaults
Expand Down Expand Up @@ -121,7 +128,6 @@ process.on('uncaughtException', function (err) {
// ------------------------------------------------------------------------------------------------------------------------------
// Life Starts Here!
// ------------------------------------------------------------------------------------------------------------------------------
process.env.app_state = 'starting'; //init
process.env.app_first_setup = 'yes'; //init
helper.checkConfig();
setupWebSocket();
Expand All @@ -133,9 +139,10 @@ logger.info('Using settings in ' + process.env.creds_filename + ' to see if we h
enroll_admin(1, function (e) {
if (e != null) {
logger.warn('Error enrolling admin');
broadcast_state('failed_enroll');
broadcast_state('enrolling', 'failed');
startup_unsuccessful();
} else {
broadcast_state('enrolling', 'success');

// --- Setup Marbles Library --- //
setup_marbles_lib(function () {
Expand Down Expand Up @@ -168,17 +175,20 @@ function detect_prev_startup(opts, cb) {
marbles_lib.read_everything(null, function (err, resp) { //read the ledger for marble owners
if (err != null) {
logger.warn('Error reading ledger');
if (opts.startup) broadcast_state('start_waiting'); //do not send no chaincode state... pause it at "start_waiting"
else broadcast_state('no_chaincode');
//if (opts.startup) broadcast_state('start_waiting'); //do not send no chaincode state... pause it at "start_waiting"
//else
broadcast_state('find_chaincode', 'failed');
if (cb) cb(true);
} else {
if (find_missing_owners(resp)) { //check if each user in the settings file has been created in the ledger
logger.info('We need to make marble owners'); //there are marble owners that do not exist!
if (opts.startup) broadcast_state('start_waiting'); //do not send found chaincode state... pause it at "start_waiting"
else broadcast_state('no_chaincode');
//if (opts.startup) broadcast_state('start_waiting'); //do not send found chaincode state... pause it at "start_waiting"
//else
broadcast_state('find_chaincode', 'failed');
if (cb) cb(true);
} else {
broadcast_state('registered_owners'); //everything is good
broadcast_state('find_chaincode', 'success');
broadcast_state('register_owners', 'success'); //everything is good
process.env.app_first_setup = 'no';
logger.info('Everything is in place');
if (cb) cb(null);
Expand Down Expand Up @@ -226,17 +236,17 @@ function setup_marbles_lib(cb) {
logger.debug('Chaincode was not detected: "' + helper.getChaincodeId() + '", all stop');
logger.debug('Open your browser to http://' + host + ':' + port + ' and login to tweak settings for startup');
process.env.app_first_setup = 'yes'; //overwrite state, bad startup
broadcast_state('no_chaincode');
broadcast_state('find_chaincode', 'failed');
}
else { //else we already instantiated
console.log('\n----------------------------- Chaincode found on channel "' + helper.getChannelId() + '" -----------------------------\n');

// --- Check Chaincode Compatibility --- //
marbles_lib.check_version(options, function (err, resp) {
if (helper.errorWithVersions(resp)) {
broadcast_state('no_chaincode');
broadcast_state('find_chaincode', 'failed');
} else {
broadcast_state('found_chaincode');
broadcast_state('find_chaincode', 'success');
if (cb) cb(null);
}
});
Expand Down Expand Up @@ -404,7 +414,7 @@ function build_marble_options(id, username, company) {
// We are done, inform the clients
function all_done() {
console.log('\n------------------------------------------ All Done ------------------------------------------\n');
broadcast_state('registered_owners');
broadcast_state('register_owners', 'success');
process.env.app_first_setup = 'no';

ws_server.check_for_updates(null); //call the periodic task to get the state of everything
Expand All @@ -414,15 +424,15 @@ function all_done() {
function build_state_msg() {
return {
msg: 'app_state',
state: process.env.app_state,
state: start_up_states,
first_setup: process.env.app_first_setup
};
}

// Send to all connected clients
function broadcast_state(new_state) {
function broadcast_state(change_state, outcome) {
try {
process.env.app_state = new_state;
start_up_states[change_state].state = outcome;
wss.broadcast(build_state_msg()); //tell client our app state
} catch (e) { }
}
Expand Down
2 changes: 1 addition & 1 deletion main.min.css

Large diffs are not rendered by default.

76 changes: 62 additions & 14 deletions public/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ tr {
border-bottom: 6px #343D48 solid; }

tr:hover {
background: orange; }
background: #ff5b5b; }

td {
padding: 15px 10px;
Expand Down Expand Up @@ -186,7 +186,7 @@ input[type="text"]:disabled, input[type="password"]:disabled, select:disabled {
color: #646B73; }

input.longer {
min-width: 250px; }
min-width: 333px; }

button:disabled {
cursor: default; }
Expand Down Expand Up @@ -313,7 +313,7 @@ strong {
margin: 0 auto;
padding: 5px;
border-radius: 2px;
border-left: 5px #6CC284 solid;
border-left: 5px #52b152 solid;
color: #E5EBEF;
font-size: 14px;
display: inline-block;
Expand Down Expand Up @@ -346,17 +346,17 @@ strong {
margin-bottom: 35px; }

.closeNotification:hover {
color: orange; }
color: #ff5b5b; }

.notificationIcon {
margin: 0 10px;
color: #6CC284; }
color: #52b152; }

.warningNotice {
border-left: 5px orange solid; }
border-left: 5px #ff5b5b solid; }

.warningNotice .notificationIcon {
color: orange; }
color: #ff5b5b; }

#emptyNotifications {
color: #39424D;
Expand Down Expand Up @@ -484,7 +484,7 @@ strong {
color: #2EB9D6; }

.marblesFix:hover, .marblesOpenSection:hover, .disableOwner:hover {
color: orange;
color: #ff5b5b;
cursor: pointer; }

.notAdminControl {
Expand Down Expand Up @@ -713,7 +713,7 @@ strong {
font-size: 15px; }

#loginCompany {
color: orange;
color: #ff5b5b;
text-align: center; }

#adminText {
Expand Down Expand Up @@ -911,17 +911,18 @@ strong {
.stepInputLegend {
display: inline-block;
text-align: right;
width: 115px;
width: 150px;
font-size: 13px;
margin-right: 5px; }
margin-right: 5px;
color: #fff; }

#closeStartUp, #closeTxStoryPos, #closeSettings, #closeCreate {
position: absolute;
right: 15px;
top: 15px; }

#closeStartUp:hover, #closeTxStoryPos:hover, #closeSettings:hover, #closeCreate:hover {
color: orange;
color: #ff5b5b;
cursor: pointer; }

#appStartingText {
Expand Down Expand Up @@ -976,7 +977,7 @@ strong {
margin-bottom: 50px; }

.storyOn {
color: #6CC284;
color: #52b152;
font-weight: 700; }

#construction {
Expand Down Expand Up @@ -1385,6 +1386,10 @@ strong {
color: #52b152;
border-color: #52b152; }

.errorStepIcon .stepIcon, .errorStepIcon .stepDivide {
color: #ff5b5b;
border-color: #ff5b5b; }

.stepName {
display: inline-block;
margin-left: 10px;
Expand All @@ -1393,7 +1398,8 @@ strong {

.onStep .stepIcon {
font-size: 18px;
margin-left: -1px; }
margin-left: -1px;
margin-right: -4px; }

#leftStepsTitle {
font-size: 22px;
Expand All @@ -1402,6 +1408,15 @@ strong {
.loadingdiv {
display: none; }

.inactive .stepName {
font-style: italic; }

.greenMe {
color: #52b152; }

.redMe {
color: #ff5b5b; }

.stepWrap {
display: inline-block;
text-align: center;
Expand All @@ -1420,6 +1435,13 @@ strong {
font-size: 14px;
opacity: 0; }

.failureStep {
color: #ff5b5b;
margin: 20px 0;
font-weight: 600;
font-size: 14px;
display: none; }

.nextStep {
display: none; }

Expand All @@ -1432,3 +1454,29 @@ strong {
.success .nextStep {
display: inline-block; }

.errorStepContent .failureStep {
display: block; }

.settingsExpand {
color: #fff;
padding: 4px;
text-align: left;
padding-left: 17px;
cursor: pointer; }

.settingsExpand:hover {
color: #ccc; }

.settingsContent {
margin: 16px;
display: none; }

.settingsWrap {
color: #5b6169;
border: 1px #5b6169 solid;
border-radius: 3px;
margin: 20px 0; }

#registerOwnersInputPanel {
display: block; }

2 changes: 1 addition & 1 deletion public/css/main.min.css

Large diffs are not rendered by default.

Loading

0 comments on commit 883bfd1

Please sign in to comment.