Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add group member count to item permission dropdown #334

Draft
wants to merge 15 commits into
base: dev
Choose a base branch
from
9 changes: 5 additions & 4 deletions app/controllers/groups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ def index
end

def all
personal_groups = Group.where(tag: :personal_group)
everyone_group = Group.where(tag: :everyone_group)
generic_groups = Group.where(tag: nil)

respond_to do |format|
format.json { render json: Group.all - personal_groups }
end
returned_groups = everyone_group + generic_groups

render json: returned_groups
end

# GET /groups/1/edit
Expand Down
14 changes: 14 additions & 0 deletions app/models/group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,18 @@ def self.owner_groups(item_id)
WHERE id IN (SELECT group_id FROM permissions WHERE item_id = :item_id AND permission_type = :permission_type)",
{ item_id: item_id, permission_type: "2" }]
end

def user_count
users.length
end

def user_count_string
"#{user_count} #{I18n.t('group_member', count: user_count)}"
end

def as_json(options)
super(options.merge({
methods: [:user_count, :user_count_string]
}))
end
end
2 changes: 1 addition & 1 deletion app/views/items/_item_type_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<div class="row mt-2" v-for="(permission, i) in permissions">
<div class="col">
<select :name="`permission_${i}_group_id`" :id="`permission_select_${i}_group_id`" class="form-select" required v-model="permission.groupId">
<option :value="group.id" v-for="group in groups">{{group.name}}</option>
<option :value="group.id" v-for="group in groups">{{group.name}} ({{ group.user_count_string }})</option>
</select>
</div>
<div class="col">
Expand Down
8 changes: 8 additions & 0 deletions spec/views/items/edit.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@
end
end

it "contains a member counter" do
item = FactoryBot.create(:other)
assign(:item, item)
render

expect(response).to have_text("'member' : 'members'")
end

[:book, :movie, :game, :other].each do |item_type|
it "renders correct attributes for item type #{item_type}" do
item = FactoryBot.create(item_type)
Expand Down