Actualizar plugin Glossary a 1.1.0

This commit is contained in:
Manuel Cillero 2020-11-22 21:35:04 +01:00
parent 24560c8598
commit b9e569d03f
103 changed files with 954 additions and 2967 deletions

View file

@ -0,0 +1,9 @@
class GlossaryCategory < ActiveRecord::Base
has_many :terms, class_name: 'GlossaryTerm', foreign_key: 'category_id'
belongs_to :project
acts_as_positioned
scope :sorted, lambda { order(:position) }
end

View file

@ -1,52 +0,0 @@
class GlossaryStyle < ActiveRecord::Base
unloadable
GroupByNone = 0
GroupByCategory = 1
GroupByProject = 2
ProjectCurrent = 0
ProjectMine = 1
ProjectAll = 2
belongs_to :project
attr_accessible :groupby
def grouping?
case groupby
when GroupByCategory
return true
when GroupByProject
return (project_scope != ProjectCurrent)
end
return false
end
def set_default!
self['show_desc'] = false
self['groupby'] = 1
self['project_scope'] = 0
self['sort_item_0'] = ''
self['sort_item_1'] = ''
self['sort_item_2'] = ''
end
def sort_params
ary = []
for cnt in 0...3
prm = self["sort_item_#{cnt}"]
if (prm and !prm.empty?)
case prm
when 'project'
next if (groupby == GroupByProject or project_scope == ProjectCurrent)
when 'category'
next if (groupby == GroupByCategory)
end
ary << prm
end
end
ary.uniq
end
end

View file

@ -0,0 +1,59 @@
require 'csv'
class GlossaryTerm < ActiveRecord::Base
belongs_to :category, class_name: 'GlossaryCategory', foreign_key: 'category_id'
belongs_to :project
belongs_to :author, class_name: 'User', foreign_key: 'author_id'
belongs_to :updater, class_name: 'User', foreign_key: 'updater_id'
# class method from Redmine::Acts::Attachable::ClassMethods
acts_as_attachable view_permission: :view_glossary_terms, edit_permission: :manage_glossary_terms,
delete_permission: :manage_glossary_terms
acts_as_event datetime: :updated_at,
description: :description,
author: nil,
title: Proc.new {|o| "#{l(:glossary_title)} ##{o.id} - #{o.name}" },
url: Proc.new {|o| { controller: 'glossary_terms',
action: 'show',
id: o.id,
project_id: o.project }
}
acts_as_searchable columns: [ "#{table_name}.name", "#{table_name}.description", "#{table_name}.rubi"],
preload: [:project ],
date_column: "#{table_name}.created_at",
scope: joins(:project),
permission: :view_glossary_terms
acts_as_activity_provider scope: joins(:project),
type: 'glossary_terms',
permission: :view_glossary_terms,
timestamp: :updated_at
scope :search_by_name, -> (keyword) {
where 'name like ?', "#{sanitize_sql_like(keyword)}%"
}
scope :search_by_rubi, -> (keyword) {
where 'rubi like ?', "#{sanitize_sql_like(keyword)}%"
}
def self.csv_attributes
["name", "name_en", "datatype", "codename", "description", "rubi", "abbr_whole"]
end
def self.import(file, project)
CSV.foreach(file.path, headers: true, encoding: "CP932:UTF-8" ) do |row|
term = new
term.attributes = row.to_hash.slice(*csv_attributes)
term.project = project
unless row["category"].blank?
term.category = GlossaryCategory.find_by(name: row["category"]) ||
GlossaryCategory.create(name: row["category"], project: project)
end
term.save!
end
end
end

View file

@ -1,149 +0,0 @@
class Term < ActiveRecord::Base
unloadable
belongs_to :category, :class_name => 'TermCategory', :foreign_key => 'category_id'
belongs_to :project
belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
validates_presence_of :name, :project
validates_length_of :name, :maximum => 255
acts_as_attachable
acts_as_searchable :columns => ["#{table_name}.name", "#{table_name}.description"],
:project_key => [:project]
acts_as_event :title => Proc.new {|o| "#{l(:glossary_title)} ##{o.id}: #{o.name}" },
:description => Proc.new {|o| "#{o.description}"},
:datetime => :created_on,
:type => 'terms',
:url => Proc.new {|o| {:controller => 'glossary', :action => 'show', :id => o.project, :term_id => o.id} }
attr_accessible :project_id, :category_id, :author, :name, :name_en, :datatype, :codename, :description,
:rubi, :abbr_whole
def author
author_id ? User.find_by_id(author_id) : nil
end
def updater
updater_id ? User.find_by_id(updater_id) : nil
end
def project
Project.find_by_id(project_id)
end
def datetime
(self[:created_on] != self[:updated_on]) ? self[:updated_on] : self[:created_on]
end
def value(prmname)
case prmname
when 'project'
(project) ? project.name : ""
when 'category'
(category) ? category : ""
when 'datetime'
datetime
else
self[prmname]
end
end
def param_to_s(prmname)
if (prmname == 'created_on' or prmname == 'updated_on')
format_time(self[prmname])
else
value(prmname).to_s
end
end
def <=>(term)
id <=> term.id
end
def self.compare_safe(a, b, &blk)
if (!a and !b)
return 0
elsif (!a or !b)
return -1 if a
return 1 if b
end
yield(a,b)
end
def self.compare_by_param(prm, a, b)
case prm
when 'project'
a.project.identifier <=> b.project.identifier
when 'category'
self.compare_safe(a.category, b.category) {|acat, bcat|
acat.position <=> bcat.position
}
when 'datetime'
self.compare_safe(a.value(prm), b.value(prm)) {|aval, bval|
(aval <=> bval) * -1
}
when 'name'
((a.rubi.empty?) ? a.name : a.rubi) <=> ((b.rubi.empty?) ? b.name : b.rubi)
else
self.compare_safe(a.value(prm), b.value(prm)) {|aval, bval|
aval <=> bval
}
end
end
def to_s
"##{id}: #{name}"
end
def self.find_for_macro(tname, proj, all_project = false)
if proj
term = Term.find_by(:project_id => proj.id, :name => tname)
return term if term
end
return nil unless all_project
return self.find_by_name(tname)
end
def self.default_show_params
['name_en', 'rubi', 'abbr_whole', 'datatype', 'codename', 'project', 'category']
end
def self.default_searched_params
['name', 'name_en', 'abbr_whole', 'datatype', 'codename', 'description']
end
def self.default_sort_params
['id', 'name', 'name_en', 'abbr_whole', 'datatype', 'codename', 'project', 'category',
'datetime']
end
def self.hidable_params
['name_en', 'rubi', 'abbr_whole', 'datatype', 'codename']
end
def self.setting_params
['name_en', 'rubi', 'abbr_whole', 'datatype', 'codename']
end
def self.export_params
['id','project',
'name', 'name_en', 'rubi', 'abbr_whole', 'category', 'datatype', 'codename',
'author', 'updater', 'created_on', 'updated_on',
'description']
end
def self.import_params
['name', 'name_en', 'rubi', 'abbr_whole', 'category', 'datatype', 'codename',
'description']
end
end

View file

@ -1,29 +0,0 @@
class TermCategory < ActiveRecord::Base
belongs_to :project
has_many :terms, :foreign_key => 'category_id', :dependent => :nullify
acts_as_list :scope => :project_id
attr_accessible :name, :project_id, :position
validates_presence_of :name
validates_uniqueness_of :name, :scope => [:project_id]
alias :destroy_without_reassign :destroy
# Destroy the category
# If a category is specified, terms are reassigned to this category
def destroy(reassign_to = nil)
if reassign_to && reassign_to.is_a?(TermCategory) && reassign_to.project == self.project
Term.update_all("category_id = #{reassign_to.id}", "category_id = #{id}")
end
destroy_without_reassign
end
def <=>(category)
position <=> category.position
end
def to_s; name end
end