diff options
| author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2019-03-13 15:48:14 -0400 | 
|---|---|---|
| committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2019-03-13 15:48:14 -0400 | 
| commit | b62d43ccde70aa6fccf5341e57a695a2cfb289c1 (patch) | |
| tree | 8e612d68c89e8358c80663f2dcfab35f33ba89c3 | |
| parent | b6018ad11156d8b38a87dc682064495cd788608c (diff) | |
| download | thoughts-b62d43ccde70aa6fccf5341e57a695a2cfb289c1.tar.gz thoughts-b62d43ccde70aa6fccf5341e57a695a2cfb289c1.tar.bz2 thoughts-b62d43ccde70aa6fccf5341e57a695a2cfb289c1.zip | |
Game list is sortable
| -rw-r--r-- | app/assets/images/down_arrow.gif | bin | 0 -> 843 bytes | |||
| -rw-r--r-- | app/assets/images/up_arrow.gif | bin | 0 -> 835 bytes | |||
| -rw-r--r-- | app/assets/javascripts/entries.coffee | 3 | ||||
| -rw-r--r-- | app/assets/stylesheets/main/games.scss | 40 | ||||
| -rw-r--r-- | app/controllers/games_controller.rb | 14 | ||||
| -rw-r--r-- | app/helpers/application_helper.rb | 7 | ||||
| -rw-r--r-- | app/views/games/index.html.haml | 45 | 
7 files changed, 84 insertions, 25 deletions
| diff --git a/app/assets/images/down_arrow.gif b/app/assets/images/down_arrow.gif new file mode 100644 index 0000000..3438db3 --- /dev/null +++ b/app/assets/images/down_arrow.gif | |||
| Binary files differ | |||
| diff --git a/app/assets/images/up_arrow.gif b/app/assets/images/up_arrow.gif new file mode 100644 index 0000000..6438c97 --- /dev/null +++ b/app/assets/images/up_arrow.gif | |||
| Binary files differ | |||
| diff --git a/app/assets/javascripts/entries.coffee b/app/assets/javascripts/entries.coffee deleted file mode 100644 index 24f83d1..0000000 --- a/app/assets/javascripts/entries.coffee +++ /dev/null | |||
| @@ -1,3 +0,0 @@ | |||
| 1 | # Place all the behaviors and hooks related to the matching controller here. | ||
| 2 | # All this logic will automatically be available in application.js. | ||
| 3 | # You can use CoffeeScript in this file: http://coffeescript.org/ | ||
| diff --git a/app/assets/stylesheets/main/games.scss b/app/assets/stylesheets/main/games.scss index 98aca43..901d30d 100644 --- a/app/assets/stylesheets/main/games.scss +++ b/app/assets/stylesheets/main/games.scss | |||
| @@ -18,6 +18,36 @@ | |||
| 18 | td { | 18 | td { | 
| 19 | padding: 0.5em; | 19 | padding: 0.5em; | 
| 20 | } | 20 | } | 
| 21 | |||
| 22 | thead { | ||
| 23 | th { | ||
| 24 | border-bottom: 1px solid #aaa; | ||
| 25 | text-align: left; | ||
| 26 | padding: 0.5em; | ||
| 27 | |||
| 28 | a { | ||
| 29 | text-decoration: none; | ||
| 30 | |||
| 31 | &:visited { | ||
| 32 | color: blue; | ||
| 33 | } | ||
| 34 | } | ||
| 35 | |||
| 36 | .current { | ||
| 37 | padding-right: 12px; | ||
| 38 | background-repeat: no-repeat; | ||
| 39 | background-position: right center; | ||
| 40 | |||
| 41 | &.asc { | ||
| 42 | background-image: image-url("up_arrow.gif"); | ||
| 43 | } | ||
| 44 | |||
| 45 | &.desc { | ||
| 46 | background-image: image-url("down_arrow.gif"); | ||
| 47 | } | ||
| 48 | } | ||
| 49 | } | ||
| 50 | } | ||
| 21 | } | 51 | } | 
| 22 | 52 | ||
| 23 | .game-progress p { | 53 | .game-progress p { | 
| @@ -34,3 +64,13 @@ | |||
| 34 | font-size: 0.8em; | 64 | font-size: 0.8em; | 
| 35 | color: #777; | 65 | color: #777; | 
| 36 | } | 66 | } | 
| 67 | |||
| 68 | h2#games-title { | ||
| 69 | background-color: #d6aeff; | ||
| 70 | display: block; | ||
| 71 | font-size: 20px; | ||
| 72 | font-family: 'Roboto', sans-serif; | ||
| 73 | padding: 0.5em 20px; | ||
| 74 | border-top: 1px solid #edf; | ||
| 75 | border-bottom: 1px solid #edf; | ||
| 76 | } | ||
| diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 8ddcf24..dcbe226 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb | |||
| @@ -1,9 +1,21 @@ | |||
| 1 | class GamesController < ApplicationController | 1 | class GamesController < ApplicationController | 
| 2 | helper_method :sort_column, :sort_direction | ||
| 3 | |||
| 2 | def index | 4 | def index | 
| 3 | @games = Game.order(started_on: :desc) | 5 | @games = Game.order(sort_column + " " + sort_direction) | 
| 4 | 6 | ||
| 5 | if params[:status] | 7 | if params[:status] | 
| 6 | @games = @games.where(status: params[:status]) | 8 | @games = @games.where(status: params[:status]) | 
| 7 | end | 9 | end | 
| 8 | end | 10 | end | 
| 11 | |||
| 12 | private | ||
| 13 | |||
| 14 | def sort_column | ||
| 15 | Game.column_names.include?(params[:sort]) ? params[:sort] : "started_on" | ||
| 16 | end | ||
| 17 | |||
| 18 | def sort_direction | ||
| 19 | %[asc desc].include?(params[:dir]) ? params[:dir] : "asc" | ||
| 20 | end | ||
| 9 | end | 21 | end | 
| diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index a8b1c7e..8008b04 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb | |||
| @@ -4,4 +4,11 @@ module ApplicationHelper | |||
| 4 | content_for :title, text | 4 | content_for :title, text | 
| 5 | end | 5 | end | 
| 6 | 6 | ||
| 7 | def sortable(col, title = nil) | ||
| 8 | title ||= col.titleize | ||
| 9 | css_class = (col == sort_column) ? "current #{sort_direction}" : nil | ||
| 10 | direction = (col == sort_column and sort_direction == "asc") ? "desc" : "asc" | ||
| 11 | link_to title, {:sort => col, :dir => direction}, {:class => css_class} | ||
| 12 | end | ||
| 13 | |||
| 7 | end | 14 | end | 
| diff --git a/app/views/games/index.html.haml b/app/views/games/index.html.haml index f7e7a44..56c5a05 100644 --- a/app/views/games/index.html.haml +++ b/app/views/games/index.html.haml | |||
| @@ -1,23 +1,26 @@ | |||
| 1 | - title "Games" | 1 | - title "Games" | 
| 2 | %h2 Games | 2 | .breadcrumb= link_to "← Back to home page", root_path | 
| 3 | %h2#games-title Games | ||
| 3 | %table#games-table | 4 | %table#games-table | 
| 4 | %tr | 5 | %thead | 
| 5 | %th Title | 6 | %tr | 
| 6 | %th Status | 7 | %th= sortable "title" | 
| 7 | %th Score | 8 | %th= sortable "status" | 
| 8 | %th Progress | 9 | %th= sortable "score" | 
| 9 | - @games.each do |game| | 10 | %th= sortable "progress" | 
| 10 | %tr{ class: cycle("even", "odd") } | 11 | %tbody | 
| 11 | %td | 12 | - @games.each do |game| | 
| 12 | %span.game-title= game.title | 13 | %tr{ class: cycle("even", "odd") } | 
| 13 | - unless game.started_on.blank? | 14 | %td | 
| 14 | %span.game-started | 15 | %span.game-title= game.title | 
| 15 | Started on | 16 | - unless game.started_on.blank? | 
| 16 | %time= game.started_on | 17 | %span.game-started | 
| 17 | - unless game.finished_on.blank? | 18 | Started on | 
| 18 | %span.game-finished | 19 | %time= game.started_on | 
| 19 | Finished on | 20 | - unless game.finished_on.blank? | 
| 20 | %time= game.finished_on | 21 | %span.game-finished | 
| 21 | %td= game.status | 22 | Finished on | 
| 22 | %td= game.score | 23 | %time= game.finished_on | 
| 23 | %td.game-progress= simple_format game.progress | 24 | %td= game.status | 
| 25 | %td= game.score | ||
| 26 | %td.game-progress= simple_format game.progress | ||
