added sorting of players-teams-score in confidential page.
This commit is contained in:
1 parent
a314f5d804
commit
ff993beb55
4 files changed
+91
-11
No files matched your search
@@ -1,4 +1,4 @@
|
||||
define(['m', '_', 'util', 'resultParser', 'teams', 'views/topNavBar', 'views/footer'], function(m, _, util, resultParser, teams, topNavBar, footer) {
|
||||
define(['m', '_', 'util', 'resultParser', 'teams', 'views/topNavBar', 'views/footer', 'images/rain.svg'], function(m, _, util, resultParser, teams, topNavBar, footer, rainSvg) {
|
||||
var statsView = {};
|
||||
|
||||
statsView.controller = function(){
|
||||
@@ -85,9 +85,17 @@ define(['m', '_', 'util', 'resultParser', 'teams', 'views/topNavBar', 'views/foo
|
||||
return !_.isNumber(points) ? '-' : points + '';
|
||||
};
|
||||
|
||||
schedulView._gameName = function(game){
|
||||
if(game.rain){
|
||||
return [rainSvg('1.5em'), " ", game.time];
|
||||
}
|
||||
return [game.time, " ", m('span', {style: {visibility: 'hidden'}}, rainSvg('1.5em'))];
|
||||
};
|
||||
|
||||
schedulView._gameRow = function(game){
|
||||
|
||||
return m('tr',[
|
||||
m('td', game.time),
|
||||
m('td', schedulView._gameName(game)),
|
||||
m('td', schedulView._getTeamTag(game.home)),
|
||||
m('td', schedulView._asGamePoints(game.home_points)),
|
||||
m('td', 'vs'),
|
||||
|
||||
@@ -76,36 +76,86 @@ define(['m', '_', 'teams', 'views/topNavBar', 'views/footer'], function (m, _ ,
|
||||
|
||||
var confidentialTable = {};
|
||||
|
||||
confidentialTable._sortFunction = function(sortingElm){
|
||||
|
||||
};
|
||||
|
||||
confidentialTable._sortPlayers = function(sorting, playerList){
|
||||
var sortingKeys = _.map(sorting(), 'key');
|
||||
var sortingDirections = _.map(sorting(), function(o){
|
||||
return o.direction == 1 ? 'desc' : 'asc';
|
||||
});
|
||||
return _.orderBy(playerList, sortingKeys, sortingDirections);
|
||||
};
|
||||
|
||||
confidentialTable.controller = function(model){
|
||||
var players = m.prop([]);
|
||||
var ctrl = {};
|
||||
ctrl.model = model;
|
||||
ctrl.players = m.request({method: "GET", url: "api/players.json"}).then(players);
|
||||
|
||||
ctrl.players = m.request({method: "GET", url: "api/players.json"})
|
||||
.then(players);
|
||||
ctrl.sortPlayers = function(){
|
||||
ctrl.players(confidentialTable._sortPlayers(ctrl.model.sorting, ctrl.players()));
|
||||
};
|
||||
return ctrl;
|
||||
};
|
||||
|
||||
confidentialTable.arrows = function(){
|
||||
confidentialTable._getSortDict = function(sorting){
|
||||
var ret = {};
|
||||
_.each(sorting(), function(elm){
|
||||
ret[elm.key] = elm.direction;
|
||||
});
|
||||
return ret;
|
||||
|
||||
};
|
||||
|
||||
confidentialTable._isSortingUp = function(sorting, key){
|
||||
var dict = confidentialTable._getSortDict(sorting);
|
||||
return dict[key] === 1;
|
||||
};
|
||||
|
||||
confidentialTable._isSortingDown = function(sorting, key){
|
||||
var dict = confidentialTable._getSortDict(sorting);
|
||||
return dict[key] === -1;
|
||||
};
|
||||
|
||||
confidentialTable.arrows = function(sorting, key){
|
||||
var sortUp = confidentialTable._isSortingUp(sorting, key);
|
||||
var sortDown = confidentialTable._isSortingDown(sorting, key);
|
||||
var style = {
|
||||
display: 'inline-block',
|
||||
'line-height': '0.5em',
|
||||
'margin-right': '1em',
|
||||
'font-size': '0.7em'
|
||||
};
|
||||
var sortedStyle = {color: '#8cc14c', 'font-weight': 'bold'};
|
||||
return m('span', {style: style},
|
||||
m('i.fa.fa-chevron-up'),
|
||||
m('i.fa.fa-chevron-up', {style: sortUp ? sortedStyle: {}}),
|
||||
m('br'),
|
||||
m('i.fa.fa-chevron-down')
|
||||
m('i.fa.fa-chevron-down', {style: sortDown ? sortedStyle: {}})
|
||||
);
|
||||
};
|
||||
|
||||
confidentialTable.tableHeader = function(){
|
||||
confidentialTable._setSorting = function(sorting, key){
|
||||
var newDirection = {key: key, direction: -1 * confidentialTable._getSortDict(sorting)[key]};
|
||||
var directions = _.filter(sorting(), function(o){
|
||||
return o.key != key;
|
||||
});
|
||||
sorting([newDirection].concat(directions));
|
||||
};
|
||||
|
||||
confidentialTable.tableHeader = function(sorting){
|
||||
var setSorting = function(key){
|
||||
return _.partial(confidentialTable._setSorting, sorting, key);
|
||||
};
|
||||
return m('thead',
|
||||
m('tr', [
|
||||
m('th', confidentialTable.arrows(), 'Équipe'),
|
||||
m('th', confidentialTable.arrows(), 'Nom'),
|
||||
m('th', {onclick: setSorting('team')}, confidentialTable.arrows(sorting, 'team'), 'Équipe'),
|
||||
m('th', {onclick: setSorting('name')}, confidentialTable.arrows(sorting, 'name'), 'Nom'),
|
||||
m('th.uk-hidden-small', 'Courriel'),
|
||||
m('th.uk-hidden-small', 'Téléphone'),
|
||||
m('th', confidentialTable.arrows(), 'Cote')
|
||||
m('th', {onclick: setSorting('score')}, confidentialTable.arrows(sorting, 'score'), 'Cote')
|
||||
]));
|
||||
};
|
||||
|
||||
@@ -147,8 +197,9 @@ define(['m', '_', 'teams', 'views/topNavBar', 'views/footer'], function (m, _ ,
|
||||
};
|
||||
|
||||
confidentialTable.view = function(ctrl){
|
||||
ctrl.sortPlayers();
|
||||
return m('table.uk-table.uk-table-hover.uk-table-striped',
|
||||
confidentialTable.tableHeader(),
|
||||
confidentialTable.tableHeader(ctrl.model.sorting),
|
||||
confidentialTable.tableBody(ctrl.players(),
|
||||
ctrl.model.activatedTeams(),
|
||||
ctrl.model.activatedScores()
|
||||
@@ -162,6 +213,7 @@ define(['m', '_', 'teams', 'views/topNavBar', 'views/footer'], function (m, _ ,
|
||||
var model = {};
|
||||
model.activatedTeams = m.prop(['bleu', 'rouge', 'jaune', 'gris']);
|
||||
model.activatedScores = m.prop([1, 2, 3, 4, 5]);
|
||||
model.sorting = m.prop([{key: 'team', direction: 1}, {key: 'score', direction: -1}, {key: 'name', direction: 1}]);
|
||||
return model;
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user