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

UI for setting the reason why SHF is waiting on an applicant #281

Closed
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
31414af
update ruby_version -> 2.4.0
weedySeaDragon Jun 16, 2017
c823e06
Merge branch 'develop' into sprint16-#143810729-UI-custom-reason-waiting
weedySeaDragon Jun 19, 2017
44867ed
add attributes to MembershipApplication: waiting_reason & custom_reas…
weedySeaDragon Jun 21, 2017
f06224f
seed MemberAppWaitingReason with the "Other/Custom" reason (text from…
weedySeaDragon Jun 21, 2017
1d3a786
pass locale to other_reason_name/_desc to make seeding easier
weedySeaDragon Jun 21, 2017
ebb0f4f
features & specs for setting reasons for waiting
weedySeaDragon Jun 21, 2017
0a5dd0d
remove assertion no longer used (removed the 'submit/save' button)
weedySeaDragon Jun 21, 2017
4f48f4c
helpers: return the correct method to call based on the current local
weedySeaDragon Jun 21, 2017
441df21
add allowed attributes to Pundit policy
weedySeaDragon Jun 21, 2017
4a3ce00
refactor reasons_waiting into a parital; move to above the 'status' b…
weedySeaDragon Jun 21, 2017
aaa6ace
respond to a .js request for the reason waiting
weedySeaDragon Jun 21, 2017
10ec808
I18n locale entries needed
weedySeaDragon Jun 21, 2017
e8cc76d
if Seeding tests are run prior to this spec, ensure the table is clea…
weedySeaDragon Jun 21, 2017
b848df6
CSS styling
weedySeaDragon Jun 21, 2017
4f75ecc
Merge branch 'develop' into sprint16-#143810729-UI-custom-reason-waiting
weedySeaDragon Jun 21, 2017
a041ef3
fix: seed the EN name of the 'other reason' (should have passed in :e…
weedySeaDragon Jun 21, 2017
a44214b
need to get the current text for the 'other reason' if the locale has…
weedySeaDragon Jun 21, 2017
b776f70
Merge branch 'develop' into sprint16-#143810729-UI-custom-reason-waiting
weedySeaDragon Jun 21, 2017
73afa63
clean up per HoundCI suggestions
weedySeaDragon Jun 21, 2017
df94ef9
DRY error situations
weedySeaDragon Jun 21, 2017
ba9fc60
features: other/custom reason comes from the locale file, is not a mo…
weedySeaDragon Jun 22, 2017
9b798c7
do not seed the 'custom/other' reason; it's not stored in the db
weedySeaDragon Jun 22, 2017
c1fbde8
add set: select an item without any I18n
weedySeaDragon Jun 23, 2017
bf2b195
CSS styling
weedySeaDragon Jun 23, 2017
5bf594e
return "OK" if update successful; set the text for the "other/custom.…
weedySeaDragon Jun 23, 2017
e70d877
no .js is needed to return if action was successful
weedySeaDragon Jun 23, 2017
eb3b970
other_reason placeholder stuff no longer needed in Model; remove spec…
weedySeaDragon Jun 23, 2017
608d0a7
all logic for "enter custom reason.." into this javascript
weedySeaDragon Jun 23, 2017
2c3c0ed
Merge branch 'develop' into sprint16-#143810729-UI-custom-reason-waiting
weedySeaDragon Jun 23, 2017
a73f2af
interim progress (Pat)
patmbolger Jun 24, 2017
001a5d7
refactored some JS
patmbolger Jun 24, 2017
871fd64
changed feature steps in accordance with id changes in view (Pat)
patmbolger Jun 24, 2017
4fdf5f5
removed selenium webdriver from Gemfile (Pat)
patmbolger Jun 24, 2017
cf0645a
fixed a couple cuke steps (Pat)
patmbolger Jun 24, 2017
05fd86d
fixed remaining cuke tests (Pat)
patmbolger Jun 25, 2017
c0d90a8
changes to CSS per houndci
weedySeaDragon Jun 26, 2017
6d3b704
POLTERGEIST fix: do not use "let" (use var instead)
weedySeaDragon Jun 26, 2017
e5cbbaf
remove selenium (no longer needed)
weedySeaDragon Jun 26, 2017
75a36d6
update gemfile.lock
weedySeaDragon Jun 26, 2017
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
26 changes: 23 additions & 3 deletions app/assets/stylesheets/member-app-waiting-reason.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
.member_app_waiting_reasons {
#member-app-waiting-reasons {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using id selectors

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using id selectors


input.wpcf7-form-control.is-custom {
width: 3rem;
margin-bottom: 1rem;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Properties should be ordered border-bottom, margin-bottom

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Properties should be ordered border-bottom, margin-bottom

.row {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rule declaration should be preceded by an empty line

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rule declaration should be preceded by an empty line

margin-top: 0;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Properties should be ordered margin-bottom, margin-top, padding-bottom, padding-top

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Properties should be ordered margin-bottom, margin-top, padding-bottom, padding-top

margin-bottom: 0;
padding-top: 0.5rem;
padding-bottom: 0.5rem;
}

border-bottom: 1pt solid coral;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected item on line 11 to appear before line 4. Rule sets should be ordered as follows: @extends, @includes without @content, properties, @includes with @content, nested rule sets
Color coral should be written in hexadecimal form as #ff7f50
Color literals like coral should only be used in variable declarations; they should be referred to via variable everywhere else.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected item on line 11 to appear before line 4. Rule sets should be ordered as follows: @extends, @includes without @content, properties, @includes with @content, nested rule sets
Color coral should be written in hexadecimal form as #ff7f50
Color literals like coral should only be used in variable declarations; they should be referred to via variable everywhere else.



select {
height: 110%;
}

label {
font-weight: normal;
}

input[type="text"] {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid qualifying attribute selectors with an element.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid qualifying attribute selectors with an element.

padding: 0.3rem;
width: 35rem;
}

}
66 changes: 52 additions & 14 deletions app/controllers/membership_applications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ class MembershipApplicationsController < ApplicationController

before_action :get_membership_application, except: [:information, :index, :new, :create]
before_action :authorize_membership_application, only: [:update, :show, :edit]
before_action :set_other_waiting_reason, only: [:show, :edit, :update]


def new
Expand All @@ -16,7 +17,7 @@ def index
authorize MembershipApplication

action_params, @items_count, items_per_page =
process_pagination_params('membership_application')
process_pagination_params('membership_application')

@search_params = MembershipApplication.ransack(action_params)

Expand Down Expand Up @@ -47,15 +48,11 @@ def create
helpers.flash_message(:notice, t('.success'))
redirect_to root_path
else
helpers.flash_message(:alert, t('.error'))
current_user.membership_applications.reload
render :new
create_error(t('.error'))
end

else
helpers.flash_message(:alert, t('.error'))
current_user.membership_applications.reload
render :new
create_error(t('.error'))
end
end

Expand All @@ -67,18 +64,26 @@ def update

check_and_mark_if_ready_for_review params['membership_application'] if params.fetch('membership_application', false)

helpers.flash_message(:notice, t('.success'))
render :show
respond_to do |format|
format.js do
head :ok # just let the receiver know everything is OK. no need to render anything
end

format.html do
helpers.flash_message(:notice, t('.success'))
render :show
end

end

else
helpers.flash_message(:alert, t('.error'))
redirect_to edit_membership_application_path(@membership_application)
update_error(t('.error'))
end

else
helpers.flash_message(:alert, t('.error'))
redirect_to edit_membership_application_path(@membership_application)
update_error(t('.error'))
end

end


Expand All @@ -95,7 +100,7 @@ def information


def destroy
@membership_application = MembershipApplication.find(params[:id]) # we don't need to fetch the categories
@membership_application = MembershipApplication.find(params[:id]) # we don't need to fetch the categories
@membership_application.destroy
redirect_to membership_applications_url, notice: t('membership_applications.application_deleted')
end
Expand Down Expand Up @@ -132,21 +137,30 @@ def need_info


def cancel_need_info

# empty out the reason for waiting info
@membership_application.waiting_reason = nil
@membership_application.custom_reason_text = nil

simple_state_change(:cancel_waiting_for_applicant!, t('.success'), t('.error'))
end


def need_payment
simple_state_change(:ask_for_payment!, t('.success'), t('.error'))
end


def cancel_need_payment
simple_state_change(:cancel_waiting_for_payment!, t('.success'), t('.error'))
end


def received_payment
simple_state_change(:received_payment!, t('.success'), t('.error'))
end


private
def membership_application_params
params.require(:membership_application).permit(*policy(@membership_application || MembershipApplication).permitted_attributes)
Expand All @@ -164,6 +178,11 @@ def authorize_membership_application
end


def set_other_waiting_reason
@other_waiting_reason_text = t('admin_only.member_app_waiting_reasons.other_custom_reason')
end


def new_file_uploaded(params)

successful = true
Expand Down Expand Up @@ -205,4 +224,23 @@ def simple_state_change(state_method, success_msg, error_msg)
end


def create_error(error_message)
helpers.flash_message(:alert, error_message)
current_user.membership_applications.reload
render :new
end


def update_error(error_message)

if request.xhr?
render json: @membership_application.errors.full_messages, status: :unprocessable_entity if request.xhr?
else
helpers.flash_message(:alert, error_message)
redirect_to edit_membership_application_path(@membership_application)
end

end


end
46 changes: 46 additions & 0 deletions app/helpers/membership_applications_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,54 @@ def can_edit_state?
policy(@membership_application).permitted_attributes_for_edit.include? :state
end


def member_full_name
@membership_application ? "#{@membership_application.first_name} #{@membership_application.last_name}" : '..'

end


# the method to use to get the name for a reason, given the locale
# If no locale is given, the current locale is used.
# If the locale given isn't found or defined, the default name method is used
def reason_name_method(locale = I18n.locale)
reason_method 'name', locale
end


# the method to use to get the description for a reason, given the locale
# If no locale is given, the current locale is used.
# If the locale given isn't found or defined, the default name method is used
def reason_desc_method(locale = I18n.locale)
reason_method 'description', locale
end


# a collection of arrays with [the name of the reasons for waiting, the reason (object)]
# in the locale
def reasons_for_waiting_names(use_locale = I18n.locale)
reasons_for_waiting_info('name', use_locale)
end


# a collection of arrays with [the descriptions of the reasons for waiting, the reason (object)]
# in the locale
def reasons_for_waiting_descs(use_locale = I18n.locale)
reasons_for_waiting_info('description', use_locale)
end


private

def reason_method(method_prefix, locale)
possible_method = "#{method_prefix}_#{locale}".to_sym
(AdminOnly::MemberAppWaitingReason.new.respond_to?(possible_method) ? possible_method : AdminOnly::MemberAppWaitingReason.send("default_#{method_prefix}_method".to_sym))
end


def reasons_for_waiting_info(method_prefix, locale)
method_name = reason_method(method_prefix, locale)
AdminOnly::MemberAppWaitingReason.all.map { |r| [r.id, r.send(method_name)] }
end

end
14 changes: 12 additions & 2 deletions app/models/admin_only/member_app_waiting_reason.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,25 @@ def other_reason_placeholder?


# This is effectively a CONSTANT that is used in the UI
def self.other_reason_name
I18n.t('admin_only.member_app_waiting_reasons.other_custom_reason')
def self.other_reason_name(locale = I18n.locale)
I18n.t('admin_only.member_app_waiting_reasons.other_custom_reason', locale)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second parameter to the translate method should be an options hash. As it stands now the locale is ignored, and the method always returns the swedish translation

I18n.t('admin_only.member_app_waiting_reasons.other_custom_reason', locale: locale)

end


def self.other_reason_desc(locale = I18n.locale)
I18n.t('admin_only.member_app_waiting_reasons.other_custom_reason_desc', locale)
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.




def self.default_name_method
:name_sv
end

def self.default_description_method
:description_sv
end

end

end
Expand Down
5 changes: 5 additions & 0 deletions app/models/membership_application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ class MembershipApplication < ApplicationRecord
has_and_belongs_to_many :business_categories
has_many :uploaded_files

belongs_to :waiting_reason, optional: true,
foreign_key: "member_app_waiting_reasons_id",
class_name: 'AdminOnly::MemberAppWaitingReason'


validates_presence_of :first_name,
:last_name,
:company_number,
Expand Down
4 changes: 2 additions & 2 deletions app/policies/membership_application_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def user_owner_attributes


def all_attributes
owner_attributes + [:membership_number]
owner_attributes + [:membership_number, :waiting_reason, :custom_reason_text, :member_app_waiting_reasons_id]
end


Expand All @@ -121,4 +121,4 @@ def owner?
user && @record.respond_to?(:user) && @record.user == user
end

end
end
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
- if @membership_application.waiting_for_applicant?
= render 'reason_waiting'



#admin-change-status-buttons
%p.header
= "#{t('membership_applications.show.change_status')}:"


= button_to t('membership_applications.start_review_btn'), start_review_membership_application_path(@membership_application), {class: 'btn start-review', disabled: !(@membership_application.may_start_review?)}
.row
= button_to t('membership_applications.start_review_btn'), start_review_membership_application_path(@membership_application), {class: 'btn start-review', disabled: !(@membership_application.may_start_review?)}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using instance variables in partials views


= button_to t('membership_applications.accept_btn'), accept_membership_application_path(@membership_application), {class: 'btn accept', disabled: !(@membership_application.may_accept?)}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using instance variables in partials views


= button_to t('membership_applications.accept_btn'), accept_membership_application_path(@membership_application), {class: 'btn accept', disabled: !(@membership_application.may_accept?)}
= button_to t('membership_applications.reject_btn'), reject_membership_application_path(@membership_application), {class: 'btn reject', disabled: !(@membership_application.may_reject?)}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using instance variables in partials views


= button_to t('membership_applications.reject_btn'), reject_membership_application_path(@membership_application), {class: 'btn reject', disabled: !(@membership_application.may_reject?)}
= button_to t('membership_applications.ask_applicant_for_info_btn'), need_info_membership_application_path(@membership_application), {class: 'btn need-info', disabled: !(@membership_application.may_ask_applicant_for_info?)}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using instance variables in partials views


= button_to t('membership_applications.ask_applicant_for_info_btn'), need_info_membership_application_path(@membership_application), {class: 'btn need-info', disabled: !(@membership_application.may_ask_applicant_for_info?)}
.row
= button_to t('membership_applications.cancel_waiting_for_applicant_btn'), cancel_need_info_membership_application_path(@membership_application), {class: 'btn cancel-need-info', disabled: !(@membership_application.may_cancel_waiting_for_applicant?)}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using instance variables in partials views


= button_to t('membership_applications.cancel_waiting_for_applicant_btn'), cancel_need_info_membership_application_path(@membership_application), {class: 'btn cancel-need-info', disabled: !(@membership_application.may_cancel_waiting_for_applicant?)}
= button_to t('membership_applications.ask_applicant_for_payment_btn'), need_payment_membership_application_path(@membership_application), {class: 'btn need-payment', disabled: !(@membership_application.may_ask_for_payment?)}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using instance variables in partials views


= button_to t('membership_applications.ask_applicant_for_payment_btn'), need_payment_membership_application_path(@membership_application), {class: 'btn need-payment', disabled: !(@membership_application.may_ask_for_payment?)}
= button_to t('membership_applications.cancel_waiting_for_payment_btn'), cancel_need_payment_membership_application_path(@membership_application), {class: 'btn cancel_need-payment', disabled: !(@membership_application.may_cancel_waiting_for_payment?)}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using instance variables in partials views


= button_to t('membership_applications.cancel_waiting_for_payment_btn'), cancel_need_payment_membership_application_path(@membership_application), {class: 'btn cancel_need-payment', disabled: !(@membership_application.may_cancel_waiting_for_payment?)}
= button_to t('membership_applications.received_payment_btn'), received_payment_membership_application_path(@membership_application), {class: 'btn received-payment', disabled: !(@membership_application.may_received_payment?)}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using instance variables in partials views


= button_to t('membership_applications.received_payment_btn'), received_payment_membership_application_path(@membership_application), {class: 'btn received-payment', disabled: !(@membership_application.may_received_payment?)}

%br
- if !@membership_application.paid?
Expand Down
Loading