Last active
June 11, 2016 14:27
-
-
Save cah-danmonroe/7fa78fb76931b846963bc108adc38744 to your computer and use it in GitHub Desktop.
Score grid - without displayscore object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
appName:'Score Grid Twiddle', | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Route.extend({ | |
model() { | |
return { | |
activityscores: [ | |
this.store.createRecord('activityscore', { | |
activity: { | |
name: 'Activity 1', | |
multiplier: 1 | |
}, | |
scores: [ | |
this.store.createRecord('score', { points: 1 }), | |
this.store.createRecord('score', { points: 2 }), | |
this.store.createRecord('score', { points: 2 }), | |
this.store.createRecord('score', { points: 3 }) | |
] | |
}), | |
this.store.createRecord('activityscore', { | |
activity: { | |
name: 'Activity 2', | |
multiplier: 2 | |
}, | |
scores: [ | |
this.store.createRecord('score', { points: 4 }), | |
this.store.createRecord('score', { points: 3 }), | |
this.store.createRecord('score', { points: 3 }), | |
this.store.createRecord('score', { points: 7 }) | |
] | |
}), | |
this.store.createRecord('activityscore', { | |
activity: { | |
name: 'Activity 3', | |
multiplier: 1 | |
}, | |
scores: [ | |
this.store.createRecord('score', { points: 7 }), | |
this.store.createRecord('score', { points: 5 }), | |
this.store.createRecord('score', { points: 5 }), | |
this.store.createRecord('score', { points: 4 }) | |
] | |
}), | |
this.store.createRecord('activityscore', { | |
activity: { | |
name: 'Activity 4', | |
multiplier: 1 | |
}, | |
scores: [ | |
this.store.createRecord('score', { points: 7 }), | |
this.store.createRecord('score', { points: 5 }), | |
this.store.createRecord('score', { points: 5 }), | |
this.store.createRecord('score', { points: 4 }) | |
] | |
}), | |
this.store.createRecord('activityscore', { | |
activity: { | |
name: 'Activity 5', | |
multiplier: 1 | |
}, | |
scores: [ | |
this.store.createRecord('score', { points: 7 }), | |
this.store.createRecord('score', { points: 5 }), | |
this.store.createRecord('score', { points: 5 }), | |
this.store.createRecord('score', { points: 4 }) | |
] | |
}), | |
this.store.createRecord('activityscore', { | |
activity: { | |
name: 'Activity 6', | |
multiplier: 1 | |
}, | |
scores: [ | |
this.store.createRecord('score', { points: 7 }), | |
this.store.createRecord('score', { points: 5 }), | |
this.store.createRecord('score', { points: 5 }), | |
this.store.createRecord('score', { points: 4 }) | |
] | |
}) | |
] | |
}; | |
}, | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.ObjectProxy.extend({ | |
droppedHigh:false, | |
droppedLow:false, | |
isDropped: Ember.computed.or('droppedHigh','droppedLow') | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Component.extend({ | |
tagName: 'td', | |
classNames: ["score"], | |
classNameBindings: [ | |
"score.droppedLow:droppedLow", | |
"score.droppedHigh:droppedHigh" | |
], | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import DS from 'ember-data'; | |
export default DS.Model.extend({ | |
name: DS.attr('string'), | |
multiplier: DS.attr('number', {defaultValue: 1}) | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import DS from 'ember-data'; | |
export default DS.Model.extend({ | |
activity: DS.belongsTo('activity'), | |
scores: DS.hasMany('score'), | |
totalScore: DS.attr('number', {defaultValue:0}) | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import DS from 'ember-data'; | |
export default DS.Model.extend({ | |
activityscore: DS.belongsTo('activityscore'), | |
points: DS.attr('number', {defaultValue: 0}), | |
droppedHigh:false, | |
droppedLow:false, | |
isDropped: Ember.computed.or('droppedHigh','droppedLow') | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Component.extend({ | |
totalScoreList: Ember.computed.mapBy('activityscores', 'totalScore'), | |
totalActivitiesScore: Ember.computed.sum('totalScoreList') | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
import DisplayScore from '../displayScore'; | |
export default Ember.Component.extend({ | |
tagName: 'tr', | |
activity: null, | |
sortedScores: Ember.computed.sort('activityscore.scores.@each.points', function (score1, score2) { | |
if (+score1.get('points') > +score2.get('points')) { | |
return 1; | |
} else if (+score1.get('points') < +score2.get('points')) { | |
return -1; | |
} | |
return 0; | |
}), | |
displayScores: Ember.computed('activityscore.scores.@each.points', function () { | |
let scores = this.get('activityscore.scores'); | |
if (Ember.isPresent(scores)) { | |
var numLowToDrop = 1, | |
numHighToDrop = 1; | |
let returnArray = scores; | |
/** | |
let returnArray = scores.map(function (item, index, enumerable) { | |
return DisplayScore.create({ | |
content: item, | |
droppedLow: false, | |
droppedHigh: false | |
}); | |
}); | |
**/ | |
let arrayToSort = returnArray.map(function (item) { | |
return item; | |
}); | |
let sortedArray = arrayToSort.sort(function (score1, score2) { | |
if (+score1.get('points') > +score2.get('points')) { | |
return 1; | |
} else if (+score1.get('points') < +score2.get('points')) { | |
return -1; | |
} | |
return 0; | |
}); | |
sortedArray.forEach(function (item, index, enumerable) { | |
item.set('droppedLow', index < numLowToDrop); | |
item.set('droppedHigh', index >= (enumerable.length - numHighToDrop)); | |
}); | |
return returnArray; | |
} else { | |
return Ember.A(); | |
} | |
}), | |
countedDisplayScores: Ember.computed.filterBy('displayScores', 'isDropped', false), | |
countedDisplayScorePoints: Ember.computed.mapBy('countedDisplayScores', 'points'), | |
calculatedTotal: Ember.computed('countedDisplayScorePoints', function () { | |
let totalScore = 0; | |
this.get('countedDisplayScorePoints').forEach(function (item) { | |
totalScore += +item; | |
}); | |
if (Ember.isPresent(this.get('activityscore.activity.multiplier'))) { | |
totalScore *= +this.get('activityscore.activity.multiplier'); | |
} | |
this.set('activityscore.totalScore', totalScore); | |
return totalScore; | |
}) | |
}); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
margin: 12px 16px; | |
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; | |
font-size: 12pt; | |
} | |
input { | |
width: 50px; | |
text-align: center; | |
margin: 0 5px; | |
} | |
td { | |
text-align: center; | |
padding: 5px; | |
} | |
.score input, input.legend { | |
border: none; | |
border-bottom: 1px solid #333; | |
} | |
.droppedLow input, input.legend.low { | |
color: #A2A2A2; | |
font-style: italic; | |
background-color: #ffdde4; | |
} | |
.droppedHigh input, input.legend.high { | |
color: #A2A2A2; | |
font-style: italic; | |
background-color: #fff0d7; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.4.17", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "2.2.0", | |
"ember-data": "release", | |
"ember-template-compiler": "2.2.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment