Skip to content

Commit

Permalink
Implement live and all followed games
Browse files Browse the repository at this point in the history
- Merge Game and GamesFollowed models and inherit from Game
- Create GamesLiveFollowed model and inherit from GamesTop
- Set query parameters to UserFollowedGamesRoute
- Add UserFollowedGamesController and add quickbar toggle button

Resolve #243, #148, #109
  • Loading branch information
bastimeyer committed Apr 27, 2016
1 parent b47c5ca commit 8c7d3ff
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 19 deletions.
3 changes: 3 additions & 0 deletions src/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ define(function( require ) {
TwitchChannelsFollowedSerializer: require( "models/twitch/ChannelsFollowedSerializer" ),
TwitchGamesFollowed: require( "models/twitch/GamesFollowed" ),
TwitchGamesFollowedSerializer: require( "models/twitch/GamesFollowedSerializer" ),
TwitchGamesLiveFollowed: require( "models/twitch/GamesLiveFollowed" ),
TwitchGamesLiveFollowedSerializer: require( "models/twitch/GamesLiveFollowedSerializer" ),

TwitchSearchGame: require( "models/twitch/SearchGame" ),
TwitchSearchGameSerializer: require( "models/twitch/SearchGameSerializer" ),
Expand Down Expand Up @@ -273,6 +275,7 @@ define(function( require ) {
UserFollowedChannelsController: require( "controllers/UserFollowedChannelsController" ),
UserFollowedChannelsTemplate: require( "hbs!templates/user/UserFollowedChannels" ),
UserFollowedGamesRoute: require( "routes/UserFollowedGamesRoute" ),
UserFollowedGamesController: require( "controllers/UserFollowedGamesController" ),
UserFollowedGamesTemplate: require( "hbs!templates/user/UserFollowedGames" ),

SettingsRoute: require( "routes/SettingsRoute" ),
Expand Down
22 changes: 22 additions & 0 deletions src/app/controllers/UserFollowedGamesController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
define([
"Ember"
], function(
Ember
) {

var get = Ember.get;
var set = Ember.set;


return Ember.Controller.extend({
queryParams: [ "all" ],

actions: {
"toggleAll": function() {
// query parameters are strings
set( this, "all", get( this, "all" ) === "true" ? "false" : "true" );
}
}
});

});
3 changes: 2 additions & 1 deletion src/app/models/twitch/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ define([
giantbomb_id: attr( "number" ),
logo: belongsTo( "twitchImage", { async: false } ),
name: attr( "string" ),
popularity: attr( "number" )
popularity: attr( "number" ),
properties: attr()

}).reopenClass({
toString: function() { return "kraken/games"; }
Expand Down
17 changes: 3 additions & 14 deletions src/app/models/twitch/GamesFollowed.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
define([
"EmberData"
"models/twitch/Game"
], function(
DS
Game
) {

var attr = DS.attr;
var belongsTo = DS.belongsTo;


return DS.Model.extend({
box: belongsTo( "twitchImage", { async: false } ),
giantbomb_id: attr( "number" ),
logo: belongsTo( "twitchImage", { async: false } ),
name: attr( "string" ),
properties: attr( "number" )

}).reopenClass({
return Game.extend().reopenClass({
toString: function() { return "api/users/:user/follows/games"; }
});

Expand Down
11 changes: 11 additions & 0 deletions src/app/models/twitch/GamesLiveFollowed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
define([
"models/twitch/GamesTop"
], function(
GamesTop
) {

return GamesTop.extend().reopenClass({
toString: function() { return "api/users/:user/follows/games/live"; }
});

});
13 changes: 13 additions & 0 deletions src/app/models/twitch/GamesLiveFollowedSerializer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
define([
"models/twitch/GamesTopSerializer"
], function(
GamesTopSerializer
) {

return GamesTopSerializer.extend({
modelNameFromPayloadKey: function() {
return "twitchGamesLiveFollowed";
}
});

});
24 changes: 21 additions & 3 deletions src/app/routes/UserFollowedGamesRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,33 @@ define([
return UserIndexRoute.extend( InfiniteScrollMixin, ModelMetadataMixin, {
itemSelector: ".game-item-component",

modelName: "twitchGamesFollowed",
queryParams: {
all: {
refreshModel: true
}
},

model: function() {
return get( this, "store" ).query( this.modelName, {
modelName: "twitchGamesLiveFollowed",
modelNameAll: "twitchGamesFollowed",

model: function( params ) {
// query parameters are strings
var modelname = params.all === "true"
? this.modelNameAll
: this.modelName;

return get( this, "store" ).query( modelname, {
offset: get( this, "offset" ),
limit : get( this, "limit" )
})
.then( toArray )
.then( preload( "box.large" ) );
},

fetchContent: function() {
return this.model({
all: get( this, "controller.all" )
});
}
});

Expand Down
7 changes: 6 additions & 1 deletion src/templates/user/UserFollowedGames.hbs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
<main class="content content-user content-user-followed-games">
<header>
<h2>Followed games</h2>
<h2>{{#if (is-equal all "true")}}All followed games{{else}}Followed live games{{/if}}</h2>
{{headline-totals total=metadata.total}}
{{#quick-bar}}
{{form-button
action="toggleAll"
class=(unless (is-equal all "true") "active")
icon="fa-video-camera"
title=(if (is-equal all "true") "Show games with live channels" "Show all followed games")}}
{{quick-bar-homepage}}
{{/quick-bar}}
</header>
Expand Down

0 comments on commit 8c7d3ff

Please sign in to comment.