diff --git a/app/assets/stylesheets/themes/default/components/_gather.scss b/app/assets/stylesheets/themes/default/components/_gather.scss index 5238713..ae2bdba 100644 --- a/app/assets/stylesheets/themes/default/components/_gather.scss +++ b/app/assets/stylesheets/themes/default/components/_gather.scss @@ -202,3 +202,11 @@ table.gathers { ul.gatherers { @include span-columns(12); } + +ul#gatherers { + li.away a { + font-style: italic; + font-weight: normal; + color: #5b5b5b; + } +} diff --git a/app/controllers/gatherers_controller.rb b/app/controllers/gatherers_controller.rb index 6a45076..488b403 100644 --- a/app/controllers/gatherers_controller.rb +++ b/app/controllers/gatherers_controller.rb @@ -32,6 +32,22 @@ class GatherersController < ApplicationController redirect_to_back end + def status + raise AccessError unless @gatherer.can_destroy? cuser + + states = { + "leaving" => Gatherer::STATE_LEAVING, + "away" => Gatherer::STATE_AWAY, + "active" => Gatherer::STATE_ACTIVE, + } + + if states.has_key?(params[:status]) + @gatherer.update_attribute(:status, states[params[:status]]) + end + + render :nothing => true, :status => 200 + end + def destroy raise AccessError unless @gatherer.can_destroy? cuser diff --git a/app/controllers/gathers_controller.rb b/app/controllers/gathers_controller.rb index 79acc85..d8f4a87 100644 --- a/app/controllers/gathers_controller.rb +++ b/app/controllers/gathers_controller.rb @@ -72,5 +72,24 @@ class GathersController < ApplicationController end @gatherer = @gather.gatherers.of_user(cuser).first if cuser + update_gatherers + end + + def update_gatherers + # Update user that has left and came back + if @gatherer and @gatherer.status == Gatherer::STATE_LEAVING + @gatherer.update_attribute(:status, Gatherer::STATE_ACTIVE) + end + + # Remove any users that left over 30 seconds ago + removed_users = false + @gather.gatherers.each do |gatherer| + if gatherer.status == Gatherer::STATE_LEAVING and gatherer.updated_at < Time.now - 30 + removed_users = true + gatherer.destroy + end + end + + @gather.reload if removed_users end end diff --git a/app/models/gatherer.rb b/app/models/gatherer.rb index 06bf570..0b49f1b 100644 --- a/app/models/gatherer.rb +++ b/app/models/gatherer.rb @@ -15,6 +15,10 @@ class Gatherer < ActiveRecord::Base IDLE_TIME = 600 EJECT_VOTES = 4 + STATE_ACTIVE = 0 + STATE_AWAY = 1 + STATE_LEAVING = 2 + include Extra attr_protected :id diff --git a/app/views/gathers/_running.html.erb b/app/views/gathers/_running.html.erb index dba8a21..de2d68f 100644 --- a/app/views/gathers/_running.html.erb +++ b/app/views/gathers/_running.html.erb @@ -6,7 +6,7 @@