From 775eca0026fb1ee6e06b4d1e0f876f46f61d46e8 Mon Sep 17 00:00:00 2001 From: Dennis Collinson Date: Thu, 22 Mar 2012 16:58:07 -0700 Subject: [PATCH] MS DC You can has choose a template --- app/models/status_message.rb | 2 +- app/presenters/post_presenter.rb | 2 +- .../20120322223517_add_template_name_to_posts.rb | 5 +++++ db/schema.rb | 3 ++- public/javascripts/app/pages/framer.js | 2 +- public/javascripts/app/pages/post-viewer.js | 8 +++++--- public/javascripts/app/views/template_picker_view.js | 6 +++--- spec/controllers/status_messages_controller_spec.rb | 2 +- .../app/views/template_picker_view_spec.js | 12 ++++++------ 9 files changed, 25 insertions(+), 17 deletions(-) create mode 100644 db/migrate/20120322223517_add_template_name_to_posts.rb diff --git a/app/models/status_message.rb b/app/models/status_message.rb index 289150a87..aad453ac1 100644 --- a/app/models/status_message.rb +++ b/app/models/status_message.rb @@ -21,7 +21,7 @@ class StatusMessage < Post # therefore, we put the validation in a before_destory callback instead of a validation before_destroy :presence_of_content - attr_accessible :text, :provider_display_name + attr_accessible :text, :provider_display_name, :frame_name attr_accessor :oembed_url after_create :create_mentions diff --git a/app/presenters/post_presenter.rb b/app/presenters/post_presenter.rb index f8e1febf5..0f7984947 100644 --- a/app/presenters/post_presenter.rb +++ b/app/presenters/post_presenter.rb @@ -23,7 +23,7 @@ class PostPresenter :reshares => self.reshares, :comments => self.comments, :participations => self.participations, - :templateName => template_name, + :frame_name => self.post.frame_name || template_name, :title => title }) end diff --git a/db/migrate/20120322223517_add_template_name_to_posts.rb b/db/migrate/20120322223517_add_template_name_to_posts.rb new file mode 100644 index 000000000..cedd5951c --- /dev/null +++ b/db/migrate/20120322223517_add_template_name_to_posts.rb @@ -0,0 +1,5 @@ +class AddTemplateNameToPosts < ActiveRecord::Migration + def change # thanks josh susser + add_column :posts, :frame_name, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index f662bf314..1f2bfd100 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20120301143226) do +ActiveRecord::Schema.define(:version => 20120322223517) do create_table "account_deletions", :force => true do |t| t.string "diaspora_handle" @@ -334,6 +334,7 @@ ActiveRecord::Schema.define(:version => 20120301143226) do t.integer "o_embed_cache_id" t.integer "reshares_count", :default => 0 t.datetime "interacted_at" + t.string "frame_name" end add_index "posts", ["author_id", "root_guid"], :name => "index_posts_on_author_id_and_root_guid", :unique => true diff --git a/public/javascripts/app/pages/framer.js b/public/javascripts/app/pages/framer.js index 7492fb963..1aee8f318 100644 --- a/public/javascripts/app/pages/framer.js +++ b/public/javascripts/app/pages/framer.js @@ -22,7 +22,7 @@ app.pages.Framer = app.views.Base.extend({ postView : function(){ //we might be leaky like cray cray with this - var templateType = this.model.get("templateName") + var templateType = this.model.get("frame_name") this._postView = new app.views.Post({ model : this.model, diff --git a/public/javascripts/app/pages/post-viewer.js b/public/javascripts/app/pages/post-viewer.js index f43bf957f..afea0ae7d 100644 --- a/public/javascripts/app/pages/post-viewer.js +++ b/public/javascripts/app/pages/post-viewer.js @@ -25,11 +25,13 @@ app.pages.PostViewer = app.views.Base.extend({ this.authorView = new app.views.PostViewerAuthor({ model : this.model }); this.interactionsView = new app.views.PostViewerInteractions({ model : this.model }); this.navView = new app.views.PostViewerNav({ model : this.model }); + + var frameName = this.model.get("frame_name") this.postView = new app.views.Post({ model : this.model, - className : this.model.get("templateName") + " post loaded", - templateName : "post-viewer/content/" + this.model.get("templateName"), - attributes : {"data-template" : this.model.get("templateName")} + className : frameName + " post loaded", + templateName : "post-viewer/content/" + frameName, + attributes : {"data-template" : frameName} }); this.render(); diff --git a/public/javascripts/app/views/template_picker_view.js b/public/javascripts/app/views/template_picker_view.js index 5d55a87f4..bada25338 100644 --- a/public/javascripts/app/views/template_picker_view.js +++ b/public/javascripts/app/views/template_picker_view.js @@ -2,7 +2,7 @@ app.views.TemplatePicker = app.views.Base.extend({ templateName : "template-picker", initialize : function(){ - this.model.set({templateName : 'status'}) + this.model.set({frame_name : 'status'}) }, events : { @@ -10,11 +10,11 @@ app.views.TemplatePicker = app.views.Base.extend({ }, postRenderTemplate : function(){ - this.$("select[name=template]").val(this.model.get("templateName")) + this.$("select[name=template]").val(this.model.get("frame_name")) }, setModelTemplate : function(evt){ - this.model.set({"templateName": this.$("select[name=template]").val()}) + this.model.set({"frame_name": this.$("select[name=template]").val()}) }, presenter : function() { diff --git a/spec/controllers/status_messages_controller_spec.rb b/spec/controllers/status_messages_controller_spec.rb index b6dbd587d..fa823b3fd 100644 --- a/spec/controllers/status_messages_controller_spec.rb +++ b/spec/controllers/status_messages_controller_spec.rb @@ -75,7 +75,7 @@ describe StatusMessagesController do { :status_message => { :public => "true", :text => "facebook, is that you?", - }, + }, :aspect_ids => [@aspect1.id.to_s] } } diff --git a/spec/javascripts/app/views/template_picker_view_spec.js b/spec/javascripts/app/views/template_picker_view_spec.js index b9979668e..7b1e8ef19 100644 --- a/spec/javascripts/app/views/template_picker_view_spec.js +++ b/spec/javascripts/app/views/template_picker_view_spec.js @@ -1,12 +1,12 @@ describe("app.views.TemplatePicker", function(){ beforeEach(function(){ - this.model = factory.statusMessage({templateName: undefined}) + this.model = factory.statusMessage({frame_name: undefined}) this.view = new app.views.TemplatePicker({model : this.model }) }) describe("initialization", function(){ - it("sets the post_type of the model to 'status' by default", function(){ - expect(this.view.model.get("templateName")).toBe("status") + it("sets the frame_name of the model to 'status' by default", function(){ + expect(this.view.model.get("frame_name")).toBe("status") }) }) @@ -15,14 +15,14 @@ describe("app.views.TemplatePicker", function(){ this.view.render() }) - it("selects the model's templateName from the dropdown", function(){ + it("selects the model's frame_name from the dropdown", function(){ expect(this.view.$("select[name=template]").val()).toBe("status") }) - it("changes the templateName on the model when is is selected", function(){ + it("changes the frame_name on the model when is is selected", function(){ this.view.$("select[name=template]").val("note") this.view.$("select[name=template]").trigger("change") - expect(this.model.get("templateName")).toBe('note') + expect(this.model.get("frame_name")).toBe('note') }) }) }) \ No newline at end of file