Skip to content

Commit

Permalink
cleaned up models, started on read/edit plan, added layout paritals
Browse files Browse the repository at this point in the history
  • Loading branch information
annaswims committed Mar 13, 2011
1 parent 715ce5a commit 4e8ca6b
Show file tree
Hide file tree
Showing 41 changed files with 990 additions and 662 deletions.
6 changes: 3 additions & 3 deletions Gemfile.lock
Expand Up @@ -36,7 +36,7 @@ GEM
activesupport (= 3.0.4)
activesupport (3.0.4)
annotate (2.4.0)
arel (2.0.8)
arel (2.0.9)
authlogic (2.1.6)
activesupport
builder (2.1.2)
Expand Down Expand Up @@ -65,12 +65,12 @@ GEM
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.16)
mysql (2.7)
mysql (2.8.1)
net-scp (1.0.4)
net-ssh (>= 1.99.1)
net-sftp (2.0.5)
net-ssh (>= 2.0.9)
net-ssh (2.1.0)
net-ssh (2.1.3)
net-ssh-gateway (1.0.1)
net-ssh (>= 1.99.1)
polyglot (0.3.1)
Expand Down
4 changes: 3 additions & 1 deletion app/controllers/application_controller.rb
@@ -1,16 +1,18 @@
class ApplicationController < ActionController::Base
protect_from_forgery


# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.
helper :all # include all helpers, all the time
helper_method :current_account, :current_account_session


def current_account
@current_account ||= current_account_session && current_account_session.record
end

def current_account_session
@current_account_session ||= AccountSession.find
end

end
2 changes: 2 additions & 0 deletions app/controllers/home_controller.rb
@@ -1,6 +1,8 @@
class HomeController < ApplicationController

def index
end

def login
@account = Account.new()
end
Expand Down
22 changes: 22 additions & 0 deletions app/controllers/plan_controller.rb
@@ -0,0 +1,22 @@
class PlanController < ApplicationController

def edit
@plan = current_account.plan
end

def update
@plan = current_account.plan
@plan.edit_text = params[:plan][:edit_text]
if @plan.save
redirect_to :action=>:read, :username => @plan.account.username
else
render :action => "edit"
end
end

def read
@plan = Account.find_by_username(params[:username]).plan
# TODO mark as read
end

end
4 changes: 4 additions & 0 deletions app/helpers/application_helper.rb
@@ -1,2 +1,6 @@
module ApplicationHelper
# def show_autofinger(priority)
# Autofinger.where(:owner=>current_account.userid, :priority=>priority)
# end

end
1 change: 1 addition & 0 deletions app/helpers/home_helper.rb
@@ -1,2 +1,3 @@
module HomeHelper

end
58 changes: 30 additions & 28 deletions app/models/account.rb
@@ -1,6 +1,4 @@
require 'lib/bellmyer/create_alias.rb'
class Account < ActiveRecord::Base
include Bellmyer::CreateAlias
set_primary_key :userid
validates :username, :presence => true, :length =>{ :maximum => 16 }
validates :password, :length =>{ :maximum => 34 }
Expand All @@ -9,18 +7,18 @@ class Account < ActiveRecord::Base
validates :show_images, :presence => true

has_many :interests_in_others, :class_name => "Autofinger", :foreign_key => "owner"
has_many :people_that_interest_me, :class_name => "Accounts", :through => :interests_in_others, :source=>"subject_of_interest"

has_many :people_that_interest_me, :class_name => "Account", :through => :interests_in_others, :source=>"subject_of_interest"
has_many :board_votes, :foreign_key=> :userid
has_many :opt_links, :foreign_key=> :userid
has_many :avail_links, :through=>:opt_links
has_one :permission, :foreign_key=> :userid
has_many :poll_votes, :foreign_key=> :userid
has_one :stylesheet, :foreign_key=> :userid
has_many :main_board, :foreign_key=> :userid
has_many :sub_board, :foreign_key=> :userid
has_many :main_boards, :foreign_key=> :userid
has_many :sub_boards, :foreign_key=> :userid
has_one :viewed_secret, :foreign_key=> :userid
has_one :plan, :foreign_key => :user_id
has_one :display, :foreign_key => :user_id
has_one :display, :foreign_key => :userid

before_validation do
self.show_images = true
Expand All @@ -33,9 +31,11 @@ def instance_method_already_implemented?(method_name)
super
end
end

def changed_date= value
self[:changed] = value
end

def changed_date
self[:changed]
end
Expand All @@ -57,33 +57,35 @@ def crypted_password= hash
def crypted_password
read_attribute :password
end

end



# == Schema Information
#
# Table name: accounts
#
# userid :integer(2) not null, primary key
# username :string(16) default(""), not null
# created :datetime
# password :string(34)
# email :string(64)
# pseudo :string(64)
# login :datetime
# changed :datetime
# poll :integer(1)
# group_bit :string(1)
# spec_message :string(255)
# grad_year :string(4)
# edit_cols :integer(1)
# edit_rows :integer(1)
# webview :string(1) default("0")
# notes_asc :string(1)
# user_type :string(128)
# show_images :boolean(1) default(FALSE), not null
# guest_password :string(30)
# is_admin :boolean(1) default(FALSE)
# userid :integer not null, primary key
# username :string(16) default(""), not null
# created :datetime
# password :string(34)
# email :string(64)
# pseudo :string(64)
# login :datetime
# changed :datetime
# poll :integer(1)
# group_bit :string(1)
# spec_message :string(255)
# grad_year :string(4)
# edit_cols :integer(1)
# edit_rows :integer(1)
# webview :string(1) default("0")
# notes_asc :string(1)
# user_type :string(128)
# show_images :boolean default(FALSE), not null
# guest_password :string(30)
# is_admin :boolean default(FALSE)
# persistence_token :string(255)
# password_salt :string(255)
#

4 changes: 2 additions & 2 deletions app/models/autofinger.rb
Expand Up @@ -2,8 +2,8 @@ class Autofinger < ActiveRecord::Base
set_table_name :autofinger
validates_presence_of :owner, :interest

belongs_to :interested_party, :foreign_key => :owner, :class_name => "Accounts"
belongs_to :subject_of_interest, :foreign_key => :interest, :class_name => "Accounts"
belongs_to :interested_party, :foreign_key => :owner, :class_name => "Account"
belongs_to :subject_of_interest, :foreign_key => :interest, :class_name => "Account"
end

# == Schema Information
Expand Down
3 changes: 2 additions & 1 deletion app/models/avail_link.rb
Expand Up @@ -3,11 +3,12 @@ class AvailLink < ActiveRecord::Base
has_many :opt_links, :foreign_key =>:linknum
end


# == Schema Information
#
# Table name: avail_links
#
# linknum :integer(1) not null, primary key
# linknum :integer not null, primary key
# linkname :string(128)
# descr :text
# html_code :text(255)
Expand Down
5 changes: 3 additions & 2 deletions app/models/board_vote.rb
Expand Up @@ -5,15 +5,16 @@ class BoardVote < ActiveRecord::Base

end


# == Schema Information
#
# Table name: boardvotes
#
# voteid :integer(2) not null, primary key
# voteid :integer not null, primary key
# userid :integer(2) default(0), not null
# threadid :integer(2) default(0), not null
# messageid :integer(2) default(0), not null
# vote_date :timestamp not null
# vote_date :datetime not null
# vote :integer(2)
#

3 changes: 2 additions & 1 deletion app/models/display.rb
Expand Up @@ -5,11 +5,12 @@ class Display < ActiveRecord::Base
belongs_to :account, :foreign_key=> :userid
belongs_to :style, :foreign_key=>:style
end

# == Schema Information
#
# Table name: display
#
# userid :integer(2) default(0), not null, primary key
# userid :integer not null, primary key
# interface :integer(1)
# style :integer(1)
#
Expand Down
3 changes: 2 additions & 1 deletion app/models/interface.rb
Expand Up @@ -4,11 +4,12 @@ class Interface < ActiveRecord::Base
has_many :displays, :foreign_key =>:interface
end


# == Schema Information
#
# Table name: interface
#
# interface :integer(1) not null, primary key
# interface :integer not null, primary key
# path :string(128)
# descr :string(255)
#
Expand Down
3 changes: 2 additions & 1 deletion app/models/main_board.rb
Expand Up @@ -5,11 +5,12 @@ class MainBoard < ActiveRecord::Base
has_many :sub_boards, :foreign_key =>:threadid
end


# == Schema Information
#
# Table name: mainboard
#
# threadid :integer(2) not null, primary key
# threadid :integer not null, primary key
# title :string(128)
# created :datetime
# lastupdated :datetime
Expand Down
3 changes: 2 additions & 1 deletion app/models/permission.rb
Expand Up @@ -3,11 +3,12 @@ class Permission < ActiveRecord::Base
belongs_to :account, :foreign_key=> :userid
end


# == Schema Information
#
# Table name: perms
#
# userid :integer(2) not null
# userid :integer not null
# status :string(32)
#

62 changes: 61 additions & 1 deletion app/models/plan.rb
@@ -1,14 +1,74 @@
class Plan < ActiveRecord::Base
belongs_to :account, :foreign_key=> :user_id
before_save :clean_text
before_update :set_modified_time

def userid
user_id
end

# TODO make actual rails links
# this is by no means finished or tested
def clean_text
checked = {}
self.plan= CGI.escapeHTML(edit_text) #take out html
# escape all html but <b><tt><pre><s><i><u><a href="">
self.plan.gsub!(/((\[\w*\],?){8})(?=[^ ,])/s, "$1 ")
self.plan.gsub!(/\n/s, "<br>")
self.plan.gsub!(/\&lt\;hr\&gt\;/si, "</p><hr><p class=\"sub\">")
# replace the first </p> that we just inserted erroneously
self.plan = '<p class="sub">'+self.plan+'</p>';
self.plan.gsub!(/\&lt\;b\&gt\;(.*?)\&lt\;\/b\&gt\;/si, "<b>\\1</b>") #allow stuff in the bold tag back in
self.plan.gsub!(/\&lt\;tt\&gt\;(.*?)\&lt\;\/tt\&gt\;/si, "<tt>\\1</tt>")
self.plan.gsub!(/\&lt\;pre\&gt\;(.*?)\&lt\;\/pre\&gt\;/si, "</p><pre class=\"sub\">\\1</pre><p class=\"sub\">")
self.plan.gsub!(/\&lt\;strike\&gt\;(.*?)\&lt\;\/strike\&gt\;/si, "<span class=\"strike\">\\1</span><!--strike-->")
self.plan.gsub!(/\&lt\;s\&gt\;(.*?)\&lt\;\/s\&gt\;/si, "<s>\\1</s>")
self.plan.gsub!(/\&lt\;i\&gt\;(.*?)\&lt\;\/i\&gt\;/si, "<i>\\1</i>") #allow stuff in the italics tag back in
self.plan.gsub!(/\&lt\;u\&gt\;(.*?)\&lt\;\/u\&gt\;/si, "<span class=\"underline\">\\1</span><!--u-->") #allow stuff in the underline tag back in
self.plan.gsub!(/\&lt\;a.+?href=.&quot\;(.+?).&quot\;&gt\;(.+?)&lt\;\/a&gt\;/si, "<a href=\"\\1\" class=\"onplan\">\\2</a>")
loves = self.plan.scan(/.*?\[(.*?)\].*?/s)#get an array of everything in brackets
logger.debug("self.plan________"+self.plan)
for love in loves
debugger
item = love.first
jlw = item.gsub(/\#/, "\/")
unless checked[item]
account = Account.where(:username=>item).first
if account.blank?
if item.match(/^\d+$/) && SubBoard.find(:first, :conditions=>{:messageid=>item})
#TODO Regexp.escape(item, "/")
self.plan.gsub!(/\[" . Regexp.escape(item) . "\]/s, "[<a href=\"board_messages.php?messagenum=$item#{item}\" class=\"boardlink\">#{item}</a>]")
end
if item =~ /:/
if item =~ /|/
love_replace = item.match(/(.+?)\|(.+)/si)
self.plan.gsub!(/\[" . Regexp.escape(item) . "\]/s, "<a href=\"/read/#{love_replace[1]}\" class=\"onplan\">#{love_replace[2]}</a>") #change all occurences of person on plan
else
self.plan.gsub!(/\[" . Regexp.escape(item) . "\]/s, "<a href=\"#{item}\" class=\"onplan\">#{item}</a>")
end
end
else
self.plan.gsub!(/\[#{item}\]/s, "[<a href=\"/read/#{item}\" class=\"planlove\">#{item}</a>]"); #change all occurences of person on plan

end
end
checked[item]=true
end
logger.debug("self.plan________"+self.plan)
end

private
def set_modified_time
self.account.changed = Time.now()
self.account.save!
end
end

# == Schema Information
#
# Table name: plans
#
# id :integer(2) not null, primary key
# id :integer not null, primary key
# user_id :integer(2)
# plan :text(16777215)
# edit_text :text
Expand Down
6 changes: 4 additions & 2 deletions app/models/poll_choice.rb
@@ -1,15 +1,17 @@
class PollChoice < ActiveRecord::Base
set_primary_key :poll_choice_id
belongs_to :poll_question
has_many :poll_votes
end



# == Schema Information
#
# Table name: poll_choices
#
# poll_choice_id :integer(4) not null, primary key
# poll_question_id :integer(4)
# poll_choice_id :integer not null, primary key
# poll_question_id :integer
# html :text
# created :datetime
#
Expand Down

0 comments on commit 4e8ca6b

Please sign in to comment.