Url params 🎉 (#276)

* basic implementation

Signed-off-by: tech4GT <varun.gupta1798@gmail.com>

* fix bug

Signed-off-by: tech4GT <varun.gupta1798@gmail.com>

* fix everything

Signed-off-by: tech4GT <varun.gupta1798@gmail.com>

* add test and refactor

Signed-off-by: tech4GT <varun.gupta1798@gmail.com>

* update demo

Signed-off-by: tech4GT <varun.gupta1798@gmail.com>

* fix comma issue

Signed-off-by: tech4GT <varun.gupta1798@gmail.com>

* update test

Signed-off-by: tech4GT <varun.gupta1798@gmail.com>

* now doing with native encode

Signed-off-by: tech4GT <varun.gupta1798@gmail.com>
This commit is contained in:
Varun Gupta
2018-06-03 21:41:07 +05:30
committed by Jeffrey Warren
parent ac183205f0
commit 871453b857
6 changed files with 180 additions and 104 deletions

View File

@@ -3,23 +3,23 @@ else {var isBrowser = false}
require('./util/getStep.js')
ImageSequencer = function ImageSequencer(options) {
var sequencer = (this.name == "ImageSequencer")?this:this.sequencer;
options = options || {};
options.inBrowser = options.inBrowser || isBrowser;
options.sequencerCounter = 0;
function objTypeOf(object){
return Object.prototype.toString.call(object).split(" ")[1].slice(0,-1)
}
function log(color,msg) {
if(options.ui!="none") {
if(arguments.length==1) console.log(arguments[0]);
else if(arguments.length==2) console.log(color,msg);
}
}
function copy(a) {
if (!typeof(a) == "object") return a;
if (objTypeOf(a) == "Array") return a.slice();
@@ -32,11 +32,11 @@ ImageSequencer = function ImageSequencer(options) {
}
return a;
}
function makeArray(input) {
return (objTypeOf(input)=="Array")?input:[input];
}
var image,
steps = [],
modules = require('./Modules'),
@@ -45,27 +45,27 @@ ImageSequencer = function ImageSequencer(options) {
inputlog = [],
events = require('./ui/UserInterface')(),
fs = require('fs');
// if in browser, prompt for an image
// if (options.imageSelect || options.inBrowser) addStep('image-select');
// else if (options.imageUrl) loadImage(imageUrl);
function addSteps(){
var this_ = (this.name == "ImageSequencer")?this:this.sequencer;
var args = (this.name == "ImageSequencer")?[]:[this.images];
var json_q = {};
for(var arg in arguments){args.push(copy(arguments[arg]));}
json_q = formatInput.call(this_,args,"+");
inputlog.push({method:"addSteps", json_q:copy(json_q)});
for (var i in json_q)
for (var j in json_q[i])
require("./AddStep")(this_,i,json_q[i][j].name,json_q[i][j].o);
return this;
}
function removeStep(image,index) {
//remove the step from images[image].steps and redraw remaining images
if(index>0) {
@@ -75,16 +75,16 @@ ImageSequencer = function ImageSequencer(options) {
}
//tell the UI a step has been removed
}
function removeSteps(image,index) {
var run = {}, indices;
var this_ = (this.name == "ImageSequencer")?this:this.sequencer;
var args = (this.name == "ImageSequencer")?[]:[this.images];
for(var arg in arguments) args.push(copy(arguments[arg]));
var json_q = formatInput.call(this_,args,"-");
inputlog.push({method:"removeSteps", json_q:copy(json_q)});
for (var img in json_q) {
indices = json_q[img].sort(function(a,b){return b-a});
run[img] = indices[indices.length-1];
@@ -94,16 +94,16 @@ ImageSequencer = function ImageSequencer(options) {
// this.run(run); // This is creating problems
return this;
}
function insertSteps(image, index, name, o) {
var run = {};
var this_ = (this.name == "ImageSequencer")?this:this.sequencer;
var args = (this.name == "ImageSequencer")?[]:[this.images];
for (var arg in arguments) args.push(arguments[arg]);
var json_q = formatInput.call(this_,args,"^");
inputlog.push({method:"insertSteps", json_q:copy(json_q)});
for (var img in json_q) {
var details = json_q[img];
details = details.sort(function(a,b){return b.index-a.index});
@@ -114,39 +114,39 @@ ImageSequencer = function ImageSequencer(options) {
// this.run(run); // This is Creating issues
return this;
}
function run(spinnerObj,t_image,t_from) {
let progressObj;
if(arguments[0] != 'test'){
progressObj = spinnerObj
delete arguments['0']
delete arguments['0']
}
var this_ = (this.name == "ImageSequencer")?this:this.sequencer;
var args = (this.name == "ImageSequencer")?[]:[this.images];
for (var arg in arguments) args.push(copy(arguments[arg]));
var callback = function() {};
for (var arg in args)
if(objTypeOf(args[arg]) == "Function")
callback = args.splice(arg,1)[0];
var json_q = formatInput.call(this_,args,"r");
require('./Run')(this_, json_q, callback,progressObj);
return true;
}
function loadImages() {
var args = [];
var sequencer = this;
for (var arg in arguments) args.push(copy(arguments[arg]));
var json_q = formatInput.call(this,args,"l");
inputlog.push({method:"loadImages", json_q:copy(json_q)});
var loadedimages = this.copy(json_q.loadedimages);
var ret = {
name: "ImageSequencer Wrapper",
sequencer: this,
@@ -158,7 +158,7 @@ ImageSequencer = function ImageSequencer(options) {
setUI: this.setUI,
images: loadedimages
};
function load(i) {
if(i==loadedimages.length) {
json_q.callback.call(ret);
@@ -169,24 +169,24 @@ ImageSequencer = function ImageSequencer(options) {
load(++i);
});
}
load(0);
}
function replaceImage(selector,steps,options) {
options = options || {};
options.callback = options.callback || function() {};
return require('./ReplaceImage')(this,selector,steps,options);
}
function setUI(UI) {
this.events = require('./ui/UserInterface')(UI);
}
var exportBin = function(dir,basic) {
return require('./ExportBin')(dir,this,basic);
}
function modulesInfo(name) {
var modulesdata = {}
if(name == "load-image") return {};
@@ -197,7 +197,8 @@ ImageSequencer = function ImageSequencer(options) {
else modulesdata = modules[name][1];
return modulesdata;
}
// Strigifies the current sequence
function toString(step) {
if(step) {
return stepToString(step);
@@ -205,17 +206,49 @@ ImageSequencer = function ImageSequencer(options) {
return copy(this.images.image1.steps).map(stepToString).slice(1).join(',');
}
}
// Stringifies one step of the sequence
function stepToString(step) {
let inputs = copy(modulesInfo(step.options.name).inputs);
inputs = inputs || {};
for(let input in inputs) inputs[input] = step.options[input] || inputs[input].default;
for(let input in inputs) {
inputs[input] = step.options[input] || inputs[input].default;
inputs[input] = encodeURIComponent(inputs[input]);
}
var configurations = Object.keys(inputs).map(key=>key + ':' + inputs[key]).join(',');
return `${step.options.name}(${configurations})`;
}
// Coverts stringified sequence into JSON
function importStringtoJson(str){
let steps = str.split('),');
steps.push(steps.splice(-1)[0].slice(0,-1));
return steps.map(importStringtoJsonStep);
}
// Converts one stringified step into JSON
function importStringtoJsonStep(str){
str = [
str.substr(0,str.indexOf('(')),
str.slice(str.indexOf('(')+1)
];
str[1] = str[1].split(',').reduce(function(acc,cur,i){
cur = [
cur.substr(0,cur.indexOf(':')),
decodeURIComponent(cur.substr(cur.indexOf(':') + 1))
];
if(!!cur[0]) acc[cur[0]] = cur[1];
return acc;
},{});
return {
name : str[0],
options:str[1]
}
}
return {
//literals and objects
name: "ImageSequencer",
@@ -224,7 +257,7 @@ ImageSequencer = function ImageSequencer(options) {
modules: modules,
images: images,
events: events,
//user functions
loadImages: loadImages,
loadImage: loadImages,
@@ -238,14 +271,16 @@ ImageSequencer = function ImageSequencer(options) {
modulesInfo: modulesInfo,
toString: toString,
stepToString: stepToString,
importStringtoJson: importStringtoJson,
importStringtoJsonStep: importStringtoJsonStep,
//other functions
log: log,
objTypeOf: objTypeOf,
copy: copy,
setInputStep: require('./ui/SetInputStep')(sequencer)
}
}
module.exports = ImageSequencer;