Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated web demo #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 19 additions & 58 deletions web/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -49,78 +49,39 @@ h2 {
float: left;
}

.box {
#diagramTitle {
font-family: Segoe, "Segoe UI", "DejaVu Sans", "Trebuchet MS", Verdana, sans-serif;
font-size: 16px;
}

#log {
font-family: 'Droid Sans Mono', Menlo, Consolas, 'Courier New', Courier, monospace;
font-size: 14px;
}

.state {
margin: 8px;
padding: 10px;
text-align: center;
border-radius: 10px;
font-family: Segoe, "Segoe UI", "DejaVu Sans", "Trebuchet MS", Verdana, sans-serif;
font-size: 18px;
border: 1px solid #3D3D3D;
background-color: white;
}

.first-state {
font-family: Segoe, "Segoe UI", "DejaVu Sans", "Trebuchet MS", Verdana, sans-serif;
font-size: 32px;
}

#StateA {
}

#StateB {

}

#StateC {

}

#StateD {
background-color: #7499ff
}

#StateE {
background-color: #7499ff
}

#StateF {

}

#StateG {
background-color: #7499ff
}

#StateH {
background-color: #7499ff
}

#StateX {
background-color: #7499ff
}

#StateY {
background-color: #7499ff
.state.leaf {
background-color: #7499ff;
}

#StateZ {
background-color: #7499ff
.state.initial {
}


#diagramTitle {
font-family: Segoe, "Segoe UI", "DejaVu Sans", "Trebuchet MS", Verdana, sans-serif;
font-size: 16px;
.state.initial.leaf {
}

#log {
font-family: 'Droid Sans Mono', Menlo, Consolas, 'Courier New', Courier, monospace;
font-size: 14px;
.state.current {
background-color: #FF4064;
}

.currentState{
border: 3px solid #3D3D3D;
}

.state{
border: 1px solid #3D3D3D;
}
216 changes: 108 additions & 108 deletions web/index.html
Original file line number Diff line number Diff line change
@@ -1,66 +1,63 @@
<!doctype html>
<html>

<head>
<meta charset="utf-8">
<title>FHSM Demo</title>
<script type='text/javascript' src='//code.jquery.com/jquery-2.1.0.js'></script>
<script type="text/javascript" src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link href="css/style.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="js/qwe.js"></script>
<meta charset="utf-8">
<title>qwe demo</title>
<script type='text/javascript' src='http://code.jquery.com/jquery-2.1.0.js'></script>
<script type="text/javascript" src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link href="css/style.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="js/qwe.js"></script>
</head>

<body>
<div id="container-box">
<div id="left-col">

<h2 id="diagramTitle">Click the on a state and watch the log</h2>

<div id="StateA" class="state box">
state <strong>A</strong>

<div id="StateB" class="state box">
state <strong>B</strong> <span class="first-state">*</span>

<div id="StateC" class="state box">
<div id="StateA" class="state initial">
state <strong>A</strong>*
<div id="StateB" class="state initial">
state <strong>B</strong>*
<div id="StateC" class="state">
state <strong>C</strong>

<div id="StateD" class="state box">
state <strong>D</strong> <span class="first-state">*</span><br/><br/>
<div id="StateD" class="state leaf initial">
state <strong>D</strong>*
</div>
<div id="StateE" class="state box">
state <strong>E</strong><br/>
<div id="StateE" class="state leaf">
state <strong>E</strong>
</div>
</div>
<div id="StateF" class="state box">
state <strong>F</strong> <span class="first-state">*</span>

<div id="StateG" class="state box">
state <strong>G</strong><br/>
<div id="StateF" class="state initial">
state <strong>F</strong>*
<div id="StateG" class="state leaf">
state <strong>G</strong>
</div>
<div id="StateH" class="state box">
state <strong>H</strong> <span class="first-state">*</span><br/>
<div id="StateH" class="state leaf initial">
state <strong>H</strong>*
</div>
</div>
<div id="StateX" class="state box">
<div id="StateX" class="state leaf">
state <strong>X</strong>
</div>
</div>
<div id="StateY" class="state box">
<div id="StateY" class="state leaf">
state <strong>Y</strong>
</div>
</div>
<div id="StateZ" class="state box">
<div id="StateZ" class="state leaf">
state <strong>Z</strong>
</div>

</div>

<div id="right-col">
<div id="right-col-container">
<h2>Diagram</h2>
<p class="diagram-description">
States are classified in <strong>leaf</strong> and <strong>non-leaf</strong> states:
<ul class="diagram-description">
<li class="diagram-description"><strong>leaf states</strong> are colored in blue have no children</li>
<li class="diagram-description"><strong>leaf states</strong> are colored in blue and have no children</li>
<li class="diagram-description"><strong>non-leaf states</strong> have at least one child that is marked (*)
as an initial state
</li>
Expand All @@ -69,89 +66,92 @@ <h2>Diagram</h2>
<h2>Log</h2>
<button id="clearButton">Clear</button>
<br/>
<textarea id="log" rows="23" cols="60" title="Log"></textarea>
<textarea id="log" rows="23" cols="60" title="Log" readonly></textarea>
</div>
</div>
</div>
</div>

<script>
$(document).ready(function(){
qwe.dbgMode(true);
var log = $('#log');

var StateA = qwe.state('StateA');
StateA.trace = function(text) {
var state = this.hsm.state;
log.append(state.name +': ' + text + '\n');
};
StateA.moveTo = function(e, state){ this.hsm.tran(state); };

var StateB = qwe.state('StateB', StateA);
var StateC = qwe.state('StateC', StateB, false);
var StateD = qwe.state('StateD', StateC);
var StateE = qwe.state('StateE', StateC);
var StateF = qwe.state('StateF', StateB);
var StateG = qwe.state('StateG', StateF, false);
var StateH = qwe.state('StateH', StateF);
var StateX = qwe.state('StateX', StateB);
var StateY = qwe.state('StateY', StateA);
var StateZ = qwe.state('StateZ');
// A Whole new state machine
StateZ.trace = function(text) {
var state = this.hsm.state;
log.append(state.name +': ' + text + '\n');
};
StateZ.moveTo = function(e, state){ this.hsm.tran(state); };


function MyObject(){
// Put here any state you want
}

var obj = new MyObject();
qwe.init(obj, StateA, function(srcState, currState){
this.hsm.trace('Previous state was: ' + srcState.name);
this.hsm.trace('Current state is: ' + currState.name);
});

////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// From here just the scene setup
////////////////////////////////////////////////////////////////////////////////////////////////////////////////

var log = $('#log');
qwe.dbgMode(true);

var TopState = qwe.state('TopState');

TopState.trace = function(text) {
var state = this.hsm.state;
log.append(state.name +': ' + text + '\n');
};

var StateA = qwe.state('StateA', TopState);
var StateB = qwe.state('StateB', StateA);
var StateC = qwe.state('StateC', StateB, false);
var StateD = qwe.state('StateD', StateC);
var StateE = qwe.state('StateE', StateC);
var StateF = qwe.state('StateF', StateB);
var StateG = qwe.state('StateG', StateF, false);
var StateH = qwe.state('StateH', StateF);
var StateX = qwe.state('StateX', StateB);
var StateY = qwe.state('StateY', StateA);
var StateZ = qwe.state('StateZ', TopState);

TopState.enter = function(e, state){
log.append('State machine initialization\n');
log.append('qwe.dbgInspectState:\n');
log.append(qwe.dbgInspectState(StateA));
};

TopState.moveTo = function(e, state) {
log.append('executing Action "moveTo" ' + state.name +'\n');
this.counter += 1;
this.hsm.tran(state);
log.append('None passes these parts!');
};

function MyObject() {
// Put here any state you want
this.counter = 0;
}
var obj = new MyObject();

qwe.init(obj, TopState, function(srcState, currState) {
this.hsm.trace('Previous state was ' + srcState.name);
this.hsm.trace('Current state is ' + currState.name);
this.hsm.trace('counter=' + this.counter);
$('#'+srcState.name).removeClass('current');
$('#'+currState.name).addClass('current');
});

///////////////////////////////////////////////////////////////////////////////////////
// From here just the scene setup
///////////////////////////////////////////////////////////////////////////////////////

$('#clearButton').on('click', function(){
log.html('');
});

function createEventHandler(state){
function handler(e){
log.html('');
log.append('qwe.dbgInspectState:\n');
log.append(qwe.dbgInspectState(StateA));
log.append('HSM Initialized\nClick on the diagram!\n');

function createEventHandler(state){
function handler(e){
log.html('');
log.append('clicked ' + state.name + '\n');
e.stopImmediatePropagation();
obj.hsm.send('moveTo', state);
}
return handler;
}

$('#StateA').on('click', createEventHandler(StateA));
$('#StateB').on('click', createEventHandler(StateB));
$('#StateC').on('click', createEventHandler(StateC));
$('#StateD').on('click', createEventHandler(StateD));
$('#StateE').on('click', createEventHandler(StateE));
$('#StateF').on('click', createEventHandler(StateF));
$('#StateG').on('click', createEventHandler(StateG));
$('#StateH').on('click', createEventHandler(StateH));
$('#StateX').on('click', createEventHandler(StateX));
$('#StateY').on('click', createEventHandler(StateY));
$('#StateZ').on('click', createEventHandler(StateZ));

$('#clearButton').on('click', function(){
log.html('');
});

});

log.append('clicked ' + state.name + '\n');
e.stopImmediatePropagation();
obj.hsm.send('moveTo', state);
}
return handler;
}

$('#StateA').on('click', createEventHandler(StateA));
$('#StateB').on('click', createEventHandler(StateB));
$('#StateC').on('click', createEventHandler(StateC));
$('#StateD').on('click', createEventHandler(StateD));
$('#StateE').on('click', createEventHandler(StateE));
$('#StateF').on('click', createEventHandler(StateF));
$('#StateG').on('click', createEventHandler(StateG));
$('#StateH').on('click', createEventHandler(StateH));
$('#StateX').on('click', createEventHandler(StateX));
$('#StateY').on('click', createEventHandler(StateY));
$('#StateZ').on('click', createEventHandler(StateZ));
</script>
</body>

</html>