DG RS; added groups. can't delete, but can make new ones
This commit is contained in:
parent
d71966476b
commit
aebe7b97c0
12 changed files with 151 additions and 6 deletions
|
|
@ -16,6 +16,7 @@ class ApplicationController < ActionController::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_friends_and_status
|
def set_friends_and_status
|
||||||
|
@groups = current_user.groups
|
||||||
@friends = current_user.friends if current_user
|
@friends = current_user.friends if current_user
|
||||||
@latest_status_message = StatusMessage.newest_for(current_user) if current_user
|
@latest_status_message = StatusMessage.newest_for(current_user) if current_user
|
||||||
end
|
end
|
||||||
|
|
|
||||||
44
app/controllers/groups_controller.rb
Normal file
44
app/controllers/groups_controller.rb
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
class GroupsController < ApplicationController
|
||||||
|
before_filter :authenticate_user!
|
||||||
|
|
||||||
|
def create
|
||||||
|
@group = current_user.group(params[:group])
|
||||||
|
|
||||||
|
if @group.created_at
|
||||||
|
flash[:notice] = "Successfully created group."
|
||||||
|
redirect_to root_url
|
||||||
|
else
|
||||||
|
render :action => 'new'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def new
|
||||||
|
@group = Group.new
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
@group = Group.first(:id => params[:id])
|
||||||
|
@group.destroy
|
||||||
|
flash[:notice] = "Successfully destroyed group."
|
||||||
|
redirect_to groups_url
|
||||||
|
end
|
||||||
|
|
||||||
|
def show
|
||||||
|
@group = Group.first(:id => params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
|
def edit
|
||||||
|
@group = Group.first(:id => params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
@group = Group.first(:id => params[:id])
|
||||||
|
if @group.update_attributes(params[:group])
|
||||||
|
flash[:notice] = "Successfully updated group."
|
||||||
|
redirect_to @group
|
||||||
|
else
|
||||||
|
render :action => 'edit'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
12
app/models/group.rb
Normal file
12
app/models/group.rb
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
class Group
|
||||||
|
include MongoMapper::Document
|
||||||
|
|
||||||
|
key :name, String
|
||||||
|
|
||||||
|
many :people, :class_name => 'Person'
|
||||||
|
belongs_to :user, :class_name => 'User'
|
||||||
|
|
||||||
|
timestamps!
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
@ -12,6 +12,8 @@ class User
|
||||||
many :friends, :in => :friend_ids, :class_name => 'Person'
|
many :friends, :in => :friend_ids, :class_name => 'Person'
|
||||||
many :pending_friends, :in => :pending_friend_ids, :class_name => 'Person'
|
many :pending_friends, :in => :pending_friend_ids, :class_name => 'Person'
|
||||||
|
|
||||||
|
many :groups, :class_name => 'Group'
|
||||||
|
|
||||||
before_validation_on_create :assign_key
|
before_validation_on_create :assign_key
|
||||||
before_validation :do_bad_things
|
before_validation :do_bad_things
|
||||||
|
|
||||||
|
|
@ -28,9 +30,14 @@ class User
|
||||||
"#{person.profile.first_name.to_s} #{person.profile.last_name.to_s}"
|
"#{person.profile.first_name.to_s} #{person.profile.last_name.to_s}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
######### Groups ######################
|
||||||
|
|
||||||
|
def group( opts = {} )
|
||||||
|
opts[:user] = self
|
||||||
|
Group.create(opts)
|
||||||
|
end
|
||||||
|
|
||||||
######### Friend Requesting
|
######### Friend Requesting ###########
|
||||||
def send_friend_request_to(friend_url)
|
def send_friend_request_to(friend_url)
|
||||||
unless self.friends.find{ |x| x.url == friend_url}
|
unless self.friends.find{ |x| x.url == friend_url}
|
||||||
p = Request.instantiate(:to => friend_url, :from => self.person)
|
p = Request.instantiate(:to => friend_url, :from => self.person)
|
||||||
|
|
|
||||||
6
app/views/groups/_new_group.haml
Normal file
6
app/views/groups/_new_group.haml
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
= form_for Group.new do |f|
|
||||||
|
= f.error_messages
|
||||||
|
%p
|
||||||
|
= f.label :name
|
||||||
|
= f.text_field :name
|
||||||
|
= f.submit 'create', :class => 'button'
|
||||||
25
app/views/groups/edit.html.haml
Normal file
25
app/views/groups/edit.html.haml
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
%h1.big_text
|
||||||
|
.back
|
||||||
|
= link_to "⇧ #{@group.name}", @group
|
||||||
|
|
||||||
|
= "Editing #{@group.name}"
|
||||||
|
|
||||||
|
.sub_header
|
||||||
|
="updated #{how_long_ago(@group)}"
|
||||||
|
|
||||||
|
- form_for @group do |a|
|
||||||
|
= a.error_messages
|
||||||
|
%p
|
||||||
|
= a.text_field :name
|
||||||
|
|
||||||
|
#submit_block
|
||||||
|
= link_to "Cancel", root_path
|
||||||
|
or
|
||||||
|
= a.submit
|
||||||
|
|
||||||
|
.button.delete
|
||||||
|
= link_to 'Delete Album', @group, :confirm => 'Are you sure?', :method => :delete
|
||||||
|
|
||||||
|
#content_bottom
|
||||||
|
.back
|
||||||
|
= link_to "⇧ #{@group.name}", @group
|
||||||
14
app/views/groups/new.html.haml
Normal file
14
app/views/groups/new.html.haml
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
%h1.big_text
|
||||||
|
=link_to 'groups', groups_path
|
||||||
|
>>
|
||||||
|
new group
|
||||||
|
|
||||||
|
= form_for @group do |f|
|
||||||
|
= f.error_messages
|
||||||
|
%p
|
||||||
|
= f.label :name
|
||||||
|
= f.text_field :name
|
||||||
|
%p
|
||||||
|
= f.submit
|
||||||
|
|
||||||
|
%p= link_to "Back to List", groups_path
|
||||||
|
|
@ -1,14 +1,13 @@
|
||||||
#group
|
#group
|
||||||
%ul
|
%ul
|
||||||
%li.other_presidents= link_to "OTHER PRESIDENTS", root_path(:g => "other_presidents")
|
- for group in @groups
|
||||||
%li.ostatus= link_to "OSTATUS", ostatus_path(:g => "ostatus")
|
%li= link_to group.name, group_path(group)
|
||||||
%li.new_circle= link_to "NEW CIRCLE", "#"
|
|
||||||
|
%li.new_group= link_to "NEW GROUP", new_group_path
|
||||||
|
|
||||||
#friend_pictures
|
#friend_pictures
|
||||||
- for friend in @friends
|
- for friend in @friends
|
||||||
= person_image_link(friend)
|
= person_image_link(friend)
|
||||||
|
|
||||||
-for author in @subscribed_persons
|
|
||||||
= link_to (image_tag author.avatar_thumbnail, :class => "person_picture"), author_path(author)
|
|
||||||
.add_new
|
.add_new
|
||||||
= link_to "+", requests_path
|
= link_to "+", requests_path
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ Diaspora::Application.routes.draw do |map|
|
||||||
resources :requests
|
resources :requests
|
||||||
resources :photos
|
resources :photos
|
||||||
resources :albums
|
resources :albums
|
||||||
|
resources :groups
|
||||||
|
|
||||||
match "/images/files/*path" => "gridfs#serve"
|
match "/images/files/*path" => "gridfs#serve"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,7 @@ header {
|
||||||
color: #555555;
|
color: #555555;
|
||||||
background-color: #2b2726;
|
background-color: #2b2726;
|
||||||
background-color: black;
|
background-color: black;
|
||||||
|
background-color: white;
|
||||||
border-bottom: 3px solid #333333;
|
border-bottom: 3px solid #333333;
|
||||||
padding: 6px 0;
|
padding: 6px 0;
|
||||||
padding-top: 0; }
|
padding-top: 0; }
|
||||||
|
|
@ -436,6 +437,7 @@ h1.big_text {
|
||||||
margin-right: 10px; }
|
margin-right: 10px; }
|
||||||
#group ul > li.selected, #group ul > li.selected a {
|
#group ul > li.selected, #group ul > li.selected a {
|
||||||
color: white;
|
color: white;
|
||||||
|
color: black;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
font-size: 18px; }
|
font-size: 18px; }
|
||||||
#group a {
|
#group a {
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,7 @@ header
|
||||||
:background
|
:background
|
||||||
:color #2B2726
|
:color #2B2726
|
||||||
:color #000
|
:color #000
|
||||||
|
:color #fff
|
||||||
:border
|
:border
|
||||||
:bottom 3px solid #333
|
:bottom 3px solid #333
|
||||||
:padding 6px 0
|
:padding 6px 0
|
||||||
|
|
@ -546,6 +547,7 @@ h1.big_text
|
||||||
|
|
||||||
&.selected, &.selected a
|
&.selected, &.selected a
|
||||||
:color #fff
|
:color #fff
|
||||||
|
:color #000
|
||||||
:font
|
:font
|
||||||
:weight bold
|
:weight bold
|
||||||
:size 18px
|
:size 18px
|
||||||
|
|
|
||||||
32
spec/models/group_spec.rb
Normal file
32
spec/models/group_spec.rb
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
require File.dirname(__FILE__) + '/../spec_helper'
|
||||||
|
|
||||||
|
describe Group do
|
||||||
|
before do
|
||||||
|
@user = Factory.create(:user)
|
||||||
|
@friend = Factory.create(:person)
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'creation' do
|
||||||
|
it 'should have a name' do
|
||||||
|
group = @user.group(:name => 'losers')
|
||||||
|
group.name.should == "losers"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'querying' do
|
||||||
|
before do
|
||||||
|
@group = @user.group(:name => 'losers', :people => [@friend])
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'belong to a user' do
|
||||||
|
@group.user.id.should == @user.id
|
||||||
|
@user.groups.size.should == 1
|
||||||
|
@user.groups.first.id.should == @group.id
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should have people' do
|
||||||
|
@group.people.all.include?(@friend).should be true
|
||||||
|
@group.people.size.should == 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
Reference in a new issue