Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Medal Distribution tool #521

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions app/controllers/leagues_controller.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
class LeaguesController < ApplicationController
include LeaguePermissions

before_action except: [:index, :new, :create] do
before_action except: [:index, :new, :create, :medals] do
@league = League.includes(:tiebreakers).find(params[:id])
end

before_action only: [:medals] do
@league = League.includes(:tiebreakers).find(params[:league_id])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the route change this shouldn't be needed. :medals shouldn't be excepted from the previous before_action.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unable to find league ID when I removed the exception and those two lines, re-adding them it works as expected.

image

end

before_action :require_user_leagues_permission, only: [:new, :create, :destroy]
before_action :require_user_league_permission, only: [:edit, :update, :modify]
before_action :require_user_league_permission, only: [:edit, :update, :modify, :medals]
before_action :require_league_not_hidden_or_permission, only: [:show]
before_action :require_hidden, only: [:destroy]

Expand Down Expand Up @@ -49,6 +53,18 @@ def show
.group_by(&:division)
end

def medals
@rosters = @league.rosters.includes(:division)
@ordered_rosters = @league.ordered_rosters_by_division
coreobs marked this conversation as resolved.
Show resolved Hide resolved
@divisions = @ordered_rosters.map(&:first)
@roster = @league.roster_for(current_user) if user_signed_in?
@personal_matches = @roster.matches.pending.ordered.reverse_order.includes(:home_team, :away_team) if @roster
@top_div_matches = @divisions.first.matches.pending.ordered
.includes(:home_team, :away_team).last(5)
@matches = @league.matches.ordered.includes(:rounds, :home_team, :away_team)
.group_by(&:division)
end

def edit
@weekly_scheduler = @league.weekly_scheduler || League::Schedulers::Weekly.new
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/leagues/matches/_matches_table.html.haml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

- if matches.empty?
.py-2.text-muted
%li.list-group-item
coreobs marked this conversation as resolved.
Show resolved Hide resolved
No matches scheduled

- else
Expand Down
65 changes: 65 additions & 0 deletions app/views/leagues/medals.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
- content_for(:title) { "Medal Distribution for #{@league.name}" }

%h1 Medal Distribution for #{@league.name}

%p.alert.alert-warning Please Note: We do not provide a way of distributing your promotional items/medals, only a way of downloading lists of SteamID64 IDs for individual teams or divisions. For distribution, we recommend PGrant, or whatever Valve provides when receiving the promotional item IDs for your medals.

%hr

.row
.col-md-12
.panel.panel-container
.panel-body.table-responsive
- @ordered_rosters.each do |div, rosters|
%h3= div.name
%table.table
%tr
%th #
%th Team
%th Points
%th Add to the list
- present_collection(@league.tiebreakers).each do |tiebreaker|
%th= tiebreaker.name_with_tooltip

- rosters.each_with_index do |roster, rank|
%tr
%th{ scope: 'row' }= rank + 1
%td
= present(roster).listing
%ul{:class => "steamids", style: "display: none"}
- roster.users.each do |player|
%li
=player.steam_id
%td= roster.points
- @league.tiebreakers.each do |tiebreaker|
%th= tiebreaker.value_for(roster)
%td
%input{:name => "list", :type => "checkbox"}
%button.btn.btn-primary.btn-lg.btn-block{:type => "button", :id => "download"} Download
%br

:javascript
$(function() {
function download(filename, text) {
var element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}

$("#download").click(function () {
var ids = [];
$("input:checked").each(function () {
list = $(this).parent().parent().find(".steamids > li");
list.each(function () {
var temp = $(this).html().replace(/(\r\n\t|\n|\r\t)/gm,"");
ids.push(temp);
});
});
console.log(ids);
download("MedalSteam64IDs" + Date.now() + ".txt", ids.join("\n"));
});
});
4 changes: 4 additions & 0 deletions app/views/leagues/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
= inline_svg_tag 'open_iconic/people.svg', class: 'icon mr-2'
Signups

= link_to league_medals_path(@league), class: 'btn btn-admin' do
= inline_svg_tag 'open_iconic/badge.svg', class: 'icon mr-2'
Medals

.spacer.d-none.d-md-block

= link_to edit_league_path(@league), class: 'btn btn-admin', type: 'button' do
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
end

resources :leagues do
get 'medals', to: 'leagues#medals'
coreobs marked this conversation as resolved.
Show resolved Hide resolved
patch 'modify', on: :member

resources :transfers, controller: 'leagues/transfers', only: [:index, :destroy, :update]
Expand Down