Added Who's Playing? screen

This commit is contained in:
MrYummy
2017-05-28 17:46:54 -04:00
parent dfb1ed9185
commit 252dc5bdfa
6 changed files with 32 additions and 3 deletions

View File

@@ -1,5 +1,7 @@
class StaticsController < ApplicationController class StaticsController < ApplicationController
caches_action :online, expires_in: 10.seconds
def index def index
if current_user if current_user
redirect_to blogposts_path redirect_to blogposts_path
@@ -14,4 +16,8 @@ class StaticsController < ApplicationController
def donate def donate
end end
def online
@players = JSON.parse(File.read("/etc/minecraft/redstoner/plugins/JavaUtils/players.json"))["players"]
@players.collect!{ |p| User.find_by(uuid: p["uuid"].tr("-", "")) or User.new(name: p["name"], ign: p["name"], uuid: p["uuid"].tr("-", ""), role: Role.get("normal"), confirmed: true) }.sort_by!(&:role).reverse!
end
end end

View File

@@ -31,6 +31,9 @@
<li> <li>
<%= link_to "Donate", donate_statics_path, class: ("active" if con == "statics" && params[:action] == "donate") %> <%= link_to "Donate", donate_statics_path, class: ("active" if con == "statics" && params[:action] == "donate") %>
</li> </li>
<li>
<%= link_to "Who's Playing?", online_statics_path, class: ("active" if con == "statics" && params[:action] == "online") %>
</li>
</ul> </ul>
</div> </div>
<div id="userbar"> <div id="userbar">

View File

@@ -0,0 +1,17 @@
<% title "Who's Playing?" %>
<h1>These players are currently playing on Redstoner:</h1>
<div id="userlist">
<% @players.each do |u| %>
<div class="list-user">
<%= link_to(u.avatar(64), u) %>
<div class="detail">
<%= render partial: "users/username", locals: { user: u } %><br>
<i><%= u.ign %></i>
<% unless u.id %>
<br><i>(Not signed up)</i>
<% end %>
</div>
</div>
<% end %>
</div>

View File

@@ -24,4 +24,4 @@ test:
adapter: sqlite3 adapter: sqlite3
database: db/test.sqlite3 database: db/test.sqlite3
pool: 5 pool: 5
timeout: 5000 timeout: 5000

View File

@@ -6,6 +6,8 @@ Redstoner::Application.configure do
# since you don't have to restart the web server when you make code changes. # since you don't have to restart the web server when you make code changes.
config.cache_classes = false config.cache_classes = false
config.action_controller.perform_caching = true
# Log error messages when you accidentally call methods on nil. # Log error messages when you accidentally call methods on nil.
config.whiny_nils = true config.whiny_nils = true
@@ -43,4 +45,4 @@ Redstoner::Application.configure do
password: ENV["GMAIL_PASSWORD"], password: ENV["GMAIL_PASSWORD"],
} }
end end

View File

@@ -4,10 +4,11 @@ Redstoner::Application.routes.draw do
resources :comments resources :comments
end end
resources :statics, only: [:home, :donate], path: '/' do resources :statics, only: [:home, :donate, :online], path: '/' do
collection do collection do
get 'donate' get 'donate'
get 'home' get 'home'
get 'online'
get 'index' get 'index'
end end
end end