-
Notifications
You must be signed in to change notification settings - Fork 408
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial implementation of admin console and site settings
- Loading branch information
Showing
23 changed files
with
399 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
$(document).ready -> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
$(document).ready -> | ||
$(".user_menu_link").click (e)-> | ||
e.preventDefault() | ||
$(".user_menu").toggle() | ||
false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module Admin | ||
class AdminController < BaseController | ||
|
||
def index | ||
@settings = Setting.my_settings | ||
@all_users = User.find(:all, :conditions => ["id != ?", current_user.id]) | ||
|
||
# Note that this reject! will remove users from all_users in order to show users in 2 different tables | ||
@waiting_for_approval_users = @all_users.reject!{|user| user.status.waiting_approval? } || [] | ||
end | ||
|
||
def update | ||
|
||
max_rooms = params[:setting][:max_rooms].to_i | ||
public_site = params[:setting][:public_site] == "1" | ||
|
||
Setting.set_values(:max_rooms => max_rooms, :public_site => public_site) | ||
|
||
redirect_to :admin_root | ||
end | ||
|
||
def update_users | ||
|
||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module Admin | ||
class BaseController < ApplicationController | ||
before_filter :authenticate_admin! | ||
|
||
private | ||
|
||
def authenticate_admin! | ||
redirect_to root_url unless current_user.try(:is_admin?) | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module Admin::AdminHelper | ||
def user_status user | ||
"<div class='#{user.status}'>#{user.status}</div>".html_safe | ||
end | ||
|
||
def user_action user | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
class Setting < ActiveRecord::Base | ||
attr_accessible :values | ||
serialize :values, Hash | ||
|
||
before_create :set_default_values | ||
before_create :ensure_only_one_settings | ||
before_destroy :ensure_only_one_settings | ||
|
||
before_save :validate_max_rooms, :validate_public_site | ||
|
||
def max_rooms | ||
self.values[:max_rooms] | ||
end | ||
|
||
def public_site? | ||
self.values[:public_site] | ||
end | ||
|
||
alias_method :public_site, :public_site? | ||
|
||
def set_default_values | ||
self.values.merge!(self.class.default_values) | ||
end | ||
|
||
def ensure_only_one_settings | ||
return false if Setting.count >= 1 | ||
end | ||
|
||
# Making sure the max_rooms is an integer and is never less than the current number of rooms | ||
def validate_max_rooms | ||
self.values[:max_rooms].is_a?(Integer) && self.values[:max_rooms] >= Channel.count unless self.new_record? | ||
end | ||
|
||
# Making sure the public site is a boolean | ||
def validate_public_site | ||
!!self.values[:public_site] == self.values[:public_site] unless self.new_record? | ||
end | ||
|
||
def self.default_values | ||
return {:max_rooms => 99, :public_site => false } | ||
end | ||
|
||
# Helper methods to be used while we don't need to deal with multi-tenancy | ||
def self.my_settings | ||
self.first_or_create | ||
end | ||
|
||
def self.get_value(k) | ||
setting = self.my_settings | ||
setting.values[k] | ||
end | ||
|
||
def self.set_values(values) | ||
setting = self.my_settings | ||
|
||
values.each do |k,v| | ||
setting.values[k.to_sym] = v | ||
end | ||
|
||
setting.save! | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<% content_for :javascript_includes do %> | ||
<%= javascript_include_tag "admin/admin" %> | ||
<% end %> | ||
|
||
<div class="admin-main-area"> | ||
<%= form_for @settings, :url => admin_update_path do |f| %> | ||
<%= f.label :max_rooms, 'Max number of rooms' %>: | ||
<%= f.text_field :max_rooms %><br /> | ||
<%= f.label :public_site, 'Is this a public site?' %>: | ||
<%= f.check_box :public_site %><br /> | ||
<%= f.submit %> | ||
<% end %> | ||
|
||
<div class="waiting-for-approval-users"> | ||
<% if @waiting_for_approval_users.any? %> | ||
<table cellspacing="0" cellpadding="0" border="0"> | ||
<thead> | ||
<tr> | ||
<th class="">Username</th> | ||
<th class="">First Name</th> | ||
<th class="">Last Name</th> | ||
<th class="">Email</th> | ||
<th class="">Status</th> | ||
<th class="">Action</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<% @all_users.each do |user| %> | ||
<tr class="<%= cycle('odd', 'even')%>" data-user-id="<%= user.id%>"> | ||
<td> | ||
<%= user.username %> | ||
</td> | ||
<td> | ||
<%= user.first_name %> | ||
</td> | ||
<td> | ||
<%= user.last_name %> | ||
</td> | ||
<td> | ||
<%= user.email %> | ||
</td> | ||
<td> | ||
<%= user_status(user) %> | ||
</td> | ||
<td> | ||
|
||
</td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
<% else %> | ||
<div>There are no users. Invite others to join Kandan!</div> | ||
<% end %> | ||
</div> | ||
|
||
<div class="approved-users"> | ||
<% if @all_users.any? %> | ||
<table cellspacing="0" cellpadding="0" border="0"> | ||
<thead> | ||
<tr> | ||
<th class="">Username</th> | ||
<th class="">First Name</th> | ||
<th class="">Last Name</th> | ||
<th class="">Email</th> | ||
<th class="">Status</th> | ||
<th class="">Action</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<% @all_users.each do |user| %> | ||
<tr class="<%= cycle('odd', 'even')%>" data-user-id="<%= user.id%>"> | ||
<td> | ||
<%= user.username %> | ||
</td> | ||
<td> | ||
<%= user.first_name %> | ||
</td> | ||
<td> | ||
<%= user.last_name %> | ||
</td> | ||
<td> | ||
<%= user.email %> | ||
</td> | ||
<td> | ||
<%= user_status(user) %> | ||
</td> | ||
<td> | ||
|
||
</td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
<% else %> | ||
<div>There are no users. Invite others to join Kandan!</div> | ||
<% end %> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.