Skip to content

Commit

Permalink
reset, variables
Browse files Browse the repository at this point in the history
  • Loading branch information
MaryamArab committed Nov 30, 2017
1 parent c02f1a8 commit d7a56ed
Show file tree
Hide file tree
Showing 7 changed files with 197 additions and 60 deletions.
13 changes: 10 additions & 3 deletions StrategyTracker/StrategyTracker.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
<script type="text/ng-template" id="statement-renderer.html">
<div ng-class="(execObj.activeLines.indexOf(st.text) >= 0 ) ? 'active' : 'code'">{{st.text}}</div>
<ul style="list-style: none">
<li ng-repeat=" st in st.statements" ng-include="'statement-renderer.html'"
></li>
<li ng-repeat=" st in st.statements" ng-include="'statement-renderer.html'"></li>
</ul>
</script>
<title> Debugging Strategy</title>
Expand Down Expand Up @@ -167,8 +166,15 @@ <h4 class="panel-title">
variables
</div>
<div class="panel-body text-left">
<div class="form-group var-div">
<label class="col-sm-4" ng-for="var.name" style="margin-bottom: 10px">Test </label>
<div id="value-view-demo">
<!-- This element's contents will be replaced with your component. -->
</div>
</div>

<!--ng-class="{'hidden': currentStatement.variables.indexOf(var.name) === -1}-->
<div class="form-group var-div" ng-repeat="var in allVariables track by $index" >
<div class="form-group var-div" ng-repeat="var in allVariables track by $index" ng-show="var.show" >

<label class="col-sm-4" ng-for="var.name" style="margin-bottom: 10px">{{var.name}} </label>
<input class="col-sm-8" type="text" ng-id="var.name" ng-model="var.val" style="margin-bottom: 10px">
Expand All @@ -184,6 +190,7 @@ <h4 class="panel-title">
</div>
</div>
</body>
<script src="js/build.js"></script>
</html>
</body>
</html>
92 changes: 92 additions & 0 deletions StrategyTracker/js/ValueView.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import React from 'react';

class ValueView extends React.Component {

constructor() {

super();

this.state = {
value: "",
editing: false
};

this.renderValue = this.renderValue.bind(this);
this.edit = this.edit.bind(this);
this.save = this.save.bind(this);
this.handleChange = this.handleChange.bind(this);
this.borderStyle = {border: '1px solid lightGray', padding: '1em', display: 'inline-block'};

}

render() {
return (
<div style={this.borderStyle}>
{
this.state.editing === true ?
<textarea autoFocus onBlur={this.save} value={this.state.value} onChange={this.handleChange}></textarea> :
<div style={{cursor: "pointer"}} onClick={this.edit}>
{ this.renderValue(this.state.value) }
</div>
}
</div>
);
}

// Renders a view appropriate for the string's content.
renderValue(value) {

value = value.trim();

if(value === '' || value === 'nothing') return this.renderNothing();
else if(value.split(',').length > 1) return this.renderList(value);
else if(value.match(/^https?:\/\/[a-zA-Z0-9_\-]+\.?[a-zA-Z0-9_\-]+\.[a-zA-Z0-9_\-??]+$/)) return this.renderLink(value);
else return value;

}

renderNothing() {

return (
<div style={{fontStyle: 'italic'}}>nothing</div>
);

}

renderList(value) {

return value.split(',').map((item, index) => {
return <span style={this.borderStyle} key={index}>{ this.renderValue(item.trim()) }</span>;
});

}

renderLink(value) {

return <a href={value}>{value}</a>;

}

edit() {

// Set to edit. Expects text area to auto-focus itself.
this.setState({ editing: true });

}

save() {

// Return to rendering the view.
this.setState({ editing: false });

}

handleChange(event) {

this.setState({value: event.target.value});

}

}

export { ValueView };
1 change: 1 addition & 0 deletions StrategyTracker/js/build.js

Large diffs are not rendered by default.

71 changes: 42 additions & 29 deletions StrategyTracker/js/bundle.js

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions StrategyTracker/js/demo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';
import ReactDOM from 'react-dom';

import { ValueView } from './ValueView';

import 'bootstrap';

ReactDOM.render((
<ValueView/>
), document.getElementById('value-view-demo'));
63 changes: 39 additions & 24 deletions StrategyTracker/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,23 @@ if (typeof window !== 'undefined' && window.angular) {
$scope.currentStrategy = $scope.execObj.currentStrategy;
$scope.currentStatement = $scope.execObj.currentStatement;
$scope.variables = $scope.execObj.variables;
// for(let i=0; i<$scope.selectedStrategy.strategies.length; i++){
// $scope.extractVariables($scope.selectedStrategy.strategies[i]);
// }
$scope.extractVariables($scope.selectedStrategy.strategies[0]);
for(let i=0; i<$scope.selectedStrategy.strategies.length; i++){
$scope.extractVariables($scope.selectedStrategy.strategies[i]);
}
for(let i = 0; i<varNames.length; i++){
$scope.allVariables.push({"name":varNames[i], "val": null});
$scope.allVariables.push({"name":varNames[i], "val": null, "show": false});
}

varNames = [];
$scope.extractVariables($scope.currentStrategy);
console.log("shown vars", varNames);
angular.forEach($scope.allVariables, function(val, key) {
console.log(key, val);
if(varNames.indexOf(val.name) >= 0) {
val.show = true;
} else {
val.show = false;
}
});
// this is to open the modal to input strategy parameters
$("#initialParams").modal({
backdrop: "static",
Expand All @@ -60,6 +69,19 @@ if (typeof window !== 'undefined' && window.angular) {
};

$scope.initFailure = { val: ""};
function showVars() {
varNames = [];
$scope.extractVariables($scope.currentStrategy);
angular.forEach($scope.allVariables, function(val, key) {
if(varNames.indexOf(val.name) >= 0) {
val.show = true;
} else {
val.show = false;
}
});
// always show the parameter passed to first strategy
$scope.allVariables[0].show = true;
}

// this is to watch any changes for setting up strategy parameters
$scope.$watch('initFailure.val', function(newval, oldval) {
Expand All @@ -68,7 +90,7 @@ if (typeof window !== 'undefined' && window.angular) {

$scope.proceedToStrategy = function() {
angular.forEach($scope.selectedStrategy.strategies[0].parameters, function(val, key) {
$scope.allVariables.unshift({"name": val, "val": $scope.initFailure.val});
$scope.allVariables.unshift({"name": val, "val": $scope.initFailure.val, "show": true});
});
};

Expand All @@ -90,19 +112,21 @@ if (typeof window !== 'undefined' && window.angular) {

$scope.reset= function () {
if($scope.selectedStrategy) {
interpreter.reset();
$scope.allVariables.splice(1);
varNames=[];
$scope.execObj = interpreter.init($scope.selectedStrategy.strategies[0], $scope.selectedStrategy.strategies);
$scope.currentStrategy = $scope.execObj.currentStrategy;
$('#' + $scope.currentStrategy.name).collapse('show');
$scope.currentStatement = $scope.execObj.currentStatement;
$scope.variables = $scope.execObj.variables;
// for(let i=0; i<$scope.selectedStrategy.strategies.length; i++){
// $scope.extractVariables($scope.selectedStrategy.strategies[i]);
// }
$scope.extractVariables($scope.selectedStrategy.strategies[0]);
for(let i=0; i<$scope.selectedStrategy.strategies.length; i++){
$scope.extractVariables($scope.selectedStrategy.strategies[i]);
}
for(let i = 0; i<varNames.length; i++){
$scope.allVariables.push({"name":varNames[i], "val": null});
$scope.allVariables.push({"name":varNames[i], "val": null, "show": false});
}
showVars();
} else {
alert("please choose a strategy first");
}
Expand All @@ -117,12 +141,7 @@ if (typeof window !== 'undefined' && window.angular) {
$('#' + $scope.execObj.currentStrategy.name).collapse('show');
$('#' + $scope.currentStrategy.name).collapse('hide');
$scope.currentStrategy = $scope.execObj.currentStrategy;
$scope.allVariables.splice(1);
varNames=[];
$scope.extractVariables($scope.currentStrategy);
for(let i = 0; i<varNames.length; i++){
$scope.allVariables.push({"name":varNames[i], "val": null});
}
showVars();
if($scope.strategy !== undefined)
$scope.statements = $scope.strategy.statements;
//$('#' +$scope.strategy.name).collapse('show');
Expand All @@ -138,12 +157,8 @@ if (typeof window !== 'undefined' && window.angular) {
$('#' + $scope.currentStrategy.name).collapse('hide');
$scope.currentStrategy = $scope.execObj.currentStrategy;
$scope.statements = $scope.currentStrategy.statements;
$scope.allVariables.splice(1);
varNames=[];
$scope.extractVariables($scope.currentStrategy);
for(let i = 0; i<varNames.length; i++){
$scope.allVariables.push({"name":varNames[i], "val": null});
}
showVars();

}
$scope.currentStatement = $scope.execObj.currentStatement;
$scope.activeLines = $scope.execObj.activeLines;
Expand Down
7 changes: 3 additions & 4 deletions StrategyTracker/js/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ class Interpreter {
}
}
reset(){
let wizardDiv = document.getElementById("wizard");
this.historyBackward.splice(0,this.historyBackward.length);
this.executionStack.splice(0,this.executionStack.length);
this.updateWizard(wizardDiv);
this.executionStack = [];
this.historyBackward = [];
}

findStatementByText(currentStrat,statementText){

for(var i=0; i<currentStrat.statements.length; i++){
Expand Down

0 comments on commit d7a56ed

Please sign in to comment.