forked from OpenNeo/impress
set list visibility in closet_lists#edit
This commit is contained in:
parent
ad45d755da
commit
0c92bf5987
10 changed files with 41 additions and 10 deletions
|
@ -17,8 +17,16 @@ class ClosetHangersController < ApplicationController
|
||||||
@public_perspective = params.has_key?(:public) || !user_is?(@user)
|
@public_perspective = params.has_key?(:public) || !user_is?(@user)
|
||||||
@perspective_user = current_user unless @public_perspective
|
@perspective_user = current_user unless @public_perspective
|
||||||
|
|
||||||
@closet_lists_by_owned = @user.closet_lists.alphabetical.
|
@closet_lists_by_owned = @user.closet_lists.
|
||||||
includes(:hangers => :item).group_by(&:hangers_owned)
|
alphabetical.includes(:hangers => :item)
|
||||||
|
unless @perspective_user == @user
|
||||||
|
# If we run this when the user matches, we'll end up with effectively:
|
||||||
|
# WHERE belongs_to_user AND (is_public OR belongs_to_user)
|
||||||
|
# and it's a bit silly to put the SQL server through a condition that's
|
||||||
|
# always true.
|
||||||
|
@closet_lists_by_owned = @closet_lists_by_owned.visible_to(@perspective_user)
|
||||||
|
end
|
||||||
|
@closet_lists_by_owned = @closet_lists_by_owned.group_by(&:hangers_owned)
|
||||||
|
|
||||||
visible_groups = @user.closet_hangers_groups_visible_to(@perspective_user)
|
visible_groups = @user.closet_hangers_groups_visible_to(@perspective_user)
|
||||||
unless visible_groups.empty?
|
unless visible_groups.empty?
|
||||||
|
|
|
@ -17,9 +17,9 @@ module ClosetHangersHelper
|
||||||
owned ? :owned_closet_hangers_visibility : :wanted_closet_hangers_visibility
|
owned ? :owned_closet_hangers_visibility : :wanted_closet_hangers_visibility
|
||||||
end
|
end
|
||||||
|
|
||||||
def hangers_group_visibility_choices(owned)
|
def closet_visibility_choices(*args)
|
||||||
ClosetVisibility.levels.map do |level|
|
ClosetVisibility.levels.map do |level|
|
||||||
[level.name.to_s.humanize, level.id]
|
[level.send(*args), level.id]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -3,13 +3,18 @@ class ClosetList < ActiveRecord::Base
|
||||||
has_many :hangers, :class_name => 'ClosetHanger', :foreign_key => 'list_id',
|
has_many :hangers, :class_name => 'ClosetHanger', :foreign_key => 'list_id',
|
||||||
:dependent => :nullify
|
:dependent => :nullify
|
||||||
|
|
||||||
attr_accessible :description, :hangers_owned, :name
|
attr_accessible :description, :hangers_owned, :name, :visibility
|
||||||
|
|
||||||
validates :name, :presence => true, :uniqueness => {:scope => :user_id}
|
validates :name, :presence => true, :uniqueness => {:scope => :user_id}
|
||||||
validates :user, :presence => true
|
validates :user, :presence => true
|
||||||
validates :hangers_owned, :inclusion => {:in => [true, false], :message => "can't be blank"}
|
validates :hangers_owned, :inclusion => {:in => [true, false], :message => "can't be blank"}
|
||||||
|
|
||||||
scope :alphabetical, order(:name)
|
scope :alphabetical, order(:name)
|
||||||
|
scope :visible_to, lambda { |user|
|
||||||
|
condition = arel_table[:visibility].gteq(ClosetVisibility[:public].id)
|
||||||
|
condition = condition.or(arel_table[:user_id].eq(user.id)) if user
|
||||||
|
where(condition)
|
||||||
|
}
|
||||||
|
|
||||||
after_save :sync_hangers_owned!
|
after_save :sync_hangers_owned!
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,10 @@ module ClosetVisibility
|
||||||
@description
|
@description
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def human_name
|
||||||
|
name.to_s.humanize
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
LEVELS = [
|
LEVELS = [
|
||||||
|
|
|
@ -12,7 +12,7 @@ body.closet_lists-new, body.closet_lists-create, body.closet_lists-edit, body.cl
|
||||||
|
|
||||||
li
|
li
|
||||||
padding: 0.75em 0
|
padding: 0.75em 0
|
||||||
width: 25em
|
width: 35em
|
||||||
|
|
||||||
input, textarea, select
|
input, textarea, select
|
||||||
clear: both
|
clear: both
|
||||||
|
|
|
@ -72,7 +72,7 @@
|
||||||
- unless public_perspective?
|
- unless public_perspective?
|
||||||
= form_for @user, :html => {:class => 'visibility-form'} do |f|
|
= form_for @user, :html => {:class => 'visibility-form'} do |f|
|
||||||
= f.select hangers_group_visibility_field_name(owned),
|
= f.select hangers_group_visibility_field_name(owned),
|
||||||
hangers_group_visibility_choices(owned)
|
closet_visibility_choices(:human_name)
|
||||||
= f.submit "Save"
|
= f.submit "Save"
|
||||||
= closet_visibility_descriptions
|
= closet_visibility_descriptions
|
||||||
- if has_lists?(owned)
|
- if has_lists?(owned)
|
||||||
|
|
|
@ -10,6 +10,9 @@
|
||||||
%li
|
%li
|
||||||
= f.label :hangers_owned, 'This is a list for…'.html_safe
|
= f.label :hangers_owned, 'This is a list for…'.html_safe
|
||||||
= f.select :hangers_owned, hangers_owned_options
|
= f.select :hangers_owned, hangers_owned_options
|
||||||
|
%li
|
||||||
|
= f.label :visibility, 'Who can see this list?'
|
||||||
|
= f.select :visibility, closet_visibility_choices(:description, 'Items in this list')
|
||||||
%li
|
%li
|
||||||
= f.label :description
|
= f.label :description
|
||||||
%span.hint
|
%span.hint
|
||||||
|
|
10
db/migrate/20110731021808_add_visibility_to_closet_lists.rb
Normal file
10
db/migrate/20110731021808_add_visibility_to_closet_lists.rb
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
class AddVisibilityToClosetLists < ActiveRecord::Migration
|
||||||
|
def self.up
|
||||||
|
add_column :closet_lists, :visibility, :integer, :null => false, :default => 1
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.down
|
||||||
|
remove_column :closet_lists, :visibility
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended to check this file into your version control system.
|
# It's strongly recommended to check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(:version => 20110730174148) do
|
ActiveRecord::Schema.define(:version => 20110731021808) do
|
||||||
|
|
||||||
create_table "auth_servers", :force => true do |t|
|
create_table "auth_servers", :force => true do |t|
|
||||||
t.string "short_name", :limit => 10, :null => false
|
t.string "short_name", :limit => 10, :null => false
|
||||||
|
@ -37,6 +37,7 @@ ActiveRecord::Schema.define(:version => 20110730174148) do
|
||||||
t.boolean "hangers_owned", :null => false
|
t.boolean "hangers_owned", :null => false
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
|
t.integer "visibility", :default => 1, :null => false
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "contributions", :force => true do |t|
|
create_table "contributions", :force => true do |t|
|
||||||
|
|
|
@ -1180,7 +1180,7 @@ body.closet_lists-new form ul.fields label, body.closet_lists-create form ul.fie
|
||||||
/* line 13, ../../../app/stylesheets/closet_lists/_form.sass */
|
/* line 13, ../../../app/stylesheets/closet_lists/_form.sass */
|
||||||
body.closet_lists-new form ul.fields li, body.closet_lists-create form ul.fields li, body.closet_lists-edit form ul.fields li, body.closet_lists-update form ul.fields li {
|
body.closet_lists-new form ul.fields li, body.closet_lists-create form ul.fields li, body.closet_lists-edit form ul.fields li, body.closet_lists-update form ul.fields li {
|
||||||
padding: 0.75em 0;
|
padding: 0.75em 0;
|
||||||
width: 25em;
|
width: 35em;
|
||||||
}
|
}
|
||||||
/* line 17, ../../../app/stylesheets/closet_lists/_form.sass */
|
/* line 17, ../../../app/stylesheets/closet_lists/_form.sass */
|
||||||
body.closet_lists-new form ul.fields input, body.closet_lists-new form ul.fields textarea, body.closet_lists-new form ul.fields select, body.closet_lists-create form ul.fields input, body.closet_lists-create form ul.fields textarea, body.closet_lists-create form ul.fields select, body.closet_lists-edit form ul.fields input, body.closet_lists-edit form ul.fields textarea, body.closet_lists-edit form ul.fields select, body.closet_lists-update form ul.fields input, body.closet_lists-update form ul.fields textarea, body.closet_lists-update form ul.fields select {
|
body.closet_lists-new form ul.fields input, body.closet_lists-new form ul.fields textarea, body.closet_lists-new form ul.fields select, body.closet_lists-create form ul.fields input, body.closet_lists-create form ul.fields textarea, body.closet_lists-create form ul.fields select, body.closet_lists-edit form ul.fields input, body.closet_lists-edit form ul.fields textarea, body.closet_lists-edit form ul.fields select, body.closet_lists-update form ul.fields input, body.closet_lists-update form ul.fields textarea, body.closet_lists-update form ul.fields select {
|
||||||
|
|
Loading…
Reference in a new issue