diff --git a/app/assets/javascripts/admin/enterprises/services/enterprise.js.coffee b/app/assets/javascripts/admin/enterprises/services/enterprise.js.coffee index b6e6a6147e..26061ef720 100644 --- a/app/assets/javascripts/admin/enterprises/services/enterprise.js.coffee +++ b/app/assets/javascripts/admin/enterprises/services/enterprise.js.coffee @@ -1,4 +1,5 @@ angular.module("admin.enterprises") + # Populate Enterprise.enterprise with enterprise json array from the page. .factory 'Enterprise', (enterprise) -> new class Enterprise - enterprise: enterprise \ No newline at end of file + enterprise: enterprise diff --git a/app/assets/javascripts/darkswarm/filters/capitalize.js.coffee b/app/assets/javascripts/darkswarm/filters/capitalize.js.coffee index acbd3fd637..5c2272135b 100644 --- a/app/assets/javascripts/darkswarm/filters/capitalize.js.coffee +++ b/app/assets/javascripts/darkswarm/filters/capitalize.js.coffee @@ -1,4 +1,5 @@ Darkswarm.filter "capitalize", -> + # Convert to basic sentence case. (input, scope) -> - input = input.toLowerCase() if input? + input = input.toLowerCase() if input? input.substring(0, 1).toUpperCase() + input.substring(1) diff --git a/app/assets/javascripts/darkswarm/filters/localize_currency.js.coffee b/app/assets/javascripts/darkswarm/filters/localize_currency.js.coffee index ffa98c5a33..7087e09fc3 100644 --- a/app/assets/javascripts/darkswarm/filters/localize_currency.js.coffee +++ b/app/assets/javascripts/darkswarm/filters/localize_currency.js.coffee @@ -1,15 +1,14 @@ -# Convert number to string currency using injected currency configuration. -# -# @requires currencyConfig json - /app/serializers/api/currency_config_serializer.rb -# @return: string Darkswarm.filter "localizeCurrency", (currencyConfig)-> + # Convert number to string currency using injected currency configuration. (amount) -> + # Set country code (eg. "US"). currency_code = if currencyConfig.display_currency then " " + currencyConfig.currency else "" + # Set decimal points, 2 or 0 if hide_cents. decimals = if currencyConfig.hide_cents == "true" then 0 else 2 - # We need to use parseFloat before toFixed as the amount should be a passed in as a string. + # We need to use parseFloat before toFixed as the amount should come in as a string. amount_fixed = parseFloat(amount).toFixed(decimals) - # Build the final price string. + # Build the final price string. TODO use spree decimal point and spacer character settings. if currencyConfig.symbol_position == 'before' currencyConfig.symbol + amount_fixed + currency_code else diff --git a/app/assets/javascripts/darkswarm/filters/search_enterprises.js.coffee b/app/assets/javascripts/darkswarm/filters/search_enterprises.js.coffee index 20d0fd91c9..2c42fe93d3 100644 --- a/app/assets/javascripts/darkswarm/filters/search_enterprises.js.coffee +++ b/app/assets/javascripts/darkswarm/filters/search_enterprises.js.coffee @@ -1,4 +1,5 @@ Darkswarm.filter 'searchEnterprises', (Matcher)-> + # Search multiple fields of enterprises for matching text fragment. (enterprises, text) -> enterprises ||= [] text ?= "" diff --git a/app/assets/javascripts/darkswarm/filters/show_profiles.js.coffee b/app/assets/javascripts/darkswarm/filters/show_hub_profiles.js.coffee similarity index 55% rename from app/assets/javascripts/darkswarm/filters/show_profiles.js.coffee rename to app/assets/javascripts/darkswarm/filters/show_hub_profiles.js.coffee index b76dc8373e..b97a0c35e4 100644 --- a/app/assets/javascripts/darkswarm/filters/show_profiles.js.coffee +++ b/app/assets/javascripts/darkswarm/filters/show_hub_profiles.js.coffee @@ -1,7 +1,8 @@ -Darkswarm.filter 'showProfiles', ()-> +Darkswarm.filter 'showHubProfiles', ()-> + # Filter hub_profile enterprises in or out. (enterprises, show_profiles) -> enterprises ||= [] - show_profiles ?= true + show_profiles ?= false enterprises.filter (enterprise)=> show_profiles or enterprise.is_distributor diff --git a/app/assets/javascripts/darkswarm/services/enterprise_modal.js.coffee b/app/assets/javascripts/darkswarm/services/enterprise_modal.js.coffee index 1cd0727cd8..a0fb3ce5c5 100644 --- a/app/assets/javascripts/darkswarm/services/enterprise_modal.js.coffee +++ b/app/assets/javascripts/darkswarm/services/enterprise_modal.js.coffee @@ -1,4 +1,5 @@ Darkswarm.factory "EnterpriseModal", ($modal, $rootScope)-> + # Build a modal popup for an enterprise. new class EnterpriseModal open: (enterprise)-> scope = $rootScope.$new(true) # Spawn an isolate to contain the enterprise diff --git a/app/assets/javascripts/darkswarm/services/enterprises.js.coffee b/app/assets/javascripts/darkswarm/services/enterprises.js.coffee index 108be61879..e6a8c621dd 100644 --- a/app/assets/javascripts/darkswarm/services/enterprises.js.coffee +++ b/app/assets/javascripts/darkswarm/services/enterprises.js.coffee @@ -1,16 +1,20 @@ Darkswarm.factory 'Enterprises', (enterprises, CurrentHub, Taxons, Dereferencer, visibleFilter)-> new class Enterprises - enterprises_by_id: {} # id/object pairs for lookup + enterprises_by_id: {} constructor: -> + # Populate Enterprises.enterprises from json in page. @enterprises = enterprises + # Map enterprises to id/object pairs for lookup. for enterprise in enterprises @enterprises_by_id[enterprise.id] = enterprise + # Replace enterprise and taxons ids with actual objects. @dereferenceEnterprises() @dereferenceTaxons() - @visible = visibleFilter @enterprises - @producers = @visible.filter (enterprise)-> + # Remove non-visible enterprises. + @visible_enterprises = visibleFilter @enterprises + @producers = @visible_enterprises.filter (enterprise)-> enterprise.enterprise_category in ["producer_hub", "producer_shop", "producer"] - @hubs = @visible.filter (enterprise)-> + @hubs = @visible_enterprises.filter (enterprise)-> enterprise.enterprise_category in ["hub", "hub_profile", "producer_hub", "producer_shop"] dereferenceEnterprises: -> diff --git a/app/assets/javascripts/darkswarm/services/matcher.js.coffee b/app/assets/javascripts/darkswarm/services/matcher.js.coffee index aadd6a4128..9360afdd1f 100644 --- a/app/assets/javascripts/darkswarm/services/matcher.js.coffee +++ b/app/assets/javascripts/darkswarm/services/matcher.js.coffee @@ -1,6 +1,7 @@ Darkswarm.factory "Matcher", -> - new class Matcher - match: (properties, text)-> - properties.some (prop)-> - prop ||= "" - prop.toLowerCase().indexOf(text.toLowerCase()) != -1 + # Match text fragment in an array of strings. + new class Matcher + match: (properties, text)-> + properties.some (prop)-> + prop ||= "" + prop.toLowerCase().indexOf(text.toLowerCase()) != -1 diff --git a/app/assets/javascripts/darkswarm/services/taxons.js.coffee b/app/assets/javascripts/darkswarm/services/taxons.js.coffee index cbe6c118e0..72ccc4078a 100644 --- a/app/assets/javascripts/darkswarm/services/taxons.js.coffee +++ b/app/assets/javascripts/darkswarm/services/taxons.js.coffee @@ -1,8 +1,9 @@ Darkswarm.factory "Taxons", (taxons)-> new class Taxons - taxons: taxons + taxons: taxons taxons_by_id: {} constructor: -> + # Map taxons to id/object pairs for lookup. for taxon in @taxons @taxons_by_id[taxon.id] = taxon diff --git a/app/views/shared/components/_enterprise_no_results.html.haml b/app/views/shared/components/_enterprise_no_results.html.haml new file mode 100644 index 0000000000..2e6edd0875 --- /dev/null +++ b/app/views/shared/components/_enterprise_no_results.html.haml @@ -0,0 +1,5 @@ +%producer.row{"ng-show" => "filteredEnterprises.length == 0"} + %p.no-results + Sorry, no results found for + %strong {{query}}. + Try another search? diff --git a/app/views/shared/components/_enterprise_search.html.haml b/app/views/shared/components/_enterprise_search.html.haml new file mode 100644 index 0000000000..0ccb23220c --- /dev/null +++ b/app/views/shared/components/_enterprise_search.html.haml @@ -0,0 +1,7 @@ +#active-table-search.row + .small-12.columns + %input{type: :text, + "ng-model" => "query", + placeholder: "Search by name or suburb...", + "ng-debounce" => "150", + "ofn-disable-enter" => true}