Skip to content

Commit

Permalink
Merge pull request #542 from slidewiki/SWIK-1085-new_activities_for_u…
Browse files Browse the repository at this point in the history
…sing_and_duplicating_slides

Swik 1085 new activities for using slides
  • Loading branch information
kadevgraaf authored Sep 15, 2017
2 parents 9a44e92 + bbe19b5 commit c31bf7e
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 10 deletions.
5 changes: 3 additions & 2 deletions components/Deck/ActivityFeedPanel/ActivityItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,14 @@ class ActivityItem extends React.Component {
);
break;
case 'use':
IconNode = (<i className="ui large copy icon"></i>);
IconNode = (<i className="ui large attach icon"></i>);
const title = (node.use_info.target_name !== '') ? node.use_info.target_name : node.use_info.target_id;
SummaryNode = (
<div className="summary">
<a className="user" href={node.user_id ? '/user/' + node.user_id : ''}>
{node.author ? node.author.username : 'unknown'}
</a> {'used '} {nodeRef}
{' in deck '}<a href={'/deckview/' + node.use_info.target_id}>{node.use_info.target_name}</a>
{' in deck '}<a href={'/deck/' + node.use_info.target_id}>{title}</a>
<br/>
{DateDiv}
</div>
Expand Down
50 changes: 48 additions & 2 deletions components/Deck/ContentPanel/AttachSubdeck/AttachSlidesModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {connectToStores} from 'fluxible-addons-react';
import {Button, Icon, Modal, Container, Segment, TextArea, Popup} from 'semantic-ui-react';
import UserProfileStore from '../../../../stores/UserProfileStore';
import AttachSubdeckModalStore from '../../../../stores/AttachSubdeckModalStore';
import DeckTreeStore from '../../../../stores/DeckTreeStore';
import FocusTrap from 'focus-trap-react';
import loadUserDecks from '../../../../actions/attachSubdeck/loadUserDecks';
import loadRecentDecks from '../../../../actions/attachSubdeck/loadRecentDecks';
Expand All @@ -12,6 +13,7 @@ import initModal from '../../../../actions/attachSubdeck/initModal';
import addTreeNodeListAndNavigate from '../../../../actions/decktree/addTreeNodeListAndNavigate';
import updateSelectedSlides from '../../../../actions/attachSubdeck/updateSelectedSlides';
import updateSelectedDeck from '../../../../actions/attachSubdeck/updateSelectedDeck';
import addActivities from '../../../../actions/activityfeed/addActivities';
import AttachMenu from './AttachMenu';
import AttachMyDecks from './AttachMyDecks';
import AttachSlideWiki from './AttachSlideWiki';
Expand Down Expand Up @@ -146,6 +148,34 @@ class AttachSubdeckModal extends React.Component{
};
});
this.context.executeAction(addTreeNodeListAndNavigate, {selector: this.props.selector, nodeSpec:nodeSpec});

//find target deck id
let targetDeckId = this.props.selector.sid;
if (this.props.selector.stype === 'slide') {
const pathArray = this.props.selector.spath.split(';');
if (pathArray.length > 1) {
const parentDeck = pathArray[pathArray.length - 2];
targetDeckId = parentDeck.split(':')[0];
} else {
targetDeckId = this.props.selector.id;
}
}

let activities = nodeSpec.map((node) => {
return {
activity_type: 'use',
user_id: String(this.props.UserProfileStore.userid),
content_id: node.id,
content_kind: 'slide',
use_info: {
target_id: targetDeckId,
target_name: this.getTitle(this.props.DeckTreeStore.deckTree, 'deck', targetDeckId)
}
};
});

this.context.executeAction(addActivities, {activities: activities});

this.handleClose();

}
Expand All @@ -158,6 +188,21 @@ class AttachSubdeckModal extends React.Component{

}

//find node title
getTitle(deckTree, type, id) {
let title = '';
if (deckTree.get('type') === type && deckTree.get('id') === id) {
title = deckTree.get('title');
} else if (deckTree.get('type') === 'deck') {
deckTree.get('children').forEach((item, index) => {
if (title === '') {
title = this.getTitle(item, type, id);
}
});
}

return title;
}

render() {

Expand Down Expand Up @@ -285,10 +330,11 @@ AttachSubdeckModal.contextTypes = {
executeAction: React.PropTypes.func.isRequired
};

AttachSubdeckModal = connectToStores(AttachSubdeckModal,[UserProfileStore,AttachSubdeckModalStore],(context,props) => {
AttachSubdeckModal = connectToStores(AttachSubdeckModal,[UserProfileStore,AttachSubdeckModalStore,DeckTreeStore],(context,props) => {
return {
UserProfileStore: context.getStore(UserProfileStore).getState(),
AttachSubdeckModalStore: context.getStore(AttachSubdeckModalStore).getState()
AttachSubdeckModalStore: context.getStore(AttachSubdeckModalStore).getState(),
DeckTreeStore: context.getStore(DeckTreeStore).getState()
};
});

Expand Down
48 changes: 46 additions & 2 deletions components/Deck/ContentPanel/AttachSubdeck/AttachSubdeckModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import {connectToStores} from 'fluxible-addons-react';
import { Button, Icon, Modal, Container, Segment, TextArea, Popup } from 'semantic-ui-react';
import UserProfileStore from '../../../../stores/UserProfileStore';
import AttachSubdeckModalStore from '../../../../stores/AttachSubdeckModalStore';
import DeckTreeStore from '../../../../stores/DeckTreeStore';
import FocusTrap from 'focus-trap-react';
import loadUserDecks from '../../../../actions/attachSubdeck/loadUserDecks';
import loadRecentDecks from '../../../../actions/attachSubdeck/loadRecentDecks';
import resetModalStore from '../../../../actions/attachSubdeck/resetModalStore';
import initModal from '../../../../actions/attachSubdeck/initModal';
import addTreeNodeAndNavigate from '../../../../actions/decktree/addTreeNodeAndNavigate';
import addActivity from '../../../../actions/activityfeed/addActivity';
import AttachDeckList from './AttachDeckList';
import AttachMenu from './AttachMenu';
import AttachMyDecks from './AttachMyDecks';
Expand Down Expand Up @@ -108,10 +110,51 @@ class AttachSubdeckModal extends React.Component{
//selector: Object {id: "56", stype: "deck", sid: 67, spath: "67:2"}
//nodeSec: Object {type: "deck", id: 1245-2}
this.context.executeAction(addTreeNodeAndNavigate, {selector: this.props.selector, nodeSpec: {type:'deck',id:this.state.selectedDeckId}});

//find target deck id
let targetDeckId = this.props.selector.sid;
if (this.props.selector.stype === 'slide') {
const pathArray = this.props.selector.spath.split(';');
if (pathArray.length > 1) {
const parentDeck = pathArray[pathArray.length - 2];
targetDeckId = parentDeck.split(':')[0];
} else {
targetDeckId = this.props.selector.id;
}
}

let activity = {
activity_type: 'use',
user_id: String(this.props.UserProfileStore.userid),
content_id: this.state.selectedDeckId,
content_kind: 'deck',
use_info: {
target_id: targetDeckId,
target_name: this.getTitle(this.props.DeckTreeStore.deckTree, 'deck', targetDeckId)
}
};

this.context.executeAction(addActivity, {activity: activity});

this.handleClose();

}

//find node title
getTitle(deckTree, type, id) {
let title = '';
if (deckTree.get('type') === type && deckTree.get('id') === id) {
title = deckTree.get('title');
} else if (deckTree.get('type') === 'deck') {
deckTree.get('children').forEach((item, index) => {
if (title === '') {
title = this.getTitle(item, type, id);
}
});
}

return title;
}

render() {

Expand Down Expand Up @@ -211,10 +254,11 @@ AttachSubdeckModal.contextTypes = {
executeAction: React.PropTypes.func.isRequired
};

AttachSubdeckModal = connectToStores(AttachSubdeckModal,[UserProfileStore,AttachSubdeckModalStore],(context,props) => {
AttachSubdeckModal = connectToStores(AttachSubdeckModal,[UserProfileStore,AttachSubdeckModalStore,DeckTreeStore],(context,props) => {
return {
UserProfileStore: context.getStore(UserProfileStore).getState(),
AttachSubdeckModalStore: context.getStore(AttachSubdeckModalStore).getState()
AttachSubdeckModalStore: context.getStore(AttachSubdeckModalStore).getState(),
DeckTreeStore: context.getStore(DeckTreeStore).getState()
};
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,16 @@ class UserNotificationsItem extends React.Component {
);
break;
case 'use':
const useIconClass = allIconClass.concat(' copy');
const useIconClass = allIconClass.concat(' attach');
const title = (node.use_info.target_name !== '') ? node.use_info.target_name : node.use_info.target_id;
iconNotification = (<i className={useIconClass}></i>);
summaryNotification = (
<div className="summary">
<a className="user" href={notification.user_id ? '/user/' + notification.user_id : ''}>
{notification.author ? notification.author.username : 'unknown'}
</a> {'used ' + notification.content_kind + ' '}
<a href={viewPath}>{cheerioContentName}</a>
{/*{' in deck '}<a href={'/slideview/' + notification.use_info.target_id}>{notification.use_info.target_name}</a>*/}
{' in deck '}<a href={'/deckview/' + notification.use_info.target_id}>{notification.use_info.target_name}</a>
{' in deck '}<a href={'/deck/' + notification.use_info.target_id}>{title}</a>
<br/>
{DateDiv}
</div>
Expand Down
2 changes: 1 addition & 1 deletion stores/UserNotificationsStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class UserNotificationsStore extends BaseStore {
{type:'react', selected: true},
// {type:'rate', selected: true},
// {type:'translate', selected: true},
// {type:'use', selected: true},
{type:'use', selected: true},
{type:'fork', selected: true},
{type:'delete', selected: true},
{type:'joined', selected: true},
Expand Down

0 comments on commit c31bf7e

Please sign in to comment.