Browse Source

rein damit

Paul Klumpp 11 years ago
parent
commit
a28aa446fa

+ 2 - 1
Gemfile

@@ -37,6 +37,7 @@ gem 'jquery-rails'
 # To use debugger
 # gem 'debugger'
 
-gem 'shotgun'
 gem 'activeadmin'
 
+gem 'shotgun'
+

+ 17 - 0
app/admin/bots.rb

@@ -1,6 +1,8 @@
 ActiveAdmin.register Bot do
   menu :priority => 4
 
+
+
   index do
     column :id
     column :botnick do |b|
@@ -15,6 +17,7 @@ ActiveAdmin.register Bot do
 
 
   show :title => :botnick do
+
     attributes_table do
       row :id
       row :botnick
@@ -22,9 +25,23 @@ ActiveAdmin.register Bot do
       row :activate
       row :created_at
       row :updated_at
+    end
 
+    panel "This Bot's Channels" do
+      table_for(bot.channels)  do
+        column :name
+        column :activate
+      end
     end
+
     active_admin_comments
+
+  end
+
+  sidebar :help do
+    ul do
+      li "Owner: It is nice to read some contact infos like an email address in the owners field. To make life for spamcrawlers harder, use an obfuscation method for the address, like: foo {at] bar dot domain"
+    end
   end
 
 

+ 9 - 1
app/admin/channels.rb

@@ -42,7 +42,15 @@ ActiveAdmin.register Channel do
 
     f.inputs "Details" do
       f.input :name, :label => "Channelname"
-      f.input :bot, :as => :select, :member_label => :botnick  # https://github.com/justinfrench/formtastic/blob/master/lib/formtastic/inputs/select_input.rb
+      if params[:bot_id] && params[:botnick] then
+        f.input :bot_id, :as => :string,  :member_label => :botnick, :input_html => { :readonly => true, :size => 10, :value => params[:botnick] }
+        f.input :bot_id, :as => :hidden,  :value => params[:bot_id], :member_label => :botnick, :input_html => { :readonly => true, :size => 10, :value => params[:bot_id] }
+        #f.input :bot, :as => :select, :member_label => :botnick  # https://github.com/justinfrench/formtastic/blob/master/lib/formtastic/inputs/select_input.rb
+      else
+        f.input :bot, :as => :select, :member_label => :botnick  # https://github.com/justinfrench/formtastic/blob/master/lib/formtastic/inputs/select_input.rb
+      end
+
+
       f.input :activate
     end
     f.buttons

+ 29 - 6
app/admin/dashboards.rb

@@ -8,21 +8,44 @@ ActiveAdmin::Dashboards.build do
   # Here is an example of a simple dashboard section
   #
   section "Bots and Channels" do
-    ul do
-      @bots = Bot.all
-      @bots.each do |bot|
-        li bot.botnick
 
-        ol do
+    @bots = Bot.all
+    @bots.each do |bot|
+
+      panel "Botnick: " + bot.botnick do
+
+        span link_to("view this bot", "admin/bots/" + bot.id.to_s)
+        span "|"
+        span link_to("edit this bot", "admin/bots/" + bot.id.to_s + "/edit")
+        span "|"
+        span link_to("add a channel to this bot", "admin/channels/new?bot_id=" + bot.id.to_s + "&botnick=" + bot.botnick.to_s)
+
+        table do
           @channels = Channel.find_all_by_bot_id(bot.id)
+          th :Name
+          th :Activate
+          th :Actions
           @channels.each do |c|
-            li c.name
+
+            tr do
+              td c.name
+              td c.activate
+              td do
+                span link_to("view", "admin/channels/" + c.id.to_s)
+                span link_to("edit", "admin/channels/" + c.id.to_s + "/edit")
+                span link_to("delete", "admin/channels/" + c.id.to_s, :method => 'delete', :confirm => "You sure?")
+              end
+            end
           end
         end
+
       end
+
     end
+    span link_to("add a new bot", "admin/bots/new")
   end
 
+
   section "Frequencies and Bans" do
     ul do
       @frequencies = Frequency.all

+ 26 - 0
app/assets/stylesheets/active_admin.css.scss

@@ -4,3 +4,29 @@
 
 // To customize the Active Admin interfaces, add your
 // styles here:
+
+.panel{
+  margin-bottom: 0px;
+}
+
+.panel_contents table {
+  margin: 0px;
+}
+
+.panel_contents table th {
+  padding-top: 0px;
+}
+
+.panel > div {
+  padding-top: 0px;
+  padding-bottom: 5px;
+}
+
+.panel > h3 {
+  margin-bottom: 0px;
+}
+
+td {
+  padding-top: 0px;
+  padding-bottom: 0px;
+}

+ 4 - 9
app/models/admin_user.rb

@@ -1,10 +1,4 @@
 class AdminUser < ActiveRecord::Base
-  # Include default devise modules. Others available are:
-  # :token_authenticatable, :confirmable,
-  # :lockable, :timeoutable and :omniauthable
-  devise :database_authenticatable, 
-         :recoverable, :rememberable, :trackable, :validatable
-
   # Setup accessible (or protected) attributes for your model
   attr_accessible :email, :password, :password_confirmation, :remember_me
   # Include default devise modules. Others available are:
@@ -13,9 +7,9 @@ class AdminUser < ActiveRecord::Base
   devise :database_authenticatable, 
          :recoverable, :rememberable, :trackable, :validatable
 
-  # Setup accessible (or protected) attributes for your model
-  attr_accessible :email, :password, :password_confirmation, :remember_me
-  # attr_accessible :title, :body
+  validates :email,
+            :presence => true,
+            :format => { :with => /\A[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]+\z/, :message => "Must be of E-Mail address format" }
 
 
   after_create { |admin| admin.send_reset_password_instructions }
@@ -23,4 +17,5 @@ class AdminUser < ActiveRecord::Base
   def password_required?
     new_record? ? false : super
   end
+
 end

+ 6 - 0
app/models/ban.rb

@@ -8,4 +8,10 @@ class Ban < ActiveRecord::Base
   validates_presence_of :frequency_id
   validates_presence_of :frequency_id, :on => :update
 
+  validates :hostmask,
+            :presence => true
+
+  validates :reason,
+            :presence =>  true
+
 end

+ 10 - 3
app/models/bot.rb

@@ -6,9 +6,16 @@ class Bot < ActiveRecord::Base
   accepts_nested_attributes_for :channels, :allow_destroy => true
 
   # Validation
-  validates :botnick,  :presence => true, :format => { :with => /\A[a-zA-Z0-9]*+\z/,
-                                                        :message => "Channel name must be alphanumeric" }
-  validates :owner,  :presence => true
+  validates :botnick,
+            :uniqueness => true,
+            :presence => true,
+            :format => { :with => /\A[a-zA-Z0-9]*+\z/, :message => "Channel name must be alphanumeric" }
+
+  validates :owner,
+            :presence => true
+
+
+
 
 
 end

+ 4 - 2
app/models/channel.rb

@@ -5,8 +5,10 @@ class Channel < ActiveRecord::Base
   belongs_to :bot
 
   # Validation
-  validates :name,  :presence => true, :format => { :with => /\A#.+\z/,
-                                                      :message => "Channel name must begin with #" }
+  validates :name,
+            :uniqueness => true,
+            :presence => true,
+            :format => { :with => /\A#.+\z/, :message => "Channel name must begin with #" }
 
   validates_presence_of :bot_id
   validates_presence_of :bot_id, :on => :update

+ 13 - 0
app/models/frequency.rb

@@ -6,6 +6,19 @@ class Frequency < ActiveRecord::Base
   accepts_nested_attributes_for :bans, :allow_destroy => true
 
   # Validation
+  validates :name,
+            :uniqueness => true,
+            :presence => true,
+            :format => { :with => /\A-.+-\z/, :message => "Frequency name must begin and end with -" }
+
+  validates :prefix,
+            :uniqueness => true,
+            :presence => true,
+            :format => { :with => /\A\..+\z/, :message => "Frequency call prefix must begin with ." }
+
+  validates :delay,
+            :presence => true
+
   before_destroy :raise_if_last
   def raise_if_last
     if Frequency.count < 3

+ 1 - 1
config/routes.rb

@@ -6,7 +6,7 @@ Nooo::Application.routes.draw do
 
   devise_for :admin_users, ActiveAdmin::Devise.config
 
-  match '/' => 'network#show'
+  match '/' => redirect("/admin")
 
   #resources :users
   #resources :bots