Browse Source

Refactor Layer

up-style-manager
Artur Arseniev 5 years ago
parent
commit
44de77d2fa
  1. 85
      src/style_manager/model/Layer.js
  2. 2
      src/style_manager/model/PropertyStack.js

85
src/style_manager/model/Layer.js

@ -1,16 +1,44 @@
import Backbone from 'backbone'; import { Model } from 'common';
import Properties from './Properties';
import { camelCase } from 'utils/mixins'; import { camelCase } from 'utils/mixins';
import Properties from './Properties';
export default class Layer extends Model {
defaults() {
return {
index: '',
value: '',
values: {},
active: false,
preview: false,
properties: [],
};
}
/**
* Get layer index.
* @returns {Number}
*/
getIndex() {
const coll = this.collection;
return coll ? coll.indexOf(this) : -1;
}
export default Backbone.Model.extend({ /**
defaults: { * Get layer values.
index: '', * @param {Object} [opts={}] Options
value: '', * @param {Boolean} [opts.camelCase] Return property names in camelCase.
values: {}, * @returns {Object}
active: false, */
preview: false, getValues(opts = {}) {
properties: [], const values = this.get('values');
},
return opts.camelCase
? Object.keys(values).reduce((res, key) => {
res[camelCase(key)] = values[key];
return res;
}, {})
: values;
}
initialize() { initialize() {
const prp = this.get('properties'); const prp = this.get('properties');
@ -32,44 +60,23 @@ export default Backbone.Model.extend({
this.set('value', val.trim()); this.set('value', val.trim());
} }
}, }
getValues(opts = {}) {
const values = this.get('values');
return opts.camelCase
? Object.keys(values).reduce((res, key) => {
res[camelCase(key)] = values[key];
return res;
}, {})
: values;
},
upValues(props = {}) { upValues(props = {}) {
return this.set('values', { return this.set('values', {
...this.getValues(), ...this.getValues(),
...props, ...props,
}); });
}, }
getIndex() {
const coll = this.collection;
return coll ? coll.indexOf(this) : -1;
},
onPropAdd(prop) { onPropAdd(prop) {
const coll = this.collection; const coll = this.collection;
prop.parent = coll && coll.property; prop.parent = coll && coll.property;
}, }
/**
* Get property at some index
* @param {Number} index
* @return {Object}
*/
getPropertyAt(index) { getPropertyAt(index) {
return this.get('properties').at(index); return this.get('properties').at(index);
}, }
getPropertyValue(property) { getPropertyValue(property) {
let result = ''; let result = '';
@ -79,11 +86,11 @@ export default Backbone.Model.extend({
} }
}); });
return result; return result;
}, }
getFullValue() { getFullValue() {
let result = []; let result = [];
this.get('properties').each(prop => result.push(prop.getFullValue())); this.get('properties').each(prop => result.push(prop.getFullValue()));
return result.join(' ').trim(); return result.join(' ').trim();
}, }
}); }

2
src/style_manager/model/PropertyStack.js

@ -129,7 +129,7 @@ export default class PropertyStack extends PropertyComposite {
} }
/** /**
* Get layer label. * Get the layer label. The label can be customized with the `layerLabel` property.
* @param {[Layer]} layer * @param {[Layer]} layer
* @returns {String} * @returns {String}
* @example * @example

Loading…
Cancel
Save