Nuevo plugin Redmine Glossary 0.9.2

This commit is contained in:
Manuel Cillero 2019-01-29 19:42:59 +01:00
parent 5d298a7529
commit 693eb3ee50
72 changed files with 2962 additions and 0 deletions

View file

@ -0,0 +1,73 @@
require 'glossary_import_info'
module GlossaryHelper
def label_param(prmname)
case prmname
when 'id'
'#'
when 'project'
I18n.t(:label_project)
when 'category'
I18n.t(:field_category)
when 'datetime'
I18n.t(:field_updated_on)
when 'author'
I18n.t(:field_author)
when 'updater'
I18n.t(:label_updater)
when 'created_on'
I18n.t(:field_created_on)
when 'updated_on'
I18n.t(:field_updated_on)
when 'description'
I18n.t(:field_description)
else
I18n.t("label.#{prmname}")
end
end
def param_visible?(prmname)
!Setting.plugin_redmine_glossary["hide_item_#{prmname}"]
end
def collect_visible_params(prmary)
ary = []
prmary {|prm|
ary << prm if param_visible?(prm)
}
end
def default_show_params; Term.default_show_params; end
def default_searched_params; Term.default_searched_params; end
def default_sort_params; Term.default_sort_params; end
def params_select(form, name, prms)
options = prms.collect{|prm| [label_param(prm), prm]}
form.select(name, options, :include_blank=>true)
end
def params_select_tag(name, prms, defaultprm)
options = [""]
options += prms.collect{|prm| [label_param(prm), prm]}
select_tag(name, options_from_collection_for_select(options), defaultprm)
end
# extract tokens from the question
# eg. hello "bye bye" => ["hello", "bye bye"]
def tokenize_by_space(str)
str.scan(%r{((\s|^)"[\s\w]+"(\s|$)|\S+)}).collect {|m|
m.first.gsub(%r{(^\s*"\s*|\s*"\s*$)}, '')
}
end
def updated_by(updated, author)
l(:label_updated_time_by, :author => link_to_user(author), :age => time_tag(updated)).html_safe
end
end

View file

@ -0,0 +1,99 @@
module GlossaryPortHelper
#def glossary_csvout(csv, ic, ary)
def glossary_csvout(csv, ary)
csv << ary.collect {|c|
begin
#ic.iconv(c.to_s)
Redmine::CodesetUtil.from_utf8(c.to_s, l(:general_csv_encoding))
rescue
c.to_s
end
}
end
def glossary_to_csv(terms)
#ic = Iconv.new(l(:general_csv_encoding), 'UTF-8')
export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv|
# csv header fields
headers = Term.export_params.collect {|prm|
label_param(prm)
}
#glossary_csvout(csv, ic, headers)
glossary_csvout(csv, headers)
# csv lines
terms.each do |term|
fields = Term.export_params.collect {|prm|
term.param_to_s(prm)
}
#glossary_csvout(csv, ic, fields)
glossary_csvout(csv, fields)
end
end
export
end
def glossary_from_csv(portinfo, projid)
line_count = 0
begin
#ic = Iconv.new('UTF-8', portinfo.in_encoding)
raise l(:error_file_none) if (!portinfo.import_file)
FCSV::parse(portinfo.import_file.read) { |row|
line_count += 1
next if (portinfo.is_first_comment and line_count == 1)
next if (row.empty?)
name = row[portinfo.param_col('name')]
raise sprintf(l(:error_no_name), t("label.name")) unless name
#name = ic.iconv(name)
name = Redmine::CodesetUtil.to_utf8(name, portinfo.in_encoding)
term = Term.find_by(project_id: projid, name: name)
if (term)
portinfo.upterm_num += 1
else
term = Term.new(:name => name, :project_id => projid)
portinfo.newterm_num += 1
end
for col in 0 ... row.size
prm = portinfo.col_param(col)
next unless prm
#val = ic.iconv(row[col].to_s)
val = Redmine::CodesetUtil.to_utf8(row[col].to_s, portinfo.in_encoding)
case prm
when 'name'
when 'category'
unless val.empty? then
cat = TermCategory.find_by_name(val)
unless (cat)
cat = TermCategory.new(:name => val, :project_id => projid)
unless (cat.save)
raise l(:error_create_term_category)
end
portinfo.cat_num += 1
end
term['category_id'] = cat.id
end
else
term[prm] = val
end
end
unless (term.save)
raise l(:error_create_term)
end
}
rescue => evar
portinfo.err_string = evar.to_s
if (0 < line_count)
portinfo.err_string += sprintf(l(:error_csv_import_row), line_count)
end
end
end
end

View file

@ -0,0 +1,107 @@
module GlossaryStylesHelper
def retrieve_glossary_style
if (User.current.anonymous?)
if (session[:glossary_style])
@glossary_style = GlossaryStyle.new(session[:glossary_style])
end
else
if !params[:glossary_style_id].blank?
@glossary_style = GlossaryStyle.find_by(params[:glossary_style_id])
else
@glossary_style= GlossaryStyle.find_by(:user_id => User.current.id)
end
end
unless (@glossary_style)
@glossary_style = GlossaryStyle.new(:groupby => GlossaryStyle::GroupByCategory)
@glossary_style.user_id = User.current.id
end
end
def search_index_table(ary, sepcnt, proj, search_index_type = nil)
return "" if (!ary.is_a?(Array) or sepcnt <= 0)
str = '<table><tr>'
cnt = 0
for ch in ary
str += '</tr><tr>' if ((cnt != 0) and (cnt % sepcnt) == 0 )
cnt += 1
str += '<td>'
if (ch and !ch.empty?)
prms = {:controller => 'glossary', :action => 'index', :project_id => proj,
:search_index_ch => ch}
prms[:search_index_type] = search_index_type if (search_index_type)
str += link_to(ch, prms)
end
str += '</td>'
end
str += '</tr></table>'
str.html_safe
end
def search_params
[:search_str, :search_category, :latest_days]
end
def search_params_all
search_params + [:search_index_ch, :search_index_type]
end
def add_search_params(prms)
search_params_all.each {|prm|
prms[prm] = params[prm] if (params[prm] and !params[prm].empty?)
}
end
def glossary_searching?
search_params.each {|prm|
return true if (params[prm] and !params[prm].empty?)
}
return false
end
def authorized_projects(projscope, curproj, authcnd)
ary = []
case projscope
when GlossaryStyle::ProjectCurrent
return [curproj]
when GlossaryStyle::ProjectMine
ary = User.current.memberships.collect(&:project).compact.uniq
when GlossaryStyle::ProjectAll
ary = Project.visible.all
end
ary.find_all {|proj|
User.current.allowed_to?(authcnd, proj)
}
end
def break_categories(cats)
catstrs = []
cats.each {|cat|
catstrs << cat.name
if (cat.name.include?('/'))
str = cat.name
while (str =~ /^(.+)\/[^\/]+$/)
str = $1
catstrs << str
end
end
}
catstrs
end
def seach_category_options(projscope, curproj)
options = [""]
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.where(querystr)).sort.uniq
end
options << "(#{l(:label_not_categorized)})"
end
end

View file

@ -0,0 +1,2 @@
module TermCategoriesHelper
end