OpenProject is the leading open source project management software.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
openproject/app/controllers/timelog_controller.rb

233 lines
6.8 KiB

#-- encoding: UTF-8
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2012-2020 the OpenProject GmbH
#
# 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.
#++
class TimelogController < ApplicationController
helper_method :gon
before_action :find_work_package, only: %i[new create]
before_action :find_project, only: %i[new create]
before_action :find_time_entry, only: %i[show edit update destroy]
before_action :authorize, except: [:index]
before_action :find_optional_project, only: [:index]
include SortHelper
include TimelogHelper
include CustomFieldsHelper
include PaginationHelper
[27828] Feature: Query menu in sidenav (#6429) * in main menu add gantt as extra work package child item * Satisfy spec and code climate * Add gantt chart icon behin default gantt query name. * WIP Query menu in left sidebar * Shift query dropdown in left sidenav * Reload menu or load query on click from every project location * WIP set correct label for default queries * Query menu listens on all changes of queries (delete, create, rename, toggle starred) and updates immediatly * WIP: Inline edit, field validation * Inline Edit validation and comfirm * Inline edit: validation of duplicate name * Set default columns and sorting for static queries * Codeclimate issues fixed * WIP Inline edit validation not working perfectly in all error states * Inline edit working * Autocompleter hover disabled and hovering over categories fixed * Category hover and toggle fixed; tested in Chrome, Firefox and Opera * Placeholder cut off fixed and text wrap added * English and german wording adjusted * Styles of inline edit and menu adjusted; matching wiki page styles * prevent menus to be displayed to often * application menu only displayed on work package * specify using no_menu layout more often * adapt tests to altered production implementation * Hamburger icon only in project; on global wp page: default queries shown correctly and summary removed * searching for undefined leads to error * Accessible click fixed (listen on escape) * Gantt in top menu deleted (gantt chart is part of default queries on wp page) * load menu on wp summary page * reduce times queries are loaded * lowercase on second word * remove menu from search and home * Styles fixed (category toggle and correct highlighting) * reflect static query in url * fix autocomplete handling in specs * Open all global menus on default and hide hamburger icon on global pages; Rebuild changes that have been ovrwritten after merge" * Correct highlighting of default queries after reload * Replace summary cuke with spec * WIP * Clear up selectors * Avoid actively setting promises and instead use $state.go to load links [ci skip] * Make editable title component a little simpler We can reuse the component I built for the wiki, that wasn't present in the frontend beforehand. * Fix moving through the menu and selecting items [ci skip] * Add save button to query title when query changed * Improve static names lookup by comparing query_props * Adapt and fix specs * Allow inner scrolling of wp query results Also, style the webkit scrollbar to make it pretty where supported * Allow renaming the query through setting menu, but simply focus on field [ci skip]
6 years ago
include Concerns::Layout
menu_item :time_entries
def index
# Set tab param to recognize correct selected tab
5 years ago
params[:tab] = params[:tab] || 'details'
sort_init 'spent_on', 'desc'
sort_update 'spent_on' => 'spent_on',
'user' => 'user_id',
'activity' => 'activity_id',
'project' => "#{Project.table_name}.name",
'work_package' => 'work_package_id',
'comments' => 'comments',
'hours' => 'hours'
cond = ARCondition.new
if @issue
cond << WorkPackage.self_and_descendants_of_condition(@issue)
elsif @project
11 years ago
cond << @project.project_condition(Setting.display_subprojects_work_packages?)
end
retrieve_date_range allow_nil: true
if @from && @to
cond << ['spent_on BETWEEN ? AND ?', @from, @to]
end
respond_to do |format|
format.html do
[27828] Feature: Query menu in sidenav (#6429) * in main menu add gantt as extra work package child item * Satisfy spec and code climate * Add gantt chart icon behin default gantt query name. * WIP Query menu in left sidebar * Shift query dropdown in left sidenav * Reload menu or load query on click from every project location * WIP set correct label for default queries * Query menu listens on all changes of queries (delete, create, rename, toggle starred) and updates immediatly * WIP: Inline edit, field validation * Inline Edit validation and comfirm * Inline edit: validation of duplicate name * Set default columns and sorting for static queries * Codeclimate issues fixed * WIP Inline edit validation not working perfectly in all error states * Inline edit working * Autocompleter hover disabled and hovering over categories fixed * Category hover and toggle fixed; tested in Chrome, Firefox and Opera * Placeholder cut off fixed and text wrap added * English and german wording adjusted * Styles of inline edit and menu adjusted; matching wiki page styles * prevent menus to be displayed to often * application menu only displayed on work package * specify using no_menu layout more often * adapt tests to altered production implementation * Hamburger icon only in project; on global wp page: default queries shown correctly and summary removed * searching for undefined leads to error * Accessible click fixed (listen on escape) * Gantt in top menu deleted (gantt chart is part of default queries on wp page) * load menu on wp summary page * reduce times queries are loaded * lowercase on second word * remove menu from search and home * Styles fixed (category toggle and correct highlighting) * reflect static query in url * fix autocomplete handling in specs * Open all global menus on default and hide hamburger icon on global pages; Rebuild changes that have been ovrwritten after merge" * Correct highlighting of default queries after reload * Replace summary cuke with spec * WIP * Clear up selectors * Avoid actively setting promises and instead use $state.go to load links [ci skip] * Make editable title component a little simpler We can reuse the component I built for the wiki, that wasn't present in the frontend beforehand. * Fix moving through the menu and selecting items [ci skip] * Add save button to query title when query changed * Improve static names lookup by comparing query_props * Adapt and fix specs * Allow inner scrolling of wp query results Also, style the webkit scrollbar to make it pretty where supported * Allow renaming the query through setting menu, but simply focus on field [ci skip]
6 years ago
render layout: layout_non_or_no_menu
end
format.csv do
# Export all entries
@entries = TimeEntry
.visible
.includes(:project,
:activity,
:user,
work_package: %i[type assigned_to priority])
.references(:projects)
.where(cond.conditions)
.distinct(false)
.order(sort_clause)
render csv: entries_to_csv(@entries), filename: 'timelog.csv'
end
end
end
def new
@time_entry = new_time_entry(@project, @issue, permitted_params.time_entry.to_h)
8 years ago
call_hook(:controller_timelog_edit_before_save, params: params, time_entry: @time_entry)
11 years ago
render action: 'edit'
end
def create
combined_params = permitted_params
.time_entry
.to_h
.reverse_merge(project: @project,
work_package_id: @issue)
call = TimeEntries::CreateService
.new(user: current_user)
.call(combined_params)
@time_entry = call.result
respond_for_saving call
end
def edit
@time_entry.attributes = permitted_params.time_entry
8 years ago
call_hook(:controller_timelog_edit_before_save, params: params, time_entry: @time_entry)
end
def update
service = TimeEntries::UpdateService
.new(user: current_user,
model: @time_entry)
call = service.call(attributes: permitted_params.time_entry)
respond_for_saving call
end
def destroy
if @time_entry.destroy && @time_entry.destroyed?
respond_to do |format|
format.html do
flash[:notice] = l(:notice_successful_delete)
redirect_back fallback_location: { action: 'index', project_id: @time_entry.project }
end
format.json do
render json: { text: l(:notice_successful_delete) }
end
end
else
respond_to do |format|
format.html do
flash[:error] = l(:notice_unable_delete_time_entry)
redirect_back fallback_location: { action: 'index', project_id: @time_entry.project }
end
format.json do
render json: { isError: true, text: l(:notice_unable_delete_time_entry) }
end
end
end
end
11 years ago
private
def find_time_entry
@time_entry = TimeEntry.find(params[:id])
unless @time_entry.editable_by?(User.current)
render_403
return false
end
@project = @time_entry.project
rescue ActiveRecord::RecordNotFound
render_404
end
def find_project
11 years ago
@project = Project.find(project_id_from_params) if @project.nil?
rescue ActiveRecord::RecordNotFound
render_404
end
def new_time_entry(project, work_package, attributes)
time_entry = TimeEntry.new(project: project,
work_package: work_package,
user: User.current,
spent_on: User.current.today)
time_entry.attributes = attributes
time_entry
end
def respond_for_saving(call)
@errors = call.errors
if call.success?
respond_to do |format|
format.html do
flash[:notice] = l(:notice_successful_update)
redirect_back_or_default action: 'index', project_id: @time_entry.project
end
end
else
respond_to do |format|
format.html do
render action: 'edit'
end
end
end
end
11 years ago
def project_id_from_params
if params.has_key?(:project_id)
params[:project_id]
elsif params.has_key?(:time_entry) && permitted_params.time_entry.has_key?(:project_id)
permitted_params.time_entry[:project_id]
11 years ago
end
end
def find_work_package
@issue = work_package_from_params
@project = @issue.project unless @issue.nil?
end
def work_package_from_params
if params.has_key?(:work_package_id)
work_package_id = params[:work_package_id]
elsif params.has_key?(:time_entry) && permitted_params.time_entry.has_key?(:work_package_id)
work_package_id = permitted_params.time_entry[:work_package_id]
11 years ago
end
WorkPackage.find_by id: work_package_id
11 years ago
end
def default_breadcrumb
I18n.t(:label_spent_time)
end
end