Exemplo n.º 1
0
function unifySection(section, duplicate=false){

  // make a section refs and ids unique so we can duplicate
  section     = _.copy(section);
  
  //TODO: bad pattern
  // console.log("changing id");
  if(duplicate || !section.id){
    section.id  = _.randomId("s_"); //do we need id?
  }

  section.key  = _.randomId("k_"); //do we need key? //yes we need //need better organization

  //bug because repeater is getting itself turned into null
  section.fields.forEach(field=>{
    // if(!field) return; //if its null? why should field be
    field.ref = _.uniqueId("ref_");

    if(!field.fields) {
      return;
    }

    field.fields.forEach(child=>{
        child.forEach( gchild => gchild.ref = _.uniqueId("ref_"));
    });
  });

  section.settings.forEach(function(field){
    field.ref = _.uniqueId("ref_");
  });

  return section;
}
Exemplo n.º 2
0
    let updatePromise = new Promise((resolve, reject)=>{

      if( JSON.stringify(lastData) === JSON.stringify(newData) ){
        return reject(`${name} did not change so no need to sync now`);
      }

      lastData  = _.copy(newData);
      
      console.log(`${name} changed so we should sync now`);
      return resolve();
    });
Exemplo n.º 3
0
function simplifySections(sections){
  let oSections = _.copy(sections);

  return _.map(oSections, function(section){
    let data      = {};
    // data.id       = _.uniqueId('op-section-');
    data.id       = section.id;
    data.slug     = section.slug;
    data.fields   = simplify(section.fields);
    data.settings = simplify(section.settings);

    return data;
  });
}
Exemplo n.º 4
0
	return _.map(sections, function(section){
    let block = _.find(blocks, {slug: section.slug}); 
    
    //what if a block disappears
    if(!block) {
			return false;
		}
		
    block           = _.copy(block);
    block.id        = section.id;
    block.content   = section.content;
    block.style     = section.style;
		block.fields    = mistify(section.fields, block.fields);
		block.settings  = mistify(section.settings, block.settings);

		// console.log(block);
		return unifySection(block);
	}).filter(Boolean);
Exemplo n.º 5
0
function ShouldSync(initialData, name){
  let lastData = _.copy(initialData); //immutable please


  function check(newData){
    let updatePromise = new Promise((resolve, reject)=>{

      if( JSON.stringify(lastData) === JSON.stringify(newData) ){
        return reject(`${name} did not change so no need to sync now`);
      }

      lastData  = _.copy(newData);
      
      console.log(`${name} changed so we should sync now`);
      return resolve();
    });

    return updatePromise;
  };

  return check;
}
Exemplo n.º 6
0
const _ = require('underscore');

_.mixin({
  copy(obj){
    return JSON.parse(JSON.stringify(obj));
  },

  randomId(prefix){
  	prefix = prefix || "";
  	return _.uniqueId(prefix + Math.ceil(Math.random() * 1000000));
  },

  move(array, fromIndex, toIndex) {
    let arr = _.copy(array);
    arr.splice(toIndex, 0, arr.splice(fromIndex, 1)[0] );
    return arr;
  },

  getPosition(element) {
    var xPosition = 0;
    var yPosition = 0;
  
    while(element) {
        xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
        yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
        element = element.offsetParent;
    }
    return { x: xPosition, y: yPosition };
  }
});
Exemplo n.º 7
0
 return _.map(rGroup, function(rField){
   let field   = _.copy(rField);
   field.value = dbGroups[groupIndex][rField.name];
   return field;
 });