プロジェクト

全般

プロフィール

« | » 

リビジョン f0fa005d

高徹 高橋 徹 さんがほぼ11年前に追加

updating for Redmine 3.0(Rails 4.2)

差分を表示:

app/controllers/glossary_controller.rb
def show
set_show_params
@term_categories = TermCategory.find(:all, :conditions => "project_id = #{@project.id}", :order => "position")
@term_categories = TermCategory.where(:project_id => @project.id).order(:position)
respond_to do |format|
format.html { render :template => 'glossary/show.html.erb', :layout => !request.xhr? }
end
end
def new
@term_categories = TermCategory.find(:all, :conditions => "project_id = #{@project.id}", :order => "position")
@term_categories = TermCategory.where(:project_id => @project.id).order(:position)
@term = Term.new(params[:term])
@term.name = CGI::unescapeHTML(params[:new_term_name]) if params[:new_term_name]
@term.project_id = @project.id
......
end
def edit
@term_categories = TermCategory.find(:all, :conditions => "project_id = #{@project.id}", :order => "position")
@term_categories = TermCategory.where(:project_id => @project.id).order(:position)
if request.post? || request.put?
if request.post? || request.put? || request.patch?
@term.attributes = params[:term]
@term.updater_id = User.current.id
if @term.save
......
redirect_to :controller => 'term_categories', :action => 'index', :project_id => @project
end
format.js do
term_categories = TermCategory.find(:all, :conditions => "project_id = #{@project.id}")
term_categories = TermCategory.where(:project_id => @project.id)
render(:update) {|page| page.replace "term_category_id",
content_tag('select', '<option></option>' + options_from_collection_for_select(term_categories, 'id', 'name', @category.id), :id => 'term_category_id', :name => 'term[category_id]')
}
......
def move_all
projs = Project.visible.find(:all)
projs = Project.visible.all
@allowed_projs = projs.find_all {|proj|
User.current.allowed_to?({:controller =>'glossary', :action => 'index'}, proj) and
User.current.allowed_to?({:controller =>'glossary', :action => 'move_all'}, proj) and
......
}
if request.post?
newproj = Project.find(params[:new_project_id])
cats = TermCategory.find(:all, :conditions => "project_id = #{newproj.id}",
:order => "position")
cats = TermCategory.where(:project_id => newproj.id).order(:position)
posbase = (cats.blank?) ? 0 : cats.last.position - 1;
cats = TermCategory.find(:all, :conditions => "project_id = #{@project.id}")
cats = TermCategory.where(:project_id => @project.id)
cats.each {|cat|
cat.project_id = newproj.id
cat.position += cat.position + posbase
cat.save
}
Term::update_all("project_id = #{newproj.id}", "project_id = #{@project.id}")
Term.where(project_id: @project.id).update_all(project_id: newproj.id)
flash[:notice] = l(:notice_successful_update)
redirect_to({:action => 'index', :project_id => newproj})
end
......
#### sort
def sort_terms(terms, prms)
terms.sort! {|a, b|
terms.to_a.sort! {|a, b|
re = nil
prms.each {|prm|
re = Term.compare_by_param(prm, a, b)
......
if (catname == "(#{l(:label_not_categorized)})")
queries << "( category_id IS NULL )"
else
cats = TermCategory.find(:all, :conditions => ["name LIKE :catname",
cats = TermCategory.where(["name LIKE :catname",
{:catname => catname + "%"}])
ary = []
ptn = /^#{Regexp.escape(catname)}\//
......
queries, symbols)
terms = nil
if (queries.empty?)
terms = Term.find(:all)
terms = Term.all
else
query_str = join_queries(queries, "AND")
terms = Term.find(:all, :conditions => [query_str, symbols])
terms = Term.where(query_str, symbols)
end
if (terms and params[:latest_days] and !params[:latest_days].empty?)
limitsec = Time.now.to_i - params[:latest_days].to_i * 60 * 60 * 24
......
end
def find_term
@term = Term.find(:first,
:conditions => "project_id = #{@project.id} and id = #{params[:id]}")
@term = Term.find_by(project_id: @project.id, id: params[:id])
render_404 unless @term
rescue
render_404
app/controllers/glossary_styles_controller.rb
end
else
unless params[:glossary_style_id].blank?
@glossary_style = GlossaryStyle.find(params[:glossary_style_id])
@glossary_style = GlossaryStyle.find_by(params[:glossary_style_id])
end
if (@glossary_style)
app/controllers/term_categories_controller.rb
def index
@categories = TermCategory.find(:all, :conditions => "project_id = #{@project.id}",
:order => "position")
@categories = TermCategory.where(project_id: @project.id).order(:position)
end
def edit
@category = TermCategory.find(:first, :conditions => "project_id = #{@project.id} and id = #{params[:id]}")
@category = TermCategory.find_by(project_id: @project.id, id: params[:id])
if request.put? and @category.update_attributes(params[:category])
flash[:notice] = l(:notice_successful_update)
redirect_to :controller => 'term_categories', :action => 'index', :project_id => @project
......
def change_order
if request.post?
category = TermCategory.find(:first, :conditions => "project_id = #{@project.id} and id = #{params[:id]}")
category = TermCategory.find_by(project_id: @project.id, id: params[:id])
case params[:position]
when 'highest'; category.move_to_top
when 'higher'; category.move_higher
......
end
def destroy
@category = TermCategory.find(:first, :conditions => "project_id = #{@project.id} and id = #{params[:id]}")
@category = TermCategory.find_by(project_id: @project.id, id: params[:id])
@term_count = @category.terms.size
if @term_count == 0
@category.destroy
redirect_to :controller => 'term_categories', :action => 'index', :project_id => @project
elsif params[:todo]
reassign_to = TermCategory.find(:first, :conditions => "project_id = #{@project.id} and id = #{params[:reassign_to_id]}") if params[:todo] == 'reassign'
reassign_to = TermCategory.find_by(project_id: @project.id, id: params[:reassign_to_id]) if params[:todo] == 'reassign'
@category.destroy(reassign_to)
redirect_to :controller => 'term_categories', :action => 'index', :project_id => @project
end
@categories = TermCategory.find(:all, :conditions => "project_id = #{@project.id}") - [@category]
@categories = TermCategory.where(project_id: @project.id) - [@category]
rescue ActiveRecord::RecordNotFound
render_404
end
app/helpers/glossary_port_helper.rb
#name = ic.iconv(name)
name = Redmine::CodesetUtil.to_utf8(name, portinfo.in_encoding)
term = Term.find(:first,
:conditions => ["project_id = #{projid} AND name = :name",
{:name=>name}])
term = Term.find_by(project_id: projid, name: name)
if (term)
portinfo.upterm_num += 1
else
app/helpers/glossary_styles_helper.rb
end
else
if !params[:glossary_style_id].blank?
@glossary_style = GlossaryStyle.find(params[:glossary_style_id])
@glossary_style = GlossaryStyle.find_by(params[:glossary_style_id])
else
@glossary_style= GlossaryStyle.find(:first, :conditions => "user_id = #{User.current.id}")
@glossary_style= GlossaryStyle.find_by(:user_id => User.current.id)
end
end
......
when GlossaryStyle::ProjectMine
ary = User.current.memberships.collect(&:project).compact.uniq
when GlossaryStyle::ProjectAll
ary = Project.visible.find(:all)
ary = Project.visible.all
end
ary.find_all {|proj|
User.current.allowed_to?(authcnd, proj)
......
projs = authorized_projects(projscope, curproj, {:controller => :glossary, :action => :index})
unless (projs.empty?)
querystr = projs.collect {|proj| "project_id = #{proj.id}"}.join(" OR ")
options += break_categories(TermCategory.find(:all, :conditions => querystr)).sort.uniq
options += break_categories(TermCategory.where(querystr)).sort.uniq
end
options << "(#{l(:label_not_categorized)})"
end
app/models/glossary_style.rb
belongs_to :project
attr_accessible :groupby
def grouping?
case groupby
app/models/term.rb
acts_as_attachable
acts_as_searchable :columns => ["#{table_name}.name", "#{table_name}.description"],
:include => [:project]
:project_key => [:project]
acts_as_event :title => Proc.new {|o| "#{l(:glossary_title)} ##{o.id}: #{o.name}" },
:description => Proc.new {|o| "#{o.description}"},
......
:type => 'terms',
:url => Proc.new {|o| {:controller => 'glossary', :action => 'show', :id => o.project, :term_id => o.id} }
attr_accessible :project, :category_id, :author, :name, :name_en, :datatype, :codename, :description,
:rubi, :abbr_whole
def author
author_id ? User.find(:first, :conditions => "users.id = #{author_id}") : nil
author_id ? User.find_by(author_id) : nil
end
def updater
updater_id ? User.find(:first, :conditions => "users.id = #{updater_id}") : nil
updater_id ? User.find_by(updater_id) : nil
end
def project
Project.find(:first, :conditions => "projects.id = #{project_id}")
Project.find_by(project_id)
end
def datetime
......
def self.find_for_macro(tname, proj, all_project = false)
if proj
term = Term.find(:first,
:conditions => "project_id = #{proj.id} and name = '#{tname}'")
term = Term.find_by(:project_id => proj.id, :name => tname)
return term if term
end
return nil unless all_project
app/models/term_category.rb
acts_as_list :scope => :project_id
attr_accessible :name, :project, :position
validates_presence_of :name
validates_uniqueness_of :name, :scope => [:project_id]
app/views/glossary/_sidebar.html.erb
<h3><%= l(:label_term) %></h3>
<%= link_to(l(:label_term_new), {:controller => 'glossary', :action => 'new', :project_id => @project}, :class => 'icon icon-add') %>
<br />
<% if (Term.find(:first, :conditions => "project_id = #{@project.id}")) %>
<% if (Term.find_by(:project_id => @project.id)) %>
<%= link_to_if_authorized(l(:label_move_all_terms), {:controller => 'glossary', :action => 'move_all', :project_id => @project}, :class => 'icon icon-move') %>
<br />
<% end %>
config/routes.rb
if Rails::VERSION::MAJOR < 3
ActionController::Routing::Routes.draw do |map|
map.connect 'glossary_styles/:action', :controller => 'glossary_styles'
map.with_options :controller => 'glossary' do |submap|
submap.connect 'projects/:project_id/glossary', :action => 'index'
submap.connect 'projects/:project_id/glossary/new', :action => 'new'
submap.connect 'projects/:project_id/glossary/:id', :action => 'show', :id => /\d+/
submap.connect 'projects/:project_id/glossary/:action'
submap.connect 'projects/:project_id/glossary/:id/:action', :id => /\d+/
end
map.with_options :controller => 'term_categories' do |submap|
submap.connect 'projects/:project_id/term_categories', :action => 'index'
submap.connect 'projects/:project_id/term_categories/:action'
submap.connect 'projects/:project_id/term_categories/:id/:action', :id => /\d+/
end
end
else
RedmineApp::Application.routes.draw do
match 'glossary_styles/:action', :to => 'glossary_styles', :via => [ :get, :post, :put ]
RedmineApp::Application.routes.draw do
match 'glossary_styles/:action', :to => 'glossary_styles', :via => [ :get, :post, :put, :patch ]
match 'projects/:project_id/glossary', :to => 'glossary#index', :via => [ :get ]
match 'projects/:project_id/glossary/new', :to => 'glossary#new', :via => [ :get ]
match 'projects/:project_id/glossary/edit', :to => 'glossary#edit', :via => [ :get, :post ]
match 'projects/:project_id/glossary/:id/edit', :to => 'glossary#edit', :id => /\d+/, :via => [ :get, :post ]
match 'projects/:project_id/glossary/:id/:action', :to => 'glossary', :id => /\d+/
match 'projects/:project_id/glossary/edit', :to => 'glossary#edit', :via => [ :get, :post, :patch ]
match 'projects/:project_id/glossary/:id/edit', :to => 'glossary#edit', :id => /\d+/, :via => [ :get, :post, :patch ]
match 'projects/:project_id/glossary/:id/:action', :to => 'glossary', :id => /\d+/, :via => :all
match 'projects/:project_id/glossary/:id', :to => 'glossary#show', :id => /\d+/, :via => [ :get ]
match 'projects/:project_id/glossary/destroy', :to => 'glossary#destroy', :via => [ :delete ]
match 'projects/:project_id/glossary/:action', :to => 'glossary'
match 'projects/:project_id/glossary/:action', :to => 'glossary', :via => :all
match 'projects/:project_id/term_categories', :to => 'term_categories#index'
match 'projects/:project_id/term_categories', :to => 'term_categories#index', :via => :all
match 'projects/:project_id/term_categories/destroy', :to => 'term_categories#destroy', :via => [ :delete ]
match 'projects/:project_id/term_categories/change_order', :to => 'term_categories#change_order', :via => [ :post ]
match 'projects/:project_id/term_categories/:action', :to => 'term_categories'
match 'projects/:project_id/term_categories/:id/:action', :to => 'term_categories', :id => /\d+/
end
match 'projects/:project_id/term_categories/:action', :to => 'term_categories', :via => :all
match 'projects/:project_id/term_categories/:id/:action', :to => 'term_categories', :id => /\d+/, :via => :all
end

他の形式にエクスポート: Unified diff