Asset API (#204)

Asset API
This commit is contained in:
Cássio Souza
2017-01-10 22:23:22 -02:00
committed by GitHub
parent 37f690fc44
commit a4d7622ade
52 changed files with 706 additions and 687 deletions

View File

@ -2,7 +2,6 @@ import yaml from "js-yaml";
import { set, defaultsDeep } from "lodash";
import { currentBackend } from "../backends/backend";
import { authenticate } from "../actions/auth";
import * as MediaProxy from "../valueObjects/MediaProxy";
import * as publishModes from "../constants/publishModes";
export const CONFIG_REQUEST = "CONFIG_REQUEST";
@ -64,7 +63,6 @@ export function configFailed(err) {
export function configDidLoad(config) {
return (dispatch) => {
MediaProxy.setConfig(config);
dispatch(configLoaded(config));
};
}

View File

@ -2,7 +2,7 @@ import uuid from 'uuid';
import { actions as notifActions } from 'redux-notifications';
import { BEGIN, COMMIT, REVERT } from 'redux-optimist';
import { currentBackend } from '../backends/backend';
import { getMedia } from '../reducers';
import { getAsset } from '../reducers';
import { status, EDITORIAL_WORKFLOW } from '../constants/publishModes';
const { notifSend } = notifActions;
@ -175,13 +175,13 @@ export function persistUnpublishedEntry(collection, entryDraft, existingUnpublis
return (dispatch, getState) => {
const state = getState();
const backend = currentBackend(state.config);
const mediaProxies = entryDraft.get('mediaFiles').map(path => getMedia(state, path));
const assetProxies = entryDraft.get('mediaFiles').map(path => getAsset(state, path));
const entry = entryDraft.get('entry');
const transactionID = uuid.v4();
dispatch(unpublishedEntryPersisting(collection, entry, transactionID));
const persistAction = existingUnpublishedEntry ? backend.persistUnpublishedEntry : backend.persistEntry;
persistAction.call(backend, state.config, collection, entryDraft, mediaProxies.toJS())
persistAction.call(backend, state.config, collection, entryDraft, assetProxies.toJS())
.then(() => {
dispatch(notifSend({
message: 'Entry saved',

View File

@ -2,7 +2,7 @@ import { List } from 'immutable';
import { actions as notifActions } from 'redux-notifications';
import { currentBackend } from '../backends/backend';
import { getIntegrationProvider } from '../integrations';
import { getMedia, selectIntegration } from '../reducers';
import { getAsset, selectIntegration } from '../reducers';
import { createEntry } from '../valueObjects/Entry';
const { notifSend } = notifActions;
@ -52,6 +52,17 @@ export function entryLoaded(collection, entry) {
};
}
export function entryLoadError(error, collection, slug) {
return {
type: ENTRY_FAILURE,
payload: {
error,
collection: collection.get('name'),
slug,
},
};
}
export function entriesLoading(collection) {
return {
type: ENTRIES_REQUEST,
@ -161,7 +172,15 @@ export function loadEntry(entry, collection, slug) {
return backend.getEntry(collection, slug)
.then(loadedEntry => (
dispatch(entryLoaded(collection, loadedEntry))
));
))
.catch((error) => {
dispatch(notifSend({
message: `Failed to load entry: ${ error.message }`,
kind: 'danger',
dismissAfter: 4000,
}));
dispatch(entryLoadError(error, collection, slug));
});
};
}
@ -171,8 +190,9 @@ export function loadEntries(collection, page = 0) {
return;
}
const state = getState();
const backend = currentBackend(state.config);
const integration = selectIntegration(state, collection.get('name'), 'listEntries');
const provider = integration ? getIntegrationProvider(state.integrations, integration) : currentBackend(state.config);
const provider = integration ? getIntegrationProvider(state.integrations, backend.getToken, integration) : backend;
dispatch(entriesLoading(collection));
provider.listEntries(collection, page).then(
response => dispatch(entriesLoaded(collection, response.entries, response.pagination)),
@ -196,11 +216,11 @@ export function persistEntry(collection, entryDraft) {
return (dispatch, getState) => {
const state = getState();
const backend = currentBackend(state.config);
const mediaProxies = entryDraft.get('mediaFiles').map(path => getMedia(state, path));
const assetProxies = entryDraft.get('mediaFiles').map(path => getAsset(state, path));
const entry = entryDraft.get('entry');
dispatch(entryPersisting(collection, entry));
backend
.persistEntry(state.config, collection, entryDraft, mediaProxies.toJS())
.persistEntry(state.config, collection, entryDraft, assetProxies.toJS())
.then(() => {
dispatch(notifSend({
message: 'Entry saved',

View File

@ -1,10 +1,10 @@
export const ADD_MEDIA = 'ADD_MEDIA';
export const REMOVE_MEDIA = 'REMOVE_MEDIA';
export const ADD_ASSET = 'ADD_ASSET';
export const REMOVE_ASSET = 'REMOVE_ASSET';
export function addMedia(mediaProxy) {
return { type: ADD_MEDIA, payload: mediaProxy };
export function addAsset(assetProxy) {
return { type: ADD_ASSET, payload: assetProxy };
}
export function removeMedia(path) {
return { type: REMOVE_MEDIA, payload: path };
export function removeAsset(path) {
return { type: REMOVE_ASSET, payload: path };
}

View File

@ -109,7 +109,7 @@ export function searchEntries(searchTerm, page = 0) {
dispatch(searchFailure(searchTerm, 'Search integration is not configured.'));
}
const provider = integration ?
getIntegrationProvider(state.integrations, integration)
getIntegrationProvider(state.integrations, currentBackend(state.config).getToken, integration)
: currentBackend(state.config);
dispatch(searchingEntries(searchTerm));
provider.search(collections, searchTerm, page).then(
@ -129,7 +129,7 @@ export function query(namespace, collection, searchFields, searchTerm) {
dispatch(searchFailure(namespace, searchTerm, 'Search integration is not configured.'));
}
const provider = integration ?
getIntegrationProvider(state.integrations, integration)
getIntegrationProvider(state.integrations, currentBackend(state.config).getToken, integration)
: currentBackend(state.config);
dispatch(querying(namespace, collection, searchFields, searchTerm));
provider.searchBy(searchFields, collection, searchTerm).then(