-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into SWIK-1848_tag_recommendation
- Loading branch information
Showing
48 changed files
with
2,680 additions
and
237 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.