Graph: build json
This commit is contained in:
parent
ef08872534
commit
6b66a766d1
9 changed files with 308 additions and 1 deletions
|
@ -10,6 +10,8 @@
|
|||
//= require jquery.ui.selectmenu
|
||||
//= require jquery.tagify
|
||||
//= require jquery.cookie
|
||||
//= require raphael
|
||||
//= require branch-graph
|
||||
//= require_tree .
|
||||
|
||||
$(function(){
|
||||
|
@ -35,4 +37,4 @@ function showMenu() {
|
|||
|
||||
function resetMenu() {
|
||||
$(this).removeClass("hover");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
require File.join(Rails.root, 'lib', 'graph_commit')
|
||||
|
||||
class ProjectsController < ApplicationController
|
||||
before_filter :project, :except => [:index, :new, :create]
|
||||
layout :determine_layout
|
||||
|
@ -125,6 +127,36 @@ class ProjectsController < ApplicationController
|
|||
return render_404
|
||||
end
|
||||
|
||||
def graph
|
||||
@repo = project.repo
|
||||
commits = Grit::Commit.find_all(@repo, nil, {:max_count => 650})
|
||||
ref_cache = {}
|
||||
commits.collect! do |commit|
|
||||
add_refs(commit, ref_cache)
|
||||
GraphCommit.new(commit)
|
||||
end
|
||||
|
||||
days = GraphCommit.index_commits(commits)
|
||||
@days_json = days.compact.collect{|d| [d.day, d.strftime("%b")] }.to_json
|
||||
@commits_json = commits.collect do |c|
|
||||
h = {}
|
||||
h[:parents] = c.parents.collect do |p|
|
||||
[p.id,0,0]
|
||||
end
|
||||
h[:author] = c.author.name.force_encoding("UTF-8")
|
||||
h[:time] = c.time
|
||||
h[:space] = c.space
|
||||
h[:refs] = c.refs.collect{|r|r.name}.join(" ") unless c.refs.nil?
|
||||
h[:id] = c.sha
|
||||
h[:date] = c.date
|
||||
h[:message] = c.message.force_encoding("UTF-8")
|
||||
h[:email] = c.author.email
|
||||
h
|
||||
end.to_json
|
||||
|
||||
render :text => @commits_json
|
||||
end
|
||||
|
||||
def blob
|
||||
@repo = project.repo
|
||||
@commit = project.commit(params[:commit_id])
|
||||
|
@ -149,6 +181,14 @@ class ProjectsController < ApplicationController
|
|||
|
||||
protected
|
||||
|
||||
def add_refs(commit, ref_cache)
|
||||
if ref_cache.empty?
|
||||
@repo.refs.each {|ref| ref_cache[ref.commit.id] ||= [];ref_cache[ref.commit.id] << ref}
|
||||
end
|
||||
commit.refs = ref_cache[commit.id] if ref_cache.include? commit.id
|
||||
commit.refs ||= []
|
||||
end
|
||||
|
||||
def project
|
||||
@project ||= Project.find_by_code(params[:id])
|
||||
end
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
= link_to "History", project_path(@project), :class => current_page?(:controller => "projects", :action => "show", :id => @project) ? "current" : nil
|
||||
= link_to "Tree", tree_project_path(@project), :class => current_page?(:controller => "projects", :action => "tree", :id => @project) ? "current" : nil
|
||||
= link_to "Commits", project_commits_path(@project), :class => current_page?(:controller => "commits", :action => "index", :project_id => @project) ? "current" : nil
|
||||
= link_to "Network graph", graph_project_path(@project), :class => current_page?(:controller => "projects", :action => "graph", :project_id => @project) ? "current" : nil
|
||||
= link_to team_project_path(@project), :class => (current_page?(:controller => "projects", :action => "team", :id => @project) || controller.controller_name == "team_members") ? "current" : nil do
|
||||
Team
|
||||
- if @project.users_projects.count > 0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue