Merge branch 'master' into asset-settings

This commit is contained in:
Wyatt Johnson
2016-11-28 17:16:39 -07:00
13 changed files with 43 additions and 94 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
import * as actions from '../constants/auth';
import {base, handleResp, getInit} from '../helpers/response';
import {base, handleResp, getInit} from '../../../coral-framework/helpers/response';
// Check Login
+1 -1
View File
@@ -9,7 +9,7 @@ import {
SET_ROLE
} from '../constants/community';
import {base, getInit, handleResp} from '../helpers/response';
import {base, getInit, handleResp} from '../../../coral-framework/helpers/response';
export const fetchCommenters = (query = {}) => dispatch => {
dispatch(requestFetchCommenters());
+1 -1
View File
@@ -1,4 +1,4 @@
import {base, handleResp, getInit} from '../helpers/response';
import {base, handleResp, getInit} from '../../../coral-framework/helpers/response';
export const SETTINGS_LOADING = 'SETTINGS_LOADING';
export const SETTINGS_RECEIVED = 'SETTINGS_RECEIVED';
@@ -1,4 +1,4 @@
import {base, handleResp, getInit} from '../helpers/response';
import {base, handleResp, getInit} from '../../../coral-framework/helpers/response';
/**
* The adapter is a redux middleware that interecepts the actions that need
+1 -3
View File
@@ -2,9 +2,7 @@ import React from 'react';
import {render} from 'react-dom';
import CommentStream from './CommentStream';
import {Provider} from 'react-redux';
import {fetchConfig, store} from '../../coral-framework';
store.dispatch(fetchConfig());
import {store} from '../../coral-framework';
render(
<Provider store={store}>
-35
View File
@@ -1,35 +0,0 @@
import {fromJS} from 'immutable';
/**
* Action name constants
*/
export const FETCH_CONFIG_REQUEST = 'FETCH_CONFIG_REQUEST';
export const FETCH_CONFIG_FAILED = 'FETCH_CONFIG_FAILED';
export const FETCH_CONFIG_SUCCESS = 'FETCH_CONFIG_SUCCESS';
/**
* Action creators
*/
export function fetchConfig () {
return (dispatch) => {
dispatch({type: FETCH_CONFIG_REQUEST});
return fetch('/api/v1/settings')
.then(
response => {
return response.ok ? response.json()
: Promise.reject(`${response.status} ${response.statusText}`);
}
)
.then((json) => {
return dispatch({type: FETCH_CONFIG_SUCCESS, config: fromJS(json)});
})
.catch((error) => {
dispatch({type: FETCH_CONFIG_FAILED, error});
});
};
}
+28 -30
View File
@@ -1,3 +1,5 @@
import {getInit, base, handleResp} from '../../coral-framework/helpers/response';
import {fromJS} from 'immutable';
/* Item Actions */
/**
@@ -6,28 +8,9 @@
export const ADD_ITEM = 'ADD_ITEM';
export const UPDATE_ITEM = 'UPDATE_ITEM';
export const UPDATE_SETTINGS = 'UPDATE_SETTINGS';
export const APPEND_ITEM_ARRAY = 'APPEND_ITEM_ARRAY';
const getInit = (method, body) => {
const headers = {
'Content-Type': 'application/json',
'Accept': 'application/json'
};
const init = {method, headers};
if (body) {
init.body = JSON.stringify(body);
}
return init;
};
const responseHandler = response => {
if (response.status === 204) {
return;
}
return response.ok ? response.json() : Promise.reject(`${response.status} ${response.statusText}`);
};
/**
* Action creators
*/
@@ -61,6 +44,7 @@ export const addItem = (item, item_type) => {
* id - the id of the item to be posted
* property - the property to be updated
* value - the value that the property should be set to
* item_type - the type of the item being updated (users, comments, etc)
*
*/
export const updateItem = (id, property, value, item_type) => {
@@ -73,6 +57,18 @@ export const updateItem = (id, property, value, item_type) => {
};
};
/*
* Appends data to an array in an item in the local store without posting it to the server
* Useful for adding a recently posted reply to a comment, etc.
*
* @params
* id - the id of the item to be posted
* property - the property to be updated (should be an array)
* value - the value that should be added to the array
* add_to_front - boolean that defines whether value is added at the beginning (unshift) or end (push)
* item_type - the type of the item being updated (users, comments, etc)
*
*/
export const appendItemArray = (id, property, value, add_to_front, item_type) => {
return {
type: APPEND_ITEM_ARRAY,
@@ -99,8 +95,8 @@ export const appendItemArray = (id, property, value, add_to_front, item_type) =>
*/
export function getStream (assetUrl) {
return (dispatch) => {
return fetch(`/api/v1/stream?asset_url=${encodeURIComponent(assetUrl)}`)
.then(responseHandler)
return fetch(`${base}/stream?asset_url=${encodeURIComponent(assetUrl)}`)
.then(handleResp)
.then((json) => {
/* Add items to the store */
@@ -110,6 +106,8 @@ export function getStream (assetUrl) {
action.id = `${action.action_type}_${action.item_id}`;
dispatch(addItem(action, 'actions'));
});
} else if (type === 'settings') {
dispatch({type: UPDATE_SETTINGS, config: fromJS(json[type])});
} else {
json[type].forEach(item => {
dispatch(addItem(item, type));
@@ -168,8 +166,8 @@ export function getStream (assetUrl) {
export function getItemsArray (ids) {
return (dispatch) => {
return fetch(`/v1/item/${ids}`, getInit('GET'))
.then(responseHandler)
return fetch(`${base}/item/${ids}`, getInit('GET'))
.then(handleResp)
.then((json) => {
for (let i = 0; i < json.items.length; i++) {
dispatch(addItem(json.items[i]));
@@ -198,8 +196,8 @@ export function postItem (item, type, id) {
if (id) {
item.id = id;
}
return fetch(`/api/v1/${type}`, getInit('POST', item))
.then(responseHandler)
return fetch(`${base}/${type}`, getInit('POST', item))
.then(handleResp)
.then((json) => {
dispatch(addItem({...item, id:json.id}, type));
return json.id;
@@ -229,8 +227,8 @@ export function postAction (item_id, action_type, user_id, item_type) {
user_id
};
return fetch(`/api/v1/${item_type}/${item_id}/actions`, getInit('POST', action))
.then(responseHandler);
return fetch(`${base}/${item_type}/${item_id}/actions`, getInit('POST', action))
.then(handleResp);
};
}
@@ -251,7 +249,7 @@ export function postAction (item_id, action_type, user_id, item_type) {
export function deleteAction (action_id) {
return () => {
return fetch(`/api/v1/actions/${action_id}`, {method: 'DELETE'})
.then(responseHandler);
return fetch(`${base}/actions/${action_id}`, {method: 'DELETE'})
.then(handleResp);
};
}
+2 -2
View File
@@ -3,10 +3,10 @@ export const base = '/api/v1';
export const getInit = (method, body) => {
let init = {
method,
headers: new Headers({
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
}),
},
credentials: 'same-origin'
};
-2
View File
@@ -1,6 +1,5 @@
import Notification from './modules/notification/Notification';
import store from './store';
import {fetchConfig} from './actions/config';
import * as itemActions from './actions/items';
import I18n from './modules/i18n/i18n';
import * as notificationActions from './actions/notification';
@@ -9,7 +8,6 @@ import * as authActions from './actions/auth';
export {
Notification,
store,
fetchConfig,
itemActions,
I18n,
notificationActions,
+4 -9
View File
@@ -1,7 +1,7 @@
/* @flow */
import {Map} from 'immutable';
import * as actions from '../actions/config';
import * as actions from '../actions/items';
const initialState = Map({
features: Map({})
@@ -9,15 +9,10 @@ const initialState = Map({
export default (state = initialState, action) => {
switch(action.type) {
case actions.FETCH_CONFIG_REQUEST:
return state.set('loading', true);
case actions.FETCH_CONFIG_FAILED:
return state.set('loading', false);
// Override config if worked
case actions.FETCH_CONFIG_SUCCESS:
return action.config.set('loading', false);
// Override config if worked
case actions.UPDATE_SETTINGS:
return action.config;
default:
return state;
+1 -3
View File
@@ -1,6 +1,5 @@
const express = require('express');
const Setting = require('../../../models/setting');
const _ = require('lodash');
const router = express.Router();
@@ -8,8 +7,7 @@ router.get('/', (req, res, next) => {
Setting
.getSettings()
.then(settings => {
const whitelist = ['moderation'];
res.json(_.pick(settings, whitelist));
res.json(settings);
})
.catch(next);
});
+2 -6
View File
@@ -14,7 +14,6 @@ router.get('/', (req, res, next) => {
// Get the asset_id for this url (or create it if it doesn't exist)
Promise.all([
// Find or create the asset by url.
Asset.findOrCreateByUrl(decodeURIComponent(req.query.asset_url))
@@ -38,14 +37,12 @@ router.get('/', (req, res, next) => {
settings = Object.assign(settings, asset.settings);
}
// Fetch the appropriate comments stream.
// Fetch the appropriate comments stream.
let comments;
if (settings.moderation === 'post') {
comments = Comment.findAcceptedByAssetId(asset.id);
} else {
// Defaults to 'pre' moderation.
comments = Comment.findAcceptedAndNewByAssetId(asset.id);
}
@@ -93,7 +90,7 @@ router.get('/', (req, res, next) => {
// It's comments...
comments,
// All the users/authors of those comments...
// The users who wrote those comments
users,
// And all actions about the asset, comments, and users.
@@ -104,7 +101,6 @@ router.get('/', (req, res, next) => {
]);
})
.then(([asset, comments, users, actions, settings]) => {
// Send back the payload containing all this data.
res.json({
assets: [asset],
@@ -127,6 +127,7 @@ describe('itemActions', () => {
'Accept': 'application/json',
'Content-Type':'application/json'
},
credentials: 'same-origin',
body: JSON.stringify(item.data)
}
);