From e7463524af03a62b8ba4adbdee29efe5f547c2d4 Mon Sep 17 00:00:00 2001 From: MrYummy Date: Sun, 28 May 2017 17:46:54 -0400 Subject: Added Who's Playing? screen --- app/controllers/statics_controller.rb | 6 ++++++ app/views/layouts/_head.html.erb | 3 +++ app/views/statics/online.html.erb | 17 +++++++++++++++++ config/database.yml | 2 +- config/environments/development.rb | 4 +++- config/routes.rb | 3 ++- 6 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 app/views/statics/online.html.erb diff --git a/app/controllers/statics_controller.rb b/app/controllers/statics_controller.rb index f2891f3..70d3bd8 100644 --- a/app/controllers/statics_controller.rb +++ b/app/controllers/statics_controller.rb @@ -1,5 +1,7 @@ class StaticsController < ApplicationController + caches_action :online, expires_in: 10.seconds + def index if current_user redirect_to blogposts_path @@ -14,4 +16,8 @@ class StaticsController < ApplicationController def donate 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 diff --git a/app/views/layouts/_head.html.erb b/app/views/layouts/_head.html.erb index e6b5080..c64fe30 100644 --- a/app/views/layouts/_head.html.erb +++ b/app/views/layouts/_head.html.erb @@ -31,6 +31,9 @@
  • <%= link_to "Donate", donate_statics_path, class: ("active" if con == "statics" && params[:action] == "donate") %>
  • +
  • + <%= link_to "Who's Playing?", online_statics_path, class: ("active" if con == "statics" && params[:action] == "online") %> +
  • diff --git a/app/views/statics/online.html.erb b/app/views/statics/online.html.erb new file mode 100644 index 0000000..8c31182 --- /dev/null +++ b/app/views/statics/online.html.erb @@ -0,0 +1,17 @@ +<% title "Who's Playing?" %> +

    These players are currently playing on Redstoner:

    +
    + <% @players.each do |u| %> +
    + <%= link_to(u.avatar(64), u) %> +
    + <%= render partial: "users/username", locals: { user: u } %>
    + <%= u.ign %> + <% unless u.id %> +
    (Not signed up) + <% end %> +
    +
    + <% end %> +
    + diff --git a/config/database.yml b/config/database.yml index f421bef..db672c6 100644 --- a/config/database.yml +++ b/config/database.yml @@ -24,4 +24,4 @@ test: adapter: sqlite3 database: db/test.sqlite3 pool: 5 - timeout: 5000 \ No newline at end of file + timeout: 5000 diff --git a/config/environments/development.rb b/config/environments/development.rb index 06819fd..bfa0c96 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -6,6 +6,8 @@ Redstoner::Application.configure do # since you don't have to restart the web server when you make code changes. config.cache_classes = false + config.action_controller.perform_caching = true + # Log error messages when you accidentally call methods on nil. config.whiny_nils = true @@ -43,4 +45,4 @@ Redstoner::Application.configure do password: ENV["GMAIL_PASSWORD"], } -end \ No newline at end of file +end diff --git a/config/routes.rb b/config/routes.rb index 584c94f..f79ab5b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -4,10 +4,11 @@ Redstoner::Application.routes.draw do resources :comments end - resources :statics, only: [:home, :donate], path: '/' do + resources :statics, only: [:home, :donate, :online], path: '/' do collection do get 'donate' get 'home' + get 'online' get 'index' end end -- cgit v1.2.3