Skip to content

Commit

Permalink
[SDESK-4730] Changes to scheduled_updates feature and merging informa…
Browse files Browse the repository at this point in the history
…tion to newsroom
  • Loading branch information
nrvikas committed Oct 14, 2019
1 parent 55ebf58 commit afe98b2
Show file tree
Hide file tree
Showing 22 changed files with 2,229 additions and 124 deletions.
6 changes: 3 additions & 3 deletions client/components/Coverages/CoverageEditor/CoverageForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
import {get} from 'lodash';
import {getItemInArrayById, gettext, planningUtils, generateTempId} from '../../../utils';
import moment from 'moment';
import {WORKFLOW_STATE} from '../../../constants';
import {WORKFLOW_STATE, DEFAULT_DATE_FORMAT, DEFAULT_TIME_FORMAT} from '../../../constants';
import {Button} from '../../UI';
import {Row, Label, LineInput} from '../../UI/Form';
import {ScheduledUpdate} from '../ScheduledUpdate';
Expand Down Expand Up @@ -400,6 +400,6 @@ CoverageForm.propTypes = {
};

CoverageForm.defaultProps = {
dateFormat: 'DD/MM/YYYY',
timeFormat: 'HH:mm',
dateFormat: DEFAULT_DATE_FORMAT,
timeFormat: DEFAULT_TIME_FORMAT,
};
6 changes: 3 additions & 3 deletions client/components/Coverages/CoverageEditor/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {CoverageForm} from './CoverageForm';
import {CoverageFormHeader} from './CoverageFormHeader';

import {planningUtils, gettext, editorMenuUtils} from '../../../utils';
import {COVERAGES} from '../../../constants';
import {COVERAGES, DEFAULT_DATE_FORMAT, DEFAULT_TIME_FORMAT} from '../../../constants';

export const CoverageEditor = ({
diff,
Expand Down Expand Up @@ -249,6 +249,6 @@ CoverageEditor.propTypes = {
};

CoverageEditor.defaultProps = {
dateFormat: 'DD/MM/YYYY',
timeFormat: 'HH:mm',
dateFormat: DEFAULT_DATE_FORMAT,
timeFormat: DEFAULT_TIME_FORMAT,
};
6 changes: 3 additions & 3 deletions client/components/Coverages/CoverageItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
planningUtils,
} from '../../utils';
import {UserAvatar} from '../UserAvatar';
import {WORKFLOW_STATE} from '../../constants';
import {WORKFLOW_STATE, DEFAULT_DATE_FORMAT, DEFAULT_TIME_FORMAT} from '../../constants';

export const CoverageItem = ({
item,
Expand Down Expand Up @@ -148,7 +148,7 @@ CoverageItem.propTypes = {
};

CoverageItem.defaultProps = {
dateFormat: 'DD/MM/YYYY',
timeFormat: 'HH:mm',
dateFormat: DEFAULT_DATE_FORMAT,
timeFormat: DEFAULT_TIME_FORMAT,
isPreview: false,
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {Row as PreviewRow} from '../../UI/Preview';
import moment from 'moment-timezone';
import {get} from 'lodash';
import {getCreator, getItemInArrayById, gettext} from '../../../utils';
import {DEFAULT_DATE_FORMAT, DEFAULT_TIME_FORMAT} from '../../../constants';
import {StateLabel} from '../../index';

export const CoveragePreviewTopBar = ({
Expand Down Expand Up @@ -86,6 +87,6 @@ CoveragePreviewTopBar.propTypes = {


CoveragePreviewTopBar.defaultProps = {
dateFormat: 'DD/MM/YYYY',
timeFormat: 'HH:mm',
dateFormat: DEFAULT_DATE_FORMAT,
timeFormat: DEFAULT_TIME_FORMAT,
};
6 changes: 3 additions & 3 deletions client/components/Coverages/CoveragePreview/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {CollapseBox} from '../../UI';
import {get} from 'lodash';
import {gettext, stringUtils, planningUtils} from '../../../utils';
import {ContactsPreviewList} from '../../Contacts/index';
import {PLANNING, WORKFLOW_STATE} from '../../../constants';
import {PLANNING, WORKFLOW_STATE, DEFAULT_DATE_FORMAT, DEFAULT_TIME_FORMAT} from '../../../constants';

import {CoverageItem} from '../';
import {CoveragePreviewTopBar} from './CoveragePreviewTopBar';
Expand Down Expand Up @@ -205,6 +205,6 @@ CoveragePreview.propTypes = {


CoveragePreview.defaultProps = {
dateFormat: 'DD/MM/YYYY',
timeFormat: 'HH:mm',
dateFormat: DEFAULT_DATE_FORMAT,
timeFormat: DEFAULT_TIME_FORMAT,
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import {gettext, planningUtils} from '../../../utils';
import {WORKFLOW_STATE} from '../../../constants';
import {WORKFLOW_STATE, DEFAULT_DATE_FORMAT, DEFAULT_TIME_FORMAT} from '../../../constants';
import {
TextAreaInput,
SelectInput,
Expand Down Expand Up @@ -177,6 +177,6 @@ ScheduledUpdateForm.propTypes = {
};

ScheduledUpdateForm.defaultProps = {
dateFormat: 'DD/MM/YYYY',
timeFormat: 'HH:mm',
dateFormat: DEFAULT_DATE_FORMAT,
timeFormat: DEFAULT_TIME_FORMAT,
};
6 changes: 3 additions & 3 deletions client/components/Coverages/ScheduledUpdate/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {CoverageFormHeader} from '../CoverageEditor/CoverageFormHeader';
import {CoveragePreviewTopBar} from '../CoveragePreview/CoveragePreviewTopBar';

import {planningUtils, gettext, stringUtils} from '../../../utils';
import {PLANNING, COVERAGES} from '../../../constants';
import {PLANNING, COVERAGES, DEFAULT_DATE_FORMAT, DEFAULT_TIME_FORMAT} from '../../../constants';

export const ScheduledUpdate = ({
diff,
Expand Down Expand Up @@ -255,7 +255,7 @@ ScheduledUpdate.propTypes = {
};

ScheduledUpdate.defaultProps = {
dateFormat: 'DD/MM/YYYY',
timeFormat: 'HH:mm',
dateFormat: DEFAULT_DATE_FORMAT,
timeFormat: DEFAULT_TIME_FORMAT,
openScheduledUpdates: [],
};
6 changes: 3 additions & 3 deletions client/components/Events/EventMetadata/index.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import {get} from 'lodash';
import {ICON_COLORS} from '../../../constants';
import {ICON_COLORS, DEFAULT_DATE_FORMAT, DEFAULT_TIME_FORMAT} from '../../../constants';
import {StateLabel} from '../..';
import {EventScheduleSummary} from '../';
import {ItemIcon} from '../../index';
Expand Down Expand Up @@ -250,8 +250,8 @@ EventMetadata.propTypes = {


EventMetadata.defaultProps = {
dateFormat: 'DD/MM/YYYY',
timeFormat: 'HH:mm',
dateFormat: DEFAULT_DATE_FORMAT,
timeFormat: DEFAULT_TIME_FORMAT,
scrollInView: true,
showIcon: true,
showBorder: true,
Expand Down
5 changes: 3 additions & 2 deletions client/components/Events/EventScheduleSummary/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
import {RepeatEventSummary} from '../RepeatEventSummary';
import {Row} from '../../UI/Preview';
import {gettext, eventUtils, timeUtils} from '../../../utils';
import {DEFAULT_DATE_FORMAT, DEFAULT_TIME_FORMAT} from '../../../constants';
import {get} from 'lodash';
import './style.scss';

Expand Down Expand Up @@ -75,8 +76,8 @@ EventScheduleSummary.propTypes = {
};

EventScheduleSummary.defaultProps = {
dateFormat: 'DD/MM/YYYY',
timeFormat: 'HH:mm',
dateFormat: DEFAULT_DATE_FORMAT,
timeFormat: DEFAULT_TIME_FORMAT,
noPadding: false,
useEventTimezone: false,
};
3 changes: 3 additions & 0 deletions client/constants/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ export {EVENTS} from './events';

export const WS_NOTIFICATION = 'WS_NOTIFICATION';

export const DEFAULT_DATE_FORMAT = 'DD/MM/YYYY';
export const DEFAULT_TIME_FORMAT = 'HH:mm';

export const DATE_FORMATS = {
COMPARE_FORMAT: 'YYYY-M-D',
DISPLAY_DATE_FORMAT: 'D. MMMM YYYY HH:mm',
Expand Down
7 changes: 7 additions & 0 deletions client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,13 @@ export default angular.module('superdesk-planning', [])
assignments.onPublishFromAuthoring
);
}

if (get(deployConfig, 'config.planning_link_updates_to_coverage')) {
functionPoints.register(
'archive:rewrite_after',
assignments.onArchiveRewrite
);
}
});
},
]);
151 changes: 140 additions & 11 deletions client/services/AssignmentsService.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import {get} from 'lodash';
import React from 'react';
import {Provider} from 'react-redux';
import moment from 'moment';

import {gettext} from '../utils';
import {gettext, planningUtils} from '../utils';

import {WORKSPACE, MODALS, ASSIGNMENTS} from '../constants';
import {WORKSPACE, MODALS, ASSIGNMENTS, DEFAULT_DATE_FORMAT, DEFAULT_TIME_FORMAT} from '../constants';
import {ModalsContainer} from '../components';
import * as actions from '../actions';

Expand All @@ -19,6 +20,8 @@ export class AssignmentsService {
this.config = config;

this.onPublishFromAuthoring = this.onPublishFromAuthoring.bind(this);
this.onArchiveRewrite = this.onArchiveRewrite.bind(this);
this.onUnloadModal = this.onUnloadModal.bind();
}

getAssignmentQuery(slugline, contentType) {
Expand Down Expand Up @@ -82,6 +85,82 @@ export class AssignmentsService {
});
}

onArchiveRewrite(item) {
if (!get(item, 'assignment_id')) {
return Promise.resolve(item);
}

return this.api('assignments').getById(item.assignment_id)
.then((assignment) => (
this.api('planning').query({
source: JSON.stringify({
query: {terms: {_id: [get(assignment, 'planning_item')]}},
}),
})
.then((data) => {
let items = get(data, '_items', []);

items.forEach((item) => {
planningUtils.modifyForClient((item));
});

const planning = get(items, '[0]');

if (!planning) {
return Promise.resolve(item);
}
// Check to see if there is a scheduled update following this assignment
// that is available for linking
const coverage = get(planning, 'coverages', []).find((c) =>
c.coverage_id === assignment.coverage_item);

if (!coverage || get(coverage, 'scheduled_updates.length', 0) <= 0) {
return Promise.resolve(item);
}

let availableScheduledUpdate;

if (item.assignment_id === get(coverage, 'assigned_to.assignment_id')) {
if (![ASSIGNMENTS.WORKFLOW_STATE.ASSIGNED, ASSIGNMENTS.WORKFLOW_STATE.SUBMITTED].includes(
get(coverage, 'scheduled_updates[0].assigned_to.state'))) {
return Promise.resolve(item);
}

availableScheduledUpdate = coverage.scheduled_updates[0];
} else {
const linkedScheduledUpdateIndex = coverage.scheduled_updates.findIndex(
(s) => assignment._id === get(s, 'assigned_to.assignment_id'));

if (linkedScheduledUpdateIndex < 0 ||
(linkedScheduledUpdateIndex === coverage.scheduled_updates.length - 1) ||
![ASSIGNMENTS.WORKFLOW_STATE.ASSIGNED, ASSIGNMENTS.WORKFLOW_STATE.SUBMITTED].includes(
get(coverage,
`scheduled_updates[${linkedScheduledUpdateIndex + 1}].assigned_to.state`))) {
return Promise.resolve(item);
}

availableScheduledUpdate = coverage.scheduled_updates[linkedScheduledUpdateIndex + 1];
}

if (!availableScheduledUpdate) {
return Promise.resolve(item);
}

return new Promise((resolve, reject) => this.showScheduleUpdatesConfirmationModal(
item,
availableScheduledUpdate,
resolve,
reject));
}, (error) =>
// At errors we leave the archive item as it is
Promise.resolve(item)
)
), (error) =>
// At errors we leave the archive item as it is
Promise.resolve(item)
);
}

getBySlugline(slugline, contentType) {
return this.api('assignments').query({
source: JSON.stringify({
Expand All @@ -93,6 +172,63 @@ export class AssignmentsService {
});
}

onUnloadModal(store, closeModal, action, res) {
closeModal();
store.dispatch(actions.resetStore());
return action(res);
}

showScheduleUpdatesConfirmationModal(newsItem, scheduledUpdate, resolve, reject) {
let store;

return this.sdPlanningStore.initWorkspace(WORKSPACE.AUTHORING, (newStore) => {
store = newStore;
return Promise.resolve();
})
.then(() => this.modal.createCustomModal()
.then(({openModal, closeModal}) => {
openModal(
<Provider store={store}>
<ModalsContainer />
</Provider>
);

const $scope = {
resolve: () =>
// link to the new assignment
this.api('assignments_link').save({}, {
assignment_id: get(scheduledUpdate, 'assigned_to.assignment_id'),
item_id: newsItem._id,
reassign: true,
force: true,
})
.then((item) => {
newsItem.assignment_id = item.assignment_id;
this.onUnloadModal(store, closeModal, resolve, item);
}, () => {
this.notify.warning(gettext('Failed to link to requested assignment!'));
this.onUnloadModal(store, closeModal, resolve, newsItem);
}),
reject: () => {
this.onUnloadModal(store, closeModal, resolve, newsItem);
},
};

const time = moment(scheduledUpdate.planning.scheduled).format(
DEFAULT_DATE_FORMAT + ' ' + DEFAULT_TIME_FORMAT);
const prompt = gettext('Do you want to link it to that assignment ?');

store.dispatch(actions.showModal({
modalType: MODALS.CONFIRMATION,
modalProps: {
body: gettext(`There is an update assignment for this story due at '${time}'. ${prompt}`),
action: $scope.resolve,
onCancel: $scope.reject,
},
}));
}));
}

showLinkAssignmentModal(item, resolve, reject) {
let store;

Expand Down Expand Up @@ -123,19 +259,12 @@ export class AssignmentsService {
)
);

const onUnload = () => {
closeModal();
store.dispatch(actions.resetStore());
};

const $scope = {
resolve: () => {
onUnload();
resolve();
this.onUnloadModal(store, closeModal, resolve);
},
reject: () => {
onUnload();
reject();
this.onUnloadModal(store, closeModal, reject);
},
};

Expand Down
Loading

0 comments on commit afe98b2

Please sign in to comment.