2018-06-11 19:03:43 -07:00
|
|
|
import { attempt, flatten, isError } from 'lodash';
|
|
|
|
import { fromJS, Map } from 'immutable';
|
|
|
|
import fuzzy from 'fuzzy';
|
WIP - Global UI (#785)
* update top bar and collections sidebar UI
* update collection entries UI
* improve global layout
* merge search page into collection page
* enable new entry button
* search fixup
* wip -initial editor update
* update editor scrolling and markdown toolbar position
* wip
* editor toolbar progress
* editor toolbar wip
* finished basic editor toolbar
* add standalone toggle component
* improve markdown toolbar spacing
* add user avatar placeholder
* finish markdown toggle styling
* refactor icon setup, add new icons
* add new icons to markdown editor toolbar
* remove extra app container
* add markdown active mark style
* relation and text widget styling
* widget design updates, basic list/object design update
* widget style updates, image widget improvements
* refactor widget directory, fix file removal
* widget focus styles
* finish editor widget focus styles
* migrate media library modal to react-modal
* wip - migrate editor component form to modal
* wip - move editor component form to modal
* wip - embed plugin forms in the editor
* inline shortcode forms working
* disable react hot loading, its breaking things
* improve shortcode form styles
* make shortcode form collapsible, improve styling
* add close functionality to shortcode blocks
* improve base media library styling
* fix shortcode label
* migrate unstyled workflow to new UI
* wip - reorganizing everything
* more work moving everything
* finish more moving and eliminating stuff
* restructure, remove react-toolbox
* wip - removing old stuff, more restructure
* finish restructure
* wip - css arch
* switch back to test repo
* update react-datetime to ^2.11.0
* remove leftover react-toolbox button
* more restructuring clean-up
* fix UI component directory case
* wip -css editor control style
* wip - consolidate widget styles
* wip - use a single control renderer
* fixed object values breaking
* wip - editor control active styles
* pass control wrapper to widgets
* ensure branch name is trimmed
* wip - improve widget authoring support
* import Map to Widget component
* refactor toolbar buttons
* wip - more widget active styles
* break out editor toggle component
* add local scroll sync back
* update editor toggle icons
* limit editor control pane content width
* fix editor control spacing
* migrate markdown toolbar stickiness to css
* fix markdown toolbar border radius
* temporarily use test backend
* stop markdown toolbar from going to bottom
* restore disabled markdown toolbar buttons for raw
* test markdown widget without focus styles
* more widget updates
* remove card visuals from editor
* disable dragging editor split off screen
* use editorControl component for shortcode fields
* make header site link configurable
* add configurable collection descriptions
* temporarily add example assets
* add basic list view
* remove outdated css mixins
* add and implement search icon
* activate quick add menu
* visualize usable space in editor view
* fix entry close, other improvements
* wip - editorial workflow updates
* some dropshadow and other CSS tweaks
* workflow ui updates
* add worfklow card buttons
* fix workflow card button handlers
* some dropshadow and other CSS tweaks
* make workflow board wider
* center workflow and collection views
* add basic responsiveness
* a bunch of fun UI fixes! a BUNCH! (#875)
* give `.nc-entryEditor-toolbar-mainSection` left and right child divs
* a bunch of fun UI fixes! a BUNCH!
* remove obscure --buttonShadow
* revert to test repo
* fix not found page styling
* allow workflow publishing from any column
* disallow publishing from all columns, with feedback
* fix new entry button
* fix markdown state persisting across entries
* enable simple workflow save and new from editor
* update slug in address bar when saving new entry
* wip - workflow updates, deletion working
* add status change functionality to editor
* wip - improving status change from editor
* editor toolbar back button improvements, loading improvements, cleanup
* progress on the media library UI cleanup
* remove font smothing css
* a quick fix for these buttons
* tweaks
* progress on media library modal— broken FYI
* fix media library functionality, finish migrating footer
* remove media library footer files
* remove leftover css import
* fix media library
* editor publishing functionality complete (unstyled)
* remove leftover loader var from media library
* wip - editor publishing styles
* add status dropdown styling
* editor toolbar style updates
* editor toolbar state improvements
* progress on the media library UI cleanup, style improvements
* finish editorial workflow editor styling
* finish media library styling
* fix config
* add what-input to optimize focus styling
* fix button
* fix navigation blocking for simple workflow
* improve simple workflow publishing
* add avatar dropdown to editor top bar
* style github and test-repo auth pages
* add git gateway auth page styles
* improve editor error styling
2017-12-07 12:37:10 -05:00
|
|
|
import { resolveFormat } from "Formats/formats";
|
|
|
|
import { selectIntegration } from 'Reducers/integrations';
|
|
|
|
import {
|
|
|
|
selectListMethod,
|
|
|
|
selectEntrySlug,
|
|
|
|
selectEntryPath,
|
|
|
|
selectAllowNewEntries,
|
|
|
|
selectAllowDeletion,
|
2018-05-25 10:15:01 -06:00
|
|
|
selectFolderEntryExtension,
|
|
|
|
selectIdentifier,
|
2018-06-11 19:03:43 -07:00
|
|
|
selectInferedField,
|
WIP - Global UI (#785)
* update top bar and collections sidebar UI
* update collection entries UI
* improve global layout
* merge search page into collection page
* enable new entry button
* search fixup
* wip -initial editor update
* update editor scrolling and markdown toolbar position
* wip
* editor toolbar progress
* editor toolbar wip
* finished basic editor toolbar
* add standalone toggle component
* improve markdown toolbar spacing
* add user avatar placeholder
* finish markdown toggle styling
* refactor icon setup, add new icons
* add new icons to markdown editor toolbar
* remove extra app container
* add markdown active mark style
* relation and text widget styling
* widget design updates, basic list/object design update
* widget style updates, image widget improvements
* refactor widget directory, fix file removal
* widget focus styles
* finish editor widget focus styles
* migrate media library modal to react-modal
* wip - migrate editor component form to modal
* wip - move editor component form to modal
* wip - embed plugin forms in the editor
* inline shortcode forms working
* disable react hot loading, its breaking things
* improve shortcode form styles
* make shortcode form collapsible, improve styling
* add close functionality to shortcode blocks
* improve base media library styling
* fix shortcode label
* migrate unstyled workflow to new UI
* wip - reorganizing everything
* more work moving everything
* finish more moving and eliminating stuff
* restructure, remove react-toolbox
* wip - removing old stuff, more restructure
* finish restructure
* wip - css arch
* switch back to test repo
* update react-datetime to ^2.11.0
* remove leftover react-toolbox button
* more restructuring clean-up
* fix UI component directory case
* wip -css editor control style
* wip - consolidate widget styles
* wip - use a single control renderer
* fixed object values breaking
* wip - editor control active styles
* pass control wrapper to widgets
* ensure branch name is trimmed
* wip - improve widget authoring support
* import Map to Widget component
* refactor toolbar buttons
* wip - more widget active styles
* break out editor toggle component
* add local scroll sync back
* update editor toggle icons
* limit editor control pane content width
* fix editor control spacing
* migrate markdown toolbar stickiness to css
* fix markdown toolbar border radius
* temporarily use test backend
* stop markdown toolbar from going to bottom
* restore disabled markdown toolbar buttons for raw
* test markdown widget without focus styles
* more widget updates
* remove card visuals from editor
* disable dragging editor split off screen
* use editorControl component for shortcode fields
* make header site link configurable
* add configurable collection descriptions
* temporarily add example assets
* add basic list view
* remove outdated css mixins
* add and implement search icon
* activate quick add menu
* visualize usable space in editor view
* fix entry close, other improvements
* wip - editorial workflow updates
* some dropshadow and other CSS tweaks
* workflow ui updates
* add worfklow card buttons
* fix workflow card button handlers
* some dropshadow and other CSS tweaks
* make workflow board wider
* center workflow and collection views
* add basic responsiveness
* a bunch of fun UI fixes! a BUNCH! (#875)
* give `.nc-entryEditor-toolbar-mainSection` left and right child divs
* a bunch of fun UI fixes! a BUNCH!
* remove obscure --buttonShadow
* revert to test repo
* fix not found page styling
* allow workflow publishing from any column
* disallow publishing from all columns, with feedback
* fix new entry button
* fix markdown state persisting across entries
* enable simple workflow save and new from editor
* update slug in address bar when saving new entry
* wip - workflow updates, deletion working
* add status change functionality to editor
* wip - improving status change from editor
* editor toolbar back button improvements, loading improvements, cleanup
* progress on the media library UI cleanup
* remove font smothing css
* a quick fix for these buttons
* tweaks
* progress on media library modal— broken FYI
* fix media library functionality, finish migrating footer
* remove media library footer files
* remove leftover css import
* fix media library
* editor publishing functionality complete (unstyled)
* remove leftover loader var from media library
* wip - editor publishing styles
* add status dropdown styling
* editor toolbar style updates
* editor toolbar state improvements
* progress on the media library UI cleanup, style improvements
* finish editorial workflow editor styling
* finish media library styling
* fix config
* add what-input to optimize focus styling
* fix button
* fix navigation blocking for simple workflow
* improve simple workflow publishing
* add avatar dropdown to editor top bar
* style github and test-repo auth pages
* add git gateway auth page styles
* improve editor error styling
2017-12-07 12:37:10 -05:00
|
|
|
} from "Reducers/collections";
|
|
|
|
import { createEntry } from "ValueObjects/Entry";
|
|
|
|
import { sanitizeSlug } from "Lib/urlHelper";
|
2018-07-19 18:11:23 -07:00
|
|
|
import BitBucketBackend from "./bitbucket/implementation";
|
2018-01-25 08:55:13 -08:00
|
|
|
import { registerBackend, getBackend } from 'Lib/registry';
|
2018-07-17 19:13:52 -04:00
|
|
|
import { Cursor, CURSOR_COMPATIBILITY_SYMBOL } from 'netlify-cms-lib-util';
|
2018-07-17 18:09:59 -04:00
|
|
|
import { EDITORIAL_WORKFLOW, status } from 'Constants/publishModes';
|
2018-01-25 08:55:13 -08:00
|
|
|
|
2016-05-30 16:55:32 -07:00
|
|
|
class LocalStorageAuthStore {
|
2016-12-23 17:30:27 -02:00
|
|
|
storageKey = "netlify-cms-user";
|
2016-05-30 16:55:32 -07:00
|
|
|
|
|
|
|
retrieve() {
|
|
|
|
const data = window.localStorage.getItem(this.storageKey);
|
|
|
|
return data && JSON.parse(data);
|
2016-02-25 12:31:21 -08:00
|
|
|
}
|
|
|
|
|
2016-05-30 16:55:32 -07:00
|
|
|
store(userData) {
|
|
|
|
window.localStorage.setItem(this.storageKey, JSON.stringify(userData));
|
2016-02-25 12:31:21 -08:00
|
|
|
}
|
2016-11-01 14:35:20 +01:00
|
|
|
|
|
|
|
logout() {
|
|
|
|
window.localStorage.removeItem(this.storageKey);
|
|
|
|
}
|
2016-02-25 12:31:21 -08:00
|
|
|
}
|
|
|
|
|
2018-05-25 10:15:01 -06:00
|
|
|
const slugFormatter = (collection, entryData, slugConfig) => {
|
|
|
|
const template = collection.get('slug') || "{{slug}}";
|
2018-05-24 09:23:55 -04:00
|
|
|
const date = new Date();
|
2017-06-22 14:05:22 +01:00
|
|
|
|
2018-05-25 10:15:01 -06:00
|
|
|
const identifier = entryData.get(selectIdentifier(collection));
|
|
|
|
if (!identifier) {
|
|
|
|
throw new Error("Collection must have a field name that is a valid entry identifier");
|
|
|
|
}
|
2017-09-05 19:30:03 -07:00
|
|
|
|
2017-10-03 09:01:06 -06:00
|
|
|
const slug = template.replace(/\{\{([^\}]+)\}\}/g, (_, field) => {
|
2016-10-28 11:42:31 -02:00
|
|
|
switch (field) {
|
2016-12-23 16:59:48 -02:00
|
|
|
case "year":
|
2016-10-10 15:34:21 -03:00
|
|
|
return date.getFullYear();
|
2016-12-23 16:59:48 -02:00
|
|
|
case "month":
|
2016-10-21 20:42:14 -02:00
|
|
|
return (`0${ date.getMonth() + 1 }`).slice(-2);
|
2016-12-23 16:59:48 -02:00
|
|
|
case "day":
|
2016-10-21 20:42:14 -02:00
|
|
|
return (`0${ date.getDate() }`).slice(-2);
|
2018-04-05 23:16:18 +09:00
|
|
|
case "hour":
|
|
|
|
return (`0${ date.getHours() }`).slice(-2);
|
|
|
|
case "minute":
|
|
|
|
return (`0${ date.getMinutes() }`).slice(-2);
|
|
|
|
case "second":
|
|
|
|
return (`0${ date.getSeconds() }`).slice(-2);
|
2016-12-23 16:59:48 -02:00
|
|
|
case "slug":
|
2018-05-25 10:15:01 -06:00
|
|
|
return identifier.trim();
|
2016-10-10 15:34:21 -03:00
|
|
|
default:
|
2017-09-30 17:25:05 -06:00
|
|
|
return entryData.get(field, "").trim();
|
2016-10-10 15:34:21 -03:00
|
|
|
}
|
2017-10-03 09:01:06 -06:00
|
|
|
})
|
|
|
|
// Convert slug to lower-case
|
|
|
|
.toLocaleLowerCase()
|
2017-09-30 17:27:07 -06:00
|
|
|
|
2018-03-27 16:56:10 -06:00
|
|
|
// Replace periods with dashes.
|
|
|
|
.replace(/[.]/g, '-');
|
2017-09-30 17:27:07 -06:00
|
|
|
|
2018-03-27 16:56:10 -06:00
|
|
|
return sanitizeSlug(slug, slugConfig);
|
2016-10-10 15:34:21 -03:00
|
|
|
};
|
|
|
|
|
2018-05-23 22:57:56 +02:00
|
|
|
const commitMessageTemplates = Map({
|
|
|
|
create: 'Create {{collection}} “{{slug}}”',
|
|
|
|
update: 'Update {{collection}} “{{slug}}”',
|
|
|
|
delete: 'Delete {{collection}} “{{slug}}”',
|
|
|
|
uploadMedia: 'Upload “{{path}}”',
|
|
|
|
deleteMedia: 'Delete “{{path}}”'
|
|
|
|
});
|
|
|
|
|
|
|
|
const commitMessageFormatter = (type, config, { slug, path, collection }) => {
|
|
|
|
const templates = commitMessageTemplates.merge(config.getIn(['backend', 'commit_messages'], Map()));
|
|
|
|
const messageTemplate = templates.get(type);
|
|
|
|
return messageTemplate.replace(/\{\{([^\}]+)\}\}/g, (_, variable) => {
|
|
|
|
switch (variable) {
|
|
|
|
case 'slug':
|
|
|
|
return slug;
|
|
|
|
case 'path':
|
|
|
|
return path;
|
|
|
|
case 'collection':
|
|
|
|
return collection.get('label');
|
|
|
|
default:
|
|
|
|
console.warn(`Ignoring unknown variable “${ variable }” in commit message template.`);
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-06-11 19:03:43 -07:00
|
|
|
const extractSearchFields = searchFields => entry => searchFields.reduce((acc, field) => {
|
|
|
|
const f = entry.data[field];
|
|
|
|
return f ? `${acc} ${f}` : acc;
|
|
|
|
}, "");
|
|
|
|
|
|
|
|
const sortByScore = (a, b) => {
|
|
|
|
if (a.score > b.score) return -1;
|
|
|
|
if (a.score < b.score) return 1;
|
|
|
|
return 0;
|
|
|
|
};
|
|
|
|
|
2016-02-25 12:31:21 -08:00
|
|
|
class Backend {
|
2018-07-23 12:14:53 -04:00
|
|
|
constructor(implementation, { backendName, authStore = null, config } = {}) {
|
|
|
|
this.implementation = implementation.init(config, {
|
|
|
|
useWorkflow: config.getIn(["publish_mode"]) === EDITORIAL_WORKFLOW,
|
|
|
|
updateUserCredentials: this.updateUserCredentials,
|
|
|
|
});
|
2017-08-29 13:08:15 -06:00
|
|
|
this.backendName = backendName;
|
2016-02-25 12:31:21 -08:00
|
|
|
this.authStore = authStore;
|
2016-09-05 12:12:38 -03:00
|
|
|
if (this.implementation === null) {
|
2016-12-23 16:59:48 -02:00
|
|
|
throw new Error("Cannot instantiate a Backend with no implementation");
|
2016-02-25 12:31:21 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
currentUser() {
|
|
|
|
if (this.user) { return this.user; }
|
2016-06-05 01:52:18 -07:00
|
|
|
const stored = this.authStore && this.authStore.retrieve();
|
2017-08-29 13:08:15 -06:00
|
|
|
if (stored && stored.backendName === this.backendName) {
|
2017-08-29 13:45:05 -06:00
|
|
|
return Promise.resolve(this.implementation.restoreUser(stored)).then((user) => {
|
2017-08-29 13:08:15 -06:00
|
|
|
const newUser = {...user, backendName: this.backendName};
|
|
|
|
// return confirmed/rehydrated user object instead of stored
|
|
|
|
this.authStore.store(newUser);
|
|
|
|
return newUser;
|
2017-08-27 20:12:54 -06:00
|
|
|
});
|
2016-06-05 01:52:18 -07:00
|
|
|
}
|
2016-12-23 16:59:48 -02:00
|
|
|
return Promise.resolve(null);
|
2016-02-25 12:31:21 -08:00
|
|
|
}
|
|
|
|
|
2018-07-19 18:11:23 -07:00
|
|
|
updateUserCredentials = updatedCredentials => {
|
|
|
|
const storedUser = this.authStore && this.authStore.retrieve();
|
|
|
|
if (storedUser && storedUser.backendName === this.backendName) {
|
|
|
|
const newUser = { ...storedUser, ...updatedCredentials };
|
|
|
|
this.authStore.store(newUser);
|
|
|
|
return newUser;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-02-25 12:31:21 -08:00
|
|
|
authComponent() {
|
|
|
|
return this.implementation.authComponent();
|
|
|
|
}
|
|
|
|
|
2016-02-25 20:40:35 -08:00
|
|
|
authenticate(credentials) {
|
2016-05-30 16:55:32 -07:00
|
|
|
return this.implementation.authenticate(credentials).then((user) => {
|
2017-08-29 13:08:15 -06:00
|
|
|
const newUser = {...user, backendName: this.backendName};
|
|
|
|
if (this.authStore) { this.authStore.store(newUser); }
|
|
|
|
return newUser;
|
2016-05-30 16:55:32 -07:00
|
|
|
});
|
2016-02-25 20:40:35 -08:00
|
|
|
}
|
|
|
|
|
2016-11-01 14:35:20 +01:00
|
|
|
logout() {
|
2017-09-05 19:30:03 -07:00
|
|
|
return Promise.resolve(this.implementation.logout()).then(() => {
|
|
|
|
if (this.authStore) {
|
|
|
|
this.authStore.logout();
|
|
|
|
}
|
|
|
|
});
|
2016-11-01 14:35:20 +01:00
|
|
|
}
|
|
|
|
|
2017-01-10 22:23:22 -02:00
|
|
|
getToken = () => this.implementation.getToken();
|
|
|
|
|
2018-06-11 19:03:43 -07:00
|
|
|
processEntries(loadedEntries, collection) {
|
|
|
|
const collectionFilter = collection.get('filter');
|
|
|
|
const entries = loadedEntries.map(loadedEntry => createEntry(
|
|
|
|
collection.get("name"),
|
|
|
|
selectEntrySlug(collection, loadedEntry.file.path),
|
|
|
|
loadedEntry.file.path,
|
|
|
|
{ raw: loadedEntry.data || '', label: loadedEntry.file.label }
|
|
|
|
));
|
|
|
|
const formattedEntries = entries.map(this.entryWithFormat(collection));
|
|
|
|
// If this collection has a "filter" property, filter entries accordingly
|
|
|
|
const filteredEntries = collectionFilter
|
|
|
|
? this.filterEntries({ entries: formattedEntries }, collectionFilter)
|
|
|
|
: formattedEntries;
|
|
|
|
return filteredEntries;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-10-21 20:42:14 -02:00
|
|
|
listEntries(collection) {
|
2016-11-11 17:54:58 -02:00
|
|
|
const listMethod = this.implementation[selectListMethod(collection)];
|
2017-04-14 19:19:45 +01:00
|
|
|
const extension = selectFolderEntryExtension(collection);
|
|
|
|
return listMethod.call(this.implementation, collection, extension)
|
2018-06-11 19:03:43 -07:00
|
|
|
.then(loadedEntries => ({
|
|
|
|
entries: this.processEntries(loadedEntries, collection),
|
|
|
|
/*
|
|
|
|
Wrap cursors so we can tell which collection the cursor is
|
|
|
|
from. This is done to prevent traverseCursor from requiring a
|
|
|
|
`collection` argument.
|
|
|
|
*/
|
|
|
|
cursor: Cursor.create(loadedEntries[CURSOR_COMPATIBILITY_SYMBOL]).wrapData({
|
|
|
|
cursorType: "collectionEntries",
|
|
|
|
collection,
|
|
|
|
}),
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
// The same as listEntries, except that if a cursor with the "next"
|
|
|
|
// action available is returned, it calls "next" on the cursor and
|
|
|
|
// repeats the process. Once there is no available "next" action, it
|
|
|
|
// returns all the collected entries. Used to retrieve all entries
|
|
|
|
// for local searches and queries.
|
|
|
|
async listAllEntries(collection) {
|
|
|
|
if (collection.get("folder") && this.implementation.allEntriesByFolder) {
|
|
|
|
const extension = selectFolderEntryExtension(collection);
|
|
|
|
return this.implementation.allEntriesByFolder(collection, extension)
|
|
|
|
.then(entries => this.processEntries(entries, collection));
|
|
|
|
}
|
|
|
|
|
|
|
|
const response = await this.listEntries(collection);
|
|
|
|
const { entries } = response;
|
|
|
|
let { cursor } = response;
|
|
|
|
while (cursor && cursor.actions.includes("next")) {
|
|
|
|
const { entries: newEntries, cursor: newCursor } = await this.traverseCursor(cursor, "next");
|
|
|
|
entries.push(...newEntries);
|
|
|
|
cursor = newCursor;
|
|
|
|
}
|
|
|
|
return entries;
|
|
|
|
}
|
|
|
|
|
|
|
|
async search(collections, searchTerm) {
|
|
|
|
// Perform a local search by requesting all entries. For each
|
|
|
|
// collection, load it, search, and call onCollectionResults with
|
|
|
|
// its results.
|
|
|
|
const errors = [];
|
|
|
|
const collectionEntriesRequests = collections.map(async collection => {
|
|
|
|
// TODO: pass search fields in as an argument
|
|
|
|
const searchFields = [
|
|
|
|
selectInferedField(collection, 'title'),
|
|
|
|
selectInferedField(collection, 'shortTitle'),
|
|
|
|
selectInferedField(collection, 'author'),
|
|
|
|
];
|
|
|
|
const collectionEntries = await this.listAllEntries(collection);
|
|
|
|
return fuzzy.filter(searchTerm, collectionEntries, {
|
|
|
|
extract: extractSearchFields(searchFields),
|
|
|
|
});
|
|
|
|
}).map(p => p.catch(err => errors.push(err) && []));
|
|
|
|
|
|
|
|
const entries = await Promise.all(collectionEntriesRequests).then(arrs => flatten(arrs));
|
|
|
|
|
|
|
|
if (errors.length > 0) {
|
|
|
|
throw new Error({ message: "Errors ocurred while searching entries locally!", errors });
|
|
|
|
}
|
|
|
|
const hits = entries.filter(({ score }) => score > 5).sort(sortByScore).map(f => f.original);
|
|
|
|
return { entries: hits };
|
|
|
|
}
|
|
|
|
|
|
|
|
async query(collection, searchFields, searchTerm) {
|
|
|
|
const entries = await this.listAllEntries(collection);
|
|
|
|
const hits = fuzzy.filter(searchTerm, entries, { extract: extractSearchFields(searchFields) })
|
|
|
|
.filter(entry => entry.score > 5)
|
|
|
|
.sort(sortByScore)
|
|
|
|
.map(f => f.original);
|
|
|
|
return { query: searchTerm, hits };
|
|
|
|
}
|
|
|
|
|
|
|
|
traverseCursor(cursor, action) {
|
|
|
|
const [data, unwrappedCursor] = cursor.unwrapData();
|
|
|
|
// TODO: stop assuming all cursors are for collections
|
|
|
|
const collection = data.get("collection");
|
|
|
|
return this.implementation.traverseCursor(unwrappedCursor, action)
|
|
|
|
.then(async ({ entries, cursor: newCursor }) => ({
|
|
|
|
entries: this.processEntries(entries, collection),
|
|
|
|
cursor: Cursor.create(newCursor).wrapData({
|
|
|
|
cursorType: "collectionEntries",
|
|
|
|
collection,
|
|
|
|
}),
|
|
|
|
}));
|
2016-02-25 20:40:35 -08:00
|
|
|
}
|
|
|
|
|
2016-10-27 13:12:18 -02:00
|
|
|
getEntry(collection, slug) {
|
2016-11-11 17:54:58 -02:00
|
|
|
return this.implementation.getEntry(collection, slug, selectEntryPath(collection, slug))
|
2016-10-27 15:33:15 +02:00
|
|
|
.then(loadedEntry => this.entryWithFormat(collection, slug)(createEntry(
|
2016-12-23 16:59:48 -02:00
|
|
|
collection.get("name"),
|
2016-10-27 14:23:36 +02:00
|
|
|
slug,
|
|
|
|
loadedEntry.file.path,
|
|
|
|
{ raw: loadedEntry.data, label: loadedEntry.file.label }
|
2016-10-27 14:45:32 +02:00
|
|
|
))
|
2016-10-27 14:23:36 +02:00
|
|
|
);
|
2016-06-05 01:52:18 -07:00
|
|
|
}
|
|
|
|
|
2017-08-14 09:00:47 -04:00
|
|
|
getMedia() {
|
|
|
|
return this.implementation.getMedia();
|
|
|
|
}
|
|
|
|
|
2016-09-06 13:04:17 -03:00
|
|
|
entryWithFormat(collectionOrEntity) {
|
2016-06-05 01:52:18 -07:00
|
|
|
return (entry) => {
|
2016-09-06 13:04:17 -03:00
|
|
|
const format = resolveFormat(collectionOrEntity, entry);
|
2017-05-31 16:12:31 -04:00
|
|
|
if (entry && entry.raw !== undefined) {
|
2018-01-29 15:35:36 -07:00
|
|
|
const data = (format && attempt(format.fromFile.bind(format, entry.raw))) || {};
|
2017-06-07 12:47:57 -04:00
|
|
|
if (isError(data)) console.error(data);
|
2017-05-31 16:12:31 -04:00
|
|
|
return Object.assign(entry, { data: isError(data) ? {} : data });
|
2016-06-05 01:52:18 -07:00
|
|
|
}
|
2016-10-27 14:45:32 +02:00
|
|
|
return format.fromFile(entry);
|
2016-06-05 01:52:18 -07:00
|
|
|
};
|
2016-02-25 12:31:21 -08:00
|
|
|
}
|
2016-06-06 21:53:22 -03:00
|
|
|
|
2017-11-09 13:14:45 -07:00
|
|
|
unpublishedEntries(collections) {
|
|
|
|
return this.implementation.unpublishedEntries()
|
2016-10-28 11:42:31 -02:00
|
|
|
.then(loadedEntries => loadedEntries.filter(entry => entry !== null))
|
|
|
|
.then(entries => (
|
|
|
|
entries.map((loadedEntry) => {
|
2017-03-15 18:47:18 -07:00
|
|
|
const entry = createEntry(
|
|
|
|
loadedEntry.metaData.collection,
|
|
|
|
loadedEntry.slug,
|
|
|
|
loadedEntry.file.path,
|
|
|
|
{
|
|
|
|
raw: loadedEntry.data,
|
|
|
|
isModification: loadedEntry.isModification,
|
|
|
|
}
|
|
|
|
);
|
2016-10-27 15:27:39 -02:00
|
|
|
entry.metaData = loadedEntry.metaData;
|
|
|
|
return entry;
|
|
|
|
})
|
|
|
|
))
|
2016-10-28 11:42:31 -02:00
|
|
|
.then(entries => ({
|
|
|
|
pagination: 0,
|
2018-03-03 22:30:10 -05:00
|
|
|
entries: entries.reduce((acc, entry) => {
|
2017-11-09 13:14:45 -07:00
|
|
|
const collection = collections.get(entry.collection);
|
2018-03-03 22:30:10 -05:00
|
|
|
if (collection) {
|
|
|
|
acc.push(this.entryWithFormat(collection)(entry));
|
|
|
|
}
|
|
|
|
return acc;
|
|
|
|
}, []),
|
2016-10-28 11:42:31 -02:00
|
|
|
}));
|
2016-09-06 13:04:17 -03:00
|
|
|
}
|
|
|
|
|
2016-09-13 03:59:48 -03:00
|
|
|
unpublishedEntry(collection, slug) {
|
2016-10-27 15:27:39 -02:00
|
|
|
return this.implementation.unpublishedEntry(collection, slug)
|
2016-10-28 11:42:31 -02:00
|
|
|
.then((loadedEntry) => {
|
2017-03-15 18:47:18 -07:00
|
|
|
const entry = createEntry(
|
|
|
|
"draft",
|
|
|
|
loadedEntry.slug,
|
|
|
|
loadedEntry.file.path,
|
|
|
|
{
|
|
|
|
raw: loadedEntry.data,
|
|
|
|
isModification: loadedEntry.isModification,
|
|
|
|
});
|
2016-10-28 11:42:31 -02:00
|
|
|
entry.metaData = loadedEntry.metaData;
|
|
|
|
return entry;
|
|
|
|
})
|
|
|
|
.then(this.entryWithFormat(collection, slug));
|
2016-09-13 03:59:48 -03:00
|
|
|
}
|
|
|
|
|
2018-05-24 09:23:55 -04:00
|
|
|
persistEntry(config, collection, entryDraft, MediaFiles, integrations, options = {}) {
|
2016-12-23 16:59:48 -02:00
|
|
|
const newEntry = entryDraft.getIn(["entry", "newRecord"]) || false;
|
2016-09-05 12:12:38 -03:00
|
|
|
|
|
|
|
const parsedData = {
|
2016-12-23 16:59:48 -02:00
|
|
|
title: entryDraft.getIn(["entry", "data", "title"], "No Title"),
|
|
|
|
description: entryDraft.getIn(["entry", "data", "description"], "No Description!"),
|
2016-09-05 12:12:38 -03:00
|
|
|
};
|
|
|
|
|
2016-12-23 16:59:48 -02:00
|
|
|
const entryData = entryDraft.getIn(["entry", "data"]).toJS();
|
2016-08-25 16:11:00 -03:00
|
|
|
let entryObj;
|
|
|
|
if (newEntry) {
|
2016-11-11 17:54:58 -02:00
|
|
|
if (!selectAllowNewEntries(collection)) {
|
2016-12-23 16:59:48 -02:00
|
|
|
throw (new Error("Not allowed to create new entries in this collection"));
|
2016-10-27 14:23:36 +02:00
|
|
|
}
|
2018-05-25 10:15:01 -06:00
|
|
|
const slug = slugFormatter(collection, entryDraft.getIn(["entry", "data"]), config.get("slug"));
|
2016-11-11 17:54:58 -02:00
|
|
|
const path = selectEntryPath(collection, slug);
|
2016-08-25 16:11:00 -03:00
|
|
|
entryObj = {
|
2016-10-28 04:51:37 +02:00
|
|
|
path,
|
2016-10-21 20:42:14 -02:00
|
|
|
slug,
|
2018-05-24 09:23:55 -04:00
|
|
|
raw: this.entryToRaw(collection, entryDraft.get("entry")),
|
2016-08-25 16:11:00 -03:00
|
|
|
};
|
|
|
|
} else {
|
2016-12-23 16:59:48 -02:00
|
|
|
const path = entryDraft.getIn(["entry", "path"]);
|
2017-02-21 23:04:12 -08:00
|
|
|
const slug = entryDraft.getIn(["entry", "slug"]);
|
2016-08-25 16:11:00 -03:00
|
|
|
entryObj = {
|
2016-10-28 04:51:37 +02:00
|
|
|
path,
|
2017-02-21 23:04:12 -08:00
|
|
|
slug,
|
|
|
|
raw: this.entryToRaw(collection, entryDraft.get("entry")),
|
2016-08-25 16:11:00 -03:00
|
|
|
};
|
|
|
|
}
|
2016-07-19 17:11:22 -03:00
|
|
|
|
2018-05-23 22:57:56 +02:00
|
|
|
const commitMessage = commitMessageFormatter(newEntry ? 'create' : 'update', config, { collection, slug: entryObj.slug, path: entryObj.path });
|
2016-07-19 17:11:22 -03:00
|
|
|
|
2016-12-23 16:59:48 -02:00
|
|
|
const collectionName = collection.get("name");
|
2016-08-30 19:06:20 -03:00
|
|
|
|
2017-11-11 09:48:47 -05:00
|
|
|
/**
|
|
|
|
* Determine whether an asset store integration is in use.
|
|
|
|
*/
|
2017-11-11 21:28:56 -05:00
|
|
|
const hasAssetStore = integrations && !!selectIntegration(integrations, null, 'assetStore');
|
2017-11-11 09:48:47 -05:00
|
|
|
const updatedOptions = { ...options, hasAssetStore };
|
2018-07-17 18:09:59 -04:00
|
|
|
const opts = {
|
|
|
|
newEntry,
|
|
|
|
parsedData,
|
|
|
|
commitMessage,
|
|
|
|
collectionName,
|
|
|
|
initialStatus: status.first(),
|
|
|
|
...updatedOptions
|
|
|
|
};
|
2017-11-11 09:48:47 -05:00
|
|
|
|
WIP - Global UI (#785)
* update top bar and collections sidebar UI
* update collection entries UI
* improve global layout
* merge search page into collection page
* enable new entry button
* search fixup
* wip -initial editor update
* update editor scrolling and markdown toolbar position
* wip
* editor toolbar progress
* editor toolbar wip
* finished basic editor toolbar
* add standalone toggle component
* improve markdown toolbar spacing
* add user avatar placeholder
* finish markdown toggle styling
* refactor icon setup, add new icons
* add new icons to markdown editor toolbar
* remove extra app container
* add markdown active mark style
* relation and text widget styling
* widget design updates, basic list/object design update
* widget style updates, image widget improvements
* refactor widget directory, fix file removal
* widget focus styles
* finish editor widget focus styles
* migrate media library modal to react-modal
* wip - migrate editor component form to modal
* wip - move editor component form to modal
* wip - embed plugin forms in the editor
* inline shortcode forms working
* disable react hot loading, its breaking things
* improve shortcode form styles
* make shortcode form collapsible, improve styling
* add close functionality to shortcode blocks
* improve base media library styling
* fix shortcode label
* migrate unstyled workflow to new UI
* wip - reorganizing everything
* more work moving everything
* finish more moving and eliminating stuff
* restructure, remove react-toolbox
* wip - removing old stuff, more restructure
* finish restructure
* wip - css arch
* switch back to test repo
* update react-datetime to ^2.11.0
* remove leftover react-toolbox button
* more restructuring clean-up
* fix UI component directory case
* wip -css editor control style
* wip - consolidate widget styles
* wip - use a single control renderer
* fixed object values breaking
* wip - editor control active styles
* pass control wrapper to widgets
* ensure branch name is trimmed
* wip - improve widget authoring support
* import Map to Widget component
* refactor toolbar buttons
* wip - more widget active styles
* break out editor toggle component
* add local scroll sync back
* update editor toggle icons
* limit editor control pane content width
* fix editor control spacing
* migrate markdown toolbar stickiness to css
* fix markdown toolbar border radius
* temporarily use test backend
* stop markdown toolbar from going to bottom
* restore disabled markdown toolbar buttons for raw
* test markdown widget without focus styles
* more widget updates
* remove card visuals from editor
* disable dragging editor split off screen
* use editorControl component for shortcode fields
* make header site link configurable
* add configurable collection descriptions
* temporarily add example assets
* add basic list view
* remove outdated css mixins
* add and implement search icon
* activate quick add menu
* visualize usable space in editor view
* fix entry close, other improvements
* wip - editorial workflow updates
* some dropshadow and other CSS tweaks
* workflow ui updates
* add worfklow card buttons
* fix workflow card button handlers
* some dropshadow and other CSS tweaks
* make workflow board wider
* center workflow and collection views
* add basic responsiveness
* a bunch of fun UI fixes! a BUNCH! (#875)
* give `.nc-entryEditor-toolbar-mainSection` left and right child divs
* a bunch of fun UI fixes! a BUNCH!
* remove obscure --buttonShadow
* revert to test repo
* fix not found page styling
* allow workflow publishing from any column
* disallow publishing from all columns, with feedback
* fix new entry button
* fix markdown state persisting across entries
* enable simple workflow save and new from editor
* update slug in address bar when saving new entry
* wip - workflow updates, deletion working
* add status change functionality to editor
* wip - improving status change from editor
* editor toolbar back button improvements, loading improvements, cleanup
* progress on the media library UI cleanup
* remove font smothing css
* a quick fix for these buttons
* tweaks
* progress on media library modal— broken FYI
* fix media library functionality, finish migrating footer
* remove media library footer files
* remove leftover css import
* fix media library
* editor publishing functionality complete (unstyled)
* remove leftover loader var from media library
* wip - editor publishing styles
* add status dropdown styling
* editor toolbar style updates
* editor toolbar state improvements
* progress on the media library UI cleanup, style improvements
* finish editorial workflow editor styling
* finish media library styling
* fix config
* add what-input to optimize focus styling
* fix button
* fix navigation blocking for simple workflow
* improve simple workflow publishing
* add avatar dropdown to editor top bar
* style github and test-repo auth pages
* add git gateway auth page styles
* improve editor error styling
2017-12-07 12:37:10 -05:00
|
|
|
return this.implementation.persistEntry(entryObj, MediaFiles, opts)
|
|
|
|
.then(() => entryObj.slug);
|
2016-06-06 21:53:22 -03:00
|
|
|
}
|
|
|
|
|
2018-05-23 22:57:56 +02:00
|
|
|
persistMedia(config, file) {
|
2017-08-14 09:00:47 -04:00
|
|
|
const options = {
|
2018-05-23 22:57:56 +02:00
|
|
|
commitMessage: commitMessageFormatter('uploadMedia', config, { path: file.path }),
|
2017-08-14 09:00:47 -04:00
|
|
|
};
|
|
|
|
return this.implementation.persistMedia(file, options);
|
|
|
|
}
|
|
|
|
|
2017-07-21 23:40:33 -07:00
|
|
|
deleteEntry(config, collection, slug) {
|
|
|
|
const path = selectEntryPath(collection, slug);
|
2017-10-30 20:07:54 +00:00
|
|
|
|
|
|
|
if (!selectAllowDeletion(collection)) {
|
|
|
|
throw (new Error("Not allowed to delete entries in this collection"));
|
|
|
|
}
|
|
|
|
|
2018-05-23 22:57:56 +02:00
|
|
|
const commitMessage = commitMessageFormatter('delete', config, { collection, slug, path });
|
2017-07-21 23:40:33 -07:00
|
|
|
return this.implementation.deleteFile(path, commitMessage);
|
|
|
|
}
|
|
|
|
|
2018-05-23 22:57:56 +02:00
|
|
|
deleteMedia(config, path) {
|
|
|
|
const commitMessage = commitMessageFormatter('deleteMedia', config, { path });
|
2017-08-14 09:00:47 -04:00
|
|
|
return this.implementation.deleteFile(path, commitMessage);
|
|
|
|
}
|
|
|
|
|
2017-11-11 09:48:47 -05:00
|
|
|
persistUnpublishedEntry(...args) {
|
|
|
|
return this.persistEntry(...args, { unpublished: true });
|
2016-09-13 16:00:24 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
updateUnpublishedEntryStatus(collection, slug, newStatus) {
|
|
|
|
return this.implementation.updateUnpublishedEntryStatus(collection, slug, newStatus);
|
2016-09-13 14:31:18 -03:00
|
|
|
}
|
|
|
|
|
2017-01-11 20:58:15 -02:00
|
|
|
publishUnpublishedEntry(collection, slug) {
|
|
|
|
return this.implementation.publishUnpublishedEntry(collection, slug);
|
2016-09-14 18:25:45 -03:00
|
|
|
}
|
|
|
|
|
2017-03-11 13:47:36 -05:00
|
|
|
deleteUnpublishedEntry(collection, slug) {
|
|
|
|
return this.implementation.deleteUnpublishedEntry(collection, slug);
|
|
|
|
}
|
2016-09-13 14:31:18 -03:00
|
|
|
|
2016-06-06 21:53:22 -03:00
|
|
|
entryToRaw(collection, entry) {
|
2017-02-21 23:04:12 -08:00
|
|
|
const format = resolveFormat(collection, entry.toJS());
|
|
|
|
const fieldsOrder = this.fieldsOrder(collection, entry);
|
|
|
|
return format && format.toFile(entry.get("data").toJS(), fieldsOrder);
|
|
|
|
}
|
|
|
|
|
|
|
|
fieldsOrder(collection, entry) {
|
|
|
|
const fields = collection.get('fields');
|
|
|
|
if (fields) {
|
|
|
|
return collection.get('fields').map(f => f.get('name')).toArray();
|
|
|
|
}
|
|
|
|
|
|
|
|
const files = collection.get('files');
|
|
|
|
const file = (files || []).filter(f => f.get("name") === entry.get("slug")).get(0);
|
|
|
|
if (file == null) {
|
|
|
|
throw new Error(`No file found for ${ entry.get("slug") } in ${ collection.get('name') }`);
|
|
|
|
}
|
2017-02-21 23:59:34 -08:00
|
|
|
return file.get('fields').map(f => f.get('name')).toArray();
|
2016-06-06 21:53:22 -03:00
|
|
|
}
|
2017-05-25 17:24:48 +01:00
|
|
|
|
|
|
|
filterEntries(collection, filterRule) {
|
|
|
|
return collection.entries.filter(entry => (
|
|
|
|
entry.data[filterRule.get('field')] === filterRule.get('value')
|
|
|
|
));
|
|
|
|
}
|
2016-02-25 12:31:21 -08:00
|
|
|
}
|
|
|
|
|
2016-05-30 16:55:32 -07:00
|
|
|
export function resolveBackend(config) {
|
2016-12-23 16:59:48 -02:00
|
|
|
const name = config.getIn(["backend", "name"]);
|
2016-05-30 16:55:32 -07:00
|
|
|
if (name == null) {
|
2016-12-23 16:59:48 -02:00
|
|
|
throw new Error("No backend defined in configuration");
|
2016-05-30 16:55:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
const authStore = new LocalStorageAuthStore();
|
|
|
|
|
2018-01-25 08:55:13 -08:00
|
|
|
if (!getBackend(name)) {
|
|
|
|
throw new Error(`Backend not found: ${ name }`);
|
|
|
|
} else {
|
2018-07-19 18:11:23 -07:00
|
|
|
return new Backend(getBackend(name), { backendName: name, authStore, config });
|
2016-05-30 16:55:32 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-21 20:42:14 -02:00
|
|
|
export const currentBackend = (function () {
|
2016-02-25 12:31:21 -08:00
|
|
|
let backend = null;
|
|
|
|
|
|
|
|
return (config) => {
|
|
|
|
if (backend) { return backend; }
|
2016-12-23 16:59:48 -02:00
|
|
|
if (config.get("backend")) {
|
2016-02-25 12:31:21 -08:00
|
|
|
return backend = resolveBackend(config);
|
|
|
|
}
|
|
|
|
};
|
2016-10-21 20:42:14 -02:00
|
|
|
}());
|