diff --git a/Gemfile b/Gemfile index 0ed6cfc3f3..456234f554 100644 --- a/Gemfile +++ b/Gemfile @@ -7,7 +7,11 @@ gem 'pg' gem 'spree', :github => 'openfoodfoundation/spree', :branch => '1-3-stable' gem 'spree_i18n', :github => 'spree/spree_i18n' gem 'spree_auth_devise', :github => 'spree/spree_auth_devise', :branch => '1-3-stable' -gem 'spree_paypal_express', :github => "spree-contrib/better_spree_paypal_express", :branch => "1-3-stable" + +# Waiting on merge of PR #117 +# https://github.com/spree-contrib/better_spree_paypal_express/pull/117 +gem 'spree_paypal_express', :github => "openfoodfoundation/better_spree_paypal_express", :branch => "1-3-stable" +#gem 'spree_paypal_express', :github => "spree-contrib/better_spree_paypal_express", :branch => "1-3-stable" gem 'comfortable_mexican_sofa' diff --git a/Gemfile.lock b/Gemfile.lock index 4a5a94f0a8..9bb6e501db 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -12,6 +12,15 @@ GIT specs: custom_error_message (1.1.1) +GIT + remote: git://github.com/openfoodfoundation/better_spree_paypal_express.git + revision: cdd61161ccd27cd8d183f9321422c7be113796b8 + branch: 1-3-stable + specs: + spree_paypal_express (2.0.3) + paypal-sdk-merchant (= 1.106.1) + spree_core (~> 1.3.4) + GIT remote: git://github.com/openfoodfoundation/spree.git revision: bbe5e779bcb883a1726ad4006d7c06b06c3f5372 @@ -54,15 +63,6 @@ GIT spree_sample (1.3.6.beta) spree_core (= 1.3.6.beta) -GIT - remote: git://github.com/spree-contrib/better_spree_paypal_express.git - revision: db135b89a289aaab951c1228bcc55871de0cbba7 - branch: 1-3-stable - specs: - spree_paypal_express (2.0.3) - paypal-sdk-merchant (= 1.106.1) - spree_core (~> 1.3.4) - GIT remote: git://github.com/spree/deface.git revision: 1110a1336252109bce7f98f9182042e0bc2930ae diff --git a/README.markdown b/README.markdown index 8975711f47..6ffde4df5c 100644 --- a/README.markdown +++ b/README.markdown @@ -9,7 +9,6 @@ Supported by the Open Food Foundation, we are proudly open source and not-for-pr We're part of global movement - get involved! -* We're crowd-funding RIGHT NOW - please help out at http://startsomegood.com/openfoodnetwork * Fill in this short survey to tell us who you are and what you want to do with OFN: https://docs.google.com/a/eaterprises.com.au/forms/d/1zxR5vSiU9CigJ9cEaC8-eJLgYid8CR8er7PPH9Mc-30/edit# * Find out more and join in the conversation - http://openfoodnetwork.org diff --git a/app/assets/javascripts/admin/admin.js.coffee b/app/assets/javascripts/admin/admin.js.coffee index a0235a568f..c80e6252de 100644 --- a/app/assets/javascripts/admin/admin.js.coffee +++ b/app/assets/javascripts/admin/admin.js.coffee @@ -1,3 +1,3 @@ -angular.module("ofn.admin", ["ngResource", "ngAnimate", "ofn.dropdown", "admin.products"]).config ($httpProvider) -> +angular.module("ofn.admin", ["ngResource", "ngAnimate", "ofn.dropdown", "admin.products", "infinite-scroll"]).config ($httpProvider) -> $httpProvider.defaults.headers.common["X-CSRF-Token"] = $("meta[name=csrf-token]").attr("content") $httpProvider.defaults.headers.common["Accept"] = "application/json, text/javascript, */*" \ No newline at end of file diff --git a/app/assets/javascripts/admin/all.js b/app/assets/javascripts/admin/all.js index 4c763ec411..5ffb99ccb8 100644 --- a/app/assets/javascripts/admin/all.js +++ b/app/assets/javascripts/admin/all.js @@ -16,6 +16,7 @@ //= require admin/spree_auth //= require admin/spree_promo //= require admin/spree_paypal_express +//= require ../shared/ng-infinite-scroll.min.js //= require ./admin //= require ./enterprises/enterprises //= require ./payment_methods/payment_methods diff --git a/app/assets/javascripts/admin/bulk_product_update.js.coffee b/app/assets/javascripts/admin/bulk_product_update.js.coffee index 8fc088fc97..35ec6e694c 100644 --- a/app/assets/javascripts/admin/bulk_product_update.js.coffee +++ b/app/assets/javascripts/admin/bulk_product_update.js.coffee @@ -1,23 +1,23 @@ angular.module("ofn.admin").controller "AdminProductEditCtrl", [ - "$scope", "$timeout", "$http", "dataFetcher", "DirtyProducts", "VariantUnitManager", - ($scope, $timeout, $http, dataFetcher, DirtyProducts, VariantUnitManager) -> + "$scope", "$timeout", "$http", "dataFetcher", "DirtyProducts", "VariantUnitManager", "producers", "Taxons", + ($scope, $timeout, $http, dataFetcher, DirtyProducts, VariantUnitManager, producers, Taxons) -> $scope.updateStatusMessage = text: "" style: {} $scope.columns = - supplier: {name: "Supplier", visible: true} + producer: {name: "Producer", visible: true} name: {name: "Name", visible: true} unit: {name: "Unit", visible: true} price: {name: "Price", visible: true} on_hand: {name: "On Hand", visible: true} - taxons: {name: "Taxons", visible: false} + category: {name: "Category", visible: false} available_on: {name: "Available On", visible: false} $scope.variant_unit_options = VariantUnitManager.variantUnitOptions() $scope.filterableColumns = [ - { name: "Supplier", db_column: "supplier_name" }, + { name: "Producer", db_column: "producer_name" }, { name: "Name", db_column: "name" } ] @@ -28,25 +28,20 @@ angular.module("ofn.admin").controller "AdminProductEditCtrl", [ $scope.optionTabs = filters: { title: "Filter Products", visible: false } - column_toggle: { title: "Toggle Columns", visible: false } - $scope.perPage = 25 - $scope.currentPage = 1 + + $scope.producers = producers + $scope.taxons = Taxons.taxons + $scope.filterProducers = [{id: "0", name: ""}].concat $scope.producers + $scope.filterTaxons = [{id: "0", name: ""}].concat $scope.taxons + $scope.producerFilter = "0" + $scope.categoryFilter = "0" $scope.products = [] $scope.filteredProducts = [] $scope.currentFilters = [] - $scope.totalCount = -> $scope.filteredProducts.length - $scope.totalPages = -> Math.ceil($scope.totalCount()/$scope.perPage) - $scope.firstVisibleProduct = -> ($scope.currentPage-1)*$scope.perPage+1 - $scope.lastVisibleProduct = -> Math.min($scope.totalCount(),$scope.currentPage*$scope.perPage) - $scope.setPage = (page) -> $scope.currentPage = page - $scope.minPage = -> Math.max(1,Math.min($scope.totalPages()-4,$scope.currentPage-2)) - $scope.maxPage = -> Math.min($scope.totalPages(),Math.max(5,$scope.currentPage+2)) + $scope.limit = 15 + $scope.productsWithUnsavedVariants = [] - $scope.$watch -> - $scope.totalPages() - , (newVal, oldVal) -> - $scope.currentPage = Math.max $scope.totalPages(), 1 if newVal != oldVal && $scope.totalPages() < $scope.currentPage $scope.initialise = (spree_api_key) -> authorise_api_reponse = "" @@ -55,24 +50,29 @@ angular.module("ofn.admin").controller "AdminProductEditCtrl", [ $scope.spree_api_key_ok = data.hasOwnProperty("success") and data["success"] == "Use of API Authorised" if $scope.spree_api_key_ok $http.defaults.headers.common["X-Spree-Token"] = spree_api_key - dataFetcher("/api/enterprises/managed?template=bulk_index&q[is_primary_producer_eq]=true").then (data) -> - $scope.suppliers = data - # Need to have suppliers before we get products so we can match suppliers to product.supplier - $scope.fetchProducts() + $scope.fetchProducts() else if authorise_api_reponse.hasOwnProperty("error") $scope.api_error_msg = authorise_api_reponse("error") else api_error_msg = "You don't have an API key yet. An attempt was made to generate one, but you are currently not authorised, please contact your site administrator for access." + $scope.$watchCollection '[query, producerFilter, categoryFilter]', -> + $scope.limit = 15 # Reset limit whenever searching $scope.fetchProducts = -> # WARNING: returns a promise $scope.loading = true queryString = $scope.currentFilters.reduce (qs,f) -> return qs + "q[#{f.property.db_column}_#{f.predicate.predicate}]=#{f.value};" , "" - return dataFetcher("/api/products/managed?template=bulk_index;page=1;per_page=500;#{queryString}").then (data) -> - $scope.resetProducts data + return dataFetcher("/api/products/bulk_products?page=1;per_page=20;#{queryString}").then (data) -> + $scope.resetProducts data.products $scope.loading = false + if data.pages > 1 + for page in [2..data.pages] + dataFetcher("/api/products/bulk_products?page=#{page};per_page=20;#{queryString}").then (data) -> + for product in data.products + $scope.unpackProduct product + $scope.products.push product $scope.resetProducts = (data) -> @@ -87,17 +87,15 @@ angular.module("ofn.admin").controller "AdminProductEditCtrl", [ $scope.unpackProduct = (product) -> $scope.displayProperties ||= {} $scope.displayProperties[product.id] ||= showVariants: false - $scope.matchSupplier product + #$scope.matchProducer product $scope.loadVariantUnit product - $scope.matchSupplier = (product) -> - for i of $scope.suppliers - supplier = $scope.suppliers[i] - if angular.equals(supplier, product.supplier) - product.supplier = supplier - break - + # $scope.matchProducer = (product) -> + # for producer in $scope.producers + # if angular.equals(producer.id, product.producer) + # product.producer = producer + # break $scope.loadVariantUnit = (product) -> product.variant_unit_with_scale = @@ -108,13 +106,14 @@ angular.module("ofn.admin").controller "AdminProductEditCtrl", [ else null - if product.variants - for variant in product.variants - $scope.loadVariantVariantUnit product, variant - $scope.loadVariantVariantUnit product, product.master if product.master + $scope.loadVariantUnitValues product if product.variants + $scope.loadVariantUnitValue product, product.master if product.master + $scope.loadVariantUnitValues = (product) -> + for variant in product.variants + $scope.loadVariantUnitValue product, variant - $scope.loadVariantVariantUnit = (product, variant) -> + $scope.loadVariantUnitValue = (product, variant) -> unit_value = $scope.variantUnitValue product, variant unit_value = if unit_value? then unit_value else '' variant.unit_value_with_description = "#{unit_value} #{variant.unit_description || ''}".trim() @@ -153,29 +152,10 @@ angular.module("ofn.admin").controller "AdminProductEditCtrl", [ tab.visible = !tab.visible $scope.visibleTab = tab - $scope.addFilter = (filter) -> - existingfilterIndex = $scope.indexOfFilter filter - if $scope.filterableColumns.indexOf(filter.property) >= 0 && $scope.filterTypes.indexOf(filter.predicate) >= 0 && filter.value != "" && filter.value != undefined - if (DirtyProducts.count() > 0 and confirm("Unsaved changes will be lost. Continue anyway?")) or (DirtyProducts.count() == 0) - if existingfilterIndex == -1 - $scope.currentFilters.push filter - $scope.fetchProducts() - else if confirm("'#{filter.predicate.name}' filter already exists on column '#{filter.property.name}'. Replace it?") - $scope.currentFilters[existingfilterIndex] = filter - $scope.fetchProducts() - else - alert("Please ensure all filter fields are filled in before adding a filter.") - - $scope.removeFilter = (filter) -> - index = $scope.currentFilters.indexOf(filter) - if index != -1 - $scope.currentFilters.splice index, 1 - $scope.fetchProducts() - - $scope.indexOfFilter = (filter) -> - for existingFilter, i in $scope.currentFilters - return i if filter.property == existingFilter.property && filter.predicate == existingFilter.predicate - return -1 + $scope.resetSelectFilters = -> + $scope.query = "" + $scope.producerFilter = "0" + $scope.categoryFilter = "0" $scope.editWarn = (product, variant) -> if (DirtyProducts.count() > 0 and confirm("Unsaved changes will be lost. Continue anyway?")) or (DirtyProducts.count() == 0) @@ -192,6 +172,7 @@ angular.module("ofn.admin").controller "AdminProductEditCtrl", [ display_name: null on_hand: null price: null + $scope.productsWithUnsavedVariants.push product $scope.displayProperties[product.id].showVariants = true @@ -200,6 +181,11 @@ angular.module("ofn.admin").controller "AdminProductEditCtrl", [ $scope.variantIdCounter -= 1 $scope.variantIdCounter + $scope.updateVariantLists = (server_products) -> + for product in $scope.productsWithUnsavedVariants + server_product = $scope.findProduct(product.id, server_products) + product.variants = server_product.variants + $scope.loadVariantUnitValues product $scope.deleteProduct = (product) -> if confirm("Are you sure?") @@ -244,7 +230,7 @@ angular.module("ofn.admin").controller "AdminProductEditCtrl", [ $scope.hasVariants = (product) -> - Object.keys(product.variants).length > 0 + product.variants.length > 0 $scope.hasUnit = (product) -> @@ -269,7 +255,7 @@ angular.module("ofn.admin").controller "AdminProductEditCtrl", [ if productsToSubmit.length > 0 $scope.updateProducts productsToSubmit # Don't submit an empty list else - $scope.setMessage $scope.updateStatusMessage, "No changes to update.", color: "grey", 3000 + $scope.setMessage $scope.updateStatusMessage, "No changes to save.", color: "grey", 3000 $scope.updateProducts = (productsToSubmit) -> @@ -281,22 +267,16 @@ angular.module("ofn.admin").controller "AdminProductEditCtrl", [ products: productsToSubmit filters: $scope.currentFilters ).success((data) -> - # TODO: remove this check altogether, need to write controller tests if we want to test this behaviour properly - # Note: Rob implemented subset(), which is a simpler alternative to productsWithoutDerivedAttributes(). However, it - # conflicted with some changes I made before merging my work, so for now I've reverted to the old way of - # doing things. TODO: Review together and decide on strategy here. -- Rohan, 14-1-2014 - #if subset($scope.productsWithoutDerivedAttributes(), data) - if $scope.productListsMatch $scope.products, data - $scope.resetProducts data - $timeout -> $scope.displaySuccess() - else - # console.log angular.toJson($scope.productsWithoutDerivedAttributes($scope.products)) - # console.log "---" - # console.log angular.toJson($scope.productsWithoutDerivedAttributes(data)) - # console.log "---" - $scope.displayFailure "Product lists do not match." + DirtyProducts.clear() + $scope.updateVariantLists(data.products) + $timeout -> $scope.displaySuccess() ).error (data, status) -> - $scope.displayFailure "Server returned with error status: " + status + if status == 400 && data.errors? && data.errors.length > 0 + errors = error + "\n" for error in data.errors + alert "Saving failed with the following error(s):\n" + errors + $scope.displayFailure "Save failed due to invalid data" + else + $scope.displayFailure "Server returned with error status: " + status $scope.packProduct = (product) -> @@ -322,58 +302,19 @@ angular.module("ofn.admin").controller "AdminProductEditCtrl", [ if variant.hasOwnProperty("unit_value_with_description") match = variant.unit_value_with_description.match(/^([\d\.]+(?= |$)|)( |)(.*)$/) if match - product = $scope.findProduct(product.id) + product = $scope.findProduct(product.id, $scope.products) variant.unit_value = parseFloat(match[1]) variant.unit_value = null if isNaN(variant.unit_value) variant.unit_value *= product.variant_unit_scale if variant.unit_value && product.variant_unit_scale variant.unit_description = match[3] - - $scope.productListsMatch = (clientProducts, serverProducts) -> - $scope.copyNewVariantIds clientProducts, serverProducts - angular.toJson($scope.productsWithoutDerivedAttributes(clientProducts)) == angular.toJson($scope.productsWithoutDerivedAttributes(serverProducts)) - - - # When variants are created clientside, they are given a negative id. The server - # responds with a real id, which would cause the productListsMatch() check to fail. - # To avoid that false negative, we copy the server variant id to the client for any - # negative ids. - $scope.copyNewVariantIds = (clientProducts, serverProducts) -> - if clientProducts? - for product, i in clientProducts - if product.variants? - for variant, j in product.variants - if variant.id < 0 - variant.id = serverProducts[i].variants[j].id - - - $scope.productsWithoutDerivedAttributes = (products) -> - products_filtered = [] - if products - products_filtered = $scope.deepCopyProducts products - for product in products_filtered - delete product.variant_unit_with_scale - if product.variants - for variant in product.variants - delete variant.unit_value_with_description - # If we end up live-updating this field, we might want to reinstate its verification here - delete variant.options_text - delete product.master - products_filtered - - - $scope.deepCopyProducts = (products) -> - copied_products = (angular.extend {}, product for product in products) - for product in copied_products - if product.variants - product.variants = (angular.extend {}, variant for variant in product.variants) - copied_products - - - $scope.findProduct = (id) -> - products = (product for product in $scope.products when product.id == id) + $scope.findProduct = (id, product_list) -> + products = (product for product in product_list when product.id == id) if products.length == 0 then null else products[0] + $scope.incrementLimit = -> + if $scope.limit < $scope.products.length + $scope.limit = $scope.limit + 5 $scope.setMessage = (model, text, style, timeout) -> model.text = text @@ -386,26 +327,27 @@ angular.module("ofn.admin").controller "AdminProductEditCtrl", [ $scope.displayUpdating = -> - $scope.setMessage $scope.updateStatusMessage, "Updating...", - color: "orange" + $scope.setMessage $scope.updateStatusMessage, "Saving...", + color: "#FF9906" , false $scope.displaySuccess = -> - $scope.setMessage $scope.updateStatusMessage, "Update complete", - color: "green" + $scope.setMessage $scope.updateStatusMessage, "Changes saved.", + color: "#9fc820" , 3000 $scope.displayFailure = (failMessage) -> - $scope.setMessage $scope.updateStatusMessage, "Updating failed. " + failMessage, - color: "red" - , 10000 + $scope.setMessage $scope.updateStatusMessage, "Saving failed. " + failMessage, + color: "#DA5354" + , false $scope.displayDirtyProducts = -> if DirtyProducts.count() > 0 - $scope.setMessage $scope.updateStatusMessage, "Changes to " + DirtyProducts.count() + " products remain unsaved.", + message = if DirtyProducts.count() == 1 then "one product" else DirtyProducts.count() + " products" + $scope.setMessage $scope.updateStatusMessage, "Changes to " + message + " remain unsaved.", color: "gray" , false else @@ -442,8 +384,8 @@ filterSubmitProducts = (productsToFilter) -> if product.hasOwnProperty("name") filteredProduct.name = product.name hasUpdatableProperty = true - if product.hasOwnProperty("supplier") - filteredProduct.supplier_id = product.supplier.id + if product.hasOwnProperty("producer") + filteredProduct.supplier_id = product.producer hasUpdatableProperty = true if product.hasOwnProperty("price") filteredProduct.price = product.price @@ -458,8 +400,8 @@ filterSubmitProducts = (productsToFilter) -> if product.hasOwnProperty("on_hand") and filteredVariants.length == 0 #only update if no variants present filteredProduct.on_hand = product.on_hand hasUpdatableProperty = true - if product.hasOwnProperty("taxon_ids") - filteredProduct.taxon_ids = product.taxon_ids + if product.hasOwnProperty("category") + filteredProduct.primary_taxon_id = product.category hasUpdatableProperty = true if product.hasOwnProperty("available_on") filteredProduct.available_on = product.available_on @@ -510,11 +452,3 @@ toObjectWithIDKeys = (array) -> object[array[i].id].variants = toObjectWithIDKeys(array[i].variants) if array[i].hasOwnProperty("variants") and array[i].variants instanceof Array object - -subset = (bigArray,smallArray) -> - if smallArray instanceof Array && bigArray instanceof Array && smallArray.length > 0 - for item in smallArray - return false if angular.toJson(bigArray).indexOf(angular.toJson(item)) == -1 - return true - else - return false diff --git a/app/assets/javascripts/admin/controllers/providers_controller.js.coffee b/app/assets/javascripts/admin/controllers/providers_controller.js.coffee new file mode 100644 index 0000000000..3b3378d013 --- /dev/null +++ b/app/assets/javascripts/admin/controllers/providers_controller.js.coffee @@ -0,0 +1,7 @@ +angular.module("ofn.admin").controller "ProvidersCtrl", ($scope, paymentMethod) -> + if paymentMethod.type + $scope.include_html = "/admin/payment_methods/show_provider_preferences?" + + "provider_type=#{paymentMethod.type};" + + "pm_id=#{paymentMethod.id};" + else + $scope.include_html = "" \ No newline at end of file diff --git a/app/assets/javascripts/admin/directives/provider_prefs_for.js.coffee b/app/assets/javascripts/admin/directives/provider_prefs_for.js.coffee new file mode 100644 index 0000000000..467bad4e5f --- /dev/null +++ b/app/assets/javascripts/admin/directives/provider_prefs_for.js.coffee @@ -0,0 +1,7 @@ +angular.module("ofn.admin").directive "providerPrefsFor", ($http) -> + link: (scope, element, attrs) -> + element.on "change blur load", -> + scope.$apply -> + scope.include_html = "/admin/payment_methods/show_provider_preferences?" + + "provider_type=#{element.val()};" + + "pm_id=#{attrs.providerPrefsFor};" \ No newline at end of file diff --git a/app/assets/javascripts/admin/directives/taxon_autocomplete.js.coffee b/app/assets/javascripts/admin/directives/taxon_autocomplete.js.coffee index e5713274ef..5f17a0d1dd 100644 --- a/app/assets/javascripts/admin/directives/taxon_autocomplete.js.coffee +++ b/app/assets/javascripts/admin/directives/taxon_autocomplete.js.coffee @@ -4,18 +4,16 @@ angular.module("ofn.admin").directive "ofnTaxonAutocomplete", (Taxons) -> link: (scope,element,attrs,ngModel) -> setTimeout -> element.select2 - placeholder: Spree.translations.taxon_placeholder - multiple: true + placeholder: "Category" + multiple: false initSelection: (element, callback) -> - Taxons.findByIDs(element.val()).$promise.then (result) -> - callback Taxons.cleanTaxons(result) + callback Taxons.findByID(scope.product.category) query: (query) -> - Taxons.findByTerm(query.term).$promise.then (result) -> - query.callback { results: Taxons.cleanTaxons(result) } + query.callback { results: Taxons.findByTerm(query.term) } formatResult: (taxon) -> - taxon.pretty_name + taxon.name formatSelection: (taxon) -> - taxon.pretty_name + taxon.name element.on "change", -> scope.$apply -> ngModel.$setViewValue element.val() \ No newline at end of file diff --git a/app/assets/javascripts/admin/filters/category_filter.js.coffee b/app/assets/javascripts/admin/filters/category_filter.js.coffee new file mode 100644 index 0000000000..b89e706815 --- /dev/null +++ b/app/assets/javascripts/admin/filters/category_filter.js.coffee @@ -0,0 +1,4 @@ +angular.module("ofn.admin").filter "category", ($filter) -> + return (products, taxonID) -> + return products if taxonID == "0" + return $filter('filter')( products, { category: taxonID }, true ) \ No newline at end of file diff --git a/app/assets/javascripts/admin/filters/producer_filter.js.coffee b/app/assets/javascripts/admin/filters/producer_filter.js.coffee new file mode 100644 index 0000000000..7325b2200d --- /dev/null +++ b/app/assets/javascripts/admin/filters/producer_filter.js.coffee @@ -0,0 +1,4 @@ +angular.module("ofn.admin").filter "producer", ($filter) -> + return (products, producerID) -> + return products if producerID == "0" + $filter('filter')( products, { producer: producerID }, true ) \ No newline at end of file diff --git a/app/assets/javascripts/admin/filters/taxons_term_filter.js.coffee b/app/assets/javascripts/admin/filters/taxons_term_filter.js.coffee new file mode 100644 index 0000000000..78a54175bf --- /dev/null +++ b/app/assets/javascripts/admin/filters/taxons_term_filter.js.coffee @@ -0,0 +1,7 @@ +angular.module("ofn.admin").filter "taxonsTermFilter", -> + return (lineItems,selectedSupplier,selectedDistributor,selectedOrderCycle) -> + filtered = [] + filtered.push lineItem for lineItem in lineItems when (angular.equals(selectedSupplier,"0") || lineItem.supplier.id == selectedSupplier) && + (angular.equals(selectedDistributor,"0") || lineItem.order.distributor.id == selectedDistributor) && + (angular.equals(selectedOrderCycle,"0") || lineItem.order.order_cycle.id == selectedOrderCycle) + filtered \ No newline at end of file diff --git a/app/assets/javascripts/admin/services/taxons.js.coffee b/app/assets/javascripts/admin/services/taxons.js.coffee index 1779ec3518..6944fe132f 100644 --- a/app/assets/javascripts/admin/services/taxons.js.coffee +++ b/app/assets/javascripts/admin/services/taxons.js.coffee @@ -1,13 +1,15 @@ -angular.module("ofn.admin").factory "Taxons", ($resource) -> - resource = $resource "/admin/taxons/search" +angular.module("ofn.admin").factory "Taxons", (taxons, $filter) -> + new class Taxons + constructor: -> + @taxons = taxons - return { + # For finding a single Taxon + findByID: (id) -> + $filter('filter')(@taxons, {id: id}, true)[0] + + # For finding multiple Taxons represented by comma delimited string findByIDs: (ids) -> - resource.get { ids: ids } + taxon for taxon in @taxons when taxon.id.toString() in ids.split(",") findByTerm: (term) -> - resource.get { q: term } - - cleanTaxons: (data) -> - data['taxons'].map (result) -> result - } \ No newline at end of file + $filter('filter')(@taxons, term) \ No newline at end of file diff --git a/app/assets/javascripts/darkswarm/all.js.coffee b/app/assets/javascripts/darkswarm/all.js.coffee index 45f91366ba..f529ac3255 100644 --- a/app/assets/javascripts/darkswarm/all.js.coffee +++ b/app/assets/javascripts/darkswarm/all.js.coffee @@ -11,7 +11,6 @@ #= require lodash.underscore.js #= require angular-scroll.min.js #= require angular-google-maps.min.js -#= require angular-timer.min.js #= require ../shared/mm-foundation-tpls-0.2.2.min.js #= require ../shared/bindonce.min.js #= require ../shared/ng-infinite-scroll.min.js diff --git a/app/assets/javascripts/darkswarm/controllers/authentication/login_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/authentication/login_controller.js.coffee index c24f7a70f2..144cf0dfef 100644 --- a/app/assets/javascripts/darkswarm/controllers/authentication/login_controller.js.coffee +++ b/app/assets/javascripts/darkswarm/controllers/authentication/login_controller.js.coffee @@ -1,13 +1,13 @@ -Darkswarm.controller "LoginCtrl", ($scope, $http, AuthenticationService, Redirections, Loading) -> +Darkswarm.controller "LoginCtrl", ($scope, $http, $window, AuthenticationService, Redirections, Loading) -> $scope.path = "/login" $scope.submit = -> Loading.message = "Hold on a moment, we're logging you in" $http.post("/user/spree_user/sign_in", {spree_user: $scope.spree_user}).success (data)-> if Redirections.after_login - location.href = location.origin + Redirections.after_login + $window.location.href = $window.location.origin + Redirections.after_login else - location.href = location.origin + location.pathname # Strips out hash fragments + $window.location.href = $window.location.origin + $window.location.pathname # Strips out hash fragments .error (data) -> Loading.clear() $scope.errors = data.message diff --git a/app/assets/javascripts/darkswarm/controllers/checkout/checkout_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/checkout/checkout_controller.js.coffee index a5966e503b..e77712eae6 100644 --- a/app/assets/javascripts/darkswarm/controllers/checkout/checkout_controller.js.coffee +++ b/app/assets/javascripts/darkswarm/controllers/checkout/checkout_controller.js.coffee @@ -3,7 +3,7 @@ Darkswarm.controller "CheckoutCtrl", ($scope, storage, Checkout, CurrentUser, Cu # Bind to local storage $scope.fieldsToBind = ["bill_address", "email", "payment_method_id", "shipping_method_id", "ship_address"] - prefix = "order_#{Checkout.order.id}#{Checkout.order.user_id}#{CurrentHub.hub.id}" + prefix = "order_#{Checkout.order.id}#{CurrentUser?.id}#{CurrentHub.hub.id}" for field in $scope.fieldsToBind storage.bind $scope, "Checkout.order.#{field}", diff --git a/app/assets/javascripts/darkswarm/darkswarm.js.coffee b/app/assets/javascripts/darkswarm/darkswarm.js.coffee index 7a6cba7070..1e58fe7294 100644 --- a/app/assets/javascripts/darkswarm/darkswarm.js.coffee +++ b/app/assets/javascripts/darkswarm/darkswarm.js.coffee @@ -5,7 +5,6 @@ window.Darkswarm = angular.module("Darkswarm", ["ngResource", 'infinite-scroll', 'angular-flash.service', 'templates', - 'timer', 'ngSanitize', 'ngAnimate', 'google-maps', diff --git a/app/assets/javascripts/templates/price_breakdown.html.haml b/app/assets/javascripts/templates/price_breakdown.html.haml index 01588933ca..0b7eba917a 100644 --- a/app/assets/javascripts/templates/price_breakdown.html.haml +++ b/app/assets/javascripts/templates/price_breakdown.html.haml @@ -24,6 +24,9 @@ %li{"bo-if" => "variant.fees.transport"} .right {{ variant.fees.transport | currency }} Transport fee + %li{"bo-if" => "variant.fees.fundraising"} + .right {{ variant.fees.fundraising | currency }} + Fundraising fee %li %strong .right = {{ variant.price | currency }} diff --git a/app/assets/stylesheets/admin/openfoodnetwork.css.scss b/app/assets/stylesheets/admin/openfoodnetwork.css.scss index 87983a6bc7..3281c8d116 100644 --- a/app/assets/stylesheets/admin/openfoodnetwork.css.scss +++ b/app/assets/stylesheets/admin/openfoodnetwork.css.scss @@ -140,6 +140,24 @@ table#listing_enterprise_groups { } } +#no_results { + font-weight:bold; + color: #DA5354; +} + + +#loading { + text-align: center; + img.spinner { + width: 100px; + height: 100px; + } + h1 { + margin-top: 20px; + color: gray; + } +} + .ofn_drop_down { padding: 7px 15px; border-radius: 3px; diff --git a/app/assets/stylesheets/admin/products.css.scss b/app/assets/stylesheets/admin/products.css.scss index c8ceaaaac2..bddc7f9e9e 100644 --- a/app/assets/stylesheets/admin/products.css.scss +++ b/app/assets/stylesheets/admin/products.css.scss @@ -2,59 +2,6 @@ display: block; } -div.pagination { - div.pagenav { - margin: 0px; - span.first, span.prev, span.next, span.last { - padding: 5px 0px; - display:inline-block; - } - } -} - -div.pagination_info { - text-align: right; -} - - - -div.applied_filter { - margin-bottom: 5px; - border: solid 2px #5498da; - padding: 5px 0px; - border-radius: 5px; - div.four.columns { - padding-left: 10px; - } -} - -div.option_tabs { - div.applied_filters, div.filters, div.column_toggle { - margin-bottom: 10px; - } -} - -div.option_tab_titles { - h6 { - border-radius: 3px; - border: 1px solid #cee1f4; - padding: 3px; - text-align: center; - color: darken(#cee1f4, 3); - cursor: pointer; - -moz-user-select: none; - -khtml-user-select: none; - -webkit-user-select: none; - -ms-user-select: none; - user-select: none; - } - h6.selected { - border: 1px solid #5498da; - color: #5498da; - } - margin-bottom: 10px; -} - tbody.odd { tr.product { td { background-color: white; } } tr.variant.odd { td { background-color: lighten(#eff5fc, 3); } } @@ -76,41 +23,41 @@ th.left-actions, td.left-actions { border-right: 1px solid #cee1f4 !important; } -li.column-list-item { - border-radius: 3px; - padding: 2px 20px; - margin: 2px 1px; - background-color: white; - border: 2px solid lightgray; - color: darkgray; - font-size: 100%; - cursor: default; - text-align: center; - cursor: pointer; - -moz-user-select: none; - -khtml-user-select: none; - -webkit-user-select: none; - -ms-user-select: none; - user-select: none; -} - -li.column-list-item.selected { - border: 2px solid #5498da; - background-color: #5498da; - color: white; - font-size: 100%; -} - -ul.column-list { - list-style: none; +#update-status-message { + margin: 4px 0px; + font-weight: bold; } table#listing_products.bulk { clear: both; - td.supplier { - select { - width: 125px; + colgroup col { + &.producer { + width: 18%; + } + &.name { + width: 18%; + } + &.unit { + width: 14%; + } + &.display_as { + width: 12%; + } + &.price { + width: 10%; + } + &.on_hand { + width: 10%; + } + &.category { + width: 15%; + } + &.available_on { + width: 15%; + } + &.actions { + width: 3%; } } diff --git a/app/assets/stylesheets/darkswarm/home_tagline.css.sass b/app/assets/stylesheets/darkswarm/home_tagline.css.sass index ce8b275747..ed85e07d60 100644 --- a/app/assets/stylesheets/darkswarm/home_tagline.css.sass +++ b/app/assets/stylesheets/darkswarm/home_tagline.css.sass @@ -7,24 +7,19 @@ background-color: black background-image: url("/assets/home/ofn_bg_1.jpg") @include fullbg - height: 500px + height: 400px padding: 40px 0px - h1, h2, span, small, timer + h1, h2, p color: white - p - color: $clr-brick-light h1 - margin-bottom: 3rem + margin-bottom: 1em h2 font-size: 1.6875rem max-width: 610px margin: 0 auto - padding-bottom: 0.5rem a color: white &:hover, &:active, &:focus color: $clr-brick-light-bright @include textsoftpress - a.button.primary - color: white \ No newline at end of file diff --git a/app/controllers/spree/admin/payment_methods_controller_decorator.rb b/app/controllers/spree/admin/payment_methods_controller_decorator.rb index 11f707d9e6..7941deb9ee 100644 --- a/app/controllers/spree/admin/payment_methods_controller_decorator.rb +++ b/app/controllers/spree/admin/payment_methods_controller_decorator.rb @@ -1,25 +1,62 @@ -Spree::Admin::PaymentMethodsController.class_eval do - # Only show payment methods that user has access to and sort by distributor name - # ! Redundant code copied from Spree::Admin::ResourceController with modifications marked - def collection - return parent.send(controller_name) if parent_data.present? - collection = if model_class.respond_to?(:accessible_by) && - !current_ability.has_block?(params[:action], model_class) +module Spree + module Admin + PaymentMethodsController.class_eval do + skip_before_filter :load_resource, only: [:show_provider_preferences] + before_filter :load_hubs, only: [:new, :edit, :update] + create.before :load_hubs - model_class.accessible_by(current_ability, action) + # Only show payment methods that user has access to and sort by distributor name + # ! Redundant code copied from Spree::Admin::ResourceController with modifications marked + def collection + return parent.send(controller_name) if parent_data.present? + collection = if model_class.respond_to?(:accessible_by) && + !current_ability.has_block?(params[:action], model_class) - else - model_class.scoped - end + model_class.accessible_by(current_ability, action) - collection = collection.managed_by(spree_current_user).by_name # This line added + else + model_class.scoped + end - # This block added - if params.key? :enterprise_id - distributor = Enterprise.find params[:enterprise_id] - collection = collection.for_distributor(distributor) + collection = collection.managed_by(spree_current_user).by_name # This line added + + # This block added + if params.key? :enterprise_id + distributor = Enterprise.find params[:enterprise_id] + collection = collection.for_distributor(distributor) + end + + collection + end + + def show_provider_preferences + if params[:pm_id].present? + @payment_method = PaymentMethod.find(params[:pm_id]) + authorize! :show_provider_preferences, @payment_method + payment_method_type = params[:provider_type] + if @payment_method['type'].to_s != payment_method_type + @payment_method.update_column(:type, payment_method_type) + @payment_method = PaymentMethod.find(params[:pm_id]) + end + else + @payment_method = params[:provider_type].constantize.new() + end + render partial: 'provider_settings' + end + + private + + def load_data + if spree_current_user.admin? || Rails.env.test? + @providers = Gateway.providers.sort{|p1, p2| p1.name <=> p2.name } + else + @providers = Gateway.providers.reject{ |p| p.name.include? "Bogus" }.sort{|p1, p2| p1.name <=> p2.name } + end + end + + def load_hubs + @hubs = Enterprise.managed_by(spree_current_user).is_distributor.sort_by!{ |d| [(@payment_method.has_distributor? d) ? 0 : 1, d.name] } + end end - - collection end end diff --git a/app/controllers/spree/admin/products_controller_decorator.rb b/app/controllers/spree/admin/products_controller_decorator.rb index 4f0c592284..9f4fdbe46b 100644 --- a/app/controllers/spree/admin/products_controller_decorator.rb +++ b/app/controllers/spree/admin/products_controller_decorator.rb @@ -1,5 +1,5 @@ Spree::Admin::ProductsController.class_eval do - before_filter :load_spree_api_key, :only => :bulk_edit + before_filter :load_bpe_data, :only => :bulk_edit alias_method :location_after_save_original, :location_after_save @@ -31,9 +31,13 @@ Spree::Admin::ProductsController.class_eval do end if product_set.save - redirect_to "/api/products/managed?template=bulk_index;page=1;per_page=500;#{bulk_index_query}" + redirect_to "/api/products/bulk_products?page=1;per_page=500;#{bulk_index_query}" else - render :nothing => true, :status => 418 + if product_set.errors.present? + render json: { errors: product_set.errors }, status: 400 + else + render :nothing => true, :status => 500 + end end end @@ -78,8 +82,10 @@ Spree::Admin::ProductsController.class_eval do private - def load_spree_api_key + def load_bpe_data current_user.generate_spree_api_key! unless spree_current_user.spree_api_key @spree_api_key = spree_current_user.spree_api_key + @producers = Enterprise.managed_by(spree_current_user).is_primary_producer.order(:name) + @taxons = Spree::Taxon.order(:name) end end diff --git a/app/controllers/spree/admin/reports_controller_decorator.rb b/app/controllers/spree/admin/reports_controller_decorator.rb index 377f1dbedf..28174724dd 100644 --- a/app/controllers/spree/admin/reports_controller_decorator.rb +++ b/app/controllers/spree/admin/reports_controller_decorator.rb @@ -386,12 +386,23 @@ Spree::Admin::ReportsController.class_eval do table_items = @line_items @include_blank = 'All' - header = ["Producer", "Product", "Variant", "Amount", "Curr. Cost per Unit", "Total Cost", "Status", "Incoming Transport"] + header = ["Producer", "Product", "Variant", "Amount", "Total Units", "Curr. Cost per Unit", "Total Cost", "Status", "Incoming Transport"] + + ovn = OpenFoodNetwork::OptionValueNamer.new() columns = [ proc { |line_items| line_items.first.variant.product.supplier.name }, proc { |line_items| line_items.first.variant.product.name }, proc { |line_items| line_items.first.variant.full_name }, proc { |line_items| line_items.sum { |li| li.quantity } }, + proc { |line_items| ovn.name(OpenStruct.new({ + unit_value: ( line_items.map{ |li| li.variant.unit_value.nil? }.any? ? 0 : line_items.sum { |li| li.quantity * li.variant.unit_value } ), + unit_description: line_items.first.variant.unit_description, + product: OpenStruct.new({ + variant_unit: line_items.first.product.variant_unit, + variant_unit_scale: line_items.first.product.variant_unit_scale, + variant_unit_name: line_items.first.product.variant_unit_name + }) + }))}, proc { |line_items| line_items.first.variant.price }, proc { |line_items| line_items.sum { |li| li.quantity * li.price } }, proc { |line_items| "" }, diff --git a/app/controllers/spree/api/products_controller_decorator.rb b/app/controllers/spree/api/products_controller_decorator.rb index 77c1aa6632..7e81e1f789 100644 --- a/app/controllers/spree/api/products_controller_decorator.rb +++ b/app/controllers/spree/api/products_controller_decorator.rb @@ -7,6 +7,10 @@ Spree::Api::ProductsController.class_eval do respond_with(@products, default_template: :index) end + def bulk_products + @products = product_scope.ransack(params[:q]).result.managed_by(current_api_user).page(params[:page]).per(params[:per_page]) + render text: { products: ActiveModel::ArraySerializer.new(@products, each_serializer: Spree::Api::ProductSerializer), pages: @products.num_pages }.to_json + end def soft_delete authorize! :delete, Spree::Product diff --git a/app/helpers/admin/injection_helper.rb b/app/helpers/admin/injection_helper.rb index 4bbff9bf79..481e7912c6 100644 --- a/app/helpers/admin/injection_helper.rb +++ b/app/helpers/admin/injection_helper.rb @@ -12,6 +12,14 @@ module Admin admin_inject_json_ams_array "admin.shipping_methods", "shippingMethods", @shipping_methods, Api::Admin::IdNameSerializer end + def admin_inject_producers + admin_inject_json_ams_array "ofn.admin", "producers", @producers, Api::Admin::IdNameSerializer + end + + def admin_inject_taxons + admin_inject_json_ams_array "ofn.admin", "taxons", @taxons, Api::Admin::TaxonSerializer + end + def admin_inject_json_ams(ngModule, name, data, serializer, opts = {}) json = serializer.new(data).to_json render partial: "admin/json/injection_ams", locals: {ngModule: ngModule, name: name, json: json} diff --git a/app/helpers/checkout_helper.rb b/app/helpers/checkout_helper.rb index 171a672cda..6441cd619e 100644 --- a/app/helpers/checkout_helper.rb +++ b/app/helpers/checkout_helper.rb @@ -22,7 +22,7 @@ module CheckoutHelper end def checkout_cart_total_with_adjustments(order) - current_order.display_item_total.money.to_f + checkout_adjustments_total(current_order).money.to_f + order.display_item_total.money.to_f + checkout_adjustments_total(order).money.to_f end diff --git a/app/models/enterprise_fee.rb b/app/models/enterprise_fee.rb index f41ad76c96..6270f77b7a 100644 --- a/app/models/enterprise_fee.rb +++ b/app/models/enterprise_fee.rb @@ -10,7 +10,7 @@ class EnterpriseFee < ActiveRecord::Base attr_accessible :enterprise_id, :fee_type, :name, :calculator_type - FEE_TYPES = %w(packing transport admin sales) + FEE_TYPES = %w(packing transport admin sales fundraising) PER_ORDER_CALCULATORS = ['Spree::Calculator::FlatRate', 'Spree::Calculator::FlexiRate'] diff --git a/app/models/spree/ability_decorator.rb b/app/models/spree/ability_decorator.rb index e6d93f25aa..a04d966ee7 100644 --- a/app/models/spree/ability_decorator.rb +++ b/app/models/spree/ability_decorator.rb @@ -44,7 +44,7 @@ class AbilityDecorator # Enterprise User can only access payment methods for their distributors can [:index, :create], Spree::PaymentMethod - can [:admin, :read, :update, :fire, :resend, :destroy], Spree::PaymentMethod do |payment_method| + can [:admin, :read, :update, :fire, :resend, :destroy, :show_provider_preferences], Spree::PaymentMethod do |payment_method| (user.enterprises & payment_method.distributors).any? end diff --git a/app/models/spree/payment_method_decorator.rb b/app/models/spree/payment_method_decorator.rb index ddbc0251a9..01f6e2f0e8 100644 --- a/app/models/spree/payment_method_decorator.rb +++ b/app/models/spree/payment_method_decorator.rb @@ -4,6 +4,8 @@ Spree::PaymentMethod.class_eval do attr_accessible :distributor_ids + validates :distributors, presence: { message: "^At least one hub must be selected" } + # -- Scopes scope :managed_by, lambda { |user| if user.has_spree_role?('admin') @@ -30,4 +32,19 @@ end # Ensure that all derived classes also allow distributor_ids Spree::Gateway.providers.each do |p| p.attr_accessible :distributor_ids + p.instance_eval do + def clean_name + case name + when "Spree::PaymentMethod::Check" + "Cash/EFT/etc. (payments for which automatic validation is not required)" + when "Spree::Gateway::Migs" + "MasterCard Internet Gateway Service (MIGS)" + when "Spree::Gateway::PayPalExpress" + "PayPal Express" + else + i = name.rindex('::') + 2 + name[i..-1] + end + end + end end diff --git a/app/overrides/spree/admin/payment_methods/_form/add_distributors.html.haml.deface b/app/overrides/spree/admin/payment_methods/_form/add_distributors.html.haml.deface deleted file mode 100644 index 0ed490a94a..0000000000 --- a/app/overrides/spree/admin/payment_methods/_form/add_distributors.html.haml.deface +++ /dev/null @@ -1,8 +0,0 @@ -/ insert_before '[data-hook="environment"]' - -= f.field_container :distributors do - = f.label :distributors - %br - - distributors = Enterprise.is_distributor.managed_by(spree_current_user) | f.object.distributors - = f.collection_select(:distributor_ids, distributors, :id, :name, {include_blank: false}, {class: "select2 fullwidth", multiple: true}) - = f.error_message_on :distributors diff --git a/app/overrides/spree/admin/payment_methods/_form/remove_clearing_div.deface b/app/overrides/spree/admin/payment_methods/_form/remove_clearing_div.deface new file mode 100644 index 0000000000..613ffe010b --- /dev/null +++ b/app/overrides/spree/admin/payment_methods/_form/remove_clearing_div.deface @@ -0,0 +1 @@ +remove "div.clear" \ No newline at end of file diff --git a/app/overrides/spree/admin/payment_methods/_form/replace_form_fields.html.haml.deface b/app/overrides/spree/admin/payment_methods/_form/replace_form_fields.html.haml.deface new file mode 100644 index 0000000000..3b588a98c1 --- /dev/null +++ b/app/overrides/spree/admin/payment_methods/_form/replace_form_fields.html.haml.deface @@ -0,0 +1,36 @@ +/ replace "div[data-hook='admin_payment_method_form_fields']" + +%div.alpha.eleven.columns + .row + .alpha.three.columns + = label_tag nil, t(:name) + .omega.eight.columns + = text_field :payment_method, :name, :class => 'fullwidth' + .row + .alpha.three.columns + = label_tag nil, t(:description) + .omega.eight.columns + = text_area :payment_method, :description, {:cols => 60, :rows => 6, :class => 'fullwidth'} + - if spree_current_user.admin? + .row + .alpha.three.columns + = label_tag nil, t(:environment) + .omega.eight.columns + = collection_select(:payment_method, :environment, Rails.configuration.database_configuration.keys.sort, :to_s, :titleize, {}, {:id => 'gtwy-env', :class => 'select2 fullwidth'}) + .row + .alpha.three.columns + = label_tag nil, t(:display) + .omega.eight.columns + = select(:payment_method, :display_on, Spree::PaymentMethod::DISPLAY.collect { |display| [t(display), display == :both ? nil : display.to_s] }, {}, {:class => 'select2 fullwidth'}) + .row + .alpha.three.columns + = label_tag nil, t(:active) + .two.columns + = radio_button :payment_method, :active, true +   + = label_tag nil, t(:say_yes) + .omega.six.columns + = radio_button :payment_method, :active, false +   + = label_tag nil, t(:say_no) + = render 'providers' \ No newline at end of file diff --git a/app/overrides/spree/admin/payment_methods/edit/add_hubs_sidebar.html.haml.deface b/app/overrides/spree/admin/payment_methods/edit/add_hubs_sidebar.html.haml.deface new file mode 100644 index 0000000000..26ee2888bd --- /dev/null +++ b/app/overrides/spree/admin/payment_methods/edit/add_hubs_sidebar.html.haml.deface @@ -0,0 +1,5 @@ +/ insert_after "code[erb-loud]:contains(\"render :partial => 'form', :locals => { :f => f }\")" + +.one.column   += render :partial => 'spree/admin/shared/hubs_sidebar', :locals => { f: f, klass: :payment_method } +.clear \ No newline at end of file diff --git a/app/overrides/spree/admin/payment_methods/edit/remove_configuration_sidebar.deface b/app/overrides/spree/admin/payment_methods/edit/remove_configuration_sidebar.deface new file mode 100644 index 0000000000..cc3fbcdee1 --- /dev/null +++ b/app/overrides/spree/admin/payment_methods/edit/remove_configuration_sidebar.deface @@ -0,0 +1 @@ +remove "code[erb-loud]:contains(\"render :partial => 'spree/admin/shared/configuration_menu'\")" \ No newline at end of file diff --git a/app/overrides/spree/admin/payment_methods/new/add_hubs_sidebar.html.haml.deface b/app/overrides/spree/admin/payment_methods/new/add_hubs_sidebar.html.haml.deface new file mode 100644 index 0000000000..26ee2888bd --- /dev/null +++ b/app/overrides/spree/admin/payment_methods/new/add_hubs_sidebar.html.haml.deface @@ -0,0 +1,5 @@ +/ insert_after "code[erb-loud]:contains(\"render :partial => 'form', :locals => { :f => f }\")" + +.one.column   += render :partial => 'spree/admin/shared/hubs_sidebar', :locals => { f: f, klass: :payment_method } +.clear \ No newline at end of file diff --git a/app/overrides/spree/admin/payment_methods/new/remove_configuration_sidebar.deface b/app/overrides/spree/admin/payment_methods/new/remove_configuration_sidebar.deface new file mode 100644 index 0000000000..cc3fbcdee1 --- /dev/null +++ b/app/overrides/spree/admin/payment_methods/new/remove_configuration_sidebar.deface @@ -0,0 +1 @@ +remove "code[erb-loud]:contains(\"render :partial => 'spree/admin/shared/configuration_menu'\")" \ No newline at end of file diff --git a/app/overrides/spree/admin/shipping_methods/_form/replace_form_fields.html.haml.deface b/app/overrides/spree/admin/shipping_methods/_form/replace_form_fields.html.haml.deface index 5d0fce3841..190cff1a17 100644 --- a/app/overrides/spree/admin/shipping_methods/_form/replace_form_fields.html.haml.deface +++ b/app/overrides/spree/admin/shipping_methods/_form/replace_form_fields.html.haml.deface @@ -1,6 +1,6 @@ / replace "div[data-hook='admin_shipping_method_form_fields']" -.alpha.twelve.columns{"data-hook" => "admin_shipping_method_form_fields"} +.alpha.eleven.columns{"data-hook" => "admin_shipping_method_form_fields"} .row .alpha.three.columns = f.label :name, t(:name) @@ -41,7 +41,7 @@ = f.radio_button :require_ship_address, true   = f.label :delivery, t(:delivery) - .six.columns + .omega.six.columns = f.radio_button :require_ship_address, false   = f.label :pick_up, t(:pick_up) diff --git a/app/overrides/spree/admin/shipping_methods/edit/add_hubs_sidebar.html.haml.deface b/app/overrides/spree/admin/shipping_methods/edit/add_hubs_sidebar.html.haml.deface index 74fc957e71..057013c5a6 100644 --- a/app/overrides/spree/admin/shipping_methods/edit/add_hubs_sidebar.html.haml.deface +++ b/app/overrides/spree/admin/shipping_methods/edit/add_hubs_sidebar.html.haml.deface @@ -1,3 +1,4 @@ / insert_after "code[erb-loud]:contains(\"render :partial => 'form', :locals => { :f => f }\")" -= render :partial => 'spree/admin/shared/hubs_sidebar', :locals => { :f => f } \ No newline at end of file +.one.column   += render :partial => 'spree/admin/shared/hubs_sidebar', :locals => { f: f, klass: :shipping_method } \ No newline at end of file diff --git a/app/overrides/spree/admin/shipping_methods/new/add_hubs_sidebar.html.haml.deface b/app/overrides/spree/admin/shipping_methods/new/add_hubs_sidebar.html.haml.deface index 74fc957e71..057013c5a6 100644 --- a/app/overrides/spree/admin/shipping_methods/new/add_hubs_sidebar.html.haml.deface +++ b/app/overrides/spree/admin/shipping_methods/new/add_hubs_sidebar.html.haml.deface @@ -1,3 +1,4 @@ / insert_after "code[erb-loud]:contains(\"render :partial => 'form', :locals => { :f => f }\")" -= render :partial => 'spree/admin/shared/hubs_sidebar', :locals => { :f => f } \ No newline at end of file +.one.column   += render :partial => 'spree/admin/shared/hubs_sidebar', :locals => { f: f, klass: :shipping_method } \ No newline at end of file diff --git a/app/serializers/api/admin/taxon_serializer.rb b/app/serializers/api/admin/taxon_serializer.rb new file mode 100644 index 0000000000..61766c87cf --- /dev/null +++ b/app/serializers/api/admin/taxon_serializer.rb @@ -0,0 +1,3 @@ +class Api::Admin::TaxonSerializer < ActiveModel::Serializer + attributes :id, :name, :pretty_name +end \ No newline at end of file diff --git a/app/serializers/spree/api/product_serializer.rb b/app/serializers/spree/api/product_serializer.rb new file mode 100644 index 0000000000..aa8919f8d6 --- /dev/null +++ b/app/serializers/spree/api/product_serializer.rb @@ -0,0 +1,26 @@ +class Spree::Api::ProductSerializer < ActiveModel::Serializer + attributes :id, :name, :variant_unit, :variant_unit_scale, :variant_unit_name, :on_demand + + attributes :on_hand, :price, :available_on, :permalink_live + + has_one :supplier, key: :producer, embed: :id + has_one :primary_taxon, key: :category, embed: :id + has_many :variants, key: :variants, serializer: Spree::Api::VariantSerializer # embed: ids + has_one :master, serializer: Spree::Api::VariantSerializer + + def on_hand + object.on_hand.nil? ? 0 : object.on_hand.to_f.finite? ? object.on_hand : "On demand" + end + + def price + object.price.nil? ? '0.0' : object.price + end + + def available_on + object.available_on.blank? ? "" : object.available_on.strftime("%F %T") + end + + def permalink_live + object.permalink + end +end \ No newline at end of file diff --git a/app/serializers/spree/api/variant_serializer.rb b/app/serializers/spree/api/variant_serializer.rb new file mode 100644 index 0000000000..f594a540ef --- /dev/null +++ b/app/serializers/spree/api/variant_serializer.rb @@ -0,0 +1,12 @@ +class Spree::Api::VariantSerializer < ActiveModel::Serializer + attributes :id, :options_text, :unit_value, :unit_description, :on_demand, :display_as, :display_name + attributes :on_hand, :price + + def on_hand + object.on_hand.nil? ? 0 : ( object.on_hand.to_f.finite? ? object.on_hand : "On demand" ) + end + + def price + object.price.nil? ? 0.to_f : object.price + end +end \ No newline at end of file diff --git a/app/views/home/index.html.haml b/app/views/home/index.html.haml index cd220f3d53..63d2216052 100644 --- a/app/views/home/index.html.haml +++ b/app/views/home/index.html.haml @@ -2,16 +2,10 @@ .row .small-12.text-center.columns %h1= image_tag "ofn_logo_beta.png", title: "Open Food Network (beta)" - %h2 We're crowdfunding right now! - %h5 - %timer{"end-time" => '1407679200000'} - {{days}} days, {{hours}} hrs, {{minutes}} mins & {{seconds}} secs to go - %p Help us make Open Food Network the best it can be: - %a.button.primary{href: "http://startsomegood.com/openfoodnetwork", target:"_blank"} Support now - / %h2 An open marketplace that makes it easy to find, buy, sell and move sustainable local food. - %br - %ofn-modal{title: "Learn more"} - = render partial: "modals/learn_more" + %h2 An open marketplace that makes it easy to find, buy, sell and move sustainable local food. + + %ofn-modal{title: "Learn more"} + = render partial: "modals/learn_more" = render partial: "home/hubs" diff --git a/app/views/spree/admin/orders/bulk_management.html.haml b/app/views/spree/admin/orders/bulk_management.html.haml index a73c0cea07..08a05595c5 100644 --- a/app/views/spree/admin/orders/bulk_management.html.haml +++ b/app/views/spree/admin/orders/bulk_management.html.haml @@ -92,10 +92,11 @@ %div.menu_item{ :class => "three columns alpha", 'ng-repeat' => "column in columns", 'ofn-toggle-column' => true } %span{ :class => 'one column alpha', :style => 'text-align: center'} {{ column.visible && "✓" || !column.visible && " " }} %span{ :class => 'two columns omega' } {{column.name }} - %div.loading{ :class => "sixteen columns alpha", 'ng-show' => 'loading' } - %h4 Loading Line Items... + %div.sixteen.columns.alpha#loading{ 'ng-if' => 'loading' } + %img.spinner{ src: "/assets/loading.gif" } + %h1 LOADING ORDERS %div{ :class => "sixteen columns alpha", 'ng-show' => '!loading && filteredLineItems.length == 0'} - %h4{ :style => 'color:red;' } No matching line items found. + %h1#no_results No orders found. %div{ 'ng-hide' => 'loading || filteredLineItems.length == 0' } %table.index#listing_orders.bulk{ :class => "sixteen columns alpha" } %thead diff --git a/app/views/spree/admin/payment_methods/_provider_settings.html.haml b/app/views/spree/admin/payment_methods/_provider_settings.html.haml new file mode 100644 index 0000000000..e227180fc3 --- /dev/null +++ b/app/views/spree/admin/payment_methods/_provider_settings.html.haml @@ -0,0 +1,7 @@ +- if @payment_method.preferences.present? + %fieldset.alpha.eleven.columns.no-border-bottom#gateway_fields + %legend{ align: "center"} + = t(:provider_settings) + .preference-settings + = fields_for :payment_method, @payment_method do |payment_method_form| + = preference_fields(@payment_method, payment_method_form) \ No newline at end of file diff --git a/app/views/spree/admin/payment_methods/_providers.html.haml b/app/views/spree/admin/payment_methods/_providers.html.haml new file mode 100644 index 0000000000..77b11fb473 --- /dev/null +++ b/app/views/spree/admin/payment_methods/_providers.html.haml @@ -0,0 +1,10 @@ +:javascript + angular.module('ofn.admin').value('paymentMethod', #{ { id: @payment_method.id, type: @payment_method.type }.to_json }) +#provider-settings{ ng: { app: "ofn.admin", controller: "ProvidersCtrl" } } + .row + .alpha.three.columns + = label :payment_method, :type, t(:provider) + .omega.eight.columns + = collection_select(:payment_method, :type, @providers, :to_s, :clean_name, (!@object.persisted? ? { :selected => "Spree::PaymentMethod::Check"} : {}), { class: 'select2 fullwidth', 'provider-prefs-for' => "#{@object.id}"}) + + %div{"ng-include" => "include_html" } \ No newline at end of file diff --git a/app/views/spree/admin/products/bulk_edit.html.haml b/app/views/spree/admin/products/bulk_edit.html.haml index d1cdd6324f..206a336a5e 100644 --- a/app/views/spree/admin/products/bulk_edit.html.haml +++ b/app/views/spree/admin/products/bulk_edit.html.haml @@ -12,117 +12,87 @@ %div#new_product(data-hook) - +=admin_inject_producers +=admin_inject_taxons %div{ 'ng-app' => 'ofn.admin', 'ng-controller' => 'AdminProductEditCtrl', 'ng-init' => "initialise('#{@spree_api_key}');loading=true;" } + %div.sixteen.columns.alpha + %div.quick_search{ :class => "four columns alpha" } + %label{ :for => 'quick_filter' } + %br + %input.search{ :class => "four columns alpha", 'ng-model' => 'query', :name => "quick_filter", :type => 'text', 'placeholder' => 'Quick Search' } + .filter_select{ :class => "four columns" } + %label{ :for => 'producer_filter' }Producer + %br + %select{ :class => "four columns alpha", :id => 'producer_filter', 'ofn-select2-min-search' => 5, 'ng-model' => 'producerFilter', 'ng-options' => 'producer.id as producer.name for producer in filterProducers' } + .filter_select{ :class => "four columns" } + %label{ :for => 'category_filter' }Category + %br + %select{ :class => "four columns alpha", :id => 'category_filter', 'ofn-select2-min-search' => 5, 'ng-model' => 'categoryFilter', 'ng-options' => 'taxon.id as taxon.name for taxon in filterTaxons'} + %div{ :class => "one column" }   + .filter_clear{ :class => "three columns omega" } + %label{ :for => 'clear_all_filters' } + %br + %input.fullwidth{ :type => 'button', :id => 'clear_all_filters', :value => "Clear Filters", 'ng-click' => "resetSelectFilters()" } + %hr.sixteen.columns.alpha + %div.sixteen.columns.alpha{ 'ng-hide' => 'loading || products.length == 0', style: "margin-bottom: 10px" } + %div.four.columns.alpha + %input.four.columns.alpha{ :type => 'button', :value => 'Save Changes', 'ng-click' => 'submitProducts()'} + %div.nine.columns + %h6{ id: "update-status-message", ng: { style: 'updateStatusMessage.style' } } + {{ updateStatusMessage.text || " " }} + %div.three.columns.omega + %div.ofn_drop_down.three.columns.omega{ 'ng-controller' => "DropDownCtrl", :id => "columns_dropdown", 'ofn-drop-down' => true, :style => 'float:right;' } + %span{ :class => 'icon-reorder' }   Columns + %span{ 'ng-class' => "expanded && 'icon-caret-up' || !expanded && 'icon-caret-down'" } + %div.menu{ 'ng-show' => "expanded" } + %div.menu_item{ :class => "three columns alpha", 'ng-repeat' => "column in columns", 'ofn-toggle-column' => true } + %span{ :class => 'one column alpha', :style => 'text-align: center'} {{ column.visible && "✓" || !column.visible && " " }} + %span{ :class => 'two columns omega' } {{column.name }} %div{ 'ng-show' => '!spree_api_key_ok' } {{ api_error_msg }} - %div.option_tab_titles{ :class => "sixteen columns alpha" } - %h6{ :class => "three columns alpha", 'ng-repeat' => "tab in optionTabs", "ng-click" => "shiftTab(tab)", "ng-class" => "tab.visible && 'selected' || !tab.visible && 'unselected'"} - {{ tab.title }} - %div.option_tabs{ :class => "sixteen columns alpha" } - %div.filters{ :class => "sixteen columns alpha", "ng-show" => 'optionTabs.filters.visible' } - %div{ :class => "four columns alpha" } - Column: - %br.clear - %select.fullwidth{ 'ng-model' => 'filterProperty', :id => "filter_property", 'ng-options' => 'fc.name for fc in filterableColumns', 'ofn-select2-min-search' => 10 } - %div{ :class => "four columns omega" } - Filter Type: - %br.clear - %select.fullwidth{ 'ng-model' => 'filterPredicate', :id => "filter_predicate", 'ng-options' => 'ft.name for ft in filterTypes', 'ofn-select2-min-search' => 10 } - %div{ :class => "six columns omega" } - Value: - %br.clear - %input{ :class => "four columns alpha", 'ng-model' => 'filterValue', :id => "filter_value", :type => "text", 'placeholder' => 'Filter Value' } - %div{ :class => "two columns omega" } -   - %input.fullwidth{ :name => "add_filter", :value => "Apply Filter", :type => "button", "ng-click" => "addFilter({property:filterProperty,predicate:filterPredicate,value:filterValue})" } - %div.applied_filters{ :class => "sixteen columns alpha", "ng-show" => 'optionTabs.filters.visible && currentFilters.length > 0' } - %div.applied_filter{ :class => "sixteen columns alpha", 'ng-repeat' => 'filter in currentFilters' } - %div{ :class => "four columns alpha" } - {{ filter.property.name }} - %div{ :class => "four columns omega" } - {{ filter.predicate.name }} - %div{ :class => "six columns omega" } - {{ filter.value }} - %div{ :class => "two columns omega" } - %a{ :href => "#", 'ng-click' => "removeFilter(filter)" } Remove Filter - %div.column_toggle{ :class => "sixteen columns alpha", "ng-show" => 'optionTabs.column_toggle.visible' } - %ul.column-list{ :class => "sixteen columns alpha" } - %li.column-list-item{ :class => "three columns alpha", 'ofn-toggle-column' => 'column', 'ng-repeat' => 'column in columns' } - {{ column.name }} - %hr - %div.sixteen.columns.alpha.loading{ 'ng-show' => 'loading' } - %h4 Loading Products... - %div.sixteen.columns.alpha{ 'ng-show' => '!loading && products.length == 0' } - %h4{ :style => 'color:red;' } No matching products found. - %div.sixteen.columns.alpha{ 'ng-show' => '!loading && products.length == 500' } - %h6 Search returned too many products to display (500+), please apply more search filters to reduce the number of matching products - %div.sixteen.columns.alpha{ 'ng-hide' => 'loading || products.length == 500 || products.length == 0' } - %div.quick_search{ :class => "five columns omega" } - %input.search{ :class => "four columns alpha", 'ng-model' => 'query', :name => "quick_filter", :type => 'text', 'placeholder' => 'Quick Search' } - %div.pagination{ :class => "seven columns omega" } - %div.pagenav{ :class => "two columns alpha" } - %span.first - %a{ :href => "#", 'ng-click' => "currentPage = 1", 'ng-show' => "currentPage > 1" } - « First - %span.prev - %a{ :href => "#", 'ng-click' => "currentPage = currentPage - 1", 'ng-show' => "currentPage > 1" } - ‹ Prev - %div.pagenav{ :class => "columns omega" } - %span.page{ 'ng-repeat' => "page in [] | rangeArray:minPage():maxPage()", 'ng-class' => "{current: currentPage==page}" } - %a{ :href => "#", 'ng-click' => "setPage(page)" } - {{page}} - %span{ 'ng-show' => "maxPage() < totalPages()" } ... - %div.pagenav{ :class => "two columns omega" } - %span.next - %a{ :href => "#", 'ng-click' => "currentPage = currentPage + 1", 'ng-show' => "currentPage < totalPages()" } - Next › - %span.last - %a{ :href => "#", 'ng-click' => "currentPage = totalPages()", 'ng-show' => "currentPage < totalPages()" } - Last » - %div.pagination_info{ :class => 'four columns alpha' } - Show  - %select{ 'ng-model' => 'perPage', :name => 'perPage', 'ng-options' => 'pp for pp in [25,50,100,200]'} -  per page - %br - %span Displaying {{firstVisibleProduct()}}-{{lastVisibleProduct()}} of {{totalCount()}} products - %table.index#listing_products.bulk + %div.sixteen.columns.alpha#loading{ 'ng-if' => 'loading' } + %img.spinner{ src: "/assets/loading.gif" } + %h1 LOADING PRODUCTS + %div.sixteen.columns.alpha{ 'ng-show' => '!loading && filteredProducts.length == 0' } + %h1#no_results No products found. + %div.sixteen.columns.alpha{ 'ng-hide' => 'loading || filteredProducts.length == 0' } + %table.index#listing_products.bulk{ "infinite-scroll" => "incrementLimit()", "infinite-scroll-distance" => "1" } %colgroup - %col - %col - %col{'style' => 'width: 20%;'} - %col{'style' => 'width: 12%;'} - %col{'style' => 'width: 12%;'} - %col{'style' => 'width: 12%;'} - %col - %col - %col - %col - %col - %col + %col.actions + %col.producer{ ng: { show: 'columns.producer.visible' } } + %col.name{ ng: { show: 'columns.name.visible' } } + %col.unit{ ng: { show: 'columns.unit.visible' } } + %col.display_as{ ng: { show: 'columns.unit.visible' } } + %col.price{ ng: { show: 'columns.price.visible'} } + %col.on_hand{ ng: { show: 'columns.on_hand.visible' } } + %col.category{ ng: { show: 'columns.category.visible' } } + %col.available_on{ ng: { show: 'columns.available_on.visible' } } + %col.actions + %col.actions + %col.actions %thead %tr %th.left-actions - %th{ 'ng-show' => 'columns.supplier.visible' } Supplier - %th{ 'ng-show' => 'columns.name.visible' } Name - %th{ 'ng-show' => 'columns.unit.visible' } Unit / Value - %th{ 'ng-show' => 'columns.unit.visible' } Display As - %th{ 'ng-show' => 'columns.price.visible' } Price - %th{ 'ng-show' => 'columns.on_hand.visible' } On Hand - %th{ 'ng-show' => 'columns.taxons.visible' } Taxons - %th{ 'ng-show' => 'columns.available_on.visible' } Av. On + %th.producer{ 'ng-show' => 'columns.producer.visible' } Producer + %th.name{ 'ng-show' => 'columns.name.visible' } Name + %th.unit{ 'ng-show' => 'columns.unit.visible' } Unit / Value + %th.display_as{ 'ng-show' => 'columns.unit.visible' } Display As + %th.price{ 'ng-show' => 'columns.price.visible' } Price + %th.on_hand{ 'ng-show' => 'columns.on_hand.visible' } On Hand + %th.category{ 'ng-show' => 'columns.category.visible' } Category + %th.available_on{ 'ng-show' => 'columns.available_on.visible' } Av. On %th.actions %th.actions %th.actions - %tbody{ 'ng-repeat' => 'product in filteredProducts = (products | filter:query)', 'ng-class-even' => "'even'", 'ng-class-odd' => "'odd'", 'ng-show' => "$index >= perPage*(currentPage-1) && $index < perPage*currentPage" } + %tbody{ 'ng-repeat' => 'product in filteredProducts = ( products | filter:query | producer: producerFilter | category: categoryFilter | limitTo:limit )', 'ng-class-even' => "'even'", 'ng-class-odd' => "'odd'" } %tr.product{ :id => "p_{{product.id}}" } %td.left-actions %a{ 'ofn-toggle-variants' => 'true', :class => "view-variants icon-chevron-right", 'ng-show' => 'hasVariants(product)' } %a{ :class => "add-variant icon-plus-sign", 'ng-click' => "addVariant(product)", 'ng-show' => "!hasVariants(product) && hasUnit(product)" } - %td.supplier{ 'ng-show' => 'columns.supplier.visible' } - %select.select2{ 'ng-model' => 'product.supplier', :name => 'supplier', 'ofn-track-product' => 'supplier', 'ng-options' => 's.name for s in suppliers' } - %td{ 'ng-show' => 'columns.name.visible' } + %td.producer{ 'ng-show' => 'columns.producer.visible' } + %select.select2.fullwidth{ 'ng-model' => 'product.producer', :name => 'producer', 'ofn-track-product' => 'producer', 'ng-options' => 'producer.id as producer.name for producer in producers' } + %td.name{ 'ng-show' => 'columns.name.visible' } %input{ 'ng-model' => "product.name", :name => 'product_name', 'ofn-track-product' => 'name', :type => 'text' } %td.unit{ 'ng-show' => 'columns.unit.visible' } %select.select2{ 'ng-model' => 'product.variant_unit_with_scale', :name => 'variant_unit_with_scale', 'ofn-track-product' => 'variant_unit_with_scale', 'ng-options' => 'unit[1] as unit[0] for unit in variant_unit_options' } @@ -131,14 +101,14 @@ %input{ 'ng-model' => 'product.variant_unit_name', :name => 'variant_unit_name', 'ofn-track-product' => 'variant_unit_name', :placeholder => 'unit', 'ng-show' => "product.variant_unit_with_scale == 'items'", :type => 'text' } %td.display_as{ 'ng-show' => 'columns.unit.visible' } %input{ 'ofn-display-as' => 'product.master', name: 'display_as', 'ofn-track-master' => 'display_as', type: 'text', placeholder: '{{ placeholder_text }}', ng: { hide: 'hasVariants(product)', model: 'product.master.display_as' } } - %td{ 'ng-show' => 'columns.price.visible' } + %td.price{ 'ng-show' => 'columns.price.visible' } %input{ 'ng-model' => 'product.price', 'ofn-decimal' => :true, :name => 'price', 'ofn-track-product' => 'price', :type => 'text', 'ng-hide' => 'hasVariants(product)' } - %td{ 'ng-show' => 'columns.on_hand.visible' } + %td.on_hand{ 'ng-show' => 'columns.on_hand.visible' } %span{ 'ng-bind' => 'product.on_hand', :name => 'on_hand', 'ng-show' => '!hasOnDemandVariants(product) && (hasVariants(product) || product.on_demand)' } %input.field{ 'ng-model' => 'product.on_hand', :name => 'on_hand', 'ofn-track-product' => 'on_hand', 'ng-hide' => 'hasVariants(product) || product.on_demand', :type => 'number' } - %td{ 'ng-if' => 'columns.taxons.visible' } - %input.fullwidth{ :type => 'text', 'ng-model' => 'product.taxon_ids', 'ofn-taxon-autocomplete' => '', 'ofn-track-product' => 'taxon_ids' } - %td{ 'ng-show' => 'columns.available_on.visible' } + %td.category{ 'ng-if' => 'columns.category.visible' } + %input.fullwidth{ :type => 'text', id: "p{{product.id}}_category", 'ng-model' => 'product.category', 'ofn-taxon-autocomplete' => '', 'ofn-track-product' => 'category' } + %td.available_on{ 'ng-show' => 'columns.available_on.visible' } %input{ 'ng-model' => 'product.available_on', :name => 'available_on', 'ofn-track-product' => 'available_on', 'datetimepicker' => 'product.available_on', type: "text" } %td.actions %a{ 'ng-click' => 'editWarn(product)', :class => "edit-product icon-edit no-text" } @@ -146,11 +116,11 @@ %a{ 'ng-click' => 'cloneProduct(product)', :class => "clone-product icon-copy no-text" } %td.actions %a{ 'ng-click' => 'deleteProduct(product)', :class => "delete-product icon-trash no-text" } - %tr.variant{ 'ng-repeat' => 'variant in product.variants', 'ng-show' => 'displayProperties[product.id].showVariants', 'ng-class-even' => "'even'", 'ng-class-odd' => "'odd'" } + %tr.variant{ :id => "v_{{variant.id}}", 'ng-repeat' => 'variant in product.variants', 'ng-show' => 'displayProperties[product.id].showVariants', 'ng-class-even' => "'even'", 'ng-class-odd' => "'odd'" } %td.left-actions %a{ :class => "variant-item icon-caret-right", 'ng-hide' => "$last" } %a{ :class => "add-variant icon-plus-sign", 'ng-click' => "addVariant(product)", 'ng-show' => "$last" } - %td{ 'ng-show' => 'columns.supplier.visible' } + %td{ 'ng-show' => 'columns.producer.visible' } %td{ 'ng-show' => 'columns.name.visible' } %input{ 'ng-model' => 'variant.display_name', :name => 'variant_display_name', 'ofn-track-variant' => 'display_name', :type => 'text', placeholder: "{{ product.name }}" } %td.unit_value{ 'ng-show' => 'columns.unit.visible' } @@ -162,13 +132,10 @@ %td{ 'ng-show' => 'columns.on_hand.visible' } %input.field{ 'ng-model' => 'variant.on_hand', 'ng-change' => 'updateOnHand(product)', :name => 'variant_on_hand', 'ng-hide' => 'variant.on_demand', 'ofn-track-variant' => 'on_hand', :type => 'number' } %span{ 'ng-bind' => 'variant.on_hand', :name => 'variant_on_hand', 'ng-show' => 'variant.on_demand' } - %td{ 'ng-show' => 'columns.taxons.visible' } + %td{ 'ng-show' => 'columns.category.visible' } %td{ 'ng-show' => 'columns.available_on.visible' } %td.actions %a{ 'ng-click' => 'editWarn(product,variant)', :class => "edit-variant icon-edit no-text", 'ng-show' => "variantSaved(variant)" } %td.actions %td.actions %a{ 'ng-click' => 'deleteVariant(product,variant)', :class => "delete-variant icon-trash no-text" } - %input{ :type => 'button', :value => 'Update', 'ng-click' => 'submitProducts()'} - %span{ id: "update-status-message", 'ng-style' => 'updateStatusMessage.style' } - {{ updateStatusMessage.text }} diff --git a/app/views/spree/admin/shared/_hubs_sidebar.html.haml b/app/views/spree/admin/shared/_hubs_sidebar.html.haml index 445a45ea6c..cdd367065a 100644 --- a/app/views/spree/admin/shared/_hubs_sidebar.html.haml +++ b/app/views/spree/admin/shared/_hubs_sidebar.html.haml @@ -5,13 +5,13 @@ %span.four.columns.alpha.centered Hubs .four.columns.alpha.list{ class: "#{hubs_color}" } - if @hubs.count > 0 - = f.hidden_field :distributor_ids, :multiple => true, value: nil + = hidden_field klass, :distributor_ids, :multiple => true, value: nil - @hubs.each do |hub| %span.four.columns.alpha.list-item{ class: "#{cycle('odd','even')}" } %a.three.columns.alpha{ href: "#{main_app.edit_admin_enterprise_path(hub)}" } = hub.name %span.one.column.omega - = f.check_box :distributor_ids, { multiple: true }, hub.id, nil + = check_box klass, :distributor_ids, { multiple: true }, hub.id, nil - else .four.columns.alpha.list-item %span.three.columns.alpha None Available diff --git a/app/views/spree/order_mailer/confirm_email.text.erb b/app/views/spree/order_mailer/confirm_email.text.erb index a72ada83e2..932eaebe4c 100644 --- a/app/views/spree/order_mailer/confirm_email.text.erb +++ b/app/views/spree/order_mailer/confirm_email.text.erb @@ -10,8 +10,8 @@ Order for: <%= @order.bill_address.full_name %> <%= item.variant.sku %> <%= raw(item.variant.product.supplier.name) %> <%= raw(item.variant.product.name) %> <%= raw(item.variant.options_text) -%> (QTY: <%=item.quantity%>) @ <%= item.single_money %> = <%= item.display_amount %> <% end %> ============================================================ -Subtotal: <%= @order.display_item_total %> -<% checkout_adjustments_for_summary(@order).each do |adjustment| %> +Subtotal: <%= number_to_currency checkout_cart_total_with_adjustments(@order) %> +<% checkout_adjustments_for_summary(@order, exclude: [:distribution]).each do |adjustment| %> <%= raw(adjustment.label) %> <%= adjustment.display_amount %> <% end %> Order Total: <%= @order.display_total %> diff --git a/config/routes.rb b/config/routes.rb index 75516552a4..b9c0a2da55 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -107,6 +107,7 @@ Spree::Core::Engine.routes.prepend do match '/admin/reports/products_and_inventory' => 'admin/reports#products_and_inventory', :as => "products_and_inventory_admin_reports", :via => [:get, :post] match '/admin/reports/customers' => 'admin/reports#customers', :as => "customers_admin_reports", :via => [:get, :post] match '/admin', :to => 'admin/overview#index', :as => :admin + match '/admin/payment_methods/show_provider_preferences' => 'admin/payment_methods#show_provider_preferences', :via => :get namespace :api, :defaults => { :format => 'json' } do @@ -116,6 +117,7 @@ Spree::Core::Engine.routes.prepend do resources :products do get :managed, on: :collection + get :bulk_products, on: :collection delete :soft_delete resources :variants do diff --git a/db/schema.rb b/db/schema.rb index 7b31f581f1..84b51e8b93 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -553,9 +553,9 @@ ActiveRecord::Schema.define(:version => 20140723023713) do t.string "email" t.text "special_instructions" t.integer "distributor_id" - t.integer "order_cycle_id" t.string "currency" t.string "last_ip_address" + t.integer "order_cycle_id" t.integer "cart_id" end diff --git a/lib/open_food_network/option_value_namer.rb b/lib/open_food_network/option_value_namer.rb index 101fae427c..2c2383906d 100644 --- a/lib/open_food_network/option_value_namer.rb +++ b/lib/open_food_network/option_value_namer.rb @@ -1,27 +1,34 @@ module OpenFoodNetwork - class OptionValueNamer < Struct.new(:variant) - def name - value, unit = self.option_value_value_unit - separator = self.value_scaled? ? '' : ' ' + class OptionValueNamer + def initialize(variant = nil) + @variant = variant + end + + def name(obj = nil) + @variant = obj unless obj.nil? + value, unit = option_value_value_unit + separator = value_scaled? ? '' : ' ' name_fields = [] name_fields << "#{value}#{separator}#{unit}" if value.present? && unit.present? - name_fields << variant.unit_description if variant.unit_description.present? + name_fields << @variant.unit_description if @variant.unit_description.present? name_fields.join ' ' end + private + def value_scaled? - variant.product.variant_unit_scale.present? + @variant.product.variant_unit_scale.present? end def option_value_value_unit - if variant.unit_value.present? - if %w(weight volume).include? variant.product.variant_unit - value, unit_name = self.option_value_value_unit_scaled + if @variant.unit_value.present? + if %w(weight volume).include? @variant.product.variant_unit + value, unit_name = option_value_value_unit_scaled else - value = variant.unit_value - unit_name = variant.product.variant_unit_name + value = @variant.unit_value + unit_name = @variant.product.variant_unit_name unit_name = unit_name.pluralize if value > 1 end @@ -35,9 +42,9 @@ module OpenFoodNetwork end def option_value_value_unit_scaled - unit_scale, unit_name = self.scale_for_unit_value + unit_scale, unit_name = scale_for_unit_value - value = variant.unit_value / unit_scale + value = @variant.unit_value / unit_scale [value, unit_name] end @@ -48,10 +55,10 @@ module OpenFoodNetwork # Find the largest available unit where unit_value comes to >= 1 when expressed in it. # If there is none available where this is true, use the smallest available unit. - unit = units[variant.product.variant_unit].select { |scale, unit_name| - variant.unit_value / scale >= 1 + unit = units[@variant.product.variant_unit].select { |scale, unit_name| + @variant.unit_value / scale >= 1 }.to_a.last - unit = units[variant.product.variant_unit].first if unit.nil? + unit = units[@variant.product.variant_unit].first if unit.nil? unit end diff --git a/spec/controllers/spree/admin/payment_methods_controller_spec.rb b/spec/controllers/spree/admin/payment_methods_controller_spec.rb new file mode 100644 index 0000000000..f3266f69c2 --- /dev/null +++ b/spec/controllers/spree/admin/payment_methods_controller_spec.rb @@ -0,0 +1,76 @@ +require 'spec_helper' + +describe Spree::Admin::PaymentMethodsController do + context "Requesting provider preference fields" do + let(:enterprise) { create(:distributor_enterprise) } + let(:user) do + new_user = create(:user, email: 'enterprise@hub.com', password: 'blahblah', :password_confirmation => 'blahblah', ) + new_user.spree_roles = [] # for some reason unbeknown to me, this new user gets admin permissions by default. + new_user.enterprise_roles.build(enterprise: enterprise).save + new_user.save + new_user + end + + before do + controller.stub spree_current_user: user + end + + context "on an existing payment method" do + let(:payment_method) { create(:payment_method) } + + context "where I have permission" do + before do + payment_method.distributors << user.enterprises.is_distributor.first + end + + context "without an altered provider type" do + it "renders provider settings with same payment method" do + spree_get :show_provider_preferences, { + pm_id: payment_method.id, + provider_type: "Spree::PaymentMethod::Check" + } + expect(assigns(:payment_method)).to eq payment_method + expect(response).to render_template partial: '_provider_settings' + end + end + + context "with an altered provider type" do + it "renders provider settings with a different payment method" do + spree_get :show_provider_preferences, { + pm_id: payment_method.id, + provider_type: "Spree::Gateway::Bogus" + } + expect(assigns(:payment_method)).not_to eq payment_method + expect(response).to render_template partial: '_provider_settings' + end + end + end + + context "where I do not have permission" do + before do + payment_method.distributors = [] + end + + it "renders unauthorised" do + spree_get :show_provider_preferences, { + pm_id: payment_method.id, + provider_type: "Spree::PaymentMethod::Check" + } + expect(assigns(:payment_method)).to eq payment_method + expect(flash[:error]).to eq "Authorization Failure" + end + end + end + + context "on a new payment method" do + it "renders provider settings with a new payment method of type" do + spree_get :show_provider_preferences, { + pm_id: "", + provider_type: "Spree::Gateway::Bogus" + } + expect(assigns(:payment_method)).to be_a_new Spree::Gateway::Bogus + expect(response).to render_template partial: '_provider_settings' + end + end + end +end \ No newline at end of file diff --git a/spec/features/admin/bulk_order_management_spec.rb b/spec/features/admin/bulk_order_management_spec.rb index 963cd04f8d..a8fe6cbda7 100644 --- a/spec/features/admin/bulk_order_management_spec.rb +++ b/spec/features/admin/bulk_order_management_spec.rb @@ -24,7 +24,7 @@ feature %q{ it "displays a message when number of line items is zero" do visit '/admin/orders/bulk_management' - page.should have_text "No matching line items found." + page.should have_text "No orders found." end diff --git a/spec/features/admin/bulk_product_update_spec.rb b/spec/features/admin/bulk_product_update_spec.rb index 79cff455a7..ccddba5508 100644 --- a/spec/features/admin/bulk_product_update_spec.rb +++ b/spec/features/admin/bulk_product_update_spec.rb @@ -18,31 +18,14 @@ feature %q{ visit '/admin/products/bulk_edit' - page.should have_field "product_name", with: p1.name, :visible => true - page.should have_field "product_name", with: p2.name, :visible => true + expect(page).to have_field "product_name", with: p1.name, :visible => true + expect(page).to have_field "product_name", with: p2.name, :visible => true end it "displays a message when number of products is zero" do visit '/admin/products/bulk_edit' - page.should have_text "No matching products found." - end - - pending "displays a message when number of products is too great" do - 501.times { FactoryGirl.create(:simple_product) } - - visit '/admin/products/bulk_edit' - - page.should have_text "Search returned too many products to display (500+), please apply more search filters to reduce the number of matching products" - end - - it "displays pagination information" do - p1 = FactoryGirl.create(:product) - p2 = FactoryGirl.create(:product) - - visit '/admin/products/bulk_edit' - - page.should have_text "Displaying 1-2 of 2 products" + expect(page).to have_text "No products found." end it "displays a select box for suppliers, with the appropriate supplier selected" do @@ -54,8 +37,8 @@ feature %q{ visit '/admin/products/bulk_edit' - page.should have_select "supplier", with_options: [s1.name,s2.name,s3.name], selected: s2.name - page.should have_select "supplier", with_options: [s1.name,s2.name,s3.name], selected: s3.name + expect(page).to have_select "producer", with_options: [s1.name,s2.name,s3.name], selected: s2.name + expect(page).to have_select "producer", with_options: [s1.name,s2.name,s3.name], selected: s3.name end it "displays a date input for available_on for each product, formatted to yyyy-mm-dd hh:mm:ss" do @@ -63,11 +46,11 @@ feature %q{ p2 = FactoryGirl.create(:product, available_on: Date.today-1) visit '/admin/products/bulk_edit' - first("div.option_tab_titles h6", :text => "Toggle Columns").click - first("li.column-list-item", text: "Available On").click + first("div#columns_dropdown", :text => "COLUMNS").click + first("div#columns_dropdown div.menu div.menu_item", text: "Available On").click - page.should have_field "available_on", with: p1.available_on.strftime("%F %T") - page.should have_field "available_on", with: p2.available_on.strftime("%F %T") + expect(page).to have_field "available_on", with: p1.available_on.strftime("%F %T") + expect(page).to have_field "available_on", with: p2.available_on.strftime("%F %T") end it "displays a price input for each product without variants (ie. for master variant)" do @@ -82,9 +65,9 @@ feature %q{ visit '/admin/products/bulk_edit' - page.should have_field "price", with: "22.0" - page.should have_field "price", with: "44.0" - page.should_not have_field "price", with: "66.0", visible: true + expect(page).to have_field "price", with: "22.0" + expect(page).to have_field "price", with: "44.0" + expect(page).to have_no_field "price", with: "66.0", visible: true end it "displays an on hand count input for each product (ie. for master variant) if no regular variants exist" do @@ -97,9 +80,9 @@ feature %q{ visit '/admin/products/bulk_edit' - page.should_not have_selector "span[name='on_hand']", text: "0" - page.should have_field "on_hand", with: "15" - page.should have_field "on_hand", with: "12" + expect(page).to have_no_selector "span[name='on_hand']", text: "0" + expect(page).to have_field "on_hand", with: "15" + expect(page).to have_field "on_hand", with: "12" end it "displays an on hand count in a span for each product (ie. for master variant) if other variants exist" do @@ -113,9 +96,9 @@ feature %q{ visit '/admin/products/bulk_edit' - page.should_not have_field "on_hand", with: "15" - page.should have_selector "span[name='on_hand']", text: "4" - page.should have_field "on_hand", with: "12" + expect(page).to have_no_field "on_hand", with: "15" + expect(page).to have_selector "span[name='on_hand']", text: "4" + expect(page).to have_field "on_hand", with: "12" end it "displays 'on demand' for the on hand count when the product is available on demand" do @@ -124,8 +107,8 @@ feature %q{ visit '/admin/products/bulk_edit' - page.should have_selector "span[name='on_hand']", text: "On demand" - page.should_not have_field "on_hand", visible: true + expect(page).to have_selector "span[name='on_hand']", text: "On demand" + expect(page).to have_no_field "on_hand", visible: true end it "displays 'on demand' for any variant that is available on demand" do @@ -136,10 +119,10 @@ feature %q{ visit '/admin/products/bulk_edit' first("a.view-variants").trigger('click') - page.should_not have_selector "span[name='on_hand']", text: "On demand", visible: true - page.should have_field "variant_on_hand", with: "4" - page.should_not have_field "variant_on_hand", with: "", visible: true - page.should have_selector "span[name='variant_on_hand']", text: "On demand" + expect(page).to have_no_selector "span[name='on_hand']", text: "On demand", visible: true + expect(page).to have_field "variant_on_hand", with: "4" + expect(page).to have_no_field "variant_on_hand", with: "", visible: true + expect(page).to have_selector "span[name='variant_on_hand']", text: "On demand" end it "displays a select box for the unit of measure for the product's variants" do @@ -147,7 +130,7 @@ feature %q{ visit '/admin/products/bulk_edit' - page.should have_select "variant_unit_with_scale", selected: "Weight (g)" + expect(page).to have_select "variant_unit_with_scale", selected: "Weight (g)" end it "displays a text field for the item name when unit is set to 'Items'" do @@ -155,8 +138,8 @@ feature %q{ visit '/admin/products/bulk_edit' - page.should have_select "variant_unit_with_scale", selected: "Items" - page.should have_field "variant_unit_name", with: "packet" + expect(page).to have_select "variant_unit_with_scale", selected: "Items" + expect(page).to have_field "variant_unit_name", with: "packet" end end @@ -170,13 +153,13 @@ feature %q{ v2 = FactoryGirl.create(:variant, display_name: "something2" ) visit '/admin/products/bulk_edit' - page.should have_selector "a.view-variants" + expect(page).to have_selector "a.view-variants" all("a.view-variants").each { |e| e.trigger('click') } - page.should have_field "product_name", with: v1.product.name - page.should have_field "product_name", with: v2.product.name - page.should have_field "variant_display_name", with: v1.display_name - page.should have_field "variant_display_name", with: v2.display_name + expect(page).to have_field "product_name", with: v1.product.name + expect(page).to have_field "product_name", with: v2.product.name + expect(page).to have_field "variant_display_name", with: v1.display_name + expect(page).to have_field "variant_display_name", with: v2.display_name end it "displays an on_hand input (for each variant) for each product" do @@ -187,9 +170,9 @@ feature %q{ visit '/admin/products/bulk_edit' all("a.view-variants").each { |e| e.trigger('click') } - page.should have_selector "span[name='on_hand']", text: "21" - page.should have_field "variant_on_hand", with: "15" - page.should have_field "variant_on_hand", with: "6" + expect(page).to have_selector "span[name='on_hand']", text: "21" + expect(page).to have_field "variant_on_hand", with: "15" + expect(page).to have_field "variant_on_hand", with: "6" end @@ -201,9 +184,9 @@ feature %q{ visit '/admin/products/bulk_edit' all("a.view-variants").each { |e| e.trigger('click') } - page.should have_field "price", with: "2.0", visible: false - page.should have_field "variant_price", with: "12.75" - page.should have_field "variant_price", with: "2.5" + expect(page).to have_field "price", with: "2.0", visible: false + expect(page).to have_field "variant_price", with: "12.75" + expect(page).to have_field "variant_price", with: "2.5" end it "displays a unit value field (for each variant) for each product" do @@ -214,10 +197,10 @@ feature %q{ visit '/admin/products/bulk_edit' all("a.view-variants").each { |e| e.trigger('click') } - page.should have_field "variant_unit_value_with_description", with: "1.2 (small bag)" - page.should have_field "variant_unit_value_with_description", with: "4.8 (large bag)" - page.should have_field "variant_display_as", with: "bag" - page.should have_field "variant_display_as", with: "bin" + expect(page).to have_field "variant_unit_value_with_description", with: "1.2 (small bag)" + expect(page).to have_field "variant_unit_value_with_description", with: "4.8 (large bag)" + expect(page).to have_field "variant_display_as", with: "bag" + expect(page).to have_field "variant_display_as", with: "bin" end end @@ -232,7 +215,7 @@ feature %q{ visit '/admin/products/bulk_edit' find("a", text: "NEW PRODUCT").click - page.should have_content 'NEW PRODUCT' + expect(page).to have_content 'NEW PRODUCT' fill_in 'product_name', :with => 'Big Bag Of Apples' select(s.name, :from => 'product_supplier_id') @@ -240,9 +223,9 @@ feature %q{ select taxon.name, from: 'product_primary_taxon_id' click_button 'Create' - URI.parse(current_url).path.should == '/admin/products/bulk_edit' - flash_message.should == 'Product "Big Bag Of Apples" has been successfully created!' - page.should have_field "product_name", with: 'Big Bag Of Apples' + expect(URI.parse(current_url).path).to eq '/admin/products/bulk_edit' + expect(flash_message).to eq 'Product "Big Bag Of Apples" has been successfully created!' + expect(page).to have_field "product_name", with: 'Big Bag Of Apples' end @@ -253,13 +236,13 @@ feature %q{ visit '/admin/products/bulk_edit' # I should not see an add variant button - page.should_not have_selector 'a.add-variant', visible: true + expect(page).to have_no_selector 'a.add-variant', visible: true # When I set the unit select "Weight (kg)", from: "variant_unit_with_scale" # I should see an add variant button - page.should have_selector 'a.add-variant', visible: true + expect(page).to have_selector 'a.add-variant', visible: true # When I add three variants page.find('a.add-variant', visible: true).trigger('click') @@ -267,44 +250,44 @@ feature %q{ page.find('a.add-variant', visible: true).trigger('click') # They should be added, and should see no edit buttons - page.all("tr.variant").count.should == 3 - page.should_not have_selector "a.edit-variant", visible: true + variant_count = page.all("tr.variant").count + expect(variant_count).to eq 3 + expect(page).to have_no_selector "a.edit-variant", visible: true # When I remove two, they should be removed page.all('a.delete-variant').first.click page.all('a.delete-variant').first.click - page.all("tr.variant").count.should == 1 + variant_count = page.all("tr.variant").count + expect(variant_count).to eq 1 # When I fill out variant details and hit update fill_in "variant_display_name", with: "Case of 12 Bottles" - fill_in "variant_unit_value_with_description", with: "4000 (12x250 mL bottles)" + fill_in "variant_unit_value_with_description", with: "3 (12x250 mL bottles)" fill_in "variant_display_as", with: "Case" fill_in "variant_price", with: "4.0" fill_in "variant_on_hand", with: "10" - click_button 'Update' + click_button 'Save Changes' + expect(page.find("#update-status-message")).to have_content "Changes saved." - page.find("span#update-status-message").should have_content "Update complete" + updated_variant = Spree::Variant.where(deleted_at: nil).last + expect(updated_variant.display_name).to eq "Case of 12 Bottles" + expect(updated_variant.unit_value).to eq 3000 + expect(updated_variant.unit_description).to eq "(12x250 mL bottles)" + expect(updated_variant.display_as).to eq "Case" + expect(updated_variant.price).to eq 4.0 + expect(updated_variant.on_hand).to eq 10 # Then I should see edit buttons for the new variant - page.should have_selector "a.edit-variant", visible: true - - # And the variants should be saved - visit '/admin/products/bulk_edit' - page.should have_selector "a.view-variants" - first("a.view-variants").trigger('click') - - page.should have_field "variant_display_name", with: "Case of 12 Bottles" - page.should have_field "variant_unit_value_with_description", with: "4000 (12x250 mL bottles)" - page.should have_field "variant_display_as", with: "Case" - page.should have_field "variant_price", with: "4.0" - page.should have_field "variant_on_hand", with: "10" + expect(page).to have_selector "a.edit-variant", visible: true end scenario "updating a product with no variants (except master)" do s1 = FactoryGirl.create(:supplier_enterprise) s2 = FactoryGirl.create(:supplier_enterprise) - p = FactoryGirl.create(:product, supplier: s1, available_on: Date.today, variant_unit: 'volume', variant_unit_scale: 1) + t1 = FactoryGirl.create(:taxon) + t2 = FactoryGirl.create(:taxon) + p = FactoryGirl.create(:product, supplier: s1, available_on: Date.today, variant_unit: 'volume', variant_unit_scale: 1, primary_taxon: t2) p.price = 10.0 p.on_hand = 6; p.save! @@ -313,36 +296,43 @@ feature %q{ visit '/admin/products/bulk_edit' - first("div.option_tab_titles h6", :text => "Toggle Columns").click - first("li.column-list-item", text: "Available On").click + first("div#columns_dropdown", :text => "COLUMNS").click + first("div#columns_dropdown div.menu div.menu_item", text: "Available On").click + first("div#columns_dropdown div.menu div.menu_item", text: "Category").click - page.should have_field "product_name", with: p.name - page.should have_select "supplier", selected: s1.name - page.should have_field "available_on", with: p.available_on.strftime("%F %T") - page.should have_field "price", with: "10.0" - page.should have_select "variant_unit_with_scale", selected: "Volume (L)" - page.should have_field "on_hand", with: "6" + within "tr#p_#{p.id}" do + expect(page).to have_field "product_name", with: p.name + expect(page).to have_select "producer", selected: s1.name + expect(page).to have_field "available_on", with: p.available_on.strftime("%F %T") + expect(page).to have_field "price", with: "10.0" + save_screenshot '/Users/rob/Desktop/ss.png' + expect(page).to have_selector "div#s2id_p#{p.id}_category a.select2-choice" + expect(page).to have_select "variant_unit_with_scale", selected: "Volume (L)" + expect(page).to have_field "on_hand", with: "6" - fill_in "product_name", with: "Big Bag Of Potatoes" - select(s2.name, :from => 'supplier') - fill_in "available_on", with: (Date.today-3).strftime("%F %T") - fill_in "price", with: "20" - select "Weight (kg)", from: "variant_unit_with_scale" - fill_in "on_hand", with: "18" - fill_in "display_as", with: "Big Bag" + fill_in "product_name", with: "Big Bag Of Potatoes" + select s2.name, :from => 'producer' + fill_in "available_on", with: (Date.today-3).strftime("%F %T") + fill_in "price", with: "20" + select "Weight (kg)", from: "variant_unit_with_scale" + select2_select t1.name, from: "p#{p.id}_category" + fill_in "on_hand", with: "18" + fill_in "display_as", with: "Big Bag" + end - click_button 'Update' - page.find("span#update-status-message").should have_content "Update complete" + click_button 'Save Changes' + expect(page.find("#update-status-message")).to have_content "Changes saved." - visit '/admin/products/bulk_edit' - - page.should have_field "product_name", with: "Big Bag Of Potatoes" - page.should have_select "supplier", selected: s2.name - page.should have_field "available_on", with: (Date.today-3).strftime("%F %T"), visible: false - page.should have_field "price", with: "20.0" - page.should have_select "variant_unit_with_scale", selected: "Weight (kg)" - page.should have_field "on_hand", with: "18" - page.should have_field "display_as", with: "Big Bag" + p.reload + expect(p.name).to eq "Big Bag Of Potatoes" + expect(p.supplier).to eq s2 + expect(p.variant_unit).to eq "weight" + expect(p.variant_unit_scale).to eq 1000 # Kg + expect(p.available_on).to eq 3.days.ago.beginning_of_day + expect(p.master.display_as).to eq "Big Bag" + expect(p.price).to eq 20.0 + expect(p.on_hand).to eq 18 + expect(p.primary_taxon).to eq t1 end scenario "updating a product with a variant unit of 'items'" do @@ -352,18 +342,18 @@ feature %q{ visit '/admin/products/bulk_edit' - page.should have_select "variant_unit_with_scale", selected: "Weight (kg)" + expect(page).to have_select "variant_unit_with_scale", selected: "Weight (kg)" select "Items", from: "variant_unit_with_scale" fill_in "variant_unit_name", with: "loaf" - click_button 'Update' - page.find("span#update-status-message").should have_content "Update complete" + click_button 'Save Changes' + expect(page.find("#update-status-message")).to have_content "Changes saved." - visit '/admin/products/bulk_edit' - - page.should have_select "variant_unit_with_scale", selected: "Items" - page.should have_field "variant_unit_name", with: "loaf" + p.reload + expect(p.variant_unit).to eq "items" + expect(p.variant_unit_scale).to be_nil + expect(p.variant_unit_name).to eq "loaf" end scenario "setting a variant unit on a product that has none" do @@ -374,20 +364,21 @@ feature %q{ visit '/admin/products/bulk_edit' - page.should have_select "variant_unit_with_scale", selected: '' + expect(page).to have_select "variant_unit_with_scale", selected: '' select "Weight (kg)", from: "variant_unit_with_scale" first("a.view-variants").trigger('click') fill_in "variant_unit_value_with_description", with: '123 abc' - click_button 'Update' - page.find("span#update-status-message").should have_content "Update complete" + click_button 'Save Changes' + expect(page.find("#update-status-message")).to have_content "Changes saved." - visit '/admin/products/bulk_edit' - first("a.view-variants").trigger('click') - - page.should have_select "variant_unit_with_scale", selected: "Weight (kg)" - page.should have_field "variant_unit_value_with_description", with: "123 abc" + p.reload + expect(p.variant_unit).to eq "weight" + expect(p.variant_unit_scale).to eq 1000 # Kg + v.reload + expect(v.unit_value).to eq 123000 # 123 kg in g + expect(v.unit_description).to eq "abc" end describe "setting the master unit value for a product without variants" do @@ -398,25 +389,20 @@ feature %q{ visit '/admin/products/bulk_edit' - page.should have_select "variant_unit_with_scale", selected: '' - page.should_not have_field "master_unit_value_with_description", visible: true + expect(page).to have_select "variant_unit_with_scale", selected: '' + expect(page).to have_no_field "master_unit_value_with_description", visible: true select "Weight (kg)", from: "variant_unit_with_scale" fill_in "master_unit_value_with_description", with: '123 abc' - click_button 'Update' - page.find("span#update-status-message").should have_content "Update complete" - - visit '/admin/products/bulk_edit' - - page.should have_select "variant_unit_with_scale", selected: "Weight (kg)" - page.should have_field "master_unit_value_with_description", with: "123 abc" + click_button 'Save Changes' + expect(page.find("#update-status-message")).to have_content "Changes saved." p.reload - p.variant_unit.should == 'weight' - p.variant_unit_scale.should == 1000 - p.master.unit_value.should == 123000 - p.master.unit_description.should == 'abc' + expect(p.variant_unit).to eq 'weight' + expect(p.variant_unit_scale).to eq 1000 + expect(p.master.unit_value).to eq 123000 + expect(p.master.unit_description).to eq 'abc' end it "does not show the field when the product has variants" do @@ -428,7 +414,7 @@ feature %q{ visit '/admin/products/bulk_edit' select "Weight (kg)", from: "variant_unit_with_scale" - page.should_not have_field "master_unit_value_with_description", visible: true + expect(page).to have_no_field "master_unit_value_with_description", visible: true end end @@ -442,30 +428,29 @@ feature %q{ login_to_admin_section visit '/admin/products/bulk_edit' - page.should have_selector "a.view-variants" + expect(page).to have_selector "a.view-variants" first("a.view-variants").trigger('click') - page.should have_field "variant_price", with: "3.0" - page.should have_field "variant_unit_value_with_description", with: "250 (bottle)" - page.should have_field "variant_on_hand", with: "9" - page.should have_selector "span[name='on_hand']", text: "9" + expect(page).to have_field "variant_price", with: "3.0" + expect(page).to have_field "variant_unit_value_with_description", with: "250 (bottle)" + expect(page).to have_field "variant_on_hand", with: "9" + expect(page).to have_selector "span[name='on_hand']", text: "9" + select "Volume (L)", from: "variant_unit_with_scale" fill_in "variant_price", with: "4.0" fill_in "variant_on_hand", with: "10" - fill_in "variant_unit_value_with_description", with: "4000 (12x250 mL bottles)" + fill_in "variant_unit_value_with_description", with: "2 (8x250 mL bottles)" - page.should have_selector "span[name='on_hand']", text: "10" + expect(page).to have_selector "span[name='on_hand']", text: "10" - click_button 'Update' - page.find("span#update-status-message").should have_content "Update complete" + click_button 'Save Changes' + expect(page.find("#update-status-message")).to have_content "Changes saved." - visit '/admin/products/bulk_edit' - page.should have_selector "a.view-variants" - first("a.view-variants").trigger('click') - - page.should have_field "variant_price", with: "4.0" - page.should have_field "variant_on_hand", with: "10" - page.should have_field "variant_unit_value_with_description", with: "4000 (12x250 mL bottles)" + v.reload + expect(v.price).to eq 4.0 + expect(v.on_hand).to eq 10 + expect(v.unit_value).to eq 2 # 2L in L + expect(v.unit_description).to eq "(8x250 mL bottles)" end scenario "updating delegated attributes of variants in isolation" do @@ -475,21 +460,18 @@ feature %q{ login_to_admin_section visit '/admin/products/bulk_edit' - page.should have_selector "a.view-variants" + expect(page).to have_selector "a.view-variants" first("a.view-variants").trigger('click') - page.should have_field "variant_price", with: "3.0" + expect(page).to have_field "variant_price", with: "3.0" fill_in "variant_price", with: "10.0" - click_button 'Update' - page.find("span#update-status-message").should have_content "Update complete" + click_button 'Save Changes' + expect(page.find("#update-status-message")).to have_content "Changes saved." - visit '/admin/products/bulk_edit' - page.should have_selector "a.view-variants" - first("a.view-variants").trigger('click') - - page.should have_field "variant_price", with: "10.0" + v.reload + expect(v.price).to eq 10.0 end scenario "updating a product mutiple times without refresh" do @@ -498,26 +480,32 @@ feature %q{ visit '/admin/products/bulk_edit' - page.should have_field "product_name", with: "original name" + expect(page).to have_field "product_name", with: "original name" fill_in "product_name", with: "new name 1" - click_button 'Update' - page.find("span#update-status-message").should have_content "Update complete" + click_button 'Save Changes' + expect(page.find("#update-status-message")).to have_content "Changes saved." + p.reload + expect(p.name).to eq "new name 1" fill_in "product_name", with: "new name 2" - click_button 'Update' - page.find("span#update-status-message").should have_content "Update complete" + click_button 'Save Changes' + expect(page.find("#update-status-message")).to have_content "Changes saved." + p.reload + expect(p.name).to eq "new name 2" fill_in "product_name", with: "original name" - click_button 'Update' - page.find("span#update-status-message").should have_content "Update complete" + click_button 'Save Changes' + expect(page.find("#update-status-message")).to have_content "Changes saved." + p.reload + expect(p.name).to eq "original name" end scenario "updating a product after cloning a product" do - FactoryGirl.create(:product, :name => "product 1") + p = FactoryGirl.create(:product, :name => "product 1") login_to_admin_section visit '/admin/products/bulk_edit' @@ -526,54 +514,42 @@ feature %q{ fill_in "product_name", :with => "new product name" - click_button 'Update' - page.find("span#update-status-message").should have_content "Update complete" + click_button 'Save Changes' + expect(page.find("#update-status-message")).to have_content "Changes saved." + p.reload + expect(p.name).to eq "new product name" end scenario "updating when no changes have been made" do Capybara.using_wait_time(2) do FactoryGirl.create(:product, :name => "product 1") - FactoryGirl.create(:product, :name => "product 2") login_to_admin_section visit '/admin/products/bulk_edit' - click_button 'Update' - page.find("span#update-status-message").should have_content "No changes to update." + click_button 'Save Changes' + expect(page.find("#update-status-message")).to have_content "No changes to save." end end scenario "updating when a filter has been applied" do - p1 = FactoryGirl.create(:simple_product, :name => "product1") - p2 = FactoryGirl.create(:simple_product, :name => "product2") + s1 = create(:supplier_enterprise) + s2 = create(:supplier_enterprise) + p1 = FactoryGirl.create(:simple_product, :name => "product1", supplier: s1) + p2 = FactoryGirl.create(:simple_product, :name => "product2", supplier: s2) login_to_admin_section visit '/admin/products/bulk_edit' - page.should have_selector "div.option_tab_titles h6", :text => "Filter Products" - first("div.option_tab_titles h6", :text => "Filter Products").click + select2_select s1.name, from: "producer_filter" - select2_select "Name", from: "filter_property" - select2_select "Contains", from: "filter_predicate" - fill_in "filter_value", :with => "1" - click_button "Apply Filter" - page.should_not have_field "product_name", with: p2.name + expect(page).to have_no_field "product_name", with: p2.name fill_in "product_name", :with => "new product1" - click_on 'Update' - page.find("span#update-status-message").should have_content "Update complete" - end - - scenario "updating a product when there are more products than the default API page size" do - 26.times { FactoryGirl.create(:simple_product) } - login_to_admin_section - - visit '/admin/products/bulk_edit' - - field = page.all("table#listing_products input[name='product_name']").first - field.set "new name" - click_button 'Update' - page.find("span#update-status-message").should have_content "Update complete" + click_button 'Save Changes' + expect(page.find("#update-status-message")).to have_content "Changes saved." + p1.reload + expect(p1.name).to eq "new product1" end describe "using action buttons" do @@ -586,15 +562,17 @@ feature %q{ visit '/admin/products/bulk_edit' - page.should have_selector "a.delete-product", :count => 3 + expect(page).to have_selector "a.delete-product", :count => 3 - first("a.delete-product").click + within "tr#p_#{p1.id}" do + first("a.delete-product").click + end - page.should have_selector "a.delete-product", :count => 2 + expect(page).to have_selector "a.delete-product", :count => 2 visit '/admin/products/bulk_edit' - page.should have_selector "a.delete-product", :count => 2 + expect(page).to have_selector "a.delete-product", :count => 2 end it "shows a delete button for variants, which deletes the appropriate variant when clicked" do @@ -604,20 +582,22 @@ feature %q{ login_to_admin_section visit '/admin/products/bulk_edit' - page.should have_selector "a.view-variants" + expect(page).to have_selector "a.view-variants" all("a.view-variants").each { |e| e.trigger('click') } - page.should have_selector "a.delete-variant", :count => 3 + expect(page).to have_selector "a.delete-variant", :count => 3 - first("a.delete-variant").click + within "tr#v_#{v1.id}" do + first("a.delete-variant").click + end - page.should have_selector "a.delete-variant", :count => 2 + expect(page).to have_selector "a.delete-variant", :count => 2 visit '/admin/products/bulk_edit' - page.should have_selector "a.view-variants" + expect(page).to have_selector "a.view-variants" all("a.view-variants").select { |e| e.visible? }.each { |e| e.trigger('click') } - page.should have_selector "a.delete-variant", :count => 2 + expect(page).to have_selector "a.delete-variant", :count => 2 end end @@ -630,11 +610,13 @@ feature %q{ visit '/admin/products/bulk_edit' - page.should have_selector "a.edit-product", :count => 3 + expect(page).to have_selector "a.edit-product", :count => 3 - first("a.edit-product").click + within "tr#p_#{p1.id}" do + first("a.edit-product").click + end - URI.parse(current_url).path.should == "/admin/products/#{p1.permalink}/edit" + expect(URI.parse(current_url).path).to eq "/admin/products/#{p1.permalink}/edit" end it "shows an edit button for variants, which takes the user to the standard edit page for that variant" do @@ -644,14 +626,16 @@ feature %q{ login_to_admin_section visit '/admin/products/bulk_edit' - page.should have_selector "a.view-variants" + expect(page).to have_selector "a.view-variants" all("a.view-variants").each { |e| e.trigger('click') } - page.should have_selector "a.edit-variant", :count => 3 + expect(page).to have_selector "a.edit-variant", :count => 3 - first("a.edit-variant").click + within "tr#v_#{v1.id}" do + first("a.edit-variant").click + end - URI.parse(current_url).path.should == "/admin/products/#{v1.product.permalink}/variants/#{v1.id}/edit" + expect(URI.parse(current_url).path).to eq "/admin/products/#{v1.product.permalink}/variants/#{v1.id}/edit" end end @@ -664,220 +648,82 @@ feature %q{ visit '/admin/products/bulk_edit' - page.should have_selector "a.clone-product", :count => 3 + expect(page).to have_selector "a.clone-product", :count => 3 - first("a.clone-product").click - page.should have_selector "a.clone-product", :count => 4 - page.should have_field "product_name", with: "COPY OF #{p1.name}" - page.should have_select "supplier", selected: "#{p1.supplier.name}" + within "tr#p_#{p1.id}" do + first("a.clone-product").click + end + expect(page).to have_selector "a.clone-product", :count => 4 + expect(page).to have_field "product_name", with: "COPY OF #{p1.name}" + expect(page).to have_select "producer", selected: "#{p1.supplier.name}" visit '/admin/products/bulk_edit' - page.should have_selector "a.clone-product", :count => 4 - page.should have_field "product_name", with: "COPY OF #{p1.name}" - page.should have_select "supplier", selected: "#{p1.supplier.name}" + expect(page).to have_selector "a.clone-product", :count => 4 + expect(page).to have_field "product_name", with: "COPY OF #{p1.name}" + expect(page).to have_select "producer", selected: "#{p1.supplier.name}" end end end describe "using the page" do - describe "using tabs to hide and display page controls" do - it "shows a column display toggle button, which shows a list of columns when clicked" do - FactoryGirl.create(:simple_product) - login_to_admin_section - - visit '/admin/products/bulk_edit' - - page.should have_selector "div.column_toggle", :visible => false - - page.should have_selector "div.option_tab_titles h6.unselected", :text => "Toggle Columns" - first("div.option_tab_titles h6", :text => "Toggle Columns").click - - page.should have_selector "div.option_tab_titles h6.selected", :text => "Toggle Columns" - page.should have_selector "div.column_toggle", :visible => true - page.should have_selector "li.column-list-item", text: "Available On" - - page.should have_selector "div.filters", :visible => false - - page.should have_selector "div.option_tab_titles h6.unselected", :text => "Filter Products" - first("div.option_tab_titles h6", :text => "Filter Products").click - - page.should have_selector "div.option_tab_titles h6.unselected", :text => "Toggle Columns" - page.should have_selector "div.option_tab_titles h6.selected", :text => "Filter Products" - page.should have_selector "div.filters", :visible => true - - first("div.option_tab_titles h6", :text => "Filter Products").click - - page.should have_selector "div.option_tab_titles h6.unselected", :text => "Filter Products" - page.should have_selector "div.option_tab_titles h6.unselected", :text => "Toggle Columns" - page.should have_selector "div.filters", :visible => false - page.should have_selector "div.column_toggle", :visible => false - end - end - - describe "using column display toggle" do - it "shows a column display toggle button, which shows a list of columns when clicked" do + describe "using column display dropdown" do + it "shows a column display dropdown, which shows a list of columns when clicked" do FactoryGirl.create(:simple_product) login_to_admin_section visit '/admin/products/bulk_edit' - first("div.option_tab_titles h6", :text => "Toggle Columns").click - first("li.column-list-item", text: "Available On").click + first("div#columns_dropdown", :text => "COLUMNS").click + first("div#columns_dropdown div.menu div.menu_item", text: "Available On").click - page.should have_selector "th", :text => "NAME" - page.should have_selector "th", :text => "SUPPLIER" - page.should have_selector "th", :text => "PRICE" - page.should have_selector "th", :text => "ON HAND" - page.should have_selector "th", :text => "AV. ON" + expect(page).to have_selector "th", :text => "NAME" + expect(page).to have_selector "th", :text => "PRODUCER" + expect(page).to have_selector "th", :text => "PRICE" + expect(page).to have_selector "th", :text => "ON HAND" + expect(page).to have_selector "th", :text => "AV. ON" - page.should have_selector "div.option_tab_titles h6", :text => "Toggle Columns" + first("div#columns_dropdown div.menu div.menu_item", text: /^.{0,1}Producer$/).click - page.should have_selector "div ul.column-list li.column-list-item", text: "Supplier" - first("li.column-list-item", text: "Supplier").click - - page.should_not have_selector "th", :text => "SUPPLIER" - page.should have_selector "th", :text => "NAME" - page.should have_selector "th", :text => "PRICE" - page.should have_selector "th", :text => "ON HAND" - page.should have_selector "th", :text => "AV. ON" - end - end - - describe "using pagination controls" do - it "shows pagination controls" do - 27.times { FactoryGirl.create(:product) } - login_to_admin_section - - visit '/admin/products/bulk_edit' - - page.should have_select 'perPage', :selected => '25' - within '.pagination' do - page.should have_text "1 2" - page.should have_text "Next" - page.should have_text "Last" - end - end - - it "allows the number of visible products to be altered" do - 27.times { FactoryGirl.create(:product) } - login_to_admin_section - - visit '/admin/products/bulk_edit' - - select '25', :from => 'perPage' - page.all("input[name='product_name']").select{ |e| e.visible? }.length.should == 25 - select '50', :from => 'perPage' - page.all("input[name='product_name']").select{ |e| e.visible? }.length.should == 27 - end - - it "displays the correct products when changing pages" do - 25.times { FactoryGirl.create(:product, :name => "page1product") } - 5.times { FactoryGirl.create(:product, :name => "page2product") } - login_to_admin_section - - visit '/admin/products/bulk_edit' - - select '25', :from => 'perPage' - page.all("input[name='product_name']").select{ |e| e.visible? }.all?{ |e| e.value == "page1product" }.should == true - find("a", text: "2").click - page.all("input[name='product_name']").select{ |e| e.visible? }.all?{ |e| e.value == "page2product" }.should == true - end - - it "moves the user to the last available page when changing the number of pages in any way causes user to become orphaned" do - 50.times { FactoryGirl.create(:product) } - FactoryGirl.create(:product, :name => "fancy_product_name") - login_to_admin_section - - visit '/admin/products/bulk_edit' - - select '25', :from => 'perPage' - find("a", text: "3").click - select '50', :from => 'perPage' - page.first("div.pagenav span.page.current").should have_text "2" - page.all("input[name='product_name']", :visible => true).length.should == 1 - - select '25', :from => 'perPage' - fill_in "quick_filter", :with => "fancy_product_name" - page.first("div.pagenav span.page.current").should have_text "1" - page.all("input[name='product_name']", :visible => true).length.should == 1 - end - - it "paginates the filtered product list rather than all products" do - 25.times { FactoryGirl.create(:product, :name => "product_name") } - 3.times { FactoryGirl.create(:product, :name => "test_product_name") } - login_to_admin_section - - visit '/admin/products/bulk_edit' - - select '25', :from => 'perPage' - page.should have_text "1 2" - fill_in "quick_filter", :with => "test_product_name" - page.all("input[name='product_name']", :visible => true).length.should == 3 - page.all("input[name='product_name']", :visible => true).all?{ |e| e.value == "test_product_name" }.should == true - page.should_not have_text "1 2" - page.should have_text "1" + expect(page).to have_no_selector "th", :text => "PRODUCER" + expect(page).to have_selector "th", :text => "NAME" + expect(page).to have_selector "th", :text => "PRICE" + expect(page).to have_selector "th", :text => "ON HAND" + expect(page).to have_selector "th", :text => "AV. ON" end end describe "using filtering controls" do - it "displays basic filtering controls" do - FactoryGirl.create(:simple_product) - + it "displays basic filtering controls which filter the product list" do + s1 = create(:supplier_enterprise) + s2 = create(:supplier_enterprise) + p1 = FactoryGirl.create(:simple_product, :name => "product1", supplier: s1) + p2 = FactoryGirl.create(:simple_product, :name => "product2", supplier: s2) login_to_admin_section + visit '/admin/products/bulk_edit' - page.should have_selector "div.option_tab_titles h6", :text => "Filter Products" - first("div.option_tab_titles h6", :text => "Filter Products").click + # Page shows the filter controls + expect(page).to have_select "producer_filter", visible: false + expect(page).to have_select "category_filter", visible: false - page.should have_select "filter_property", visible: false - page.should have_select "filter_predicate", visible: false - page.should have_field "filter_value" - end + # All products are shown when no filter is selected + expect(page).to have_field "product_name", with: p1.name + expect(page).to have_field "product_name", with: p2.name - describe "clicking the 'Apply Filter' Button" do - before(:each) do - FactoryGirl.create(:simple_product, :name => "Product1") - FactoryGirl.create(:simple_product, :name => "Product2") + # Set a filter + select2_select s1.name, from: "producer_filter" - login_to_admin_section - visit '/admin/products/bulk_edit' + # Products are hidden when filtered out + expect(page).to have_field "product_name", with: p1.name + expect(page).to have_no_field "product_name", with: p2.name - first("div.option_tab_titles h6", :text => "Filter Products").click + # Clearing filters + click_button "Clear Filters" - select2_select "Name", :from => "filter_property" - select2_select "Equals", :from => "filter_predicate" - fill_in "filter_value", :with => "Product1" - click_button "Apply Filter" - end - - it "adds a new filter to the list of applied filters" do - page.should have_text "Name Equals Product1" - end - - it "displays the 'loading' splash" do - page.should have_selector "div.loading", :text => "Loading Products..." - end - - it "loads appropriate products" do - page.should have_field "product_name", :with => "Product1" - page.should_not have_field "product_name", :with => "Product2" - end - - describe "clicking the 'Remove Filter' link" do - before(:each) do - find("a", text: "Remove Filter").click - end - - it "removes the filter from the list of applied filters" do - page.should_not have_text "Name Equals Product1" - end - - it "loads appropriate products" do - page.should have_field "product_name", :with => "Product1" - page.should have_field "product_name", :with => "Product2" - end - end + # All products are shown again + expect(page).to have_field "product_name", with: p1.name + expect(page).to have_field "product_name", with: p2.name end end end @@ -904,15 +750,15 @@ feature %q{ it "shows only products that I supply" do visit '/admin/products/bulk_edit' - page.should have_field 'product_name', with: product_supplied.name - page.should_not have_field 'product_name', with: product_not_supplied.name + expect(page).to have_field 'product_name', with: product_supplied.name + expect(page).to have_no_field 'product_name', with: product_not_supplied.name end it "shows only suppliers that I manage" do visit '/admin/products/bulk_edit' - page.should have_select 'supplier', with_options: [s1.name, s2.name], selected: s1.name - page.should_not have_select 'supplier', with_options: [s3.name] + expect(page).to have_select 'producer', with_options: [s1.name, s2.name], selected: s1.name + expect(page).to have_no_select 'producer', with_options: [s3.name] end it "shows inactive products that I supply" do @@ -920,40 +766,42 @@ feature %q{ visit '/admin/products/bulk_edit' - page.should have_field 'product_name', with: product_supplied_inactive.name + expect(page).to have_field 'product_name', with: product_supplied_inactive.name end it "allows me to update a product" do p = product_supplied visit '/admin/products/bulk_edit' - first("div.option_tab_titles h6", :text => "Toggle Columns").click - first("li.column-list-item", text: "Available On").click + first("div#columns_dropdown", :text => "COLUMNS").click + first("div#columns_dropdown div.menu div.menu_item", text: "Available On").click - page.should have_field "product_name", with: p.name - page.should have_select "supplier", selected: s1.name - page.should have_field "available_on", with: p.available_on.strftime("%F %T") - page.should have_field "price", with: "10.0" - page.should have_field "on_hand", with: "6" + expect(page).to have_field "product_name", with: p.name + expect(page).to have_select "producer", selected: s1.name + expect(page).to have_field "available_on", with: p.available_on.strftime("%F %T") + expect(page).to have_field "price", with: "10.0" + expect(page).to have_field "on_hand", with: "6" fill_in "product_name", with: "Big Bag Of Potatoes" - select s2.name, from: 'supplier' + select(s2.name, :from => 'producer') fill_in "available_on", with: (Date.today-3).strftime("%F %T") fill_in "price", with: "20" + select "Weight (kg)", from: "variant_unit_with_scale" fill_in "on_hand", with: "18" + fill_in "display_as", with: "Big Bag" - click_button 'Update' - page.find("span#update-status-message").should have_content "Update complete" + click_button 'Save Changes' + expect(page.find("#update-status-message")).to have_content "Changes saved." - visit '/admin/products/bulk_edit' - first("div.option_tab_titles h6", :text => "Toggle Columns").click - first("li.column-list-item", text: "Available On").click - - page.should have_field "product_name", with: "Big Bag Of Potatoes" - page.should have_select "supplier", selected: s2.name - page.should have_field "available_on", with: (Date.today-3).strftime("%F %T") - page.should have_field "price", with: "20.0" - page.should have_field "on_hand", with: "18" + p.reload + expect(p.name).to eq "Big Bag Of Potatoes" + expect(p.supplier).to eq s2 + expect(p.variant_unit).to eq "weight" + expect(p.variant_unit_scale).to eq 1000 # Kg + expect(p.available_on).to eq 3.days.ago.beginning_of_day + expect(p.master.display_as).to eq "Big Bag" + expect(p.price).to eq 20.0 + expect(p.on_hand).to eq 18 end end end diff --git a/spec/features/admin/enterprises_spec.rb b/spec/features/admin/enterprises_spec.rb index 4d277972e5..6ec19098fe 100644 --- a/spec/features/admin/enterprises_spec.rb +++ b/spec/features/admin/enterprises_spec.rb @@ -113,7 +113,7 @@ feature %q{ e2 = create(:enterprise) eg1 = create(:enterprise_group, name: 'eg1') eg2 = create(:enterprise_group, name: 'eg2') - payment_method = create(:payment_method, distributors: []) + payment_method = create(:payment_method, distributors: [e2]) shipping_method = create(:shipping_method, distributors: [e2]) enterprise_fee = create(:enterprise_fee, enterprise: @enterprise ) diff --git a/spec/features/admin/payment_method_spec.rb b/spec/features/admin/payment_method_spec.rb index 660a187b3d..36fe344930 100644 --- a/spec/features/admin/payment_method_spec.rb +++ b/spec/features/admin/payment_method_spec.rb @@ -21,7 +21,7 @@ feature %q{ fill_in 'payment_method_name', :with => 'Cheque payment method' - select @distributors[0].name, :from => 'payment_method_distributor_ids', visible: false + check "payment_method_distributor_ids_#{@distributors[0].id}" click_button 'Create' flash_message.should == 'Payment Method has been successfully created!' @@ -29,6 +29,28 @@ feature %q{ payment_method = Spree::PaymentMethod.find_by_name('Cheque payment method') payment_method.distributors.should == [@distributors[0]] end + + scenario "updating a payment method" do + pm = create(:payment_method, distributors: [@distributors[0]]) + login_to_admin_section + + visit spree.edit_admin_payment_method_path pm + + fill_in 'payment_method_name', :with => 'New PM Name' + + uncheck "payment_method_distributor_ids_#{@distributors[0].id}" + check "payment_method_distributor_ids_#{@distributors[1].id}" + check "payment_method_distributor_ids_#{@distributors[2].id}" + select2_select "PayPal Express", from: "payment_method_type" + click_button 'Update' + + expect(flash_message).to eq 'Payment Method has been successfully updated!' + + payment_method = Spree::PaymentMethod.find_by_name('New PM Name') + expect(payment_method.distributors).to include @distributors[1], @distributors[2] + expect(payment_method.distributors).not_to include @distributors[0] + expect(payment_method.type).to eq "Spree::Gateway::PayPalExpress" + end end context "as an enterprise user" do @@ -46,14 +68,18 @@ feature %q{ login_to_admin_as enterprise_user end - it "creates payment methods" do + it "I can get to the new enterprise page" do click_link 'Enterprises' within(".enterprise-#{distributor1.id}") { click_link 'Payment Methods' } click_link 'New Payment Method' + current_path.should == spree.new_admin_payment_method_path + end + it "creates payment methods" do + visit spree.new_admin_payment_method_path fill_in 'payment_method_name', :with => 'Cheque payment method' - select distributor1.name, :from => 'payment_method_distributor_ids' + check "payment_method_distributor_ids_#{distributor1.id}" click_button 'Create' flash_message.should == 'Payment Method has been successfully created!' diff --git a/spec/features/consumer/shopping/checkout_auth_spec.rb b/spec/features/consumer/shopping/checkout_auth_spec.rb index 81ee44fdcd..2e756879a9 100644 --- a/spec/features/consumer/shopping/checkout_auth_spec.rb +++ b/spec/features/consumer/shopping/checkout_auth_spec.rb @@ -12,7 +12,8 @@ feature "As a consumer I want to check out my cart", js: true do let!(:order_cycle) { create(:simple_order_cycle, distributors: [distributor], coordinator: create(:distributor_enterprise)) } let(:product) { create(:simple_product, supplier: supplier) } let(:order) { create(:order, order_cycle: order_cycle, distributor: distributor) } - let(:user) { create_enterprise_user } + let(:address) { create(:address, firstname: "Foo", lastname: "Bar") } + let(:user) { create(:user, bill_address: address, ship_address: address) } after { Warden.test_reset! } before do @@ -38,6 +39,19 @@ feature "As a consumer I want to check out my cart", js: true do page.should have_login_modal end + it "populates user details once logged in" do + visit checkout_path + within("section[role='main']") { click_button "Log in" } + page.should have_login_modal + fill_in "Email", with: user.email + fill_in "Password", with: user.password + within(".login-modal") { click_button 'Log in' } + toggle_details + + page.should have_field 'First Name', with: 'Foo' + page.should have_field 'Last Name', with: 'Bar' + end + it "allows user to checkout as guest" do visit checkout_path checkout_as_guest diff --git a/spec/features/consumer/shopping/checkout_spec.rb b/spec/features/consumer/shopping/checkout_spec.rb index e3e2c9c4ad..846fc57a9b 100644 --- a/spec/features/consumer/shopping/checkout_spec.rb +++ b/spec/features/consumer/shopping/checkout_spec.rb @@ -72,8 +72,7 @@ feature "As a consumer I want to check out my cart", js: true do let!(:pm1) { create(:payment_method, distributors: [distributor], name: "Roger rabbit", type: "Spree::PaymentMethod::Check") } let!(:pm2) { create(:payment_method, distributors: [distributor]) } let!(:pm3) do - Spree::Gateway::PayPalExpress.create!(name: "Paypal", environment: 'test').tap do |pm| - pm.distributors << distributor + Spree::Gateway::PayPalExpress.create!(name: "Paypal", environment: 'test', distributor_ids: [distributor.id]).tap do |pm| pm.preferred_login = 'devnull-facilitator_api1.rohanmitchell.com' pm.preferred_password = '1406163716' pm.preferred_signature = 'AFcWxV21C7fd0v3bYYYRCpSSRl31AaTntNJ-AjvUJkWf4dgJIvcLsf1V' diff --git a/spec/javascripts/unit/admin/controllers/providers_controller_decorator.js.coffee b/spec/javascripts/unit/admin/controllers/providers_controller_decorator.js.coffee new file mode 100644 index 0000000000..2fcd776035 --- /dev/null +++ b/spec/javascripts/unit/admin/controllers/providers_controller_decorator.js.coffee @@ -0,0 +1,30 @@ +describe "ProvidersCtrl", -> + ctrl = null + scope = null + paymentMethod = null + + describe "initialising using a payment method without a type", -> + beforeEach -> + module 'ofn.admin' + scope = {} + paymentMethod = + type: null + + inject ($controller)-> + ctrl = $controller 'ProvidersCtrl', {$scope: scope, paymentMethod: paymentMethod } + + it "sets the invlude_html porperty on scope to blank", -> + expect(scope.include_html).toBe "" + + describe "initialising using a payment method with a type", -> + beforeEach -> + module 'ofn.admin' + scope = {} + paymentMethod = + type: "NOT NULL" + + inject ($controller)-> + ctrl = $controller 'ProvidersCtrl', {$scope: scope, paymentMethod: paymentMethod } + + it "sets the include_html porperty on scope to some address", -> + expect(scope.include_html).toBe "/admin/payment_methods/show_provider_preferences?provider_type=NOT NULL;pm_id=#{paymentMethod.id};" \ No newline at end of file diff --git a/spec/javascripts/unit/admin/services/taxons_spec.js.coffee b/spec/javascripts/unit/admin/services/taxons_spec.js.coffee new file mode 100644 index 0000000000..9dd22935d5 --- /dev/null +++ b/spec/javascripts/unit/admin/services/taxons_spec.js.coffee @@ -0,0 +1,32 @@ +describe "Taxons service", -> + Taxons = taxons = $httpBackend = $resource = null + + beforeEach -> + module "ofn.admin" + module ($provide)-> + $provide.value "taxons", [{id: "1", name: "t1"}, {id: "2", name: "t2"}, {id: "12", name: "t12"}, {id: "31", name: "t31"}] + null + + beforeEach inject (_Taxons_, _$resource_, _$httpBackend_) -> + Taxons = _Taxons_ + $resource = _$resource_ + $httpBackend = _$httpBackend_ + + describe "findByID", -> + it "returns the taxon with exactly matching id, ignoring ids which do not exactly match", -> + result = Taxons.findByID("1") + expect(result).toEqual {id: "1", name: "t1"} + + describe "findByIDs", -> + it "returns taxons with exactly matching ids", -> + result = Taxons.findByIDs("1,2") + expect(result).toEqual [{id: "1", name: "t1"}, {id: "2", name: "t2"}] + + it "ignores ids which do not exactly match", -> + result = Taxons.findByIDs("1,3") + expect(result).toEqual [{id: "1", name: "t1"}] + + describe "findByTerm", -> + it "returns taxons which match partially", -> + result = Taxons.findByTerm("t1") + expect(result).toEqual [{id: "1", name: "t1"}, {id: "12", name: "t12"}] \ No newline at end of file diff --git a/spec/javascripts/unit/bulk_product_update_spec.js.coffee b/spec/javascripts/unit/bulk_product_update_spec.js.coffee index 44466b5d10..b9081a1882 100644 --- a/spec/javascripts/unit/bulk_product_update_spec.js.coffee +++ b/spec/javascripts/unit/bulk_product_update_spec.js.coffee @@ -184,10 +184,7 @@ describe "filtering products for submission to database", -> created_at: null updated_at: null count_on_hand: 0 - supplier_id: 5 - supplier: - id: 5 - name: "Supplier 1" + producer: 5 group_buy: null group_buy_unit_size: null @@ -238,6 +235,11 @@ describe "AdminProductEditCtrl", -> beforeEach -> module "ofn.admin" + module ($provide)-> + $provide.value "producers", [] + $provide.value "taxons", [] + null + beforeEach inject((_$controller_, _$timeout_, $rootScope, _$httpBackend_, _DirtyProducts_) -> $scope = $rootScope.$new() $ctrl = _$controller_ @@ -249,38 +251,43 @@ describe "AdminProductEditCtrl", -> ) describe "loading data upon initialisation", -> - it "gets a list of suppliers and then resets products with a list of data", -> + it "gets a list of producers and then resets products with a list of data", -> $httpBackend.expectGET("/api/users/authorise_api?token=api_key").respond success: "Use of API Authorised" - $httpBackend.expectGET("/api/enterprises/managed?template=bulk_index&q[is_primary_producer_eq]=true").respond "list of suppliers" spyOn($scope, "fetchProducts").andReturn "nothing" $scope.initialise "api_key" $httpBackend.flush() - expect($scope.suppliers).toEqual "list of suppliers" expect($scope.fetchProducts.calls.length).toEqual 1 expect($scope.spree_api_key_ok).toEqual true describe "fetching products", -> it "makes a standard call to dataFetcher when no filters exist", -> - $httpBackend.expectGET("/api/products/managed?template=bulk_index;page=1;per_page=500;").respond "list of products" + $httpBackend.expectGET("/api/products/bulk_products?page=1;per_page=20;").respond "list of products" $scope.fetchProducts() it "calls resetProducts after data has been received", -> spyOn $scope, "resetProducts" - $httpBackend.expectGET("/api/products/managed?template=bulk_index;page=1;per_page=500;").respond "list of products" + $httpBackend.expectGET("/api/products/bulk_products?page=1;per_page=20;").respond { products: "list of products" } $scope.fetchProducts() $httpBackend.flush() expect($scope.resetProducts).toHaveBeenCalledWith "list of products" + it "calls makes more calls to dataFetcher if more pages exist", -> + $httpBackend.expectGET("/api/products/bulk_products?page=1;per_page=20;").respond { products: [], pages: 2 } + $httpBackend.expectGET("/api/products/bulk_products?page=2;per_page=20;").respond { products: ["list of products"] } + $scope.fetchProducts() + $httpBackend.flush() + it "applies filters when they are present", -> filter = {property: $scope.filterableColumns[1], predicate:$scope.filterTypes[0], value:"Product1"} $scope.currentFilters.push filter # Don't use addFilter as that is not what we are testing expect($scope.currentFilters).toEqual [filter] - $httpBackend.expectGET("/api/products/managed?template=bulk_index;page=1;per_page=500;q[name_eq]=Product1;").respond "list of products" + $httpBackend.expectGET("/api/products/bulk_products?page=1;per_page=20;q[name_eq]=Product1;").respond "list of products" $scope.fetchProducts() + $httpBackend.flush() it "sets the loading property to true before fetching products and unsets it when loading is complete", -> - $httpBackend.expectGET("/api/products/managed?template=bulk_index;page=1;per_page=500;").respond "list of products" + $httpBackend.expectGET("/api/products/bulk_products?page=1;per_page=20;").respond "list of products" $scope.fetchProducts() expect($scope.loading).toEqual true $httpBackend.flush() @@ -324,7 +331,6 @@ describe "AdminProductEditCtrl", -> describe "preparing products", -> beforeEach -> - spyOn $scope, "matchSupplier" spyOn $scope, "loadVariantUnit" it "initialises display properties for the product", -> @@ -333,12 +339,6 @@ describe "AdminProductEditCtrl", -> $scope.unpackProduct product expect($scope.displayProperties[123]).toEqual {showVariants: false} - it "calls matchSupplier for the product", -> - product = {id: 123} - $scope.displayProperties = {} - $scope.unpackProduct product - expect($scope.matchSupplier.calls.length).toEqual 1 - it "calls loadVariantUnit for the product", -> product = {id: 123} $scope.displayProperties = {} @@ -346,33 +346,6 @@ describe "AdminProductEditCtrl", -> expect($scope.loadVariantUnit.calls.length).toEqual 1 - describe "matching supplier", -> - it "changes the supplier of the product to the one which matches it from the suppliers list", -> - s1_s = - id: 1 - name: "S1" - - s2_s = - id: 2 - name: "S2" - - s1_p = - id: 1 - name: "S1" - - expect(s1_s is s1_p).not.toEqual true - $scope.suppliers = [ - s1_s - s2_s - ] - product = - id: 10 - supplier: s1_p - - $scope.matchSupplier product - expect(product.supplier is s1_s).toEqual true - - describe "loading variant unit", -> describe "setting product variant_unit_with_scale field", -> it "sets by combining variant_unit and variant_unit_scale", -> @@ -397,8 +370,9 @@ describe "AdminProductEditCtrl", -> $scope.loadVariantUnit product expect(product.variant_unit_with_scale).toEqual "items" - it "loads data for variants (inc. master)", -> - spyOn $scope, "loadVariantVariantUnit" + it "loads data for variants (incl. master)", -> + spyOn $scope, "loadVariantUnitValues" + spyOn $scope, "loadVariantUnitValue" product = variant_unit_scale: 1.0 @@ -406,15 +380,27 @@ describe "AdminProductEditCtrl", -> variants: [{id: 2, unit_value: 2, unit_description: '(two)'}] $scope.loadVariantUnit product - expect($scope.loadVariantVariantUnit).toHaveBeenCalledWith product, product.variants[0] - expect($scope.loadVariantVariantUnit).toHaveBeenCalledWith product, product.master + expect($scope.loadVariantUnitValues).toHaveBeenCalledWith product + expect($scope.loadVariantUnitValue).toHaveBeenCalledWith product, product.master + + it "loads data for variants (excl. master)", -> + spyOn $scope, "loadVariantUnitValue" + + product = + variant_unit_scale: 1.0 + master: {id: 1, unit_value: 1, unit_description: '(one)'} + variants: [{id: 2, unit_value: 2, unit_description: '(two)'}] + $scope.loadVariantUnitValues product + + expect($scope.loadVariantUnitValue).toHaveBeenCalledWith product, product.variants[0] + expect($scope.loadVariantUnitValue).not.toHaveBeenCalledWith product, product.master describe "setting variant unit_value_with_description", -> it "sets by combining unit_value and unit_description", -> product = variant_unit_scale: 1.0 variants: [{id: 1, unit_value: 1, unit_description: '(bottle)'}] - $scope.loadVariantVariantUnit product, product.variants[0] + $scope.loadVariantUnitValues product, product.variants[0] expect(product.variants[0]).toEqual id: 1 unit_value: 1 @@ -425,28 +411,28 @@ describe "AdminProductEditCtrl", -> product = variant_unit_scale: 1.0 variants: [{id: 1, unit_value: 1}] - $scope.loadVariantVariantUnit product, product.variants[0] + $scope.loadVariantUnitValues product, product.variants[0] expect(product.variants[0].unit_value_with_description).toEqual '1' it "uses unit_description when value is missing", -> product = variant_unit_scale: 1.0 variants: [{id: 1, unit_description: 'Small'}] - $scope.loadVariantVariantUnit product, product.variants[0] + $scope.loadVariantUnitValues product, product.variants[0] expect(product.variants[0].unit_value_with_description).toEqual 'Small' it "converts values from base value to chosen unit", -> product = variant_unit_scale: 1000.0 variants: [{id: 1, unit_value: 2500}] - $scope.loadVariantVariantUnit product, product.variants[0] + $scope.loadVariantUnitValues product, product.variants[0] expect(product.variants[0].unit_value_with_description).toEqual '2.5' it "displays a unit_value of zero", -> product = variant_unit_scale: 1.0 variants: [{id: 1, unit_value: 0}] - $scope.loadVariantVariantUnit product, product.variants[0] + $scope.loadVariantUnitValues product, product.variants[0] expect(product.variants[0].unit_value_with_description).toEqual '0' @@ -827,6 +813,8 @@ describe "AdminProductEditCtrl", -> it "runs displaySuccess() when post returns success", -> spyOn $scope, "displaySuccess" + spyOn $scope, "updateVariantLists" + spyOn DirtyProducts, "clear" $scope.products = [ { id: 1 @@ -851,104 +839,34 @@ describe "AdminProductEditCtrl", -> $httpBackend.flush() $timeout.flush() expect($scope.displaySuccess).toHaveBeenCalled() + expect(DirtyProducts.clear).toHaveBeenCalled() + expect($scope.updateVariantLists).toHaveBeenCalled() - it "runs displayFailure() when post return data does not match $scope.products", -> - spyOn $scope, "displayFailure" - $scope.products = "current list of products" - $httpBackend.expectPOST("/admin/products/bulk_update").respond 200, "returned list of products" - $scope.updateProducts "updated list of products" - $httpBackend.flush() - expect($scope.displayFailure).toHaveBeenCalled() - - it "runs displayFailure() when post returns error", -> + it "runs displayFailure() when post returns an error", -> spyOn $scope, "displayFailure" $scope.products = "updated list of products" - $httpBackend.expectPOST("/admin/products/bulk_update").respond 404, "updated list of products" + $httpBackend.expectPOST("/admin/products/bulk_update").respond 500, "updated list of products" $scope.updateProducts "updated list of products" $httpBackend.flush() expect($scope.displayFailure).toHaveBeenCalled() - - describe "copying new variant ids from server to client", -> - it "copies server ids to the client where the client id is negative", -> - clientProducts = [ - { - id: 123 - variants: [{id: 1}, {id: -2}, {id: -3}] - } - ] - serverProducts = [ - { - id: 123 - variants: [{id: 1}, {id: 4534}, {id: 3453}] - } - ] - $scope.copyNewVariantIds(clientProducts, serverProducts) - expect(clientProducts).toEqual(serverProducts) - - - describe "fetching products without derived attributes", -> - it "returns products without the variant_unit_with_scale field", -> - $scope.products = [{id: 123, variant_unit_with_scale: 'weight_1000'}] - expect($scope.productsWithoutDerivedAttributes($scope.products)).toEqual([{id: 123}]) - - it "returns an empty array when products are undefined", -> - expect($scope.productsWithoutDerivedAttributes($scope.products)).toEqual([]) - - it "does not alter original products", -> - $scope.products = [{ - id: 123 - variant_unit_with_scale: 'weight_1000' - variants: [{options_text: 'foo'}] - }] - $scope.productsWithoutDerivedAttributes($scope.products) - expect($scope.products).toEqual [{ - id: 123 - variant_unit_with_scale: 'weight_1000' - variants: [{options_text: 'foo'}] - }] - - describe "updating variants", -> - it "returns variants without the unit_value_with_description field", -> - $scope.products = [{id: 123, variants: [{id: 234, unit_value_with_description: 'foo'}]}] - expect($scope.productsWithoutDerivedAttributes($scope.products)).toEqual [ - { - id: 123 - variants: [{id: 234}] - } - ] - - it "removes the master variant", -> - $scope.products = [{id: 123, master: {id: 234, unit_value_with_description: 'foo'}}] - expect($scope.productsWithoutDerivedAttributes($scope.products)).toEqual [ - { - id: 123 - } - ] - - - describe "deep copying products", -> - it "copies products", -> - product = {id: 123} - copiedProducts = $scope.deepCopyProducts [product] - expect(copiedProducts[0]).not.toBe(product) - - it "copies variants", -> - variant = {id: 1} - product = {id: 123, variants: [variant]} - copiedProducts = $scope.deepCopyProducts [product] - expect(copiedProducts[0].variants[0]).not.toBe(variant) - + it "shows an alert with error information when post returns 400 with an errors array", -> + spyOn(window, "alert") + $scope.products = "updated list of products" + $httpBackend.expectPOST("/admin/products/bulk_update").respond 400, { "errors": ["an error"] } + $scope.updateProducts "updated list of products" + $httpBackend.flush() + expect(window.alert).toHaveBeenCalledWith("Saving failed with the following error(s):\nan error\n") describe "fetching a product by id", -> it "returns the product when it is present", -> product = {id: 123} $scope.products = [product] - expect($scope.findProduct(123)).toEqual product + expect($scope.findProduct(123, $scope.products)).toEqual product it "returns null when the product is not present", -> $scope.products = [] - expect($scope.findProduct(123)).toBeNull() + expect($scope.findProduct(123, $scope.products)).toBeNull() describe "adding variants", -> @@ -1122,7 +1040,7 @@ describe "AdminProductEditCtrl", -> $scope.cloneProduct $scope.products[0] $httpBackend.flush() - it "adds the newly created product to $scope.products and matches supplier", -> + it "adds the newly created product to $scope.products and matches producer", -> spyOn($scope, "unpackProduct").andCallThrough() $scope.products = [ id: 13 @@ -1132,8 +1050,7 @@ describe "AdminProductEditCtrl", -> product: id: 17 name: "new_product" - supplier: - id: 6 + producer: 6 variants: [ id: 3 @@ -1143,8 +1060,7 @@ describe "AdminProductEditCtrl", -> $httpBackend.expectGET("/api/products/17?template=bulk_show").respond 200, id: 17 name: "new_product" - supplier: - id: 6 + producer: 6 variants: [ id: 3 @@ -1157,8 +1073,7 @@ describe "AdminProductEditCtrl", -> id: 17 name: "new_product" variant_unit_with_scale: null - supplier: - id: 6 + producer: 6 variants: [ id: 3 @@ -1175,8 +1090,7 @@ describe "AdminProductEditCtrl", -> id: 17 name: "new_product" variant_unit_with_scale: null - supplier: - id: 6 + producer: 6 variants: [ id: 3 @@ -1188,94 +1102,15 @@ describe "AdminProductEditCtrl", -> describe "filtering products", -> - describe "adding a filter to the filter list", -> - filterObject1 = filterObject2 = null - - beforeEach -> - spyOn($scope, "fetchProducts").andReturn "nothing" - spyOn(DirtyProducts, "count").andReturn 0 - filterObject1 = {property: $scope.filterableColumns[0], predicate: $scope.filterTypes[0], value: "value1"} - filterObject2 = {property: $scope.filterableColumns[1], predicate: $scope.filterTypes[1], value: "value2"} - $scope.addFilter filterObject1 - $scope.addFilter filterObject2 - - it "adds objects sent to addFilter() to $scope.currentFilters", -> - expect($scope.currentFilters).toEqual [filterObject1, filterObject2] - - it "ignores objects sent to addFilter() which do not contain a 'property' with a corresponding key in filterableColumns", -> - filterObject3 = {property: "some_random_property", predicate: $scope.filterTypes[0], value: "value3"} - $scope.addFilter filterObject3 - expect($scope.currentFilters).toEqual [filterObject1, filterObject2] - - it "ignores objects sent to addFilter() which do not contain a query with a corresponding key in filterTypes", -> - filterObject3 = {property: $scope.filterableColumns[0], predicate: "something", value: "value3"} - $scope.addFilter filterObject3 - expect($scope.currentFilters).toEqual [filterObject1, filterObject2] - - it "ignores objects sent to addFilter() which have a blank 'value' property", -> - filterObject3 = {property: $scope.filterableColumns[0], predicate: $scope.filterTypes[1], value: ""} - $scope.addFilter filterObject3 - expect($scope.currentFilters).toEqual [filterObject1, filterObject2] - - it "calls fetchProducts when adding a new filter", -> - expect($scope.fetchProducts.calls.length).toEqual(2) - - describe "when unsaved products exist", -> - beforeEach -> - filterObject3 = {property: $scope.filterableColumns[0], predicate: $scope.filterTypes[1], value: "value3"} - spyOn(window, "confirm").andReturn false - DirtyProducts.count.andReturn 1 - $scope.addFilter filterObject3 - - it "it does not call fetchProducts", -> - expect($scope.fetchProducts.calls.length).toEqual(2) - - it "does not add the filter to $scope.currentFilters", -> - expect($scope.currentFilters).toEqual [filterObject1, filterObject2] - - it "asks the user to save changes before proceeding", -> - expect(window.confirm).toHaveBeenCalledWith "Unsaved changes will be lost. Continue anyway?" - - describe "when a filter on the same property and predicate already exists", -> - filterObject3 = null - - beforeEach -> - filterObject3 = { property: filterObject2.property, predicate: filterObject2.predicate, value: "new value" } - - it "asks the user for permission before proceeding", -> - spyOn(window, "confirm").andReturn true - $scope.addFilter filterObject3 - expect(window.confirm).toHaveBeenCalledWith "'#{filterObject3.predicate.name}' filter already exists on column '#{filterObject3.property.name}'. Replace it?" - - it "replaces the filter in $scope.currentFilters when user clicks OK", -> - spyOn(window, "confirm").andReturn true - $scope.addFilter filterObject3 - expect($scope.currentFilters).toEqual [filterObject1, filterObject3] - - it "does not add the filter to $scope.currentFilters when user clicks cancel", -> - spyOn(window, "confirm").andReturn false - $scope.addFilter filterObject3 - expect($scope.currentFilters).toEqual [filterObject1, filterObject2] - - describe "removing a filter from the filter list", -> - filterObject1 = filterObject2 = null - - beforeEach -> - spyOn($scope, "fetchProducts").andReturn "nothing" - filterObject1 = {property: $scope.filterableColumns[0], predicate: $scope.filterTypes[0], value: "Product1"} - filterObject2 = {property: $scope.filterableColumns[0], predicate: $scope.filterTypes[0], value: "Product2"} - $scope.currentFilters = [ filterObject1, filterObject2 ] - - it "removes the specified filter from $scope.currentFilters and calls fetchProducts", -> - $scope.removeFilter filterObject1 - expect($scope.currentFilters).toEqual [ filterObject2 ] - expect($scope.fetchProducts.calls.length).toEqual 1 - - it "ignores filters which do not exist in currentFilters", -> - filterObject3 = {property: $scope.filterableColumns[1], predicate: $scope.filterTypes[1], value: "SomethingElse"} - $scope.removeFilter filterObject3 - expect($scope.currentFilters).toEqual [ filterObject1, filterObject2 ] - expect($scope.fetchProducts.calls.length).toEqual 0 + describe "clearing filters", -> + it "resets filter variables", -> + $scope.query = "lala" + $scope.producerFilter = "5" + $scope.categoryFilter = "6" + $scope.resetSelectFilters() + expect($scope.query).toBe "" + expect($scope.producerFilter).toBe "0" + expect($scope.categoryFilter).toBe "0" describe "converting arrays of objects with ids to an object with ids as keys", -> @@ -1334,28 +1169,3 @@ describe "converting arrays of objects with ids to an object with ids as keys", expect(toObjectWithIDKeys).toHaveBeenCalledWith [id: 17] expect(toObjectWithIDKeys).not.toHaveBeenCalledWith {12: {id: 12}} - -describe "Taxons service", -> - Taxons = $httpBackend = $resource = null - - beforeEach -> - module "ofn.admin" - - beforeEach inject (_Taxons_, _$resource_, _$httpBackend_) -> - Taxons = _Taxons_ - $resource = _$resource_ - $httpBackend = _$httpBackend_ - - it "calling findByIDs makes a http request", -> - response = { taxons: "list of taxons by id" } - $httpBackend.expectGET("/admin/taxons/search?ids=1,2").respond 200, response - taxons = Taxons.findByIDs("1,2") - $httpBackend.flush() - expect(angular.equals(taxons,response)).toBe true - - it "calling findByTerm makes a http request", -> - response = { taxons: "list of taxons by term" } - $httpBackend.expectGET("/admin/taxons/search?q=lala").respond 200, response - taxons = Taxons.findByTerm("lala") - $httpBackend.flush() - expect(angular.equals(taxons,response)).toBe true diff --git a/spec/javascripts/unit/darkswarm/controllers/checkout/checkout_controller_spec.js.coffee b/spec/javascripts/unit/darkswarm/controllers/checkout/checkout_controller_spec.js.coffee index ceebc55eab..d56a7495ab 100644 --- a/spec/javascripts/unit/darkswarm/controllers/checkout/checkout_controller_spec.js.coffee +++ b/spec/javascripts/unit/darkswarm/controllers/checkout/checkout_controller_spec.js.coffee @@ -46,7 +46,7 @@ describe "CheckoutCtrl", -> describe "Local storage", -> it "binds to localStorage when given a scope", -> - prefix = "order_#{scope.order.id}#{scope.order.user_id}#{CurrentHubMock.hub.id}" + prefix = "order_#{scope.order.id}#{CurrentUser?.id}#{CurrentHubMock.hub.id}" field = scope.fieldsToBind[0] expect(storage.bind).toHaveBeenCalledWith(scope, "Checkout.order.#{field}", {storeName: "#{prefix}_#{field}"}) expect(storage.bind).toHaveBeenCalledWith(scope, "Checkout.ship_address_same_as_billing", {storeName: "#{prefix}_sameasbilling", defaultValue: true}) diff --git a/spec/javascripts/unit/darkswarm/services/product_spec.js.coffee b/spec/javascripts/unit/darkswarm/services/product_spec.js.coffee index 237cbcd369..d7c5a20b91 100644 --- a/spec/javascripts/unit/darkswarm/services/product_spec.js.coffee +++ b/spec/javascripts/unit/darkswarm/services/product_spec.js.coffee @@ -14,6 +14,7 @@ describe 'Products service', -> supplier: id: 9 price: 11 + master: {} variants: [] currentOrder = line_items: [] @@ -39,7 +40,7 @@ describe 'Products service', -> it "dereferences suppliers", -> Enterprises.enterprises_by_id = {id: 9, name: "test"} - $httpBackend.expectGET("/shop/products").respond([{supplier : {id: 9}}]) + $httpBackend.expectGET("/shop/products").respond([{supplier : {id: 9}, master: {}}]) $httpBackend.flush() expect(Products.products[0].supplier).toBe Enterprises.enterprises_by_id["9"] diff --git a/spec/lib/open_food_network/enterprise_fee_calculator_spec.rb b/spec/lib/open_food_network/enterprise_fee_calculator_spec.rb index 0ca7da4999..9c950234cd 100644 --- a/spec/lib/open_food_network/enterprise_fee_calculator_spec.rb +++ b/spec/lib/open_food_network/enterprise_fee_calculator_spec.rb @@ -37,19 +37,20 @@ module OpenFoodNetwork let!(:ef_sales) { create(:enterprise_fee, fee_type: 'sales', amount: 4.56) } let!(:ef_packing) { create(:enterprise_fee, fee_type: 'packing', amount: 7.89) } let!(:ef_transport) { create(:enterprise_fee, fee_type: 'transport', amount: 0.12) } + let!(:ef_fundraising) { create(:enterprise_fee, fee_type: 'fundraising', amount: 3.45) } let!(:exchange) { create(:exchange, order_cycle: order_cycle, sender: coordinator, receiver: distributor, incoming: false, - enterprise_fees: [ef_admin, ef_sales, ef_packing, ef_transport], + enterprise_fees: [ef_admin, ef_sales, ef_packing, ef_transport, ef_fundraising], variants: [product.master]) } it "returns a breakdown of fees" do - EnterpriseFeeCalculator.new(distributor, order_cycle).fees_by_type_for(product.master).should == {admin: 1.23, sales: 4.56, packing: 7.89, transport: 0.12} + EnterpriseFeeCalculator.new(distributor, order_cycle).fees_by_type_for(product.master).should == {admin: 1.23, sales: 4.56, packing: 7.89, transport: 0.12, fundraising: 3.45} end it "filters out zero fees" do ef_admin.calculator.update_attribute :preferred_amount, 0 - EnterpriseFeeCalculator.new(distributor, order_cycle).fees_by_type_for(product.master).should == {sales: 4.56, packing: 7.89, transport: 0.12} + EnterpriseFeeCalculator.new(distributor, order_cycle).fees_by_type_for(product.master).should == {sales: 4.56, packing: 7.89, transport: 0.12, fundraising: 3.45} end end diff --git a/spec/lib/open_food_network/option_value_namer_spec.rb b/spec/lib/open_food_network/option_value_namer_spec.rb index b16574ba4c..354fd46369 100644 --- a/spec/lib/open_food_network/option_value_namer_spec.rb +++ b/spec/lib/open_food_network/option_value_namer_spec.rb @@ -4,34 +4,34 @@ module OpenFoodNetwork describe OptionValueNamer do describe "generating option value name" do let(:v) { Spree::Variant.new } - let(:subject) { OptionValueNamer.new v } + let(:subject) { OptionValueNamer.new } it "when description is blank" do v.stub(:unit_description) { nil } subject.stub(:value_scaled?) { true } subject.stub(:option_value_value_unit) { %w(value unit) } - subject.name.should == "valueunit" + subject.name(v).should == "valueunit" end it "when description is present" do v.stub(:unit_description) { 'desc' } subject.stub(:option_value_value_unit) { %w(value unit) } subject.stub(:value_scaled?) { true } - subject.name.should == "valueunit desc" + subject.name(v).should == "valueunit desc" end it "when value is blank and description is present" do v.stub(:unit_description) { 'desc' } subject.stub(:option_value_value_unit) { [nil, nil] } subject.stub(:value_scaled?) { true } - subject.name.should == "desc" + subject.name(v).should == "desc" end it "spaces value and unit when value is unscaled" do v.stub(:unit_description) { nil } subject.stub(:option_value_value_unit) { %w(value unit) } subject.stub(:value_scaled?) { false } - subject.name.should == "value unit" + subject.name(v).should == "value unit" end end @@ -42,7 +42,7 @@ module OpenFoodNetwork v.stub(:product) { p } subject = OptionValueNamer.new v - subject.value_scaled?.should be_true + expect(subject.send(:value_scaled?)).to be_true end it "returns false otherwise" do @@ -51,7 +51,7 @@ module OpenFoodNetwork v.stub(:product) { p } subject = OptionValueNamer.new v - subject.value_scaled?.should be_false + expect(subject.send(:value_scaled?)).to be_false end end @@ -65,7 +65,7 @@ module OpenFoodNetwork v.stub(:unit_value) { 100 } - subject.option_value_value_unit.should == [100, 'g'] + expect(subject.send(:option_value_value_unit)).to eq [100, 'g'] end it "generates values when unit value is non-integer" do @@ -73,7 +73,7 @@ module OpenFoodNetwork v.stub(:product) { p } v.stub(:unit_value) { 123.45 } - subject.option_value_value_unit.should == [123.45, 'g'] + expect(subject.send(:option_value_value_unit)).to eq [123.45, 'g'] end it "returns a value of 1 when unit value equals the scale" do @@ -81,7 +81,7 @@ module OpenFoodNetwork v.stub(:product) { p } v.stub(:unit_value) { 1000.0 } - subject.option_value_value_unit.should == [1, 'kg'] + expect(subject.send(:option_value_value_unit)).to eq [1, 'kg'] end it "generates values for all weight scales" do @@ -89,7 +89,7 @@ module OpenFoodNetwork p = double(:product, variant_unit: 'weight', variant_unit_scale: scale) v.stub(:product) { p } v.stub(:unit_value) { 100 * scale } - subject.option_value_value_unit.should == [100, unit] + expect(subject.send(:option_value_value_unit)).to eq [100, unit] end end @@ -98,7 +98,7 @@ module OpenFoodNetwork p = double(:product, variant_unit: 'volume', variant_unit_scale: scale) v.stub(:product) { p } v.stub(:unit_value) { 100 * scale } - subject.option_value_value_unit.should == [100, unit] + expect(subject.send(:option_value_value_unit)).to eq [100, unit] end end @@ -106,7 +106,7 @@ module OpenFoodNetwork p = double(:product, variant_unit: 'volume', variant_unit_scale: 0.001) v.stub(:product) { p } v.stub(:unit_value) { 0.0001 } - subject.option_value_value_unit.should == [0.1, 'mL'] + expect(subject.send(:option_value_value_unit)).to eq [0.1, 'mL'] end it "generates values for item units" do @@ -114,7 +114,7 @@ module OpenFoodNetwork p = double(:product, variant_unit: 'items', variant_unit_scale: nil, variant_unit_name: unit) v.stub(:product) { p } v.stub(:unit_value) { 100 } - subject.option_value_value_unit.should == [100, unit.pluralize] + expect(subject.send(:option_value_value_unit)).to eq [100, unit.pluralize] end end @@ -122,14 +122,14 @@ module OpenFoodNetwork p = double(:product, variant_unit: 'items', variant_unit_scale: nil, variant_unit_name: 'packet') v.stub(:product) { p } v.stub(:unit_value) { 1 } - subject.option_value_value_unit.should == [1, 'packet'] + expect(subject.send(:option_value_value_unit)).to eq [1, 'packet'] end it "returns [nil, nil] when unit value is not set" do p = double(:product, variant_unit: 'items', variant_unit_scale: nil, variant_unit_name: 'foo') v.stub(:product) { p } v.stub(:unit_value) { nil } - subject.option_value_value_unit.should == [nil, nil] + expect(subject.send(:option_value_value_unit)).to eq [nil, nil] end end end diff --git a/spec/models/product_distribution_spec.rb b/spec/models/product_distribution_spec.rb index 44ebb3cfd3..7e1a6933bc 100644 --- a/spec/models/product_distribution_spec.rb +++ b/spec/models/product_distribution_spec.rb @@ -25,6 +25,8 @@ describe ProductDistribution do describe "adjusting orders" do context "integration" do it "creates an adjustment for product distributions" do + pending "Intermittently failing spec - we intend to remove product distributions soon" + # Given an order distributor = create(:distributor_enterprise) order = create(:order, distributor: distributor) diff --git a/spec/models/spree/order_spec.rb b/spec/models/spree/order_spec.rb index 085ee615c6..63c315a18a 100644 --- a/spec/models/spree/order_spec.rb +++ b/spec/models/spree/order_spec.rb @@ -22,9 +22,11 @@ describe Spree::Order do end describe "Payment methods" do - let(:order) { build(:order, distributor: create(:distributor_enterprise)) } - let(:pm1) { create(:payment_method, distributors: [order.distributor])} - let(:pm2) { create(:payment_method, distributors: [])} + let(:order_distributor) { create(:distributor_enterprise) } + let(:some_other_distributor) { create(:distributor_enterprise) } + let(:order) { build(:order, distributor: order_distributor) } + let(:pm1) { create(:payment_method, distributors: [order_distributor])} + let(:pm2) { create(:payment_method, distributors: [some_other_distributor])} it "finds the correct payment methods" do Spree::PaymentMethod.stub(:available).and_return [pm1, pm2] diff --git a/spec/models/spree/payment_method_spec.rb b/spec/models/spree/payment_method_spec.rb index ef70afd426..692db7c7a4 100644 --- a/spec/models/spree/payment_method_spec.rb +++ b/spec/models/spree/payment_method_spec.rb @@ -9,5 +9,20 @@ module Spree PaymentMethod.by_name.should == [pm2, pm3, pm1] end + + it "raises errors when required fields are missing" do + pm = PaymentMethod.new() + pm.save + pm.errors.to_a.should == ["Name can't be blank", "At least one hub must be selected"] + end + + it "generates a clean name for known Payment Method types" do + Spree::PaymentMethod::Check.clean_name.should == "Cash/EFT/etc. (payments for which automatic validation is not required)" + Spree::Gateway::Migs.clean_name.should == "MasterCard Internet Gateway Service (MIGS)" + Spree::Gateway::PayPalExpress.clean_name.should == "PayPal Express" + + # Testing else condition + Spree::Gateway::BogusSimple.clean_name.should == "BogusSimple" + end end end diff --git a/spec/serializers/spree/product_serializer_spec.rb b/spec/serializers/spree/product_serializer_spec.rb new file mode 100644 index 0000000000..bbb65c1c7e --- /dev/null +++ b/spec/serializers/spree/product_serializer_spec.rb @@ -0,0 +1,7 @@ +describe Spree::Api::ProductSerializer do + let(:product) { create(:simple_product) } + it "serializes a product" do + serializer = Spree::Api::ProductSerializer.new product + serializer.to_json.should match product.name + end +end \ No newline at end of file diff --git a/spec/serializers/spree/variant_serializer_spec.rb b/spec/serializers/spree/variant_serializer_spec.rb new file mode 100644 index 0000000000..e0f26d3423 --- /dev/null +++ b/spec/serializers/spree/variant_serializer_spec.rb @@ -0,0 +1,7 @@ +describe Spree::Api::VariantSerializer do + let(:variant) { create(:variant) } + it "serializes a variant" do + serializer = Spree::Api::VariantSerializer.new variant + serializer.to_json.should match variant.options_text + end +end \ No newline at end of file diff --git a/vendor/assets/javascripts/angular-timer.min.js b/vendor/assets/javascripts/angular-timer.min.js deleted file mode 100755 index 9fdc966a93..0000000000 --- a/vendor/assets/javascripts/angular-timer.min.js +++ /dev/null @@ -1,8 +0,0 @@ -/** - * angular-timer - v1.1.6 - 2014-07-01 7:37 AM - * https://github.com/siddii/angular-timer - * - * Copyright (c) 2014 Siddique Hameed - * Licensed MIT - */ -var timerModule=angular.module("timer",[]).directive("timer",["$compile",function(a){return{restrict:"EAC",replace:!1,scope:{interval:"=interval",startTimeAttr:"=startTime",endTimeAttr:"=endTime",countdownattr:"=countdown",finishCallback:"&finishCallback",autoStart:"&autoStart",maxTimeUnit:"="},controller:["$scope","$element","$attrs","$timeout",function(b,c,d,e){function f(){b.timeoutId&&clearTimeout(b.timeoutId)}function g(){b.maxTimeUnit&&"day"!==b.maxTimeUnit?"second"===b.maxTimeUnit?(b.seconds=Math.floor(b.millis/1e3),b.minutes=0,b.hours=0,b.days=0,b.months=0,b.years=0):"minute"===b.maxTimeUnit?(b.seconds=Math.floor(b.millis/1e3%60),b.minutes=Math.floor(b.millis/6e4),b.hours=0,b.days=0,b.months=0,b.years=0):"hour"===b.maxTimeUnit?(b.seconds=Math.floor(b.millis/1e3%60),b.minutes=Math.floor(b.millis/6e4%60),b.hours=Math.floor(b.millis/36e5),b.days=0,b.months=0,b.years=0):"month"===b.maxTimeUnit?(b.seconds=Math.floor(b.millis/1e3%60),b.minutes=Math.floor(b.millis/6e4%60),b.hours=Math.floor(b.millis/36e5%24),b.days=Math.floor(b.millis/36e5/24%30),b.months=Math.floor(b.millis/36e5/24/30),b.years=0):"year"===b.maxTimeUnit&&(b.seconds=Math.floor(b.millis/1e3%60),b.minutes=Math.floor(b.millis/6e4%60),b.hours=Math.floor(b.millis/36e5%24),b.days=Math.floor(b.millis/36e5/24%30),b.months=Math.floor(b.millis/36e5/24/30%12),b.years=Math.floor(b.millis/36e5/24/365)):(b.seconds=Math.floor(b.millis/1e3%60),b.minutes=Math.floor(b.millis/6e4%60),b.hours=Math.floor(b.millis/36e5%24),b.days=Math.floor(b.millis/36e5/24),b.months=0,b.years=0),b.secondsS=1==b.seconds?"":"s",b.minutesS=1==b.minutes?"":"s",b.hoursS=1==b.hours?"":"s",b.daysS=1==b.days?"":"s",b.monthsS=1==b.months?"":"s",b.yearsS=1==b.years?"":"s",b.sseconds=b.seconds<10?"0"+b.seconds:b.seconds,b.mminutes=b.minutes<10?"0"+b.minutes:b.minutes,b.hhours=b.hours<10?"0"+b.hours:b.hours,b.ddays=b.days<10?"0"+b.days:b.days,b.mmonths=b.months<10?"0"+b.months:b.months,b.yyears=b.years<10?"0"+b.years:b.years}"function"!=typeof String.prototype.trim&&(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")}),b.autoStart=d.autoStart||d.autostart,c.append(0===c.html().trim().length?a("{{millis}}")(b):a(c.contents())(b)),b.startTime=null,b.endTime=null,b.timeoutId=null,b.countdown=b.countdownattr&&parseInt(b.countdownattr,10)>=0?parseInt(b.countdownattr,10):void 0,b.isRunning=!1,b.$on("timer-start",function(){b.start()}),b.$on("timer-resume",function(){b.resume()}),b.$on("timer-stop",function(){b.stop()}),b.$on("timer-clear",function(){b.clear()}),b.$on("timer-set-countdown",function(a,c){b.countdown=c}),b.start=c[0].start=function(){b.startTime=b.startTimeAttr?new Date(b.startTimeAttr):new Date,b.endTime=b.endTimeAttr?new Date(b.endTimeAttr):null,b.countdown||(b.countdown=b.countdownattr&&parseInt(b.countdownattr,10)>0?parseInt(b.countdownattr,10):void 0),f(),h(),b.isRunning=!0},b.resume=c[0].resume=function(){f(),b.countdownattr&&(b.countdown+=1),b.startTime=new Date-(b.stoppedTime-b.startTime),h(),b.isRunning=!0},b.stop=b.pause=c[0].stop=c[0].pause=function(){var a=b.timeoutId;b.clear(),b.$emit("timer-stopped",{timeoutId:a,millis:b.millis,seconds:b.seconds,minutes:b.minutes,hours:b.hours,days:b.days})},b.clear=c[0].clear=function(){b.stoppedTime=new Date,f(),b.timeoutId=null,b.isRunning=!1},c.bind("$destroy",function(){f(),b.isRunning=!1}),b.countdownattr?(b.millis=1e3*b.countdownattr,b.addCDSeconds=c[0].addCDSeconds=function(a){b.countdown+=a,b.$digest(),b.isRunning||b.start()},b.$on("timer-add-cd-seconds",function(a,c){e(function(){b.addCDSeconds(c)})}),b.$on("timer-set-countdown-seconds",function(a,c){b.isRunning||b.clear(),b.countdown=c,b.millis=1e3*c,g()})):b.millis=0,g();var h=function(){b.millis=new Date-b.startTime;var a=b.millis%1e3;return b.endTimeAttr&&(b.millis=b.endTime-new Date,a=b.interval-b.millis%1e3),b.countdownattr&&(b.millis=1e3*b.countdown),b.millis<0?(b.stop(),b.millis=0,g(),void(b.finishCallback&&b.$eval(b.finishCallback))):(g(),b.timeoutId=setTimeout(function(){h(),b.$digest()},b.interval-a),b.$emit("timer-tick",{timeoutId:b.timeoutId,millis:b.millis}),void(b.countdown>0?b.countdown--:b.countdown<=0&&(b.stop(),b.finishCallback&&b.$eval(b.finishCallback))))};(void 0===b.autoStart||b.autoStart===!0)&&b.start()}]}}]);"undefined"!=typeof module&&"undefined"!=typeof exports&&module.exports===exports&&(module.exports=timerModule); \ No newline at end of file