Adding wysiwyg and settings

This commit is contained in:
2013-09-28 04:59:19 -07:00
parent f03ffcd356
commit 2c204a8f9d
171 changed files with 26473 additions and 72 deletions

View File

@@ -25,4 +25,10 @@ def index
end
end
def more_info
respond_to do |format|
format.html # more_info.html.erb
end
end
end

View File

@@ -20,55 +20,57 @@ require "optparse"
def index
recent_mac_logs_ungrouped = MacLog.last(1000)
@mac_time_start_date = recent_mac_logs_ungrouped.first.created_at
recent_mac_logs = recent_mac_logs_ungrouped.group_by(&:mac)
@mac_times = {}
# Go thru each mac
recent_mac_logs.each do |mac_log|
last_active = nil
# And the entries for each mac (mac_log.first is the string, mac_log.last is the array)
mac_log.last.each do |entry|
# Find an activate followed immediately by a deactivate
if entry.action == "activate"
last_active = entry
else
if last_active && entry.action == "deactivate"
# Calculate the time difference between the two and append to this mac's total time
this_entry = @mac_times[entry.mac]
if this_entry
this_time = this_entry[:time]
else
this_time = 0
end
@mac_times[entry.mac] = {:mac => entry, :time => (entry.created_at - last_active.created_at) + this_time}
if recent_mac_logs_ungrouped.present?
@mac_time_start_date = recent_mac_logs_ungrouped.first.created_at
recent_mac_logs = recent_mac_logs_ungrouped.group_by(&:mac)
@mac_times = {}
# Go thru each mac
recent_mac_logs.each do |mac_log|
last_active = nil
# And the entries for each mac (mac_log.first is the string, mac_log.last is the array)
mac_log.last.each do |entry|
# Find an activate followed immediately by a deactivate
if entry.action == "activate"
last_active = entry
else
# No pair found; discard.
last_active = nil
if last_active && entry.action == "deactivate"
# Calculate the time difference between the two and append to this mac's total time
this_entry = @mac_times[entry.mac]
if this_entry
this_time = this_entry[:time]
else
this_time = 0
end
@mac_times[entry.mac] = {:mac => entry, :time => (entry.created_at - last_active.created_at) + this_time}
else
# No pair found; discard.
last_active = nil
end
end
end
end
end
@mac_times_sorted = @mac_times.sort{|a,b| b.last[:time] <=> a.last[:time] }
@most_active_mac = nil
@runner_up_mac = nil
@mac_times_sorted.each do |mac_time|
unless @most_active_mac
this_mac = Mac.find_by_mac(mac_time.first)
unless this_mac.hidden
@most_active_mac = this_mac
@most_active = mac_time
end
else
unless @runner_up_mac
@mac_times_sorted = @mac_times.sort{|a,b| b.last[:time] <=> a.last[:time] }
@most_active_mac = nil
@runner_up_mac = nil
@mac_times_sorted.each do |mac_time|
unless @most_active_mac
this_mac = Mac.find_by_mac(mac_time.first)
unless this_mac.hidden
@runner_up_mac = this_mac
@runner_up = mac_time
@most_active_mac = this_mac
@most_active = mac_time
end
else
unless @runner_up_mac
this_mac = Mac.find_by_mac(mac_time.first)
unless this_mac.hidden
@runner_up_mac = this_mac
@runner_up = mac_time
end
end
end
end
end
#@active_macs = Mac.where(:active => true, :hidden => false)
#@active_macs += Mac.where(:active => true, :hidden => nil)

View File

@@ -0,0 +1,32 @@
class SettingsController < ApplicationController
authorize_resource
def index
@settings = Setting.all
@@default_settings.each do |key, value|
if @settings[key].blank?
@settings[key] = value
end
end
end
def edit
value = Setting[params[:id].to_sym]
if value.present?
@setting = {}
@setting[:var] = params[:id]
@setting[:value] = value
elsif @@default_settings[params[:id].to_sym].present?
@setting = {}
@setting[:var] = params[:id]
@setting[:value] = @@default_settings[params[:id].to_sym]
end
end
def update
Setting[params[:id]] = params[:value]
redirect_to settings_path
end
end

3
app/models/setting.rb Normal file
View File

@@ -0,0 +1,3 @@
class Setting < RailsSettings::CachedSettings
attr_accessible :var
end

View File

@@ -1,6 +1,6 @@
<h1>Welcome to the HeatSync Labs Members App.</h1>
<h1><%= Setting.welcome_title %></h1>
<% if !user_signed_in? then %>
<p>You can sign up to become a member here!</p>
<%= simple_format Setting.welcome_body %>
<% end %>
@@ -45,27 +45,7 @@
<td>
<h2>Member Resources</h2>
<ul>
<li><%= link_to "Wiki", "http://wiki.heatsynclabs.org" %></li>
<li><%= link_to "Discussion Group", "http://groups.google.com/group/heatsynclabs" %></li>
<li><%= link_to "IRC", "irc://irc.freenode.net#heatsynclabs" %></li>
<li><%= link_to "Live Webcams", "http://live.heatsynclabs.org/" %></li>
<li>Lab Phone: (480) 751-1929</li>
<li>
<style type="text/css">
form input {font-family: 'Lucida Console', Monaco, monospace; }
</style>
<b>Send a Message!</b>
<form method="post" action="http://tweet.zyphon.com/signage.php">
<em>Type here and your message will show up on the LED sign in the front window!</em><br/>
<em>(Please be nice!)</em><br/>
<input type="text" name="msg" id="msg" value=" Hello" size="9" /> (max 9 chars per line)<br/>
<input type="text" name="msg2" id="msg2" value=" World" size="9" /><br/>
<input type="submit" name="submitbutton" id="submitbutton" value="Go!" />
</form>
</li>
</ul>
<%= simple_format Setting.member_resources_inset %>
</td>
</tr>

View File

@@ -0,0 +1,2 @@
<h1>More Information</h1>
<%= simple_format Setting.more_info_page %>

View File

@@ -18,7 +18,7 @@
<%= link_to 'Certifications', certifications_path if can? :read, Certification %>
<% end %>
<%= link_to 'Payments', payments_path if can? :read, Payment %>
<%= link_to 'Computers', macs_path if user_signed_in? && (can? :read, Mac) %>
<%= link_to 'Computers', macs_path if user_signed_in? || (can? :read, Mac) %>
<% if user_signed_in? then %><%= link_to 'Profile', edit_user_registration_path %><% end %>
<%= link_to 'Logout', destroy_user_session_path, :method => :delete if user_signed_in? %>
<%= link_to 'Login', new_user_session_path unless user_signed_in? %>

View File

@@ -1,3 +1,4 @@
<% if @mac_time_start_date.present? %>
<b>Most Active Machine Last <%= distance_of_time_in_words DateTime.now, @mac_time_start_date %>:</b>
<span title="<%= @most_active_mac.mac %><%= " - "+@most_active_mac.ip.to_s if can? :read_details, @most_active_mac %>">
<%= @most_active_mac.user.name unless @most_active_mac.user.blank? %>
@@ -11,6 +12,7 @@
<%= "("+@runner_up_mac.note+")" unless @runner_up_mac.note.blank? %>
- <%= (@runner_up.last[:time] / 1.hour).round %> hrs
</span>
<% end %>
<h2>What machines are on our network?</h2>
<%= link_to "New MAC registration", new_mac_path if can? :create, Mac %>

View File

@@ -0,0 +1,18 @@
<script type="text/javascript" src="/wymeditor/wymeditor/jquery.wymeditor.min.js"></script>
<script type="text/javascript">
$(function(){
$('.wysiwyg').wymeditor();
});
</script>
<%= form_tag(setting_path(@setting[:var]), :method => :put) do %>
<h3>Editing <%= @setting[:var].titleize %></h3>
<div class="field">
<%= text_area_tag :value, @setting[:value], :cols => 50, :class => "wysiwyg" %><br/>
<em>Use %{provider_name} or %{client_name} to include names in messages.</em>
</div>
<div class="field">
<%= submit_tag "Save", {:class => "wymupdate"} %><br/>
<%= link_to "Back", settings_path %>
</div>
<% end %>

View File

@@ -0,0 +1,16 @@
<h2>Site-Wide Settings</h2>
<table>
<tr>
<th>Name</th>
<th>Value</th>
</tr>
<% @settings.each do |setting| %>
<tr>
<td><%= setting.first.titleize %></td>
<td>"<%= setting.last %>"</td>
<% if can? :update, setting %>
<td><%= link_to 'Edit', edit_setting_path(setting.first) %></td>
<% end %>
</tr>
<% end %>
</table>