Skip to content

Commit

Permalink
Merge fb81194 into dbfaaa9
Browse files Browse the repository at this point in the history
  • Loading branch information
nrvikas committed Jul 19, 2019
2 parents dbfaaa9 + fb81194 commit b8fe434
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 15 deletions.
31 changes: 23 additions & 8 deletions client/components/Events/EventHistory.jsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React from 'react';
import PropTypes from 'prop-types';
import {HISTORY_OPERATIONS} from '../../constants';
import {HISTORY_OPERATIONS, ITEM_TYPE} from '../../constants';
import {gettext, historyUtils} from '../../utils';
import {get} from 'lodash';
import {AbsoluteDate} from '../index';
import {ContentBlock} from '../UI/SidePanel';

export class EventHistory extends React.Component {
closeAndOpenDuplicate(duplicateId) {
this.props.openItemPreview(duplicateId, 'event');
this.props.openItemPreview(duplicateId, ITEM_TYPE.EVENT);
}

getHistoryActionElement(historyItem) {
Expand Down Expand Up @@ -91,6 +91,10 @@ export class EventHistory extends React.Component {
case HISTORY_OPERATIONS.DUPLICATE:
text = gettext('Duplicated');
break;

case HISTORY_OPERATIONS.CREATED_FROM_PLANNING:
text = gettext('Created from a planning item');
break;
}

return historyUtils.getHistoryRowElement(text, historyItem, this.props.users);
Expand Down Expand Up @@ -125,8 +129,8 @@ export class EventHistory extends React.Component {
{historyItem.operation === HISTORY_OPERATIONS.PLANNING_CREATED && (
<div className="history-list__link">
<a onClick={this.props.openItemPreview.bind(
null, historyItem.update.planning_id, 'planning')}>
View planning item
null, historyItem.update.planning_id, ITEM_TYPE.PLANNING)}>
{gettext('View planning item')}
</a>
</div>)
}
Expand All @@ -135,15 +139,15 @@ export class EventHistory extends React.Component {
<div className="history-list__link">
<a onClick={this.closeAndOpenDuplicate.bind(this,
historyItem.update.duplicate_id)}>
View duplicate event
{gettext('View duplicate event')}
</a>
</div>
)}
{historyItem.operation === HISTORY_OPERATIONS.DUPLICATE_FROM && (
<div className="history-list__link">
<a onClick={this.closeAndOpenDuplicate.bind(this,
historyItem.update.duplicate_id)}>
View original event
{gettext('View original event')}
</a>
</div>
)}
Expand All @@ -153,7 +157,7 @@ export class EventHistory extends React.Component {
<div className="history-list__link">
<a onClick={this.closeAndOpenDuplicate.bind(this,
historyItem.update.reschedule_to)}>
View rescheduled event
{gettext('View rescheduled event')}
</a>
</div>
}
Expand All @@ -163,10 +167,21 @@ export class EventHistory extends React.Component {
<div className="history-list__link">
<a onClick={this.closeAndOpenDuplicate.bind(this,
historyItem.update.reschedule_from)}>
View original event
{gettext('View original event')}
</a>
</div>
}

{historyItem.operation === HISTORY_OPERATIONS.CREATED_FROM_PLANNING &&
get(historyItem, 'update.created_from_planning') &&
<div className="history-list__link">
<a onClick={this.props.openItemPreview.bind(this,
historyItem.update.created_from_planning, ITEM_TYPE.PLANNING)}>
{gettext('View planning item')}
</a>
</div>
}

</div>
</div>
</li>
Expand Down
26 changes: 22 additions & 4 deletions client/components/Planning/PlanningHistory.jsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import React from 'react';
import PropTypes from 'prop-types';
import {PLANNING, HISTORY_OPERATIONS} from '../../constants';
import {PLANNING, HISTORY_OPERATIONS, ITEM_TYPE} from '../../constants';
import {getItemInArrayById, gettext, historyUtils} from '../../utils';
import {get} from 'lodash';
import {ContentBlock} from '../UI/SidePanel';
import {CoverageHistory} from '../Coverages';

export class PlanningHistory extends React.Component {
closeAndOpenDuplicate(duplicateId) {
this.props.openItemPreview(duplicateId, 'planning');
closeAndOpenDuplicate(duplicateId, type = ITEM_TYPE.PLANNING) {
this.props.openItemPreview(duplicateId, type);
}

getHistoryActionElement(historyItem) {
let text, agenda;

switch (historyItem.operation) {
case HISTORY_OPERATIONS.CREATE:
text = gettext('Created');
text = get(historyItem, 'update.event_item') ? gettext('Created from event') :
gettext('Created');
break;

case HISTORY_OPERATIONS.ADD_TO_PLANNING:
Expand Down Expand Up @@ -75,6 +76,10 @@ export class PlanningHistory extends React.Component {
case PLANNING.HISTORY_OPERATIONS.ADD_FEATURED:
text = gettext('Added to featured stories');
break;

case PLANNING.HISTORY_OPERATIONS.CREATE_EVENT:
text = gettext('Associated an event');
break;
}

return historyUtils.getHistoryRowElement(text, historyItem, this.props.users);
Expand Down Expand Up @@ -127,6 +132,19 @@ export class PlanningHistory extends React.Component {
</a>
</div>
)}
{(historyItem.operation === PLANNING.HISTORY_OPERATIONS.CREATE_EVENT ||
historyItem.operation === HISTORY_OPERATIONS.CREATE) &&
get(historyItem, 'update.event_item') && (
<div className="history-list__link">
<a onClick={this.closeAndOpenDuplicate.bind(
this,
historyItem.update.event_item,
ITEM_TYPE.EVENT
)}>
{gettext('View associated event')}
</a>
</div>
)}
</div>
</div>
</li>);
Expand Down
1 change: 1 addition & 0 deletions client/constants/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export const HISTORY_OPERATIONS = {
DUPLICATE_FROM: 'duplicate_from',
DUPLICATE: 'duplicate',
ADD_TO_PLANNING: 'add_to_planning',
CREATED_FROM_PLANNING: 'created_from_planning',
};

export const QUEUE_ITEM_PREFIX = 'queueitem';
Expand Down
1 change: 1 addition & 0 deletions client/constants/planning.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,6 @@ export const PLANNING = {
PLANNING_CANCEL: 'planning_cancel',
ADD_FEATURED: 'add_featured',
REMOVE_FEATURED: 'remove_featured',
CREATE_EVENT: 'create_event',
},
};
27 changes: 27 additions & 0 deletions server/features/events.feature
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,33 @@ Feature: Events
"extra": {"item": "#events._id#"}
}]
"""
When we get "/events_history"
Then we get a list with 1 items
"""
{
"_items": [{
"operation": "created_from_planning",
"event_id": "#events._id#",
"update": {
"name": "TestEvent",
"created_from_planning": "#planning._id#"
}
}]
}
"""
When we get "/planning_history"
Then we get a list with 1 items
"""
{
"_items": [{
"operation": "create_event",
"planning_id": "#planning._id#",
"update": {
"event_item": "#events._id#"
}
}]
}
"""

@auth
Scenario: Fails to link a new Event to a Planning Item if another use holds the Planning lock
Expand Down
8 changes: 7 additions & 1 deletion server/features/events_post.feature
Original file line number Diff line number Diff line change
Expand Up @@ -753,13 +753,19 @@ Feature: Events Post
"""
Then we get OK response
When we get "published_planning"
Then we get list with 2 items
Then we get list with 3 items
"""
{
"_items": [
{
"item_id": "#planning._id#"
},
{
"item_id": "#planning._id#",
"published_item": {
"event_item": "#events._id#"
}
},
{
"item_id": "#events._id#",
"published_item": {
Expand Down
2 changes: 1 addition & 1 deletion server/planning/events/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ def _link_to_planning(event):
updates,
planning_item
)
app.on_updated_planning(updates, {'_id': plan_id})
app.on_updated_planning(updates, planning_item)

def get_expired_items(self, expiry_datetime, spiked_events_only=False):
"""Get the expired items
Expand Down
15 changes: 14 additions & 1 deletion server/planning/events/events_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

"""Superdesk Files"""

from superdesk import Resource
from superdesk import Resource, get_resource_service
from planning.history import HistoryService
import logging
from eve.utils import config
Expand All @@ -31,6 +31,19 @@ class EventsHistoryResource(Resource):


class EventsHistoryService(HistoryService):
def on_item_created(self, items, operation=None):
created_from_planning = []
regular_events = []
for item in items:
planning_items = get_resource_service('events').get_plannings_for_event(item)
if planning_items.count() > 0:
item['created_from_planning'] = planning_items[0].get('_id')
created_from_planning.append(item)
else:
regular_events.append((item))

super().on_item_created(created_from_planning, 'created_from_planning')
super().on_item_created(regular_events)

def on_item_deleted(self, doc):
lookup = {'event_id': doc[config.ID_FIELD]}
Expand Down
3 changes: 3 additions & 0 deletions server/planning/planning/planning_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ def on_item_updated(self, updates, original, operation=None):
if original.get(LOCK_ACTION) == 'assign_agenda':
diff['agendas'] = [a for a in diff.get('agendas', []) if a not in original.get('agendas', [])]

if diff.get('event_item'):
operation = 'create_event'

self._save_history(item, diff, operation)

self._save_coverage_history(updates, original)
Expand Down

0 comments on commit b8fe434

Please sign in to comment.