loot
This commit is contained in:
@ -1,7 +1,4 @@
|
||||
class AdminController < ApplicationController
|
||||
# echo "ya got butts?" | sha256
|
||||
PASSWORD = "50cf9308a2cd117a16f7c1f8eb2267fb87556066403b751f8fbf0af159bc9bac"
|
||||
|
||||
before_action :authenticate_admin, only: [:index, :set_alt, :clear_alt ]
|
||||
|
||||
def index
|
||||
@ -42,7 +39,7 @@ class AdminController < ApplicationController
|
||||
|
||||
def login_submit
|
||||
pw = params[:password]
|
||||
if pw == PASSWORD
|
||||
if pw == ENV["ADMINPW"]
|
||||
session[:user_id] = 1
|
||||
redirect_to admin_path, notice: "Logged in!"
|
||||
else
|
||||
|
@ -2,15 +2,16 @@ class BotController < ApplicationController
|
||||
skip_before_action :verify_authenticity_token
|
||||
before_action :authenticate
|
||||
|
||||
def players
|
||||
|
||||
def leaderboard
|
||||
players = Player.where(main_player_id: nil).order(purse: :desc)
|
||||
render json: players
|
||||
end
|
||||
|
||||
def summary
|
||||
|
||||
end
|
||||
|
||||
def player_name
|
||||
|
||||
def lords
|
||||
players = Player.where(main_player_id: nil).order(purse: :desc)
|
||||
lords = []
|
||||
lords << players.first
|
||||
lords << players.last
|
||||
render json: lords
|
||||
end
|
||||
end
|
||||
|
43
app/controllers/loot_controller.rb
Normal file
43
app/controllers/loot_controller.rb
Normal file
@ -0,0 +1,43 @@
|
||||
class LootController < ApplicationController
|
||||
skip_before_action :verify_authenticity_token, only: [ :create ]
|
||||
before_action :authenticate, only: [ :create ]
|
||||
|
||||
respond_to? :json
|
||||
|
||||
def create
|
||||
@loot = Loot.new(item_id: params[:item_id], item_name: params[:item_name], timestamp: params[:timestamp], roll_type: params[:roll_type])
|
||||
|
||||
player = Player.find_by(name: params[:player])
|
||||
if player.nil?
|
||||
player = Player.new(name: params[:player], wins: 0, losses: 0, purse: 0)
|
||||
player.save
|
||||
end
|
||||
@loot.player = player
|
||||
|
||||
if @loot.save
|
||||
render json: {}, status: :ok
|
||||
else
|
||||
render json: { error: "Unable to process input" }, status: :unprocessable_content
|
||||
end
|
||||
end
|
||||
|
||||
def index
|
||||
@players = Player.all.reject(&:alt?).map { |player| [
|
||||
player.name,
|
||||
player.get_loot_count_with_roll("mainspec"),
|
||||
player.get_loot_count_with_roll("minor"),
|
||||
player.get_loot_count_with_roll("offspec"),
|
||||
player.get_loot_count_with_roll("transmog"),
|
||||
]}.sort
|
||||
end
|
||||
|
||||
def list
|
||||
@loot = Loot.all.sort_by &:timestamp
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def already_reported_response
|
||||
render json: { error: "Already reported this loot" }, status: :already_reported
|
||||
end
|
||||
end
|
2
app/helpers/loot_helper.rb
Normal file
2
app/helpers/loot_helper.rb
Normal file
@ -0,0 +1,2 @@
|
||||
module LootHelper
|
||||
end
|
34
app/models/loot.rb
Normal file
34
app/models/loot.rb
Normal file
@ -0,0 +1,34 @@
|
||||
class Loot < ApplicationRecord
|
||||
belongs_to :player
|
||||
|
||||
def player_name_with_alt
|
||||
if self.player.alt?
|
||||
"#{self.player.name} (alt of #{self.player.main_player.name})"
|
||||
else
|
||||
self.player.name
|
||||
end
|
||||
end
|
||||
|
||||
def wowhead
|
||||
"https://wowhead.com/item=#{self.item_id}"
|
||||
end
|
||||
|
||||
def roll_type_pretty
|
||||
case self.roll_type
|
||||
when "mainspec"
|
||||
"Main Spec"
|
||||
when "offspec"
|
||||
"Offspec"
|
||||
when "minor"
|
||||
"Minor Upgrade"
|
||||
when "transmog"
|
||||
"Transmog"
|
||||
else
|
||||
"Unknown"
|
||||
end
|
||||
end
|
||||
|
||||
def date
|
||||
self.timestamp&.strftime("%m/%d/%Y")
|
||||
end
|
||||
end
|
@ -5,6 +5,9 @@ class Player < ApplicationRecord
|
||||
# A Player can have multiple alts
|
||||
has_many :alternate_players, class_name: "Player", foreign_key: "main_player_id"
|
||||
|
||||
# A Player can have many loots
|
||||
has_many :loots
|
||||
|
||||
validate :no_circular_references
|
||||
|
||||
def total_wins
|
||||
@ -35,6 +38,10 @@ class Player < ApplicationRecord
|
||||
self.main_player
|
||||
end
|
||||
|
||||
def has_alts?
|
||||
self.alternate_players.count > 0
|
||||
end
|
||||
|
||||
def main_name
|
||||
if alt?
|
||||
self.main_player.name
|
||||
@ -46,4 +53,25 @@ class Player < ApplicationRecord
|
||||
errors.add(:main_account, "circular reference")
|
||||
end
|
||||
end
|
||||
|
||||
def get_loot
|
||||
loot = Loot.where(player_id: self.id)
|
||||
self.alternate_players.each do |alt|
|
||||
loot << Loot.where(player_id: alt.id)
|
||||
end
|
||||
loot
|
||||
end
|
||||
|
||||
def get_loot_with_roll(roll)
|
||||
ids = [self.id] + self.alternate_players.pluck(:id)
|
||||
Loot.where(player_id: ids, roll_type: roll)
|
||||
end
|
||||
|
||||
def get_loot_count
|
||||
get_loot.size
|
||||
end
|
||||
|
||||
def get_loot_count_with_roll(roll)
|
||||
get_loot_with_roll(roll).size
|
||||
end
|
||||
end
|
||||
|
@ -40,6 +40,18 @@
|
||||
|
||||
<%= submit_tag "Set Alt", id: "set-alt-button" %>
|
||||
<% end %>
|
||||
|
||||
<% form_with(url: "/admin/set_lootban", method: :post, local: true) do %>
|
||||
<h2>Set Lootban</h2>
|
||||
<label for="lootban-input">Set Lootban: </label>
|
||||
<input id="lootban-input" type="text">
|
||||
<%= submit_tag "Set Lootban", id: "set-lootban-button" %>
|
||||
<% end %>
|
||||
|
||||
<% form_with(url: "/admin/delete_lootban", method: :post, local: true) do %>
|
||||
<%= submit_tag "Clear Lootban", id: "clear-lootban-button" %>
|
||||
<% end %>
|
||||
|
||||
<a href="/">Leaderboard</a>
|
||||
<a href="/admin/destroy">Logout</a>
|
||||
</div>
|
||||
|
||||
|
27
app/views/loot/index.html.erb
Normal file
27
app/views/loot/index.html.erb
Normal file
@ -0,0 +1,27 @@
|
||||
<h1>Seasonal Loot Distribution</h1>
|
||||
|
||||
<% if @players.any? %>
|
||||
<div class="wrapper">
|
||||
<div class="table">
|
||||
<div class="row header">
|
||||
<div class="cell">Player</div>
|
||||
<div class="cell">Main Spec</div>
|
||||
<div class="cell">Minor Upgrade</div>
|
||||
<div class="cell">Offspec</div>
|
||||
<div class="cell">Transmog</div>
|
||||
</div>
|
||||
<% @players.each do |player| %>
|
||||
<div class="row">
|
||||
<div class="cell" data-title="Player"><%= player[0] %></div>
|
||||
<div class="cell" data-title="Main Spec"><%= player[1]%></div>
|
||||
<div class="cell" data-title="Minor Upgrade"><%= player[2]%></div>
|
||||
<div class="cell" data-title="Offspec"><%= player[3] %></div>
|
||||
<div class="cell" data-title="Transmog"><%= player[4] %></div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
<a href="/loot/list">Loot List</a>
|
||||
</div>
|
||||
<% else %>
|
||||
<h1>No loot records exist</h1>
|
||||
<% end %>
|
25
app/views/loot/list.html.erb
Normal file
25
app/views/loot/list.html.erb
Normal file
@ -0,0 +1,25 @@
|
||||
<h1>Seasonal Loot List</h1>
|
||||
|
||||
<% if @loot.any? %>
|
||||
<div class="wrapper">
|
||||
<div class="table">
|
||||
<div class="row header">
|
||||
<div class="cell">Date</div>
|
||||
<div class="cell">Player</div>
|
||||
<div class="cell">Item</div>
|
||||
<div class="cell">Roll Type</div>
|
||||
</div>
|
||||
<% @loot.each do |l| %>
|
||||
<div class="row">
|
||||
<div class="cell" data-title="Date"><%= l.date %></div>
|
||||
<div class="cell" data-title="Player"><%= l.player_name_with_alt %></div>
|
||||
<div class="cell" data-title="Item"><%= link_to l.item_name, l.wowhead, target: "_blank", rel: "nofollow" %></div>
|
||||
<div class="cell" data-title="Roll Type"><%= l.roll_type_pretty %></div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
<a href="/loot">Loot Distribution</a>
|
||||
</div>
|
||||
<% else %>
|
||||
<h1>No loot records exist</h1>
|
||||
<% end %>
|
Reference in New Issue
Block a user