From 6753b96f29a99f50ec6c2ddf4d6b0a5bdbc992e3 Mon Sep 17 00:00:00 2001 From: Will Marshall Date: Fri, 18 Apr 2014 13:01:36 +1000 Subject: [PATCH] Adding darkswarm variant of home page, getting Angular skeleton into place, taking shit off window --- .../javascripts/darkswarm/all.js.coffee | 2 ++ .../account_sidebar_controller.js.coffee | 2 +- ...uthentication_actions_controller.js.coffee | 2 +- .../forgot_sidebar_controller.js.coffee | 2 +- .../controllers/hubs_controller.js.coffee | 4 +++ .../login_sidebar_controller.js.coffee | 2 +- .../controllers/sidebar_controller.js.coffee | 2 +- .../signup_sidebar_controller.js.coffee | 2 +- .../javascripts/darkswarm/darkswarm.js.coffee | 2 +- .../directives/disable_enter.js.coffee | 9 +++++ .../darkswarm/services/hubs.js.coffee | 4 +++ app/controllers/darkswarm_controller.rb | 5 +-- app/views/darkswarm/index.html.haml | 35 ++++++++++++++++++- app/views/layouts/landing_page.html.haml | 3 ++ app/views/shared/_hubs.rabl | 30 ++++++++++++++++ app/views/shop/shop/_products.html.haml | 2 -- config/routes.rb | 2 +- .../assets/javascripts/angular-backstretch.js | 10 ++++++ 18 files changed, 107 insertions(+), 13 deletions(-) create mode 100644 app/assets/javascripts/darkswarm/controllers/hubs_controller.js.coffee create mode 100644 app/assets/javascripts/darkswarm/directives/disable_enter.js.coffee create mode 100644 app/assets/javascripts/darkswarm/services/hubs.js.coffee create mode 100644 app/views/shared/_hubs.rabl create mode 100644 vendor/assets/javascripts/angular-backstretch.js diff --git a/app/assets/javascripts/darkswarm/all.js.coffee b/app/assets/javascripts/darkswarm/all.js.coffee index 65fa9107a9..6783a6f9e2 100644 --- a/app/assets/javascripts/darkswarm/all.js.coffee +++ b/app/assets/javascripts/darkswarm/all.js.coffee @@ -10,6 +10,8 @@ #= require ../shared/bindonce.min.js #= require ../shared/ng-infinite-scroll.min.js #= require ../shared/angular-local-storage.js +#= require ../search/jquery.backstretch.js +#= require angular-backstretch.js #= require angular-flash.min.js # #= require ../shared/jquery.timeago diff --git a/app/assets/javascripts/darkswarm/controllers/account_sidebar_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/account_sidebar_controller.js.coffee index 2ce5419400..4a31ce5697 100644 --- a/app/assets/javascripts/darkswarm/controllers/account_sidebar_controller.js.coffee +++ b/app/assets/javascripts/darkswarm/controllers/account_sidebar_controller.js.coffee @@ -1,4 +1,4 @@ -window.AccountSidebarCtrl = Darkswarm.controller "AccountSidebarCtrl", ($scope, $http, $location, SpreeUser, Navigation) -> +Darkswarm.controller "AccountSidebarCtrl", ($scope, $http, $location, SpreeUser, Navigation) -> $scope.path = "/account" Navigation.paths.push $scope.path diff --git a/app/assets/javascripts/darkswarm/controllers/authentication_actions_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/authentication_actions_controller.js.coffee index 188867d7da..77c8b45d9d 100644 --- a/app/assets/javascripts/darkswarm/controllers/authentication_actions_controller.js.coffee +++ b/app/assets/javascripts/darkswarm/controllers/authentication_actions_controller.js.coffee @@ -1,4 +1,4 @@ -window.AuthenticationActionsCtrl = Darkswarm.controller "AuthenticationActionsCtrl", ($scope, Navigation, storage) -> +Darkswarm.controller "AuthenticationActionsCtrl", ($scope, Navigation, storage) -> $scope.toggleLogin = -> Navigation.navigate "/login" diff --git a/app/assets/javascripts/darkswarm/controllers/forgot_sidebar_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/forgot_sidebar_controller.js.coffee index e3c272a3af..4300461a0d 100644 --- a/app/assets/javascripts/darkswarm/controllers/forgot_sidebar_controller.js.coffee +++ b/app/assets/javascripts/darkswarm/controllers/forgot_sidebar_controller.js.coffee @@ -1,4 +1,4 @@ -window.ForgotSidebarCtrl = Darkswarm.controller "ForgotSidebarCtrl", ($scope, $http, $location, SpreeUser, Navigation) -> +Darkswarm.controller "ForgotSidebarCtrl", ($scope, $http, $location, SpreeUser, Navigation) -> $scope.spree_user = SpreeUser.spree_user $scope.path = "/forgot" $scope.sent = false diff --git a/app/assets/javascripts/darkswarm/controllers/hubs_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/hubs_controller.js.coffee new file mode 100644 index 0000000000..8d2ea7df50 --- /dev/null +++ b/app/assets/javascripts/darkswarm/controllers/hubs_controller.js.coffee @@ -0,0 +1,4 @@ +Darkswarm.controller "HubsCtrl", ($scope, Hubs) -> + console.log Hubs.hubs[0] + $scope.Hubs = Hubs + $scope.hubs = Hubs.hubs diff --git a/app/assets/javascripts/darkswarm/controllers/login_sidebar_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/login_sidebar_controller.js.coffee index 54b10b0b4a..63d31a8f3c 100644 --- a/app/assets/javascripts/darkswarm/controllers/login_sidebar_controller.js.coffee +++ b/app/assets/javascripts/darkswarm/controllers/login_sidebar_controller.js.coffee @@ -1,4 +1,4 @@ -window.LoginSidebarCtrl = Darkswarm.controller "LoginSidebarCtrl", ($scope, $http, $location, SpreeUser, Navigation) -> +Darkswarm.controller "LoginSidebarCtrl", ($scope, $http, $location, SpreeUser, Navigation) -> $scope.spree_user = SpreeUser.spree_user $scope.path = "/login" Navigation.paths.push $scope.path diff --git a/app/assets/javascripts/darkswarm/controllers/sidebar_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/sidebar_controller.js.coffee index 8544f57922..cd7ce8fe0b 100644 --- a/app/assets/javascripts/darkswarm/controllers/sidebar_controller.js.coffee +++ b/app/assets/javascripts/darkswarm/controllers/sidebar_controller.js.coffee @@ -1,4 +1,4 @@ -window.SidebarCtrl = Darkswarm.controller "SidebarCtrl", ($scope, $location) -> +Darkswarm.controller "SidebarCtrl", ($scope, $location) -> $scope.sidebarPaths = ["/login", "/signup", "/forgot", "/account"] $scope.active = -> diff --git a/app/assets/javascripts/darkswarm/controllers/signup_sidebar_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/signup_sidebar_controller.js.coffee index 14c924e275..ef6ded77fd 100644 --- a/app/assets/javascripts/darkswarm/controllers/signup_sidebar_controller.js.coffee +++ b/app/assets/javascripts/darkswarm/controllers/signup_sidebar_controller.js.coffee @@ -1,4 +1,4 @@ -window.SignupSidebarCtrl = Darkswarm.controller "SignupSidebarCtrl", ($scope, $http, $location, SpreeUser, Navigation) -> +Darkswarm.controller "SignupSidebarCtrl", ($scope, $http, $location, SpreeUser, Navigation) -> $scope.spree_user = SpreeUser.spree_user $scope.path = "/signup" Navigation.paths.push $scope.path diff --git a/app/assets/javascripts/darkswarm/darkswarm.js.coffee b/app/assets/javascripts/darkswarm/darkswarm.js.coffee index 71d99be03b..2bd874402c 100644 --- a/app/assets/javascripts/darkswarm/darkswarm.js.coffee +++ b/app/assets/javascripts/darkswarm/darkswarm.js.coffee @@ -1,4 +1,4 @@ -window.Darkswarm = angular.module("Darkswarm", ["ngResource", "filters", 'mm.foundation', 'angularLocalStorage', 'pasvaz.bindonce', 'infinite-scroll', 'angular-flash.service']).config ($httpProvider, $tooltipProvider) -> +window.Darkswarm = angular.module("Darkswarm", ["ngResource", "filters", 'mm.foundation', 'angularLocalStorage', 'pasvaz.bindonce', 'infinite-scroll', 'angular-flash.service', 'backstretch']).config ($httpProvider, $tooltipProvider) -> $httpProvider.defaults.headers.post['X-CSRF-Token'] = $('meta[name="csrf-token"]').attr('content') $httpProvider.defaults.headers.put['X-CSRF-Token'] = $('meta[name="csrf-token"]').attr('content') $httpProvider.defaults.headers['common']['X-Requested-With'] = 'XMLHttpRequest' diff --git a/app/assets/javascripts/darkswarm/directives/disable_enter.js.coffee b/app/assets/javascripts/darkswarm/directives/disable_enter.js.coffee new file mode 100644 index 0000000000..9385b390a1 --- /dev/null +++ b/app/assets/javascripts/darkswarm/directives/disable_enter.js.coffee @@ -0,0 +1,9 @@ +Darkswarm.directive "ofnDisableEnter", ()-> + restrict: 'A' + link: (scope, element, attrs)-> + element.bind "keydown keypress", (e)-> + code = e.keyCode || e.which + if code == 13 + e.preventDefault() + + diff --git a/app/assets/javascripts/darkswarm/services/hubs.js.coffee b/app/assets/javascripts/darkswarm/services/hubs.js.coffee new file mode 100644 index 0000000000..d70a2941df --- /dev/null +++ b/app/assets/javascripts/darkswarm/services/hubs.js.coffee @@ -0,0 +1,4 @@ +Darkswarm.factory 'Hubs', ($location, hubs) -> + new class Hubs + constructor: -> + @hubs = hubs diff --git a/app/controllers/darkswarm_controller.rb b/app/controllers/darkswarm_controller.rb index b1a7422e02..aee9a59996 100644 --- a/app/controllers/darkswarm_controller.rb +++ b/app/controllers/darkswarm_controller.rb @@ -1,5 +1,6 @@ -class DarkswarmController < ApplicationController - def index +class DarkswarmController < BaseController + layout 'darkswarm' + def index end end diff --git a/app/views/darkswarm/index.html.haml b/app/views/darkswarm/index.html.haml index 5938185c06..79b6641801 100644 --- a/app/views/darkswarm/index.html.haml +++ b/app/views/darkswarm/index.html.haml @@ -1 +1,34 @@ -TESTING +%div#image-url-container{backstretch: true, + "background-url" => "#{LandingPageImage.random.photo.url(:max_common_res)}" } + .row + .large-10.large-centered.columns + #postcode_select_box + .row + .large-12.columns + #logo-container= image_tag "ofn_logo.png" + .row + .large-12.large-centered.columns + = link_to about_us_path do + %strong + %i What is open food network? + + .row + .large-12.columns.text-center + %h2 Ready to shop? + %p Select a food hub from the list below: +#hubs{"ng-controller" => "HubsCtrl"} + + :javascript + angular.module('Darkswarm').value('hubs', #{render "shared/hubs"}) + + .row + .large-9.columns + %input{type: :text, "ng-model" => "query", value: "Search postcode, suburb or hub name...", + "ofn-disable-enter" => true} + .large-3.columns + Advanced search + .row + .large-12.columns + %ul + %li{"ng-repeat" => "hub in hubs | filter:query"} + %pre {{ hub | json }} diff --git a/app/views/layouts/landing_page.html.haml b/app/views/layouts/landing_page.html.haml index 893c112899..e03086a2b8 100644 --- a/app/views/layouts/landing_page.html.haml +++ b/app/views/layouts/landing_page.html.haml @@ -37,13 +37,16 @@ %li= link_to "Distributors", "#", :data => { "reveal-id" => "become-distributor" } %li.divider %li= link_to "Farmers", "#", :data => { "reveal-id" => "become-farmer" } + %section{ role: "main" } = yield + %section#sidebar{ role: "complementary" } .login-panel #login-content.hide = render "home/login" #sign-up-content.hide = render "home/signup" + = yield :scripts diff --git a/app/views/shared/_hubs.rabl b/app/views/shared/_hubs.rabl new file mode 100644 index 0000000000..832a9c5028 --- /dev/null +++ b/app/views/shared/_hubs.rabl @@ -0,0 +1,30 @@ +collection Enterprise.is_distributor +attributes :name, :id + +child :address do + attributes :city + node :state do |address| + address.state.abbr + end +end + +node :pickup do |hub| + not hub.shipping_methods.where(:require_ship_address => false).empty? +end + +node :delivery do |hub| + not hub.shipping_methods.where(:require_ship_address => true).empty? +end + +node :path do |hub| + shop_enterprise_path(hub) +end + +#child :shipping_methods do + #attributes :name, :require_ship_address +#end + +# ALL PRODUCERS +# +# Orders closing when? +# Current order_cycle + closing when? diff --git a/app/views/shop/shop/_products.html.haml b/app/views/shop/shop/_products.html.haml index 833b338cfa..25bd8d134e 100644 --- a/app/views/shop/shop/_products.html.haml +++ b/app/views/shop/shop/_products.html.haml @@ -6,8 +6,6 @@ %input#search.text{"ng-model" => "query", placeholder: "Search", "ng-keypress" => "searchKeypress($event)"} %input.button.right{type: :submit, value: "Add to Cart"} - {{ limit }} - %table %thead %th.name Item diff --git a/config/routes.rb b/config/routes.rb index 301315857b..4dce7339a6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,5 @@ Openfoodnetwork::Application.routes.draw do - root :to => 'home#temp_landing_page' + root :to => 'darkswarm#index' resource :shop, controller: "shop/shop" do get :products diff --git a/vendor/assets/javascripts/angular-backstretch.js b/vendor/assets/javascripts/angular-backstretch.js new file mode 100644 index 0000000000..80e14aa4fb --- /dev/null +++ b/vendor/assets/javascripts/angular-backstretch.js @@ -0,0 +1,10 @@ +angular.module('backstretch', []); +angular.module('backstretch') + .directive('backstretch', function () { + return { + restrict: 'A', + link: function (scope, element, attr) { + element.backstretch(attr.backgroundUrl); + } + } + });