Nuevo plugin Redmine Checklist 3.1.10 light
This commit is contained in:
parent
294bc87e76
commit
ef5521e0a2
65 changed files with 3544 additions and 0 deletions
92
plugins/redmine_checklists/app/models/checklist.rb
Normal file
92
plugins/redmine_checklists/app/models/checklist.rb
Normal file
|
@ -0,0 +1,92 @@
|
|||
# This file is a part of Redmine Checklists (redmine_checklists) plugin,
|
||||
# issue checklists management plugin for Redmine
|
||||
#
|
||||
# Copyright (C) 2011-2017 RedmineUP
|
||||
# http://www.redmineup.com/
|
||||
#
|
||||
# redmine_checklists is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# redmine_checklists is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with redmine_checklists. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
class Checklist < ActiveRecord::Base
|
||||
unloadable
|
||||
include Redmine::SafeAttributes
|
||||
belongs_to :issue
|
||||
belongs_to :author, :class_name => "User", :foreign_key => "author_id"
|
||||
has_one :comment, :as => :commented, :dependent => :delete
|
||||
if ActiveRecord::VERSION::MAJOR >= 4
|
||||
attr_protected :id
|
||||
end
|
||||
acts_as_event :datetime => :created_at,
|
||||
:url => Proc.new {|o| {:controller => 'issues', :action => 'show', :id => o.issue_id}},
|
||||
:type => 'issue issue-closed',
|
||||
:title => Proc.new {|o| o.subject },
|
||||
:description => Proc.new {|o| "#{l(:field_issue)}: #{o.issue.subject}" }
|
||||
|
||||
|
||||
if ActiveRecord::VERSION::MAJOR >= 4
|
||||
acts_as_activity_provider :type => "checklists",
|
||||
:permission => :view_checklists,
|
||||
:scope => preload({:issue => :project})
|
||||
acts_as_searchable :columns => ["#{table_name}.subject"],
|
||||
:scope => lambda { includes([:issue => :project]).order("#{table_name}.id") },
|
||||
:project_key => "#{Issue.table_name}.project_id"
|
||||
|
||||
else
|
||||
acts_as_activity_provider :type => "checklists",
|
||||
:permission => :view_checklists,
|
||||
:find_options => {:issue => :project}
|
||||
acts_as_searchable :columns => ["#{table_name}.subject"],
|
||||
:include => [:issue => :project],
|
||||
:project_key => "#{Issue.table_name}.project_id",
|
||||
:order_column => "#{table_name}.id"
|
||||
end
|
||||
|
||||
acts_as_list
|
||||
|
||||
validates_presence_of :subject
|
||||
validates_length_of :subject, :maximum => 512
|
||||
validates_presence_of :position
|
||||
validates_numericality_of :position
|
||||
|
||||
def self.recalc_issue_done_ratio(issue_id)
|
||||
issue = Issue.find(issue_id)
|
||||
return false if (Setting.issue_done_ratio != "issue_field") || RedmineChecklists.settings["issue_done_ratio"].to_i < 1 || issue.checklists.empty?
|
||||
done_checklist = issue.checklists.map{|c| c.is_done ? 1 : 0}
|
||||
done_ratio = (done_checklist.count(1) * 10) / done_checklist.count * 10
|
||||
issue.update_attribute(:done_ratio, done_ratio)
|
||||
end
|
||||
|
||||
def self.old_format?(detail)
|
||||
(detail.old_value.is_a?(String) && detail.old_value.match(/^\[[ |x]\] .+$/).present?) ||
|
||||
(detail.value.is_a?(String) && detail.value.match(/^\[[ |x]\] .+$/).present?)
|
||||
end
|
||||
|
||||
safe_attributes 'subject', 'position', 'issue_id', 'is_done'
|
||||
|
||||
def editable_by?(usr = User.current)
|
||||
usr && (usr.allowed_to?(:edit_checklists, project) || (author == usr && usr.allowed_to?(:edit_own_checklists, project)))
|
||||
end
|
||||
|
||||
def project
|
||||
issue.project if issue
|
||||
end
|
||||
|
||||
def info
|
||||
"[#{is_done ? 'x' : ' '}] #{subject.strip}"
|
||||
end
|
||||
|
||||
def add_to_list_bottom
|
||||
return unless issue.checklists.select(&:persisted?).map(&:position).include?(self[position_column])
|
||||
self[position_column] = bottom_position_in_list.to_i + 1
|
||||
end
|
||||
end
|
|
@ -0,0 +1,130 @@
|
|||
# This file is a part of Redmine Checklists (redmine_checklists) plugin,
|
||||
# issue checklists management plugin for Redmine
|
||||
#
|
||||
# Copyright (C) 2011-2017 RedmineUP
|
||||
# http://www.redmineup.com/
|
||||
#
|
||||
# redmine_checklists is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# redmine_checklists is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with redmine_checklists. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
class JournalChecklistHistory
|
||||
def self.can_fixup?(journal_details)
|
||||
unless journal_details.journal
|
||||
return false
|
||||
end
|
||||
issue = journal_details.journal.journalized
|
||||
unless issue.is_a?(Issue)
|
||||
return false
|
||||
end
|
||||
prev_journal_scope = issue.journals.order('id DESC')
|
||||
prev_journal_scope = prev_journal_scope.where('id <> ?', journal_details.journal_id) if journal_details.journal_id
|
||||
prev_journal = prev_journal_scope.first
|
||||
unless prev_journal
|
||||
return false
|
||||
end
|
||||
|
||||
return false if Time.zone.now > prev_journal.created_on + 1.minute
|
||||
|
||||
prev_journal.details.all?{ |x| x.prop_key == 'checklist'} &&
|
||||
journal_details.journal.details.all?{ |x| x.prop_key == 'checklist'} &&
|
||||
journal_details.journal.notes.blank? &&
|
||||
prev_journal.notes.blank? &&
|
||||
prev_journal.details.select{ |x| x.prop_key == 'checklist' }.size == 1
|
||||
end
|
||||
|
||||
def self.fixup(journal_details)
|
||||
issue = journal_details.journal.journalized
|
||||
prev_journal_scope = issue.journals.order('id DESC')
|
||||
prev_journal_scope = prev_journal_scope.where('id <> ?', journal_details.journal_id) if journal_details.journal_id
|
||||
prev_journal = prev_journal_scope.first
|
||||
checklist_details = prev_journal.details.find{ |x| x.prop_key == 'checklist'}
|
||||
if new(checklist_details.old_value, journal_details.value).empty_diff?
|
||||
prev_journal.destroy
|
||||
else
|
||||
checklist_details.update_attribute(:value, journal_details.value)
|
||||
journal_details.journal.destroy unless journal_details.journal.new_record? && journal_details.journal.details.any?{ |x| x.prop_key != 'checklist'}
|
||||
end
|
||||
end
|
||||
|
||||
def initialize(was, become)
|
||||
@was = force_object(was)
|
||||
@become = force_object(become)
|
||||
@was_ids = @was.map(&:id)
|
||||
@become_ids = @become.map(&:id)
|
||||
@both_ids = @become_ids & @was_ids
|
||||
end
|
||||
|
||||
def diff
|
||||
{
|
||||
:undone => undone,
|
||||
:done => done
|
||||
}
|
||||
end
|
||||
|
||||
def empty_diff?
|
||||
diff.all?{ |_,v| v.empty? }
|
||||
end
|
||||
|
||||
def journal_details(opts = {})
|
||||
JournalDetail.new(opts.merge({
|
||||
:property => 'attr',
|
||||
:prop_key => 'checklist',
|
||||
:old_value => @was.map(&:to_h).to_json,
|
||||
:value => @become.map(&:to_h).to_json
|
||||
}))
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def undone
|
||||
@both_ids.map do |id|
|
||||
was_is_done = was_by_id(id).is_done
|
||||
become_is_done = become_by_id(id).is_done
|
||||
if was_is_done != become_is_done && was_is_done
|
||||
become_by_id(id)
|
||||
else
|
||||
nil
|
||||
end
|
||||
end.compact
|
||||
end
|
||||
|
||||
def done
|
||||
@both_ids.map do |id|
|
||||
was_is_done = was_by_id(id).is_done
|
||||
become_is_done = become_by_id(id).is_done
|
||||
if was_is_done != become_is_done && become_is_done
|
||||
become_by_id(id)
|
||||
else
|
||||
nil
|
||||
end
|
||||
end.compact
|
||||
end
|
||||
|
||||
def was_by_id(id)
|
||||
@was.find{ |x| x.id == id }
|
||||
end
|
||||
|
||||
def become_by_id(id)
|
||||
@become.find{ |x| x.id == id }
|
||||
end
|
||||
|
||||
def force_object(unk)
|
||||
if unk.is_a?(String)
|
||||
json = JSON.parse(unk)
|
||||
json = [json] unless json.is_a?(Array)
|
||||
json.map{ |x| OpenStruct2.new(x.has_key?('checklist') ? x['checklist'] : x) }
|
||||
else
|
||||
unk.map{ |x| OpenStruct2.new(x.attributes) }
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue