From ec1f262c8913a1e4134409a097788b302eeccbd7 Mon Sep 17 00:00:00 2001 From: Hagen Schink Date: Wed, 13 Aug 2014 09:51:51 +0200 Subject: [PATCH 1/7] Refactor attributes hook --- .../javascripts/angular/openproject-costs-app.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/angular/openproject-costs-app.js b/app/assets/javascripts/angular/openproject-costs-app.js index 3f2d5839a9..caa23ad24c 100644 --- a/app/assets/javascripts/angular/openproject-costs-app.js +++ b/app/assets/javascripts/angular/openproject-costs-app.js @@ -31,8 +31,16 @@ var openprojectCostsApp = angular.module('openproject'); openprojectCostsApp.run(['HookService', function(HookService) { HookService.register('workPackageOverviewAttributes', function(params) { - var isEmpty = params.workPackage.embedded.summarizedCostEntries.length == 0; + var directive; - return ((params.type == "spentUnits" && !isEmpty) ? "summarized-cost-entries" : undefined); + switch (params.type) { + case "spentUnits": + if (params.workPackage.embedded.summarizedCostEntries.length > 0) { + directive = "summarized-cost-entries"; + } + break; + } + + return directive; }); }]); From 1aec8e7e773c4eaa3d7fc593ec55327e87f1d6c7 Mon Sep 17 00:00:00 2001 From: Hagen Schink Date: Wed, 13 Aug 2014 09:52:32 +0200 Subject: [PATCH 2/7] Render cost object information in WP overview --- .../angular/openproject-costs-app.js | 5 +++ .../directives/cost-object-directive.js | 40 +++++++++++++++++++ ..._work_package_overview_attributes.html.erb | 1 + lib/open_project/costs/engine.rb | 1 + .../templates/work_packages/cost_object.html | 5 +++ 5 files changed, 52 insertions(+) create mode 100644 app/assets/javascripts/angular/work_packages/directives/cost-object-directive.js create mode 100644 public/templates/work_packages/cost_object.html diff --git a/app/assets/javascripts/angular/openproject-costs-app.js b/app/assets/javascripts/angular/openproject-costs-app.js index caa23ad24c..d15b2fee63 100644 --- a/app/assets/javascripts/angular/openproject-costs-app.js +++ b/app/assets/javascripts/angular/openproject-costs-app.js @@ -39,6 +39,11 @@ openprojectCostsApp.run(['HookService', function(HookService) { directive = "summarized-cost-entries"; } break; + case "costObject": + if (params.workPackage.embedded.costObject) { + directive = "cost-object"; + } + break; } return directive; diff --git a/app/assets/javascripts/angular/work_packages/directives/cost-object-directive.js b/app/assets/javascripts/angular/work_packages/directives/cost-object-directive.js new file mode 100644 index 0000000000..85891d5217 --- /dev/null +++ b/app/assets/javascripts/angular/work_packages/directives/cost-object-directive.js @@ -0,0 +1,40 @@ +//-- copyright +// OpenProject is a project management system. +// Copyright (C) 2012-2014 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. +//++ + +angular.module('openproject.workPackages.directives') + +.directive('costObject', [function() { + return { + restrict: 'E', + templateUrl: '/templates/work_packages/cost_object.html', + link: function(scope, element, attributes) { + scope.costObject = scope.workPackage.embedded.costObject; + scope.linkToCostObject = '/cost_objects/' + scope.costObject.props.id; + } + }; +}]); diff --git a/app/views/hooks/costs/_view_work_package_overview_attributes.html.erb b/app/views/hooks/costs/_view_work_package_overview_attributes.html.erb index 5946131d94..d4daa1f53d 100644 --- a/app/views/hooks/costs/_view_work_package_overview_attributes.html.erb +++ b/app/views/hooks/costs/_view_work_package_overview_attributes.html.erb @@ -20,4 +20,5 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. <%= javascript_include_tag 'angular/openproject-costs-app.js' %> <%= javascript_include_tag 'angular/work_packages/directives/summarized-cost-entries-directive.js' %> +<%= javascript_include_tag 'angular/work_packages/directives/cost-object-directive.js' %> <%= stylesheet_link_tag 'costs/costs.css' %> diff --git a/lib/open_project/costs/engine.rb b/lib/open_project/costs/engine.rb index 874d4dbe56..65c336e606 100644 --- a/lib/open_project/costs/engine.rb +++ b/lib/open_project/costs/engine.rb @@ -152,6 +152,7 @@ module OpenProject::Costs end assets %w(angular/work_packages/directives/summarized-cost-entries-directive.js + angular/work_packages/directives/cost-object-directive.js angular/openproject-costs-app.js costs/costs.css costs/costs.js) diff --git a/public/templates/work_packages/cost_object.html b/public/templates/work_packages/cost_object.html new file mode 100644 index 0000000000..21a9d06ee8 --- /dev/null +++ b/public/templates/work_packages/cost_object.html @@ -0,0 +1,5 @@ + + + {{ costObject.props.subject }} + + From e2be19a1e2f90ded1f63d3ab84f1760af8bab0f0 Mon Sep 17 00:00:00 2001 From: Hagen Schink Date: Wed, 13 Aug 2014 10:23:34 +0200 Subject: [PATCH 3/7] Link 'spent hours' in WP overview --- .../angular/openproject-costs-app.js | 5 +++ .../directives/spent-hours-directive.js | 45 +++++++++++++++++++ ..._work_package_overview_attributes.html.erb | 1 + config/locales/js-de.yml | 4 +- config/locales/js-en.yml | 4 +- .../work_packages_overview_attributes.rb | 2 +- .../templates/work_packages/spent_hours.html | 5 +++ 7 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 app/assets/javascripts/angular/work_packages/directives/spent-hours-directive.js create mode 100644 public/templates/work_packages/spent_hours.html diff --git a/app/assets/javascripts/angular/openproject-costs-app.js b/app/assets/javascripts/angular/openproject-costs-app.js index d15b2fee63..8b4b0363cd 100644 --- a/app/assets/javascripts/angular/openproject-costs-app.js +++ b/app/assets/javascripts/angular/openproject-costs-app.js @@ -44,6 +44,11 @@ openprojectCostsApp.run(['HookService', function(HookService) { directive = "cost-object"; } break; + case "spentHoursLinked": + if (params.workPackage.props.spentHours) { + directive = "spent-hours"; + } + break; } return directive; diff --git a/app/assets/javascripts/angular/work_packages/directives/spent-hours-directive.js b/app/assets/javascripts/angular/work_packages/directives/spent-hours-directive.js new file mode 100644 index 0000000000..0eac49b805 --- /dev/null +++ b/app/assets/javascripts/angular/work_packages/directives/spent-hours-directive.js @@ -0,0 +1,45 @@ +//-- copyright +// OpenProject is a project management system. +// Copyright (C) 2012-2014 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. +//++ + +angular.module('openproject.workPackages.directives') + +.directive('spentHours', ['I18n', 'PathHelper', function(I18n, PathHelper) { + return { + restrict: 'E', + templateUrl: '/templates/work_packages/spent_hours.html', + link: function(scope, element, attributes) { + scope.spentHours = scope.workPackage.props.spentHours; + scope.spentHoursUnit = I18n.t('js.label_hours'); + scope.linkToSpentHours = PathHelper.timeEntriesPath(null, scope.workPackage.props.id); + + if (scope.spentHours == 1) { + scope.spentHoursUnit = I18n.t('js.label_hour'); + } + } + }; +}]); diff --git a/app/views/hooks/costs/_view_work_package_overview_attributes.html.erb b/app/views/hooks/costs/_view_work_package_overview_attributes.html.erb index d4daa1f53d..429d58514f 100644 --- a/app/views/hooks/costs/_view_work_package_overview_attributes.html.erb +++ b/app/views/hooks/costs/_view_work_package_overview_attributes.html.erb @@ -21,4 +21,5 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. <%= javascript_include_tag 'angular/openproject-costs-app.js' %> <%= javascript_include_tag 'angular/work_packages/directives/summarized-cost-entries-directive.js' %> <%= javascript_include_tag 'angular/work_packages/directives/cost-object-directive.js' %> +<%= javascript_include_tag 'angular/work_packages/directives/spent-hours-directive.js' %> <%= stylesheet_link_tag 'costs/costs.css' %> diff --git a/config/locales/js-de.yml b/config/locales/js-de.yml index 1e35610608..5c9093f4fb 100644 --- a/config/locales/js-de.yml +++ b/config/locales/js-de.yml @@ -38,6 +38,8 @@ de: work_packages: properties: costObject: "Budget" - spentHours: "Aufgewendete Zeit" + spentHoursLinked: "Aufgewendete Zeit" overallCosts: "Gesamtkosten" spentUnits: "Gebuchte Einheiten" + label_hour: "Stunde" + label_hours: "Stunden" diff --git a/config/locales/js-en.yml b/config/locales/js-en.yml index fa7fb92269..2863e11d33 100644 --- a/config/locales/js-en.yml +++ b/config/locales/js-en.yml @@ -38,6 +38,8 @@ en: work_packages: properties: costObject: "Budget" - spentHours: "Spent time" + spentHoursLinked: "Spent time" overallCosts: "Overall costs" spentUnits: "Spent units" + label_hour: "Hour" + label_hours: "Hours" diff --git a/lib/open_project/costs/hooks/work_packages_overview_attributes.rb b/lib/open_project/costs/hooks/work_packages_overview_attributes.rb index fa79548b63..ac6dc9ffcf 100644 --- a/lib/open_project/costs/hooks/work_packages_overview_attributes.rb +++ b/lib/open_project/costs/hooks/work_packages_overview_attributes.rb @@ -29,7 +29,7 @@ module OpenProject::Costs::Hooks attributes.reject!{ |attribute| attribute == :spentTime } attributes << :costObject - attributes << :spentHours if user_allowed_to?(project, :view_time_entries, :view_own_time_entries) + attributes << :spentHoursLinked if user_allowed_to?(project, :view_time_entries, :view_own_time_entries) attributes << :overallCosts attributes << :spentUnits if user_allowed_to?(project, :view_cost_entries, :view_own_cost_entries) diff --git a/public/templates/work_packages/spent_hours.html b/public/templates/work_packages/spent_hours.html new file mode 100644 index 0000000000..712303eea7 --- /dev/null +++ b/public/templates/work_packages/spent_hours.html @@ -0,0 +1,5 @@ + + + {{ spentHours }} {{ spentHoursUnit }} + + From f9fe0d1cbfe5ee73d52005240c158c0260bf0cf3 Mon Sep 17 00:00:00 2001 From: Hagen Schink Date: Wed, 13 Aug 2014 12:18:24 +0200 Subject: [PATCH 4/7] Load angular templates by asset pipeline --- .../directives/cost-object-directive.js | 2 +- .../directives/spent-hours-directive.js | 2 +- .../summarized-cost-entries-directive.js | 2 +- .../templates/work_packages/cost_object.html | 0 .../templates/work_packages/spent_hours.html | 0 .../summarized_cost_entries.html | 0 config/initializers/non_digest_assets.rb | 22 +++++++++++++++++++ lib/open_project/costs/engine.rb | 5 ++++- 8 files changed, 29 insertions(+), 4 deletions(-) rename {public => app/assets}/templates/work_packages/cost_object.html (100%) rename {public => app/assets}/templates/work_packages/spent_hours.html (100%) rename {public => app/assets}/templates/work_packages/summarized_cost_entries.html (100%) create mode 100644 config/initializers/non_digest_assets.rb diff --git a/app/assets/javascripts/angular/work_packages/directives/cost-object-directive.js b/app/assets/javascripts/angular/work_packages/directives/cost-object-directive.js index 85891d5217..3180af323d 100644 --- a/app/assets/javascripts/angular/work_packages/directives/cost-object-directive.js +++ b/app/assets/javascripts/angular/work_packages/directives/cost-object-directive.js @@ -31,7 +31,7 @@ angular.module('openproject.workPackages.directives') .directive('costObject', [function() { return { restrict: 'E', - templateUrl: '/templates/work_packages/cost_object.html', + templateUrl: '/assets/work_packages/cost_object.html', link: function(scope, element, attributes) { scope.costObject = scope.workPackage.embedded.costObject; scope.linkToCostObject = '/cost_objects/' + scope.costObject.props.id; diff --git a/app/assets/javascripts/angular/work_packages/directives/spent-hours-directive.js b/app/assets/javascripts/angular/work_packages/directives/spent-hours-directive.js index 0eac49b805..1e872c59bb 100644 --- a/app/assets/javascripts/angular/work_packages/directives/spent-hours-directive.js +++ b/app/assets/javascripts/angular/work_packages/directives/spent-hours-directive.js @@ -31,7 +31,7 @@ angular.module('openproject.workPackages.directives') .directive('spentHours', ['I18n', 'PathHelper', function(I18n, PathHelper) { return { restrict: 'E', - templateUrl: '/templates/work_packages/spent_hours.html', + templateUrl: '/assets/work_packages/spent_hours.html', link: function(scope, element, attributes) { scope.spentHours = scope.workPackage.props.spentHours; scope.spentHoursUnit = I18n.t('js.label_hours'); diff --git a/app/assets/javascripts/angular/work_packages/directives/summarized-cost-entries-directive.js b/app/assets/javascripts/angular/work_packages/directives/summarized-cost-entries-directive.js index c8db3f3a6c..b4d6ab3d82 100644 --- a/app/assets/javascripts/angular/work_packages/directives/summarized-cost-entries-directive.js +++ b/app/assets/javascripts/angular/work_packages/directives/summarized-cost-entries-directive.js @@ -31,7 +31,7 @@ angular.module('openproject.workPackages.directives') .directive('summarizedCostEntries', ['PathHelper', function(PathHelper) { return { restrict: 'E', - templateUrl: '/templates/work_packages/summarized_cost_entries.html', + templateUrl: '/assets/work_packages/summarized_cost_entries.html', link: function(scope, element, attributes) { if (scope.workPackage.embedded.summarizedCostEntries) { scope.costTypes = scope.workPackage.embedded.summarizedCostEntries; diff --git a/public/templates/work_packages/cost_object.html b/app/assets/templates/work_packages/cost_object.html similarity index 100% rename from public/templates/work_packages/cost_object.html rename to app/assets/templates/work_packages/cost_object.html diff --git a/public/templates/work_packages/spent_hours.html b/app/assets/templates/work_packages/spent_hours.html similarity index 100% rename from public/templates/work_packages/spent_hours.html rename to app/assets/templates/work_packages/spent_hours.html diff --git a/public/templates/work_packages/summarized_cost_entries.html b/app/assets/templates/work_packages/summarized_cost_entries.html similarity index 100% rename from public/templates/work_packages/summarized_cost_entries.html rename to app/assets/templates/work_packages/summarized_cost_entries.html diff --git a/config/initializers/non_digest_assets.rb b/config/initializers/non_digest_assets.rb new file mode 100644 index 0000000000..84692fd3fb --- /dev/null +++ b/config/initializers/non_digest_assets.rb @@ -0,0 +1,22 @@ +#-- copyright +# OpenProject Costs Plugin +# +# Copyright (C) 2009 - 2014 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. +# +# 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. +#++ + +NonStupidDigestAssets.whitelist += [ + /work_packages\/.*/ +] diff --git a/lib/open_project/costs/engine.rb b/lib/open_project/costs/engine.rb index 65c336e606..0abdaee09b 100644 --- a/lib/open_project/costs/engine.rb +++ b/lib/open_project/costs/engine.rb @@ -155,7 +155,10 @@ module OpenProject::Costs angular/work_packages/directives/cost-object-directive.js angular/openproject-costs-app.js costs/costs.css - costs/costs.js) + costs/costs.js + work_packages/cost_object.html + work_packages/spent_hours.html + work_packages/summarized_cost_entries.html) initializer "costs.register_hooks" do require 'open_project/costs/hooks' From cced80616b44c6d81034a65d6e843228e5a3aa3f Mon Sep 17 00:00:00 2001 From: Hagen Schink Date: Tue, 19 Aug 2014 08:09:00 +0200 Subject: [PATCH 5/7] Correct 'hour' labels --- config/locales/js-en.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/locales/js-en.yml b/config/locales/js-en.yml index 2863e11d33..0fb299c985 100644 --- a/config/locales/js-en.yml +++ b/config/locales/js-en.yml @@ -41,5 +41,5 @@ en: spentHoursLinked: "Spent time" overallCosts: "Overall costs" spentUnits: "Spent units" - label_hour: "Hour" - label_hours: "Hours" + label_hour: "hour" + label_hours: "hours" From dfbd4e3912cea90b50100a79637a0b2ec7e0396a Mon Sep 17 00:00:00 2001 From: Hagen Schink Date: Tue, 19 Aug 2014 08:19:44 +0200 Subject: [PATCH 6/7] Fix copyright header --- app/assets/stylesheets/costs/costs.css.sass | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/app/assets/stylesheets/costs/costs.css.sass b/app/assets/stylesheets/costs/costs.css.sass index c5dac24146..1b90cc8a32 100644 --- a/app/assets/stylesheets/costs/costs.css.sass +++ b/app/assets/stylesheets/costs/costs.css.sass @@ -1,25 +1,11 @@ /*-- copyright - * OpenProject Backlogs Plugin + * OpenProject Costs Plugin * - * Copyright (C)2013 the OpenProject Foundation (OPF) - * Copyright (C)2011 Stephan Eckardt, Tim Felgentreff, Marnen Laibow-Koser, Sandro Munda - * Copyright (C)2010-2011 friflaj - * Copyright (C)2010 Maxime Guilbot, Andrew Vit, Joakim Kolsjö, ibussieres, Daniel Passos, Jason Vasquez, jpic, Emiliano Heyns - * Copyright (C)2009-2010 Mark Maglana - * Copyright (C)2009 Joe Heck, Nate Lowrie - * - * 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 Backlogs is a derivative work based on ChiliProject Backlogs. - * The copyright follows: - * Copyright (C) 2010-2011 - Emiliano Heyns, Mark Maglana, friflaj - * Copyright (C) 2011 - Jens Ulferts, Gregor Schmidt - Finn GmbH - Berlin, Germany + * Copyright (C) 2009 - 2014 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 - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. + * version 3. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -30,7 +16,6 @@ * 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. */ @import costs/costs_legacy From 4674f7373aba7725812effcb7caa1995c0f4fea4 Mon Sep 17 00:00:00 2001 From: Hagen Schink Date: Tue, 19 Aug 2014 08:20:02 +0200 Subject: [PATCH 7/7] Use ',' (comma) as cost type separator --- .../costs/_summarized_cost_entries.css.sass | 23 +++++++++++++++++++ app/assets/stylesheets/costs/costs.css.sass | 1 + .../summarized_cost_entries.html | 2 +- 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 app/assets/stylesheets/costs/_summarized_cost_entries.css.sass diff --git a/app/assets/stylesheets/costs/_summarized_cost_entries.css.sass b/app/assets/stylesheets/costs/_summarized_cost_entries.css.sass new file mode 100644 index 0000000000..ad6d4e0ca8 --- /dev/null +++ b/app/assets/stylesheets/costs/_summarized_cost_entries.css.sass @@ -0,0 +1,23 @@ +/*-- copyright + * OpenProject Costs Plugin + * + * Copyright (C) 2009 - 2014 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. + * + * 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. + * + */ + +.costs.costTypes + .separator + margin-left: -0.2em diff --git a/app/assets/stylesheets/costs/costs.css.sass b/app/assets/stylesheets/costs/costs.css.sass index 1b90cc8a32..d385c9f5c6 100644 --- a/app/assets/stylesheets/costs/costs.css.sass +++ b/app/assets/stylesheets/costs/costs.css.sass @@ -19,3 +19,4 @@ */ @import costs/costs_legacy +@import costs/summarized_cost_entries diff --git a/app/assets/templates/work_packages/summarized_cost_entries.html b/app/assets/templates/work_packages/summarized_cost_entries.html index 15529060c7..e08348c62b 100644 --- a/app/assets/templates/work_packages/summarized_cost_entries.html +++ b/app/assets/templates/work_packages/summarized_cost_entries.html @@ -7,6 +7,6 @@ {{ costType.props.unitPlural }} - - + ,