// import can from 'can'; import superMap from 'can-connect/can/super-map/'; import tag from 'can-connect/can/tag/'; import 'can/map/define/define'; import List from 'can/list/'; import Map from 'can/map/'; import io from 'steal-socket.io'; const ItemsList = List.extend({}, { has: function(item) { return this.indexOf(item) !== -1; }, toggle: function(item) { var index = this.indexOf(item); if (index !== -1) { this.splice(index, 1); } else { this.push(item); } } }); let Order = Map.extend({ define: { status: { value: 'new' }, items: { Value: ItemsList
Game.List = List.extend({Map: Game}, /** @prototype */ { define: { /** * @property {Object<roundName,Object<courtName,bitballs/models/game>>} bitballs/models/game.static.List.properties.gamesGroupedByRound gamesGroupedByRound * @parent bitballs/models/game.static.List.properties * * An object that maps round names to court names to [bitballs/models/game] models. */ gamesGroupedByRound: { type: '*', get: function() { var rounds = {}; this.each(function (game) { var roundName = game.attr('round'); var courtName = game.attr('court'); // Get, or define the Round pseudo-model rounds[roundName] = rounds[roundName] || { _count: 0 }; // Store the game and increment the count rounds[roundName][courtName] = game; rounds[roundName]._count++; }); return rounds; } }, }, /** * @function * * Reads from the `_count` property for the given `roundName` in * [bitballs/models/game.static.List.properties.gamesGroupedByRound]. * * @param {String} roundName * @return {Array<String>} */ getGameCountForRound: function (roundName) { var gamesGroupedByRound = this.attr("gamesGroupedByRound"), round = gamesGroupedByRound[roundName]; return round ? round._count : 0; }, /** * @function * * Returns a sorted array of rounds that don't reference a [bitballs/models/game] * in [bitballs/models/game.static.List.properties.gamesGroupedByRound]. * * @return {Array<Object>} */ getAvailableRounds: function() { return Game.roundNames.filter(function (roundName) { return this.getGameCountForRound(roundName) < Game.courtNames.length; }, this); }, /** * @function * * Returns a sorted array of rounds that reference at least one [bitballs/models/game] * in [bitballs/models/game.static.List.properties.gamesGroupedByRound]. * * @return {Array<Object>} **/ getRoundsWithGames: function() { return Game.roundNames.filter(function (roundName) { return this.getGameCountForRound(roundName) > 0; }, this); }, /** * @function * Returns a sorted array of courts in [bitballs/models/game.static.List.properties.gamesGroupedByRound] * that don't reference a [bitballs/models/game] for the given `roundName`. * @param {String} roundName * @return {Array<Object>} */ getAvailableCourts: function(roundName) { return Game.courtNames.filter(function (courtName) { return !this.getGameForRoundAndCourt(roundName, courtName); }, this); }, /** * @function * * Gets a reference to a [bitballs/models/game] in [bitballs/models/game.static.List.properties.gamesGroupedByRound] * using the provided `roundName` and `courtName`. * * @param {String} roundName * @param {String} courtName * * @return {bitballs/models/game} */ getGameForRoundAndCourt: function(roundName, courtName) { var gamesGroupedByRound = this.attr("gamesGroupedByRound"), round = gamesGroupedByRound[roundName]; return round && round[courtName]; } });
import List from 'can/list/'; export const Filter = CanMap.extend({ define: { value: {}, name: { type: 'string', value: '' }, operator: { value: 'like' } } }); export const FilterList = List.extend({ 'Map': CanMap }); export const FilterOptions = [{ label: 'Does not contain', value: 'not_like', types: ['string'] }, { label: 'Contains', value: 'like', types: ['string'], filterFactory(filter) { filter.attr('value', ['%', filter.attr('value'), '%'].join('')); return filter; } }, {