From e7854bcd8eb2e330ab0cbbc27ef8c1a318f6c6e0 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Thu, 5 Mar 2015 16:38:21 +1100 Subject: [PATCH] Moving single line selectors to template, making sure other users of taxons-selector still work --- .../directives/single_line_selector.coffee | 3 +- .../directives/taxon_selector.js.coffee | 6 ++++ .../templates/single_line_selectors.html.haml | 14 ++++++++ .../templates/taxon_selector.html.haml | 2 +- app/views/home/_filters.html.haml | 2 +- app/views/producers/_filters.html.haml | 5 ++- app/views/shop/products/_filters.html.haml | 35 +------------------ 7 files changed, 27 insertions(+), 40 deletions(-) create mode 100644 app/assets/javascripts/templates/single_line_selectors.html.haml diff --git a/app/assets/javascripts/darkswarm/directives/single_line_selector.coffee b/app/assets/javascripts/darkswarm/directives/single_line_selector.coffee index b4e94d8b9e..de5abd5ab8 100644 --- a/app/assets/javascripts/darkswarm/directives/single_line_selector.coffee +++ b/app/assets/javascripts/darkswarm/directives/single_line_selector.coffee @@ -1,5 +1,6 @@ -Darkswarm.directive 'singleLineSelector', ($timeout, $filter) -> +Darkswarm.directive 'singleLineSelectors', ($timeout, $filter) -> restrict: 'E' + templateUrl: "single_line_selectors.html" link: (scope,element,attrs) -> scope.fitting = false diff --git a/app/assets/javascripts/darkswarm/directives/taxon_selector.js.coffee b/app/assets/javascripts/darkswarm/directives/taxon_selector.js.coffee index 5fb67c8405..069964092a 100644 --- a/app/assets/javascripts/darkswarm/directives/taxon_selector.js.coffee +++ b/app/assets/javascripts/darkswarm/directives/taxon_selector.js.coffee @@ -45,3 +45,9 @@ Darkswarm.directive "taxonSelector", (FilterSelectorsService)-> taxon: taxon selectors.push selector selectors + + scope.ifDefined = (value, if_undefined) -> + if angular.isDefined(value) + value + else + if_undefined diff --git a/app/assets/javascripts/templates/single_line_selectors.html.haml b/app/assets/javascripts/templates/single_line_selectors.html.haml new file mode 100644 index 0000000000..da48fd97e1 --- /dev/null +++ b/app/assets/javascripts/templates/single_line_selectors.html.haml @@ -0,0 +1,14 @@ +%ul + %taxon-selector{objects: "Products.products | products:query | products:showProfiles", + "active-taxons" => "activeTaxons", "taxon-selectors" => "taxonSelectors" } + + %li.more{ ng: { show: "overFlowSelectors().length > 0 || fitting", class: "{active: selectedOverFlowSelectors().length > 0}" } } + %a.dropdown{ dropdown: { toggle: "#more-taxons" } } + %span + + {{ overFlowSelectors().length }} more + %i.ofn-i_052-point-down + .f-dropdown.content#more-taxons + %ul + %active-selector{ ng: { repeat: "selector in overFlowSelectors()", hide: "selector.fits" } } + %render-svg{path: "{{selector.taxon.icon}}"} + %span {{ selector.taxon.name }} diff --git a/app/assets/javascripts/templates/taxon_selector.html.haml b/app/assets/javascripts/templates/taxon_selector.html.haml index 513225d6f4..7bd178c2ab 100644 --- a/app/assets/javascripts/templates/taxon_selector.html.haml +++ b/app/assets/javascripts/templates/taxon_selector.html.haml @@ -1,3 +1,3 @@ -%active-selector{"ng-repeat" => "selector in taxonSelectors", "ng-show" => "selector.fits"} +%active-selector{ ng: { repeat: "selector in selectors()", show: "ifDefined(selector.fits, true)" } } %render-svg{path: "{{selector.taxon.icon}}"} %span {{ selector.taxon.name }} diff --git a/app/views/home/_filters.html.haml b/app/views/home/_filters.html.haml index 52fceb6688..09d5e46df4 100644 --- a/app/views/home/_filters.html.haml +++ b/app/views/home/_filters.html.haml @@ -11,7 +11,7 @@ Type %ul.small-block-grid-2.medium-block-grid-4.large-block-grid-5 %taxon-selector{objects: "Enterprises.hubs | searchEnterprises:query", - results: "activeTaxons"} + "active-taxons" => "activeTaxons"} .small-12.large-3.columns %h5.tdhead .light Filter by diff --git a/app/views/producers/_filters.html.haml b/app/views/producers/_filters.html.haml index e1cd0ccba9..0f863a7a2f 100644 --- a/app/views/producers/_filters.html.haml +++ b/app/views/producers/_filters.html.haml @@ -11,7 +11,6 @@ .light Filter by Type %ul.small-block-grid-2.medium-block-grid-4.large-block-grid-6 - %taxon-selector{objects: "Enterprises.producers | searchEnterprises:query ", - results: "activeTaxons"} + %taxon-selector{objects: "Enterprises.producers | searchEnterprises:query ", + "active-taxons" => "activeTaxons"} = render partial: 'shared/components/filter_box' - diff --git a/app/views/shop/products/_filters.html.haml b/app/views/shop/products/_filters.html.haml index 59bda1baf4..8581ea1607 100644 --- a/app/views/shop/products/_filters.html.haml +++ b/app/views/shop/products/_filters.html.haml @@ -1,38 +1,5 @@ .filter-box.filter-box-shopfront.animate-hide.text-right - %single-line-selector - %ul - %taxon-selector{objects: "Products.products | products:query | products:showProfiles", - "active-taxons" => "activeTaxons", "taxon-selectors" => "taxonSelectors" } - - %li.more{ ng: { show: "overFlowSelectors().length > 0 || fitting", class: "{active: selectedOverFlowSelectors().length > 0}" } } - %a.dropdown{ dropdown: { toggle: "#more-taxons" } } - %span - + {{ overFlowSelectors().length }} more - %i.ofn-i_052-point-down - .f-dropdown.content#more-taxons - %ul - %active-selector{ ng: { repeat: "selector in overFlowSelectors()", hide: "selector.fits" } } - %render-svg{path: "{{selector.taxon.icon}}"} - %span {{ selector.taxon.name }} - - / TODO: Needs controller for Angular Bootstrap directive for dropdown: - / {"ng-controller" => "DropdownCtrl"} - - / %li - / .btn-group{:dropdown => "", "is-open" => "status.isopen"} - / %button.btn.btn-primary.dropdown-toggle{"dropdown-toggle" => "", "ng-disabled" => "disabled", :type => "button"} - / + 7 more - / %span.caret - / %ul.dropdown-menu{:role => "menu"} - / %li - / %a{:href => "#"} Action - / %li - / %a{:href => "#"} Another action - / %li - / %a{:href => "#"} Something else here - / %li.divider - / %li - / %a{:href => "#"} Separated link + %single-line-selectors -# .filter-box.property-box-shopfront.animate-hide.text-right -# %ul