app/controllers/project_controller.rb in damagecontrol-0.5.0 vs app/controllers/project_controller.rb in damagecontrol-0.5.0.1391
- old
+ new
@@ -1,62 +1,42 @@
require 'rscm'
require 'damagecontrol/project'
require 'damagecontrol/directories'
require 'damagecontrol/diff_parser'
require 'damagecontrol/diff_htmlizer'
+require 'damagecontrol/publisher/base'
class ProjectController < ApplicationController
# TODO: check if the various SCMs are installed and disable them with a warning if not.
# Each SCM class should have an available? method
- SCMS = [
-# Uncomment this to see Mooky in action in the web interface!
-# RSCM::Mooky,
- RSCM::CVS,
- RSCM::SVN,
- RSCM::StarTeam
- ]
-
- TRACKERS = [
- DamageControl::Tracker::Null,
- DamageControl::Tracker::Bugzilla,
- DamageControl::Tracker::JIRA,
- DamageControl::Tracker::RubyForge,
- DamageControl::Tracker::SourceForge,
- DamageControl::Tracker::Scarab,
- DamageControl::Tracker::Trac
- ]
-
- SCM_WEBS = [
-# SCMWeb::Null.new,
-# SCMWeb::ViewCVS.new,
-# SCMWeb::Fisheye.new
- ]
-
def initialize
super
@navigation_name = "changesets_list"
end
def index
- @projects = DamageControl::Project.find_all
+ @projects = ::DamageControl::Project.find_all
@navigation_name = "null"
end
def new
@project = DamageControl::Project.new
- @scms = SCMS.collect {|o| o.new}
+
+ @scms = RSCM::AbstractSCM.classes.collect {|cls| cls.new}
first_scm = @scms[0]
def first_scm.selected?
true
end
- @trackers = TRACKERS.collect {|o| o.new}
+
+ @trackers = DamageControl::Tracker::Base.classes.collect {|cls| cls.new}
first_tracker = @trackers[0]
def first_tracker.selected?
true
end
+
@edit = true
@new_project = true
render_action("view")
end
@@ -86,42 +66,35 @@
end
index
end
def save
- project = instantiate_from_params("project")
- project.scm = instantiate_from_params("scm")
- project.tracker = instantiate_from_params("tracker")
-
- begin
- Rscm.save_project(project)
- rescue => e
- $stderr.puts(e.backtrace.join("\n"))
- return render_text("Couldn't connect to RSCM server. Please make sure it's running.<br>" + e.message)
- end
+ project = instantiate_from_hash(DamageControl::Project, @params[DamageControl::Project.name])
+ project.scm = find_selected("scms")
+ project.tracker = find_selected("trackers")
+ project.publishers = instantiate_array_from_hashes(@params["publishers"])
+ project.save
+
redirect_to(:action => "view", :id => project.name)
end
- def changesets
+ def changeset
load
- last_changeset_identifier = @params["changeset"]
- @changesets = @project.changesets(last_changeset_identifier.to_identifier, 1)
- @changesets.accept(HtmlDiffVisitor.new(@project))
+ changeset_identifier = @params["changeset"]
+ @changeset = @project.changeset(changeset_identifier.to_identifier)
+ @changeset.accept(HtmlDiffVisitor.new(@project))
end
protected
# Visitor that adds a method called +html_diff+ to each change
class HtmlDiffVisitor
def initialize(project)
@project = project
end
- def visit_changesets(changesets)
- end
-
def visit_changeset(changeset)
@changeset = changeset
end
def visit_change(change)
@@ -171,11 +144,11 @@
# :image => "/images/24x24/box_delete.png",
# :name => "Delete #{@project.name} project"
# }
# end
- if(@project.exists? && @project.scm && !@project.scm.exists? && @project.scm.can_create?)
+ if(@project.exists? && @project.scm && @project.scm.can_create? && !@project.scm.exists?)
@sidebar_links << {
:controller => "scm",
:action => "create",
:id => @project.name,
:image => "/images/24x24/safe_new.png",
@@ -211,11 +184,11 @@
:image => "/images/24x24/garbage.png",
:name => "Delete working copy"
}
end
- if(@project.exists?)
+ if(@project.exists? && @project.tracker)
@sidebar_links << {
:href => @project.tracker.url,
:image => "/images/24x24/scroll_information.png",
:name => @project.tracker.name
}
@@ -248,37 +221,22 @@
scm = @project.scm
def scm.selected?
true
end
+ # Make a dupe of the scm/tracker lists and substitute with project's value
+ @scms = RSCM::AbstractSCM.classes.collect {|cls| $stderr.puts "CLASS: #{cls.name}" ;cls.new}
+ @scms.each_index {|i| @scms[i] = @project.scm if @scms[i].class == @project.scm.class}
tracker = @project.tracker
def tracker.selected?
true
end
-
- # Make a dupe of the scm/tracker lists and substitute with project's value
- @scms = SCMS.collect {|o| o.new}
- @scms.each_index {|i| @scms[i] = @project.scm if @scms[i].class == @project.scm.class}
-
- @trackers = TRACKERS.collect {|o| o.new}
+ @trackers = DamageControl::Tracker::Base.classes.collect {|cls| cls.new}
@trackers.each_index {|i| @trackers[i] = @project.tracker if @trackers[i].class == @project.tracker.class}
@linkable_changesets = @project.changesets(@project.latest_changeset_identifier, 10)
@select_changeset_identifiers = @project.changeset_identifiers[0..-(@linkable_changesets.length+1)]
set_sidebar_links
end
-
- # Instantiates an object from parameters
- def instantiate_from_params(param)
- class_name = @params[param]
- clazz = eval(class_name)
- ob = clazz.new
- attribs = @params[class_name] || {}
- attribs.each do |k,v|
- ob.send("#{k}=", v)
- end
- ob
- end
-
end