Skip to content

Commit

Permalink
Improve navbar a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
melkor217 committed Jun 1, 2016
1 parent f8db469 commit 7da0b16
Show file tree
Hide file tree
Showing 21 changed files with 208 additions and 22 deletions.
Binary file added app/assets/images/misc/steamgroup.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions app/controllers/players_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def index
@scope = Player.where(hideranking: 0)
end
end

# GET /players/1
# GET /players/1.json
def show
Expand All @@ -46,7 +47,7 @@ def killstats
if request.format.json?
ks = @player.killstats
puts ks
ks = ks.sort_by do |k,v|
ks = ks.sort_by do |k, v|
val = v[params[:sort].to_sym].to_i
if params[:order].to_sym == :asc
val
Expand All @@ -64,7 +65,7 @@ def killstats

def weapons
@weapons = @player.weapons
@sum = @weapons.map do |k,v|
@sum = @weapons.map do |k, v|
v
end.sum
end
Expand Down
28 changes: 28 additions & 0 deletions app/jobs/get_group_steam_info_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class GetGroupSteamInfoJob < ApplicationJob
def perform(options = {})
puts options.to_s
puts self.queue_name
# Do something later
options[:format] = :xml
if (uri = SteamId.steam_group_url(options))
begin
record = SteamGroup.find_or_initialize_by(options) do |group|
doc = Nokogiri::XML(Net::HTTP.get(uri))
logger.debug("Getting info for player #{uri.to_s}")
group.groupID = doc.xpath('//memberList/groupDetails/groupID64').text.to_i
group.groupName = doc.xpath('//memberList/groupDetails/groupName').text
group.summary = doc.xpath('//memberList/groupDetails/summary').text
group.avatarIcon = doc.xpath('//memberList/groupDetails/avatarIcon').text
group.avatarMedium = doc.xpath('//memberList/groupDetails/avatarMedium').text
group.avatarFull = doc.xpath('//memberList/groupDetails/avatarFull').text
group.memberCount = doc.xpath('//memberList/memberCount').text
end
record.save
rescue
logger.warn("Failed to get group profile for #{options.to_s}")
end

end
sleep 5 if self.queue_name != :urgent
end
end
4 changes: 3 additions & 1 deletion app/jobs/get_player_steam_info_job.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
class GetPlayerSteamInfoJob < ApplicationJob
def perform(options = {})
logger.warn options.to_s
uniqueid = UniqueId.find_by!(options)
# Do something later
if uniqueid and (uri = SteamId.steam_profile_url(uniqueid.uniqueId, format: :xml))
begin
doc = Nokogiri::XML(Net::HTTP.get(uri))
logger.debug("Getting info for group #{uri.to_s}")
uniqueid.avatarFull = doc.xpath('//profile/avatarFull').text
uniqueid.avatarMedium = doc.xpath('//profile/avatarMedium').text
uniqueid.avatarIcon = doc.xpath('//profile/avatarIcon').text
Expand All @@ -21,6 +23,6 @@ def perform(options = {})
end
uniqueid.steamUpdated = Time.now
uniqueid.save
sleep 5
sleep 5 if self.queue_name != :urgent
end
end
3 changes: 3 additions & 0 deletions app/models/option.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Option < ApplicationRecord
self.table_name = 'hlstats_Options' # MySQL table name
end
3 changes: 3 additions & 0 deletions app/models/option_choise.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class OptionChoise < ApplicationRecord
self.table_name = 'hlstats_Option_Choises' # MySQL table name
end
12 changes: 12 additions & 0 deletions app/models/steam_group.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class SteamGroup < ApplicationRecord
def self.try_find_by(options = {})
group = SteamGroup.find_by(options)
return group if group
GetGroupSteamInfoJob.perform_later(options)
return nil
end

def self.sitegroup
self.try_find_by(groupURL: Option.find_by!(keyname: 'steamgroup').value)
end
end
18 changes: 18 additions & 0 deletions app/views/layouts/_brand.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<% if (group = SteamGroup.sitegroup) %>
<ul class="nav navbar-nav">
<li>
<a class="navbar-brand" style="padding-right: 5px;" href="/"><%= group.groupName %></a>
</li>
<li style="border-right: 1px solid #999">
<a style="margin: 0px; padding: 0px" href="<%= SteamId.steam_group_url(group) %>">
<img style="padding-right: 12px; padding-bottom: 5px; padding-top: 5px; padding-left: 0px; margin-left: 5px" class="navbar-brand" src="<%= group.avatarMedium %>"/>
</a>
</li>
</ul>
<% else %>
<ul class="nav navbar-nav">
<li>
<a class="navbar-brand" href="<%= players_path %>">Ayanami</a>
</li>
</ul>
<% end %>
40 changes: 22 additions & 18 deletions app/views/layouts/_navbar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,34 @@
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="<%= players_path %>">Ayanami</a>
<!--<a class="navbar-brand" href="<%= players_path %>">Ayanami</a>-->
<%= render 'layouts/brand' %>
</div>

<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="<%=cp(players_path)%>"><a href="<%= players_path %>">Players<span class="sr-only">(current)</span></a></li>
<li class="<%=cp(servers_path)%>"><a href="<%= servers_path %>">Servers<span class="sr-only">(current)</span></a></li>
<li class="<%=cp(countries_path)%>"><a href="<%= countries_path %>">Countries</a></li>
<li class="<%=cp(weapons_path)%>"><a href="<%= weapons_path %>">Weapons</a></li>
<li class="<%=cp(frags_path)%>"><a href="<%= frags_path %>">Frags</a></li>
<!-- <li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li role="separator" class="divider"></li>
<li><a href="#">Separated link</a></li>
<li role="separator" class="divider"></li>
<li><a href="#">One more separated link</a></li>
</ul>
</li>-->
<li class="<%= cp(players_path) %>">
<a href="<%= players_path %>">Players<span class="sr-only">(current)</span></a></li>
<li class="<%= cp(servers_path) %>">
<a href="<%= servers_path %>">Servers<span class="sr-only">(current)</span></a></li>
<li class="<%= cp(countries_path) %>"><a href="<%= countries_path %>">Countries</a></li>
<li class="<%= cp(weapons_path) %>"><a href="<%= weapons_path %>">Weapons</a></li>
<li class="<%= cp(frags_path) %>"><a href="<%= frags_path %>">Frags</a></li>
<!-- <li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li role="separator" class="divider"></li>
<li><a href="#">Separated link</a></li>
<li role="separator" class="divider"></li>
<li><a href="#">One more separated link</a></li>
</ul>
</li>-->
</ul>
<%= render 'layouts/steamgroup' %>
<%#
<form class="navbar-form navbar-left" role="search">
<div class="form-group">
Expand Down
9 changes: 9 additions & 0 deletions app/views/layouts/_steamgroup.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<% if (group = SteamGroup.sitegroup) %>
<ul class="nav navbar-nav navbar-right">
<li style="border-left: 1px solid #999">
<a style="margin: 0px; padding: 0px" href="<%= SteamId.steam_group_url(group) %>">
<img style="padding: 8px; margin-top: 0px; margin-bot: 0px; margin-left: 5px" class="navbar-brand" src="<%= asset_path('misc/steamgroup.png') %>"/>
</a>
</li>
</ul>
<% end %>
5 changes: 5 additions & 0 deletions db/migrate/20160601180030_add_option_steam_group.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddOptionSteamGroup < ActiveRecord::Migration[5.0]
def change
Option.create(keyname: 'steamgroup', value: 'reijii-dm', opttype: 2)
end
end
15 changes: 15 additions & 0 deletions db/migrate/20160601181555_create_steam_groups.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class CreateSteamGroups < ActiveRecord::Migration[5.0]
def change
create_table :steam_groups do |t|
t.integer :groupID, index: true, limit: 8, null: false, unique: true
t.string :groupName, index: true
t.string :groupURL, index: true
t.string :summary, limit: 2048
t.string :avatarIcon
t.string :avatarMedium
t.string :avatarFull
t.string :memberCount, index: true
t.timestamps
end
end
end
19 changes: 18 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20160529192550) do
ActiveRecord::Schema.define(version: 20160601181555) do

create_table "geoLiteCity_Blocks", id: false, force: :cascade, options: "ENGINE=MyISAM DEFAULT CHARSET=utf8" do |t|
t.bigint "startIpNum", default: 0, null: false, unsigned: true
Expand Down Expand Up @@ -682,4 +682,21 @@
t.index ["timestamp"], name: "timestamp", using: :btree
end

create_table "steam_groups", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
t.bigint "groupID", null: false
t.string "groupName"
t.string "groupURL"
t.string "summary", limit: 2048
t.string "avatarIcon"
t.string "avatarMedium"
t.string "avatarFull"
t.string "memberCount"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["groupID"], name: "index_steam_groups_on_groupID", using: :btree
t.index ["groupName"], name: "index_steam_groups_on_groupName", using: :btree
t.index ["groupURL"], name: "index_steam_groups_on_groupURL", using: :btree
t.index ["memberCount"], name: "index_steam_groups_on_memberCount", using: :btree
end

end
8 changes: 8 additions & 0 deletions lib/steam_id.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,12 @@ def self.steam_profile_url(steamid, options = {})
end
return URI(uri)
end
def self.steam_group_url(options)
return nil if not /^[0-9A-z\-]+$/.match(options[:groupURL])
if options[:format] == :xml
URI("http://steamcommunity.com/groups/#{options[:groupURL]}/memberslistxml/?xml=1")
else
URI("http://steamcommunity.com/groups/#{options[:groupURL]}/")
end
end
end
11 changes: 11 additions & 0 deletions test/fixtures/option_choises.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value
11 changes: 11 additions & 0 deletions test/fixtures/options.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value
11 changes: 11 additions & 0 deletions test/fixtures/steam_groups.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value
7 changes: 7 additions & 0 deletions test/jobs/get_group_steam_info_job_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class GetGroupSteamInfoJobTest < ActiveJob::TestCase
# test "the truth" do
# assert true
# end
end
7 changes: 7 additions & 0 deletions test/models/option_choise_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class OptionChoiseTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
7 changes: 7 additions & 0 deletions test/models/option_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class OptionTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
7 changes: 7 additions & 0 deletions test/models/steam_group_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class SteamGroupTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

0 comments on commit 7da0b16

Please sign in to comment.