From 6da48dbc957b7f08d4eb59bba7993a0abcef5403 Mon Sep 17 00:00:00 2001 From: "Julien Carion (juca)" Date: Thu, 20 Jul 2023 08:23:50 +0000 Subject: [PATCH] [IMP] web: add show weekends to calendar This commit adds the "show weekends" functionality to calendar which allows the user to choose whether weekends should be shown in the calendar or not (defaults to false). task-3425523 closes odoo/odoo#129107 Signed-off-by: Luca Vitali (luvi) --- .../calendar_common_renderer.js | 3 +- .../src/views/calendar/calendar_controller.js | 33 ++++++++++++++----- .../views/calendar/calendar_controller.xml | 2 +- addons/web/static/src/views/calendar/hooks.js | 7 ++++ .../view_components/view_scale_selector.js | 2 ++ .../view_components/view_scale_selector.xml | 8 +++++ .../views/calendar/calendar_view_tests.js | 5 ++- .../view_scale_selector_tests.js | 10 ++++++ 8 files changed, 58 insertions(+), 12 deletions(-) diff --git a/addons/web/static/src/views/calendar/calendar_common/calendar_common_renderer.js b/addons/web/static/src/views/calendar/calendar_common/calendar_common_renderer.js index 98487de5d7b..b8c178c593a 100644 --- a/addons/web/static/src/views/calendar/calendar_common/calendar_common_renderer.js +++ b/addons/web/static/src/views/calendar/calendar_common/calendar_common_renderer.js @@ -96,6 +96,7 @@ export class CalendarCommonRenderer extends Component { unselectAuto: false, weekLabel: this.props.model.scale === "month" && this.env.isSmall ? "" : this.env._t("Week"), + weekends: this.props.isWeekendVisible, weekNumberCalculation: "ISO", weekNumbers: true, weekNumbersWithinDays: !this.env.isSmall, @@ -158,7 +159,7 @@ export class CalendarCommonRenderer extends Component { this.popover.open( target, this.getPopoverProps(record), - `o_cw_popover o_calendar_color_${typeof(color) === "number" ? color : 0}` + `o_cw_popover o_calendar_color_${typeof color === "number" ? color : 0}` ); } updateSize() { diff --git a/addons/web/static/src/views/calendar/calendar_controller.js b/addons/web/static/src/views/calendar/calendar_controller.js index c24085a148f..ef1e61ca5e5 100644 --- a/addons/web/static/src/views/calendar/calendar_controller.js +++ b/addons/web/static/src/views/calendar/calendar_controller.js @@ -16,6 +16,7 @@ import { SearchBar } from "@web/search/search_bar/search_bar"; import { useSearchBarToggler } from "@web/search/search_bar/search_bar_toggler"; import { ViewScaleSelector } from "@web/views/view_components/view_scale_selector"; import { CogMenu } from "@web/search/cog_menu/cog_menu"; +import { browser } from "@web/core/browser/browser"; import { Component, useState } from "@odoo/owl"; @@ -43,20 +44,28 @@ export class CalendarController extends Component { this.orm = useService("orm"); this.displayDialog = useUniqueDialog(); - this.model = useModelWithSampleData(this.props.Model, { - ...this.props.archInfo, - resModel: this.props.resModel, - domain: this.props.domain, - fields: this.props.fields, - }, { - onWillStart: this.onWillStartModel.bind(this), - }); + this.model = useModelWithSampleData( + this.props.Model, + { + ...this.props.archInfo, + resModel: this.props.resModel, + domain: this.props.domain, + fields: this.props.fields, + }, + { + onWillStart: this.onWillStartModel.bind(this), + } + ); useSetupView({ getLocalState: () => this.model.exportedState, }); this.state = useState({ + isWeekendVisible: + browser.localStorage.getItem("calendar.isWeekendVisible") != null + ? JSON.parse(browser.localStorage.getItem("calendar.isWeekendVisible")) + : true, showSideBar: !this.env.isSmall, }); @@ -66,6 +75,7 @@ export class CalendarController extends Component { get rendererProps() { return { model: this.model, + isWeekendVisible: this.model.scale === "day" || this.state.isWeekendVisible, createRecord: this.createRecord.bind(this), deleteRecord: this.deleteRecord.bind(this), editRecord: this.editRecord.bind(this), @@ -216,7 +226,7 @@ export class CalendarController extends Component { } onWillStartModel() {} - + async setDate(move) { let date = null; switch (move) { @@ -242,6 +252,11 @@ export class CalendarController extends Component { async setScale(scale) { await this.model.load({ scale }); } + + toggleWeekendVisibility() { + this.state.isWeekendVisible = !this.state.isWeekendVisible; + browser.localStorage.setItem("calendar.isWeekendVisible", this.state.isWeekendVisible); + } } CalendarController.components = { DatePicker: CalendarDatePicker, diff --git a/addons/web/static/src/views/calendar/calendar_controller.xml b/addons/web/static/src/views/calendar/calendar_controller.xml index 358bd0c09b0..b72cffcd308 100644 --- a/addons/web/static/src/views/calendar/calendar_controller.xml +++ b/addons/web/static/src/views/calendar/calendar_controller.xml @@ -33,7 +33,7 @@ aria-label="Previous" t-on-click.stop="() => this.setDate('previous')" > - +