Skip to content

Commit

Permalink
Merge branch 'master' into addMetadataToDeckPage
Browse files Browse the repository at this point in the history
  • Loading branch information
aoelen committed Dec 14, 2018
2 parents 9bbac8c + ec682bc commit 43c27d4
Show file tree
Hide file tree
Showing 41 changed files with 6,700 additions and 1,751 deletions.
8 changes: 8 additions & 0 deletions actions/import/storeTags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { shortTitle } from '../../configs/general';
const log = require('../log/clog');

export default function storeTags(context, payload, done) {
log.info(context);
context.dispatch('STORE_TAGS', payload);
done();
}
31 changes: 21 additions & 10 deletions actions/loadDeck.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ import log from './log/clog';
export default function loadDeck(context, payload, done) {
log.info(context); // do not remove such log messages. If you don't want to see them, change log level in config
context.dispatch('UPDATE_MODE', {mode: 'loading'});

// resets the deck view store
// TODO (what other store to reset ???)
context.dispatch('LOAD_DECK_PAGE_START');

if (!(AllowedPattern.DECK_ID.test(payload.params.id))) {
context.executeAction(deckIdTypeError, payload, done);
return;
Expand Down Expand Up @@ -102,16 +107,6 @@ export default function loadDeck(context, payload, done) {

payload.params.jwt = context.getStore(UserProfileStore).getState().jwt;

let permissionsPromise;
//if user is not logged in, only allow view mode and reset permissions, else load this user's permissions on the selected root deck
if (!payload.params.jwt){
if (!payload.query.interestedUser) //NOTE should not be changed in the special case: Link from email for deck owner to add new editor
payloadCustom.params.mode = 'view';
permissionsPromise = context.executeAction(resetPermissions, payloadCustom);
} else {
permissionsPromise = context.executeAction(loadPermissions, payloadCustom);
}

context.dispatch('UPDATE_DECK_PAGE_CONTENT', payloadCustom);
pageTitle = pageTitle + ' | ' + payloadCustom.params.stype + ' | ' + payloadCustom.params.sid + ' | ' + payloadCustom.params.mode;
if((currentState.selector.id === payloadCustom.params.id) && (currentState.selector.spath === payloadCustom.params.spath)){
Expand All @@ -131,6 +126,12 @@ export default function loadDeck(context, payload, done) {

// load translation stuff
context.executeAction(loadNodeTranslations, payload.params, (err, results) => {
if (err) {
// log the error and return!!!
log.error(context, {filepath: __filename, message: err.message});
return done(err);
}

//load all required actions in parallel
async.parallel([
(callback) => {
Expand All @@ -141,6 +142,16 @@ export default function loadDeck(context, payload, done) {
}, callback);
},
(callback) => {
let permissionsPromise;
//if user is not logged in, only allow view mode and reset permissions, else load this user's permissions on the selected root deck
if (!payload.params.jwt){
if (!payload.query.interestedUser) //NOTE should not be changed in the special case: Link from email for deck owner to add new editor
payloadCustom.params.mode = 'view';
permissionsPromise = context.executeAction(resetPermissions, payloadCustom);
} else {
permissionsPromise = context.executeAction(loadPermissions, payloadCustom);
}

permissionsPromise.then(() => {
let permissions = context.getStore(PermissionsStore).getState().permissions;
//special handling for special case: Link from email for deck owner to add new editor
Expand Down
9 changes: 2 additions & 7 deletions actions/loadDeckView.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,14 @@ export default function loadDeckView(context, payload, done) {

context.service.read('deck.content', payload, {timeout: 20 * 1000}, (err, res) => {
if (err) {
console.log(err);
log.error(context, {filepath: __filename});
log.error(context, {filepath: __filename, message: err.message });
context.executeAction(serviceUnavailable, payload, done);
return;
} else {
// console.log('loadDeckView params', payload.params, '\n', payload);
res.isRootDeck = payload.params.spath === '';
context.dispatch('LOAD_DECK_CONTENT_SUCCESS', res);
context.dispatch('LOAD_DECK_METADATA_SUCCESS', {
thumbnailID: res.slidesData.children[0].id,
thumbnailTheme: res.slidesData.theme,
description: res.deckData.description
});
context.dispatch('LOAD_DECK_METADATA_SUCCESS', {thumbnailID: res.slidesData.children[0].id});
}
let pageTitle = shortTitle + ' | ' + res.slidesData.title;
let cleanTitle = pageTitle.replace(/<\/?[^>]+(>|$)/g, '').replace(/&#39;/g, '\'').replace(/&#34;/g, '\"');
Expand Down
2 changes: 1 addition & 1 deletion actions/loadLegacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default function loadLegacy(context, payload, done) {
context.executeAction(serviceUnavailable, payload, done);
//context.dispatch('LOAD_FEATURED_FAILURE', err);
} else {
done({'statusCode':'301','redirectURL': '/deck/' + res.new_id});
done({'statusCode': 301,'redirectURL': '/deck/' + res.new_id});
}
});
}
5 changes: 3 additions & 2 deletions actions/slide/changeSlideTransition.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import {shortTitle} from '../../configs/general';
import serviceUnavailable from '../error/serviceUnavailable';
const log = require('../log/clog');

export default function changeSlideSize(context, payload, done) {
export default function changeSlideTransition(context, payload, done) {
//catched by slideEditStore
context.dispatch('CHANGE_SLIDE_TRANSITION', {
slideTransition: payload.slideTransition
slideTransition: payload.slideTransition //,
// transitionType: payload.transitionType //
});
}
4 changes: 0 additions & 4 deletions actions/slide/loadSlideView.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ export default function loadSlideView(context, payload, done) {
} else {
context.dispatch('LOAD_SLIDE_CONTENT_SUCCESS', res);
context.dispatch('LOAD_SLIDE_EDIT_SUCCESS', res);
context.dispatch('LOAD_DECK_METADATA_SUCCESS', {
thumbnailID: res.selector.sid,
thumbnailTheme: context.getStore(DeckTreeStore).theme
});
}
let deckTitle = context.getStore(DeckTreeStore).getState().deckTree.get('title');
let pageTitle = shortTitle + ' | ' + deckTitle + ' | ' + res.slide.title;
Expand Down
26 changes: 26 additions & 0 deletions actions/slide/saveSlideWithDeckTransition.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const log = require('../log/clog');
import saveSlide from './saveSlide';

export default function saveSlideWithDeckTransition(context, payload, done) {
let args = {
id: payload.currentSlidePayload.deckID
};
context.service.read('deck.slides', args, {timeout: 20 * 1000}, (err, res) => {
res.slides.map((slide) => {
if(slide.id === payload.currentSlidePayload.id) {
context.executeAction(saveSlide, payload.currentSlidePayload);
} else {
let otherPayload = {
id: slide.id,

transition: payload.currentSlidePayload.transition
};
// Extract necessary information from each slide, add transition and update it in deck-service.

}
});
});



}
4 changes: 2 additions & 2 deletions actions/translation/loadNodeTranslations.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export default function loadNodeTranslations(context, payload, done) {

context.service.read('decktree.nodetranslation', payload, {timeout: 20 * 1000}, (err, res) => {
if (err) {
log.error(context, {filepath: __filename});
context.executeAction(serviceUnavailable, payload, done);
log.error(context, {filepath: __filename, message: err.message});
done(err);
} else {
context.dispatch('LOAD_TRANSLATIONS_SUCCESS', res);
done();
Expand Down
39 changes: 34 additions & 5 deletions components/AddDeck/AddDeck.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import checkNoOfSlides from '../../actions/addDeck/checkNoOfSlides';
import importCanceled from '../../actions/import/importCanceled';
import importFinished from '../../actions/import/importFinished';
import uploadFile from '../../actions/import/uploadFile';
import storeTags from '../../actions/import/storeTags';
import addActivity from '../../actions/activityfeed/addActivity';
import publishDeck from '../../actions/addDeck/publishDeck';
import ImportModal from '../Import/ImportModal';
Expand All @@ -33,6 +34,7 @@ class AddDeck extends React.Component {
constructor(props) {
super(props);
this.percentage = 0;
this.defaultTagNames = [];// used for saving defaultName properties for tags
}
componentDidMount() {
// let that = this;
Expand Down Expand Up @@ -75,7 +77,8 @@ class AddDeck extends React.Component {
}
handleAddDeck(x) {
//console.log('handleAddDeck');

this.saveTags();

this.context.executeAction(addDeckDeleteError, null);

//validate input
Expand All @@ -86,7 +89,14 @@ class AddDeck extends React.Component {
const { value: educationLevel } = this.refs.dropdown_level.getSelectedItem();
// const license = this.refs.select_licenses.value;
const license = 'CC BY-SA';//default license
const tags = [...this.tagInput.getSelected(), ...this.topicInput.getSelected()];
let tags = [...this.tagInput.getSelected(), ...this.topicInput.getSelected()];
tags.forEach((tag) => {
// check whether we have earlier assigned defaultName to tagName (in saveTags function) for this tag and restore the original state
if (this.defaultTagNames.includes(tag.tagName)) {
tag.defaultName = tag.tagName;
delete tag.tagName;
}
});
const acceptedConditions = this.refs.checkbox_conditions.checked;
const acceptedImagesLicense = this.refs.checkbox_imageslicense.checked;
//console.log(title, language, description, theme, license, tags, acceptedConditions);
Expand Down Expand Up @@ -413,6 +423,25 @@ class AddDeck extends React.Component {
console.error('Submission not possible - no file or not pptx/odp/zip');
}
}

saveTags() {
let tags = this.tagInput.getSelected();
tags.forEach((tag) => {
if (!tag.tagName && tag.defaultName) {
tag.tagName = tag.defaultName;//assign defaultName to tagName to avoid errors during the initialization of the TagInput component
this.defaultTagNames.push((tag.defaultName));//save defaultName in the array so that in the end we can restore the tag state in handleAddDeck
}
});
let topics = this.topicInput.getSelected();
topics.forEach((topic) => {
if (!topic.tagName && topic.defaultName) {
topic.tagName = topic.defaultName;
this.defaultTagNames.push((topic.defaultName));
}
});
//save tags in the store so that they can be restored during the initialization of TagInput component
this.context.executeAction(storeTags, {tags:tags, topics: topics});
}

render() {
//redirect to new deck if created
Expand Down Expand Up @@ -611,13 +640,13 @@ class AddDeck extends React.Component {
</div>
<div className="field">
<label htmlFor="topics_input_field" id="topics_label"><FormattedMessage id='DeckProperty.Tag.Topic.Choose' defaultMessage='Choose Subject' /></label>
<TagInput id="topics_input_field" initialTags={[]} ref={(i) => (this.topicInput = i)} tagFilter={{ tagType: 'topic' }} aria-labelledby="topics_label" aria-describedby="describe_topic" />
<TagInput id="topics_input_field" initialTags={this.props.ImportStore.topics} ref={(i) => (this.topicInput = i)} tagFilter={{ tagType: 'topic' }} aria-labelledby="topics_label" aria-describedby="describe_topic" />
</div>
</div>

<div className="field">
<label htmlFor="tags_input_field" id="tags_label"><FormattedMessage id='DeckProperty.Tag.Choose' defaultMessage='Choose Tags' /></label>
<TagInput id="tags_input_field" initialTags={[]} ref={(i) => (this.tagInput = i)} allowAdditions={true} aria-labelledby="tags_label" aria-describedby="describe_tags" />
<TagInput id="tags_input_field" initialTags={this.props.ImportStore.tags} ref={(i) => (this.tagInput = i)} allowAdditions={true} aria-labelledby="tags_label" aria-describedby="describe_tags" />
</div>

<div className="ui message" id="uploadDesc">
Expand All @@ -637,7 +666,7 @@ class AddDeck extends React.Component {
defaultMessage='Select file' />
</div>
*/}
<ImportModal />
<ImportModal savetags={this.saveTags.bind(this)}/>
{/* <Import />*/}

</div>
Expand Down
Loading

0 comments on commit 43c27d4

Please sign in to comment.