Rewriting shopfront alert regarding changeable orders to be dynamic

This commit is contained in:
Rob Harrington
2017-05-18 15:35:07 +10:00
parent b6f4ce373e
commit 74d8dc48b4
9 changed files with 39 additions and 8 deletions

View File

@@ -10,7 +10,7 @@ Darkswarm.controller "OrderCycleCtrl", ($scope, $timeout, OrderCycle) ->
$("#order_cycle_id").trigger("openTrigger")
Darkswarm.controller "OrderCycleChangeCtrl", ($scope, $timeout, OrderCycle, Products, Variants, Cart) ->
Darkswarm.controller "OrderCycleChangeCtrl", ($scope, $timeout, OrderCycle, Products, Variants, Cart, ChangeableOrdersAlert) ->
# Track previous order cycle id for use with revertOrderCycle()
$scope.previous_order_cycle_id = OrderCycle.order_cycle.order_cycle_id
$scope.$watch 'order_cycle.order_cycle_id', (newValue, oldValue)->
@@ -31,3 +31,4 @@ Darkswarm.controller "OrderCycleChangeCtrl", ($scope, $timeout, OrderCycle, Prod
Cart.clear()
Products.update()
Cart.reloadFinalisedLineItems()
ChangeableOrdersAlert.reload()

View File

@@ -0,0 +1,5 @@
Darkswarm.directive "changeableOrdersAlert", (ChangeableOrdersAlert) ->
restrict: "C"
scope: true
link: (scope, element, attrs) ->
scope.alert = ChangeableOrdersAlert

View File

@@ -0,0 +1,14 @@
Darkswarm.factory 'ChangeableOrdersAlert', ($http) ->
new class ChangeableOrdersAlert
html: ''
visible: true
constructor: ->
@reload()
reload: ->
$http.get('/shop/changeable_orders_alert').then (response) =>
@html = response.data.trim()
close: =>
@visible = false

View File

@@ -110,6 +110,10 @@
}
}
.alert-box.changeable-orders-alert {
margin-bottom: 0px;
}
.alert-box.shopfront-message {
border: 2px solid $clr-turquoise;
border-radius: 5px;

View File

@@ -37,6 +37,10 @@ class ShopController < BaseController
end
end
def changeable_orders_alert
render layout: false
end
private
def filtered_json(products_json)

View File

@@ -19,9 +19,10 @@ module Spree
def changeable_orders
# Only returns open order for the current user + shop + oc combo
return [] unless spree_current_user && current_distributor && current_order_cycle
return [] unless current_distributor.allow_order_changes?
Spree::Order.complete.where(
return @changeable_orders unless @changeable_orders.nil?
return @changeable_orders = [] unless spree_current_user && current_distributor && current_order_cycle
return @changeable_orders = [] unless current_distributor.allow_order_changes?
@changeable_orders = Spree::Order.complete.where(
state: 'complete',
user_id: spree_current_user.id,
distributor_id: current_distributor.id,
@@ -33,6 +34,7 @@ module Spree
end
def shop_changeable_orders_alert_html
return "" unless changeable_orders.any?
t(:shop_changeable_orders_alert_html,
count: changeable_orders.count,
path: changeable_orders_link_path,

View File

@@ -8,10 +8,9 @@
= inject_shop_enterprises
%shop.darkswarm
- if changeable_orders.any?
.alert-box.info{ "ofn-inline-alert" => true, ng: { show: "visible" } }
= shop_changeable_orders_alert_html
%a.close{ ng: { click: "close()" } } &times;
.alert-box.changeable-orders-alert.info.animate-show{ ng: { show: "alert.visible && alert.html" } }
%span{ ng: { bind: { html: "alert.html" } } }
%a.close{ ng: { click: "alert.close()" } } &times;
- content_for :order_cycle_form do

View File

@@ -0,0 +1 @@
= shop_changeable_orders_alert_html

View File

@@ -28,6 +28,7 @@ Openfoodnetwork::Application.routes.draw do
get :products
post :order_cycle
get :order_cycle
get :changeable_orders_alert
end
resources :producers, only: [:index] do