<commit_before><link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="../bower_components/paper-button/paper-button.html">
<link rel="import" href="../bower_components/core-ajax/core-ajax.html">
<link rel="import" href="../bower_components/paper-toast/paper-toast.html">
<polymer-element name="usersinfo-element">
  <template>
  	<style>
    :host{
      display: block;
      margin:32px 0 32px 0;
    }
    #rowheadings {
      font-weight: 800;
    }
    table {
      width: 100%;
      border-collapse: collapse; 
    }
    tr.border_top {
      width: 100%;
      border-top: 1px solid black;
    }
    td,th {
      text-align: center;
      width: 20%;
      padding: 8px 0 8px 0;
    }
    .label {
      color: #fff;
      padding: 4px;
      border-radius: 4px;
    }
    .bgcolor-grey {
      background-color: #8C8C8C;
    }
    .bgcolor-success {
      background-color: #5CB85C;
    }
    .bgcolor-danger {
      background-color: #D9534F;
    }
    .bgcolor-info {
      background-color: #5bc0de;
    }
    .bgcolor-warning {
      background-color: #f0ad4e;
    }
    .bgcolor-primary {
      background-color: #337ab7;
    }
    .color-grey {
      color: #8C8C8C;
    }
    .color-success {
      color: #5CB85C;
    }
    .color-danger {
      color: #D9534F;
    }
    .color-info {
      color: #5bc0de;
    }
    .color-warning {
      color: #f0ad4e;
    }
    .color-primary {
      color: #337ab7;
    }
    input {
      width: 80%;
    }
    .thinput {
      padding: 0 0 8px 0;
    }
    #toast {
      background-color: #D9534F;
      color: #fff;
    }
	  </style>
    <core-ajax
        url="../UsersInfo"
        params="{{params}}"
        handleAs="json"
        response="{{response}}"
        contentType="application/json"
        id="coreajax"
        on-core-response="{{handleResponse}}"
        error="{{errorresp}}"
        on-core-error="{{handleError}}"></core-ajax>
    <table>
      <thead>
        <tr class="border_top">
          <th id="0" on-click="{{changeSort}}" style="{{sortColumn == '0' ? (sortDescending ? 'text-decoration:overline' : 'text-decoration:underline') : ''}}">Roll-number</th>
          <th id="1" on-click="{{changeSort}}" style="{{sortColumn == '1' ? (sortDescending ? 'text-decoration:overline' : 'text-decoration:underline') : ''}}">Name</th>
          <th id="5" on-click="{{changeSort}}" style="{{sortColumn == '5' ? (sortDescending ? 'text-decoration:overline' : 'text-decoration:underline') : ''}}">Answer</th>
          <th id="2" on-click="{{changeSort}}" style="{{sortColumn == '2' ? (sortDescending ? 'text-decoration:overline' : 'text-decoration:underline') : ''}}">Status</th>
          <th id="3" on-click="{{changeSort}}" style="{{sortColumn == '3' ? (sortDescending ? 'text-decoration:overline' : 'text-decoration:underline') : ''}}">LastUpdate</th>
          <th id="6" hidden?="{{!timed}}" on-click="{{changeSort}}" style="{{sortColumn == '6' ? (sortDescending ? 'text-decoration:overline' : 'text-decoration:underline') : ''}}">TimeTook</th>
        </tr>
        <tr>
          <th class="thinput"><input type="search" value="{{value0}}"/></th>
          <th class="thinput"><input type="search" value="{{value1}}"/></th>
          <th class="thinput"><input type="search" value="{{value2}}"/></th>
          <th class="thinput"><input type="search" value="{{value3}}"/></th>
          <th class="thinput"><input type="search" value="{{value4}}"/></th>
          <th class="thinput" hidden?="{{!timed}}"><input type="search" value="{{value5}}"/></th>
        </tr>
      </thead>
      <tbody>
        <template id="usersinfotemplete" repeat="{{userinfo in usersdata | sortByKey(sortColumn, sortDescending)}}">
          <tr class="border_top" hidden?="{{hiddenornot(userinfo[0],userinfo[1],userinfo[5],getstatus(userinfo[2],userinfo[4]),userinfo[3],userinfo[6], value0, value1, value2, value3, value4, value5)}}">
            <td>{{userinfo[0]}}</td>
            <td>{{userinfo[1]}}</td>
            <td><span class="{{userinfo[4]? 'color-success' : 'color-danger'}}">{{userinfo[5]}}</span></td>
            <td><span class="label {{getstatuscolor(userinfo[2],userinfo[4])}}">{{getstatus(userinfo[2],userinfo[4])}}</span></td>
            <td>{{userinfo[3]}}</td>
            <td hidden?="{{!timed}}">{{userinfo[6]}}</td>
          </tr>
        </template>
      </tbody>
    </table>
    <span><paper-toast id="toast" text=""></paper-toast></span>
  </template>
  <script>
    var jssortColumn = '0';
    var jssortDescending = true;
    Polymer({
      usersdata:[["120050053","bhargav",0,"10:53:34","","",""],["120050048","sundeep",3,"10:53:39",false,"2",1],["120050069","sumanth",0,"10:53:34","","",""],["120050064","nishanth",0,"10:53:34","","",""]],
      sortColumn:'3',
      sortDescending: true,
      value0:'',
      value1:'',
      value2:'',
      value3:'',
      value4:'',
      value5:'',
      fetch:true,
      params:{},
      timed: true,
      ready: function(){
        this.fetchdata();
      },
      fetchdata: function(){
        this.params = {};
        this.params["fetch"] = this.fetch;
        this.$.coreajax.go();

        this.async(this.fetchdata, null, 3000); 
      },
      changeSort: function(e,p,o){
        var clickedSortColumn = o.id;
        if(clickedSortColumn == this.sortColumn){
          //column already sorted, reverse sort
          this.sortDescending = !this.sortDescending;
        }else{
          this.sortColumn = clickedSortColumn;
        }
      },
      sortByKey : function(array, key, desc) {
        return array.sort(function(a, b) {
          var x = a[key];
          var y = b[key];
          //console.log(key+" "+x+" "+y);
       
          if (typeof x == "string" && typeof y == "string"){
            x = x.toLowerCase(); 
            y = y.toLowerCase();
          }
          if(desc){
            return ((x < y) ? 1 : ((x > y) ? -1 : 0));
          }else{
            return ((x < y) ? -1 : ((x > y) ? 1 : 0));
          }
        });
      },
      hiddenornot: function(userinfo0,userinfo1,userinfo2,userinfo3,userinfo4,userinfo5,value0,value1,value2,value3,value4,value5){
        console.log(JSON.stringify(userinfo3));
        var b0 = value0=='' || JSON.stringify(userinfo0).toLowerCase().indexOf(value0.toLowerCase()) > -1;
        var b1 = value1=='' || JSON.stringify(userinfo1).toLowerCase().indexOf(value1.toLowerCase()) > -1;
        var b2 = value2=='' || JSON.stringify(userinfo2).toLowerCase().indexOf(value2.toLowerCase()) > -1;
        var b3 = value3=='' || JSON.stringify(userinfo3).toLowerCase().indexOf(value3.toLowerCase()) > -1;
        var b4 = value4=='' || JSON.stringify(userinfo4).toLowerCase().indexOf(value4.toLowerCase()) > -1;
        var b5 = value5=='' || JSON.stringify(userinfo5).toLowerCase() >= value5.toLowerCase();
        //console.log(b0,b1,b2,b3,b4);
        if(b0 && b1 && b2 && b3 && b4 && b5) return false;
        else return true;
      },
      resort: function(){
        jssortColumn = this.sortColumn;
        jssortDescending = this.sortDescending;
        console.log(this.usersdata);
        this.usersdata = this.usersdata.sort(function(a, b) {
          var x = a[jssortColumn];
          var y = b[jssortColumn];
       
          console.log(key+" "+x+" "+y);

          if (typeof x == "string"){
            x = x.toLowerCase(); 
            y = y.toLowerCase();
          }
          if(jssortDescending){
            return ((x < y) ? 1 : ((x > y) ? -1 : 0));
          }else{
            return ((x < y) ? -1 : ((x > y) ? 1 : 0));
          }
        });
      },
      getstatus : function(statuscode,correct){
        if(statuscode==0) return "Disconnected";
        else if(statuscode==1) return "Connected";
        else if(statuscode==2) return "Attempting";
        else if(statuscode==3) {
          if(correct) return "Correct";
          else return "Wrong";
        }else if(statuscode==4) return "Stopped";
        else return "Invalid";
      },
      getstatuscolor : function(statuscode,correct){
        if(statuscode==0) return "bgcolor-grey";
        else if(statuscode==1) return "bgcolor-info";
        else if(statuscode==2) return "bgcolor-warning";
        else if(statuscode==3) {
          if(correct) return "bgcolor-success";
          else return "bgcolor-danger";
        }else if(statuscode==4) return "bgcolor-primary";
        else return "bgcolor-danger";
      },
      handleResponse: function(event, response) {
        if(this.response.status == 1){
          //console.log(this.response.usersdata);
          this.timed = this.response.timed;
          this.usersdata = JSON.parse(this.response.usersdata);
        }else {
          this.$.toast.text="Authentication failed";
          this.$.toast.show();
        }
      },
      handleError: function(event, response) {
        if(this.errorresp!=null){
          this.$.toast.text="Connection with server failed!";
          this.$.toast.show();
        }<commit_msg>download users info functionality added<commit_after><link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="../bower_components/paper-button/paper-button.html">
<link rel="import" href="../bower_components/core-ajax/core-ajax.html">
<link rel="import" href="../bower_components/paper-toast/paper-toast.html">
<polymer-element name="usersinfo-element">
  <template>
  	<style>
    :host{
      display: block;
      margin: 0 0 32px 0;
    }
    #rowheadings {
      font-weight: 800;
    }
    table {
      width: 100%;
      border-collapse: collapse; 
    }
    tr.border_top {
      width: 100%;
      border-top: 1px solid black;
    }
    td,th {
      text-align: center;
      width: 20%;
      padding: 8px 0 8px 0;
    }
    .label {
      color: #fff;
      padding: 4px;
      border-radius: 4px;
    }
    .bgcolor-grey {
      background-color: #8C8C8C;
    }
    .bgcolor-success {
      background-color: #5CB85C;
    }
    .bgcolor-danger {
      background-color: #D9534F;
    }
    .bgcolor-info {
      background-color: #5bc0de;
    }
    .bgcolor-warning {
      background-color: #f0ad4e;
    }
    .bgcolor-primary {
      background-color: #337ab7;
    }
    .color-grey {
      color: #8C8C8C;
    }
    .color-success {
      color: #5CB85C;
    }
    .color-danger {
      color: #D9534F;
    }
    .color-info {
      color: #5bc0de;
    }
    .color-warning {
      color: #f0ad4e;
    }
    .color-primary {
      color: #337ab7;
    }
    input {
      width: 80%;
    }
    .thinput {
      padding: 0 0 8px 0;
    }
    #toast {
      background-color: #D9534F;
      color: #fff;
    }
    paper-button.bluecls {
      text-transform: inherit;
      background-color: #337ab7;
      color: #fff;
      margin: 0 0 8px 0;
    }
	  </style>
    <core-ajax
        url="../UsersInfo"
        params="{{params}}"
        handleAs="json"
        response="{{response}}"
        contentType="application/json"
        id="coreajax"
        on-core-response="{{handleResponse}}"
        error="{{errorresp}}"
        on-core-error="{{handleError}}"></core-ajax>
    <div horizontal end-justified layout>
      <paper-button id="downqfilebtn" raised class="bluecls" on-click="{{HandleDownloadClick}}">Download</paper-button>
    </div>
    <table>
      <thead>
        <tr class="border_top">
          <th id="0" on-click="{{changeSort}}" style="{{sortColumn == '0' ? (sortDescending ? 'text-decoration:overline' : 'text-decoration:underline') : ''}}">Roll-number</th>
          <th id="1" on-click="{{changeSort}}" style="{{sortColumn == '1' ? (sortDescending ? 'text-decoration:overline' : 'text-decoration:underline') : ''}}">Name</th>
          <th id="5" on-click="{{changeSort}}" style="{{sortColumn == '5' ? (sortDescending ? 'text-decoration:overline' : 'text-decoration:underline') : ''}}">Answer</th>
          <th id="2" on-click="{{changeSort}}" style="{{sortColumn == '2' ? (sortDescending ? 'text-decoration:overline' : 'text-decoration:underline') : ''}}">Status</th>
          <th id="3" on-click="{{changeSort}}" style="{{sortColumn == '3' ? (sortDescending ? 'text-decoration:overline' : 'text-decoration:underline') : ''}}">LastUpdate</th>
          <th id="6" hidden?="{{!timed}}" on-click="{{changeSort}}" style="{{sortColumn == '6' ? (sortDescending ? 'text-decoration:overline' : 'text-decoration:underline') : ''}}">TimeTook</th>
        </tr>
        <tr>
          <th class="thinput"><input type="search" value="{{value0}}"/></th>
          <th class="thinput"><input type="search" value="{{value1}}"/></th>
          <th class="thinput"><input type="search" value="{{value2}}"/></th>
          <th class="thinput"><input type="search" value="{{value3}}"/></th>
          <th class="thinput"><input type="search" value="{{value4}}"/></th>
          <th class="thinput" hidden?="{{!timed}}"><input type="search" value="{{value5}}"/></th>
        </tr>
      </thead>
      <tbody id="tabletobdy">
        <template id="usersinfotemplete" repeat="{{userinfo in usersdata | sortByKey(sortColumn, sortDescending)}}">
          <tr class="border_top" hidden?="{{hiddenornot(userinfo[0],userinfo[1],userinfo[5],getstatus(userinfo[2],userinfo[4]),userinfo[3],userinfo[6], value0, value1, value2, value3, value4, value5)}}">
            <td>{{userinfo[0]}}</td>
            <td>{{userinfo[1]}}</td>
            <td><span class="{{userinfo[4]? 'color-success' : 'color-danger'}}">{{userinfo[5]}}</span></td>
            <td><span class="label {{getstatuscolor(userinfo[2],userinfo[4])}}">{{getstatus(userinfo[2],userinfo[4])}}</span></td>
            <td>{{userinfo[3]}}</td>
            <td hidden?="{{!timed}}">{{userinfo[6]}}</td>
          </tr>
        </template>
      </tbody>
    </table>
    <span><paper-toast id="toast" text=""></paper-toast></span>
  </template>
  <script>
    var jssortColumn = '0';
    var jssortDescending = true;
    Polymer({
      usersdata:[["120050053","bhargav",0,"10:53:34","","",""],["120050048","sundeep",3,"10:53:39",false,"2",1],["120050069","sumanth",0,"10:53:34","","",""],["120050064","nishanth",0,"10:53:34","","",""]],
      sortColumn:'3',
      sortDescending: true,
      value0:'',
      value1:'',
      value2:'',
      value3:'',
      value4:'',
      value5:'',
      fetch:true,
      params:{},
      timed: true,
      ready: function(){
        this.fetchdata();
      },
      fetchdata: function(){
        this.params = {};
        this.params["fetch"] = this.fetch;
        this.$.coreajax.go();

        this.async(this.fetchdata, null, 3000); 
      },
      changeSort: function(e,p,o){
        var clickedSortColumn = o.id;
        if(clickedSortColumn == this.sortColumn){
          //column already sorted, reverse sort
          this.sortDescending = !this.sortDescending;
        }else{
          this.sortColumn = clickedSortColumn;
        }
      },
      sortByKey : function(array, key, desc) {
        return array.sort(function(a, b) {
          var x = a[key];
          var y = b[key];
          //console.log(key+" "+x+" "+y);
       
          if (typeof x == "string" && typeof y == "string"){
            x = x.toLowerCase(); 
            y = y.toLowerCase();
          }
          if(desc){
            return ((x < y) ? 1 : ((x > y) ? -1 : 0));
          }else{
            return ((x < y) ? -1 : ((x > y) ? 1 : 0));
          }
        });
      },
      hiddenornot: function(userinfo0,userinfo1,userinfo2,userinfo3,userinfo4,userinfo5,value0,value1,value2,value3,value4,value5){
        console.log(JSON.stringify(userinfo3));
        var b0 = value0=='' || JSON.stringify(userinfo0).toLowerCase().indexOf(value0.toLowerCase()) > -1;
        var b1 = value1=='' || JSON.stringify(userinfo1).toLowerCase().indexOf(value1.toLowerCase()) > -1;
        var b2 = value2=='' || JSON.stringify(userinfo2).toLowerCase().indexOf(value2.toLowerCase()) > -1;
        var b3 = value3=='' || JSON.stringify(userinfo3).toLowerCase().indexOf(value3.toLowerCase()) > -1;
        var b4 = value4=='' || JSON.stringify(userinfo4).toLowerCase().indexOf(value4.toLowerCase()) > -1;
        var b5 = value5=='' || JSON.stringify(userinfo5).toLowerCase() >= value5.toLowerCase();
        //console.log(b0,b1,b2,b3,b4);
        if(b0 && b1 && b2 && b3 && b4 && b5) return false;
        else return true;
      },
      resort: function(){
        jssortColumn = this.sortColumn;
        jssortDescending = this.sortDescending;
        console.log(this.usersdata);
        this.usersdata = this.usersdata.sort(function(a, b) {
          var x = a[jssortColumn];
          var y = b[jssortColumn];
       
          console.log(key+" "+x+" "+y);

          if (typeof x == "string"){
            x = x.toLowerCase(); 
            y = y.toLowerCase();
          }
          if(jssortDescending){
            return ((x < y) ? 1 : ((x > y) ? -1 : 0));
          }else{
            return ((x < y) ? -1 : ((x > y) ? 1 : 0));
          }
        });
      },
      getstatus : function(statuscode,correct){
        if(statuscode==0) return "Disconnected";
        else if(statuscode==1) return "Connected";
        else if(statuscode==2) return "Attempting";
        else if(statuscode==3) {
          if(correct) return "Correct";
          else return "Wrong";
        }else if(statuscode==4) return "Stopped";
        else return "Invalid";
      },
      getstatuscolor : function(statuscode,correct){
        if(statuscode==0) return "bgcolor-grey";
        else if(statuscode==1) return "bgcolor-info";
        else if(statuscode==2) return "bgcolor-warning";
        else if(statuscode==3) {
          if(correct) return "bgcolor-success";
          else return "bgcolor-danger";
        }else if(statuscode==4) return "bgcolor-primary";
        else return "bgcolor-danger";
      },
      handleResponse: function(event, response) {
        if(this.response.status == 1){
          //console.log(this.response.usersdata);
          this.timed = this.response.timed;
          this.usersdata = JSON.parse(this.response.usersdata);
        }else {
          this.$.toast.text="Authentication failed";
          this.$.toast.show();
        }
      },
      handleError: function(event, response) {
        /*
        if(this.errorresp!=null){
          this.$.toast.text="Connection with server failed!";
          this.$.toast.show();
        }
        */
      },
      HandleDownloadClick: function(){
        //https://thiscouldbebetter.wordpress.com/2012/12/18/loading-editing-and-saving-a-text-file-in-html5-using-javascrip/
        var textToWrite="";
        var children = this.$.tabletobdy.querySelectorAll('tr');
        for (var i=0; i<children.length; i++) {
          var temp="";
          if(!children[i].hidden) {
            var tds = children[i].querySelectorAll('td');
            for(var j=0; j<tds.length; j++){
              var inner = tds[j].querySelectorAll('span')[0];
              if(inner!=undefined) inner = inner.innerHTML;
              else inner = tds[j].innerHTML;
              temp+=inner;
              if(j!=tds.length-1) temp+=",";
            }
            textToWrite+=temp+"\n";
          }
        }
        //console.log(textToWrite);

        var textFileAsBlob = new Blob([textToWrite], {type:'text/plain'});
        var fileNameToSaveAs = 'usersinfo';

        var downloadLink = document.createElement("a");
        downloadLink.download = fileNameToSaveAs;
        downloadLink.innerHTML = "Download File";
        if (window.URL != null)
        {
          // Chrome allows the link to be clicked
          // without actually adding it to the DOM.
          downloadLink.href = window.URL.createObjectURL(textFileAsBlob);
        }
        else
        {
          // Firefox requires the link to be added to the DOM
          // before it can be clicked.
          downloadLink.href = window.URL.createObjectURL(textFileAsBlob);
          downloadLink.onclick = this.destroyClickedElement;
          downloadLink.style.display = "none";
          document.body.appendChild(downloadLink);
        }

        downloadLink.click();
      },
      destroyClickedElement: function(event)
      {
        document.body.removeChild(event.target);
{'fraction_non_alphanumeric': 0.18434542586750788, 'fraction_numerical': 0.027109621451104102, 'mean_word_length': 2.4087701612903225, 'pattern_counts': {'":': 0, '<': 169, '<?xml version=': 0, '>': 179, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 15, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6070717', 'n_tokens_mistral': 6762, 'n_tokens_neox': 6533, 'n_words': 1139}