Skip to content

Commit

Permalink
#23 input color based on success/error implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
lazygalaxy committed Apr 16, 2016
1 parent 170d928 commit e258041
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 21 deletions.
6 changes: 3 additions & 3 deletions client/common/general.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
<div class="col-xs-6">
{{#if equals this.homeTeam._id 'CTRY_XYZ'}}
<input value="" class="form-control" style="margin: 0 auto;width: 50px;text-align: center;" required disabled> {{else}}
<input id="{{this._id}}" name="homeScore" value="{{this.homeScore}}" class="form-control" style="margin: 0 auto;width: 50px;text-align: center;" required> {{/if}}
<input id="{{this._id}}" name="homeScore" value="{{this.homeScore}}" class="form-control" style="margin: 0 auto;width: 50px;text-align: center;background-color: {{this.homeScoreColor}};" required> {{/if}}
</div>
<div class="col-xs-6">
{{#if equals this.awayTeam._id 'CTRY_XYZ'}}
<input value="" class="form-control" style="margin: 0 auto;width: 50px;text-align: center;" required disabled> {{else}}
<input id="{{this._id}}" name="awayScore" value="{{this.awayScore}}" class="form-control" style="margin: 0 auto;width: 50px;text-align: center;" required> {{/if}}
<input id="{{this._id}}" name="awayScore" value="{{this.awayScore}}" class="form-control" style="margin: 0 auto;width: 50px;text-align: center;background-color: {{this.awayScoreColor}};" required> {{/if}}
</div>
<div class="col-xs-12">{{this.description}}
</div>
Expand Down Expand Up @@ -96,7 +96,7 @@ <h4 class="modal-title">Question Rules ({{points}} points)</h4>
</div>
<div class=" text-center">
<p>{{this.description}} ({{points}} points)</p>{{#if equals this.optionType 'INTEGER'}}
<input id="{{this._id}}" name="answer" value="{{this.answer}}" class="form-control" style="margin: 0 auto;width: 200px;text-align: center;"> {{else}}
<input id="{{this._id}}" name="answer" value="{{this.answer}}" class="form-control" style="margin: 0 auto;width: 200px;text-align: center;background-color: {{this.answerColor}};"> {{else}}
<div class="btn-group">
<button data-toggle="dropdown" class="btn btn-primary dropdown-toggle" style="width: 200px;">{{> displayOption getActor this.answer}}&nbsp;<span class="caret"></span></button>
<ul class="dropdown-menu scrollable-menu answer-selection">
Expand Down
4 changes: 4 additions & 0 deletions client/pages/admin/resultAdmin.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ Template.resultAdmin.helpers({

matches.forEach(function (match) {
match.type = 'match';
match.homeScoreColor = '#ffffff';
match.awayScoreColor = '#ffffff';
if (match._id in resultsMap) {
match.homeScore = resultsMap[match._id].homeScore;
match.awayScore = resultsMap[match._id].awayScore;
Expand All @@ -37,6 +39,8 @@ Template.resultAdmin.helpers({

questions.forEach(function (question) {
question.type = 'question';
question.answerColor = '#ffffff';

if (question._id in resultsMap) {
question.answer = resultsMap[question._id].answer;
}
Expand Down
49 changes: 40 additions & 9 deletions client/pages/predictions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ Template.predictions.helpers({
}).fetch();

var matches = Matches.find({
// "homeTeam.iso3": {
// $ne: 'XYZ'
// },
// "awayTeam.iso3": {
// $ne: 'XYZ'
// },
// "homeTeam.iso3": {
// $ne: 'XYZ'
// },
// "awayTeam.iso3": {
// $ne: 'XYZ'
// },
date: {
$gt: new Date()
}
Expand All @@ -28,16 +28,47 @@ Template.predictions.helpers({

matches.forEach(function (match) {
match.type = 'match';
match.homeScoreColor = '#ffffff';
match.awayScoreColor = '#ffffff';

if (match._id in predictionsMap) {
match.homeScore = predictionsMap[match._id].homeScore;
match.awayScore = predictionsMap[match._id].awayScore;
var prediction = predictionsMap[match._id];

match.homeScore = prediction.homeScore;
if (prediction.hasOwnProperty('homeScoreError')) {
if (prediction.homeScoreError) {
match.homeScoreColor = '#ff7777';
} else {
match.homeScoreColor = '#77ff77';
}
}

match.awayScore = prediction.awayScore;
if (prediction.hasOwnProperty('awayScoreError')) {
if (prediction.awayScoreError) {
match.awayScoreColor = '#ff7777';
} else {
match.awayScoreColor = '#77ff77';
}
}
}
});

questions.forEach(function (question) {
question.type = 'question';
question.answerColor = '#ffffff';

if (question._id in predictionsMap) {
question.answer = predictionsMap[question._id].answer;
var prediction = predictionsMap[question._id];
question.answer = prediction.answer;

if (prediction.hasOwnProperty('answerError')) {
if (prediction.answerError) {
question.answerColor = '#ff7777';
} else {
question.answerColor = '#77ff77';
}
}
}
});
}
Expand Down
41 changes: 32 additions & 9 deletions server/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,31 @@ Meteor.startup(function () {
Meteor.methods({
'upsertPrediction': function (itemId, name, value) {
if (Meteor.user()) {
var obj = {};
var validation = validateValue(itemId, name, value);
value = validation[0];
if (validation.length == 2) {
obj[name + 'Error'] = true;
Predictions.upsert({
_id: itemId + '_' + Meteor.user()._id
}, {
$set: obj
});
console.info(itemId + '_' + Meteor.user()._id + ' ' + name + 'Error');
throw new Meteor.Error(500, validation[1]);
}

value = validation[0];
var nowDate = new Date();
if (nowDate > validation[1]) {
if (nowDate > validation[2]) {
throw new Meteor.Error(500, 'Prediction item has expired.');
}

var prediction = Predictions.findOne({
_id: itemId + '_' + Meteor.user()._id
});
if (!prediction || !prediction.hasOwnProperty(name) || prediction[name] != value) {
var obj = {};
obj[name] = value;
obj[name + 'Error'] = false;
obj['date'] = new Date();
obj['itemId'] = itemId;
obj['competitionId'] = itemId.split('_')[0];
Expand All @@ -25,15 +36,25 @@ Meteor.startup(function () {
}, {
$set: obj
});
return validation[2];
return validation[1];
} else if (prediction[name] == value && prediction[name + 'Error']) {
obj[name + 'Error'] = false;
Predictions.upsert({
_id: itemId + '_' + Meteor.user()._id
}, {
$set: obj
});
}
}
},
'upsertResult': function (itemId, name, value) {
if (Meteor.user()) {
var validation = validateValue(itemId, name, value);
value = validation[0];
if (validation.length == 2) {
throw new Meteor.Error(500, validation[1]);
}

value = validation[0];
var result = Results.findOne({
_id: itemId + '_' + Meteor.user()._id
});
Expand All @@ -49,7 +70,7 @@ Meteor.startup(function () {
}, {
$set: obj
});
return validation[2];
return validation[1];
}
}
},
Expand Down Expand Up @@ -96,7 +117,8 @@ Meteor.startup(function () {
});
if (match) {
if (!value || (value % 1 != 0) || value < 0 || value > 9) {
throw new Meteor.Error(500, 'Invalid value entered ' + value + '. Integer values between 0 and 9 expected.');
message = 'Invalid value entered ' + value + '. Integer values between 0 and 9 expected.';
return [value, message];
}
value = parseInt(value);
predictionEndDate = match.date;
Expand All @@ -112,7 +134,8 @@ Meteor.startup(function () {
if (question) {
if (question.optionType == 'INTEGER') {
if (!value || (value % 1 != 0) || value < 0 || value > 999) {
throw new Meteor.Error(500, 'Invalid value entered ' + value + '. Integer values between 0 and 999 expected.');
message = 'Invalid value entered ' + value + '. Integer values between 0 and 999 expected.';
return [value, message];
}
value = parseInt(value);
}
Expand All @@ -123,6 +146,6 @@ Meteor.startup(function () {
}
}

return [value, predictionEndDate, message];
return [value, message, predictionEndDate];
}
});

0 comments on commit e258041

Please sign in to comment.