Skip to content

Fix sign up locale 🌐 + some admin improvements 💅 #682

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

Merged
merged 8 commits into from
Apr 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions app/admin/category.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
index do
id_column
column :name do |category|
"#{tag.span(nil, class: "glyphicon glyphicon-#{category.icon_name}")} #{category.name}".html_safe
"#{category_icon(category)} #{category.name}".html_safe
end
actions
end
Expand All @@ -17,9 +17,12 @@

show do |cat|
attributes_table do
row :name do
"#{category_icon(cat)} #{cat.name}".html_safe
end
row :icon_name
row :created_at
row :updated_at
row :icon_name
row :name_translations do
render_translations(cat.name_translations)
end
Expand Down
10 changes: 10 additions & 0 deletions app/admin/dashboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@
end
end
end

column do
panel "Recent Petitions" do
ul do
Petition.last(5).map do |petition|
li "#{petition.user} #{glyph(:arrow_right)} #{petition.organization}".html_safe
end
end
end
end
end
end
end
2 changes: 1 addition & 1 deletion app/admin/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
render_translations(t.title_translations)
end
row :content_translations do
render_translations(t.content_translations, "<br>")
render_translations(t.content_translations, "<hr>")
end
end
end
Expand Down
28 changes: 26 additions & 2 deletions app/admin/organization.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,40 @@
ActiveAdmin.register Organization do
index do
id_column
column :name
column :name do |organization|
output = tag.p organization.name

if organization.logo.attached?
output << image_tag(organization.logo.variant(resize: "40^x"))
end

output.html_safe
end
column :created_at do |organization|
l organization.created_at.to_date, format: :long
end
column :city
column :neighborhood
column :email
column :phone
column :members do |organization|
organization.members.count
end
column :posts do |organization|
organization.posts.count
end
actions
end

show do
div do
if organization.logo.attached?
image_tag(organization.logo.variant(resize: "100^x"))
end
end
default_main_content
end

form do |f|
f.inputs do
f.input :name
Expand All @@ -23,6 +46,7 @@
f.input :address
f.input :description
f.input :public_opening_times
f.input :logo, as: :file
end
f.actions
end
Expand All @@ -47,5 +71,5 @@ def destroy
filter :neighborhood

permit_params :name, :email, :web, :phone, :city, :neighborhood,
:address, :description, :public_opening_times
:address, :description, :public_opening_times, :logo
end
4 changes: 3 additions & 1 deletion app/admin/petition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
column :user
column :organization
column :created_at
column :status
column :status do |petition|
petition.status.upcase
end
end

filter :status, as: :select, collection: -> { Petition.statuses }
Expand Down
9 changes: 7 additions & 2 deletions app/admin/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
column :organizations do |u|
u.organizations.map(&:to_s).join(", ")
end
column :posts do |u|
u.posts.count
end
actions
end

Expand All @@ -31,6 +34,7 @@
filter :username
filter :phone
filter :postcode
filter :locale

form do |f|
f.semantic_errors *f.object.errors.keys
Expand All @@ -40,9 +44,10 @@
f.input :phone
f.input :postcode
f.input :gender, as: :select, collection: User::GENDERS
f.input :locale, as: :select, collection: I18n.available_locales
end
f.inputs "Memberships" do
f.has_many :members do |m|
f.has_many :members, allow_destroy: true do |m|
m.input :organization, collection: Organization.order(id: :asc).pluck(:name, :id)
m.input :active
m.input :manager
Expand Down Expand Up @@ -79,5 +84,5 @@
end

permit_params :username, :email, :phone, :postcode, :gender,
members_attributes: [:organization_id, :active, :manager]
members_attributes: [:id, :organization_id, :active, :manager, :_destroy]
end
2 changes: 1 addition & 1 deletion app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ label[required]::after{
}

.organization-logo {
padding-top: 100px;
padding-top: 80px;

img {
display: block;
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ def scoped_users
end

def user_params
fields_to_permit = %w"gender username email date_of_birth phone
alt_phone active description notifications push_notifications postcode"
fields_to_permit = %w"gender username email date_of_birth phone alt_phone active
locale description notifications push_notifications postcode"
fields_to_permit += %w"admin registration_number
registration_date" if admin?
fields_to_permit += %w"organization_id superadmin" if superadmin?
Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class User < ApplicationRecord
has_many :device_tokens
has_many :petitions, dependent: :delete_all

accepts_nested_attributes_for :members
accepts_nested_attributes_for :members, allow_destroy: true

default_scope { order("users.id ASC") }
scope :actives, -> { references(:members).where(members: { active: true }) }
Expand Down
2 changes: 2 additions & 0 deletions app/views/users/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<%= show_error_messages!(@user) %>
<%= simple_form_for @user do |f| %>
<%= f.hidden_field :locale, value: I18n.locale %>

<div class="form-inputs">
<%= f.input :username %>

Expand Down
4 changes: 2 additions & 2 deletions config/initializers/active_admin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
config.comments = false
config.namespace :admin do |admin|
admin.build_menu :utility_navigation do |menu|
menu.add label: "Languages" do |lang|
menu.add id: :languages, label: -> { "Languages (#{I18n.t("locales.#{locale}")})" } do |lang|
I18n.available_locales.each do |locale|
lang.add label: I18n.t("locales.#{locale}", locale: locale), url: ->{ url_for(locale: locale) }
end
end
admin.add_current_user_to_menu menu
admin.add_current_user_to_menu menu
admin.add_logout_button_to_menu menu
end
end
Expand Down