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
|
@ -0,0 +1,107 @@
|
|||
# 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 ChecklistsController < ApplicationController
|
||||
unloadable
|
||||
|
||||
before_filter :find_checklist_item, :except => [:index, :create]
|
||||
before_filter :find_issue_by_id, :only => [:index, :create]
|
||||
before_filter :authorize, :except => [:done]
|
||||
helper :issues
|
||||
|
||||
accept_api_auth :index, :update, :destroy, :create, :show
|
||||
|
||||
def index
|
||||
@checklists = @issue.checklists
|
||||
respond_to do |format|
|
||||
format.api
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
respond_to do |format|
|
||||
format.api
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@checklist_item.destroy
|
||||
respond_to do |format|
|
||||
format.api { render_api_ok }
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
@checklist_item = Checklist.new(params[:checklist])
|
||||
@checklist_item.issue = @issue
|
||||
respond_to do |format|
|
||||
format.api {
|
||||
if @checklist_item.save
|
||||
render :action => 'show', :status => :created, :location => checklist_url(@checklist_item)
|
||||
else
|
||||
render_validation_errors(@checklist_item)
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
respond_to do |format|
|
||||
format.api {
|
||||
if @checklist_item.update_attributes(params[:checklist])
|
||||
render_api_ok
|
||||
else
|
||||
render_validation_errors(@checklist_item)
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def done
|
||||
(render_403; return false) unless User.current.allowed_to?(:done_checklists, @checklist_item.issue.project)
|
||||
@checklist_item.is_done = params[:is_done] == 'true'
|
||||
|
||||
if @checklist_item.save
|
||||
if (Setting.issue_done_ratio == "issue_field") && RedmineChecklists.settings["issue_done_ratio"].to_i > 0
|
||||
Checklist.recalc_issue_done_ratio(@checklist_item.issue.id)
|
||||
@checklist_item.issue.reload
|
||||
end
|
||||
end
|
||||
respond_to do |format|
|
||||
format.js
|
||||
format.html { redirect_to :back }
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_issue_by_id
|
||||
@issue = Issue.find(params[:issue_id])
|
||||
@project = @issue.project
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
def find_checklist_item
|
||||
@checklist_item = Checklist.find(params[:id])
|
||||
@project = @checklist_item.issue.project
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
end
|
58
plugins/redmine_checklists/app/helpers/checklists_helper.rb
Normal file
58
plugins/redmine_checklists/app/helpers/checklists_helper.rb
Normal file
|
@ -0,0 +1,58 @@
|
|||
# encoding: utf-8
|
||||
#
|
||||
# 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/>.
|
||||
|
||||
module ChecklistsHelper
|
||||
|
||||
def link_to_remove_checklist_fields(name, f, options={})
|
||||
f.hidden_field(:_destroy) + link_to(name, "javascript:void(0)", options)
|
||||
end
|
||||
|
||||
def new_object(f, association)
|
||||
@new_object ||= f.object.class.reflect_on_association(association).klass.new
|
||||
end
|
||||
|
||||
def fields(f, association)
|
||||
@fields ||= f.fields_for(association, new_object(f, association), :child_index => "new_#{association}") do |builder|
|
||||
render(association.to_s.singularize + "_fields", :f => builder)
|
||||
end
|
||||
end
|
||||
|
||||
def new_or_show(f)
|
||||
if f.object.new_record?
|
||||
if f.object.subject.present?
|
||||
"show"
|
||||
else
|
||||
"new"
|
||||
end
|
||||
else
|
||||
"show"
|
||||
end
|
||||
end
|
||||
|
||||
def done_css(f)
|
||||
if f.object.is_done
|
||||
"is-done-checklist-item"
|
||||
else
|
||||
""
|
||||
end
|
||||
end
|
||||
|
||||
end
|
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
|
|
@ -0,0 +1,8 @@
|
|||
<li id="checklist_item_<%= checklist_item.id %>" <%= "class=is-done-checklist-item" if checklist_item.is_done %> >
|
||||
<%= check_box_tag 'checklist_item', "", checklist_item.is_done,
|
||||
:disabled => !User.current.allowed_to?(:done_checklists, checklist_item.issue.project) && !User.current.allowed_to?(:edit_checklists, checklist_item.issue.project),
|
||||
:data_url => url_for( {:controller => "checklists", :action => "done", :id => checklist_item.id} ), :class => 'checklist-checkbox'
|
||||
%>
|
||||
<%= textilizable(checklist_item, :subject).gsub(/<\/?(p|h\d+|li|ul)>/, '').strip.html_safe %>
|
||||
|
||||
</li>
|
|
@ -0,0 +1,4 @@
|
|||
$("#checklist_item_<%= @checklist_item.id %>").toggleClass('is-done-checklist-item');
|
||||
$('#checklist_form .checklist-item#<%= @checklist_item.id %> input[type=checkbox]').trigger('click');
|
||||
$('.issue .attributes table.progress').parent().html('<%= j(progress_bar(@checklist_item.issue.done_ratio, :width => '80px', :legend => "#{@checklist_item.issue.done_ratio}%")) %>');
|
||||
$('#issue_done_ratio').val('<%= @checklist_item.issue.done_ratio %>');
|
|
@ -0,0 +1,14 @@
|
|||
api.array :checklists, api_meta(:total_count => @checklists.size) do
|
||||
@checklists.each do |checklist|
|
||||
api.checklist do
|
||||
api.id checklist.id
|
||||
api.issue_id checklist.issue_id
|
||||
api.subject checklist.subject
|
||||
api.is_done checklist.is_done
|
||||
api.position checklist.position
|
||||
|
||||
api.created_at checklist.created_at
|
||||
api.updated_at checklist.updated_at
|
||||
end
|
||||
end
|
||||
end
|
10
plugins/redmine_checklists/app/views/checklists/show.api.rsb
Normal file
10
plugins/redmine_checklists/app/views/checklists/show.api.rsb
Normal file
|
@ -0,0 +1,10 @@
|
|||
api.checklist do
|
||||
api.id @checklist_item.id
|
||||
api.issue_id @checklist_item.issue_id
|
||||
api.subject @checklist_item.subject
|
||||
api.is_done @checklist_item.is_done
|
||||
api.position @checklist_item.position
|
||||
|
||||
api.created_at @checklist_item.created_at
|
||||
api.updated_at @checklist_item.updated_at
|
||||
end
|
|
@ -0,0 +1,16 @@
|
|||
<% if !@issue.blank? && @issue.checklists.any? && User.current.allowed_to?(:view_checklists, @project) %>
|
||||
<hr />
|
||||
<div id="checklist">
|
||||
|
||||
<p><strong><%=l(:label_checklist_plural)%></strong></p>
|
||||
|
||||
<ul id="checklist_items">
|
||||
<% @issue.checklists.each do |checklist_item| %>
|
||||
<%= render :partial => 'checklists/checklist_item', :object => checklist_item %>
|
||||
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
||||
<% end %>
|
|
@ -0,0 +1,21 @@
|
|||
<span class="checklist-item <%= new_or_show(f) %>" id = "<%=f.object.id%>">
|
||||
<span class = "checklist-show-only checklist-checkbox"><%= f.check_box :is_done %></span>
|
||||
<span class = "checklist-show checklist-subject <%= done_css(f) %>">
|
||||
<%= f.object.subject %>
|
||||
</span>
|
||||
<span class = "checklist-edit checklist-new checklist-edit-box">
|
||||
<%= text_field_tag nil, f.object.subject, :class => 'edit-box'%>
|
||||
<%= f.hidden_field :subject, :class => 'checklist-subject-hidden' %>
|
||||
</span>
|
||||
<span class= "checklist-edit-only checklist-edit-save-button"><%= submit_tag l(:button_save), :type => "button", :class => "item item-save small"%> </span>
|
||||
<span class= "checklist-edit-only checklist-edit-reset-button"><% concat l(:button_cancel)
|
||||
%> </span>
|
||||
<span class = "checklist-show-only checklist-remove"><%= link_to_remove_checklist_fields "", f,
|
||||
:class => "icon icon-del" %></span>
|
||||
<%= f.hidden_field :position, :class => 'checklist-item-position' %>
|
||||
<%= f.hidden_field :id, :class => 'checklist-item-id' %>
|
||||
<span class = "icon icon-add checklist-new-only save-new-by-button"></span>
|
||||
|
||||
<br>
|
||||
</span>
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
<% if User.current.allowed_to?(:edit_checklists, @project, :global => true) %>
|
||||
<div class="tabular">
|
||||
<p id="checklist_form">
|
||||
<label><%=l(:label_checklist_plural)%></label>
|
||||
<% @issue.checklists.build if @issue.checklists.blank? || @issue.checklists.last.subject.present? %>
|
||||
<%= fields_for :issue, issue do |f| -%>
|
||||
<span id="checklist_form_items" data-checklist-fields='<%= fields(f, :checklists) %>'>
|
||||
<%= f.fields_for :checklists do |builder| %>
|
||||
<%= render :partial => 'checklist_fields', :locals => {:f => builder, :checklist => @checklist} %>
|
||||
<% end %>
|
||||
</span>
|
||||
<% end %>
|
||||
</p>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<%= javascript_tag do %>
|
||||
<% unless User.current.allowed_to?(:done_checklists, @project) %>
|
||||
$("#checklist_items input").attr("disabled", true);
|
||||
<% end %>
|
||||
|
||||
$("span#checklist_form_items").checklist();
|
||||
$("#checklist_items").checklist();
|
||||
<% end %>
|
|
@ -0,0 +1,8 @@
|
|||
<% checklist_tabs = [
|
||||
{:name => 'general', :partial => 'settings/checklists/general', :label => :label_general}]
|
||||
|
||||
%>
|
||||
|
||||
<%= render_tabs checklist_tabs %>
|
||||
|
||||
<% html_title(l(:label_settings), l(:label_checklists)) -%>
|
|
@ -0,0 +1,7 @@
|
|||
<% if Setting.issue_done_ratio == "issue_field" %>
|
||||
<p>
|
||||
<label for="settings_issue_done_ratio"><%= l(:label_checklist_done_ratio) %></label>
|
||||
<%= hidden_field_tag 'settings[issue_done_ratio]', 0, :id => nil %>
|
||||
<%= check_box_tag 'settings[issue_done_ratio]', 1, @settings["issue_done_ratio"].to_i > 0 %>
|
||||
</p>
|
||||
<% end %>
|
Loading…
Add table
Add a link
Reference in a new issue