only support csv export by timelog#index

pull/7362/head
ulferts 6 years ago
parent ba5407bb15
commit a74abeb737
No known key found for this signature in database
GPG Key ID: A205708DE1284017
  1. 76
      app/controllers/timelog_controller.rb
  2. 90
      app/views/timelog/_list.html.erb
  3. 28
      app/views/timelog/index.html.erb
  4. 30
      app/views/timelog/index.rabl
  5. 57
      app/views/timelog/show.rabl
  6. 34
      app/views/users/show.rabl
  7. 9
      config/locales/en.yml
  8. 2
      config/routes.rb
  9. 88
      spec_legacy/functional/timelog_controller_spec.rb

@ -29,8 +29,6 @@
#++
class TimelogController < ApplicationController
menu_item :issues
before_action :disable_api, except: %i[index destroy]
before_action :find_work_package, only: %i[new create]
before_action :find_project, only: %i[new create]
@ -72,49 +70,8 @@ class TimelogController < ApplicationController
respond_to do |format|
format.html do
# Paginate results
@entry_count = TimeEntry
.visible
.includes(:project, :work_package)
.references(:projects)
.where(cond.conditions)
.count
@total_hours = TimeEntry
.visible
.includes(:project, :work_package)
.references(:projects)
.where(cond.conditions)
.distinct(false)
.sum(:hours).to_f
set_entries(cond)
gon.rabl template: 'app/views/timelog/index.rabl'
gon.project_id = @project.id if @project
gon.work_package_id = @issue.id if @issue
gon.sort_column = 'spent_on'
gon.sort_direction = 'desc'
gon.total_count = total_entry_count(cond)
gon.settings = client_preferences
render layout: layout_non_or_no_menu
end
format.json do
set_entries(cond)
gon.rabl template: 'app/views/timelog/index.rabl'
end
format.atom do
entries = TimeEntry
.visible
.includes(:project, :activity, :user, work_package: :type)
.references(:projects)
.where(cond.conditions)
.order("#{TimeEntry.table_name}.created_on DESC")
.limit(Setting.feeds_limit.to_i)
render_feed(entries, title: l(:label_spent_time))
end
format.csv do
# Export all entries
@entries = TimeEntry
@ -133,15 +90,6 @@ class TimelogController < ApplicationController
end
end
def show
respond_to do |format|
# TODO: Implement html response
format.html do
head 406
end
end
end
def new
@time_entry = new_time_entry(@project, @issue, permitted_params.time_entry.to_h)
@ -206,30 +154,6 @@ class TimelogController < ApplicationController
private
def total_entry_count(cond)
TimeEntry
.visible
.includes(:project, :activity, :user, work_package: :type)
.references(:projects)
.where(cond.conditions)
.count
end
def set_entries(cond)
# .visible introduces a distinct which we don't need here and which interferes
# with the order on postgresql.
# The distinct is therefore explicitly removed
@entries = TimeEntry
.visible
.includes(:project, :activity, :user, work_package: :type)
.references(:projects)
.where(cond.conditions)
.distinct(false)
.order(sort_clause)
.page(page_param)
.per_page(per_page_param)
end
def find_time_entry
@time_entry = TimeEntry.find(params[:id])
unless @time_entry.editable_by?(User.current)

@ -1,90 +0,0 @@
<%#-- copyright
OpenProject is a project management system.
Copyright (C) 2012-2018 the OpenProject Foundation (OPF)
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License version 3.
OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
Copyright (C) 2006-2017 Jean-Philippe Lang
Copyright (C) 2010-2013 the ChiliProject Team
This program 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 2
of the License, or (at your option) any later version.
This program 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 this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
See docs/COPYRIGHT.rdoc for more details.
++#%>
<div class="generic-table--container">
<div class="generic-table--results-container">
<table class="generic-table">
<colgroup>
<col highlight-col>
<col highlight-col>
<col highlight-col>
<col highlight-col>
<col highlight-col>
<col highlight-col>
<col highlight-col>
<col>
</colgroup>
<thead>
<tr>
<%= sort_header_tag("spent_on", caption: TimeEntry.human_attribute_name(:spent_on)) %>
<%= sort_header_tag("user", caption: TimeEntry.human_attribute_name(:user)) %>
<%= sort_header_tag("activity", caption: TimeEntry.human_attribute_name(:activity)) %>
<%= sort_header_tag("project", caption: TimeEntry.human_attribute_name(:project)) %>
<%= sort_header_tag("work_package", caption: TimeEntry.human_attribute_name(:issue)) %>
<%= sort_header_tag("comments", caption: TimeEntry.human_attribute_name(:comments)) %>
<%= sort_header_tag("hours", caption: TimeEntry.human_attribute_name(:hours)) %>
<th>
<div class="generic-table--empty-header"></div>
</th>
</tr>
</thead>
<tbody>
<% entries.each do |entry| -%>
<tr class="time-entry">
<td class="spent_on"><%= format_date(entry.spent_on) %></td>
<td class="user"><%= link_to_user(entry.user) %></td>
<td class="activity"><%= h entry.activity %></td>
<td class="project"><%= link_to_project(entry.project) %></td>
<td class="subject">
<% if entry.work_package -%>
<%= entry.work_package.visible? ? link_to_work_package(entry.work_package, truncate: 50) : "##{entry.work_package.id}" -%>
<% end -%>
</td>
<td class="comments"><%= h entry.comments %></td>
<td class="hours"><%= html_hours("%.2f" % entry.hours) %></td>
<td align="center">
<% if entry.editable_by?(current_user) -%>
<%= link_to icon_wrapper('icon-context icon-edit', t(:button_edit)),
edit_time_entry_path(entry),
class: 'no-decoration-on-hover',
title: t(:button_edit) %>
<%= link_to icon_wrapper('icon-context icon-delete', t(:button_delete)),
time_entry_path(entry),
confirm: t(:text_are_you_sure),
class: 'no-decoration-on-hover',
method: :delete,
title: t(:button_delete) %>
<% end -%>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>

@ -27,10 +27,6 @@ See docs/COPYRIGHT.rdoc for more details.
++#%>
<%= nonced_javascript_tag do %>
<%= include_gon(need_tag: false) -%>
<% end %>
<%= toolbar title: l(:label_spent_time) do %>
<% if User.current.allowed_to?({controller: :timelog, action: :new}, @project) %>
<li class="toolbar-item">
@ -42,27 +38,21 @@ See docs/COPYRIGHT.rdoc for more details.
<% end %>
<% end %>
<%= form_tag(polymorphic_path([@issue || @project, :time_entries]), method: :get, id: 'query_form') do %>
<%= render partial: 'date_range' %>
<% end %>
<%= render 'time_entry_tabs' %>
<div class="total-hours">
<p><%= l(:label_total) %>: <%= html_hours(l_hours(@total_hours)) %></p>
<div class="notification-box -warning">
<a title="close" class="notification-box--close icon-context icon-close"></a>
<div class="notification-box--content">
<%= t('deprecations.time_entries') %>
</div>
</div>
<div>
<% if @entries.empty? %>
<%= no_results_box %>
<% else %>
<%= render partial: 'list', locals: { entries: @entries }%>
<%= other_formats_links do |f| %>
<%= f.link_to 'Atom', url: permitted_params.timelog.to_h.merge({issue_id: @issue, key: User.current.rss_key}) %>
<%= f.link_to 'CSV', url: permitted_params.timelog.to_h %>
<% end %>
<%= other_formats_links do |f| %>
<%= f.link_to 'CSV', url: permitted_params.timelog.to_h %>
<% end %>
</div>
<% html_title l(:label_spent_time) %>
<% content_for :header_tags do %>
<%= auto_discovery_link_tag(:atom, {issue_id: @issue, format: 'atom', key: User.current.rss_key}, title: l(:label_spent_time)) %>
<% end %>

@ -1,30 +0,0 @@
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2013 the OpenProject Foundation (OPF)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2013 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
#
# This program 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 2
# of the License, or (at your option) any later version.
#
# This program 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 this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See doc/COPYRIGHT.rdoc for more details.
#++
collection @entries => "timeEntries"
extends 'timelog/show'

@ -1,57 +0,0 @@
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2013 the OpenProject Foundation (OPF)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2013 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
#
# This program 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 2
# of the License, or (at your option) any later version.
#
# This program 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 this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See doc/COPYRIGHT.rdoc for more details.
#++
object @entry => "timeEntry"
attributes :id,
:spent_on,
:comments,
:hours
node :user do |e|
partial('users/show', object: e.user)
end
child :activity => :activity do
attributes :name
end
child :project do
attributes :id, :name
end
child :work_package do
attributes :id, :subject
node :isVisible do |w|
w.visible?
end
end
node :isEditable do |e|
e.editable_by?(User.current)
end

@ -1,34 +0,0 @@
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2013 the OpenProject Foundation (OPF)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2013 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
#
# This program 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 2
# of the License, or (at your option) any later version.
#
# This program 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 this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See doc/COPYRIGHT.rdoc for more details.
#++
object @user
attributes :id,
:name,
:firstname,
:lastname

@ -132,14 +132,7 @@ en:
single: 'or'
deprecations:
old_timeline:
replacement: "This timelines module is being replaced by the interactive timeline embedded into the work packages module."
removal: "This module is going to be removed with OpenProject 8.0. The configuration for this view will NOT be migrated to the work package view."
further_information_before: "Please take a look at"
link_name: "how to migrate to the new timeline."
further_information_after: ""
calendar:
removal: "Please note: This module is going to be removed with OpenProject 8.0."
time_entries: "This time entries view is superseded by the 'Cost reports' module. This view now only supports exporting time entry information to csv. For interactive filtering, please activate the 'Cost reports' module in the project settings."
global_search:
overwritten_tabs:

@ -214,7 +214,7 @@ OpenProject::Application.routes.draw do
namespace :time_entries do
resource :report, controller: 'reports', only: [:show]
end
resources :time_entries, controller: 'timelog'
resources :time_entries, controller: 'timelog', except: [:show]
# Match everything to be the ID of the wiki page except the part that
# is reserved for the format. This assumes that we have only two formats:

@ -92,92 +92,4 @@ describe TimelogController, type: :controller do
assert_equal 2, entry.work_package_id
assert_equal 2, entry.user_id
end
it 'should index all projects' do
get :index
assert_response :success
assert_template 'index'
refute_nil assigns(:total_hours)
assert_equal '162.90', '%.2f' % assigns(:total_hours)
assert_select 'form',
attributes: { action: '/time_entries', id: 'query_form' }
end
it 'should index at project level' do
get :index, params: { project_id: 'ecookbook' }
assert_response :success
assert_template 'index'
refute_nil assigns(:entries)
assert_equal 4, assigns(:entries).size
# project and subproject
assert_equal [1, 3], assigns(:entries).map(&:project_id).uniq.sort
refute_nil assigns(:total_hours)
assert_equal '162.90', '%.2f' % assigns(:total_hours)
# display all time by default
assert_equal nil, assigns(:from)
assert_equal nil, assigns(:to)
assert_select 'form',
attributes: { action: '/projects/ecookbook/time_entries', id: 'query_form' }
end
it 'should index at project level with date range' do
get :index, params: { project_id: 'ecookbook', from: '2007-03-20', to: '2007-04-30' }
assert_response :success
assert_template 'index'
refute_nil assigns(:entries)
assert_equal 3, assigns(:entries).size
refute_nil assigns(:total_hours)
assert_equal '12.90', '%.2f' % assigns(:total_hours)
assert_equal '2007-03-20'.to_date, assigns(:from)
assert_equal '2007-04-30'.to_date, assigns(:to)
assert_select 'form',
attributes: { action: '/projects/ecookbook/time_entries', id: 'query_form' }
end
it 'should index at project level with period' do
get :index, params: { project_id: 'ecookbook', period: '7_days' }
assert_response :success
assert_template 'index'
refute_nil assigns(:entries)
refute_nil assigns(:total_hours)
assert_equal Date.today - 7, assigns(:from)
assert_equal Date.today, assigns(:to)
assert_select 'form',
attributes: { action: '/projects/ecookbook/time_entries', id: 'query_form' }
end
it 'should index one day' do
get :index, params: { project_id: 'ecookbook', from: '2007-03-23', to: '2007-03-23' }
assert_response :success
assert_template 'index'
refute_nil assigns(:total_hours)
assert_equal '4.25', '%.2f' % assigns(:total_hours)
assert_select 'form',
attributes: { action: '/projects/ecookbook/time_entries', id: 'query_form' }
end
it 'should index at issue level' do
get :index, params: { work_package_id: 1 }
assert_response :success
assert_template 'index'
refute_nil assigns(:entries)
assert_equal 2, assigns(:entries).size
refute_nil assigns(:total_hours)
assert_equal 154.25, assigns(:total_hours)
# display all time based on what's been logged
assert_equal nil, assigns(:from)
assert_equal nil, assigns(:to)
assert_select 'form',
attributes: { action: work_package_time_entries_path(1), id: 'query_form' }
end
it 'should index atom feed' do
TimeEntry.all.each(&:recreate_initial_journal!)
get :index, params: { project_id: 1, format: 'atom' }
assert_response :success
assert_equal 'application/atom+xml', response.content_type
refute_nil assigns(:items)
assert assigns(:items).first.is_a?(TimeEntry)
end
end

Loading…
Cancel
Save