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
[39492] Create work packages in team planner split view with defaults
Oliver Günther45cbaf581078
diff --git a/frontend/src/app/features/team-planner/team-planner/planner/team-planner.component.ts b/frontend/src/app/features/team-planner/team-planner/planner/team-planner.component.tsindex ad996d72593..985bbaf2786 100644--- a/frontend/src/app/features/team-planner/team-planner/planner/team-planner.component.ts+++ b/frontend/src/app/features/team-planner/team-planner/planner/team-planner.component.ts@@ -2,6 +2,7 @@ import {ChangeDetectionStrategy,Component,ElementRef,+ HostListener,OnDestroy,OnInit,TemplateRef,@@ -9,6 +10,7 @@ import {} from '@angular/core';import {CalendarOptions,+ DateSelectArg,EventInput,} from '@fullcalendar/core';import {@@ -17,14 +19,15 @@ import {} from 'rxjs';import {debounceTime,- mergeMap,- map,- filter,distinctUntilChanged,+ filter,+ map,+ mergeMap,} from 'rxjs/operators';import { EventClickArg } from '@fullcalendar/common';import { StateService } from '@uirouter/angular';import resourceTimelinePlugin from '@fullcalendar/resource-timeline';+import interactionPlugin from '@fullcalendar/interaction';import { FullCalendarComponent } from '@fullcalendar/angular';import { I18nService } from 'core-app/core/i18n/i18n.service';import { ConfigurationService } from 'core-app/core/config/configuration.service';@@ -194,8 +197,11 @@ export class TeamPlannerComponent extends UntilDestroyedMixin implements OnInit,this.calendarOptions$.next(this.calendar.calendarOptions({schedulerLicenseKey: 'GPL-My-Project-Is-Open-Source',+ editable: false,+ selectable: true,plugins: [resourceTimelinePlugin,+ interactionPlugin,],titleFormat: {year: 'numeric',@@ -225,6 +231,7 @@ export class TeamPlannerComponent extends UntilDestroyedMixin implements OnInit,events: this.calendarEventsFunction.bind(this) as unknown,resources: [],eventClick: this.openSplitView.bind(this) as unknown,+ select: this.handleDateClicked.bind(this) as unknown,resourceLabelContent: (data:ResourceLabelContentArg) => this.renderTemplate(this.resourceContent, data.resource.id, data),resourceLabelWillUnmount: (data:ResourceLabelContentArg) => this.unrenderTemplate(data.resource.id),} as CalendarOptions),@@ -331,4 +338,39 @@ export class TeamPlannerComponent extends UntilDestroyedMixin implements OnInit,}).filter((event) => !!event) as EventInput[];}++ private handleDateClicked(info:DateSelectArg) {+ this.openNewSplitCreate(+ info.startStr,+ // end date is exclusive+ moment(info.end).subtract(1, 'd').format('YYYY-MM-DD'),+ info.resource?.id || '',+ );+ }++ // Allow triggering the select from a event, as+ // this is otherwise not testable from selenium+ @HostListener(+ 'document:teamPlannerSelectDate',+ ['$event.detail.start', '$event.detail.end', '$event.detail.assignee'],+ )+ openNewSplitCreate(start:string, end:string, resourceHref:string):void {+ const defaults = {+ startDate: start,+ dueDate: end,+ _links: {+ assignee: {+ href: resourceHref,+ },+ },+ };++ void this.$state.go(+ splitViewRoute(this.$state, 'new'),+ {+ defaults,+ tabIdentifier: 'overview',+ },+ );+ }}diff --git a/frontend/src/app/features/work-packages/components/wp-new/wp-create.component.ts b/frontend/src/app/features/work-packages/components/wp-new/wp-create.component.tsindex 76878c43d01..f15fbc0f9be 100644--- a/frontend/src/app/features/work-packages/components/wp-new/wp-create.component.ts+++ b/frontend/src/app/features/work-packages/components/wp-new/wp-create.component.ts@@ -27,9 +27,16 @@//++import {- ChangeDetectorRef, Directive, Injector, OnInit, ViewChild,+ ChangeDetectorRef,+ Directive,+ Injector,+ OnInit,+ ViewChild,} from '@angular/core';-import { StateService, Transition } from '@uirouter/core';+import {+ StateService,+ Transition,+} from '@uirouter/core';import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';import { States } from 'core-app/core/states/states.service';import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';@@ -178,9 +185,8 @@ export class WorkPackageCreateComponent extends UntilDestroyedMixin implements O}protected createdWorkPackage() {- const defaults:HalSource = {- _links: {},- };+ const defaults:HalSource = (this.stateParams.defaults as HalSource) || {};+ defaults._links = defaults._links || {};const type = this.stateParams.type ? parseInt(this.stateParams.type) : undefined;const parent = this.stateParams.parent_id ? parseInt(this.stateParams.parent_id) : undefined;diff --git a/frontend/src/app/features/work-packages/routing/split-view-routes.helper.ts b/frontend/src/app/features/work-packages/routing/split-view-routes.helper.tsindex d4c8cfe001f..13f343320e7 100644--- a/frontend/src/app/features/work-packages/routing/split-view-routes.helper.ts+++ b/frontend/src/app/features/work-packages/routing/split-view-routes.helper.ts@@ -33,7 +33,8 @@ import { StateService } from '@uirouter/angular';** @param state State service*/-export function splitViewRoute(state:StateService):string {- const baseRoute = state.current.data.baseRoute || '';- return `${baseRoute}.details`;+export function splitViewRoute(state:StateService, target:'details'|'new' = 'details'):string {+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment+ const baseRoute:string = state.current.data.baseRoute || '';+ return `${baseRoute}.${target}`;}diff --git a/frontend/src/app/features/work-packages/routing/split-view-routes.template.ts b/frontend/src/app/features/work-packages/routing/split-view-routes.template.tsindex 33511bd913f..d6b0ed1abfb 100644--- a/frontend/src/app/features/work-packages/routing/split-view-routes.template.ts+++ b/frontend/src/app/features/work-packages/routing/split-view-routes.template.ts@@ -104,6 +104,11 @@ export function makeSplitViewRoutes(baseRoute:string,name: `${routeName}.new`,url: '/create_new?{type:[0-9]+}&{parent_id:[0-9]+}',reloadOnSearch: false,+ params: {+ defaults: {+ value: null,+ },+ },data: {partition: '-split',allowMovingInEditMode: true,diff --git a/frontend/src/app/features/work-packages/routing/work-packages-routes.ts b/frontend/src/app/features/work-packages/routing/work-packages-routes.tsindex 2d8e59d3b9e..385c334e5b1 100644--- a/frontend/src/app/features/work-packages/routing/work-packages-routes.ts+++ b/frontend/src/app/features/work-packages/routing/work-packages-routes.ts@@ -65,6 +65,11 @@ export const WORK_PACKAGES_ROUTES:Ng2StateDeclaration[] = [url: '/new?type&parent_id',component: WorkPackageNewFullViewComponent,reloadOnSearch: false,+ params: {+ defaults: {+ value: null,+ },+ },data: {baseRoute: 'work-packages',allowMovingInEditMode: true,diff --git a/modules/team_planner/spec/features/shared_context.rb b/modules/team_planner/spec/features/shared_context.rbnew file mode 100644index 00000000000..a49c2cc548b--- /dev/null+++ b/modules/team_planner/spec/features/shared_context.rb@@ -0,0 +1,52 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2021 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.+#++++require 'spec_helper'+require_relative '../support/pages/team_planner'++shared_context 'with team planner full access' do+ shared_let(:project) do+ FactoryBot.create(:project, enabled_module_names: %w[work_package_tracking team_planner_view])+ end++ shared_let(:user) do+ FactoryBot.create :user,+ member_in_project: project,+ member_with_permissions: %w[+ view_work_packages edit_work_packages add_work_packages+ view_team_planner manage_team_planner+ ]+ end++ let(:team_planner) { ::Pages::TeamPlanner.new project }+ let(:filters) { team_planner.filters }++ current_user { user }+enddiff --git a/modules/team_planner/spec/features/team_planner_create_spec.rb b/modules/team_planner/spec/features/team_planner_create_spec.rbnew file mode 100644index 00000000000..dc96daed95d--- /dev/null+++ b/modules/team_planner/spec/features/team_planner_create_spec.rb@@ -0,0 +1,83 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2021 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.+#++++require 'spec_helper'+require_relative './shared_context'++describe 'Team planner create new work package', type: :feature, js: true do+ include_context 'with team planner full access'++ let(:type_task) { FactoryBot.create :type_task }+ let!(:status) { FactoryBot.create :default_status }+ let!(:priority) { FactoryBot.create :default_priority }++ before do+ project.types << type_task+ end++ it 'can create a new work package' do+ team_planner.visit!++ team_planner.expect_assignee(user, present: false)++ retry_block do+ team_planner.click_add_user+ page.find('[data-qa-selector="tp-add-assignee"] input')+ team_planner.select_user_to_add user.name+ end++ start_of_week = Time.zone.today.beginning_of_week(:sunday)+ team_planner.expect_assignee(user)+ split_create = team_planner.add_item "/api/v3/users/#{user.id}",+ start_of_week.iso8601,+ start_of_week.iso8601++ subject = split_create.edit_field(:subject)+ subject.set_value 'Newly planned task'++ split_create.save!++ split_create.expect_and_dismiss_toaster(message: I18n.t('js.notice_successful_create'))++ split_create.expect_attributes(+ combinedDate: "#{start_of_week.strftime('%m/%d/%Y')} - #{start_of_week.strftime('%m/%d/%Y')}",+ assignee: user.name+ )++ wp = WorkPackage.last+ expect(wp.subject).to eq 'Newly planned task'+ expect(wp.start_date).to eq start_of_week+ expect(wp.due_date).to eq start_of_week++ team_planner.within_lane(user) do+ team_planner.expect_event wp+ end+ end+enddiff --git a/modules/team_planner/spec/features/team_planner_spec.rb b/modules/team_planner/spec/features/team_planner_spec.rbindex ffa98ff779f..3dcd040b1e0 100644--- a/modules/team_planner/spec/features/team_planner_spec.rb+++ b/modules/team_planner/spec/features/team_planner_spec.rb@@ -29,25 +29,10 @@#++require 'spec_helper'-require_relative '../support/pages/team_planner'+require_relative './shared_context'describe 'Team planner', type: :feature, js: true do- shared_let(:project) do- FactoryBot.create(:project, enabled_module_names: %w[work_package_tracking team_planner_view])- end-- shared_let(:user) do- FactoryBot.create :user,- member_in_project: project,- member_with_permissions: %w[- view_work_packages edit_work_packages view_team_planner manage_team_planner- ]- end-- let(:team_planner) { ::Pages::TeamPlanner.new project }- let(:filters) { team_planner.filters }-- current_user { user }+ include_context 'with team planner full access'it 'hides the internally used filters' dovisit project_path(project)diff --git a/modules/team_planner/spec/support/pages/team_planner.rb b/modules/team_planner/spec/support/pages/team_planner.rbindex 7bcb34e5003..455a99dd608 100644--- a/modules/team_planner/spec/support/pages/team_planner.rb+++ b/modules/team_planner/spec/support/pages/team_planner.rb@@ -55,6 +55,25 @@ module Pagesexpect(page).to have_conditional_selector(present, '.fc-resource', text: name, wait: 10)end+ def add_item(assignee, start_date, end_date)+ script = <<~JS+ var event = new CustomEvent(+ 'teamPlannerSelectDate',+ {+ detail: {+ assignee: arguments[0],+ start: arguments[1],+ end: arguments[2]+ }+ });++ document.dispatchEvent(event);+ JS++ page.execute_script(script, assignee, start_date, end_date)+ ::Pages::SplitWorkPackageCreate.new project: project+ end+def remove_assignee(user)page.find(%([data-qa-remove-assignee="#{user.id}"])).clickend