Skip to content

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

[40533] Add cview to team planner

Oliver Günther5bd5709f0b51
diff --git a/frontend/src/app/features/calendar/op-calendar.service.ts b/frontend/src/app/features/calendar/op-calendar.service.ts
index 909e5c7ba2d..c9ad6a0f3bd 100644
--- a/frontend/src/app/features/calendar/op-calendar.service.ts
+++ b/frontend/src/app/features/calendar/op-calendar.service.ts
@@ -229,6 +229,10 @@ export class OpCalendarService extends UntilDestroyedMixin {
.toPromise();
}
+ public get initialView():string|undefined {
+ return this.urlParams.cview as string|undefined;
+ }
+
private defaultOptions():CalendarOptions {
return {
editable: false,
@@ -305,10 +309,6 @@ export class OpCalendarService extends UntilDestroyedMixin {
return undefined;
}
- private get initialView():string|undefined {
- return this.urlParams.cview as string|undefined;
- }
-
private updateDateParam(dates:DatesSetArg) {
void this.$state.go(
'.',
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.ts
index 4730c23ce2d..6d093acb14d 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
@@ -105,6 +105,7 @@ export class TeamPlannerComponent extends UntilDestroyedMixin implements OnInit,
add_assignee: this.I18n.t('js.team_planner.add_assignee'),
remove_assignee: this.I18n.t('js.team_planner.remove_assignee'),
noData: this.I18n.t('js.team_planner.no_data'),
+ two_weeks: this.I18n.t('js.team_planner.two_weeks'),
};
principals$ = this.principalIds$
@@ -214,9 +215,14 @@ export class TeamPlannerComponent extends UntilDestroyedMixin implements OnInit,
month: 'long',
day: 'numeric',
},
- initialView: 'resourceTimelineWeekDaysOnly',
+ initialView: (this.calendar.initialView || 'resourceTimelineWeek') as string,
+ headerToolbar: {
+ left: 'prev,next today',
+ center: 'title',
+ right: 'resourceTimelineWeek,resourceTimelineTwoWeeks,resourceTimelineMonth',
+ },
views: {
- resourceTimelineWeekDaysOnly: {
+ resourceTimelineWeek: {
type: 'resourceTimeline',
duration: { weeks: 1 },
slotDuration: { days: 1 },
@@ -233,6 +239,41 @@ export class TeamPlannerComponent extends UntilDestroyedMixin implements OnInit,
},
],
},
+ resourceTimelineTwoWeeks: {
+ type: 'resourceTimeline',
+ buttonText: this.text.two_weeks,
+ duration: { weeks: 2 },
+ slotDuration: { days: 1 },
+ slotLabelFormat: [
+ {
+ weekday: 'long',
+ day: '2-digit',
+ },
+ ],
+ resourceAreaColumns: [
+ {
+ field: 'title',
+ headerContent: this.text.assignees,
+ },
+ ],
+ },
+ resourceTimelineMonth: {
+ type: 'resourceTimeline',
+ duration: { months: 1 },
+ slotDuration: { days: 1 },
+ slotLabelFormat: [
+ {
+ weekday: 'long',
+ day: '2-digit',
+ },
+ ],
+ resourceAreaColumns: [
+ {
+ field: 'title',
+ headerContent: this.text.assignees,
+ },
+ ],
+ },
},
events: this.calendarEventsFunction.bind(this) as unknown,
resources: [],
diff --git a/frontend/src/app/features/team-planner/team-planner/team-planner.routes.ts b/frontend/src/app/features/team-planner/team-planner/team-planner.routes.ts
index c7e58a5ef8d..1438648553e 100644
--- a/frontend/src/app/features/team-planner/team-planner/team-planner.routes.ts
+++ b/frontend/src/app/features/team-planner/team-planner/team-planner.routes.ts
@@ -37,7 +37,7 @@ export const TEAM_PLANNER_ROUTES:Ng2StateDeclaration[] = [
{
name: 'team_planner',
parent: 'optional_project',
- url: '/team_planner?query_id&query_props&cdate',
+ url: '/team_planner?query_id&query_props&cdate&cview',
redirectTo: 'team_planner.page',
views: {
'!$default': { component: WorkPackagesBaseComponent },
@@ -45,6 +45,7 @@ export const TEAM_PLANNER_ROUTES:Ng2StateDeclaration[] = [
params: {
query_id: { type: 'query', dynamic: true },
cdate: { type: 'string', dynamic: true },
+ cview: { type: 'string', dynamic: true },
// Use custom encoder/decoder that ensures validity of URL string
query_props: { type: 'opQueryString' },
},
diff --git a/modules/team_planner/config/locales/js-en.yml b/modules/team_planner/config/locales/js-en.yml
index e56552b6936..daee17a5182 100644
--- a/modules/team_planner/config/locales/js-en.yml
+++ b/modules/team_planner/config/locales/js-en.yml
@@ -9,3 +9,4 @@ en:
no_data: 'Add assignees to set up your team planner.'
add_assignee: 'Add assignee'
remove_assignee: 'Remove assignee'
+ two_weeks: '2 weeks'
diff --git a/modules/team_planner/spec/features/team_planner_view_modes_spec.rb b/modules/team_planner/spec/features/team_planner_view_modes_spec.rb
new file mode 100644
index 00000000000..b3415630198
--- /dev/null
+++ b/modules/team_planner/spec/features/team_planner_view_modes_spec.rb
@@ -0,0 +1,59 @@
+#-- 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', type: :feature, js: true do
+ include_context 'with team planner full access'
+
+ it 'allows switching of view modes' do
+ team_planner.visit!
+
+ team_planner.expect_empty_state
+ 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
+
+ # weekly: Expect 7 slots
+ team_planner.expect_view_mode 'week'
+ expect(page).to have_selector('.fc-timeline-slot-frame', count: 7)
+
+ # 2 weeks: expect 14 slots
+ team_planner.switch_view_mode '2 weeks'
+ expect(page).to have_selector('.fc-timeline-slot-frame', count: 14)
+
+ # month: Expect 30 slots
+ team_planner.switch_view_mode 'month'
+ expect(page).to have_selector('.fc-timeline-slot-frame', minimum: 28, maximum: 31)
+ end
+end
diff --git a/modules/team_planner/spec/support/pages/team_planner.rb b/modules/team_planner/spec/support/pages/team_planner.rb
index 2708306d82a..a6c912bf45f 100644
--- a/modules/team_planner/spec/support/pages/team_planner.rb
+++ b/modules/team_planner/spec/support/pages/team_planner.rb
@@ -54,6 +54,23 @@ module Pages
expect(page).to have_conditional_selector(present, '.op-team-planner--no-data', text: 'Add assignees to set up your team planner.')
end
+ def expect_view_mode(text)
+ expect(page).to have_selector('.fc-button-active', text: text)
+
+ param = {
+ 'week' => :resourceTimelineWeek,
+ '2 weeks' => :resourceTimelineTwoWeeks,
+ 'month' => :resourceTimelineMonth
+ }[text]
+
+ expect(page).to have_current_path(/cview=#{param}/)
+ end
+
+ def switch_view_mode(text)
+ page.find('.fc-button', text: text).click
+ expect_view_mode(text)
+ end
+
def expect_assignee(user, present: true)
name = user.is_a?(User) ? user.name : user.to_s
expect(page).to have_conditional_selector(present, '.fc-resource', text: name, wait: 10)