add some angular documentation

This commit is contained in:
Rafael Schouten
2014-10-06 22:59:06 +11:00
parent 2ae325455a
commit 881e82e825
11 changed files with 42 additions and 20 deletions

View File

@@ -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
enterprise: enterprise

View File

@@ -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)

View File

@@ -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

View File

@@ -1,4 +1,5 @@
Darkswarm.filter 'searchEnterprises', (Matcher)->
# Search multiple fields of enterprises for matching text fragment.
(enterprises, text) ->
enterprises ||= []
text ?= ""

View File

@@ -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

View File

@@ -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

View File

@@ -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: ->

View File

@@ -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

View File

@@ -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

View File

@@ -0,0 +1,5 @@
%producer.row{"ng-show" => "filteredEnterprises.length == 0"}
%p.no-results
Sorry, no results found for
%strong {{query}}.
Try another search?

View File

@@ -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}