Skip to content

Admin: use select2 #617

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 4 commits into from
Apr 19, 2021
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
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ gem 'rails', '~> 6.1.1'
gem 'rails-i18n', '~> 6.0.0'
gem 'rdiscount', '~> 2.2.0.1'
gem 'activeadmin', '~> 2.9.0'
gem 'bootsnap', '~> 1.7.3', require: false
gem 'has_scope', '~> 0.7.2'
gem 'pundit', '~> 2.1.0'
gem 'pg', '~> 1.2.1'
Expand Down
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ GEM
execjs
bcrypt (3.1.16)
bindex (0.8.1)
bootsnap (1.7.3)
msgpack (~> 1.0)
bootstrap-sass (3.4.1)
autoprefixer-rails (>= 5.2.1)
sassc (>= 2.0.0)
Expand Down Expand Up @@ -204,6 +206,7 @@ GEM
mini_mime (1.0.2)
mini_portile2 (2.5.0)
minitest (5.14.4)
msgpack (1.4.2)
net-scp (3.0.0)
net-ssh (>= 2.6.5, < 7.0.0)
net-ssh (6.1.0)
Expand Down Expand Up @@ -406,6 +409,7 @@ PLATFORMS

DEPENDENCIES
activeadmin (~> 2.9.0)
bootsnap (~> 1.7.3)
bootstrap-sass (~> 3.4)
byebug (~> 11.0)
capistrano (~> 3.1)
Expand Down
2 changes: 1 addition & 1 deletion app/admin/post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
form do |f|
f.semantic_errors *f.object.errors.keys
f.inputs do
f.input :type, as: :select, collection: %w[Offer Inquiry]
f.input :type, as: :radio, collection: %w[Offer Inquiry]
f.input :title
f.input :organization
f.input :user, hint: "* should be member of the selected organization"
Expand Down
5 changes: 5 additions & 0 deletions app/assets/javascripts/active_admin.js
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
//= require active_admin/base
//= require select2

$(function() {
$("select").select2();
});
1 change: 1 addition & 0 deletions app/assets/stylesheets/active_admin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ $table-stripe-color: #f5f5f5;

@import "active_admin/mixins";
@import "active_admin/base";
@import "select2";
8 changes: 2 additions & 6 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
/*
*= require select2
*/

@import "select2";
@import "application/variables";
@import "bootstrap-sprockets";
@import "application/bootstrap-custom";
@import "application/to-categories-dropdown";
@import "application/to-member-card";
@import "application/member-card";
@import "application/footer";

html {
Expand Down

This file was deleted.

2 changes: 0 additions & 2 deletions app/controllers/offers_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Managems of offer-type posts
#
class OffersController < PostsController
def model
Offer
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/transfers_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ def accounts_from_movements(transfer, with_links: false)
account = movement.account

if account.accountable.blank?
I18n.t('.deleted_user')
I18n.t('users.show.deleted_user')
elsif account.accountable_type == 'Organization'
link_to_if(with_links, account, organization_path(account.accountable))
elsif account.accountable.active
link_to_if(with_links, account.accountable.display_name_with_uid, user_path(account.accountable.user))
else
I18n.t('.inactive_user')
I18n.t('users.show.inactive_user')
end
end
end
Expand Down
4 changes: 1 addition & 3 deletions app/models/member.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ class Member < ApplicationRecord
delegate :balance, to: :account, prefix: true, allow_nil: true
delegate :gender, :date_of_birth, to: :user, prefix: true, allow_nil: true

scope :by_month, -> (month) {
where(created_at: month.beginning_of_month..month.end_of_month)
}
scope :by_month, -> (month) { where(created_at: month.beginning_of_month..month.end_of_month) }
scope :active, -> { where active: true }

validates :organization_id, presence: true
Expand Down
13 changes: 5 additions & 8 deletions app/models/movement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,16 @@ class Movement < ApplicationRecord

belongs_to :account, optional: true
belongs_to :transfer, optional: true
has_one :other_side,
(->(self_) { where ["NOT movements.id = #{self_.id}"] }),
through: :transfer,
source: :movements

scope :by_month,
->(month) {
where(created_at: month.beginning_of_month..month.end_of_month)
}
scope :by_month, -> (month) { where(created_at: month.beginning_of_month..month.end_of_month) }

validates :amount, numericality: { other_than: 0 }

after_create do
account.update_balance
end

def other_side
transfer.movements.where.not(id: id).first
end
end
4 changes: 2 additions & 2 deletions app/views/shared/_movements.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
<%= link_to account.accountable.display_name_with_uid,
user_path(account.accountable.user) %>
<% else %>
<%= t(".inactive_user") %>
<%= t("users.show.inactive_user") %>
<% end %>
<% else %>
<%= t(".deleted_user") %>
<%= t("users.show.deleted_user") %>
<% end %>
<% end %>
</td>
Expand Down
2 changes: 1 addition & 1 deletion app/views/shared/_post_filters.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</button>
</form>

<ul class="to-categories-dropdown nav navbar-nav">
<ul class="nav navbar-nav hidden-xs">
<li class="dropdown">
<a class="dropdown-toggle" href="#" data-toggle="dropdown">
<%= @category ? @category.name : Category.model_name.human %>
Expand Down
1 change: 1 addition & 0 deletions config/boot.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)

require 'bundler/setup' # Set up gems listed in the Gemfile.
require 'bootsnap/setup' # Speed up boot time by caching expensive operations.
4 changes: 1 addition & 3 deletions config/locales/eu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,7 @@ eu:
unlocked: Zure kontua desblokeatua izan da. Sartu jarraitzeko.
errors:
internal_server_error:
description: |-
Sentitzen dugu, kontsulta honetan oker bat dagoela dirudi. Mezu bat bidali dugu teknikarien sailera eta ahal bezain laister konpontzen saiatuko gara.
.
description: Sentitzen dugu, kontsulta honetan oker bat dagoela dirudi. Mezu bat bidali dugu teknikarien sailera eta ahal bezain laister konpontzen saiatuko gara.
title: Zerbitzariaren barne akatsa
messages:
already_confirmed: Baieztatu da. Saia zaitez sartzen.
Expand Down
12 changes: 12 additions & 0 deletions spec/models/movement_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
RSpec.describe Movement do
let(:transfer) { Fabricate(:transfer) }

it "#other_side returns the other movement from same transfer" do
mov = transfer.movements.first
mov_other_side = mov.other_side

expect(mov_other_side).not_to eq(mov)
expect(mov_other_side.amount).to eq(-mov.amount)
expect(mov_other_side.transfer).to eq(mov.transfer)
end
end