Skip to content

Commit

Permalink
Merge branch 'context_based'
Browse files Browse the repository at this point in the history
  • Loading branch information
gnn06 committed Dec 10, 2018
2 parents 98e5c14 + 41c33f4 commit 18a0bf7
Show file tree
Hide file tree
Showing 20 changed files with 106 additions and 235 deletions.
23 changes: 0 additions & 23 deletions TODO

This file was deleted.

5 changes: 5 additions & 0 deletions app/controllers/ctrl_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class CtrlController < ApplicationController
def index
@toto = "22"
end
end
30 changes: 0 additions & 30 deletions app/controllers/plan_controller.rb

This file was deleted.

2 changes: 2 additions & 0 deletions app/helpers/ctrl_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module CtrlHelper
end
2 changes: 0 additions & 2 deletions app/helpers/issue_plan_helper.rb

This file was deleted.

2 changes: 0 additions & 2 deletions app/helpers/plan_helper.rb

This file was deleted.

2 changes: 2 additions & 0 deletions app/views/ctrl/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h2>goi2</h2>
<%= @toto %>
2 changes: 0 additions & 2 deletions app/views/plan/index.html.erb

This file was deleted.

89 changes: 0 additions & 89 deletions app/views/plan/show.html.erb

This file was deleted.

1 change: 0 additions & 1 deletion assets/javascripts/plan.js

This file was deleted.

43 changes: 0 additions & 43 deletions assets/stylesheets/plan.css

This file was deleted.

1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# English strings go here for Rails i18n
en:
# my_label: "My label"
depth_filter: "Depth"
4 changes: 4 additions & 0 deletions config/locales/fr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# French strings go here for Rails i18n
fr:
# my_label: "My label"
depth_filter: "Profondeur"
5 changes: 1 addition & 4 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# Plugin's routes
# See: http://guides.rubyonrails.org/routing.html
get 'plan', to: 'plan#index'
get 'plan/:id/new', to: 'plan#new'
get 'issues/:id/plan', to: 'plan#show', as: 'edit_plan'
get 'issues/:id/plan/new', to: 'plan#subtask', as: 'subtask'
get 'actionplan', :to => 'ctrl#index'
16 changes: 4 additions & 12 deletions init.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
#require_dependency 'issue_patch'
require_dependency 'actionplan_hook_listener'
require_dependency 'redmine_depth_issue_filter'

Redmine::Plugin.register :plan do
name 'Plan plugin'
Redmine::Plugin.register :actionplan_redmine_plugin do
name 'Actionplan Redmine Plugin'
author 'Author name'
description 'This is a plugin for Redmine'
version '0.0.1'
url 'http://example.com/path/to/plugin'
author_url 'http://example.com/about'

project_module :plan do
permission :add_subtask, :subtask => :new
end

permission :plan, { :plan => [:index] }, :public => true
menu :project_menu, :plan, { :controller => 'plan', :action => 'index' }, :caption => 'Plan'
end

#logger.debug "goi:init.rb"
62 changes: 62 additions & 0 deletions lib/actionplan_hook_listener.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
require 'byebug'

class ActionplanHookListener < Redmine::Hook::ViewListener
include IssuesHelper
include RoutesHelper
include ContextMenusHelper

def view_issues_context_menu_start(context = {})
issue = context[:issues][0]
attrs = {
:parent_issue_id => issue
}
attrs[:tracker_id] = issue.tracker unless issue.tracker.disabled_core_fields.include?('parent_issue_id')
# create subtask
l1 = link_to("new subtask", new_project_issue_path(issue.project, :issue => attrs, :back_url => project_issues_path(issue.project)))
# byebug
# filter subtasks
# TODO manage saved query
current_filters = context[:request].session[:issue_query][:filters]
query_params = url_filters current_filters
l2 = context_menu_link("filter sustasks", _project_issues_path(@project, { :set_filter => 1,
:f => query_params[:filter] << "parent_id",
:op => query_params[:operator].merge({"parent_id" => "~"}),
:v => query_params[:value].merge({"parent_id" => [issue.id.to_s]}),
:sort => context[:request].session[:issue_query][:sort],
:c => context[:request].session[:issue_query][:column_names],
:group_by => context[:request].session[:issue_query][:group_by]}))
# filter parent task
# TODO manage no grand_parent
direct_parent_id = issue.parent&.parent_id
if direct_parent_id then
l3 = context_menu_link("filter parent tasks", _project_issues_path(@project, { :set_filter => 1,
:f => query_params[:filter] << "parent_id",
:op => query_params[:operator].merge({"parent_id" => "~"}),
:v => query_params[:value].merge({"parent_id" => [direct_parent_id.to_s]}),
:sort => context[:request].session[:issue_query][:sort],
:c => context[:request].session[:issue_query][:column_names],
:group_by => context[:request].session[:issue_query][:group_by]}))
else
l3 = context_menu_link("filter parent tasks", _project_issues_path(@project, { :set_filter => 1,
:f => query_params[:filter].without("parent_id"),
:op => query_params[:operator].without("parent_id"),
:v => query_params[:value].without("parent_id"),
:sort => context[:request].session[:issue_query][:sort],
:c => context[:request].session[:issue_query][:column_names],
:group_by => context[:request].session[:issue_query][:group_by]}))
end
return "<li>" + l1 + "</li>" +
"<li>" + l2 + "</li>" +
"<li>" + l3 + "</li>"
end

def url_filters(filters_hash)
result = { :filter => [], :operator => {}, :value => {}}
filters_hash.each do |key, value|
result[:filter] << key
result[:operator].merge!({ key => value[:operator] })
result[:value].merge!({ key => value[:values] })
end
result
end
end
18 changes: 0 additions & 18 deletions lib/issue_patch.rb.temp

This file was deleted.

24 changes: 24 additions & 0 deletions lib/redmine_depth_issue_filter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module RedmineDepthIssueFilter
module PrependInstanceMethods
def initialize_available_filters
super
add_available_filter "depth", :type => :integer, :label => :depth_filter
end
end

module AddedInstanceMethods
# Wrapper around the +available_filters+ to add a new Deliverable filter
def sql_for_depth_field(field, operator, value)
# TODO manage operator 'entre', 'aucun' et 'tous'
"(select count(*) + 1 from issues as i2 where i2.lft < issues.lft and i2.rgt > issues.rgt) #{operator} #{value.first.to_i}"
end

end

def self.included(base) # :nodoc:
base.send(:include, AddedInstanceMethods)
IssueQuery.prepend(PrependInstanceMethods)
end
end

IssueQuery.send(:include, RedmineDepthIssueFilter)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require File.expand_path('../../test_helper', __FILE__)

class PlanControllerTest < ActionController::TestCase
class CtrlControllerTest < ActionController::TestCase
# Replace this with your real tests.
def test_truth
assert true
Expand Down
8 changes: 0 additions & 8 deletions test/functional/issue_plan_controller_test.rb

This file was deleted.

0 comments on commit 18a0bf7

Please sign in to comment.