Merge branch master into properties

This commit is contained in:
Rob Harrington
2015-04-17 13:23:33 +10:00
243 changed files with 6059 additions and 1487 deletions

View File

@@ -19,6 +19,7 @@
//= require ../shared/ng-infinite-scroll.min.js
//= require ./admin
//= require ./enterprises/enterprises
//= require ./enterprise_groups/enterprise_groups
//= require ./payment_methods/payment_methods
//= require ./products/products
//= require ./shipping_methods/shipping_methods

View File

@@ -0,0 +1,3 @@
angular.module("admin.enterprise_groups")
.controller "enterpriseGroupCtrl", ($scope, SideMenu) ->
$scope.menu = SideMenu

View File

@@ -0,0 +1,15 @@
angular.module("admin.enterprise_groups")
.controller "sideMenuCtrl", ($scope, SideMenu) ->
$scope.menu = SideMenu
$scope.select = SideMenu.select
$scope.menu.setItems [
{ name: 'Primary Details', icon_class: "icon-user" }
{ name: 'Users', icon_class: "icon-user" }
{ name: 'About', icon_class: "icon-pencil" }
{ name: 'Images', icon_class: "icon-picture" }
{ name: 'Contact', icon_class: "icon-phone" }
{ name: 'Web', icon_class: "icon-globe" }
]
$scope.select(0)

View File

@@ -0,0 +1 @@
angular.module("admin.enterprise_groups", ["admin.side_menu", "admin.users", "textAngular"])

View File

@@ -13,6 +13,7 @@ angular.module("admin.enterprises")
{ name: 'About', icon_class: "icon-pencil" }
{ name: 'Business Details', icon_class: "icon-briefcase" }
{ name: 'Images', icon_class: "icon-picture" }
{ name: "Properties", icon_class: "icon-tags", show: "showProperties()" }
{ name: "Shipping Methods", icon_class: "icon-truck", show: "showShippingMethods()" }
{ name: "Payment Methods", icon_class: "icon-money", show: "showPaymentMethods()" }
{ name: "Enterprise Fees", icon_class: "icon-tasks", show: "showEnterpriseFees()" }
@@ -28,6 +29,9 @@ angular.module("admin.enterprises")
else
true
$scope.showProperties = ->
!!$scope.Enterprise.is_primary_producer
$scope.showShippingMethods = ->
enterprisePermissions.can_manage_shipping_methods && $scope.Enterprise.sells != "none"

View File

@@ -1,10 +1,10 @@
angular.module('admin.order_cycles', ['ngResource'])
.controller('AdminCreateOrderCycleCtrl', ['$scope', 'OrderCycle', 'Enterprise', 'EnterpriseFee', ($scope, OrderCycle, Enterprise, EnterpriseFee) ->
$scope.enterprises = Enterprise.index()
.controller('AdminCreateOrderCycleCtrl', ['$scope', '$filter', 'OrderCycle', 'Enterprise', 'EnterpriseFee', 'ocInstance', ($scope, $filter, OrderCycle, Enterprise, EnterpriseFee, ocInstance) ->
$scope.enterprises = Enterprise.index(coordinator_id: ocInstance.coordinator_id)
$scope.supplied_products = Enterprise.supplied_products
$scope.enterprise_fees = EnterpriseFee.index()
$scope.enterprise_fees = EnterpriseFee.index(coordinator_id: ocInstance.coordinator_id)
$scope.order_cycle = OrderCycle.order_cycle
$scope.order_cycle = OrderCycle.new({ coordinator_id: ocInstance.coordinator_id})
$scope.loaded = ->
Enterprise.loaded && EnterpriseFee.loaded
@@ -27,14 +27,14 @@ angular.module('admin.order_cycles', ['ngResource'])
$scope.variantSuppliedToOrderCycle = (variant) ->
OrderCycle.variantSuppliedToOrderCycle(variant)
$scope.incomingExchangesVariants = ->
OrderCycle.incomingExchangesVariants()
$scope.incomingExchangeVariantsFor = (enterprise_id) ->
$filter('filterExchangeVariants')(OrderCycle.incomingExchangesVariants(), $scope.order_cycle.visible_variants_for_outgoing_exchanges[enterprise_id])
$scope.exchangeDirection = (exchange) ->
OrderCycle.exchangeDirection(exchange)
$scope.participatingEnterprises = ->
$scope.enterprises[id] for id in OrderCycle.participatingEnterpriseIds()
$scope.enterprisesWithFees = ->
$scope.enterprises[id] for id in OrderCycle.participatingEnterpriseIds() when $scope.enterpriseFeesForEnterprise(id).length > 0
$scope.toggleProducts = ($event, exchange) ->
$event.preventDefault()
@@ -79,12 +79,12 @@ angular.module('admin.order_cycles', ['ngResource'])
OrderCycle.create()
])
.controller('AdminEditOrderCycleCtrl', ['$scope', '$location', 'OrderCycle', 'Enterprise', 'EnterpriseFee', ($scope, $location, OrderCycle, Enterprise, EnterpriseFee) ->
$scope.enterprises = Enterprise.index()
$scope.supplied_products = Enterprise.supplied_products
$scope.enterprise_fees = EnterpriseFee.index()
.controller('AdminEditOrderCycleCtrl', ['$scope', '$filter', '$location', 'OrderCycle', 'Enterprise', 'EnterpriseFee', ($scope, $filter, $location, OrderCycle, Enterprise, EnterpriseFee) ->
order_cycle_id = $location.absUrl().match(/\/admin\/order_cycles\/(\d+)/)[1]
$scope.enterprises = Enterprise.index(order_cycle_id: order_cycle_id)
$scope.supplied_products = Enterprise.supplied_products
$scope.enterprise_fees = EnterpriseFee.index(order_cycle_id: order_cycle_id)
$scope.order_cycle = OrderCycle.load(order_cycle_id)
$scope.loaded = ->
@@ -108,14 +108,14 @@ angular.module('admin.order_cycles', ['ngResource'])
$scope.variantSuppliedToOrderCycle = (variant) ->
OrderCycle.variantSuppliedToOrderCycle(variant)
$scope.incomingExchangesVariants = ->
OrderCycle.incomingExchangesVariants()
$scope.incomingExchangeVariantsFor = (enterprise_id) ->
$filter('filterExchangeVariants')(OrderCycle.incomingExchangesVariants(), $scope.order_cycle.visible_variants_for_outgoing_exchanges[enterprise_id])
$scope.exchangeDirection = (exchange) ->
OrderCycle.exchangeDirection(exchange)
$scope.participatingEnterprises = ->
$scope.enterprises[id] for id in OrderCycle.participatingEnterpriseIds()
$scope.enterprisesWithFees = ->
$scope.enterprises[id] for id in OrderCycle.participatingEnterpriseIds() when $scope.enterpriseFeesForEnterprise(id).length > 0
$scope.toggleProducts = ($event, exchange) ->
$event.preventDefault()

View File

@@ -1,8 +1,9 @@
angular.module('admin.order_cycles').controller "AdminSimpleCreateOrderCycleCtrl", ($scope, OrderCycle, Enterprise, EnterpriseFee) ->
$scope.enterprises = Enterprise.index (enterprises) =>
$scope.init(enterprises)
$scope.enterprise_fees = EnterpriseFee.index()
$scope.order_cycle = OrderCycle.order_cycle
angular.module('admin.order_cycles').controller "AdminSimpleCreateOrderCycleCtrl", ($scope, OrderCycle, Enterprise, EnterpriseFee, ocInstance) ->
$scope.order_cycle = OrderCycle.new {coordinator_id: ocInstance.coordinator_id}, =>
# TODO: make this a get method, which only fetches one enterprise
$scope.enterprises = Enterprise.index {coordinator_id: ocInstance.coordinator_id}, (enterprises) =>
$scope.init(enterprises)
$scope.enterprise_fees = EnterpriseFee.index(coordinator_id: ocInstance.coordinator_id)
$scope.init = (enterprises) ->
enterprise = enterprises[Object.keys(enterprises)[0]]

View File

@@ -2,8 +2,8 @@ angular.module('admin.order_cycles').controller "AdminSimpleEditOrderCycleCtrl",
$scope.orderCycleId = ->
$location.absUrl().match(/\/admin\/order_cycles\/(\d+)/)[1]
$scope.enterprises = Enterprise.index()
$scope.enterprise_fees = EnterpriseFee.index()
$scope.enterprises = Enterprise.index(order_cycle_id: $scope.orderCycleId())
$scope.enterprise_fees = EnterpriseFee.index(order_cycle_id: $scope.orderCycleId())
$scope.order_cycle = OrderCycle.load $scope.orderCycleId(), (order_cycle) =>
$scope.init()

View File

@@ -0,0 +1,6 @@
angular.module("admin.order_cycles").filter "filterExchangeVariants", ->
return (variants, rules) ->
if variants? && rules?
return (variant for variant in variants when variant in rules)
else
return []

View File

@@ -0,0 +1,4 @@
angular.module("admin.order_cycles").filter "visibleProductVariants", ->
return (product, exchange, rules) ->
variants = product.variants.concat( [{ "id": product.master_id}] )
return (variant for variant in variants when variant.id in rules[exchange.enterprise_id])

View File

@@ -0,0 +1,3 @@
angular.module("admin.order_cycles").filter "visibleProducts", ($filter) ->
return (products, exchange, rules) ->
return (product for product in products when $filter('visibleProductVariants')(product, exchange, rules).length > 0)

View File

@@ -1,24 +1,28 @@
angular.module('admin.order_cycles').factory('Enterprise', ($resource) ->
Enterprise = $resource('/admin/enterprises/for_order_cycle/:enterprise_id.json', {}, {'index': {method: 'GET', isArray: true}})
Enterprise = $resource('/admin/enterprises/for_order_cycle/:enterprise_id.json', {}, {
'index':
method: 'GET'
isArray: true
params:
order_cycle_id: '@order_cycle_id'
coordinator_id: '@coordinator_id'
})
{
Enterprise: Enterprise
enterprises: {}
supplied_products: []
loaded: false
index: (callback=null) ->
service = this
Enterprise.index (data) ->
index: (params={}, callback=null) ->
Enterprise.index params, (data) =>
for enterprise in data
service.enterprises[enterprise.id] = enterprise
@enterprises[enterprise.id] = enterprise
for product in enterprise.supplied_products
service.supplied_products.push(product)
@supplied_products.push(product)
service.loaded = true
(callback || angular.noop)(service.enterprises)
@loaded = true
(callback || angular.noop)(@enterprises)
this.enterprises
@@ -40,4 +44,4 @@ angular.module('admin.order_cycles').factory('Enterprise', ($resource) ->
numVariants += if product.variants.length == 0 then 1 else product.variants.length
numVariants
})
})

View File

@@ -1,18 +1,23 @@
angular.module('admin.order_cycles').factory('EnterpriseFee', ($resource) ->
EnterpriseFee = $resource('/admin/enterprise_fees/:enterprise_fee_id.json', {}, {'index': {method: 'GET', isArray: true}})
EnterpriseFee = $resource('/admin/enterprise_fees/for_order_cycle/:enterprise_fee_id.json', {}, {
'index':
method: 'GET'
isArray: true
params:
order_cycle_id: '@order_cycle_id'
coordinator_id: '@coordinator_id'
})
{
EnterpriseFee: EnterpriseFee
enterprise_fees: {}
loaded: false
index: ->
service = this
EnterpriseFee.index (data) ->
service.enterprise_fees = data
service.loaded = true
index: (params={}) ->
EnterpriseFee.index params, (data) =>
@enterprise_fees = data
@loaded = true
forEnterprise: (enterprise_id) ->
enterprise_fee for enterprise_fee in this.enterprise_fees when enterprise_fee.enterprise_id == enterprise_id
enterprise_fee for enterprise_fee in @enterprise_fees when enterprise_fee.enterprise_id == enterprise_id
})

View File

@@ -1,14 +1,12 @@
angular.module('admin.order_cycles').factory('OrderCycle', ($resource, $window) ->
OrderCycle = $resource '/admin/order_cycles/:order_cycle_id.json', {}, {
OrderCycle = $resource '/admin/order_cycles/:action_name/:order_cycle_id.json', {}, {
'index': { method: 'GET', isArray: true}
'new' : { method: 'GET', params: { action_name: "new" } }
'create': { method: 'POST'}
'update': { method: 'PUT'}}
{
order_cycle:
incoming_exchanges: []
outgoing_exchanges: []
coordinator_fees: []
order_cycle: {}
loaded: false
@@ -24,7 +22,9 @@ angular.module('admin.order_cycles').factory('OrderCycle', ($resource, $window)
exchange.showProducts = !exchange.showProducts
setExchangeVariants: (exchange, variants, selected) ->
exchange.variants[variant] = selected for variant in variants
direction = if exchange.incoming then "incoming" else "outgoing"
editable = @order_cycle["editable_variants_for_#{direction}_exchanges"][exchange.enterprise_id] || []
exchange.variants[variant] = selected for variant in variants when variant in editable
addSupplier: (new_supplier_id) ->
this.order_cycle.incoming_exchanges.push({enterprise_id: new_supplier_id, incoming: true, active: true, variants: {}, enterprise_fees: []})
@@ -84,6 +84,20 @@ angular.module('admin.order_cycles').factory('OrderCycle', ($resource, $window)
for exchange in this.order_cycle.outgoing_exchanges
exchange.variants[variant_id] = false
new: (params, callback=null) ->
OrderCycle.new params, (oc) =>
delete oc.$promise
delete oc.$resolved
angular.extend(@order_cycle, oc)
@order_cycle.incoming_exchanges = []
@order_cycle.outgoing_exchanges = []
delete(@order_cycle.exchanges)
@loaded = true
(callback || angular.noop)(@order_cycle)
@order_cycle
load: (order_cycle_id, callback=null) ->
service = this
OrderCycle.get {order_cycle_id: order_cycle_id}, (oc) ->
@@ -127,6 +141,7 @@ angular.module('admin.order_cycles').factory('OrderCycle', ($resource, $window)
dataForSubmit: ->
data = this.deepCopy()
data = this.stripNonSubmittableAttributes(data)
data = this.removeInactiveExchanges(data)
data = this.translateCoordinatorFees(data)
data = this.translateExchangeFees(data)
@@ -147,6 +162,14 @@ angular.module('admin.order_cycles').factory('OrderCycle', ($resource, $window)
data
stripNonSubmittableAttributes: (order_cycle) ->
delete order_cycle.id
delete order_cycle.viewing_as_coordinator
delete order_cycle.editable_variants_for_incoming_exchanges
delete order_cycle.editable_variants_for_outgoing_exchanges
delete order_cycle.visible_variants_for_outgoing_exchanges
order_cycle
removeInactiveExchanges: (order_cycle) ->
order_cycle.incoming_exchanges =
(exchange for exchange in order_cycle.incoming_exchanges when exchange.active)

View File

@@ -11,9 +11,9 @@ $ ->
# Temporarily handles the cart showing stuff
$(document).ready ->
$('#cart_adjustments').hide()
$('.cart_adjustment').hide()
$('th.cart-adjustment-header a').click ->
$('#cart_adjustments').toggle()
$('td.cart-adjustments a').click ->
$('.cart_adjustment').toggle()
$(this).html('Item Handling Fees (included in item totals)')
false

View File

@@ -0,0 +1,12 @@
Darkswarm.controller "GroupEnterpriseNodeCtrl", ($scope, CurrentHub) ->
$scope.active = false
$scope.toggle = ->
$scope.active = !$scope.active
$scope.open = ->
$scope.active
$scope.current = ->
$scope.hub.id is CurrentHub.hub.id

View File

@@ -0,0 +1,12 @@
Darkswarm.controller "GroupEnterprisesCtrl", ($scope, Search, FilterSelectorsService) ->
$scope.totalActive = FilterSelectorsService.totalActive
$scope.clearAll = FilterSelectorsService.clearAll
$scope.filterText = FilterSelectorsService.filterText
$scope.FilterSelectorsService = FilterSelectorsService
$scope.query = Search.search()
$scope.activeTaxons = []
$scope.show_profiles = false
$scope.filtersActive = false
$scope.$watch "query", (query)->
Search.search query

View File

@@ -0,0 +1,14 @@
Darkswarm.controller "GroupPageCtrl", ($scope, group_enterprises, Enterprises, MapConfiguration, OfnMap) ->
$scope.Enterprises = Enterprises
group_enterprises_ids = group_enterprises.map (enterprise) =>
enterprise.id
is_in_group = (enterprise) ->
group_enterprises_ids.indexOf(enterprise.id) != -1
$scope.group_producers = Enterprises.producers.filter is_in_group
$scope.group_hubs = Enterprises.hubs.filter is_in_group
$scope.map = angular.copy MapConfiguration.options
$scope.mapMarkers = OfnMap.enterprise_markers group_enterprises

View File

@@ -1,3 +1,3 @@
Darkswarm.controller "MapCtrl", ($scope, MapConfiguration, OfnMap)->
$scope.OfnMap = OfnMap
$scope.map = MapConfiguration.options
$scope.map = angular.copy MapConfiguration.options

View File

@@ -3,7 +3,7 @@ Darkswarm.controller "RegistrationCtrl", ($scope, RegistrationService, Enterpris
$scope.enterprise = EnterpriseRegistrationService.enterprise
$scope.select = RegistrationService.select
$scope.steps = ['details','contact','type','about','images','social']
$scope.steps = ['details', 'contact', 'type', 'about', 'images', 'social']
$scope.countries = availableCountries

View File

@@ -1,10 +1,14 @@
Darkswarm.controller "TabsCtrl", ($scope, $rootScope, $location, OrderCycle) ->
Darkswarm.controller "TabsCtrl", ($scope, $rootScope, $location) ->
# Return active if supplied path matches url hash path.
$scope.active = (path)->
$location.hash() == path
# Toggle tab selected status by setting the url hash path.
# Select tab by setting the url hash path.
$scope.select = (path)->
$location.hash path
# Toggle tab selected status by setting the url hash path.
$scope.toggle = (path)->
if $scope.active(path)
$location.hash ""
else

View File

@@ -0,0 +1,8 @@
Darkswarm.directive "linkToService", ->
restrict: 'E'
replace: true
scope: {
ref: '='
service: '='
}
template: '<a href="{{ref | ext_url: service}}" target="_blank" ng-show="ref"></a>'

View File

@@ -0,0 +1,7 @@
Darkswarm.filter "ext_url", ->
urlPattern = /^https?:\/\//
(url, prefix) ->
if !url || url.match(urlPattern)
url
else
prefix + url

View File

@@ -1,9 +1,10 @@
Darkswarm.filter 'shipping', ()->
Darkswarm.filter 'shipping', ()->
(objects, options)->
objects ||= []
options ?= null
if options.pickup and !options.delivery
if !options
objects
else if options.pickup and !options.delivery
objects.filter (obj)->
obj.pickup
else if options.delivery and !options.pickup

View File

@@ -8,6 +8,7 @@ Darkswarm.factory 'Cart', (CurrentOrder, Variants, $timeout, $http)->
for line_item in @line_items
line_item.variant.line_item = line_item
Variants.register line_item.variant
line_item.variant.extended_name = @extendedVariantName(line_item.variant)
orderChanged: =>
@unsaved()
@@ -63,8 +64,17 @@ Darkswarm.factory 'Cart', (CurrentOrder, Variants, $timeout, $http)->
@create_line_item(variant) unless exists
create_line_item: (variant)->
variant.extended_name = @extendedVariantName(variant)
variant.line_item =
variant: variant
quantity: null
max_quantity: null
@line_items.push variant.line_item
@line_items.push variant.line_item
extendedVariantName: (variant) =>
if variant.product_name == variant.name_to_display
variant.product_name
else
name = "#{variant.product_name} - #{variant.name_to_display}"
name += " (#{variant.options_text})" if variant.options_text
name

View File

@@ -1,11 +1,13 @@
Darkswarm.factory "OfnMap", (Enterprises, EnterpriseModal, visibleFilter)->
Darkswarm.factory "OfnMap", (Enterprises, EnterpriseModal, visibleFilter) ->
new class OfnMap
constructor: ->
@enterprises = (@extend(enterprise) for enterprise in visibleFilter(Enterprises.enterprises))
@enterprises = @enterprise_markers(Enterprises.enterprises)
enterprise_markers: (enterprises) ->
@extend(enterprise) for enterprise in visibleFilter(enterprises)
# Adding methods to each enterprise
extend: (enterprise)->
extend: (enterprise) ->
new class MapMarker
# We're whitelisting attributes because GMaps tries to crawl
# our data, and our data is recursive, so it breaks