<commit_before><!DOCTYPE html>
<html>
  <head>
    <title>Build Watcher</title>
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/bootstrap-responsive.min.css" rel="stylesheet">
     <link href="css/main.css" rel="stylesheet">
    <script type="text/javascript" charset="utf-8" src="phonegap.js"></script>
    <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
    <script type="text/javascript" charset="utf-8">

    var attempts = 0;
    var baseURL = "https://build.phonegap.com";
    var appApiPath = "/api/v1/apps/";
    var token = localStorage.getItem("token");
    var id = getURLParameter("id");
    var urlPlatform = "";


    $(document).ready(function() {
      getProjectDetails();
    });


    function getProjectDetails()
    {
        $.ajax({
          url: baseURL + appApiPath + id + "?auth_token=" + token,
          type:"get",
          success: parseRequest,
          cache:false,
          crossDomain:true
        });
    }

    function rebuild()
    {

        $.ajax({
          url: baseURL + appApiPath + id + "/build/" + "?auth_token=" + token,
          type: 'POST',
          success: handleReBuildSuccess
        });

    }
    function handleReBuildSuccess(response){
        getProjectDetails();
    }


    function getURLParameter(name) {
        return decodeURIComponent(
            (location.search.match(RegExp("[?|&]"+name+'=(.+?)(&|$)'))||[,null])[1]
        );  
    }

    function determinePlatform(){
        if(typeof(device) != "undefined"){
            return device.platform;
        }
        else{
            return "Not a supported platform";
        }
    }

    function getPlatformInfo(response,platform){
        urlPlatform = platform.toLowerCase();
        if (platform == "Not a supported platform"){
            urlPlatform = "android";
        }
        if (platform == "iPad" || platform == "iPhone"  || platform == "iPod"){
            urlPlatform = "ios";
        }

        var result = new Object();
        


        if (urlPlatform == "ios"){
            result['download'] = "/apps/" + response['id'] + "/download/ios";
        }
        else{
            result['download'] = response.download[urlPlatform];
        }

        result['status'] = response.status[urlPlatform];
        result['title'] = response.title;
        result['description'] = response.description;
        result['platform'] = platform + " (" + urlPlatform + ")";

        return result;
    }

    function populateDetails(details){
        var statusClass = "warning";




        $('#title').html(details.title);
        $('#description').html(details.description);
        $('#platform').html(details.platform);
        
        $('#attempts').html(attempts);
        if (details.status == "complete"){

            if (attempts > 0){
                showAlert();
            }

            statusClass = "success";
            attempts = 0;
            $('#downloadbtn').attr("href" ,baseURL +  details.download);
        }    
        else{
            $('#download').html('');
        }

        $('#status').html('<span class="label label-'+statusClass+'">' + details.status + '</span>');
    }

    // this function should parse responses.. you can do anything you need..
    // you can make it general so it would parse all the responses the page receives based on a response field
    function parseRequest(response)
    {
        try // try to output this to the javascript console
        {
            var results =getPlatformInfo(response,determinePlatform());
            populateDetails(results);

            console.log(results.status);
            if (results.status == "pending"){
                console.log("Scheduling another attempt");
                attempts = attempts + 1;
                setTimeout("getProjectDetails()", 1000);
                $('#downloadbtn').addClass("transparent");
            }
            else{
                setTimeout("getProjectDetails()", 10000);
                $('#downloadbtn').removeClass("transparent");
            }

        }
        catch(an_exception) // alert for the users that don't have a javascript console
        {
            alert(an_exception);
        }
    }

    // Show a custom alert
    //
    function showAlert() {


        if(typeof(device) != "undefined"){
            navigator.notification.alert(
                'Proejct ready!',  // message
                null,         // callback
                'PhoneGap Build ',            // title
                'Ok!'                  // buttonName
            );


            playBeep();
            vibrate();
        }
        else{
            alert('Project Ready!')
        }

       
    }

    function playBeep() {
        navigator.notification.beep(3);
    }

    // Vibrate for 2 seconds
    //
    function vibrate() {
        navigator.notification.vibrate(1000);
    }


    </script>
  </head>
 <body>

  <div class="navbar navbar-fixed-top">
      <div class="navbar-inner">
        <div class="container">
          <a class="brand" href="./index.html">PhoneGap Build Watcher</a>

            <ul class="nav">
                <li class="">
                <a href="./list.html">Project List</a>
                </li>
                
            </ul>
          <a class="btn pull-right" href="./clear.html">Logout</a>

        </div>
      </div>
    </div>

    <div class="container">
        <table class="table table-bordered">
            <tr><th>Title</th><td id="title"></td></tr>
            <tr><th>Description</th><td id="description"></td></tr>
            <tr><th>Platform</th><td id="platform"></td></tr>
            <tr><th>Status</th><td id="status"></td></tr>
            <tr><th>Attempts</th><td id="attempts"></td></tr>
        </table>    

        <ul id="actionlist">
            <li><a href="" id="downloadbtn" class="btn btn-large btn-primary transparent" target="_blank">Download App</a></li>
            <li><button class="btn btn-large" onclick="getProjectDetails()">Refresh Status</button></li>
            <li><button class="btn btn-large" onclick="rebuild()">Rebuild App</button></li>
        </ul>
    </div> 
  </body>
</html>



<commit_msg>Fixes GH-6<commit_after><!DOCTYPE html>
<html>
  <head>
    <title>Build Watcher</title>
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/bootstrap-responsive.min.css" rel="stylesheet">
     <link href="css/main.css" rel="stylesheet">
    <script type="text/javascript" charset="utf-8" src="phonegap.js"></script>
    <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
    <script type="text/javascript" charset="utf-8">

    var attempts = 0;
    var baseURL = "https://build.phonegap.com";
    var appApiPath = "/api/v1/apps/";
    var token = localStorage.getItem("token");
    var id = getURLParameter("id");
    var urlPlatform = "";


    $(document).ready(function() {
      getProjectDetails();
    });


    function getProjectDetails()
    {
        $.ajax({
          url: baseURL + appApiPath + id + "?auth_token=" + token,
          type:"get",
          success: parseRequest,
          cache:false,
          crossDomain:true
        });
    }

    function rebuild()
    {

        $.ajax({
          url: baseURL + appApiPath + id + "/build/" + "?auth_token=" + token,
          type: 'POST',
          success: handleReBuildSuccess
        });

    }
    function handleReBuildSuccess(response){
        getProjectDetails();
    }


    function getURLParameter(name) {
        return decodeURIComponent(
            (location.search.match(RegExp("[?|&]"+name+'=(.+?)(&|$)'))||[,null])[1]
        );  
    }

    function determinePlatform(){
        if(typeof(device) != "undefined"){
            return device.platform;
        }
        else{
            return "Not a supported platform";
        }
    }

    function getPlatformInfo(response,platform){
        urlPlatform = platform.toLowerCase();
        if (platform == "Not a supported platform"){
            urlPlatform = "android";
        }
        if (platform == "iPad" || platform == "iPhone"  || platform == "iPod"){
            urlPlatform = "ios";
        }

        var result = new Object();
        


        if (urlPlatform == "ios"){
            result['download'] = "/apps/" + response['id'] + "/download/ios";
        }
        else{
            result['download'] = response.download[urlPlatform];
        }

        result['status'] = response.status[urlPlatform];
        result['title'] = response.title;
        result['description'] = response.description;
        result['platform'] = platform + " (" + urlPlatform + ")";

        return result;
    }

    function populateDetails(details){
        var statusClass = "warning";




        $('#title').html(details.title);
        $('#description').html(details.description);
        $('#platform').html(details.platform);
        
        $('#attempts').html(attempts);
        if (details.status == "complete"){

            if (attempts > 0){
                showAlert();
            }

            statusClass = "success";
            attempts = 0;
            $('#downloadbtn').attr("href" ,baseURL +  details.download);
        }    
        else{
            $('#download').html('');
        }

        $('#status').html('<span class="label label-'+statusClass+'">' + details.status + '</span>');
    }

    // this function should parse responses.. you can do anything you need..
    // you can make it general so it would parse all the responses the page receives based on a response field
    function parseRequest(response)
    {
        try // try to output this to the javascript console
        {
            var results =getPlatformInfo(response,determinePlatform());
            populateDetails(results);

            console.log(results.status);
            if (results.status == "pending"){
                console.log("Scheduling another attempt");
                attempts = attempts + 1;
                setTimeout("getProjectDetails()", 1000);
                $('#downloadbtn').addClass("transparent");
            }
            else{
                setTimeout("getProjectDetails()", 10000);
                $('#downloadbtn').removeClass("transparent");
            }

        }
        catch(an_exception) // alert for the users that don't have a javascript console
        {
            alert(an_exception);
        }
    }

    // Show a custom alert
    //
    function showAlert() {


        if(typeof(device) != "undefined"){
            navigator.notification.alert(
                'Proejct ready!',  // message
                null,         // callback
                'PhoneGap Build ',            // title
                'Ok!'                  // buttonName
            );


            playBeep();
            vibrate();
        }
        else{
            alert('Project Ready!')
        }

       
    }

    function playBeep() {
        navigator.notification.beep(3);
    }

    // Vibrate for 2 seconds
    //
    function vibrate() {
        navigator.notification.vibrate(1000);
    }


    </script>
  </head>
 <body>

  <div class="navbar navbar-fixed-top">
      <div class="navbar-inner">
        <div class="container">
          <a class="brand" href="./index.html">PhoneGap Build Watcher</a>

            <ul class="nav">
                <li class="">
                <a href="./list.html">Project List</a>
                </li>
                
            </ul>
          <a class="btn pull-right" href="./clear.html">Logout</a>

        </div>
      </div>
    </div>

    <div class="container">
        <table class="table table-bordered">
            <tr><th>Title</th><td id="title">Loading <i class="icon-cog status-indicator"></i></td></tr>
            <tr><th>Description</th><td id="description">Loading <i class="icon-cog status-indicator"></i></td></tr>
            <tr><th>Platform</th><td id="platform">Loading <i class="icon-cog status-indicator"></i></td></tr>
            <tr><th>Project Status</th><td id="status">Loading <i class="icon-cog status-indicator"></i></td></tr>
            <tr><th>Rebuild Status</th><td id="attempts">Loading <i class="icon-cog status-indicator"></i></td></tr>
        </table>    

        <ul id="actionlist">
            <li><a href="" id="downloadbtn" class="btn btn-large btn-primary transparent" target="_blank">Download App</a></li>
            <li><button class="btn btn-large" onclick="getProjectDetails()">Refresh Status</button></li>
            <li><button class="btn btn-large" onclick="rebuild()">Rebuild App</button></li>
        </ul>
    </div> 
  </body>
</html>




{'fraction_non_alphanumeric': 0.15959925442684064, 'fraction_numerical': 0.0039608574091332715, 'mean_word_length': 1.928587673413691, 'pattern_counts': {'":': 0, '<': 183, '<?xml version=': 0, '>': 185, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 22, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3544104', 'n_tokens_mistral': 3679, 'n_tokens_neox': 3495, 'n_words': 726}