OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Merge branch 'dev' into feature/61290-primerize-time-tracking-settings-in-projects-and-administration
Klaus Zandersfff7cfd36dda
diff --cc modules/costs/app/controllers/admin/cost_types_controller.rbindex a20fc8637d0,00000000000..0cb40984649mode 100644,000000..100644--- a/modules/costs/app/controllers/admin/cost_types_controller.rb+++ b/modules/costs/app/controllers/admin/cost_types_controller.rb@@@ -1,162 -1,0 +1,162 @@@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 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-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 COPYRIGHT and LICENSE files for more details.+#++++module Admin+ class CostTypesController < ApplicationController+ # Allow only admins here+ before_action :require_admin+ before_action :find_cost_type, only: %i[edit update set_rate destroy restore]+ layout "admin"+ menu_item :cost_types++ helper :sort+ include SortHelper+ helper :cost_types+ include CostTypesHelper++ def index # rubocop:disable Metrics/AbcSize+ sort_init "name", "asc"+ sort_columns = { "name" => "#{CostType.table_name}.name",+ "unit" => "#{CostType.table_name}.unit",+ "unit_plural" => "#{CostType.table_name}.unit_plural" }+ sort_update sort_columns++ @cost_types = CostType.order(sort_clause)++ if params[:clear_filter]+ @fixed_date = Time.zone.today+ @include_deleted = nil+ else+ @fixed_date = begin+ Date.parse(params[:fixed_date])+ rescue StandardError+ Time.zone.today+ end+ @include_deleted = params[:include_deleted]+ end++ render action: "index", layout: !request.xhr?+ end++ def edit+ render action: :edit, layout: !request.xhr?+ end++ def update+ @cost_type.attributes = permitted_params.cost_type++ if @cost_type.save+ flash[:notice] = t(:notice_successful_update)- redirect_back_or_default(action: "index")++ redirect_back_or_default({ action: "index" })+ else+ render action: :edit, status: :unprocessable_entity, layout: !request.xhr?+ end+ rescue ActiveRecord::StaleObjectError+ # Optimistic locking exception+ flash.now[:error] = t(:notice_locking_conflict)+ end++ def new+ @cost_type = CostType.new++ @cost_type.rates.build(valid_from: Time.zone.today) if @cost_type.rates.empty?++ render action: :edit, layout: !request.xhr?+ end++ def create # rubocop:disable Metrics/AbcSize+ @cost_type = CostType.new(permitted_params.cost_type)++ if @cost_type.save+ flash[:notice] = t(:notice_successful_update)- redirect_back_or_default(action: "index")++ redirect_back_or_default({ action: "index" })+ else+ @cost_type.rates.build(valid_from: Time.zone.today) if @cost_type.rates.empty?+ render action: :edit, status: :unprocessable_entity, layout: !request.xhr?+ end+ rescue ActiveRecord::StaleObjectError+ # Optimistic locking exception+ flash.now[:error] = t(:notice_locking_conflict)+ end++ def destroy+ @cost_type.deleted_at = DateTime.now+ @cost_type.default = false++ if @cost_type.save+ flash[:notice] = t(:notice_successful_lock)+- redirect_back_or_default(action: "index")++ redirect_back_or_default({ action: "index" })+ end+ end++ def restore+ @cost_type.deleted_at = nil+ @cost_type.default = false++ if @cost_type.save+ flash[:notice] = t(:notice_successful_restore)+- redirect_back_or_default(action: "index")++ redirect_back_or_default({ action: "index" })+ end+ end++ def set_rate # rubocop:disable Metrics/AbcSize+ today = Time.zone.today++ rate = @cost_type.rate_at(today)+ rate ||= CostRate.new.tap do |cr|+ cr.cost_type = @cost_type+ cr.valid_from = today+ end++ rate.rate = CostRate.parse_number_string_to_number(params[:rate])+ if rate.save+ flash[:notice] = t(:notice_successful_update)+ else+ # FIXME: Do some real error handling here+ flash[:error] = t(:notice_something_wrong)+ end+ redirect_to action: "index"+ end++ private++ def find_cost_type+ @cost_type = CostType.find(params[:id])+ rescue ActiveRecord::RecordNotFound+ render_404+ end++ def show_local_breadcrumb+ false+ end+ end+end