| |   |
| 1 | 1 | class SiteController < ApplicationController |
| 2 | before_filter :login_required, :only => [:dashboard] |
| 2 | 3 | |
| 3 | 4 | def index |
| 4 | 5 | @tags = Project.tag_counts |
| 5 | 6 | @projects = Project.find(:all, :limit => 5, :order => "id desc") |
| 6 | 7 | end |
| 7 | 8 | |
| 9 | def dashboard |
| 10 | @projects = current_user.projects |
| 11 | project_ids = @projects.map(&:id) |
| 12 | @recent_comments = Comment.find(:all, :limit => 10, |
| 13 | :conditions => ["project_id in (?)", project_ids], :order => "created_at desc") |
| 14 | @repository_clones = @projects.map(&:repository_clones).flatten |
| 15 | # @repository_clones = Repository.find(:all, |
| 16 | # :conditions => ["project_id in (?) and mainline = ?", project_ids, false]) |
| 17 | end |
| 18 | |
| 8 | 19 | def about |
| 9 | 20 | end |
| 10 | 21 | |
| toggle raw diff |
--- a/app/controllers/site_controller.rb
+++ b/app/controllers/site_controller.rb
@@ -1,10 +1,21 @@
class SiteController < ApplicationController
+ before_filter :login_required, :only => [:dashboard]
def index
@tags = Project.tag_counts
@projects = Project.find(:all, :limit => 5, :order => "id desc")
end
+ def dashboard
+ @projects = current_user.projects
+ project_ids = @projects.map(&:id)
+ @recent_comments = Comment.find(:all, :limit => 10,
+ :conditions => ["project_id in (?)", project_ids], :order => "created_at desc")
+ @repository_clones = @projects.map(&:repository_clones).flatten
+ # @repository_clones = Repository.find(:all,
+ # :conditions => ["project_id in (?) and mainline = ?", project_ids, false])
+ end
+
def about
end
|
| |   |
| 1 | 1 | class Comment < ActiveRecord::Base |
| 2 | 2 | belongs_to :user |
| 3 | 3 | belongs_to :repository |
| 4 | belongs_to :project |
| 4 | 5 | |
| 5 | 6 | attr_protected :user_id |
| 6 | 7 | |
| 7 | | validates_presence_of :user_id, :repository_id, :body |
| 8 | validates_presence_of :user_id, :repository_id, :body, :project_id |
| 8 | 9 | |
| 9 | 10 | |
| 10 | 11 | end |
| toggle raw diff |
--- a/app/models/comment.rb
+++ b/app/models/comment.rb
@@ -1,10 +1,11 @@
class Comment < ActiveRecord::Base
belongs_to :user
belongs_to :repository
+ belongs_to :project
attr_protected :user_id
- validates_presence_of :user_id, :repository_id, :body
+ validates_presence_of :user_id, :repository_id, :body, :project_id
end |
| |   |
| 2 | 2 | acts_as_taggable |
| 3 | 3 | |
| 4 | 4 | belongs_to :user |
| 5 | has_many :comments |
| 5 | 6 | has_many :repositories, :order => "mainline desc, created_at asc", |
| 6 | 7 | :dependent => :destroy |
| 7 | 8 | has_one :mainline_repository, :conditions => ["mainline = ?", true], |
| 8 | 9 | :class_name => "Repository" |
| 9 | | has_many :branch_repositories, :conditions => ["mainline = ?", false], |
| 10 | has_many :repository_clones, :conditions => ["mainline = ?", false], |
| 10 | 11 | :class_name => "Repository" |
| 11 | 12 | |
| 12 | 13 | URL_FORMAT_RE = /^(http|https|nntp):\/\//.freeze |
| toggle raw diff |
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -2,11 +2,12 @@ class Project < ActiveRecord::Base
acts_as_taggable
belongs_to :user
+ has_many :comments
has_many :repositories, :order => "mainline desc, created_at asc",
:dependent => :destroy
has_one :mainline_repository, :conditions => ["mainline = ?", true],
:class_name => "Repository"
- has_many :branch_repositories, :conditions => ["mainline = ?", false],
+ has_many :repository_clones, :conditions => ["mainline = ?", false],
:class_name => "Repository"
URL_FORMAT_RE = /^(http|https|nntp):\/\//.freeze |
| |   |
| 13 | 13 | <%= GitoriousConfig["extra_html_head_data"] -%> |
| 14 | 14 | </head> |
| 15 | 15 | |
| 16 | | <body> |
| 16 | <body id="<%= controller.controller_name -%>"> |
| 17 | 17 | <div id="container"> |
| 18 | 18 | <div id="header"> |
| 19 | 19 | <div class="login-logout"> |
| … | … | |
| 34 | 34 | <div id="menu"> |
| 35 | 35 | <ul> |
| 36 | 36 | <li><%= link_to "Home", root_path -%></li> |
| 37 | <% if logged_in? -%> |
| 38 | <li><%= link_to "Dashboard", dashboard_path -%></li> |
| 39 | <% end -%> |
| 37 | 40 | <li><%= link_to "Projects", projects_path -%></li> |
| 38 | 41 | <li><%= link_to "About", about_path -%></li> |
| 39 | 42 | </ul> |
| toggle raw diff |
--- a/app/views/layouts/application.html.erb
+++ b/app/views/layouts/application.html.erb
@@ -13,7 +13,7 @@
<%= GitoriousConfig["extra_html_head_data"] -%>
</head>
-<body>
+<body id="<%= controller.controller_name -%>">
<div id="container">
<div id="header">
<div class="login-logout">
@@ -34,6 +34,9 @@
<div id="menu">
<ul>
<li><%= link_to "Home", root_path -%></li>
+ <% if logged_in? -%>
+ <li><%= link_to "Dashboard", dashboard_path -%></li>
+ <% end -%>
<li><%= link_to "Projects", projects_path -%></li>
<li><%= link_to "About", about_path -%></li>
</ul> |
| |   |
| 1 | <% @page_title = "#{current_user.login}'s dashboard" -%> |
| 2 | |
| 3 | <div id="recent_comments"> |
| 4 | <h2>Recent comments on your commits</h2> |
| 5 | <% @recent_comments.each do |comment| -%> |
| 6 | <div class="comment"> |
| 7 | <p class="body"><%= sanitize(comment.body) -%></p> |
| 8 | <p class="byline hint"> |
| 9 | on <%= link_to h(comment.repository.name), project_repository_comments_path(comment.project, comment.repository, :anchor => dom_id(comment)) -%> |
| 10 | <% unless comment.sha1.blank? -%> |
| 11 | (<%= link_to h(comment.sha1[0..6]), project_repository_commit_path(comment.project, comment.repository, comment.sha1) -%>) |
| 12 | <% end -%> |
| 13 | in <%= link_to h(comment.project.title), comment.project -%> by |
| 14 | <%= link_to(h(comment.user.login), comment.user) -%> |
| 15 | <%= time_ago_in_words(comment.created_at) -%> ago |
| 16 | </p> |
| 17 | </div> |
| 18 | <% end -%> |
| 19 | <% if @recent_comments.blank? -%> |
| 20 | <p class="hint">Sorry, no comments yet</p> |
| 21 | <% end -%> |
| 22 | </div> |
| 23 | |
| 24 | <div id="clone_list"> |
| 25 | <h2>Clones of your project repositories</h2> |
| 26 | <ul> |
| 27 | <% @repository_clones.each do |repos| -%> |
| 28 | <li> |
| 29 | <%= link_to h(repos.name), project_repository_path(@project, repos) -%> |
| 30 | <small>of <%= h(repos.project.slug) -%></small> |
| 31 | </li> |
| 32 | <% end -%> |
| 33 | <% if @repository_clones.blank? -%> |
| 34 | <li class="hint">No clones so far</li> |
| 35 | <% end -%> |
| 36 | </ul> |
| 37 | </div> |
| 38 | |
| 39 | <div class="clear"></div> |
| 40 | |
| 41 | <% content_for :sidebar do -%> |
| 42 | <h4>Your projects:</h4> |
| 43 | <ul class="links"> |
| 44 | <% @projects.each do |project| -%> |
| 45 | <li><%= link_to project.slug, project -%></li> |
| 46 | <% end -%> |
| 47 | <li><%= link_to "Create new →", new_project_path -%></li> |
| 48 | </ul> |
| 49 | <% end -%> |
| toggle raw diff |
--- /dev/null
+++ b/app/views/site/dashboard.html.erb
@@ -0,0 +1,49 @@
+<% @page_title = "#{current_user.login}'s dashboard" -%>
+
+<div id="recent_comments">
+ <h2>Recent comments on your commits</h2>
+ <% @recent_comments.each do |comment| -%>
+ <div class="comment">
+ <p class="body"><%= sanitize(comment.body) -%></p>
+ <p class="byline hint">
+ on <%= link_to h(comment.repository.name), project_repository_comments_path(comment.project, comment.repository, :anchor => dom_id(comment)) -%>
+ <% unless comment.sha1.blank? -%>
+ (<%= link_to h(comment.sha1[0..6]), project_repository_commit_path(comment.project, comment.repository, comment.sha1) -%>)
+ <% end -%>
+ in <%= link_to h(comment.project.title), comment.project -%> by
+ <%= link_to(h(comment.user.login), comment.user) -%>
+ <%= time_ago_in_words(comment.created_at) -%> ago
+ </p>
+ </div>
+ <% end -%>
+ <% if @recent_comments.blank? -%>
+ <p class="hint">Sorry, no comments yet</p>
+ <% end -%>
+</div>
+
+<div id="clone_list">
+ <h2>Clones of your project repositories</h2>
+ <ul>
+ <% @repository_clones.each do |repos| -%>
+ <li>
+ <%= link_to h(repos.name), project_repository_path(@project, repos) -%>
+ <small>of <%= h(repos.project.slug) -%></small>
+ </li>
+ <% end -%>
+ <% if @repository_clones.blank? -%>
+ <li class="hint">No clones so far</li>
+ <% end -%>
+ </ul>
+</div>
+
+<div class="clear"></div>
+
+<% content_for :sidebar do -%>
+ <h4>Your projects:</h4>
+ <ul class="links">
+ <% @projects.each do |project| -%>
+ <li><%= link_to project.slug, project -%></li>
+ <% end -%>
+ <li><%= link_to "Create new →", new_project_path -%></li>
+ </ul>
+<% end -%>
\ No newline at end of file |
| |   |
| 62 | 62 | session.login '/login', :action => 'new' |
| 63 | 63 | session.logout '/logout', :action => 'destroy' |
| 64 | 64 | end |
| 65 | | |
| 65 | |
| 66 | map.dashboard "dashboard", :controller => "site", :action => "dashboard" |
| 66 | 67 | map.about "about", :controller => "site", :action => "about" |
| 67 | 68 | |
| 68 | 69 | # Install the default route as the lowest priority. |
| toggle raw diff |
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -62,7 +62,8 @@ ActionController::Routing::Routes.draw do |map|
session.login '/login', :action => 'new'
session.logout '/logout', :action => 'destroy'
end
-
+
+ map.dashboard "dashboard", :controller => "site", :action => "dashboard"
map.about "about", :controller => "site", :action => "about"
# Install the default route as the lowest priority. |
| |   |
| 1 | class AddProjectIdToComments < ActiveRecord::Migration |
| 2 | def self.up |
| 3 | add_column :comments, :project_id, :integer |
| 4 | add_index :comments, :project_id |
| 5 | ActiveRecord::Base::reset_column_information |
| 6 | |
| 7 | Comment.find(:all).each do |comment| |
| 8 | comment.update_attributes(:project_id => comment.repository.project_id) |
| 9 | end |
| 10 | end |
| 11 | |
| 12 | def self.down |
| 13 | remove_column :comments, :project_id |
| 14 | end |
| 15 | end |
| toggle raw diff |
--- /dev/null
+++ b/db/migrate/020_add_project_id_to_comments.rb
@@ -0,0 +1,15 @@
+class AddProjectIdToComments < ActiveRecord::Migration
+ def self.up
+ add_column :comments, :project_id, :integer
+ add_index :comments, :project_id
+ ActiveRecord::Base::reset_column_information
+
+ Comment.find(:all).each do |comment|
+ comment.update_attributes(:project_id => comment.repository.project_id)
+ end
+ end
+
+ def self.down
+ remove_column :comments, :project_id
+ end
+end |
| |   |
| 9 | 9 | # |
| 10 | 10 | # It's strongly recommended to check this file into your version control system. |
| 11 | 11 | |
| 12 | | ActiveRecord::Schema.define(:version => 19) do |
| 12 | ActiveRecord::Schema.define(:version => 20) do |
| 13 | 13 | |
| 14 | 14 | create_table "comments", :force => true do |t| |
| 15 | 15 | t.integer "user_id", :null => false |
| … | … | |
| 18 | 18 | t.text "body" |
| 19 | 19 | t.datetime "created_at" |
| 20 | 20 | t.datetime "updated_at" |
| 21 | t.integer "project_id" |
| 21 | 22 | end |
| 22 | 23 | |
| 23 | 24 | add_index "comments", ["user_id"], :name => "index_comments_on_user_id" |
| 24 | 25 | add_index "comments", ["repository_id"], :name => "index_comments_on_repository_id" |
| 25 | 26 | add_index "comments", ["sha1"], :name => "index_comments_on_sha1" |
| 27 | add_index "comments", ["project_id"], :name => "index_comments_on_project_id" |
| 26 | 28 | |
| 27 | 29 | create_table "committerships", :force => true do |t| |
| 28 | 30 | t.integer "user_id" |
| toggle raw diff |
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 19) do
+ActiveRecord::Schema.define(:version => 20) do
create_table "comments", :force => true do |t|
t.integer "user_id", :null => false
@@ -18,11 +18,13 @@ ActiveRecord::Schema.define(:version => 19) do
t.text "body"
t.datetime "created_at"
t.datetime "updated_at"
+ t.integer "project_id"
end
add_index "comments", ["user_id"], :name => "index_comments_on_user_id"
add_index "comments", ["repository_id"], :name => "index_comments_on_repository_id"
add_index "comments", ["sha1"], :name => "index_comments_on_sha1"
+ add_index "comments", ["project_id"], :name => "index_comments_on_project_id"
create_table "committerships", :force => true do |t|
t.integer "user_id" |
| |   |
| 2 | 2 | |
| 3 | 3 | describe SiteController do |
| 4 | 4 | |
| 5 | | describe "#index" do |
| 6 | | |
| 5 | describe "#index" do |
| 7 | 6 | it "GETs sucessfully" do |
| 8 | 7 | get :index |
| 9 | 8 | response.should be_success |
| … | … | |
| 18 | 18 | assigns[:projects].should == Project.find(:all, :limit => 5, :order => "id desc") |
| 19 | 19 | end |
| 20 | 20 | end |
| 21 | |
| 22 | describe "#dashboard" do |
| 23 | before(:each) do |
| 24 | login_as :johan |
| 25 | end |
| 26 | it "GETs successfully" do |
| 27 | get :dashboard |
| 28 | response.should be_success |
| 29 | response.should render_template("site/dashboard") |
| 30 | end |
| 31 | |
| 32 | it "requires login" do |
| 33 | login_as nil |
| 34 | get :dashboard |
| 35 | response.should redirect_to(new_sessions_path) |
| 36 | end |
| 37 | |
| 38 | it "get a list of the current_users projects" do |
| 39 | get :dashboard |
| 40 | assigns[:projects].should == [*projects(:johans)] |
| 41 | end |
| 42 | |
| 43 | it "gets a list of recent comments from users projects" do |
| 44 | get :dashboard |
| 45 | assigns[:recent_comments].should == comments(:johans_repos, :johans_repos2) |
| 46 | end |
| 47 | |
| 48 | it "gets a list of all the clones made of current_users repositories" do |
| 49 | get :dashboard |
| 50 | assigns[:repository_clones].should == [*repositories(:johans2)] |
| 51 | end |
| 52 | end |
| 21 | 53 | |
| 22 | 54 | end |
| toggle raw diff |
--- a/spec/controllers/site_controller_spec.rb
+++ b/spec/controllers/site_controller_spec.rb
@@ -2,8 +2,7 @@ require File.dirname(__FILE__) + '/../spec_helper'
describe SiteController do
- describe "#index" do
-
+ describe "#index" do
it "GETs sucessfully" do
get :index
response.should be_success
@@ -19,5 +18,37 @@ describe SiteController do
assigns[:projects].should == Project.find(:all, :limit => 5, :order => "id desc")
end
end
+
+ describe "#dashboard" do
+ before(:each) do
+ login_as :johan
+ end
+ it "GETs successfully" do
+ get :dashboard
+ response.should be_success
+ response.should render_template("site/dashboard")
+ end
+
+ it "requires login" do
+ login_as nil
+ get :dashboard
+ response.should redirect_to(new_sessions_path)
+ end
+
+ it "get a list of the current_users projects" do
+ get :dashboard
+ assigns[:projects].should == [*projects(:johans)]
+ end
+
+ it "gets a list of recent comments from users projects" do
+ get :dashboard
+ assigns[:recent_comments].should == comments(:johans_repos, :johans_repos2)
+ end
+
+ it "gets a list of all the clones made of current_users repositories" do
+ get :dashboard
+ assigns[:repository_clones].should == [*repositories(:johans2)]
+ end
+ end
end |
| |   |
| 6 | 6 | repository_id: 1 |
| 7 | 7 | sha1: 0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33 # foo |
| 8 | 8 | body: a comment |
| 9 | project_id: 1 |
| 9 | 10 | |
| 10 | 11 | johans_repos2: |
| 11 | 12 | id: 2 |
| … | … | |
| 14 | 14 | repository_id: 1 |
| 15 | 15 | sha1: 62cdb7020ff920e5aa642c3d4066950dd1f01f4d # bar |
| 16 | 16 | body: another comment |
| 17 | project_id: 1 |
| 17 | 18 | |
| 18 | 19 | moes_repos: |
| 19 | 20 | id: 3 |
| … | … | |
| 22 | 22 | repository_id: 2 |
| 23 | 23 | sha1: 62cdb7020ff920e5aa642c3d4066950dd1f01f4d # bar |
| 24 | 24 | body: a comment in moes repos |
| 25 | project_id: 2 |
| toggle raw diff |
--- a/spec/fixtures/comments.yml
+++ b/spec/fixtures/comments.yml
@@ -6,6 +6,7 @@ johans_repos:
repository_id: 1
sha1: 0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33 # foo
body: a comment
+ project_id: 1
johans_repos2:
id: 2
@@ -13,6 +14,7 @@ johans_repos2:
repository_id: 1
sha1: 62cdb7020ff920e5aa642c3d4066950dd1f01f4d # bar
body: another comment
+ project_id: 1
moes_repos:
id: 3
@@ -20,3 +22,4 @@ moes_repos:
repository_id: 2
sha1: 62cdb7020ff920e5aa642c3d4066950dd1f01f4d # bar
body: a comment in moes repos
+ project_id: 2 |
| |   |
| 9 | 9 | c = Comment.new({ |
| 10 | 10 | :repository => repositories(:johans), |
| 11 | 11 | :sha1 => Digest::SHA1.hexdigest("baz"), |
| 12 | | :body => "blabla" |
| 12 | :body => "blabla", |
| 13 | :project => projects(:johans) |
| 13 | 14 | }.merge(opts)) |
| 14 | 15 | c.user = opts[:user] || users(:johan) |
| 15 | 16 | c |
| … | … | |
| 38 | 38 | @comment.should have(1).error_on(:body) |
| 39 | 39 | end |
| 40 | 40 | |
| 41 | it "should belong to a project to be valid" do |
| 42 | @comment.project_id = nil |
| 43 | @comment.should_not be_valid |
| 44 | @comment.should have(1).error_on(:project_id) |
| 45 | end |
| 46 | |
| 41 | 47 | # it "should have a sha1 to be valid" do |
| 42 | 48 | # @comment.sha1 = nil |
| 43 | 49 | # @comment.should_not be_valid |
| toggle raw diff |
--- a/spec/models/comment_spec.rb
+++ b/spec/models/comment_spec.rb
@@ -9,7 +9,8 @@ describe Comment do
c = Comment.new({
:repository => repositories(:johans),
:sha1 => Digest::SHA1.hexdigest("baz"),
- :body => "blabla"
+ :body => "blabla",
+ :project => projects(:johans)
}.merge(opts))
c.user = opts[:user] || users(:johan)
c
@@ -37,6 +38,12 @@ describe Comment do
@comment.should have(1).error_on(:body)
end
+ it "should belong to a project to be valid" do
+ @comment.project_id = nil
+ @comment.should_not be_valid
+ @comment.should have(1).error_on(:project_id)
+ end
+
# it "should have a sha1 to be valid" do
# @comment.sha1 = nil
# @comment.should_not be_valid |