diff options
| author | mo <mo.khan@gmail.com> | 2017-09-24 13:53:09 -0600 |
|---|---|---|
| committer | mo <mo.khan@gmail.com> | 2017-09-24 13:53:09 -0600 |
| commit | 4887ba54da7ff8a25347b58c4a426cb5cf1dee3b (patch) | |
| tree | 5327f65dafd3f8a4881053d5da0d601f4c2e918a | |
| parent | dc702a89811e866eec20cc43763096dddf4a41fe (diff) | |
render categories as backbone collection in html page.
| -rw-r--r-- | app/assets/javascripts/cakeside.js.coffee | 4 | ||||
| -rw-r--r-- | app/assets/javascripts/initializers/auto_view_setup.js.coffee | 4 | ||||
| -rw-r--r-- | app/assets/javascripts/views/my/cakes/edit_view.js.coffee | 2 | ||||
| -rw-r--r-- | app/assets/javascripts/views/my/cakes/new_view.js.coffee | 2 | ||||
| -rw-r--r-- | app/controllers/application_controller.rb | 10 | ||||
| -rw-r--r-- | app/controllers/sessions_controller.rb | 2 | ||||
| -rw-r--r-- | app/views/cakes/_show.html.erb | 2 | ||||
| -rw-r--r-- | app/views/cakes/index.html.erb | 2 | ||||
| -rw-r--r-- | app/views/layouts/_header.html.erb | 2 | ||||
| -rw-r--r-- | app/views/my/kitchens/show.html.erb | 3 | ||||
| -rw-r--r-- | spec/support/authentication.rb | 2 |
11 files changed, 18 insertions, 17 deletions
diff --git a/app/assets/javascripts/cakeside.js.coffee b/app/assets/javascripts/cakeside.js.coffee index 57afc2f7..b179d909 100644 --- a/app/assets/javascripts/cakeside.js.coffee +++ b/app/assets/javascripts/cakeside.js.coffee @@ -38,13 +38,10 @@ window.csx = Backbone.history.start() @cakes = new csx.Collections.CakesCollection() - @categories = new csx.Collections.CategoriesCollection() @tutorials = new csx.Collections.TutorialsCollection() csx.Application.reqres.setHandler 'CakesRepository', => @cakes - csx.Application.reqres.setHandler 'CategoriesRepository', => - @categories @photos_cache = {} csx.Application.reqres.setHandler 'PhotosRepository', (cake_id) => if @photos_cache[cake_id] @@ -59,7 +56,6 @@ window.csx = csx.Application.reqres.setHandler 'ProfilesRepository', => @profiles ||= new csx.Collections.ProfilesCollection() - @categories.fetch(reset: true) @tutorials.fetch(reset: true) @cakes.fetch(reset: true).done -> csx.Application.start() diff --git a/app/assets/javascripts/initializers/auto_view_setup.js.coffee b/app/assets/javascripts/initializers/auto_view_setup.js.coffee index 4b72ba67..a3a48586 100644 --- a/app/assets/javascripts/initializers/auto_view_setup.js.coffee +++ b/app/assets/javascripts/initializers/auto_view_setup.js.coffee @@ -7,9 +7,11 @@ class csx.AutoViewSetup extends csx.Behaviour execute: -> for element in $('[data-autoview]') $element = $(element) - @install($element) unless $element.data('autoview-setup-complete') + @install($element) install: (element) -> + return if element.data('autoview-setup-complete') + viewName = element.data('autoview') if viewName.indexOf("-") > 0 csx.AutoView.install(element) diff --git a/app/assets/javascripts/views/my/cakes/edit_view.js.coffee b/app/assets/javascripts/views/my/cakes/edit_view.js.coffee index e4e3192c..64c4da4c 100644 --- a/app/assets/javascripts/views/my/cakes/edit_view.js.coffee +++ b/app/assets/javascripts/views/my/cakes/edit_view.js.coffee @@ -68,7 +68,7 @@ class csx.Views.My.Cakes.EditView extends Marionette.CompositeView serializeData: -> { cake: @model.toJSON(), - categories: csx.Application.request('CategoriesRepository').toJSON(), + categories: csx.Categories.toJSON(), } launchAddPhoto: -> diff --git a/app/assets/javascripts/views/my/cakes/new_view.js.coffee b/app/assets/javascripts/views/my/cakes/new_view.js.coffee index 4cfd8815..116d90df 100644 --- a/app/assets/javascripts/views/my/cakes/new_view.js.coffee +++ b/app/assets/javascripts/views/my/cakes/new_view.js.coffee @@ -57,5 +57,5 @@ class csx.Views.My.Cakes.NewView extends Marionette.ItemView serializeData: -> { cake: @model.toJSON(), - categories: csx.Application.request('CategoriesRepository').toJSON(), + categories: csx.Categories.toJSON(), } diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index bcb68012..951a53c3 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -4,8 +4,8 @@ class ApplicationController < ActionController::Base # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception before_action :load_header - #before_action :extend_session_cookie - helper_method :current_user, :user_signed_in? + before_action :extend_session_cookie + helper_method :current_user, :current_user? rescue_from ActiveRecord::RecordNotFound, with: :record_not_found def user_session(session_key = session[:raphael]) @@ -16,8 +16,8 @@ class ApplicationController < ActionController::Base user_session.try(:user) end - def user_signed_in? - current_user + def current_user? + current_user.present? end private @@ -31,7 +31,7 @@ class ApplicationController < ActionController::Base end def extend_session_cookie - session[:raphael] = user_session.access(request) if user_signed_in? + session[:raphael] = user_session.access(request) if current_user? end def record_not_found diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 564569b4..ca139465 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -1,6 +1,6 @@ class SessionsController < ApplicationController def new - redirect_to my_dashboard_path if user_signed_in? + redirect_to my_dashboard_path if current_user? @session = UserSession.new end diff --git a/app/views/cakes/_show.html.erb b/app/views/cakes/_show.html.erb index c0555eab..9c2bb197 100644 --- a/app/views/cakes/_show.html.erb +++ b/app/views/cakes/_show.html.erb @@ -2,7 +2,7 @@ <div class="col"> <h1><%= link_to @creation.name, cake_path(@creation) %></h1> <p>By <%= link_to @creation.user.name, profile_path(@creation.user) %></p> - <% if user_signed_in? && current_user != @creation.user %> + <% if current_user? && current_user != @creation.user %> <% if current_user.already_likes(@creation) %> <i class="fa fa-star fa-4x float-right"></i> <% else %> diff --git a/app/views/cakes/index.html.erb b/app/views/cakes/index.html.erb index c8a0a13a..d492a4d1 100644 --- a/app/views/cakes/index.html.erb +++ b/app/views/cakes/index.html.erb @@ -2,7 +2,7 @@ <% provide(:search_path, cakes_path) %> <% provide(:container_class, 'container') %> -<% unless user_signed_in? %> +<% unless current_user? %> <div class="row jumbotron"> <div class="col text-center"> <%= image_tag "cakeside-logo.png", alt: "CakeSide", class: "img-fluid" %> diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index 9fd798a0..8d150b1a 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -15,7 +15,7 @@ <li class="nav-item <%= "active" if params["controller"] == "tutorials" %>"> <%= link_to "Tutorials", tutorials_path(q: params[:q]), class: 'nav-link' %> </li> - <% if user_signed_in? %> + <% if current_user? %> <li class="nav-item dropdown"> <%= link_to my_dashboard_path, id: 'navbarDropdownMenuLink', class: 'nav-link dropdown-toggle', data: { toggle: 'dropdown' }, 'aria-haspopup'=>"true", 'aria-expanded'=>"false" do %> <%= current_user.name %> diff --git a/app/views/my/kitchens/show.html.erb b/app/views/my/kitchens/show.html.erb index f241562f..195a8d94 100644 --- a/app/views/my/kitchens/show.html.erb +++ b/app/views/my/kitchens/show.html.erb @@ -1,6 +1,9 @@ <% provide(:title, "Kitchen") -%> <%= content_for :javascript do -%> <%= javascript_tag do %> + csx.Categories = new Backbone.Collection(<%= raw @categories.to_json %>); + + <%# backbone_collection_for @categories %> var ALL_TAGS = <%= raw @tags.pluck(:name) %>; csx.initialize({ access_token: '<%= current_user.authentication_token %>' }); <% end %> diff --git a/spec/support/authentication.rb b/spec/support/authentication.rb index 1145db3c..47a601ce 100644 --- a/spec/support/authentication.rb +++ b/spec/support/authentication.rb @@ -3,7 +3,7 @@ module Authentication new_session = UserSession.new allow(controller).to receive(:user_session).and_return(new_session) allow(controller).to receive(:current_user).and_return(user) - allow(controller).to receive(:user_signed_in?).and_return(true) + allow(controller).to receive(:current_user?).and_return(true) end def api_login(user) |
