added ability to add parents and children to everything using the graphic interface

This commit is contained in:
Connor Turland 2012-09-29 23:45:14 -04:00
parent 1b9fa104c6
commit 66d13159f0
38 changed files with 428 additions and 20 deletions

View file

@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/

View file

@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/

View file

@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/

View file

@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/

View file

@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/

View file

@ -0,0 +1,3 @@
// Place all the styles related to the Groupgroups controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View file

@ -0,0 +1,3 @@
// Place all the styles related to the Groupitems controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View file

@ -0,0 +1,3 @@
// Place all the styles related to the Grouppeople controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View file

@ -0,0 +1,3 @@
// Place all the styles related to the Itemitems controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View file

@ -0,0 +1,3 @@
// Place all the styles related to the Personitems controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View file

@ -0,0 +1,2 @@
class GroupgroupsController < ApplicationController
end

View file

@ -0,0 +1,2 @@
class GroupitemsController < ApplicationController
end

View file

@ -0,0 +1,2 @@
class GrouppeopleController < ApplicationController
end

View file

@ -42,7 +42,7 @@ class GroupsController < ApplicationController
@group.save
respond_to do |format|
format.html {render :index}
format.html { respond_with(@user, location: restore(default: group_url(@group))) }
format.js { respond_with(@group) }
end
@ -51,8 +51,22 @@ class GroupsController < ApplicationController
# GET /groups/:id/edit
def edit
@group = Group.find_by_id(params[:id])
@ingroups1 = @group.parent_groups
if @ingroups1.count > 0
@outgroups1 = Group.find(:all, :conditions => ['id not in (?) AND id != ?', @ingroups1.map(&:id), @group.id])
else
@outgroups1 = Group.find(:all, :conditions => ['id != ?', @group.id])
end
@ingroups2 = @group.child_groups
if @ingroups2.count > 0
@outgroups2 = Group.find(:all, :conditions => ['id not in (?) AND id != ?', @ingroups2.map(&:id), @group.id])
else
@outgroups2 = Group.find(:all, :conditions => ['id != ?', @group.id])
end
respond_with(@group)
respond_with(@group, @ingroups1, @outgroups1, @ingroups2, @outgroups2)
end
# PUT /groups/:id
@ -62,6 +76,46 @@ class GroupsController < ApplicationController
@group.attributes = params[:group] if @group
@group.save if @group
#remove the selected parent groups
if params[:ingroups1]
@ingroups1 = params[:ingroups1]
@ingroups1.each do |g|
@connection = Groupgroup.where("parent_group_id = ? AND group_id = ?", g, @group.id).first
@connection.delete
end
end
#remove the selected parent groups
if params[:outgroups1]
@outgroups1 = params[:outgroups1]
@outgroups1.each do |g|
belongs = Groupgroup.new
belongs.parent_group_id = g
belongs.group_id = @group.id
belongs.save!
end
end
#remove the selected children groups
if params[:ingroups2]
@ingroups2 = params[:ingroups2]
@ingroups2.each do |g|
@connection = Groupgroup.where("parent_group_id = ? AND group_id = ?", @group.id, g).first
@connection.delete
end
end
#add the selected children groups
if params[:outgroups2]
@outgroups2 = params[:outgroups2]
@outgroups2.each do |g|
belongs = Groupgroup.new
belongs.parent_group_id = @group.id
belongs.group_id = g
belongs.save!
end
end
respond_with(@user, location: restore(default: root_url)) do |format|
end

View file

@ -0,0 +1,2 @@
class ItemitemsController < ApplicationController
end

View file

@ -46,7 +46,7 @@ class ItemsController < ApplicationController
@item.save
respond_to do |format|
format.html {render :index}
format.html { respond_with(@user, location: restore(default: item_url(@item))) }
format.js { respond_with(@item) }
end
@ -55,8 +55,36 @@ class ItemsController < ApplicationController
# GET /items/:id/edit
def edit
@item = Item.find_by_id(params[:id])
@ingroups = @item.groups
if @ingroups.count > 0
@outgroups = Group.find(:all, :conditions => ['id not in (?)', @ingroups.map(&:id)])
else
@outgroups = Group.all
end
@inpeople = @item.people
if @inpeople.count > 0
@outpeople = Person.find(:all, :conditions => ['id not in (?)', @inpeople.map(&:id)])
else
@outpeople = Person.all
end
@initems1 = @item.parent_items
if @initems1.count > 0
@outitems1 = Item.find(:all, :conditions => ['id not in (?) AND id != ?', @initems1.map(&:id), @item.id])
else
@outitems1 = Item.find(:all, :conditions => ['id != ?', @item.id])
end
@initems2 = @item.child_items
if @initems2.count > 0
@outitems2 = Item.find(:all, :conditions => ['id not in (?) AND id != ?', @initems2.map(&:id), @item.id])
else
@outitems2 = Item.find(:all, :conditions => ['id != ?', @item.id])
end
respond_with(@item)
respond_with(@item, @initems1, @outitems1, @initems2, @outitems2, @ingroups, @outgroups, @inpeople, @outpeople)
end
# PUT /actions/:id
@ -68,12 +96,88 @@ class ItemsController < ApplicationController
@item.name = params[:item][:name]
@item.desc = params[:item][:desc]
@item.link = params[:item][:link]
@item.item_category = ItemCategory.find(params[:category])
@item.item_category = ItemCategory.find(params[:category][:item_category_id])
@item.user = @user
@item.save
end
if params[:ingroups]
@ingroups = params[:ingroups]
@ingroups.each do |g|
@connection = Groupitem.where("group_id = ? AND item_id = ?", g, @item.id).first
@connection.delete
end
end
if params[:outgroups]
@outgroups = params[:outgroups]
@outgroups.each do |g|
belongs = Groupitem.new
belongs.group_id = g
belongs.item_id = @item.id
belongs.save!
end
end
if params[:inpeople]
@inpeople = params[:inpeople]
@inpeople.each do |g|
@connection = Personitem.where("person_id = ? AND item_id = ?", g, @item.id).first
@connection.delete
end
end
if params[:outpeople]
@outpeople = params[:outpeople]
@outpeople.each do |g|
belongs = Personitem.new
belongs.person_id = g
belongs.item_id = @item.id
belongs.save!
end
end
#remove the selected parent items
if params[:initems1]
@initems1 = params[:initems1]
@initems1.each do |g|
@connection = Itemitem.where("parent_item_id = ? AND item_id = ?", g, @item.id).first
@connection.delete
end
end
#remove the selected parent items
if params[:outitems1]
@outitems1 = params[:outitems1]
@outitems1.each do |g|
belongs = Itemitem.new
belongs.parent_item_id = g
belongs.item_id = @item.id
belongs.save!
end
end
#remove the selected children items
if params[:initems2]
@initems2 = params[:initems2]
@initems2.each do |g|
@connection = Itemitem.where("parent_item_id = ? AND item_id = ?", @item.id, g).first
@connection.delete
end
end
#add the selected children items
if params[:outitems2]
@outitems2 = params[:outitems2]
@outitems2.each do |g|
belongs = Itemitem.new
belongs.parent_item_id = @item.id
belongs.item_id = g
belongs.save!
end
end
respond_with(@user, location: restore(default: root_url)) do |format|
end
end

View file

@ -42,16 +42,18 @@ class PeopleController < ApplicationController
@person.save
@groups = Group.find(params[:ingroups])
@groups.each do |g|
belongs = Groupperson.new
belongs.group_id = g.id
belongs.person_id = @person.id
belongs.save!
end
if params[:ingroups]
@groups = Group.find(params[:ingroups])
@groups.each do |g|
belongs = Groupperson.new
belongs.group_id = g.id
belongs.person_id = @person.id
belongs.save!
end
end
respond_to do |format|
format.html {render :index}
format.html { respond_with(@user, location: restore(default: person_url(@person))) }
format.js { respond_with(@person) }
end
@ -60,18 +62,42 @@ class PeopleController < ApplicationController
# GET /people/:id/edit
def edit
@person = Person.find_by_id(params[:id])
respond_with(@person)
@ingroups = @person.groups
if @ingroups.count > 0
@outgroups = Group.find(:all, :conditions => ['id not in (?)', @ingroups.map(&:id)])
else
@outgroups = Group.all
end
respond_with(@person, @ingroups, @outgroups)
end
# PUT /people/:id
def update
@user = current_user
@person = Person.find_by_id(params[:id])
@person.attributes = params[:person] if @person
@person.attributes = params[:person] if @person
@person.save if @person
if params[:ingroups]
@ingroups = params[:ingroups]
@ingroups.each do |g|
@connection = Groupperson.where("group_id = ? AND person_id = ?", g, @person.id).first
@connection.delete
end
end
if params[:outgroups]
@outgroups = params[:outgroups]
@outgroups.each do |g|
belongs = Groupperson.new
belongs.group_id = g
belongs.person_id = @person.id
belongs.save!
end
end
respond_with(@user, location: restore(default: root_url)) do |format|
end
end

View file

@ -0,0 +1,2 @@
class PersonitemsController < ApplicationController
end

View file

@ -0,0 +1,2 @@
module GroupgroupsHelper
end

View file

@ -0,0 +1,2 @@
module GroupitemsHelper
end

View file

@ -0,0 +1,2 @@
module GrouppeopleHelper
end

View file

@ -0,0 +1,2 @@
module ItemitemsHelper
end

View file

@ -0,0 +1,2 @@
module PersonitemsHelper
end

View file

@ -8,6 +8,10 @@ has_many :items
acts_as_authentic do |configuration|
configuration.session_class = Session
configuration.require_password_confirmation = false
configuration.merge_validates_format_of_email_field_options unless: Proc.new { |user| user.email.blank? and user.authed? }
configuration.merge_validates_length_of_email_field_options unless: Proc.new { |user| user.email.blank? and user.authed? }
end
validates :password, :presence => true,

View file

@ -12,5 +12,37 @@
<%= form.text_field :province, class: "province" %>
<label for="group_country">Country</label>
<%= form.text_field :country, class: "country" %>
<% if @ingroups1.count > 0 %>
<label for="ingroups1">Remove Parent Groups</label>
<%= select_tag "ingroups1", options_from_collection_for_select(@ingroups1, "id", "name"), { :multiple => true } %>
<% else %>
<div style="display:none">
<%= select_tag "ingroups1", options_from_collection_for_select(@ingroups1, "id", "name"), { :multiple => true } %>
</div>
<% end %>
<% if @outgroups1.count > 0 %>
<label for="outgroups1">Add Parent Groups</label>
<%= select_tag "outgroups1", options_from_collection_for_select(@outgroups1, "id", "name"), { :multiple => true } %>
<% else %>
<div style="display:none">
<%= select_tag "outgroups1", options_from_collection_for_select(@outgroups1, "id", "name"), { :multiple => true } %>
</div>
<% end %>
<% if @ingroups2.count > 0 %>
<label for="ingroups2">Remove Child Groups</label>
<%= select_tag "ingroups2", options_from_collection_for_select(@ingroups2, "id", "name"), { :multiple => true } %>
<% else %>
<div style="display:none">
<%= select_tag "ingroups2", options_from_collection_for_select(@ingroups2, "id", "name"), { :multiple => true } %>
</div>
<% end %>
<% if @outgroups2.count > 0 %>
<label for="outgroups2">Add Child Groups</label>
<%= select_tag "outgroups2", options_from_collection_for_select(@outgroups2, "id", "name"), { :multiple => true } %>
<% else %>
<div style="display:none">
<%= select_tag "outgroups2", options_from_collection_for_select(@outgroups2, "id", "name"), { :multiple => true } %>
</div>
<% end %>
<%= form.submit "Update", class: "update" %>
<% end %>

View file

@ -1,12 +1,79 @@
<%= form_for @item, url: item_url do |form| %>
<h3>Edit Item</h3>
<label for="category">Category</label>
<%= select_tag "category", options_from_collection_for_select(ItemCategory.all, "id", "name") %>
<%= select "category", "item_category_id", ItemCategory.all.collect {|p| [ p.name, p.id ] }, { :selected => @item.item_category.id } %>
<label for="item_name">Title</label>
<%= form.text_field :name %>
<label for="item_desc">Description</label>
<%= form.text_area :desc, class: "description", :rows => 5 %>
<label for="item_link">Link</label>
<%= form.text_field :link, class: "link" %>
<% if @ingroups.count > 0 %>
<label for="ingroups">Remove Parent Groups</label>
<%= select_tag "ingroups", options_from_collection_for_select(@ingroups, "id", "name"), { :multiple => true } %>
<% else %>
<div style="display:none">
<%= select_tag "ingroups", options_from_collection_for_select(@ingroups, "id", "name"), { :multiple => true } %>
</div>
<% end %>
<% if @outgroups.count > 0 %>
<label for="outgroups">Add Parent Groups</label>
<%= select_tag "outgroups", options_from_collection_for_select(@outgroups, "id", "name"), { :multiple => true } %>
<% else %>
<div style="display:none">
<%= select_tag "outgroups", options_from_collection_for_select(@outgroups, "id", "name"), { :multiple => true } %>
</div>
<% end %>
<% if @inpeople.count > 0 %>
<label for="inpeople">Remove Parent People</label>
<%= select_tag "inpeople", options_from_collection_for_select(@inpeople, "id", "name"), { :multiple => true } %>
<% else %>
<div style="display:none">
<%= select_tag "inpeople", options_from_collection_for_select(@inpeople, "id", "name"), { :multiple => true } %>
</div>
<% end %>
<% if @outpeople.count > 0 %>
<label for="outpeople">Add Parent People</label>
<%= select_tag "outpeople", options_from_collection_for_select(@outpeople, "id", "name"), { :multiple => true } %>
<% else %>
<div style="display:none">
<%= select_tag "outpeople", options_from_collection_for_select(@outpeople, "id", "name"), { :multiple => true } %>
</div>
<% end %>
<% if @initems1.count > 0 %>
<label for="initems1">Remove Parent Items</label>
<%= select_tag "initems1", options_from_collection_for_select(@initems1, "id", "name"), { :multiple => true } %>
<% else %>
<div style="display:none">
<%= select_tag "initems1", options_from_collection_for_select(@initems1, "id", "name"), { :multiple => true } %>
</div>
<% end %>
<% if @outitems1.count > 0 %>
<label for="outitems1">Add Parent Items</label>
<%= select_tag "outitems1", options_from_collection_for_select(@outitems1, "id", "name"), { :multiple => true } %>
<% else %>
<div style="display:none">
<%= select_tag "outitems1", options_from_collection_for_select(@outitems1, "id", "name"), { :multiple => true } %>
</div>
<% end %>
<% if @initems2.count > 0 %>
<label for="initems2">Remove Child Items</label>
<%= select_tag "initems2", options_from_collection_for_select(@initems2, "id", "name"), { :multiple => true } %>
<% else %>
<div style="display:none">
<%= select_tag "initems2", options_from_collection_for_select(@initems2, "id", "name"), { :multiple => true } %>
</div>
<% end %>
<% if @outitems2.count > 0 %>
<label for="outitems2">Add Child Items</label>
<%= select_tag "outitems2", options_from_collection_for_select(@outitems2, "id", "name"), { :multiple => true } %>
<% else %>
<div style="display:none">
<%= select_tag "outitems2", options_from_collection_for_select(@outitems2, "id", "name"), { :multiple => true } %>
</div>
<% end %>
<%= form.submit "Update", class: "update" %>
<% end %>

View file

@ -12,5 +12,21 @@
<%= form.text_field :province, class: "province" %>
<label for="person_country">Country</label>
<%= form.text_field :country, class: "country" %>
<% if @ingroups.count > 0 %>
<label for="ingroups">Remove From Groups</label>
<%= select_tag "ingroups", options_from_collection_for_select(@ingroups, "id", "name"), { :multiple => true } %>
<% else %>
<div style="display:none">
<%= select_tag "ingroups", options_from_collection_for_select(@ingroups, "id", "name"), { :multiple => true } %>
</div>
<% end %>
<% if @outgroups.count > 0 %>
<label for="outgroups">Add To Groups</label>
<%= select_tag "outgroups", options_from_collection_for_select(@outgroups, "id", "name"), { :multiple => true } %>
<% else %>
<div style="display:none">
<%= select_tag "outgroups", options_from_collection_for_select(@outgroups, "id", "name"), { :multiple => true } %>
</div>
<% end %>
<%= form.submit "Update", class: "update" %>
<% end %>

View file

@ -6,7 +6,7 @@
<%= form.text_area :desc, label: "Description", class: "description", :rows => 5 %>
<label for="person_link">Link</label>
<%= form.text_field :link, label: "Link", class: "link" %>
<label for="ingroups">In These Groups</label>
<label for="ingroups">Add To Groups</label>
<%= select_tag "ingroups", options_from_collection_for_select(Group.all, "id", "name"), { :multiple => true } %>
<label for="person_city">City</label>
<%= form.text_field :city, class: "city" %>

View file

@ -0,0 +1,7 @@
require 'test_helper'
class GroupgroupsControllerTest < ActionController::TestCase
# test "the truth" do
# assert true
# end
end

View file

@ -0,0 +1,7 @@
require 'test_helper'
class GroupitemsControllerTest < ActionController::TestCase
# test "the truth" do
# assert true
# end
end

View file

@ -0,0 +1,7 @@
require 'test_helper'
class GrouppeopleControllerTest < ActionController::TestCase
# test "the truth" do
# assert true
# end
end

View file

@ -0,0 +1,7 @@
require 'test_helper'
class ItemitemsControllerTest < ActionController::TestCase
# test "the truth" do
# assert true
# end
end

View file

@ -0,0 +1,7 @@
require 'test_helper'
class PersonitemsControllerTest < ActionController::TestCase
# test "the truth" do
# assert true
# end
end

View file

@ -0,0 +1,4 @@
require 'test_helper'
class GroupgroupsHelperTest < ActionView::TestCase
end

View file

@ -0,0 +1,4 @@
require 'test_helper'
class GroupitemsHelperTest < ActionView::TestCase
end

View file

@ -0,0 +1,4 @@
require 'test_helper'
class GrouppeopleHelperTest < ActionView::TestCase
end

View file

@ -0,0 +1,4 @@
require 'test_helper'
class ItemitemsHelperTest < ActionView::TestCase
end

View file

@ -0,0 +1,4 @@
require 'test_helper'
class PersonitemsHelperTest < ActionView::TestCase
end