diff options
Diffstat (limited to 'app')
14 files changed, 233 insertions, 72 deletions
diff --git a/app/controllers/spree/admin/installments_controller.rb b/app/controllers/spree/admin/installments_controller.rb new file mode 100644 index 0000000..f499147 --- /dev/null +++ b/app/controllers/spree/admin/installments_controller.rb @@ -0,0 +1,23 @@ +module Spree + module Admin + class InstallmentsController < ResourceController + belongs_to 'subscription', model_class: SolidusSubscriptions::Subscription + + skip_before_action :load_resource, only: :index + + def index + @search = collection.ransack(params[:q]) + + @installments = @search.result(distinct: true). + page(params[:page]). + per(params[:per_page] || Spree::Config[:orders_per_page]) + end + + private + + def model_class + ::SolidusSubscriptions::Installment + end + end + end +end diff --git a/app/controllers/spree/admin/subscriptions_controller.rb b/app/controllers/spree/admin/subscriptions_controller.rb index 8462ba1..fae79aa 100644 --- a/app/controllers/spree/admin/subscriptions_controller.rb +++ b/app/controllers/spree/admin/subscriptions_controller.rb @@ -36,7 +36,7 @@ module Spree notice = @subscription.errors.full_messages.to_sentence end - redirect_to spree.admin_subscriptions_path, notice: notice + redirect_back(fallback_location: spree.admin_subscriptions_path, notice: notice) end def activate @@ -48,7 +48,7 @@ module Spree notice = @subscription.errors.full_messages.to_sentence end - redirect_to spree.admin_subscriptions_path, notice: notice + redirect_back(fallback_location: spree.admin_subscriptions_path, notice: notice) end def skip @@ -59,7 +59,7 @@ module Spree date: @subscription.actionable_date ) - redirect_to spree.admin_subscriptions_path, notice: notice + redirect_back(fallback_location: spree.admin_subscriptions_path, notice: notice) end private diff --git a/app/models/solidus_subscriptions/installment.rb b/app/models/solidus_subscriptions/installment.rb index a899cee..1cad63e 100644 --- a/app/models/solidus_subscriptions/installment.rb +++ b/app/models/solidus_subscriptions/installment.rb @@ -95,6 +95,13 @@ module SolidusSubscriptions details.where(success: true).exists? end + # Returns the state of this fulfillment + # + # @return [Symbol] :fulfilled/:unfulfilled + def state + fulfilled? ? :fulfilled : :unfulfilled + end + # Mark this installment as having a failed payment # # @param order [Spree::Order] The order generated for this processing diff --git a/app/views/spree/admin/installments/_state_pill.html.erb b/app/views/spree/admin/installments/_state_pill.html.erb new file mode 100644 index 0000000..08a86a3 --- /dev/null +++ b/app/views/spree/admin/installments/_state_pill.html.erb @@ -0,0 +1,8 @@ +<% state_class = { + fulfilled: 'active', + unfulfilled: 'error', +}[installment.state.to_sym] %> + +<span class="pill pill-<%= state_class %>"> + <%= SolidusSubscriptions::Installment.human_attribute_name("state.#{installment.state}") %> +</span> diff --git a/app/views/spree/admin/installments/index.html.erb b/app/views/spree/admin/installments/index.html.erb new file mode 100644 index 0000000..483cf4d --- /dev/null +++ b/app/views/spree/admin/installments/index.html.erb @@ -0,0 +1,36 @@ +<% content_for(:page_title, t('.title')) %> + +<%= render 'spree/admin/shared/subscription_breadcrumbs', subscription: @subscription %> +<%= render 'spree/admin/shared/subscription_sidebar', subscription: @subscription %> +<%= render 'spree/admin/shared/subscription_tabs', current: :installments, subscription: @subscription %> +<%= render 'spree/admin/shared/subscription_actions', subscription: @subscription %> + +<fieldset class="no-border-bottom"> + <legend><%= t('spree.admin.installments.index.title') %></legend> + + <%= paginate @installments, theme: 'solidus_admin' %> + + <table id="listing_installments" class="index"> + <thead> + <tr data-hook="admin_installments_index_headers"> + <th><%= sort_link(@search, :actionable_date, SolidusSubscriptions::Installment.human_attribute_name(:actionable_date)) %></th> + <th><%= sort_link(@search, :created_at, SolidusSubscriptions::Installment.human_attribute_name(:created_at)) %></th> + <th><%= SolidusSubscriptions::Installment.human_attribute_name(:fulfilled) %></th> + <th data-hook="admin_installments_index_header_actions" class="actions"></th> + </tr> + </thead> + + <tbody> + <% @installments.each do |installment| %> + <tr> + <td><%= l(installment.actionable_date.to_date) if installment.actionable_date %></td> + <td><%= l(installment.created_at.to_date) %></td> + <td><%= render 'state_pill', installment: installment %></td> + <td class="actions"></td> + </tr> + <% end %> + </tbody> + </table> + + <%= paginate @installments, theme: 'solidus_admin' %> +</fieldset> diff --git a/app/views/spree/admin/shared/_subscription_actions.html.erb b/app/views/spree/admin/shared/_subscription_actions.html.erb new file mode 100644 index 0000000..9c79258 --- /dev/null +++ b/app/views/spree/admin/shared/_subscription_actions.html.erb @@ -0,0 +1,35 @@ +<% content_for :page_actions do %> + <% if subscription.state_events.include?(:cancel) %> + <%= + link_to( + t('spree.admin.subscriptions.actions.cancel'), + spree.cancel_admin_subscription_path(subscription), + method: :delete, + data: { confirm: t('spree.admin.subscriptions.actions.cancel_alert') }, + class: 'btn btn-primary' + ) + %> + <% end %> + + <% if subscription.state_events.include?(:activate) %> + <%= + link_to( + t('spree.admin.subscriptions.actions.activate'), + spree.activate_admin_subscription_path(subscription), + method: :post, + class: 'btn btn-primary', + ) + %> + <% end %> + + <% if subscription.active? %> + <%= + link_to( + t('spree.admin.subscriptions.actions.skip'), + spree.skip_admin_subscription_path(subscription), + method: :post, + class: 'btn btn-default', + ) + %> + <% end %> +<% end %> diff --git a/app/views/spree/admin/shared/_subscription_breadcrumbs.html.erb b/app/views/spree/admin/shared/_subscription_breadcrumbs.html.erb new file mode 100644 index 0000000..6fb5f69 --- /dev/null +++ b/app/views/spree/admin/shared/_subscription_breadcrumbs.html.erb @@ -0,0 +1,4 @@ +<% admin_breadcrumb( + link_to(plural_resource_name(SolidusSubscriptions::Subscription), admin_subscriptions_path), + link_to("#{subscription.id}", edit_admin_subscription_path(subscription)) + ) %> diff --git a/app/views/spree/admin/shared/_subscription_sidebar.html.erb b/app/views/spree/admin/shared/_subscription_sidebar.html.erb new file mode 100644 index 0000000..423e7e5 --- /dev/null +++ b/app/views/spree/admin/shared/_subscription_sidebar.html.erb @@ -0,0 +1,18 @@ +<% content_for :sidebar_title do %> + <%= t("spree.admin.subscriptions.edit.sidebar") %> +<% end %> + +<% content_for :sidebar do %> + <nav class="menu"> + <fieldset class="no-border-top no-border-bottom" data-hook="admin_user_lifetime_stats"> + <dl id="user-lifetime-stats"> + <dt><%= SolidusSubscriptions::Subscription.human_attribute_name(:created_at) %>:</dt> + <dd><%= l(subscription.created_at.to_date) %></dd> + <dt><%= SolidusSubscriptions::Subscription.human_attribute_name(:state) %>:</dt> + <dd><%= render 'spree/admin/subscriptions/state_pill', subscription: subscription %></dd> + <dt><%= SolidusSubscriptions::Subscription.human_attribute_name(:processing_state) %>:</dt> + <dd><%= render 'spree/admin/subscriptions/processing_state_pill', subscription: subscription %></dd> + </dl> + </fieldset> + </nav> +<% end %> diff --git a/app/views/spree/admin/shared/_subscription_tabs.html.erb b/app/views/spree/admin/shared/_subscription_tabs.html.erb new file mode 100644 index 0000000..7c00486 --- /dev/null +++ b/app/views/spree/admin/shared/_subscription_tabs.html.erb @@ -0,0 +1,12 @@ +<% content_for :tabs do %> + <nav> + <ul class='tabs' data-hook="admin_subscription_tab_options"> + <li<%== ' class="active"' if current == :details %>> + <%= link_to t("spree.admin.subscriptions.edit.details"), spree.edit_admin_subscription_path(subscription) %> + </li> + <li<%== ' class="active"' if current == :installments %>> + <%= link_to t("spree.admin.subscriptions.edit.installments"), spree.admin_subscription_installments_path(subscription) %> + </li> + </ul> + </nav> +<% end %> diff --git a/app/views/spree/admin/subscriptions/_form.html.erb b/app/views/spree/admin/subscriptions/_form.html.erb index 80c1681..ee67d2b 100644 --- a/app/views/spree/admin/subscriptions/_form.html.erb +++ b/app/views/spree/admin/subscriptions/_form.html.erb @@ -1,88 +1,90 @@ -<fieldset data-hook="new_subscription"> - <legend><%= t('.subscription') %></legend> +<div data-hook="new_subscription"> + <fieldset class="no-border-bottom"> + <legend><%= t('.subscription') %></legend> + + <div data-hook="admin_subscription_form_fields"> + <% if f.object.new_record? %> + <div class="field"> + <%= f.label :user_id, I18n.t('spree.user'), class: "required" %> + <%= f.collection_select :user_id, Spree::User.all, :id, :email, {}, class: "select2 fullwidth" %> + </div> + <% end %> - <div data-hook="admin_subscription_form_fields"> - <% if f.object.new_record? %> <div class="field"> - <%= f.label :user_id, I18n.t('spree.user'), class: "required" %> - <%= f.collection_select :user_id, Spree::User.all, :id, :email, {}, class: "select2 fullwidth" %> + <%= f.label :actionable_date %> + <%= f.text_field :actionable_date, class: "form-control fullwidth datepicker" %> </div> - <% end %> - - <div class="field"> - <%= f.label :actionable_date %> - <%= f.text_field :actionable_date, class: "form-control fullwidth datepicker" %> - </div> - <div class="row"> - <div class="col-6"> - <div class="field"> - <%= f.label :interval_length %> - <%= f.number_field :interval_length, class: "form-control fullwidth" %> + <div class="row"> + <div class="col-6"> + <div class="field"> + <%= f.label :interval_length %> + <%= f.number_field :interval_length, class: "form-control fullwidth" %> + </div> </div> - </div> - <div class="col-6"> - <div class="field"> - <% - unit_values = SolidusSubscriptions::LineItem.interval_units.keys - units = unit_values.map do |unit| - [ - SolidusSubscriptions::LineItem.human_attribute_name("interval_units.#{unit}"), - unit, - ] - end - %> + <div class="col-6"> + <div class="field"> + <% + unit_values = SolidusSubscriptions::LineItem.interval_units.keys + units = unit_values.map do |unit| + [ + SolidusSubscriptions::LineItem.human_attribute_name("interval_units.#{unit}"), + unit, + ] + end + %> - <%= f.label :interval_units %> - <%= f.select(:interval_units, units, {}, class: 'fullwidth select2') %> + <%= f.label :interval_units %> + <%= f.select(:interval_units, units, {}, class: 'fullwidth select2') %> + </div> </div> </div> - </div> - <div class="field"> - <%= f.label :end_date %> - <%= f.text_field :end_date, class: "fullwidth datepicker" %> - </div> + <div class="field"> + <%= f.label :end_date %> + <%= f.text_field :end_date, class: "fullwidth datepicker" %> + </div> - <div class="field"> - <%= f.label :store_id %> - <%= f.collection_select :store_id, Spree::Store.all, :id, :name, {}, class: 'fullwidth select2' %> + <div class="field"> + <%= f.label :store_id %> + <%= f.collection_select :store_id, Spree::Store.all, :id, :name, {}, class: 'fullwidth select2' %> + </div> </div> - </div> + </fieldset> - <div class="js-customer-details"> - <fieldset class="no-border-bottom"> - <legend>Shipping Address</legend> + <fieldset class="no-border-bottom"> + <legend>Shipping Address</legend> + <div class="js-customer-details"> <div class="js-shipping-address"> <%= f.fields_for :shipping_address do |sa_form| %> <%= render partial: 'spree/admin/shared/address_form', locals: { f: sa_form, type: "shipping" } %> <% end %> </div> - </fieldset> - </div> + </div> + </fieldset> - <fieldset class="no-border-bottom"> + <fieldset> <legend><%= t('.subscription_line_items') %></legend> <%= f.fields_for :line_items do |lf| %> <div class="row"> - <div class="col-10"> + <div class="col-8"> <div class="field"> <%= lf.label :subscribable_id %> <%= lf.collection_select :subscribable_id, Spree::Variant.where(subscribable: true), :id, :pretty_name, {}, { class: "fullwidth select2" } %> </div> </div> - <div class="col-1"> + <div class="col-2"> <div class="field"> <%= lf.label :quantity %> <%= lf.number_field :quantity, min: 1, class: "form-control fullwidth" %> </div> </div> - <div class="col-1"> + <div class="col-2"> <div class="field align-center"> <%= lf.label :_destroy %> <%= lf.check_box :_destroy, class: "form-control", disabled: lf.object.new_record? %> @@ -90,11 +92,11 @@ </div> </div> <% end %> - </fieldset> - <% if f.object.new_record? %> - <%= render partial: 'spree/admin/shared/new_resource_links' %> - <% else %> - <%= render partial: 'spree/admin/shared/edit_resource_links' %> - <% end %> -</fieldset> + <% if f.object.new_record? %> + <%= render partial: 'spree/admin/shared/new_resource_links' %> + <% else %> + <%= render partial: 'spree/admin/shared/edit_resource_links' %> + <% end %> + </fieldset> +</div> diff --git a/app/views/spree/admin/subscriptions/_processing_state_pill.html.erb b/app/views/spree/admin/subscriptions/_processing_state_pill.html.erb new file mode 100644 index 0000000..4260446 --- /dev/null +++ b/app/views/spree/admin/subscriptions/_processing_state_pill.html.erb @@ -0,0 +1,9 @@ +<% state_class = { + success: 'active', + failed: 'error', + pending: 'inactive', +}[subscription.processing_state.to_sym] %> + +<span class="pill pill-<%= state_class %>"> + <%= subscription.class.human_attribute_name("processing_state.#{subscription.processing_state}") %> +</span> diff --git a/app/views/spree/admin/subscriptions/_state_pill.html.erb b/app/views/spree/admin/subscriptions/_state_pill.html.erb new file mode 100644 index 0000000..1d79bda --- /dev/null +++ b/app/views/spree/admin/subscriptions/_state_pill.html.erb @@ -0,0 +1,10 @@ +<% state_class = { + active: 'active', + canceled: 'error', + pending_cancellation: 'warning', + inactive: 'inactive', +}[subscription.state.to_sym] %> + +<span class="pill pill-<%= state_class %>"> + <%= subscription.human_state_name %> +</span> diff --git a/app/views/spree/admin/subscriptions/edit.html.erb b/app/views/spree/admin/subscriptions/edit.html.erb index 274bbad..e42995c 100644 --- a/app/views/spree/admin/subscriptions/edit.html.erb +++ b/app/views/spree/admin/subscriptions/edit.html.erb @@ -1,8 +1,9 @@ <% content_for(:page_title) { t('.title') } %> -<% content_for :sidebar_title do %> - Details -<% end %> +<%= render 'spree/admin/shared/subscription_breadcrumbs', subscription: @subscription %> +<%= render 'spree/admin/shared/subscription_sidebar', subscription: @subscription %> +<%= render 'spree/admin/shared/subscription_tabs', current: :details, subscription: @subscription %> +<%= render 'spree/admin/shared/subscription_actions', subscription: @subscription %> <%= form_for @subscription, url: spree.admin_subscription_path(@subscription) do |f| %> <%= render "form", f: f %> diff --git a/app/views/spree/admin/subscriptions/index.html.erb b/app/views/spree/admin/subscriptions/index.html.erb index a15f3d5..7389a10 100644 --- a/app/views/spree/admin/subscriptions/index.html.erb +++ b/app/views/spree/admin/subscriptions/index.html.erb @@ -121,22 +121,18 @@ <td><%= link_to subscription.user.email, admin_user_path(subscription.user) %></td> <td><%= subscription.actionable_date ? l(subscription.actionable_date.to_date) : '-' %></td> <td><%= subscription.interval.inspect %></td> - <td><%= content_tag :span, subscription.human_state_name, class: "state #{ subscription.state }" %></td> - <td> - <span class="state <%= subscription.processing_state %>"> - <%= subscription.class.human_attribute_name("processing_state.#{subscription.processing_state}") %> - </span> - </td> + <td><%= render 'state_pill', subscription: subscription %></td> + <td><%= render 'processing_state_pill', subscription: subscription %></td> <td class="actions"> <% if subscription.state_events.include?(:cancel) %> <%= link_to_with_icon( :stop, - t('.cancel'), + t('spree.admin.subscriptions.actions.cancel'), spree.cancel_admin_subscription_path(subscription), no_text: true, method: :delete, - data: { confirm: t('.cancel_alert') } + data: { confirm: t('spree.admin.subscriptions.actions.cancel_alert') } ) %> <% end %> @@ -145,7 +141,7 @@ <%= link_to_with_icon( :play, - t('.activate'), + t('spree.admin.subscriptions.actions.activate'), spree.activate_admin_subscription_path(subscription), no_text: true, method: :post @@ -157,7 +153,7 @@ <%= link_to_with_icon( :'fast-forward', - t('.skip'), + t('spree.admin.subscriptions.actions.skip'), spree.skip_admin_subscription_path(subscription), no_text: true, method: :post |