From 1ec96c006c840d45d8435959a09e6be4cf26bcb1 Mon Sep 17 00:00:00 2001 From: Wieland Lindenthal Date: Mon, 8 Apr 2019 17:00:51 +0200 Subject: [PATCH] Create a BCF module for the frontend and create first tiny component to show viewpoints --- .../wp-single-view/wp-single-view.html | 4 ++ .../bcf-wp-single-view.component.html | 2 + .../bcf-wp-single-view.component.sass | 0 .../bcf-wp-single-view.component.ts | 31 ++++++++++ .../app/modules/bcf/openproject-bcf.module.ts | 51 ++++++++++++++++ .../openproject-work-packages.module.ts | 4 ++ modules/bcf/lib/open_project/bcf/engine.rb | 17 ++++++ .../work_package_representer_spec.rb | 60 +++++++++++++++++++ .../bcf/spec/factories/bcf_issue_factory.rb | 42 +++++++++++++ .../bcf_viewpoint_attachment_factory.rb | 48 +++++++++++++++ .../spec/factories/bcf_viewpoint_factory.rb | 42 +++++++++++++ .../spec/factories/cost_object_factory.rb | 2 +- 12 files changed, 302 insertions(+), 1 deletion(-) create mode 100644 frontend/src/app/modules/bcf/bcf-wp-single-view/bcf-wp-single-view.component.html create mode 100644 frontend/src/app/modules/bcf/bcf-wp-single-view/bcf-wp-single-view.component.sass create mode 100644 frontend/src/app/modules/bcf/bcf-wp-single-view/bcf-wp-single-view.component.ts create mode 100644 frontend/src/app/modules/bcf/openproject-bcf.module.ts create mode 100644 modules/bcf/spec/api/v3/work_packages/work_package_representer_spec.rb create mode 100644 modules/bcf/spec/factories/bcf_issue_factory.rb create mode 100644 modules/bcf/spec/factories/bcf_viewpoint_attachment_factory.rb create mode 100644 modules/bcf/spec/factories/bcf_viewpoint_factory.rb diff --git a/frontend/src/app/components/work-packages/wp-single-view/wp-single-view.html b/frontend/src/app/components/work-packages/wp-single-view/wp-single-view.html index ac42999217..a2d895b7bb 100644 --- a/frontend/src/app/components/work-packages/wp-single-view/wp-single-view.html +++ b/frontend/src/app/components/work-packages/wp-single-view/wp-single-view.html @@ -74,6 +74,10 @@ +
+ +
+
diff --git a/frontend/src/app/modules/bcf/bcf-wp-single-view/bcf-wp-single-view.component.html b/frontend/src/app/modules/bcf/bcf-wp-single-view/bcf-wp-single-view.component.html new file mode 100644 index 0000000000..d79d5ac2d5 --- /dev/null +++ b/frontend/src/app/modules/bcf/bcf-wp-single-view/bcf-wp-single-view.component.html @@ -0,0 +1,2 @@ +

BCF

+ diff --git a/frontend/src/app/modules/bcf/bcf-wp-single-view/bcf-wp-single-view.component.sass b/frontend/src/app/modules/bcf/bcf-wp-single-view/bcf-wp-single-view.component.sass new file mode 100644 index 0000000000..e69de29bb2 diff --git a/frontend/src/app/modules/bcf/bcf-wp-single-view/bcf-wp-single-view.component.ts b/frontend/src/app/modules/bcf/bcf-wp-single-view/bcf-wp-single-view.component.ts new file mode 100644 index 0000000000..c6dc5318b0 --- /dev/null +++ b/frontend/src/app/modules/bcf/bcf-wp-single-view/bcf-wp-single-view.component.ts @@ -0,0 +1,31 @@ +import {Component, Injector, Input, OnDestroy, OnInit} from "@angular/core"; +import {I18nService} from "core-app/modules/common/i18n/i18n.service"; +import {StateService} from "@uirouter/core"; +import {WorkPackageResource} from "core-app/modules/hal/resources/work-package-resource"; + +@Component({ + selector: 'bcf-wp-single-view', + templateUrl: './bcf-wp-single-view.component.html', + styleUrls: ['./bcf-wp-single-view.component.sass'] +}) + +export class BcfWpSingleViewComponent implements OnInit, OnDestroy { + @Input() workPackage:WorkPackageResource; + + public text = { + }; + + + constructor(public readonly state:StateService, + private readonly I18n:I18nService, + private readonly injector:Injector) { + } + + ngOnInit():void { + // TODO + } + + ngOnDestroy():void { + // Nothing to do. + } +} diff --git a/frontend/src/app/modules/bcf/openproject-bcf.module.ts b/frontend/src/app/modules/bcf/openproject-bcf.module.ts new file mode 100644 index 0000000000..9eec6331f5 --- /dev/null +++ b/frontend/src/app/modules/bcf/openproject-bcf.module.ts @@ -0,0 +1,51 @@ +// -- 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-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. +// ++ + +import {NgModule} from '@angular/core'; +import {OpenprojectCommonModule} from "core-app/modules/common/openproject-common.module"; +import {OpenprojectWorkPackagesModule} from "core-app/modules/work_packages/openproject-work-packages.module"; +import {BcfWpSingleViewComponent} from "core-app/modules/bcf/bcf-wp-single-view/bcf-wp-single-view.component"; + +@NgModule({ + imports: [ + OpenprojectCommonModule, + ], + providers: [ + ], + declarations: [ + BcfWpSingleViewComponent, + ], + exports: [ + BcfWpSingleViewComponent, + ], + entryComponents: [ + ] +}) +export class OpenprojectBcfModule { +} + diff --git a/frontend/src/app/modules/work_packages/openproject-work-packages.module.ts b/frontend/src/app/modules/work_packages/openproject-work-packages.module.ts index 66f03d8b35..37f81b5fd2 100644 --- a/frontend/src/app/modules/work_packages/openproject-work-packages.module.ts +++ b/frontend/src/app/modules/work_packages/openproject-work-packages.module.ts @@ -156,6 +156,8 @@ import {WorkPackageCardViewComponent} from "core-components/wp-card-view/wp-card import {WorkPackageIsolatedQuerySpaceDirective} from "core-app/modules/work_packages/query-space/wp-isolated-query-space.directive"; import {WorkPackageDmService} from "core-app/modules/hal/dm-services/work-package-dm.service"; import {WorkPackageRelationsService} from "core-components/wp-relations/wp-relations.service"; +import {BcfWpSingleViewComponent} from "core-app/modules/bcf/bcf-wp-single-view/bcf-wp-single-view.component"; +import {OpenprojectBcfModule} from "core-app/modules/bcf/openproject-bcf.module"; @NgModule({ imports: [ @@ -170,6 +172,8 @@ import {WorkPackageRelationsService} from "core-components/wp-relations/wp-relat OpenprojectAttachmentsModule, + OpenprojectBcfModule, + // Work package custom actions //WpCustomActionsModule, DynamicModule.withComponents([WorkPackageFormAttributeGroupComponent, WorkPackageChildrenQueryComponent]) diff --git a/modules/bcf/lib/open_project/bcf/engine.rb b/modules/bcf/lib/open_project/bcf/engine.rb index 45d35b20ef..37a6f074bd 100644 --- a/modules/bcf/lib/open_project/bcf/engine.rb +++ b/modules/bcf/lib/open_project/bcf/engine.rb @@ -36,6 +36,23 @@ module OpenProject::Bcf patch_with_namespace :BasicData, :SettingSeeder + extend_api_response(:v3, :work_packages, :work_package) do + property :bcf, + exec_context: :decorator, + getter: ->(*) { + issue = represented.bcf_issue + bcf = {} + bcf[:viewpoints] = issue.viewpoints.map do |viewpoint| + attachment_path(viewpoint.snapshot.id) + end + bcf + }, + if: ->(*) { + represented.bcf_issue.present? + } + + end + extend_api_response(:v3, :work_packages, :work_package_collection) do require_relative 'patches/api/v3/export_formats' diff --git a/modules/bcf/spec/api/v3/work_packages/work_package_representer_spec.rb b/modules/bcf/spec/api/v3/work_packages/work_package_representer_spec.rb new file mode 100644 index 0000000000..e26436ab6a --- /dev/null +++ b/modules/bcf/spec/api/v3/work_packages/work_package_representer_spec.rb @@ -0,0 +1,60 @@ +#-- 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. +#++ + +require 'spec_helper' + +describe ::API::V3::WorkPackages::WorkPackageRepresenter do + include API::V3::Utilities::PathHelper + + let(:project) { FactoryBot.create(:project) } + let(:role) do + FactoryBot.create(:role, permissions: [:view_linked_issues, + :view_work_packages]) + end + let(:user) do + FactoryBot.create(:user, + member_in_project: project, + member_through_role: role) + end + let(:bcf_issue) do + FactoryBot.create(:bcf_issue) + end + let(:work_package) do + FactoryBot.create(:work_package, + project_id: project.id, + bcf_issue: bcf_issue) + end + let(:representer) do + described_class.new(work_package, + current_user: user, + embed_links: true) + end + + before(:each) do + allow(User).to receive(:current).and_return user + end + + subject(:generated) { representer.to_json } + + describe 'with BCF issues' do + it { is_expected.to have_json_path('bcf') } + it { is_expected.to have_json_path('bcf/viewpoints') } + it { is_expected.to be_json_eql(["/attachments/#{bcf_issue.viewpoints.first.id}"].to_json).at_path('bcf/viewpoints') } + end +end diff --git a/modules/bcf/spec/factories/bcf_issue_factory.rb b/modules/bcf/spec/factories/bcf_issue_factory.rb new file mode 100644 index 0000000000..e9b20a91a7 --- /dev/null +++ b/modules/bcf/spec/factories/bcf_issue_factory.rb @@ -0,0 +1,42 @@ +#-- copyright +# OpenProject Backlogs Plugin +# +# Copyright (C)2013-2014 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 +# +# 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. +#++ + +FactoryBot.define do + factory :bcf_issue, class: ::Bcf::Issue do + after(:create) do |issue| + create(:bcf_viewpoint, issue: issue) + end + end +end diff --git a/modules/bcf/spec/factories/bcf_viewpoint_attachment_factory.rb b/modules/bcf/spec/factories/bcf_viewpoint_attachment_factory.rb new file mode 100644 index 0000000000..7bce9fab9b --- /dev/null +++ b/modules/bcf/spec/factories/bcf_viewpoint_attachment_factory.rb @@ -0,0 +1,48 @@ +#-- copyright +# OpenProject Backlogs Plugin +# +# Copyright (C)2013-2014 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 +# +# 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. +#++ + +FactoryBot.define do + factory :bcf_viewpoint_attachment, class: Attachment do + description "snapshot" + filename "snapshot.jpg" + content_type "image/jpeg" + author User.current + file do + OpenProject::Files.create_uploaded_file name: filename, + content_type: content_type, + binary: true + end + end +end diff --git a/modules/bcf/spec/factories/bcf_viewpoint_factory.rb b/modules/bcf/spec/factories/bcf_viewpoint_factory.rb new file mode 100644 index 0000000000..5f28fac368 --- /dev/null +++ b/modules/bcf/spec/factories/bcf_viewpoint_factory.rb @@ -0,0 +1,42 @@ +#-- copyright +# OpenProject Backlogs Plugin +# +# Copyright (C)2013-2014 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 +# +# 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. +#++ + +FactoryBot.define do + factory :bcf_viewpoint, class: ::Bcf::Viewpoint do + after(:create) do |viewpoint| + create(:bcf_viewpoint_attachment, container: viewpoint) + end + end +end diff --git a/modules/costs/spec/factories/cost_object_factory.rb b/modules/costs/spec/factories/cost_object_factory.rb index aa383cd229..78ed16b249 100644 --- a/modules/costs/spec/factories/cost_object_factory.rb +++ b/modules/costs/spec/factories/cost_object_factory.rb @@ -18,7 +18,7 @@ #++ FactoryBot.define do - factory :cost_object do + factory :cost_object do subject { 'Some Cost Object' } description { 'Some costs' } kind { 'VariableCostObject' }