Sorting by most orders, currency symbol, hide until clicked, reformatting table headers

This commit is contained in:
stveep
2015-12-21 22:19:00 +00:00
parent 90e627ad60
commit da0810382b
8 changed files with 41 additions and 66 deletions

View File

@@ -1,9 +1,9 @@
Darkswarm.controller "DistributorNodeCtrl", ($scope, HashNavigation, $anchorScroll) ->
$scope.toggle = ->
HashNavigation.toggle $scope.distributor_id
HashNavigation.toggle $scope.distributor.id
$scope.open = ->
HashNavigation.active($scope.distributor_id)
HashNavigation.active($scope.distributor.id)
if $scope.open()
$anchorScroll()

View File

@@ -1,19 +1,7 @@
Darkswarm.factory 'Orders', (orders, CurrentHub, Taxons, Dereferencer, visibleFilter, Matcher, Geo, $rootScope)->
Darkswarm.factory 'Orders', (orders_by_distributor, currencyConfig, CurrentHub, Taxons, Dereferencer, visibleFilter, Matcher, Geo, $rootScope)->
new class Orders
orders_by_distributor: {}
distributor_names_by_id: {}
constructor: ->
# Populate Orders.orders from json in page.
@orders = orders
# Organise orders by distributor.
for order in orders
if order.distributor?
if @orders_by_distributor[order.distributor.id]? then @orders_by_distributor[order.distributor.id].push order else @orders_by_distributor[order.distributor.id] = [order]
if !@distributor_names_by_id[order.distributor.id] then @distributor_names_by_id[order.distributor.id] = {name: order.distributor.name, balance: 0}
for id in Object.keys(@distributor_names_by_id)
@distributor_names_by_id[id].balance = @orders_by_distributor[id].reduce(((x,y) ->
x + Number(y.outstanding_balance)), 0).toFixed(2)
console.log @distributor_names_by_id
@orders_by_distributor = orders_by_distributor
@currency_symbol = currencyConfig.symbol
# Sorting by most orders (most recent/frequent?)

View File

@@ -51,16 +51,11 @@ module InjectionHelper
render partial: "json/injection_ams", locals: {name: 'enterpriseAttributes', json: "#{@enterprise_attributes.to_json}"}
end
def inject_orders_for_user
# Convert ActiveRecord::Relation to array for serialization
inject_json_ams "orders", spree_current_user.orders.where(state: :complete).to_a, Api::OrderSerializer
end
def inject_orders_by_distributor
#render partial: "json/injection_ams", locals: {name:"orders_by_distributor", json: spree_current_user.orders_by_distributor}
inject_json_ams "orders_by_distributor",
Enterprise.includes(:distributed_orders).where(id: spree_current_user.enterprises_ordered_from).to_a,
Api::OrdersByDistributorSerializer
# Convert ActiveRecord::Relation to array for serialization
data_array = Enterprise.includes(:distributed_orders).where(enterprises: {id: spree_current_user.enterprises_ordered_from }, spree_orders: {state: :complete, user_id: spree_current_user.id}).to_a
data_array.sort!{|a,b| b.distributed_orders.length <=> a.distributed_orders.length} # Better to do in SQL/Angular?
inject_json_ams "orders_by_distributor", data_array, Api::OrdersByDistributorSerializer
end
def inject_json(name, partial, opts = {})

View File

@@ -1,5 +1,5 @@
class Api::OrdersByDistributorSerializer < ActiveModel::Serializer
attributes :name, :balance, :distributed_orders
attributes :name, :id, :balance, :distributed_orders
has_many :distributed_orders, serializer: Api::OrderSerializer
def balance

View File

@@ -1,20 +1,20 @@
.row.active_table_row{"ng-click" => "toggle($event)", "ng-class" => "{'closed' : !open(), 'is_distributor' : producer.is_distributor}"}
.columns.small-12.medium-4.large-4.skinny-head
%span{"bo-if" => "producer.is_distributor" }
%a.is_distributor{"bo-href" => "producer.path" }
%a.is_distributor{"bo-href" => "producer.path" }
%i{bo: {class: "producer.producer_icon_font"}}
%span.margin-top
%span.margin-top
%strong{"bo-text" => "producer.name"}
%span.producer-name{"bo-if" => "!producer.is_distributor" }
%i{bo: {class: "producer.producer_icon_font"}}
%span.margin-top
%span.margin-top
%strong{"bo-text" => "producer.name"}
.columns.small-6.medium-3.large-3
%span.margin-top{"bo-text" => "producer.address.city"}
.columns.small-4.medium-3.large-4
%span.margin-top{"bo-bind" => "producer.address.state_name | uppercase"}
.columns.small-2.medium-2.large-1.text-right
%span.margin-top
%span.margin-top
%i{"ng-class" => "{'ofn-i_005-caret-down' : !open(), 'ofn-i_006-caret-up' : open()}"}

View File

@@ -1,20 +1,17 @@
.row.active_table_row{"ng-click" => "toggle($event)", "ng-class" => "{'closed' : !open()}"}
.container{"bo-text" => "orders[0].distributor.name"}
%span {{orders[0].total_money.currency_symbol}}&nbsp{{Orders.distributor_names_by_id[distributor_id].balance}}
.row.active_table_row{"ng-if" => "open()","ng-class" => "{'open' : !ofn-i_032-closed-sign()}"}
.columns.small-12.medium-7.large-7.fat
%table
%th
%tr
%td Transaction
%td Date
%td Payment Status
%td Shipping Status
%td Value
%td Balance
%tr{"ng-repeat" => "order in orders"}
%td {{order.id}}
%td {{order.completed_at}}
%td {{order.payment_state}}
%td {{order.shipment_state}}
%tr
%th Transaction
%th Date
%th Payment Status
%th Shipping Status
%th Value
%th Balance
%tr{"ng-repeat" => "order in distributor.distributed_orders"}
%td{"bo-text" => "order.id"}
%td{"bo-text" => "order.completed_at"}
%td{"bo-text" => "order.payment_state"}
%td{"bo-text" => "order.shipment_state"}
%td {{order.total_money.currency_symbol}}&nbsp{{order.total_money.amount}}
%td {{order.balance_money.currency_symbol}}&nbsp{{order.balance_money.amount}}
%td{"ng-class" => "{'credit' : order.outstanding_balance < 0, 'debit' : order.outstanding_balance > 0, 'paid' : order.outstanding_balance == 0}"} {{order.balance_money.currency_symbol}}&nbsp{{order.balance_money.amount}}

View File

@@ -1,14 +1,10 @@
-# Add extra highlighting etc (credit/debit?) here
.row.active_table_row{"ng-click" => "toggle($event)", "ng-class" => "{'closed' : !open()}"}
.columns.small-12.medium-4.large-4.skinny-head
%span.margin-top
%strong{"bo-text" => "distributor"}
%strong{"bo-text" => "distributor.name"}
-#
.columns.small-6.medium-3.large-3
%span.margin-top{"bo-text" => "producer.address.city"}
.columns.small-4.medium-3.large-4
%span.margin-top{"bo-bind" => "producer.address.state_name | uppercase"}
.columns.small-2.medium-2.large-1.text-right
%span.margin-top
%i{"ng-class" => "{'ofn-i_005-caret-down' : !open(), 'ofn-i_006-caret-up' : open()}"}
.columns.small-6.medium-3.large-3
%span.margin-top{"bo-text" => "'Balance: ' + Orders.currency_symbol + ' ' + distributor.balance", "ng-class" => "{'credit' : order.outstanding_balance < 0, 'debit' : order.outstanding_balance > 0, 'paid' : order.outstanding_balance == 0}"}
.columns.small-2.medium-2.large-1.text-right
%span.margin-top
%i{"ng-class" => "{'ofn-i_005-caret-down' : !open(), 'ofn-i_006-caret-up' : open()}"}

View File

@@ -1,4 +1,3 @@
= inject_orders_for_user
= inject_orders_by_distributor
.row.pad-top
@@ -10,15 +9,15 @@
%dd
= @user.email
(#{link_to t(:edit), spree.edit_account_path})
-# Add back ng-cloak below
.orders{"ng-controller" => "OrdersCtrl"}
%h3 My Orders
.orders{"ng-controller" => "OrdersCtrl", "ng-cloak" => true}
.row{bindonce: true}
.small-12.columns
.active_table
%distributor.active_table_node.row.animate-repeat{"ng-repeat" => "(distributor_id, orders) in Orders.orders_by_distributor",
%distributor.active_table_node.row.animate-repeat{"ng-repeat" => "(key, distributor) in Orders.orders_by_distributor",
"ng-controller" => "DistributorNodeCtrl",
"ng-class" => "{'closed' : !open(), 'open' : open(), 'inactive' : !distributor.active}",
id: "{{distributor_id}}"}
id: "{{distributor.id}}"}
.small-12.columns
= render partial: "spree/users/skinny"
= render partial: "spree/users/fat"
-# TODO: Skinny partial