{% extends 'flashcards_base.html' %}

{% load jsonify staticfiles %}

{% block header_block %}
    <script>
        var app = angular.module('proso', ["proso.apps", "ngCookies"]);
        app.controller("demo", function($scope, userStatsService){
            $scope.service = userStatsService;
            $scope.add = function(){
                userStatsService.addGroup($scope.id, $scope.filter);
                delete $scope.filter;
                delete $scope.contexts;
                delete $scope.types;
                delete $scope.categories;
                delete $scope.id;
            };

            $scope.parse = function(str){
                try {
                    return JSON.parse(str);
                }catch(e){}
            };

            $scope.send = function(){
                f = $scope.post ? userStatsService.getStatsPost($scope.mastered) : userStatsService.getStats($scope.mastered);
                f.then(function(result){
                    $scope.json = result.data;
                });
            }
        });
    </script>
{% endblock %}

{% block content_block %}
    {% if help_text %}
        <h2>Documentation</h2>
        {{ help_text|safe }}
    {% endif %}
    <hr/>
    <div ng-app="proso" ng-controller="demo">
    <h2>JSON object</h2>
        <code>{{ json|obj2richjson }}</code>
        {% verbatim %}
        <pre>{{ json | json:4}}</pre>
        <hr/>
        <form>
            <input type="text" ng-model="id" placeholder="Identifier of group"/>
            <input type="text" ng-change="filter.categories = parse(categories)"  ng-model="categories" placeholder="Categories (list or list of lists)"/>
            <input type="text" ng-change="filter.contexts = parse(contexts)" ng-model="contexts" placeholder="Contexts (list)"/>
            <input type="text" ng-change="filter.types = parse(types)" ng-model="types" placeholder="Types (list)"/>
            <input type="text" ng-model="filter.language" placeholder="Language"/>
            <input type="button" class="pure-button pure-button-primary" value="Add" ng-click="add()">
        </form>
        <pre>{{ filter | json:4 }}</pre>
        <br/>
        <hr/>
        <pre>{{ service.getGroups() | json:4 }}</pre>
        <input type="checkbox" ng-model="mastered"/> number of mastered
        <input type="checkbox" ng-model="post"/> POST
        <input type="button" class="pure-button pure-button-primary" value="Get Stats" ng-click="send()">
        <input type="button" class="pure-button pure-button-primary" value="Clear" ng-click="service.clean()">
    {% endverbatim %}
    </div>
{% endblock %}
