leaguevine / leaguevine-ultistats

MIT License
18 stars 4 forks source link

Add a game for a team #20

Closed rrw4 closed 12 years ago

rrw4 commented 12 years ago

This could be a part of Issue #4, but thought I'd open a separate issue. The approach I'm thinking of:

  1. An "Add game" button in the team detail page
  2. Clicking this button goes to an "Add game" page, with Team 1 filled in as the team for which you're adding a game, and Team 2 can be selected, with a search, much like on the Team list page. There will also be an add team button to add a new team, if the opposing team does not exist yet.
  3. On the "Add game" page, other details for the game, like start time (defaults to next hour from current time), tournament, season, etc
  4. After submitting, the new game is created, and we go to the game detail page. User can then select "Take Stats" to start taking stats for the game.
  5. If we need to add players to either team 1 or team 2, that is done in the tracked game page.

Let me know if there's any issues with this approach. I'll start working on this.

cboulay commented 12 years ago

The buttons can be called whatever is most intuitive, but for programming purposes I would prefer this be called "new game", since "add game" might be adding a pre-existing game to a tournament or a team.

The "new game" page should be the same code whether we are creating the game from the team detail page or the tournament detail page. The only difference will be what data the new game is instantiated with.

About point 2 I think the 'add team' button should be integrated into the 'teams' searchable list view. Then the list of teams view will be reusable whether it's in the 'teams' page or in the 'new game add team' page.

The only problem I see with this is knowing where to navigate to when the "save" button is pressed after creating a new team. Should it go to the "new game" page or to the detail page for the newly created team? In the case of adding a team to a game, obviously the user wants to go to the "new game" page, but this means that we have to tell the "new team" page how we got there. It would probably also require persisting the half-created game somewhere and knowing that we need to load this half-created game when we go back to the previous "new game" page, or is it now "edit game"? There are a lot of details to manage to make this work robustly and I'm afraid it will result in a lot of redundant code at this stage. At this point in the project, since the code is changing so rapidly, I'd rather not maintain the same code in multiple places. Thus, even though it's less user friendly, I'd prefer if for now the only place the user could go from the "create team" page was to the team detail page on "save" or to the list of teams on "cancel". It's only 2 extra taps to get back to the "create game" page.

About 3 Teams or tournaments are typically associated with a season. Should we let the user change the season for the game when a game can only be created from either a team or a tournament?

About 5. Hold off on changing the tracked game page for a couple days. I'm in the middle of some major changes to it. I'll let you know (via github) when it's done. Also, I'm not a huge fan of creating a new player from the tracked game (substitution view). First, I think that's jumping past a more basic step which is simply adding players to a team from the "team details" page. Second, there are the navigation issues as per point 2. Third, the cost associated with accidentally pressing the "add player" button is too high given that the user is at their most stressed time when using the 'substitution screen'.

Once we have the local WebSQL db working then the cost will be greatly reduced and we can revisit it then.

mliu7 commented 12 years ago

About 3 I think the behavior of adding the game to the season the team or tournament is in is ideal. We shouldn't end up in a situation where we're attempting to create a game from season X while the teams playing in it are from seasons Y and Z.

About 5 Very interesting point about the cost associated with pressing the "add player" button when the user is frantically adding players. I do still think this would be a great place for the button since this is the time when the user will notice the player doesn't exist yet. But I agree we can put this off until we reduce the cost of a misclick.

cboulay commented 12 years ago

Now that I'm working on the parallel WebSQL storage I'm running into this issue again. Both teams absolutely must exist before the game is created. I'm not sure if the Leaguevine API demands this (can you POST a game without both team_ids?), but my solution demands it. So we need to make sure the game is not persisted until after both teams are created/persisted.

mliu7 commented 12 years ago

The Leaguevine API allows a game to be created with no teams entered. However, I think it is reasonable to expect a user to create the teams before the game is created, so I don't think this constraint will change anything in terms of usability. We'll just need to make sure we perform the API calls in the right order and wait for certain successful responses.

rrw4 commented 12 years ago

Chad, question about the "Create game" page. I've made a Game.Views.Edit view to display the create game page, and it will use a Search.Views.SearchableList to show the teams to select as the opponent. However, selecting the team should cause it to be populate the opposing team field, and remove the list of teams, instead of going to that team's detail page, per the usual behavior of Team.Views.List. Mark and I were discussing how to do this, and weren't quite sure - one approach was to use the JQuery live() function to hijack the click event for a.teams_list_item_link, but then we'd need to make sure that the Team.Views.List doesn't get this event, and it feels too hacky. Another possible option was to write a different Team.Views.List view that has this behavior, instead of using the current Team.Views.List, but this may be too redundant, and I'm not sure if it's a good option either. Any thoughts on what the best approach is?

cboulay commented 12 years ago

It won't be easy, but I think there is a better solution.

  1. Change templates/teams/list.html so that we are not using href
  2. Add a events attribute to modules/team.js Team.Views.Item along the lines of
events: {"click": team_tap_method}
  1. Add an initialize attribute to Team.Views.Item similar to
initialize: function() {
    if (this.options.tap_method){
        this.team_tap_method = this.options.tap_method;
    } else {
        this.team_tap_method = function(){
            Backbone.history.navigate('teams/'+str(this.model.id));
        }
}
  1. In Team.Views.List's render function, add a parameter to new Team.Views.Item({model: team, tap_method: this.options.tap_method})
  2. In Search.Views.SearchableList's render function's new this.options.ViewsListClass({collection: this.collection, tap_method: this.options.tap_method})

Now, when you instantiate the SearchableList for the Game.Views.Edit page, you can pass it a function that will take the item's model.id and insert it into the game's team_ix_id. Getting the context/scope right will be a bit tricky.

Thoughts?

rrw4 commented 12 years ago

It looks good to me, I will try it out. For 1., I'm assuming you're talking about templates/teams/item.html.

cboulay commented 12 years ago

Yes. There are other mistakes in there too (e.g., str() is not a JS function). Consider the above 'pseudocode' even though it looks like real code.

rrw4 commented 12 years ago

I can select the opposing team from the list and have team 1 (the team page from which "Create game" was selected) and team 2 (the selected opposing team) populated. However, before the team is selected, I can't seem to have team 1 show up properly. There's some commented code in the team1.fetch() success() function, which if I add, team 1 shows up beforehand, but then the list of teams doesn't show up. I'm having some problem with context or timing with the fetch success() and rendering, but not quite sure what it is. Thoughts?

Also, you'll need to un-comment templates/search/searchable_list.html and templates/teams/detail.html to see the changes.

cboulay commented 12 years ago

In the Router, newgame and editgame both call the same function, but one passes teamId first and the other gameId. This would be an issue if we used url/editgame.. but we don't. I commented that out for now.

There are some expensive operations in "render" that I would like to avoid redoing everytime I want to re-render, so I put them in the router.

To avoid having the searchable list re-render every time we needed to re-render the team's name, the searchable list and the game edit area must be siblings. So I modified the templates to reflect that.

There is a major thing that I modified, and that is changing the game's toJSON method to call toJSON of team_1 and team_2.