diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index bb091706b..a36a8c873 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -16,6 +16,7 @@ class ApplicationController < ActionController::Base end def set_friends_and_status + @groups = current_user.groups @friends = current_user.friends if current_user @latest_status_message = StatusMessage.newest_for(current_user) if current_user end diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb new file mode 100644 index 000000000..e12809fb6 --- /dev/null +++ b/app/controllers/groups_controller.rb @@ -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 diff --git a/app/models/group.rb b/app/models/group.rb new file mode 100644 index 000000000..885e471cc --- /dev/null +++ b/app/models/group.rb @@ -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 + diff --git a/app/models/user.rb b/app/models/user.rb index 7a73971ab..794c7970a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -12,6 +12,8 @@ class User many :friends, :in => :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 :do_bad_things @@ -28,9 +30,14 @@ class User "#{person.profile.first_name.to_s} #{person.profile.last_name.to_s}" end + ######### Groups ###################### + def group( opts = {} ) + opts[:user] = self + Group.create(opts) + end - ######### Friend Requesting + ######### Friend Requesting ########### def send_friend_request_to(friend_url) unless self.friends.find{ |x| x.url == friend_url} p = Request.instantiate(:to => friend_url, :from => self.person) diff --git a/app/views/groups/_new_group.haml b/app/views/groups/_new_group.haml new file mode 100644 index 000000000..755223fd8 --- /dev/null +++ b/app/views/groups/_new_group.haml @@ -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' diff --git a/app/views/groups/edit.html.haml b/app/views/groups/edit.html.haml new file mode 100644 index 000000000..461bff1db --- /dev/null +++ b/app/views/groups/edit.html.haml @@ -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 diff --git a/app/views/groups/new.html.haml b/app/views/groups/new.html.haml new file mode 100644 index 000000000..c899fd9ae --- /dev/null +++ b/app/views/groups/new.html.haml @@ -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 diff --git a/app/views/shared/_group_nav.haml b/app/views/shared/_group_nav.haml index 9ba2f6d67..c61712038 100644 --- a/app/views/shared/_group_nav.haml +++ b/app/views/shared/_group_nav.haml @@ -1,14 +1,13 @@ #group %ul - %li.other_presidents= link_to "OTHER PRESIDENTS", root_path(:g => "other_presidents") - %li.ostatus= link_to "OSTATUS", ostatus_path(:g => "ostatus") - %li.new_circle= link_to "NEW CIRCLE", "#" + - for group in @groups + %li= link_to group.name, group_path(group) + + %li.new_group= link_to "NEW GROUP", new_group_path #friend_pictures - for friend in @friends = person_image_link(friend) - -for author in @subscribed_persons - = link_to (image_tag author.avatar_thumbnail, :class => "person_picture"), author_path(author) .add_new = link_to "+", requests_path diff --git a/config/routes.rb b/config/routes.rb index 3726f5bf4..8d0cd5c01 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -8,6 +8,7 @@ Diaspora::Application.routes.draw do |map| resources :requests resources :photos resources :albums + resources :groups match "/images/files/*path" => "gridfs#serve" diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index 157423bba..ad207bf50 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -70,6 +70,7 @@ header { color: #555555; background-color: #2b2726; background-color: black; + background-color: white; border-bottom: 3px solid #333333; padding: 6px 0; padding-top: 0; } @@ -436,6 +437,7 @@ h1.big_text { margin-right: 10px; } #group ul > li.selected, #group ul > li.selected a { color: white; + color: black; font-weight: bold; font-size: 18px; } #group a { diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index df7530904..75b14624e 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -75,6 +75,7 @@ header :background :color #2B2726 :color #000 + :color #fff :border :bottom 3px solid #333 :padding 6px 0 @@ -546,6 +547,7 @@ h1.big_text &.selected, &.selected a :color #fff + :color #000 :font :weight bold :size 18px diff --git a/spec/models/group_spec.rb b/spec/models/group_spec.rb new file mode 100644 index 000000000..a40a9be11 --- /dev/null +++ b/spec/models/group_spec.rb @@ -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