Skip to main content

Advance JS search

 <!DOCTYPE html>
<html>
    <head>
        <title>
            Choosen
        </title>
        <link href="chosen.min.css" rel="stylesheet" type="text/css">
             <link crossorigin="anonymous" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.1/css/font-awesome.min.css" integrity="sha512-TECBPTD5Db97nlsJ/gGBBv9JLXg172YcGtrl/HHM4x9W++PPKEpHs61ogVd4x2omTgST1dIHoy2HeYWZzcZzHw==" referrerpolicy="no-referrer" rel="stylesheet"/>
            <style type="text/css">
                .j-filters-level {
    min-width: 400px;
    border: 1px solid lightgray;
    padding: 10px;
    margin-bottom: 5px;
}
.pointer{
  cursor: pointer;
}
.actionbuttons {
    margin-left: 20px;
}
.item {
    margin-right: 8px;
    display: inline-block;
}

.disabled-row span{
text-decoration: line-through;
  opacity: 0.8;
}
.add-item,.sub-add-item,.disabled-row,.remove-row{
  text-decoration: none !important;
  opacity: 0.8 !important;
}

.j-editor{
  display: none;
}
.j-level .addgroup  {
    /*position: absolute;
    bottom: 0px;
    left: -13px;*/
    padding: 5px;
    border-radius: 50% !important;
    border: 1px solid red;
    width: 12px;
    height: 12px;
    line-height: 11px;
    font-size: 13px;
    text-align: center;
    background-color: red;
    color: white;
    margin-right:  2px;

}
.j-level .addsubgroup  {
    /*position: absolute;
    bottom: 0px;
    left: 13px;*/
     padding: 5px;
    border-radius: 50% !important;
    border: 1px solid red;
    width: 12px;
    height: 12px;
    line-height: 11px;
    font-size: 13px;
    text-align: center;
    background-color: red;
    color: white;
}
.j-level-0{
  margin-left: 0px !important;
}
.j-level {
    border: 1px dashed blue;
    padding-bottom:  35px;
    position: relative;
     margin-top:10px; margin-left: 30px
}
.wrapper{ margin-left: 30px; margin-top: 10px;  }


.measure{ color:blue;  }
.operator{ color:red;  }
.bracket{ color:orange;  }


            </style>
        </link>
    </head>
    <body>
        <div class="j-filters">
        </div>
        <script src="jquery-3.6.0.min.js" type="text/javascript"></script>
        <script src="chosen.jquery.min.js" type="text/javascript"></script>
        <script src="lodash.min.js"></script>
  <script type="text/javascript">
    var stackList = [];    
    var currentStackListIndex = 0;   

 /* if(stackList.length < 1){
      stackList.push(["and"]);      
    }*/
    var ViewObject = {

      default:function(currentPath){
        return '<div class="item update-item '+this.class.join(",")+'" data-path="'+currentPath+'" data-identifier="'+this.identifier+'"><span class="j-label">'+this.label+'</span><span class="j-editor"></span></div>';
      },
      latest:function(currentPath){
        return '<div class="item update-item '+this.class.join(",")+'" data-path="'+currentPath+'" data-identifier="'+this.identifier+'">(<span class="j-label">'+this.label+'</span><span class="j-editor"></span>)</div>';
      },
      multipe_params:function(currentPath){
        var self = this;      
        if(typeof innerParamArray == "undefined"){ var innerParamArray = []; console.log("only once") }


        $.each(self.params,function(i,v){
        console.log(typeof self.defaultValues != "undefined" &&  Array.isArray(self.defaultValues[i]));
          
          if(typeof self.defaultValues != "undefined" &&  Array.isArray(self.defaultValues[i]))
          {
            
             innerParamArray.push('<span data-param-index="'+i+'" data-path="'+currentPath+'" class="update-inline-dropdown"><span class="j-label">'+v+'</span><span class="j-editor"></span></span>');
          }
          else if(typeof v == "string" || typeof v == "number")
          {
             innerParamArray.push('<span data-param-index="'+i+'" data-path="'+currentPath+'" class="update-inline-item"><span class="j-label">'+v+'</span><span class="j-editor"></span></span>');
          }
          else
          {
            view = getView(v,(currentPath+"-params-"+i))
            innerParamArray.push(view);       
          }     
        });
        
        if(["bracket"].indexOf(self.identifier) != -1)
        {
          a = '<div class="item update-item '+self.class.join(",")+'" data-path="'+currentPath+'" data-identifier="'+self.identifier+'"><span class="j-label">'+self.label+'('+innerParamArray.join(" ")+'<span data-path="'+(currentPath+"-params")+'" class="sub-add-item fa fa-plus"></span>)</span><span class="j-editor"></span></div>';
        }
        else if(self.params.length > 0)
        {
          //["min","max"].indexOf(self.identifier) != -1
          a = '<div class="item update-item '+this.class.join(",")+'" data-path="'+currentPath+'" data-identifier="'+this.identifier+'"><span class="j-label">'+this.label+'('+innerParamArray.join(", ")+')</span><span class="j-editor"></span></div>';
        }
        else
        {
          a = '<div class="item update-item '+self.class.join(",")+'" data-path="'+currentPath+'" data-identifier="'+self.identifier+'"><span class="j-label">'+self.label+'</span><span class="j-editor"></span></div>';
        }
        
        return a;
      },
    };


    function getView(stack,currentPath){
      
      if(stack && stack.identifier )
        return ViewObject["multipe_params"].call(stack,currentPath);     
      else
      {        
        return ViewObject['default'].call(stack,currentPath);
      }

    }
 
  var dropDownItems = {
"add":{"groupname":"Arithmetic Operations","group":"operator","identifier":"add","label":"+","params":[],"class":["operator"]},
"sub":{"groupname":"Arithmetic Operations","group":"operator","identifier":"sub","label":"-","params":[],"class":["operator"]},
"multiple":{"groupname":"Arithmetic Operations","group":"operator","identifier":"multiple","label":"*","params":[],"class":["operator"]},
"divide":{"groupname":"Arithmetic Operations","group":"operator","identifier":"divide","label":"/","params":[],"class":["operator"]},
"equal":{"groupname":"Comparision Operations","group":"operator","identifier":"equal","label":"Equals","params":[],"class":["operator"]},
"not_equal":{"groupname":"Comparision Operations","group":"operator","identifier":"not_equal","label":"Not equals","params":[],"class":["operator"]},
"greaterthan":{"groupname":"Comparision Operations","group":"operator","identifier":"greaterthan","label":"Greater than","params":[],"class":["operator"]},
"greaterthanequal":{"groupname":"Comparision Operations","group":"operator","identifier":"greaterthanequal","label":"Greater than equal to","params":[],"class":["operator"]},
"lessthan":{"groupname":"Comparision Operations","group":"operator","identifier":"lessthan","label":"Less than","params":[],"class":["operator"]},
"lessthanequal":{"groupname":"Comparision Operations","group":"operator","identifier":"lessthanequal","label":"Less than equal to","params":[],"class":["operator"]},
"cross_operation":{"groupname":"Comparision Operations","group":"operator","identifier":"cross_operation","label":"Cross Operations","params":[],"class":["operator"]},
"cross_above":{"groupname":"Comparision Operations","group":"operator","identifier":"cross_above","label":"Crossed above","params":[],"class":["operator"]},
"cross_below":{"groupname":"Comparision Operations","group":"operator","identifier":"cross_below","label":"Crossed below ","params":[],"class":["operator"]},

"number":{"groupname":"Number","group":"measure","identifier":"number","label":"Number","params":[10],"class":["measure"]},
"open":{"groupname":"Stock Attribute","group":"measure","identifier":"open","label":"Open","params":[],"class":["measure"]},
"low":{"groupname":"Stock Attribute","group":"measure","identifier":"low","label":"Low","params":[],"class":["measure"]},
"high":{"groupname":"Stock Attribute","group":"measure","identifier":"high","label":"High","params":[],"class":["measure"]},
"close":{"groupname":"Stock Attribute","group":"measure","identifier":"close","label":"Close","params":[3,4,5],"class":["bracket"]},
"bracket":{"groupname":"Bracket","group":"measure","identifier":"bracket","label":"bracket","params":[],"class":["bracket"]},    
"min":{"groupname":"Math Functions","group":"measure","identifier":"min","label":"Min","params":[20,{"groupname":"Number","group":"measure","identifier":"number","label":"Number","params":[10],"class":["measure"]}],"class":["measure"]},   
"max":{"groupname":"Math Functions","group":"measure","identifier":"max","label":"Max","defaultValues":{"1":[{"v":10000,"l":"10,000"},{"v":40000,"l":"30,000"}]},"params":[30,40000],"class":["measure"]},
"greatest":{"groupname":"Math Functions","group":"measure","identifier":"greatest","label":"Greatest","params":[],"class":["measure"]},
"least":{"groupname":"Math Functions","group":"measure","identifier":"least","label":"Least","params":[],"class":["measure"]},
"count":{"groupname":"Math Functions","group":"measure","identifier":"count","label":"Count","params":[],"class":["measure"]},
"countstreak":{"groupname":"Math Functions","group":"measure","identifier":"countstreak","label":"Countstreak","params":[],"class":["measure"]},
"abs":{"groupname":"Math Functions","group":"measure","identifier":"abs","label":"Abs","params":[],"class":["measure"]},
"ceil":{"groupname":"Math Functions","group":"measure","identifier":"ceil","label":"Ceil","params":[],"class":["measure"]},
"floor":{"groupname":"Math Functions","group":"measure","identifier":"floor","label":"Floor","params":[],"class":["measure"]},
"round":{"groupname":"Math Functions","group":"measure","identifier":"round","label":"Round","params":[],"class":["measure"]},
"square":{"groupname":"Math Functions","group":"measure","identifier":"square","label":"Square","params":[],"class":["measure"]},
"square":{"groupname":"Math Functions","group":"measure","identifier":"square","label":"Square root","params":[],"class":["measure"]},
"log":{"groupname":"Math Functions","group":"measure","identifier":"log","label":"Log","params":[],"class":["measure"]},
"log10":{"groupname":"Math Functions","group":"measure","identifier":"log10","label":"Log10","params":[2,5],"class":["measure"]},

"offsetminus0":{"groupname":"Latest Candles","group":"interdayOffset","identifier":"offsetminus0","label":"[0]","params":[],"class":["operator"]},
"offsetminus1":{"groupname":"Latest Candles","group":"interdayOffset","identifier":"offsetminus1","label":"[-1]","params":[],"class":["operator"]},
"offsetminus2":{"groupname":"Latest Candles","group":"interdayOffset","identifier":"offsetminus2","label":"[-2]","params":[],"class":["operator"]},
"offsetminus3":{"groupname":"Latest Candles","group":"interdayOffset","identifier":"offsetminus3","label":"[-3]","params":[],"class":["operator"]},
"offsetminus4":{"groupname":"Latest Candles","group":"interdayOffset","identifier":"offsetminus4","label":"[-4]","params":[],"class":["operator"]},
"offsetminus5":{"groupname":"Latest Candles","group":"interdayOffset","identifier":"offsetminus5","label":"[-5]","params":[],"class":["operator"]},
"offsetminus6":{"groupname":"Latest Candles","group":"interdayOffset","identifier":"offsetminus6","label":"[-6]","params":[],"class":["operator"]},
"offsetminus7":{"groupname":"Latest Candles","group":"interdayOffset","identifier":"offsetminus7","label":"[-7]","params":[],"class":["operator"]},
"offsetminus8":{"groupname":"Latest Candles","group":"interdayOffset","identifier":"offsetminus8","label":"[-8]","params":[],"class":["operator"]},
"offsetequal1":{"groupname":"Day nth Candles","group":"interdayOffset","identifier":"offsetequal1","label":"[=1]","params":[],"class":["operator"]},
"offsetequal2":{"groupname":"Day nth Candles","group":"interdayOffset","identifier":"offsetequal2","label":"[=2]","params":[],"class":["operator"]},
"offsetequal3":{"groupname":"Day nth Candles","group":"interdayOffset","identifier":"offsetequal3","label":"[=3]","params":[],"class":["operator"]},
"offsetequal4":{"groupname":"Day nth Candles","group":"interdayOffset","identifier":"offsetequal4","label":"[=4]","params":[],"class":["operator"]},
"offsetequal5":{"groupname":"Day nth Candles","group":"interdayOffset","identifier":"offsetequal5","label":"[=5]","params":[],"class":["operator"]},
"offsetequalminus1":{"groupname":"Prior Days Candles","group":"interdayOffset","identifier":"offsetequalminus1","label":"=[-1]","params":[],"class":["operator"]},
"offsetequalminus2":{"groupname":"Prior Days Candles","group":"interdayOffset","identifier":"offsetequalminus2","label":"=[-2]","params":[],"class":["operator"]},
"offsetequalminus3":{"groupname":"Prior Days Candles","group":"interdayOffset","identifier":"offsetequalminus3","label":"=[-3]","params":[],"class":["operator"]},
"offsetequalminus4":{"groupname":"Prior Days Candles","group":"interdayOffset","identifier":"offsetequalminus4","label":"=[-4]","params":[],"class":["operator"]},
"offsetequalminus4":{"groupname":"Prior Days Candles","group":"interdayOffset","identifier":"offsetequalminus4","label":"=[-5]","params":[],"class":["operator"]},


"off1min":{"groupname":"Intraday candles","group":"offset","identifier":"off1min","label":"1 minute","params":[],"class":["operator"]},
"off2min":{"groupname":"Intraday candles","group":"offset","identifier":"off2min","label":"2 minute","params":[],"class":["operator"]},
"off3min":{"groupname":"Intraday candles","group":"offset","identifier":"off3min","label":"3 minute","params":[],"class":["operator"]},
"off5min":{"groupname":"Intraday candles","group":"offset","identifier":"off5min","label":"5 minute","params":[],"class":["operator"]},
"off10min":{"groupname":"Intraday candles","group":"offset","identifier":"off10min","label":"10 minute","params":[],"class":["operator"]},
"off15min":{"groupname":"Intraday candles","group":"offset","identifier":"off15min","label":"15 minute","params":[],"class":["operator"]},
"off20min":{"groupname":"Intraday candles","group":"offset","identifier":"off20min","label":"20 minute","params":[],"class":["operator"]},
"off25min":{"groupname":"Intraday candles","group":"offset","identifier":"off25min","label":"25 minute","params":[],"class":["operator"]},
"off30min":{"groupname":"Intraday candles","group":"offset","identifier":"off30min","label":"30 minute","params":[],"class":["operator"]},
"off45min":{"groupname":"Intraday candles","group":"offset","identifier":"off45min","label":"45 minute","params":[],"class":["operator"]},
"off1hour":{"groupname":"Intraday candles","group":"offset","identifier":"off1hour","label":"1 hour","params":[],"class":["operator"]},
"off75min":{"groupname":"Intraday candles","group":"offset","identifier":"off75min","label":"75 minute","params":[],"class":["operator"]},
"off2hour":{"groupname":"Intraday candles","group":"offset","identifier":"off2hour","label":"2 hour","params":[],"class":["operator"]},
"off125min":{"groupname":"Intraday candles","group":"offset","identifier":"off125min","label":"125 minute","params":[],"class":["operator"]},
"off3hour":{"groupname":"Intraday candles","group":"offset","identifier":"off3hour","label":"3 hour","params":[],"class":["operator"]},
"off4hour":{"groupname":"Intraday candles","group":"offset","identifier":"off4hour","label":"4 hour","params":[],"class":["operator"]},
"offlatest":{"groupname":"Daily candles","group":"offset","identifier":"offlatest","label":"Latest","params":[],"class":["operator"]},
"off1day":{"groupname":"Daily candles","group":"offset","identifier":"off1day","label":"1 day ago","params":[],"class":["operator"]},
"off2day":{"groupname":"Daily candles","group":"offset","identifier":"off2day","label":"2 days ago","params":[],"class":["operator"]},
"off3day":{"groupname":"Daily candles","group":"offset","identifier":"off3day","label":"3 days ago","params":[],"class":["operator"]},
"off4day":{"groupname":"Daily candles","group":"offset","identifier":"off4day","label":"4 days ago","params":[],"class":["operator"]},
"off5day":{"groupname":"Daily candles","group":"offset","identifier":"off5day","label":"5 days ago","params":[],"class":["operator"]},
"offweekly":{"groupname":"Weekly candles","group":"offset","identifier":"offweekly","label":"Weekly","params":[],"class":["operator"]},
"off1week":{"groupname":"Weekly candles","group":"offset","identifier":"off1week","label":"1 week ago","params":[],"class":["operator"]},
"off2week":{"groupname":"Weekly candles","group":"offset","identifier":"off2week","label":"2 weeks ago","params":[],"class":["operator"]},
"off3week":{"groupname":"Weekly candles","group":"offset","identifier":"off3week","label":"3 weeks ago","params":[],"class":["operator"]},
"off4week":{"groupname":"Weekly candles","group":"offset","identifier":"off4week","label":"4 weeks ago","params":[],"class":["operator"]},
"off5week":{"groupname":"Weekly candles","group":"offset","identifier":"off5week","label":"5 weeks ago","params":[],"class":["operator"]},
"offmonthly":{"groupname":"Monthly candles","group":"offset","identifier":"offmonthly","label":"Monthly","params":[],"class":["operator"]},
"off1month":{"groupname":"Monthly candles","group":"offset","identifier":"off1month","label":"1 month ago","params":[],"class":["operator"]},
"off2month":{"groupname":"Monthly candles","group":"offset","identifier":"off2month","label":"2 months ago","params":[],"class":["operator"]},
"off3month":{"groupname":"Monthly candles","group":"offset","identifier":"off3month","label":"3 months ago","params":[],"class":["operator"]},
"off4month":{"groupname":"Monthly candles","group":"offset","identifier":"off4month","label":"4 months ago","params":[],"class":["operator"]},
"off5month":{"groupname":"Monthly candles","group":"offset","identifier":"off5month","label":"5 months ago","params":[],"class":["operator"]},
"off6month":{"groupname":"Monthly candles","group":"offset","identifier":"off6month","label":"6 months ago","params":[],"class":["operator"]},
"off7month":{"groupname":"Monthly candles","group":"offset","identifier":"off7month","label":"7 months ago","params":[],"class":["operator"]},
"off8month":{"groupname":"Monthly candles","group":"offset","identifier":"off8month","label":"8 months ago","params":[],"class":["operator"]},
"off9month":{"groupname":"Monthly candles","group":"offset","identifier":"off9month","label":"9 months ago","params":[],"class":["operator"]},
"offquaterly":{"groupname":"Quarterly candles","group":"offset","identifier":"offquaterly","label":"Quarterly","params":[],"class":["operator"]},
"off1quater":{"groupname":"Quarterly candles","group":"offset","identifier":"off1quater","label":"1 quarter ago","params":[],"class":["operator"]},
"off2quater":{"groupname":"Quarterly candles","group":"offset","identifier":"off2quater","label":"2 quarter ago","params":[],"class":["operator"]},
"off3quater":{"groupname":"Quarterly candles","group":"offset","identifier":"off3quater","label":"3 quarter ago","params":[],"class":["operator"]},
"off4quater":{"groupname":"Quarterly candles","group":"offset","identifier":"off4quater","label":"4 quarter ago","params":[],"class":["operator"]},
"offyearly":{"groupname":"Yearly candles","group":"offset","identifier":"offyearly","label":"Yearly","params":[],"class":["operator"]},
"off1year":{"groupname":"Yearly candles","group":"offset","identifier":"off1year","label":"1 year ago","params":[],"class":["operator"]},
"off2year":{"groupname":"Yearly candles","group":"offset","identifier":"off2year","label":"2 years ago","params":[],"class":["operator"]},
"off3year":{"groupname":"Yearly candles","group":"offset","identifier":"off3year","label":"3 years ago","params":[],"class":["operator"]},
"off4year":{"groupname":"Yearly candles","group":"offset","identifier":"off4year","label":"4 years ago","params":[],"class":["operator"]},



  };  

  function addToStack(path) {
    var buildDropDown = [];   
    //currentValue = getData(path);
    pathArray  = path.split("-");  
    pathArray.shift();
    currentValue = _.get(stackList,pathArray);
    
    if(currentValue.length == 0 || currentValue[currentValue.length-1].group == "operator")
    {
      selectedGroup = "measure";
      buildDropDown = buildGroupDropDown(selectedGroup);
      identifier = buildDropDown[1].identifier;


      /*newObj = $.extend( true, {}, dropDownItems['offsetminus0']);  
      currentValue.push(newObj);*/

      newObj = $.extend( true, {}, dropDownItems['offlatest']);  
      currentValue.push(newObj);


      newObj = $.extend( true, {}, dropDownItems[identifier]);  
      currentValue.push(newObj);
    }
    else
    {
      selectedGroup = "operator";
      buildDropDown = buildGroupDropDown(selectedGroup);
      identifier = buildDropDown[1].identifier;
      newObj = $.extend( true, {}, dropDownItems[identifier]);  
      currentValue.push(newObj);    
    }
    
    render(stackList);    
  }
  function buildGroupDropDown(selectedGroup) {
    var buildDropDown = [];
    buildDropDown.push({"groupname":" Action","group":selectedGroup,"identifier":"remove","label":"Remove Selected","params":[],"class":["operator"]});
    $.each(dropDownItems,function(i,v) {
      if(v.group == selectedGroup) {
        buildDropDown.push(v);
      }
    });    
    return buildDropDown;
  }
  function displayOptions(path,element,inputType="actionabledropdown",paramIndex="",groupname="",defaultSelected="") {
    var buildDropDown = [];
    $(".j-editor").hide();
    $(".j-label").show();
    $("#chosen").remove();
    
    pathArray  = path.split("-");  
    pathArray.shift();
    currentValue = _.get(stackList,pathArray);
    element.find(".j-label").hide();

    if(inputType == "actionabledropdown"){
      var s = $(' <select data-action-type="'+inputType+'" data-path="'+path+'" data-param-index="'+paramIndex+'" id="chosen" style="width:200px" class="chosen-select" />');
      selectedGroup = (groupname == "")?currentValue.group:groupname;
      selectedIdentifier = (defaultSelected == "")?currentValue.identifier:defaultSelected;       
      buildDropDown = buildGroupDropDown(selectedGroup);
      buildDropDown.sort( function ( a, b ) {
        if ( a.groupname < b.groupname ){
          return -1;
        }
        if ( a.groupname > b.groupname ){
          return 1;
        }
        return 0;
      } );

      optionString = '<optgroup label="'+buildDropDown[0].groupname+'">';
      optgroup = buildDropDown[0].groupname;
      $.each(buildDropDown,function(i,v){
        if(optgroup != v.groupname )
        {
          optionString += '</optgroup>';
          optionString += '<optgroup label="'+v.groupname+'">';
        }
        optionString += '<option '+((v.identifier == selectedIdentifier)?"selected":"")+' value="'+v.identifier+'">'+v.label+'</option>';
        optgroup = v.groupname;
      });
      optionString += '</optgroup>';
      $(optionString).appendTo(s)
    }
    else if(inputType == "inputbox")
    {
      var s = $('<input id="chosen"  data-action-type="'+inputType+'" data-path="'+path+'" data-param-index="'+paramIndex+'"  style="width:50px;" value="'+currentValue.params[paramIndex]+'"   />');
    }
    else if(inputType == "dropdownbox")
    {
      var selected = "";
      tmpSelectOption ='<select id="chosen"  data-action-type="'+inputType+'" data-path="'+path+'" data-param-index="'+paramIndex+'" >';
      if(typeof currentValue.defaultValues !="undefined" &&  Array.isArray(currentValue.defaultValues[paramIndex])){
            $.each(currentValue.defaultValues[paramIndex],function(ii,jj){
              if(jj['v'] == currentValue.params[paramIndex]){ selected="selected='selected'"; } else { selected="";  }
              tmpSelectOption += "<option "+selected+" value='"+jj['v']+"'>"+jj['l']+"</option>";
            });
            tmpSelectOption +="<select>";
          }

      var s = $(tmpSelectOption);
    }



    element.find(".j-editor").html(s);
    element.find(".j-editor").show();
  }
  function render(tmp_stackList,level = 0,parentIndex=0,rootPath="s") {
    
    $.each(tmp_stackList,function(mainIndex,stacks){
      
      if(typeof stacks == "string")
      {
        
        if(level == 0){

          action_selected = stacks.split("_");
          $(".j-filters").html("");
          $(".j-filters").append('<div class="j-level j-level-0 j-index-'+rootPath+'"><strong class="heading">Stock <select  data-path="'+rootPath+'" data-index="0" class="action_selected passorfail"><option value="passes" '+((action_selected[0] == 'passes')?"selected":"")+'>Passes</option><option value="fails" '+((action_selected[0] == 'fails')?"selected":"")+'>Fails</option></select> <select  data-path="'+rootPath+'"   data-index="1" class="action_selected allorany"><option value="all" '+((action_selected[1] == 'all')?"selected":"")+'>All</option><option value="any" '+((action_selected[1] == 'any')?"selected":"")+'>Any</option></select> of the below filters in <select  data-path="'+rootPath+'" data-index="2" class="action_selected markets"><option value="cash" '+((action_selected[2] == 'cash')?"selected":"")+'>cash</option><option value="banknifty" '+((action_selected[2] == 'banknifty')?"selected":"")+'>Banknifty</option><option value="etfs" '+((action_selected[2] == 'etfs')?"selected":"")+'>ETFs</option><option value="futures" '+((action_selected[2] == 'futures')?"selected":"")+'>futures</option><option value="gold_etfs" '+((action_selected[2] == 'gold_etfs')?"selected":"")+'>Gold ETFs</option><option value="indices" '+((action_selected[2] == 'indices')?"selected":"")+'>indices</option><option value="midcap50" '+((action_selected[2] == 'midcap50')?"selected":"")+'>Midcap 50</option><option value="nifty100" '+((action_selected[2] == 'nifty100')?"selected":"")+'>nifty 100</option><option value="nifty200" '+((action_selected[2] == 'nifty200')?"selected":"")+'>nifty 200</option><option value="nifty50" '+((action_selected[2] == 'nifty50')?"selected":"")+'>nifty 50</option><option value="nifty500" '+((action_selected[2] == 'nifty500')?"selected":"")+'>nifty 500</option><option value="niftyandbanknifty" '+((action_selected[2] == 'niftyandbanknifty')?"selected":"")+'>nifty and banknifty</option></select> segment:</strong><i data-path="'+rootPath+'" class="addgroup fa fa-plus"></i><i data-path="'+rootPath+'" class="addsubgroup fa fa-clone"></i></div>');
        }
      }
      else if(Array.isArray(stacks))
      {
        currentPath = rootPath+"-"+mainIndex;
        action_selected = stacks[0].split("_");
        $(".j-index-"+rootPath).append('<div class="j-level j-level-'+(level+1)+' j-index-'+currentPath+'"><strong class="heading">Stock <select  data-path="'+currentPath+'" data-index="0" class="action_selected passorfail"><option value="passes" '+((action_selected[0] == 'passes')?"selected":"")+'>Passes</option><option value="fails" '+((action_selected[0] == 'fails')?"selected":"")+'>Fails</option></select> <select  data-path="'+currentPath+'"   data-index="1" class="action_selected allorany"><option value="all" '+((action_selected[1] == 'all')?"selected":"")+'>All</option><option value="any" '+((action_selected[1] == 'any')?"selected":"")+'>Any</option></select> of the below filters in <select  data-path="'+rootPath+'" data-index="2" class="action_selected markets"><option value="cash" '+((action_selected[2] == 'cash')?"selected":"")+'>cash</option><option value="banknifty" '+((action_selected[2] == 'banknifty')?"selected":"")+'>Banknifty</option><option value="etfs" '+((action_selected[2] == 'etfs')?"selected":"")+'>ETFs</option><option value="futures" '+((action_selected[2] == 'futures')?"selected":"")+'>futures</option><option value="gold_etfs" '+((action_selected[2] == 'gold_etfs')?"selected":"")+'>Gold ETFs</option><option value="indices" '+((action_selected[2] == 'indices')?"selected":"")+'>indices</option><option value="midcap50" '+((action_selected[2] == 'midcap50')?"selected":"")+'>Midcap 50</option><option value="nifty100" '+((action_selected[2] == 'nifty100')?"selected":"")+'>nifty 100</option><option value="nifty200" '+((action_selected[2] == 'nifty200')?"selected":"")+'>nifty 200</option><option value="nifty50" '+((action_selected[2] == 'nifty50')?"selected":"")+'>nifty 50</option><option value="nifty500" '+((action_selected[2] == 'nifty500')?"selected":"")+'>nifty 500</option><option value="niftyandbanknifty" '+((action_selected[2] == 'niftyandbanknifty')?"selected":"")+'>nifty and banknifty</option></select> segment:</strong><i data-path="'+currentPath+'" class="addgroup fa fa-plus"></i><i data-path="'+currentPath+'" class="addsubgroup fa fa-clone"></i></div>');

        render(stacks,(level+1),mainIndex,currentPath);               
      }
      else
      {
        var active_class_string = (stacks.meta_data.is_active == 0)?"disabled-row":"";
        $(".j-index-"+rootPath).append("<div class='wrapper wrapper-"+level+mainIndex+" "+active_class_string+"'></div>");
        
        
        $.each(stacks.series,function(innerIndex,stack){
          //currentPath = ((rootPath == "s")?mainIndex+"-series-"+innerIndex:(rootPath+"-"+mainIndex+"-series-"+innerIndex));
          currentPath = rootPath+"-"+mainIndex+"-series-"+innerIndex;
          view = getView(stack,currentPath);

          $(".j-index-"+rootPath+" .wrapper-"+level+mainIndex).append(view);
        });

        //currentPath = ((rootPath == "s")?mainIndex+"-series":(rootPath+"-"+mainIndex+"-series"));
        currentPath = rootPath+"-"+mainIndex+"-series";
        currentPathMeta = rootPath+"-"+mainIndex+"-meta_data";
        $(".j-index-"+rootPath+" .wrapper-"+level+mainIndex).append('<span data-path="'+currentPath+'" class="add-item fa fa-plus"></span> <span data-path="'+currentPathMeta+'" class="disabled-row fa fa-toggle-on"></span> <span data-path="'+currentPath+'" class="remove-row fa fa-remove"></span>');

      }

    });   

    sessionStorage.setItem('stacksession', JSON.stringify(stackList));
  }
  function  offsetCallback(action,path,identifier)  {    
      pathArray  = path.split("-");  
      pathArray.shift();
      currentIndex  = pathArray.pop();

      target = _.get(stackList,pathArray);
      if(action == "add")
      {
        console.log(typeof target[currentIndex-1]);
        if(currentIndex == 0)
        {
          target.splice(currentIndex,0,dropDownItems['offsetminus0']);          
        }
        else if(target[currentIndex-1].group != "interdayOffset")
        {
          target.splice(currentIndex,0,dropDownItems['offsetminus0']);
        }
      }
      if(action == "remove" && typeof target[currentIndex-1] != "undefined" && target[currentIndex-1].group == "interdayOffset")
      {
        console.log("--------",(currentIndex,0,dropDownItems['offsetminus0']));
        target.splice((currentIndex-1),1);
      }     

      console.log(target)
  }
  function setItems(stackList,pathArray,newObj)
  {
    _.set(stackList,pathArray,newObj)
  }

  $(document).ready(function(){   

     stackList =[
    "passes_all_cash"
    ];

    if(sessionStorage.getItem('stacksession') != "")
    {
      //stackList = JSON.parse(sessionStorage.getItem('stacksession'));
    }


    
     
    render(stackList);
    $(document).on("click",".add-item",function(e) {
      e.stopPropagation();
      path = $(this).attr("data-path");
      addToStack(path);      
    });
    $(document).on("click",".remove-row",function(e) {
      e.stopPropagation();
      path = $(this).attr("data-path");
      pathArray  = path.split("-");  
      pathArray.shift();
      pathArray.pop();
      index = pathArray.pop();      
      if(pathArray.length > 0)
      {
        target = _.get(stackList,pathArray);
        target.splice(index,1);
      }
      else
      {
        stackList.splice(index,1);
      }
       render(stackList);
    });
    $(document).on("click",".disabled-row",function(e) {
      e.stopPropagation();
      path = $(this).attr("data-path");
      pathArray  = path.split("-");  
      pathArray.shift();  
      pathArray.push('is_active');
      toggle = 1 - parseInt(_.get(stackList,pathArray,0));
      _.set(stackList,pathArray,toggle);
      render(stackList);
      //addToStack(path);      
    });
    $(document).on("click",".sub-add-item",function(e) {
      e.stopPropagation();
      path = $(this).attr("data-path");
      addToStack(path);
    });
    $(document).on("change",".action_selected",function() {
      path = $(this).attr("data-path");
      index = $(this).attr("data-index");
      
      if(path == "s") {
        tmp = stackList[0].split("_");
        tmp[index] = $(this).val();
        stackList[0] = tmp[0]+"_"+tmp[1]+"_"+tmp[2];
      } else {       
        pathArray  = path.split("-");  
        pathArray.shift();  
        target  =_.get(stackList,pathArray);
        tmp = target[0].split("_");                
        tmp[index] = $(this).val();
        pathArray.push(0);        
        _.set(stackList,pathArray,tmp[0]+"_"+tmp[1]+"_"+tmp[2]);        
      }      
      //render(stackList);
    });
    $(document).on("click",".addgroup",function() {
      path = $(this).attr("data-path");
      if(path == "s") {
        stackList.push({series:[],meta_data:{"is_active":1}});
      } else {
        pathArray  = path.split("-");  
        pathArray.shift();    
        target  =_.get(stackList,pathArray);
        target.push({series:[],meta_data:{"is_active":1}});
      }      
      render(stackList);
    });
    $(document).on("click",".addsubgroup",function() {
      path = $(this).attr("data-path");
      if(path == "s") {
        stackList.push(["passes_all_cash",{series:[],meta_data:{"is_active":1}}]);
      } else {
        pathArray  = path.split("-");  
        pathArray.shift();
        target  =_.get(stackList,pathArray);
        target.push(["passes_all_cash",{series:[],meta_data:{"is_active":1}}]);
      }      
      render(stackList);    
    });
    $(document).on("click",".j-editor",function(e){
      e.stopPropagation();
    });
    $(document).on("change","#chosen",function(e) {
        e.stopPropagation();
        var self = $(this);
        if(self.closest(".wrapper").hasClass("disabled-row"))
        {
          return false;
        }
        path = $(this).attr("data-path");  
        paramIndex = $(this).attr("data-param-index");  

        if($(this).val() == "remove") {
          pathArray  = path.split("-");  
          pathArray.shift();
          currentIndex = pathArray.pop();
          target  =_.get(stackList,pathArray);
          target.splice(currentIndex,1);          
          
        } else if($(this).attr("data-action-type") == "actionabledropdown"){


          identifier = $(this).val();
          //updateToStack(identifier,path);
          newObj = $.extend( true, {}, dropDownItems[identifier]);  
          pathArray  = path.split("-");  
          pathArray.shift();
          //_.set(stackList,pathArray,newObj);
          setItems(stackList,pathArray,newObj);

          if(dropDownItems[identifier].group == "offset")
          {
            if(dropDownItems[identifier].groupname  == "Intraday candles")
            {              
              offsetCallback("add",path,identifier);
            }
            else
            {
              offsetCallback("remove",path,identifier);
            }
          }

        } else if($(this).attr("data-action-type") == "inputbox" || $(this).attr("data-action-type") == "dropdownbox") {
          pathArray  = (path+"-params-"+paramIndex).split("-");  
          pathArray.shift();
          //_.set(stackList,pathArray,$(this).val());
          setItems(stackList,pathArray,$(this).val());
        }
        render(stackList);    
    });
    $(document).on("click",".update-item",function(e) {
      e.stopPropagation();
      var self = $(this);
      if(self.closest(".wrapper").hasClass("disabled-row"))
      {
          return false;
      }
        path = $(this).attr("data-path");
        setTimeout(function(){
          displayOptions(path,self);
        },0);
      
    });
    $(document).on("click",".update-inline-item",function(e) {
      e.stopPropagation();
      var self = $(this);      
      if(self.closest(".wrapper").hasClass("disabled-row"))
      {
        return false;
      }
      path = $(this).attr("data-path");
      paramIndex = $(this).attr("data-param-index");
      setTimeout(function(){
        displayOptions(path,self,"inputbox",paramIndex);
      },0);
    });

    $(document).on("click",".update-inline-dropdown",function(e) {
      e.stopPropagation();
      var self = $(this);      
      if(self.closest(".wrapper").hasClass("disabled-row"))
      {
        return false;
      }
      path = $(this).attr("data-path");
      paramIndex = $(this).attr("data-param-index");
      setTimeout(function(){
        displayOptions(path,self,"dropdownbox",paramIndex);
      },0);
    });

    $(document).click(function(event) {
      var $target = $(event.target);    
      if(!$.contains($(".j-filters-level"),$target))
      {
        $(".j-label:hidden").show();
        $(".j-editor:visible").hide();
      }
    });
  });
        </script>
    </body>
</html>

Comments

Popular posts from this blog

Enable Https by self-signing certification.

  Run make-ssl-cert command > sudo make-ssl-cert generate-default-snakeoil will created 2 files in following directory.     - /etc/ssl/certs/ssl-cert-snakeoil.pem     - /etc/ssl/private/ssl-cert-snakeoil.key Open /etc/apache2/site-avilable and find and modify with below line (with above certs paths) .         SSLCertificateFile    /etc/ssl/certs/ssl-cert-snakeoil.pem         SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key > sudo a2ensite default-ssl > sudo a2enmode ssl > sudo systemctl restart apache2 Open https://localhost

simple recursive function to copy entire directories

<?php function recurse_copy ( $src , $dst ) {     $dir = opendir ( $src );     @ mkdir ( $dst );     while( false !== ( $file = readdir ( $dir )) ) {         if (( $file != '.' ) && ( $file != '..' )) {             if ( is_dir ( $src . '/' . $file ) ) {                 recurse_copy ( $src . '/' . $file , $dst . '/' . $file );             }             else {                 copy ( $src . '/' . $file , $dst . '/' . $file );             }         }     }     closedir ( $dir ); } ?>