Skip to content

Commit

Permalink
allow planning items without time (#2192)
Browse files Browse the repository at this point in the history
* allow planning items without time

toggled via `PLANNING_PLANNING_ALL_DAY` config.

STT-48
  • Loading branch information
petrjasek authored Feb 4, 2025
1 parent 1c20237 commit 691d66c
Show file tree
Hide file tree
Showing 13 changed files with 84 additions and 28 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/ci-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
node-version: ['14']
e2e: ['a', 'b']
env:
INSTALL_NODE_MODULES: true
INSTALL_NODE_MODULES: false
RUN_SERVICES: true
E2E: true
TZ: Australia/Sydney
Expand All @@ -28,6 +28,12 @@ jobs:
cache-dependency-path: 'server/requirements.txt'
- name: Setup Environment
run: ./scripts/ci-install.sh
- name: Install Planning Client
run: npm ci
working-directory: ./
- name: Install E2E Client
run: npm install
working-directory: ./e2e
- name: Build Client
working-directory: ./e2e
run: npm run build
Expand Down
9 changes: 6 additions & 3 deletions client/actions/events/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -758,10 +758,13 @@ const createEventFromPlanning = (plan: IPlanningItem) => (
...eventUtils.defaultEventValues(occurStatuses, defaultCalendar, defaultPlace),
dates: {
start: moment(plan.planning_date).clone(),
end: moment(plan.planning_date)
.clone()
.add(defaultDurationOnChange, 'h'),
end: plan.all_day ?
moment(plan.planning_date).clone() :
moment(plan.planning_date)
.clone()
.add(defaultDurationOnChange, 'h'),
tz: moment.tz.guess(),
all_day: plan.all_day,
},
subject: plan.subject,
anpa_category: plan.anpa_category,
Expand Down
16 changes: 10 additions & 6 deletions client/components/Planning/PlanningEditor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -317,14 +317,18 @@ class PlanningEditorComponent extends React.Component<IProps, IState> {
}
}

onPlanningDateChange(field, value) {
let changes: Partial<IPlanningItem> = {planning_date: value};
onPlanningDateChange(fieldOrValue: string | {[key: string]: any}, value?: any) {
if (typeof fieldOrValue === 'string') {
let changes: Partial<IPlanningItem> = {planning_date: value};

if (field.indexOf('.time') >= 0) {
changes._time_to_be_confirmed = false;
}
if (fieldOrValue.indexOf('.time') >= 0) {
changes._time_to_be_confirmed = false;
}

this.props.onChangeHandler(changes, null);
this.props.onChangeHandler(changes, null);
} else {
this.props.onChangeHandler(fieldOrValue, value);
}
}

onTimeToBeConfirmed() {
Expand Down
31 changes: 31 additions & 0 deletions client/components/fields/editor/PlanningDateTime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import * as React from 'react';
import {superdeskApi} from '../../../superdeskApi';
import {IEditorFieldProps, IPlanningItem} from '../../../interfaces';
import {EditorFieldDateTime} from './base/dateTime';
import {appConfig} from 'appConfig';
import moment from 'moment';

interface IProps extends IEditorFieldProps {
item: IPlanningItem;
Expand All @@ -12,6 +14,31 @@ interface IProps extends IEditorFieldProps {
}

export class EditorFieldPlanningDateTime extends React.PureComponent<IProps> {
allDay = appConfig.planning.all_day;

constructor(props: IProps) {
super(props);

this.onChange = this.onChange.bind(this);
}

onChange(fieldOrValues: string | { [key: string]: any }, value?: any) {
if (typeof fieldOrValues === 'string') {
const updateValue = value?.isValid() ? this.formatValue(value) : null;

this.props.onChange({
[fieldOrValues]: updateValue,
all_day: this.allDay,
});
} else {
this.props.onChange(fieldOrValues);
}
}

formatValue(value: moment.Moment) : moment.MomentInput {
return this.allDay ? value.format('YYYY-MM-DD') : value;
}

render() {
const {gettext} = superdeskApi.localization;
const {
Expand All @@ -29,6 +56,10 @@ export class EditorFieldPlanningDateTime extends React.PureComponent<IProps> {
label={label ?? gettext('Planning Date')}
showToBeConfirmed={true}
toBeConfirmed={this.props.item?._time_to_be_confirmed == true}
singleValue={true}
allDay={this.allDay}
hideTime={this.allDay}
onChange={this.onChange}
/>
);
}
Expand Down
1 change: 1 addition & 0 deletions client/components/fields/editor/base/dateTime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface IProps extends IEditorFieldProps {
singleValue?: boolean;
onToBeConfirmed?(field: string): void;
allDay?: boolean;
hideTime?: boolean;
}

export class EditorFieldDateTime extends React.PureComponent<IProps> {
Expand Down
1 change: 1 addition & 0 deletions client/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ declare module 'superdesk-api' {
autosave_timeout?: number;
default_create_planning_series_with_event_series?: boolean;
event_related_item_search_provider_name?: string;
all_day?: boolean;
};

coverage?: {
Expand Down
1 change: 1 addition & 0 deletions client/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,7 @@ export interface IPlanningItem extends IBaseRestApiResponse {
scheduled: string | Date;
}>;
planning_date: IDateTime;
all_day?: boolean;
flags?: {
marked_for_not_publication?: boolean;
overide_auto_assign_to_workflow?: boolean;
Expand Down
1 change: 1 addition & 0 deletions client/planning-extension/src/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ declare module 'superdesk-api' {
autosave_timeout?: number;
default_create_planning_series_with_event_series?: boolean;
event_related_item_search_provider_name?: string;
all_day?: boolean;
};

coverage?: {
Expand Down
28 changes: 17 additions & 11 deletions client/utils/planning.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1719,18 +1719,24 @@ function getDateStringForPlanning(planning: IPlanningItem): string {
planning.planning_date :
moment(planning.planning_date);

return planning._time_to_be_confirmed ? (
planning_date.format(appConfig.planning.dateformat) +
' @ ' +
gettext('TBC')
) :
getDateTimeString(
planning_date,
appConfig.planning.dateformat,
appConfig.planning.timeformat,
' @ ',
false
if (planning._time_to_be_confirmed) {
return (
planning_date.format(appConfig.planning.dateformat) +
' @ ' + gettext('TBC')
);
}

if (planning.all_day) {
return moment.utc(planning_date).format(appConfig.planning.dateformat);
}

return getDateTimeString(
planning_date,
appConfig.planning.dateformat,
appConfig.planning.timeformat,
' @ ',
false
);
}

function getCoverageDateText(coverage: IPlanningCoverageItem): string {
Expand Down
9 changes: 5 additions & 4 deletions e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@
"devDependencies": {
"@superdesk/build-tools": "^1.0.14",
"cypress": "^13.16.1",
"cypress-real-events": "^1.7.6",
"cypress-real-events": "^1.14.0",
"cypress-terminal-report": "^5.0.2",
"extract-text-webpack-plugin": "3.0.2",
"lodash": "^4.17.15",
"lodash": "^4.17.21",
"moment": "^2.29.4",
"moment-timezone": "^0.5.42"
"moment-timezone": "^0.5.47"
},
"scripts": {
"cypress-ui": "cypress open",
"cypress-ci": "cypress run --browser chrome",
"clean": "grunt clean",
"build": "npx @superdesk/build-tools build-root-repo ./",
"serve": "node --max-old-space-size=8192 ./node_modules/.bin/grunt server"
"serve": "node --max-old-space-size=8192 ./node_modules/.bin/grunt server",
"start": "grunt server"
}
}
5 changes: 2 additions & 3 deletions scripts/ci-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ sudo apt-get -y install libxml2-dev libxmlsec1-dev libxmlsec1-openssl
# Update python core packages
python -m pip install --upgrade pip wheel setuptools

git config --global url."https://git@".insteadOf git://

if [ "$INSTALL_NODE_MODULES" == "true" ]; then
git config --global url."https://git@".insteadOf git://
npm install
fi

Expand All @@ -24,6 +25,4 @@ if [ "$E2E" == "true" ]; then
cd e2e/server
pip install -r requirements.txt
cd ../
git config --global url."https://git@".insteadOf git://
npm install
fi
1 change: 1 addition & 0 deletions server/planning/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ def init_app(app):
app.client_config["planning"][
"default_create_planning_series_with_event_series"
] = get_config_default_create_planning_series_with_event_series(app)
app.client_config["planning"]["all_day"] = bool(app.config.get("PLANNING_PLANNING_ALL_DAY", False))

app.client_config["planning_event_link_method"] = app.config.get(settings.PLANNING_EVENT_LINK_METHOD, "one_primary")

Expand Down
1 change: 1 addition & 0 deletions server/planning/planning/planning_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@
"type": "datetime",
"nullable": False,
},
"all_day": {"type": "boolean"},
"flags": {
"type": "dict",
"schema": {
Expand Down

0 comments on commit 691d66c

Please sign in to comment.