users can now favorite posts
This commit is contained in:
parent
494ba1f9b8
commit
75d25e9475
13 changed files with 120 additions and 33 deletions
|
|
@ -10,6 +10,12 @@ app.pages.Profile = app.views.Base.extend({
|
|||
"#canvas" : "canvasView"
|
||||
},
|
||||
|
||||
events : {
|
||||
"click #edit-mode-toggle" : "toggleEdit"
|
||||
},
|
||||
|
||||
editMode : false,
|
||||
|
||||
initialize : function(options) {
|
||||
this.model = new app.models.Profile.findByGuid(options.personId)
|
||||
this.stream = options && options.stream || new app.models.Stream()
|
||||
|
|
@ -17,5 +23,12 @@ app.pages.Profile = app.views.Base.extend({
|
|||
this.model.bind("change", this.render, this) //this should go on profile info view when it gets Extracted
|
||||
|
||||
this.canvasView = new app.views.Canvas({model : this.stream})
|
||||
},
|
||||
|
||||
toggleEdit : function(evt) {
|
||||
if(evt) { evt.preventDefault() }
|
||||
this.editMode = !this.editMode
|
||||
this.$el.toggleClass("edit-mode")
|
||||
}
|
||||
|
||||
});
|
||||
|
|
@ -5,6 +5,7 @@ app.views.SmallFrame = app.views.Base.extend({
|
|||
templateName : "small-frame",
|
||||
|
||||
events : {
|
||||
"click .fav" : "favoritePost",
|
||||
"click .content" : "goToPost"
|
||||
},
|
||||
|
||||
|
|
@ -19,6 +20,9 @@ app.views.SmallFrame = app.views.Base.extend({
|
|||
},
|
||||
|
||||
dimensionsClass : function() {
|
||||
/* by default, make it big if it's a fav */
|
||||
if(this.model.get("favorite")) { return "x2 width height" }
|
||||
|
||||
var firstPhoto = this.model.get("photos")[0]
|
||||
, className = "photo ";
|
||||
|
||||
|
|
@ -48,35 +52,16 @@ app.views.SmallFrame = app.views.Base.extend({
|
|||
}
|
||||
},
|
||||
|
||||
// textClass : function(){
|
||||
// var textLength = this.model.get("text").length
|
||||
// , baseClass = "text ";
|
||||
//
|
||||
// if(textLength <= 20){
|
||||
// return baseClass + "extra-small"
|
||||
// } else if(textLength <= 140) {
|
||||
// return baseClass + "small"
|
||||
// } else if(textLength <= 500) {
|
||||
// return baseClass + "medium"
|
||||
// } else {
|
||||
// return baseClass + "large"
|
||||
// }
|
||||
// },
|
||||
//
|
||||
// photoClass : function(){
|
||||
// var photoCount = this.model.get('photos').length
|
||||
// , baseClass = "photo ";
|
||||
//
|
||||
// if(photoCount == 0 ) {
|
||||
// return ""
|
||||
// } else if(photoCount == 1){
|
||||
// return baseClass + 'one'
|
||||
// } else if(photoCount == 2 ) {
|
||||
// return baseClass + 'two'
|
||||
// } else {
|
||||
// return baseClass + 'many'
|
||||
// }
|
||||
// },
|
||||
favoritePost : function(evt) {
|
||||
if(evt) { evt.stopImmediatePropagation(); evt.preventDefault() }
|
||||
|
||||
if(this.model.get("favorite")) {
|
||||
this.model.save({favorite : false})
|
||||
} else {
|
||||
this.model.save({favorite : true})
|
||||
this.$el.addClass("x2 width height")
|
||||
}
|
||||
},
|
||||
|
||||
goToPost : function() {
|
||||
app.router.navigate(this.model.url(), true)
|
||||
|
|
|
|||
|
|
@ -9,3 +9,4 @@
|
|||
/* profile */
|
||||
@import 'new_styles/canvas';
|
||||
@import 'new_styles/spinner';
|
||||
@import 'new_styles/profile';
|
||||
|
|
@ -96,6 +96,13 @@ body {
|
|||
}
|
||||
}
|
||||
|
||||
.fav {
|
||||
position : absolute;
|
||||
z-index : 100;
|
||||
top : 10px;
|
||||
right : 10px;
|
||||
}
|
||||
|
||||
/* larger declarations */
|
||||
&.x2.width .content { @include wide(); }
|
||||
&.x2.height .content { @include tall(); }
|
||||
|
|
|
|||
36
app/assets/stylesheets/new_styles/_profile.scss
Normal file
36
app/assets/stylesheets/new_styles/_profile.scss
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
#edit-controls {
|
||||
@include transition(opacity);
|
||||
@include opacity(0);
|
||||
|
||||
position : fixed;
|
||||
|
||||
width : 100%;
|
||||
top : 0;
|
||||
left : 0;
|
||||
|
||||
text-align : center;
|
||||
|
||||
z-index : 999;
|
||||
background-color : rgba(0,0,0,0.6);
|
||||
|
||||
color : #eee;
|
||||
|
||||
padding : 10px 0;
|
||||
}
|
||||
|
||||
.canvas-frame .fav {
|
||||
@include transition(opacity);
|
||||
@include opacity(0)
|
||||
}
|
||||
|
||||
/* functionality under edit mode */
|
||||
.edit-mode {
|
||||
#edit-controls {
|
||||
@include opacity(1);
|
||||
//display : block;
|
||||
}
|
||||
|
||||
.canvas-frame .fav {
|
||||
@include opacity(1)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,3 +1,7 @@
|
|||
<div id="edit-controls">
|
||||
editing...
|
||||
</div>
|
||||
|
||||
<section id="profile_info">
|
||||
<h1>{{full_name}}</h1>
|
||||
<dl>
|
||||
|
|
@ -8,7 +12,8 @@
|
|||
</dl>
|
||||
</section>
|
||||
|
||||
<a href="/posts/new">COMPOSE</a>
|
||||
<a href="/posts/new">COMPOSE</a> |
|
||||
<a href="#" id="edit-mode-toggle">EDIT</a>
|
||||
|
||||
<section id="canvas">
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,13 @@
|
|||
<div class="content">
|
||||
|
||||
<a href="#" class="fav">
|
||||
{{#if favorite}}
|
||||
NOT WORTHY
|
||||
{{else}}
|
||||
FAVE IT
|
||||
{{/ if}}
|
||||
</a>
|
||||
|
||||
{{#if photos}}
|
||||
<div class="image-container">
|
||||
{{#each photos}}
|
||||
|
|
|
|||
|
|
@ -79,6 +79,15 @@ class PostsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def update
|
||||
@post = current_user.posts.find(params[:id])
|
||||
if @post
|
||||
@post.favorite = !@post.favorite
|
||||
@post.save
|
||||
render :nothing => true, :status => 202
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_by_guid_or_id_with_current_user(id)
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ class Post < ActiveRecord::Base
|
|||
t.add :mentioned_people
|
||||
t.add :photos
|
||||
t.add :nsfw
|
||||
t.add :favorite
|
||||
end
|
||||
|
||||
xml_attr :provider_display_name
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ Diaspora::Application.routes.draw do
|
|||
|
||||
resources :status_messages, :only => [:new, :create]
|
||||
|
||||
resources :posts, :only => [:show, :new, :destroy] do
|
||||
resources :posts do
|
||||
resources :likes, :only => [:create, :destroy, :index]
|
||||
resources :participations, :only => [:create, :destroy, :index]
|
||||
resources :comments, :only => [:new, :create, :destroy, :index]
|
||||
|
|
|
|||
5
db/migrate/20120422072257_add_favorite_to_post.rb
Normal file
5
db/migrate/20120422072257_add_favorite_to_post.rb
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
class AddFavoriteToPost < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :posts, :favorite, :boolean, :default => 0
|
||||
end
|
||||
end
|
||||
|
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20120420185823) do
|
||||
ActiveRecord::Schema.define(:version => 20120422072257) do
|
||||
|
||||
create_table "account_deletions", :force => true do |t|
|
||||
t.string "diaspora_handle"
|
||||
|
|
@ -340,6 +340,7 @@ ActiveRecord::Schema.define(:version => 20120420185823) do
|
|||
t.integer "reshares_count", :default => 0
|
||||
t.datetime "interacted_at"
|
||||
t.string "frame_name"
|
||||
t.boolean "favorite", :default => false
|
||||
end
|
||||
|
||||
add_index "posts", ["author_id", "root_guid"], :name => "index_posts_on_author_id_and_root_guid", :unique => true
|
||||
|
|
|
|||
|
|
@ -29,4 +29,20 @@ describe("app.pages.Profile", function(){
|
|||
this.page.render();
|
||||
});
|
||||
});
|
||||
|
||||
describe("edit mode", function(){
|
||||
describe("toggle edit", function(){
|
||||
it("changes the page's global edit state", function(){
|
||||
expect(this.page.editMode).toBeFalsy()
|
||||
this.page.toggleEdit()
|
||||
expect(this.page.editMode).toBeTruthy()
|
||||
})
|
||||
|
||||
it("changes the page's class to 'edit-mode'", function(){
|
||||
expect(this.page.$el).not.toHaveClass('edit-mode')
|
||||
this.page.toggleEdit()
|
||||
expect(this.page.$el).toHaveClass('edit-mode')
|
||||
})
|
||||
})
|
||||
})
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue