{% extends "base.html" %}

{% block content %}

        <h1 id=header>All experiments</h1>

        {{ experimenttable() }}
        
        <script>
            $(authWidget(() => reload( () => data_ajax('get_all_experiments'), 
                                       fillExperimentTable )))
            /*$(authWidget(() => reload(getAllExperiments, addExperimentsToTable)))
            
            function getAllExperiments() {
                var allExperiments = {}
                return data_ajax('get_users').then( (response) => {
                    
                    userdata = JSON.parse(response)
                    // parse data and get userids
                    deferreds = []
                    console.log(userdata)
                    for (user in userdata.users) {
                        console.log(user)
                        deferreds.push(data_ajax('get_user_experiments', data={"user":user}))
                    }
                    console.log(deferreds)

                    return $.when.apply($, deferreds).then(flattenExperiments)
                })
            }


            function flattenExperiments() {
                var allExperiments = []
                for (var i=0; i < arguments.length; i++) {
                    var response = arguments[i];
                    if (!(typeof response === 'string')) {
                        response = response[0]
                    }
                    console.log(response)
                    data = JSON.parse(response)
                    if (data.status == 'ok') {
                        for (var j = 0; j < data.experiments.length; j++) {
                            allExperiments.push(data.experiments[j])
                        }
                    }
                }
                
                return allExperiments
                
            }*/
        </script>



{% endblock %}
