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

add sorting users and seassign ticket by drag and drop and overview for admin #3

Open
wants to merge 1 commit 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
63 changes: 52 additions & 11 deletions app/controllers/stuff_to_do_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,54 @@ class StuffToDoController < ApplicationController
unloadable

before_filter :get_user
before_filter :get_time_grid, :only => [:index, :time_grid]
before_filter :get_time_grid, :only => [:index, :time_grid, :overview]
before_filter :require_admin, :only => :available_issues
helper :stuff_to_do
helper :timelog



def overview
@doing_now = StuffToDo.doing_now(@user)
@recommended = StuffToDo.recommended(@user)
@available = StuffToDo.available(@user, default_filters )

@users = User.active
@filters = filters_for_view
@selected_users = SortUser.sort_users( @user, (params[:users].blank? ? @users : User.find(params[:users])) )
if User.current.admin?
render :action => :overview
else
render :action => :index
end
end

def index
@doing_now = StuffToDo.doing_now(@user)
@recommended = StuffToDo.recommended(@user)
@available = StuffToDo.available(@user, default_filters )

@users = User.active
@filters = filters_for_view
@selected_users = params[:users].blank? ? @users : User.find(params[:users])
end

def reorder
if !params[:owner_id].blank? && !params[:stuff].blank?
params[:stuff].each do |stuff_id|
if @stuff = StuffToDo.all(
:conditions =>
["user_id not in (?) and stuff_id = ? and stuff_type = 'Issue' ", @user.id, stuff_id ])

@stuff.map &:destroy
end
end
end
params[:stuff].each do |stuff_id|
if @issue = Issue.find_by_id(stuff_id)
@issue.assigned_to = @user
@issue.save!
end
end
StuffToDo.reorder_list(@user, params[:stuff])
@doing_now = StuffToDo.doing_now(@user)
@recommended = StuffToDo.recommended(@user)
Expand All @@ -27,7 +60,15 @@ def reorder
format.js { render :partial => 'panes', :layout => false}
end
end

def reorder_list_user
@user = User.find(params[:user_id])
params[:users].each_with_index { |user_id,i| SortUser.reorder(@user.id, user_id, i) }
respond_to do |format|
format.html { render :text => :ok }
format.js { render :text => :ok, :layout => false}
end

end
def available_issues
@available = StuffToDo.available(@user, get_filters)

Expand All @@ -36,7 +77,7 @@ def available_issues
format.js { render :partial => 'right_panes', :layout => false}
end
end

def time_grid
respond_to do |format|
format.html { redirect_to :action => 'index'}
Expand Down Expand Up @@ -72,7 +113,7 @@ def save_time_entry
if save_time_entry_from_time_grid(@time_entry)
flash.now[:time_grid_notice] = l(:notice_successful_update)
get_time_grid # after saving in order to get the updated data

format.js { time_grid }
else
format.js { render :text => @time_entry.errors.full_messages.join(', '), :status => 403, :layout => false }
Expand All @@ -81,21 +122,21 @@ def save_time_entry
end

private

def get_user
render_403 unless User.current.logged?

if params[:user_id] && params[:user_id] != User.current.id.to_s
if User.current.admin?
@user = User.find(params[:user_id])
else
render_403
end
else
@user = User.current
@user = User.current
end
end

def filters_for_view
StuffToDoFilter.new
end
Expand Down
16 changes: 12 additions & 4 deletions app/helpers/stuff_to_do_helper.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
module StuffToDoHelper
def progress_bar_sum(collection, field, opts)
issues = remove_non_issues(collection)

total = issues.inject(0) {|sum, n| sum + n.read_attribute(field) }
divisor = issues.length
return if divisor.nil? || divisor == 0

progress_bar(total / divisor, opts)
end

def total_estimates(issues)
remove_non_issues(issues).collect(&:estimated_hours).compact.sum
end

def filter_options(filters, selected = nil)
html = options_for_select([[l(:stuff_to_do_label_filter_by), '']]) # Blank

Expand All @@ -30,7 +30,7 @@ def filter_options(filters, selected = nil)
:label => filter_group.to_s.capitalize )
end
end

return html
end

Expand Down Expand Up @@ -79,6 +79,14 @@ def total_hours_for_user(issues, user)
issues.collect {|issue| total_hours_for_issue_for_user(issue, user)}.compact.sum
end

def progress_bar_for_project( project, user )
@open_issues = project.issues.open.count(:conditions => {:assigned_to_id => user.id})
@all_issues = project.issues.count(:conditions => {:assigned_to_id => user.id})
@close_issues = @all_issues - @open_issues
return 0 if @all_issues.to_i == 0
(@close_issues.to_i * 100) / @all_issues
end

# Redmine 0.8.x compatibility
def l_hours(hours)
hours = hours.to_f
Expand Down
26 changes: 26 additions & 0 deletions app/models/sort_user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class SortUser < ActiveRecord::Base
unloadable
belongs_to :user
belongs_to :item
default_scope :order => 'sort_users.position'
class << self
def reorder(user_id,item_id, position)
@sort_user = first(:conditions => {:user_id => user_id, :item_id => item_id}) ||
new(:user_id => user_id, :item_id => item_id)
@sort_user.position = position
@sort_user.save!
end
def sort_users( user, users )
@stuff_to_do_position = all(:conditions => {:user_id => user.id})
@stuff_to_do_max_position = maximum(:position, :conditions => {:user_id => user.id})
users.map {|x|
if @user_position = @stuff_to_do_position.find{|v| v.item_id == x.id }
x.stuff_to_do_position = @user_position.position
else
x.stuff_to_do_position = @stuff_to_do_max_position.to_i + 1
end
}
users.sort{|v1,v2| v1.stuff_to_do_position <=> v2.stuff_to_do_position}
end
end
end
44 changes: 44 additions & 0 deletions app/views/stuff_to_do/origin_index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<% html_title(l(:stuff_to_do_title)) %>
<h1><%= l(:stuff_to_do_title) %></h1>

<div id="stuff-to-do-error" class="flash error" style="display:none">

</div>

<div class="menu">
<% if User.current.admin? %>
<div class="user">
<% form_tag({ :controller => 'stuff_to_do', :action => 'index'}, :method => :get, :id => 'user_switch' ) do %>
<label for="user_id"><%= l(:stuff_to_do_label_view_user_list) %></label>
<%= collection_select(:user, :id, @users.sort, :id, :name, { }, { :name => 'user_id'}) %>
<% end %>
</div>

<div class="filter">
<% form_tag({}, :id => 'filter_form') do %>
<label for="filter"><%= l(:stuff_to_do_label_filter) %></label>
<%= select_tag("filter", filter_options(@filters, params[:filter])) %>
<% end %>
</div>
<% end %>
</div>
<div style="clear:right;"></div>

<%= render :partial => 'panes' %>

<div style="clear:both;"></div>

<%= render :partial => 'time_grid' if !Setting.plugin_stuff_to_do_plugin['use_time_grid'].blank? && Setting.plugin_stuff_to_do_plugin['use_time_grid'] != "0" %>

<% content_for :header_tags do %>
<%= stylesheet_link_tag "stuff_to_do.css", :plugin => "stuff_to_do_plugin", :media => 'all' %>
<%= javascript_include_tag 'jquery-1.2.6.min.js', :plugin => 'stuff_to_do_plugin' %>
<%= javascript_include_tag 'ui/ui.core.js', :plugin => 'stuff_to_do_plugin' %>
<%= javascript_include_tag 'ui/ui.sortable.js', :plugin => 'stuff_to_do_plugin' %>
<%= javascript_include_tag 'jquery.contextMenu.js', :plugin => 'stuff_to_do_plugin' %>
<%= javascript_include_tag 'facebox.js', :plugin => 'stuff_to_do_plugin' %>
<%= javascript_tag("jQuery.noConflict();") %>
<%= javascript_include_tag 'stuff-to-do.js', :plugin => 'stuff_to_do_plugin' %>
<%= javascript_tag("var user_id = #{@user.id};") %>
<%= javascript_tag "window._token = '#{form_authenticity_token}'" %>
<% end %>
89 changes: 89 additions & 0 deletions app/views/stuff_to_do/overview.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<% html_title(l(:stuff_to_do_title)) %>
<h1><%= l(:stuff_to_do_title) %></h1>

<div id="stuff-to-do-error" class="flash error" style="display:none"></div>

<div class="overview">Overview</div>


<div class="authors-blocks">

<% @selected_users.each do |user| %>

<% @doing_now = StuffToDo.doing_now(user) %>
<%
@projects, @issues = user.projects.all(:limit => 5), []
stuff_for(@doing_now).each { |item| @issues.push(item) if item.class == Issue } %>

<div class="job-block pane" id="users_<%= user.id %>">
<h1><%= link_to user.name, :controller => 'stuff_to_do', :action => 'index', :user_id => user.id %></h1>

<div class="project-names">
<% @projects.each do |project| %>
<% if project.issues.open.first(:conditions => {:assigned_to_id => user.id }) %>
<div class="one-line">
<%= link_to( h(project.name), :controller => 'projects', :action => 'show', :id => project) %>
<span><%= total_hours_for_user project.issues, user %></span>
<div class="progress"><span style="width:<%= progress_bar_for_project(project, user) %>%;"></span></div>
</div>
<% end %>
<% end %>
</div>


<h2><a href="#" title="current issues">Current Issues</a></h2>

<div class="issues" data-user_id="<%= user.id %>">
<% @issues[0..5].each do |item| %>
<div class="one-line" data-item_id="<%= item.id %>" data-owner_id="<%= user.id %>">
<%= link_to( h("#{item.project.name} - #{item.subject}"), :controller => 'issues', :action => 'show', :id => item) %>
<span><%= item.estimated_hours %></span>
<div class="progress"><span style="width:<%= item.done_ratio.to_f %>%;"></span></div>
</div>
<% end %>
</div>


</div>
<% end %>
</div>




<% if User.current.admin? %>

<div class="filter">
<div class="filter-label">Filter by teammember</div>

<% form_tag({ :controller => 'stuff_to_do', :action => 'overview'}, :method => :get,
:id => 'user_switch', :class => "filter-by-name" ) do %>

<ul>
<% @users.each do |user| %>
<li>
<%= check_box_tag :"users[]", user.id, @selected_users.include?(user) %><label><%= user.name %></label>
</li>
<% end %>
</ul>

<button>Select</button>
<% end %>
</div>

<% end %>


<% content_for :header_tags do %>
<%= stylesheet_link_tag "stuff_to_do.css", :plugin => "stuff_to_do_plugin", :media => 'all' %>
<%= stylesheet_link_tag "stuff_to_do_overview.css", :plugin => "stuff_to_do_plugin", :media => 'all' %>
<%= javascript_include_tag 'jquery.js', :plugin => 'stuff_to_do_plugin' %>
<%= javascript_include_tag 'jquery.contextMenu.js', :plugin => 'stuff_to_do_plugin' %>
<%= javascript_include_tag 'facebox.js', :plugin => 'stuff_to_do_plugin' %>
<%= javascript_include_tag 'jquery-ui.min.js', :plugin => 'stuff_to_do_plugin' %>
<%= javascript_tag("jQuery.noConflict();") %>
<%= javascript_include_tag 'stuff-to-do.js', :plugin => 'stuff_to_do_plugin' %>
<%= javascript_include_tag 'stuff-to-do-overview.js', :plugin => 'stuff_to_do_plugin' %>
<%= javascript_tag("var user_id = #{@user.id};") %>
<%= javascript_tag "window._token = '#{form_authenticity_token}'" %>
<% end %>
Loading