Browse Source

Update storageManager configs

pull/4223/head
Artur Arseniev 5 years ago
parent
commit
0796ea73d4
  1. 24
      src/canvas/model/Frame.js
  2. 71
      src/storage_manager/config/config.js

24
src/canvas/model/Frame.js

@ -26,7 +26,7 @@ export default class Frame extends Model {
component: '', component: '',
styles: '', styles: '',
_undo: true, _undo: true,
_undoexc: ['changesCount'] _undoexc: ['changesCount'],
}; };
} }
@ -125,12 +125,7 @@ export default class Frame extends Model {
getHeadByAttr(attr, value, tag) { getHeadByAttr(attr, value, tag) {
const head = this.getHead(); const head = this.getHead();
return head.filter( return head.filter(item => item.attributes && item.attributes[attr] == value && (!tag || tag === item.tag))[0];
item =>
item.attributes &&
item.attributes[attr] == value &&
(!tag || tag === item.tag)
)[0];
} }
removeHeadByAttr(attr, value, tag) { removeHeadByAttr(attr, value, tag) {
@ -151,8 +146,8 @@ export default class Frame extends Model {
tag, tag,
attributes: { attributes: {
href, href,
rel: 'stylesheet' rel: 'stylesheet',
} },
}); });
} }
@ -165,7 +160,7 @@ export default class Frame extends Model {
!this.getHeadByAttr('src', src, tag) && !this.getHeadByAttr('src', src, tag) &&
this.addHeadItem({ this.addHeadItem({
tag, tag,
attributes: { src } attributes: { src },
}); });
} }
@ -184,17 +179,8 @@ export default class Frame extends Model {
toJSON(opts = {}) { toJSON(opts = {}) {
const obj = Model.prototype.toJSON.call(this, opts); const obj = Model.prototype.toJSON.call(this, opts);
const { em } = this;
const sm = em && em.get('StorageManager');
const smc = sm && sm.getConfig();
const defaults = result(this, 'defaults'); const defaults = result(this, 'defaults');
if (smc && !opts.fromUndo) {
const opts = { component: this.getComponent() };
if (smc.storeHtml) obj.html = em.getHtml(opts);
if (smc.storeCss) obj.css = em.getCss(opts);
}
if (opts.fromUndo) delete obj.component; if (opts.fromUndo) delete obj.component;
delete obj.styles; delete obj.styles;
delete obj.changesCount; delete obj.changesCount;

71
src/storage_manager/config/config.js

@ -1,36 +1,21 @@
export default { export default {
// Prefix identifier that will be used inside storing and loading // Prefix identifier that will be used inside storing and loading
// @deprecated
id: 'gjs-', id: 'gjs-',
// Default storage type. Available: local | remote
type: 'local',
// Enable/Disable autosaving // Enable/Disable autosaving
autosave: true, autosave: true,
// Indicates if load data inside editor after init // Enable/Disable autoload of data on editor init
autoload: true, autoload: true,
// Indicates which storage to use. Available: local | remote
type: 'local',
// If autosave enabled, indicates how many steps (general changes to structure) // If autosave enabled, indicates how many steps (general changes to structure)
// need to be done before save. Useful with remoteStorage to reduce remote calls // need to be done before save. Useful with remoteStorage to reduce remote calls
stepsBeforeSave: 1, stepsBeforeSave: 1,
//Enable/Disable components model (JSON format)
storeComponents: true,
//Enable/Disable styles model (JSON format)
storeStyles: true,
//Enable/Disable saving HTML template
storeHtml: true,
//Enable/Disable saving CSS template
storeCss: true,
// ONLY FOR LOCAL STORAGE
// If enabled, checks if browser supports Local Storage
checkLocal: true,
// Default storage options // Default storage options
options: { options: {
local: { local: {
@ -42,20 +27,27 @@ export default {
remote: { remote: {
// Custom parameters to pass with the remote request, eg. csrf token // Custom parameters to pass with the remote request, eg. csrf token
params: {}, params: {},
// Custom headers // Custom headers
headers: {}, headers: {},
// Endpoint where to save all stuff
// Endpoint URL where to store data project
urlStore: '', urlStore: '',
// Endpoint where to fetch data
// Endpoint URL where to load data project
urlLoad: '', urlLoad: '',
//Callback before request //Callback before request
beforeSend(jqXHR, settings) {}, beforeSend(jqXHR, settings) {},
//Callback after request //Callback after request
onComplete(jqXHR, status) {}, onComplete(jqXHR, status) {},
// set contentType paramater of $.ajax // set contentType paramater of $.ajax
// true: application/json; charset=utf-8' // true: application/json; charset=utf-8'
// false: 'x-www-form-urlencoded' // false: 'x-www-form-urlencoded'
contentTypeJson: true, contentTypeJson: true,
// Pass custom options to fetch API (remote storage) // Pass custom options to fetch API (remote storage)
// You can pass a simple object: { someOption: 'someValue' } // You can pass a simple object: { someOption: 'someValue' }
// or a function which returns and object to add: // or a function which returns and object to add:
@ -63,6 +55,7 @@ export default {
// return currentOpts.method === 'post' ? { method: 'patch' } : {}; // return currentOpts.method === 'post' ? { method: 'patch' } : {};
// } // }
fetchOptions: '', fetchOptions: '',
credentials: 'include', credentials: 'include',
/** /**
@ -74,38 +67,4 @@ export default {
recovery: true, recovery: true,
}, },
}, },
// ONLY FOR REMOTE STORAGE
// Custom parameters to pass with the remote storage request, eg. csrf token
params: {},
// Custom headers for the remote storage request
headers: {},
// Endpoint where to save all stuff
urlStore: '',
// Endpoint where to fetch data
urlLoad: '',
//Callback before request
beforeSend(jqXHR, settings) {},
//Callback after request
onComplete(jqXHR, status) {},
// set contentType paramater of $.ajax
// true: application/json; charset=utf-8'
// false: 'x-www-form-urlencoded'
contentTypeJson: true,
credentials: 'include',
// Pass custom options to fetch API (remote storage)
// You can pass a simple object: { someOption: 'someValue' }
// or a function which returns and object to add:
// currentOpts => {
// return currentOpts.method === 'post' ? { method: 'patch' } : {};
// }
fetchOptions: '',
}; };

Loading…
Cancel
Save