Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redmine2.0 #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Dir[File.expand_path(File.dirname(__FILE__)) + "/lib/tasks/**/*.rake"].sort.each
RedminePluginSupport::Base.setup do |plugin|
plugin.project_name = 'redmine_rate'
plugin.default_task = [:test]
plugin.tasks = [:db, :doc, :release, :clean, :test, :stats, :metrics]
plugin.tasks = [:db, :release, :clean, :test, :stats, :metrics]
plugin.redmine_root = File.expand_path(File.dirname(__FILE__) + '/../../../')
end

Expand All @@ -28,6 +28,8 @@ begin
]
end
Jeweler::GemcutterTasks.new
rescue LoadError
rescue LoadError => e
puts e.message
puts e.backtrace.join("\n")
puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
end
5 changes: 4 additions & 1 deletion app/controllers/rates_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ class RatesController < ApplicationController
helper :users
helper :sort
include SortHelper

before_filter :require_admin
before_filter :require_user_id, :only => [:index, :new]
before_filter :set_back_url
skip_before_filter :verify_authenticity_token

ValidSortOptions = {'date_in_effect' => "#{Rate.table_name}.date_in_effect", 'project_id' => "#{Project.table_name}.name"}

Expand Down Expand Up @@ -54,6 +55,7 @@ def edit
# POST /rates
# POST /rates.xml
def create
logger.info "Create"
@rate = Rate.new(params[:rate])

respond_to do |format|
Expand All @@ -65,6 +67,7 @@ def create
format.xml { render :xml => @rate, :status => :created, :location => @rate }
format.js { render :action => 'create.js.rjs'}
else
logger.error "errors: #{@rate.errors}"
format.html { render :action => "new" }
format.xml { render :xml => @rate.errors, :status => :unprocessable_entity }
format.js {
Expand Down
9 changes: 5 additions & 4 deletions app/helpers/rate_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def rate_sort_link(column, caption, default_order, options = { })
private
# Trunk version of sort_link. Was modified in r2571 of Redmine
def rate_sort_link_trunk_version(column, caption, default_order, options = { })
return caption
css, order = nil, default_order

if column.to_s == @sort_criteria.first_key
Expand Down Expand Up @@ -53,10 +54,10 @@ def rate_sort_link_trunk_version(column, caption, default_order, options = { })
#####


link_to_remote(caption,
{:update => options[:update] || "content", :url => url_options, :method => options[:method] || :post},
{:href => url_for(url_options),
:class => css})
#link_to_remote(caption,
# {:update => options[:update] || "content", :url => url_options, :method => options[:method] || :post},
# {:href => url_for(url_options),
# :class => css})
end

private
Expand Down
4 changes: 2 additions & 2 deletions app/models/rate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Rate < ActiveRecord::Base
unloadable
class InvalidParameterException < Exception; end
CACHING_LOCK_FILE_NAME = 'rate_cache'

belongs_to :project
belongs_to :user
has_many :time_entries
Expand All @@ -18,7 +18,7 @@ class InvalidParameterException < Exception; end
before_destroy :unlocked?
after_destroy :update_time_entry_cost_cache

named_scope :history_for_user, lambda { |user, order|
scope :history_for_user, lambda { |user, order|
{
:conditions => { :user_id => user.id },
:order => order,
Expand Down
5 changes: 3 additions & 2 deletions app/views/rates/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<% form_for(@rate) do |f| %>
<%= form_for(@rate) do |f| %>
<table class="list">
<thead>
<th style="width:15%"><%= l(:label_date) %></th>
Expand All @@ -12,7 +12,8 @@
<%= f.text_field "date_in_effect", :size => 10 %><%= calendar_for('rate_date_in_effect') %>
</td>
<td>
<%= # TODO: move to controller once a hook is in place for the Admin panel

<%= # TODO: move to controller once a hook is in place for the Admin panel
projects = Project.find(:all, :conditions => { :status => Project::STATUS_ACTIVE})

select_tag("rate[project_id]", project_options_for_select_with_selected(projects, @rate.project))
Expand Down
4 changes: 2 additions & 2 deletions app/views/rates/_list.html.erb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<table class="list">
<thead>
<%= rate_sort_header_tag("date_in_effect",
<%= ApplicationController.helpers.rate_sort_header_tag("date_in_effect",
:caption => l(:label_date),
:default_order => 'desc',
:style => "width: 15%",
:method => :get,
:update => "rate_history",
:user_id => @user.id) %>
<%= rate_sort_header_tag("project_id",
<%= ApplicationController.helpers.rate_sort_header_tag("project_id",
:caption => l(:label_project),
:default_order => 'asc',
:method => :get,
Expand Down
3 changes: 1 addition & 2 deletions app/views/rates/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
<h1>Editing rate</h1>

<%= render :partial => 'rates/form' %>
<%= render :partial => 'form' %>
2 changes: 1 addition & 1 deletion app/views/users/_membership_rate.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<em><%= number_to_currency(rate.amount) %></em>
<% end %>

<% remote_form_for(:rate, :url => rates_path(:format => 'js')) do |f| %>
<% form_for(:rate, :url => rates_path(:format => 'js')) do |f| %>

<%= f.text_field :amount %>
<%= f.hidden_field :date_in_effect, :value => Date.today.to_s, :id => "" %>
Expand Down
6 changes: 3 additions & 3 deletions app/views/users/_rates.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<h1><%= l(:rate_label_new_rate) %></h1>
<!-- <h1><%= l(:rate_label_new_rate) %></h1>

<% @rate = Rate.new(:user => @user ) %>
<% @back_url = url_for(:controller => 'users', :action => 'edit', :id => @user, :tab => 'rates') %>
<%= render :partial => 'rates/form' %>

<#%= render :partial => 'rates/form' %>
-->
<div id="rate_history">
<h1><%= l(:rate_label_rate_history) %></h1>
<%# TODO: Refactor out of the view once there is a hook in the controller (Post 0.8.0). %>
Expand Down
13 changes: 10 additions & 3 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
ActionController::Routing::Routes.draw do |map|
map.resources :rates
map.connect 'rate_caches', :conditions => {:method => :put}, :controller => 'rate_caches', :action => 'update'
#ActionController::Routing::Routes.draw do |map|
# map.resources :rates
# map.connect 'rate_caches', :conditions => {:method => :put}, :controller => 'rate_caches', :action => 'update'
#end

#ActionController::Routing::Routes.draw do

RedmineApp::Application.routes.draw do
resources :rates
put 'rate_caches', to: 'rate_caches#update'
end
23 changes: 20 additions & 3 deletions init.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
require 'redmine'

# Patches to the Redmine core
require 'dispatcher'
#require 'dispatcher'

Dispatcher.to_prepare :redmine_rate do

Rails.configuration.to_prepare do
gem 'lockfile'

require_dependency 'application_controller'
Expand All @@ -17,6 +18,22 @@
UsersHelper.send(:include, RateUsersHelperPatch) unless UsersHelper.included_modules.include?(RateUsersHelperPatch)
end



#Dispatcher.to_prepare :redmine_rate do
# gem 'lockfile'

# require_dependency 'application_controller'
# ApplicationController.send(:include, RateHelper)
# ApplicationController.send(:helper, :rate)

# require_dependency 'time_entry'
# TimeEntry.send(:include, RateTimeEntryPatch)

# require_dependency 'users_helper'
# UsersHelper.send(:include, RateUsersHelperPatch) unless UsersHelper.included_modules.include?(RateUsersHelperPatch)
#end

# Hooks
require 'rate_project_hook'
require 'rate_memberships_hook'
Expand All @@ -38,7 +55,7 @@

permission :view_rate, { }

menu :admin_menu, :rate_caches, { :controller => 'rate_caches', :action => 'index'}, :caption => :text_rate_caches_panel
menu :admin_menu, :rate_caches, 'rate_caches', :caption => :text_rate_caches_panel
end

require 'redmine_rate/hooks/timesheet_hook_helper'
Expand Down
35 changes: 24 additions & 11 deletions lib/rate_project_hook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,26 @@ def view_projects_settings_members_table_row(context = { })
}
# Build a form_remote_tag by hand since this isn't in the scope of a controller
# and url_rewriter doesn't like that fact.
form = form_tag(url, :onsubmit => remote_function(:url => url,
:host => Setting.host_name,
:protocol => Setting.protocol,
:form => true,
:method => 'post',
:return => 'false' )+ '; return false;')
form = form_tag(url) #, :onsubmit => remote_function(:url => url,
# :host => Setting.host_name,
# :protocol => Setting.protocol,
# :auth_token_form => context[:auth_token_form],
# :form => true,
# :method => 'post',
# :return => 'false' )+ '; return false;')

form << text_field(:rate, :amount)
form << hidden_field(:rate,:date_in_effect, :value => Date.today.to_s)
form << hidden_field(:rate, :project_id, :value => project.id)
form << hidden_field(:rate, :user_id, :value => member.user.id)
form << hidden_field(:rate, :user_id, :value => member.user.id)
#form << hidden_field(:rate, :authenticity_token, :value => context[:auth_token_form])
form << token_tag(context[:auth_token_form])
form << hidden_field_tag("back_url", url_for(:controller => 'projects', :action => 'settings', :id => project, :tab => 'members', :protocol => Setting.protocol, :host => Setting.host_name))

form << submit_tag(l(:rate_label_set_rate), :class => "small")
form << "</form>"
content << form
form << "</form>".html_safe

content << form.html_safe
end
else
if (User.current.admin?)
Expand All @@ -87,7 +90,7 @@ def view_projects_settings_members_table_row(context = { })
content << content_tag(:strong, number_to_currency(rate.amount))
end
end
return content_tag(:td, content, :align => 'left', :id => "rate_#{project.id}_#{member.user.id}" )
return content_tag(:td, content.html_safe, :align => 'left', :id => "rate_#{project.id}_#{member.user.id}" )
end

def model_project_copy_before_save(context = {})
Expand All @@ -102,5 +105,15 @@ def model_project_copy_before_save(context = {})
destination_rate.save # Need to save here because there is no relation on project to rate
end
end

def remote_function(options)
("$.ajax({url: '#{ url_for(options[:url]) }', type: '#{ options[:method] || 'GET' }', " +
"data: #{ options[:with] ? options[:with] + '&amp;' : '' } + " +
"'authenticity_token=' + encodeURIComponent('#{ options[:auth_token_form] }')" +
(options[:data_type] ? ", dataType: '" + options[:data_type] + "'" : "") +
(options[:success] ? ", success: function(response) {" + options[:success] + "}" : "") +
(options[:before] ? ", beforeSend: function(data) {" + options[:before] + "}" : "") + "});").html_safe
end

end

13 changes: 8 additions & 5 deletions lib/rate_time_entry_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ def self.included(base) # :nodoc:
module ClassMethods
# Updated the cached cost of all TimeEntries for user and project
def update_cost_cache(user, project=nil)
c = ARCondition.new
c << ["#{TimeEntry.table_name}.user_id = ?", user]
c << ["#{TimeEntry.table_name}.project_id = ?", project] if project

TimeEntry.all(:conditions => c.conditions).each do |time_entry|
#c = ARCondition.new
#c << ["#{TimeEntry.table_name}.user_id = ?", user]
#c << ["#{TimeEntry.table_name}.project_id = ?", project] if project
scope = self
scope = scope.scoped(:conditions => ["#{TimeEntry.table_name}.user_id = ?", user])
scope = scope.scoped(:conditions => ["#{TimeEntry.table_name}.project_id = ?", project]) if project

scope.all.each do |time_entry|
time_entry.save_cached_cost
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rate_users_helper_patch.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module RateUsersHelperPatch
module RateUsersHelperPatch
def self.included(base) # :nodoc:
base.send(:include, InstanceMethods)
base.class_eval do
Expand Down
3 changes: 2 additions & 1 deletion lib/redmine_rate/hooks/view_layouts_base_html_head_hook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ module RedmineRate
module Hooks
class ViewLayoutsBaseHtmlHeadHook < Redmine::Hook::ViewListener
def view_layouts_base_html_head(context={})
return content_tag(:style, "#admin-menu a.rate-caches { background-image: url('#{image_path('database_refresh.png', :plugin => 'redmine_rate')}'); }", :type => 'text/css')
#return content_tag(:style, "#admin-menu a.rate-caches { background-image: url('#{image_path('database_refresh.png', :plugin => 'redmine_rate')}'); }", :type => 'text/css')
return content_tag(:style, "#admin-menu a.rate-caches { background-image: url('.'); }", :type => 'text/css')
end
end
end
Expand Down