From b6f1277027e0ac8978c95eecafcd370d8fa4f021 Mon Sep 17 00:00:00 2001 From: Ravi Chandra Padmala Date: Sat, 24 Nov 2012 05:18:43 +0530 Subject: [PATCH] Stub frontend --- app/assets/javascripts/b4.js.coffee | 6 +++- app/assets/javascripts/collections/links.js.coffee | 4 +++ app/assets/javascripts/models/link.js.coffee | 1 + .../javascripts/routers/links_router.js.coffee | 10 ++++++ .../javascripts/views/links/links_index.js.coffee | 9 ++++++ app/assets/stylesheets/link.css.scss | 35 +++++++++++++++++++++ app/assets/templates/links/index.jst.eco | 11 +++++++ app/controllers/application_controller.rb | 1 + app/controllers/links_controller.rb | 21 ++++++++++--- app/views/application/app.html.erb | 36 ++++++++++++++-------- config/routes.rb | 2 +- 11 files changed, 116 insertions(+), 20 deletions(-) create mode 100644 app/assets/javascripts/collections/links.js.coffee create mode 100644 app/assets/javascripts/models/link.js.coffee create mode 100644 app/assets/javascripts/routers/links_router.js.coffee create mode 100644 app/assets/javascripts/views/links/links_index.js.coffee create mode 100644 app/assets/templates/links/index.jst.eco rewrite app/views/application/app.html.erb (81%) diff --git a/app/assets/javascripts/b4.js.coffee b/app/assets/javascripts/b4.js.coffee index fd9cfed..0aa8f3e 100644 --- a/app/assets/javascripts/b4.js.coffee +++ b/app/assets/javascripts/b4.js.coffee @@ -3,7 +3,11 @@ window.B4 = Collections: {} Views: {} Routers: {} - initialize: -> success() + initialize: -> + @links_router = new B4.Routers.Links + @links_view = new B4.Views.LinksIndex({model: links}) + @links_view.render() + Backbone.history.start $(document).ready -> B4.initialize() diff --git a/app/assets/javascripts/collections/links.js.coffee b/app/assets/javascripts/collections/links.js.coffee new file mode 100644 index 0000000..077af12 --- /dev/null +++ b/app/assets/javascripts/collections/links.js.coffee @@ -0,0 +1,4 @@ +class B4.Collections.Links extends Backbone.Collection + + model: B4.Models.Link + url: '/links' diff --git a/app/assets/javascripts/models/link.js.coffee b/app/assets/javascripts/models/link.js.coffee new file mode 100644 index 0000000..52f8be0 --- /dev/null +++ b/app/assets/javascripts/models/link.js.coffee @@ -0,0 +1 @@ +class B4.Models.Link extends Backbone.Model diff --git a/app/assets/javascripts/routers/links_router.js.coffee b/app/assets/javascripts/routers/links_router.js.coffee new file mode 100644 index 0000000..1938f73 --- /dev/null +++ b/app/assets/javascripts/routers/links_router.js.coffee @@ -0,0 +1,10 @@ +class B4.Routers.Links extends Backbone.Router + routes: { + "links": "index" + "tagged/:tag": "links" + } + + links: -> + B4.links.fetch() + tagged: (tag) -> + B4.Models.Links diff --git a/app/assets/javascripts/views/links/links_index.js.coffee b/app/assets/javascripts/views/links/links_index.js.coffee new file mode 100644 index 0000000..213dd69 --- /dev/null +++ b/app/assets/javascripts/views/links/links_index.js.coffee @@ -0,0 +1,9 @@ +class B4.Views.LinksIndex extends Backbone.View + el: $ '#links' + tagName: 'ul' + + render: -> + console.log(@template(links: @model.toJSON())) + $(@el).html @template(links: @model.toJSON()) + + template: JST['links/index'] diff --git a/app/assets/stylesheets/link.css.scss b/app/assets/stylesheets/link.css.scss index 78cbe44..af37455 100644 --- a/app/assets/stylesheets/link.css.scss +++ b/app/assets/stylesheets/link.css.scss @@ -1,3 +1,38 @@ // Place all the styles related to the Link controller here. // They will automatically be included in application.css. // You can use Sass (SCSS) here: http://sass-lang.com/ + +$darkgrey: #333333; +$yellow: #FFCC00; +$green: #669966; +$fuschia: #993366; + +body { + font-family: "Helvetica Neue",Helvetica,Arial,sans-serif; + font-size: 12px; + font-weight: 400; +} + +#new_link_div { + position: fixed; + top: 0px; + right: 100px; +} + +#new_link_div label { + position: relative; + left: 10px; + width: 80px; +} + +#new_link_div input[type="text"] { + position: relative; + left: 50px; + border-width: 0px; + border-bottom: 2px solid $darkgrey; +} + +#new_link_div input[type="submit"] { + border-width: 0px; + background-color: $green; +} diff --git a/app/assets/templates/links/index.jst.eco b/app/assets/templates/links/index.jst.eco new file mode 100644 index 0000000..7e3abf9 --- /dev/null +++ b/app/assets/templates/links/index.jst.eco @@ -0,0 +1,11 @@ + diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 409de5c..3602d76 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -4,5 +4,6 @@ class ApplicationController < ActionController::Base def app @link = Link.new + @links = User.find(current_user).links end end diff --git a/app/controllers/links_controller.rb b/app/controllers/links_controller.rb index 4a27a16..6bd461f 100644 --- a/app/controllers/links_controller.rb +++ b/app/controllers/links_controller.rb @@ -1,12 +1,23 @@ class LinksController < ApplicationController before_filter :authenticate_user! + def show + link = User.find(current_user).links.find(params[:id]) + render :json => link + end + def index - unless params[:tag].blank? - links = User.find(current_user).links.tagged_with(params[:tag]) - else - links = User.find(current_user).links - end + links = User.find(current_user).links + render :json => links + end + + def tagged + links = User.find(current_user).links.tagged_with(params[:tag]) + render :json => links + end + + def destroy + links = User.find(current_user).links.find(params[:id]).delete render :json => links end diff --git a/app/views/application/app.html.erb b/app/views/application/app.html.erb dissimilarity index 81% index 9ab2f7a..8dc7e25 100644 --- a/app/views/application/app.html.erb +++ b/app/views/application/app.html.erb @@ -1,13 +1,23 @@ -<%= form_for @link do |f| %> - <%= f.label :title %>: - <%= f.text_field :title %>
- - <%= f.label :url %>: - <%= f.text_field :url %>
- - <%= f.label :tags %>: - <%= f.text_field :tags %>
- - <%= f.submit %> -<% end %> -<%= render :template => 'layouts/application' %> + + + + + +<%= render :template => 'layouts/application' %> diff --git a/config/routes.rb b/config/routes.rb index e2298a0..b9caba6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -51,7 +51,7 @@ B4::Application.routes.draw do # You can have the root of your site routed with "root" # just remember to delete public/index.html. root :to => 'application#app' - match 'links/:tag' => 'links#index' + match 'links/tagged/:tag' => 'links#tagged' resources :links #match 'links/(:tag)' => 'link#show' #match 'add' => 'link#add' -- 2.11.4.GIT