Skip to content

Commit

Permalink
Merge branch 'master' into SWIK-1848_tag_recommendation
Browse files Browse the repository at this point in the history
  • Loading branch information
schatzopoulos authored Feb 9, 2018
2 parents 592909c + 98a2f71 commit f6560c5
Show file tree
Hide file tree
Showing 48 changed files with 2,680 additions and 237 deletions.
21 changes: 21 additions & 0 deletions actions/collections/addNewCollection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const log = require('../log/clog');
import serviceUnavailable from '../error/serviceUnavailable';
import UserProfileStore from '../../stores/UserProfileStore';

export default function addNewCollection(context, payload, done) {
log.info(context);

// enrich payload with jwt
payload.jwt = context.getStore(UserProfileStore).jwt;

context.service.create('deckgroups.create', payload, {timeout: 20 * 1000}, (err, res) => {
if (err) {
log.error(context, {filepath: __filename});
context.dispatch('ADD_COLLECTION_FAILURE', err);
} else {
context.dispatch('ADD_COLLECTION_SUCCESS', res);
}

done();
});
}
8 changes: 8 additions & 0 deletions actions/collections/addSelectedCollection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const log = require('../log/clog');
import serviceUnavailable from '../error/serviceUnavailable';

export default function addSelectedCollection(context, payload, done) {
log.info(context);
context.dispatch('ADD_SELECTED_COLLECTION', payload);
done();
}
21 changes: 21 additions & 0 deletions actions/collections/deleteCollection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const log = require('../log/clog');
import serviceUnavailable from '../error/serviceUnavailable';
import UserProfileStore from '../../stores/UserProfileStore';

export default function deleteCollection(context, payload, done) {
log.info(context);

// enrich payload with jwt
payload.jwt = context.getStore(UserProfileStore).jwt;

context.dispatch('SET_COLLECTIONS_LOADING'); // show loading indicator

context.service.delete('deckgroups.item', payload, {timeout: 20 * 1000}, (err, res) => {
if (err) {
log.error(context, {filepath: __filename});
context.dispatch('DELETE_COLLECTION_FAILURE', err);
return;
}
context.dispatch('DELETE_COLLECTION_SUCCESS', {id: payload.id});
});
}
35 changes: 35 additions & 0 deletions actions/collections/loadCollection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import async from 'async';
const log = require('../log/clog');
import serviceUnavailable from '../error/serviceUnavailable';
import notFoundError from '../error/notFoundError';
import loadCollectionDetails from './loadCollectionDetails';
import fetchUser from '../../actions/user/userprofile/fetchUser';
import UserProfileStore from '../../stores/UserProfileStore';

// loads deck collection details and user info
export default function loadCollection(context, payload, done) {
log.info(context);

// load required actions in parallel
async.parallel([
(callback) => {
context.executeAction(fetchUser, {
params: {
username: context.getStore(UserProfileStore).getState().username
}
}, callback);
},
(callback) => {
context.executeAction(loadCollectionDetails, payload, callback);
}
], (err, results) => {
if (err) {
log.error(context, {filepath: __filename});
context.executeAction(serviceUnavailable, payload, done);
return;
}

done();
});

}
26 changes: 26 additions & 0 deletions actions/collections/loadCollectionDetails.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const log = require('../log/clog');
import serviceUnavailable from '../error/serviceUnavailable';
import notFoundError from '../error/notFoundError';

// loads a deck collection
export default function loadCollectionDetails(context, payload, done) {
log.info(context);

context.dispatch('SET_COLLECTIONS_LOADING'); // show loading indicator

context.service.read('deckgroups.get', payload, {timeout: 20 * 1000}, (err, res) => {
if (err) {
if(err.statusCode === 404){
context.executeAction(notFoundError, {}, done);
return;
}
log.error(context, {filepath: __filename});
context.dispatch('LOAD_COLLECTION_DETAILS_FAILURE', err);
} else {
res.sortBy = (payload.query.sort) ? payload.query.sort : 'order';
context.dispatch('LOAD_COLLECTION_DETAILS_SUCCESS', res);
}

done();
});
}
43 changes: 43 additions & 0 deletions actions/collections/loadDeckCollections.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const log = require('../log/clog');
import serviceUnavailable from '../error/serviceUnavailable';
import UserProfileStore from '../../stores/UserProfileStore';

// loads deck groups assigned by the current user to a deck
export default function loadDeckCollections(context, payload, done) {
log.info(context);

// enrich payload with user id
if(payload.params){
payload.params.userId = context.getStore(UserProfileStore).userid;
payload.params.jwt = context.getStore(UserProfileStore).jwt;
} else {
payload.userId = context.getStore(UserProfileStore).userid;
payload.jwt = context.getStore(UserProfileStore).jwt;
}

context.dispatch('UPDATE_COLLECTIONS_LOADING', true);

// first get user groups that the user is member of
context.service.read('usergroup.member', payload, {timeout: 20 * 1000}, (err, usergroups) => {
if(err){
log.error(context, {filepath: __filename});
done();
} else {

// then get deck collection options
payload.usergroups = usergroups;
context.service.read('deckgroups.forDeck', payload, {timeout: 20 * 1000}, (err, res) => {
if (err) {
log.error(context, {filepath: __filename});
context.dispatch('LOAD_COLLECTIONS_FAILURE', err);
} else {
context.dispatch('LOAD_COLLECTIONS_SUCCESS', res);
}

context.dispatch('UPDATE_COLLECTIONS_LOADING', false);

done();
});
}
});
}
65 changes: 65 additions & 0 deletions actions/collections/loadUserCollections.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
const log = require('../log/clog');
import serviceUnavailable from '../error/serviceUnavailable';
import UserProfileStore from '../../stores/UserProfileStore';

// loads deck collections created by the current user or his user groups
export default function loadUserCollections(context, payload, done) {
log.info(context);

context.dispatch('SET_COLLECTIONS_LOADING'); // show loading indicator

// request deck collections for the loggedin user
if(context.getStore(UserProfileStore).userid === context.getStore(UserProfileStore).user.id){

// enrich payload with user id and authToken
if(payload.params){
payload.params.userId = context.getStore(UserProfileStore).userid;
payload.params.jwt = context.getStore(UserProfileStore).jwt;
} else {
payload.userId = context.getStore(UserProfileStore).userid;
payload.jwt = context.getStore(UserProfileStore).jwt;
}

// first get user groups that the user is member of
context.service.read('usergroup.member', payload, {timeout: 20 * 1000}, (err, usergroups) => {
if(err){
log.error(context, {filepath: __filename});
done();
} else {

// then get deck collection corresponding to the loggedin user and his user groups
payload.usergroups = usergroups;
context.service.read('deckgroups.forUser', payload, {timeout: 20 * 1000}, (err, res) => {
if (err) {
log.error(context, {filepath: __filename});
context.dispatch('LOAD_USER_COLLECTIONS_FAILURE', err);
} else {
context.dispatch('LOAD_USER_COLLECTIONS_SUCCESS', res);
}

done();
});
}
});

// request deck collections for a user that is not the logged in one
} else {
if(payload.params){
payload.params.userId = context.getStore(UserProfileStore).user.id;
} else {
payload.userId = context.getStore(UserProfileStore).user.id;
}

// just get the deck collections for this user
context.service.read('deckgroups.forUser', payload, {timeout: 20 * 1000}, (err, res) => {
if (err) {
log.error(context, {filepath: __filename});
context.dispatch('LOAD_USER_COLLECTIONS_FAILURE', err);
} else {
context.dispatch('LOAD_USER_COLLECTIONS_SUCCESS', res);
}

done();
});
}
}
8 changes: 8 additions & 0 deletions actions/collections/removeSelectedCollection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const log = require('../log/clog');
import serviceUnavailable from '../error/serviceUnavailable';

export default function removeSelectedCollections(context, payload, done) {
log.info(context);
context.dispatch('REMOVE_SELECTED_COLLECTION', payload);
done();
}
29 changes: 29 additions & 0 deletions actions/collections/updateCollectionDeckOrder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const log = require('../log/clog');
import serviceUnavailable from '../error/serviceUnavailable';
import UserProfileStore from '../../stores/UserProfileStore';
import { navigateAction } from 'fluxible-router';

export default function updateCollectionDeckOrder(context, payload, done) {
log.info(context);

// enrich payload with jwt
payload.jwt = context.getStore(UserProfileStore).jwt;

context.service.update('deckgroups.deckOrder', payload, {timeout: 20 * 1000}, (err, res) => {
if (err) {
log.error(context, {filepath: __filename});
context.dispatch('UPDATE_COLLECTION_DECK_ORDER_FAILURE', err);
} else {
context.dispatch('UPDATE_COLLECTION_DECK_ORDER_SUCCESS', res);

// redirect when new order has been saved
context.executeAction(navigateAction, {
url: `/collection/${payload.id}?sort=order`,
});
}



done();
});
}
31 changes: 31 additions & 0 deletions actions/collections/updateCollectionDecks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const log = require('../log/clog');
import serviceUnavailable from '../error/serviceUnavailable';
import UserProfileStore from '../../stores/UserProfileStore';

export default function updateCollectionDecks(context, payload, done) {
log.info(context);

// enrich payload with jwt
payload.userId = context.getStore(UserProfileStore).userid;
payload.jwt = context.getStore(UserProfileStore).jwt;

// first get user groups that the user is member of
context.service.read('usergroup.member', payload, {timeout: 20 * 1000}, (err, usergroups) => {
if(err){
log.error(context, {filepath: __filename});
done();
} else {

payload.usergroups = usergroups;
context.service.update('deckgroups.decks', payload, {timeout: 20 * 1000}, (err, res) => {
if (err) {
console.log(err);
log.error(context, {filepath: __filename});
context.dispatch('UPDATE_DECKS_OF_DECK_GROUP_ERROR', err);
}

done();
});
}
});
}
22 changes: 22 additions & 0 deletions actions/collections/updateCollectionMetadata.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const log = require('../log/clog');
import serviceUnavailable from '../error/serviceUnavailable';
import UserProfileStore from '../../stores/UserProfileStore';

export default function updateCollectionDecks(context, payload, done) {
log.info(context);

// enrich payload with jwt
payload.userId = context.getStore(UserProfileStore).userid;
payload.jwt = context.getStore(UserProfileStore).jwt;

context.service.update('deckgroups.metadata', payload, {timeout: 20 * 1000}, (err, res) => {
if (err) {
console.log(err);
log.error(context, {filepath: __filename});
context.dispatch('UPDATE_COLLECTION_METADATA_ERROR', err);
} else {
context.dispatch('UPDATE_COLLECTION_METADATA', res);
}
done();
});
}
9 changes: 9 additions & 0 deletions actions/loadDeckEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import slideIdTypeError from './error/slideIdTypeError';
import { AllowedPattern } from './error/util/allowedPattern';
import UserProfileStore from '../stores/UserProfileStore';
import serviceUnavailable from './error/serviceUnavailable';
import loadUserCollections from './collections/loadUserCollections';
import loadDeckCollections from './collections/loadDeckCollections';
const log = require('./log/clog');

export default function loadDeckEdit(context, payload, done) {
Expand All @@ -14,7 +16,14 @@ export default function loadDeckEdit(context, payload, done) {
return;
}

// load deck collections of the current user
context.executeAction(loadUserCollections, payload, done);

// load deck groups assigned to the current deck
context.executeAction(loadDeckCollections, payload, done);

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

context.service.read('deck.properties', payload, {timeout: 20 * 1000}, (err, res) => {
if (err) {
log.error(context, {filepath: __filename});
Expand Down
7 changes: 6 additions & 1 deletion actions/user/userprofile/chooseAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import fetchUser from './fetchUser';
import { fetchUserDecks } from './fetchUserDecks';
import notFoundError from '../../error/notFoundError';
const log = require('../../log/clog');
import loadUserCollections from '../../collections/loadUserCollections';
import { shortTitle } from '../../../configs/general';
import UserProfileStore from '../../../stores/UserProfileStore';

export const categories = { //Do NOT alter the order of these items! Just add your items. Used in UserProfile and CategoryBox components
categories: ['settings', 'groups'],
categories: ['settings', 'groups', 'collections'],
settings: ['profile', 'account', 'integrations'],
groups: ['overview', 'edit']
};
Expand Down Expand Up @@ -66,6 +67,10 @@ export function chooseAction(context, payload, done) {
context.dispatch('USER_CATEGORY', {category: payload.params.category, item: payload.params.item});
callback();
break;
case categories.categories[2]:
context.dispatch('USER_CATEGORY', {category: payload.params.category, item: payload.params.item});
context.executeAction(loadUserCollections, {}, callback);
break;
case undefined:
context.executeAction(fetchUserDecks, {params: {username: payload.params.username}}, callback);
break;
Expand Down
3 changes: 2 additions & 1 deletion actions/user/userprofile/fetchUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ export default function fetchUser(context, payload, done) {
}
} else {
if(!isEmpty(payload.params.category)){
if(context.getStore(UserProfileStore).username === payload.params.username)
if(context.getStore(UserProfileStore).username === payload.params.username
|| payload.params.category === 'collections') // allow route /{username}/collections
res.category = isEmpty(payload.params.category) ? '' : payload.params.category;
else{
context.executeAction(notFoundError, {}, done);
Expand Down
Loading

0 comments on commit f6560c5

Please sign in to comment.