Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

As a Planning editor I like to use “advanced templates” for events [SDESK-6746] #1905

Merged
merged 7 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions client/actions/events/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ const fetchEventTemplates = () => (dispatch, getState, {api}) => {
});
};

const createEventTemplate = (itemId) => (dispatch, getState, {api, modal, notify}) => {
const createEventTemplate = (item) => (dispatch, getState, {api, modal, notify}) => {
devketanpro marked this conversation as resolved.
Show resolved Hide resolved
modal.prompt(gettext('Template name')).then((templateName) => {
api('events_template').query({
where: {
Expand All @@ -685,7 +685,22 @@ const createEventTemplate = (itemId) => (dispatch, getState, {api, modal, notify
const doSave = () => {
api('events_template').save({
template_name: templateName,
based_on_event: itemId,
based_on_event: item._id,
embedded_planning: item.associated_plannings.map((planning) => ({
MarkLark86 marked this conversation as resolved.
Show resolved Hide resolved
coverages: planning.coverages.map((coverage) => ({
coverage_id: coverage.coverage_id,
g2_content_type: coverage.planning.g2_content_type,
desk: coverage.assigned_to.desk,
user: coverage.assigned_to.user,
language: coverage.planning.language,
news_coverage_status: coverage.news_coverage_status.qcode,
scheduled: coverage.planning.scheduled,
genre: coverage.planning.genre?.qcode,
slugline: coverage.planning.slugline,
ednote: coverage.planning.ednote,
internal_note: coverage.planning.internal_note,
})),
}))
})
.then(() => {
dispatch(fetchEventTemplates());
Expand Down
31 changes: 31 additions & 0 deletions client/actions/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,42 @@ const createNew = (itemType, item = null, updateUrl = true, modal = false) => (
}, 'create', updateUrl, modal)
);

function getEventsAssociatedItems(template: IEventTemplate) {
devketanpro marked this conversation as resolved.
Show resolved Hide resolved
return template.data.embedded_planning.map((embedded) => ({
_id: generateTempId(),
slugline: template.data.slugline,
language: template.data.language,
coverages: embedded.coverages.map((coverage) => ({
coverage_id: coverage.coverage_id,
planning: {
g2_content_type: coverage.g2_content_type,
scheduled: coverage.scheduled,
language: coverage.language,
genre: coverage.genre ? {qcode: coverage.genre} : undefined,
slugline: coverage.slugline,
ednote: coverage.ednote,
internal_note: coverage.internal_note,
},
assigned_to: {
desk: coverage.desk,
user: coverage.user,
},
news_coverage_status: {
qcode: coverage.news_coverage_status,
},
})),
}));
}

function createEventFromTemplate(template: IEventTemplate) {
const embeddedPlanning = template.data?.embedded_planning || [];
devketanpro marked this conversation as resolved.
Show resolved Hide resolved

return self.createNew(ITEM_TYPE.EVENT, {
...template.data,
dates: {
tz: template.data.dates?.tz
},
associated_plannings: embeddedPlanning ? self.getEventsAssociatedItems(template) : []
});
}

Expand Down Expand Up @@ -1670,6 +1700,7 @@ const self = {
changeEditorAction,
notifyPreconditionFailed,
setUnsetUserInitiatedSearch,
getEventsAssociatedItems,
};

export default self;
3 changes: 2 additions & 1 deletion client/components/Main/ItemEditor/EditorHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ export class EditorHeader extends React.Component {
loading,
itemManager,
autoSave,
diff,
} = this.props;

const states = this.getItemStates();
Expand Down Expand Up @@ -428,7 +429,7 @@ export class EditorHeader extends React.Component {

{!loading && !hideItemActions && (
<EditorItemActions
item={initialValues}
item={diff}
onAddCoverage={itemManager.addCoverage}
itemActions={itemActions}
session={session}
Expand Down
4 changes: 2 additions & 2 deletions client/components/Main/ItemEditor/EditorItemActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ const EditorItemActionsComponent = (props) => {
() => {
const message = gettext('Save changes before creating a template?');

dispatch(allActions.main.openActionModalFromEditor(item, message, (updatedItem) => {
dispatch(eventsApi.createEventTemplate(updatedItem._id));
dispatch(allActions.main.openActionModalFromEditor(item, message, () => {
dispatch(eventsApi.createEventTemplate(item));
}));
},
[EVENTS.ITEM_ACTIONS.MARK_AS_COMPLETED.actionName]:
Expand Down
3 changes: 3 additions & 0 deletions server/planning/events/events_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class EventsTemplateResource(Resource):
endpoint_name = "events_template"
resource_methods = ["GET", "POST"]
item_methods = ["GET", "DELETE", "PATCH", "PUT"]
allow_unknown = True
devketanpro marked this conversation as resolved.
Show resolved Hide resolved
privileges = {
"GET": "planning_event_management",
"POST": "planning_event_templates",
Expand Down Expand Up @@ -163,6 +164,8 @@ def _get_event(_id):
def _fill_event_template(self, doc):
event = self._get_event(doc["based_on_event"])
doc["data"] = event.copy()
if doc.get("embedded_planning"):
doc["data"].setdefault("embedded_planning", doc.pop("embedded_planning"))
for field in DUPLICATE_EVENT_IGNORED_FIELDS:
doc["data"].pop(field, None)

Expand Down
Loading