HydraShare / hydra

Hydra is a web platform to share your example files from Grasshopper and Dynamo
http://hydrashare.github.io/hydra/
MIT License
69 stars 151 forks source link

Add a gs script to collect and prepare the list #2

Closed mostaphaRoudsari closed 9 years ago

mostaphaRoudsari commented 9 years ago

In that way the page can load the first portion of the available files onload and keep fetching on scroll down. The current approach won't be functional once we have 1000s of files.

mostaphaRoudsari commented 9 years ago

I took out the code for now until we make sure it works fine:


// tracking example files and downloads!
    jQuery(document).ready(function( $ ) {
        var request;
        // bind the download submit event to the form
        $("#example-download").submit(function(event){
            //download the zip file from github
            window.location = example.download_path;

            // abort any pending request
            if (request) {  
                request.abort();
            }

            // setup some local variables
            var $form = $(this);        
            var $inputs = $form.find("button");
            $inputs.prop("disabled", true);
            $('#downloadCount').text('#');      
            data={"owner":example.owner,"description":example.description,"request_type":"increment"};

            // fire off the request to /form.php
            request = $.ajax({
                url: "https://script.google.com/macros/s/AKfycbxiRnl-119Qy-Ygchrjp5OiMelYUJCZ-ZHjpwKTm6dtaYCOZ9IZ/exec",
                type: "post",
                data: data
            });

            // callback handler that will be called on success
            request.done(function (response, textStatus, jqXHR){
                // log a message to the console
                $('#downloadCount').text(response.downloads);
                console.log(response);
            });
            // callback handler that will be called on failure
            request.fail(function (jqXHR, textStatus, errorThrown){
                // log the error to the console
                console.error("The following error occured: " + textStatus, errorThrown);
            });
            // callback handler that will be called regardless if the request failed or succeeded
            request.always(function () {
                // reenable the inputs
                $inputs.prop("disabled", false);
            });

            // prevent default posting of form
            event.preventDefault();
        });
    });

Here is an alternative to writing the code myself: http://stackshare.io/sheetsu

mostaphaRoudsari commented 9 years ago

This is done and runs every 1 minute. I keep it open until I integrate it into the process.

mostaphaRoudsari commented 9 years ago

It's working live now. In theory Hydra should be able to handle 1000s of examples with no issue. Also the page is feeding the results gradually. I also added the sort by functionality which fails after filtering. I will add a separate issue for that.