Removed unused models and templates.

This commit is contained in:
BorysLevytskyi
2015-12-04 21:54:47 +02:00
parent b101b89305
commit cae479e991
4 changed files with 19 additions and 112 deletions

View File

@@ -131,21 +131,6 @@
</div>
</script>
<script data-template="shiftExpressionView" data-compiled="" type="text/template">
<table class="expression">
<tr>
<td class="label">{m.operand1.input}</td>
<td class="bin">{m.operand1.bin.padLeft(m.bitsSize, '0')}</td>
<td class="other">{m.operand1.other}</td>
</tr>
<tr class="expression-result">
<td class="label">{m.string.replace(/\s/g,'')}={m.result.input}</td>
<td class="bin">{m.result.bin.padLeft(m.bitsSize, '0')}</td>
<td class="other">{m.result.other}</td>
</tr>
</table>
</script>
<script data-template="bitwiseExpressionView" data-compiled="" type="text/template">
<table class="expression">
{each itm in m.items}
@@ -159,45 +144,6 @@
</table>
</script>
<script data-template="notExpressionView" data-compiled="" type="text/template">
<table class="expression">
<tr>
<td class="sign"></td>
<td class="label">{m.operand1.input}</td>
<td class="bin">{m.operand1.bin.padLeft(m.bitsSize, '0')}</td>
<td class="other">{m.operand1.other}</td>
</tr>
<tr class="expression-result">
<td class="sign">{m.sign}</td>
<td class="label">{m.result.input}</td>
<td class="bin">{m.result.bin.padLeft(m.bitsSize, '0')}</td>
<td class="other">{m.result.other}</td>
</tr>
</table>
</script>
<script data-template="binaryExpressionView" data-compiled="" type="text/template">
<table class="expression">
<tr>
<td class="sign"></td>
<td class="label">{m.operand1.input}</td>
<td class="bin">{m.operand1.bin.padLeft(m.bitsSize, '0')}</td>
<td class="other">{m.operand1.other}</td>
</tr>
<tr>
<td class="sign">{m.sign}</td>
<td class="label">{m.operand2.input}</td>
<td class="bin">{m.operand2.bin.padLeft(m.bitsSize, '0')}</td>
<td class="other">{m.operand2.other}</td>
</tr>
<tr class="expression-result">
<td class="sign">=</td>
<td class="label">{m.result.input}</td>
<td class="bin">{m.result.bin.padLeft(m.bitsSize, '0')}</td>
<td class="other">{m.result.other}</td>
</tr>
</table>
</script>
<script data-template="numbersList" data-compiled="" type="text/template">
<table class="expression">
{each op in m.operands}
@@ -210,8 +156,6 @@
</table>
</script>
<script type="text/javascript">
var app = window.app;
@@ -225,7 +169,7 @@
}
else {
cmd.execute('help');
cmd.execute('1|2');
cmd.execute('1|2&6');
cmd.execute('1<<0x2a');
cmd.execute('2 4 8 16 32');
}

View File

@@ -51,15 +51,15 @@ app.run(function() {
},
locateModel: function (expr) {
if(expr instanceof expression.ListOfNumbersExpression) {
return new app.models.BitwiseNumbers(expr);
return new app.models.BitwiseNumbersViewModel(expr);
}
if(expr instanceof expression.SingleOperandExpression ){
return new app.models.BitwiseExpression.buildNot(expr);
return new app.models.BitwiseExpressionViewModel.buildNot(expr);
}
if(expr instanceof expression.MultipleOperandsExpression) {
return new app.models.BitwiseExpression.buildMultiple(expr);
return new app.models.BitwiseExpressionViewModel.buildMultiple(expr);
}
return new app.models.ErrorResult('Cannot create model for expression: ' + expr.toString());

View File

@@ -13,47 +13,14 @@ app.compose(function () {
// TODO: move to protojs
String.prototype.padLeft = function(size, char) { return formatter.padLeft(this, size, char); }
app.modelView(app.models.BitwiseOperation, function() {
function getTemplateId(model) {
switch (model.sign) {
case '<<':
case '>>':
case '>>>':
return 'shiftExpressionView';
case '~':
return 'notExpressionView';
default:
return 'binaryExpressionView';
}
}
return {
renderView: function(model) {
// TODO: move all this to expression
var result = expression.createOperand(calc.calcExpression(model.expression), getResultMode([model.operand1, model.operand2]));
var maxLen = getBinaryLength([model.operand1.value, model.operand2 != null ? model.operand2.value : 0, result.value]);
var model = Object.create(model);
model.bitsSize = maxLen;
model.result = result;
var templateId = getTemplateId(model);
var template = app.template(templateId);
return colorizeBits(template.render(model));
}
}
});
app.modelView(app.models.BitwiseExpression, {
app.modelView(app.models.BitwiseExpressionViewModel, {
renderView: function(model) {
var template = app.template('bitwiseExpressionView');
return colorizeBits(template.render(model));
}
});
app.modelView(app.models.BitwiseNumbers, {
app.modelView(app.models.BitwiseNumbersViewModel, {
renderView: function(model) {
model.bitsSize = getBinaryLength(model.numbers);
return colorizeBits(app.template('numbersList').render(model));
@@ -95,9 +62,6 @@ app.compose(function () {
return bits;
}
function colorizeBits(container) {
var list = container.querySelectorAll('.bin');
Array.prototype.forEach.call(list, function(el){

View File

@@ -9,7 +9,7 @@
this.string = expr.expressionString;
}
function BitwiseNumbers(expr) {
function BitwiseNumbersViewModel(expr) {
this.expression = expr;
this.operands = expr.numbers;
@@ -20,15 +20,15 @@
});
}
function BitwiseExpression() {
function BitwiseExpressionViewModel() {
this.items = [];
this.maxNumberOfBits = 0;
}
BitwiseExpression.buildMultiple = function (expr) {
BitwiseExpressionViewModel.buildMultiple = function (expr) {
var op = expr.expressions[0],
i = 1, l = expr.expressions.length,
ex, m = new BitwiseExpression();
ex, m = new BitwiseExpressionViewModel();
m.addOperand(op);
@@ -48,25 +48,25 @@
return m;
};
BitwiseExpression.buildNot = function (expression) {
var m = new BitwiseExpression();
BitwiseExpressionViewModel.buildNot = function (expression) {
var m = new BitwiseExpressionViewModel();
m.addExpression(expression);
m.addExpressionResult(expression.apply());
m.maxNumberOfBits = m.emphasizeBytes(m.maxNumberOfBits);
return m;
};
BitwiseExpression.prototype.addOperand = function(operand) {
BitwiseExpressionViewModel.prototype.addOperand = function(operand) {
this.maxNumberOfBits = Math.max(operand.getLengthInBits(), this.maxNumberOfBits);
this.items.push({ sign:'', label: operand.toString(), bin: operand.bin, other: operand.other, css: ''});
};
BitwiseExpression.prototype.addExpression = function(expression) {
BitwiseExpressionViewModel.prototype.addExpression = function(expression) {
this.maxNumberOfBits = Math.max(expression.operand1.getLengthInBits(), this.maxNumberOfBits);
this.items.push({ sign: expression.sign, label: expression.operand1.input, bin: expression.operand1.bin, other: expression.operand1.other, css: ''});
};
BitwiseExpression.prototype.addShiftExpressionResult = function(expression, resultOperand) {
BitwiseExpressionViewModel.prototype.addShiftExpressionResult = function(expression, resultOperand) {
this.maxNumberOfBits = Math.max(resultOperand.getLengthInBits(), this.maxNumberOfBits);
this.items.push({
sign: expression.sign + expression.operand1.input,
@@ -76,12 +76,12 @@
css: 'expression-result'});
};
BitwiseExpression.prototype.addExpressionResult = function(operand) {
BitwiseExpressionViewModel.prototype.addExpressionResult = function(operand) {
this.maxNumberOfBits = Math.max(operand.getLengthInBits(), this.maxNumberOfBits);
this.items.push({ sign:'=', label: operand.toString(), bin: operand.bin, other: operand.other, css: 'expression-result'});
};
BitwiseExpression.prototype.emphasizeBytes = function (bits) {
BitwiseExpressionViewModel.prototype.emphasizeBytes = function (bits) {
var cmdConfig = app.get('cmdConfig');
if(cmdConfig.emphasizeBytes && bits % 8 != 0) {
if(bits < 8) {
@@ -108,11 +108,10 @@
this.content = content;
}
app.models.BitwiseOperation = BitwiseOperation;
app.models.BitwiseNumbers = BitwiseNumbers;
app.models.BitwiseExpressionViewModel = BitwiseExpressionViewModel;
app.models.BitwiseNumbersViewModel = BitwiseNumbersViewModel;
app.models.ErrorResult = ErrorResult;
app.models.ViewResult = ViewResult;
app.models.DisplayResult = DisplayResult;
app.models.BitwiseExpression = BitwiseExpression;
})(window.app);