<commit_before>{% extends "admin_layout.html" %}
{% block body %}
    <style>
        .DTTT_container{
            display: none;
        }
    </style>
    <script>
    $( document ).ready(function() {

        var montenegroExpensesRetrieved = false;

        var montenegroExpensesTable = $( "#montenegro-expenses-table" ).DataTable( {
            dom: 'T<"clear">lfrtip',
            tableTools: {
                "sRowSelect": "multi",
                "aButtons": [ "select_all", "select_none" ]
            }
        });


        $('#montenegro-expenses-table').on('click', 'tr', function(event) {
            var cost = parseFloat(montenegroExpensesTable.row( this ).data()[3])

            var newCost = 0;
            var currentCost = $('#cost').val();
            if(currentCost == undefined || currentCost === '' || currentCost === NaN){
                currentCost = 0.0;
            }

            if($(this).hasClass('selected')){
               newCost = parseFloat(currentCost) + cost;
            }else{
               newCost = parseFloat(currentCost) - cost;
            }

            if(newCost < 100){
                newCost = 0.0;
            }

            $('#cost').val(newCost);
        });

        $( "#source_type" ).change(function() {
            if($( "#source_type" ).val() === 'Link'){
                $('#cost').val('');

                $('.source-ref-container').css('display','block');
                $('.cost-container').css('display','block');
                $('.currency-container').css('display','block');

                $('#cost').prop('disabled', false);
                $('#currency').prop('disabled', false);

                hideAllExpenseTables();

            }else if($( "#source_type" ).val() === 'Open Data'){
                $('#source_ref').val('');
                $('#cost').val('');

                $('.source-ref-container').css('display','none');
                $('.cost-container').css('display','block');
                $('.currency-container').css('display','block');

                $('#cost').prop('disabled', true);
                $('#currency').prop('disabled', true);

                if($('#region').val() === 'Kosovo'){
                    $('#source_ref').val('');
                    $('#currency option[value="EUR"]').attr("selected", "selected");
                    displayKosovoExpensesTable();

                }else if($('#region').val() === 'Montenegro')
                    $('#source_ref').val('');
                    $('#currency option[value="EUR"]').attr("selected", "selected");
                    displayMontenegroExpensesTable();

                }else if($('#region').val() === 'Serbia'){
                    $('#source_ref').val('');
                    $('#currency option[value="RSD"]').attr("selected", "selected");
                    displaySerbiaExpensesTable();
                }
            }else{
                 hideAllExpenseTables();
            }
        });

        function displayKosovoExpensesTable(){
            console.log('todo: render kosovo expense table.')
        }

        function displayMontenegroExpensesTable(){
            if(montenegroExpensesRetrieved == false){
                $.getJSON( "{{ url_for('api.expenses', region='montenegro', dataset='national-budget-execution') }}", function(results) {
                    $.each(results, function(idx, result) {
                        montenegroExpensesTable.row.add([
                            result.activity.id,
                            result.year,
                            result.activity.description,
                            result.cost
                        ]).draw();
                    });
                })
                .done(function() {
                    montenegroExpensesRetrieved = true;
                    $('.kosovo-expenses-row').css('display', 'none');
                    $('.montenegro-expenses-row').css('display', 'block');
                    $('.serbia-expenses-row').css('display', 'none');
                })
                .fail(function() {
                    console.log( "error" );
                })
            }else{
                $('.kosovo-expenses-row').css('display', 'none');
                $('.montenegro-expenses-row').css('display', 'block');
                $('.serbia-expenses-row').css('display', 'none');
            }
        }

        function displaySerbiaExpensesTable(){
            console.log('todo: render serbia expense table.')
        }

        function hideAllExpenseTables(){
            $('.kosovo-expenses-row').css('display', 'none');
            $('.montenegro-expenses-row').css('display', 'none');
            $('.serbia-expenses-row').css('display', 'none');
        }

    });
    </script>

    <div class="container-fluid" style="padding-left:5%; padding-right: 5%">
        <div class="row">
            <div class="panel panel-success">
                <div class="panel-heading">
                    <h3 class="panel-title">New Project</h3>
                </div>
                <div class="panel-body"  style="padding-left:20%; padding-right: 20%">
                    <div class="col-md-12">
                        <form action="{{ url_for('admin.project') }}" method="POST" class="form-horizontal">
                            <div class="form-group">
                                {{ form.name.label() }}
                                {{ form.name(class='form-control') }}
                            </div>
                            <div class="form-group">
                                {{ form.description.label() }}
                                {{ form.description(class='form-control') }}
                            </div>
                            <div class="form-group">
                                {{ form.region.label() }}
                                {{ form.region(class='form-control') }}
                            </div>
                            <div class="form-group">
                                {{ form.source_type.label() }}
                                {{ form.source_type(class='form-control') }}
                            </div>
                            <div class="form-group source-ref-container" style="display:none;">
                                {{ form.source_ref.label() }}
                                {{ form.source_ref(class='form-control') }}
                            </div>
                            <div class="form-group cost-container" style="display:none;">
                                {{ form.cost.label() }}
                                {{ form.cost(class='form-control') }}
                            </div>
                            <div class="form-group currency-container" style="display:none;">
                                {{ form.currency.label() }}
                                {{ form.currency(class='form-control') }}
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>

        <div class="row kosovo-expenses-row" style="display:none;padding-top:25px;">
            <div class="panel panel-success">
                <div class="panel-heading">
                    <h3 class="panel-title">Kosovo Open Dataset</h3>
                </div>

                <div class="panel-body">
                    <div class="col-md-12">
                        <table id="kosovo-expenses-table" class="display" cellspacing="0" width="100%">
                            <tr>
                                <th>ID</th>
                                <th>Year</th>
                                <th>Activity</th>
                                <th>Cost</th>
                            </tr>
                        </table>
                    </div>
                </div>
            </div>
        </div>

        <div class="row montenegro-expenses-row" style="display:none;padding-top:25px;">
            <div class="panel panel-success">
                <div class="panel-heading">
                    <h3 class="panel-title">National Budget Execution</h3>
                </div>

                <div class="panel-body">
                    <div class="col-md-12">
                        <table id="montenegro-expenses-table" class="display" cellspacing="0" width="100%">
                            <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>Year</th>
                                    <th>Activity</th>
                                    <th>Cost</th>
                                </tr>
                            </thead>
                        </table>
                    </div>
                </div>
            </div>
        </div>


        <div class="row serbia-expenses-row" style="display:none;padding-top:25px;">
            <div class="panel panel-success">
                <div class="panel-heading">
                    <h3 class="panel-title">Serbia Open Dataset</h3>
                </div>

                <div class="panel-body">
                    <div class="col-md-12">
                        <table id="serbia-expenses-table" class="display" cellspacing="0" width="100%">
                            <tr>
                                <th>ID</th>
                                <th>Year</th>
                                <th>Activity</th>
                                <th>Cost</th>
                            </tr>
                        </table>
                    </div>
                </div>
            </div>
        </div>

        <div class="row button-row" style="padding-top:25px; padding-bottom:50px;">
            <div class="col-md-12 text-center">
                <button type="submit" class="btn btn-primary">Submit</button>
            </div>
        </div>
    </div>
{% endblock %}<commit_msg>enforced some enabling/disabling of fields<commit_after>{% extends "admin_layout.html" %}
{% block body %}
    <style>
        .DTTT_container{
            display: none;
        }
    </style>
    <script>
    $( document ).ready(function() {

        var montenegroExpensesRetrieved = false;

        var montenegroExpensesTable = $( "#montenegro-expenses-table" ).DataTable( {
            dom: 'T<"clear">lfrtip',
            tableTools: {
                "sRowSelect": "multi",
                "aButtons": [ "select_all", "select_none" ]
            }
        });


        $('#montenegro-expenses-table').on('click', 'tr', function(event) {
            var cost = parseFloat(montenegroExpensesTable.row( this ).data()[3])

            var newCost = 0;
            var currentCost = $('#cost').val();
            if(currentCost == undefined || currentCost === '' || currentCost === NaN){
                currentCost = 0.0;
            }

            if($(this).hasClass('selected')){
               newCost = parseFloat(currentCost) + cost;
            }else{
               newCost = parseFloat(currentCost) - cost;
            }

            if(newCost < 100){
                newCost = 0.0;
            }

            $('#cost').val(newCost);
        });

        $( "#source_type" ).change(function() {
            if($( "#source_type" ).val() === 'Link'){
                $('#cost').val('');
                $('#source_ref').val('');

                $('.source-ref-container').css('display','block');
                $('.cost-container').css('display','block');
                $('.currency-container').css('display','block');

                $('#currency option[value=""]').attr("selected", "selected");

                $('#region').prop('disabled', true);
                $('#cost').prop('disabled', false);
                $('#currency').prop('disabled', false);

                hideAllExpenseTables();

            }else if($( "#source_type" ).val() === 'Open Data'){
                $('#source_ref').val('');
                $('#cost').val('');

                $('.source-ref-container').css('display','none');
                $('.cost-container').css('display','block');
                $('.currency-container').css('display','block');

                $('#region').prop('disabled', true);
                $('#cost').prop('disabled', true);
                $('#currency').prop('disabled', true);

                if($('#region').val() === 'Kosovo'){
                    $('#source_ref').val('https://github.com/opendatakosovo/relate-with-it/tree/master/importer/data/kosovo');
                    $('#currency option[value="EUR"]').attr("selected", "selected");
                    displayKosovoExpensesTable();

                }else if($('#region').val() === 'Montenegro'){
                    $('#source_ref').val('https://github.com/opendatakosovo/relate-with-it/tree/master/importer/data/montenegro');
                    $('#currency option[value="EUR"]').attr("selected", "selected");
                    displayMontenegroExpensesTable();

                }else if($('#region').val() === 'Serbia'){
                    $('#source_ref').val('https://github.com/opendatakosovo/relate-with-it/tree/master/importer/data/serbia');
                    $('#currency option[value="RSD"]').attr("selected", "selected");
                    displaySerbiaExpensesTable();
                }
            }else{
                $('#region').prop('disabled', false);

                $('#currency option[value=""]').attr("selected", "selected");

                $('.cost-container').css('display','none');
                $('.currency-container').css('display','none');
                hideAllExpenseTables();
            }
        });

        function displayKosovoExpensesTable(){
            console.log('todo: render kosovo expense table.')
        }

        function displayMontenegroExpensesTable(){
            if(montenegroExpensesRetrieved == false){
                $.getJSON( "{{ url_for('api.expenses', region='montenegro', dataset='national-budget-execution') }}", function(results) {
                    $.each(results, function(idx, result) {
                        montenegroExpensesTable.row.add([
                            result.activity.id,
                            result.year,
                            result.activity.description,
                            result.cost
                        ]).draw();
                    });
                })
                .done(function() {
                    montenegroExpensesRetrieved = true;
                    $('.kosovo-expenses-row').css('display', 'none');
                    $('.montenegro-expenses-row').css('display', 'block');
                    $('.serbia-expenses-row').css('display', 'none');
                })
                .fail(function() {
                    console.log( "error" );
                })
            }else{
                $('.kosovo-expenses-row').css('display', 'none');
                $('.montenegro-expenses-row').css('display', 'block');
                $('.serbia-expenses-row').css('display', 'none');
            }
        }

        function displaySerbiaExpensesTable(){
            console.log('todo: render serbia expense table.')
        }

        function hideAllExpenseTables(){
            $('.kosovo-expenses-row').css('display', 'none');
            $('.montenegro-expenses-row').css('display', 'none');
            $('.serbia-expenses-row').css('display', 'none');
        }

    });
    </script>

    <div class="container-fluid" style="padding-left:5%; padding-right: 5%">
        <div class="row">
            <div class="panel panel-success">
                <div class="panel-heading">
                    <h3 class="panel-title">New Project</h3>
                </div>
                <div class="panel-body"  style="padding-left:20%; padding-right: 20%">
                    <div class="col-md-12">
                        <form action="{{ url_for('admin.project') }}" method="POST" class="form-horizontal">
                            <div class="form-group">
                                {{ form.name.label() }}
                                {{ form.name(class='form-control') }}
                            </div>
                            <div class="form-group">
                                {{ form.description.label() }}
                                {{ form.description(class='form-control') }}
                            </div>
                            <div class="form-group">
                                {{ form.region.label() }}
                                {{ form.region(class='form-control') }}
                            </div>
                            <div class="form-group">
                                {{ form.source_type.label() }}
                                {{ form.source_type(class='form-control') }}
                            </div>
                            <div class="form-group source-ref-container" style="display:none;">
                                {{ form.source_ref.label() }}
                                {{ form.source_ref(class='form-control') }}
                            </div>
                            <div class="form-group cost-container" style="display:none;">
                                {{ form.cost.label() }}
                                {{ form.cost(class='form-control') }}
                            </div>
                            <div class="form-group currency-container" style="display:none;">
                                {{ form.currency.label() }}
                                {{ form.currency(class='form-control') }}
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>

        <div class="row kosovo-expenses-row" style="display:none;padding-top:25px;">
            <div class="panel panel-success">
                <div class="panel-heading">
                    <h3 class="panel-title">Kosovo Open Dataset</h3>
                </div>

                <div class="panel-body">
                    <div class="col-md-12">
                        <table id="kosovo-expenses-table" class="display" cellspacing="0" width="100%">
                            <tr>
                                <th>ID</th>
                                <th>Year</th>
                                <th>Activity</th>
                                <th>Cost</th>
                            </tr>
                        </table>
                    </div>
                </div>
            </div>
        </div>

        <div class="row montenegro-expenses-row" style="display:none;padding-top:25px;">
            <div class="panel panel-success">
                <div class="panel-heading">
                    <h3 class="panel-title">National Budget Execution</h3>
                </div>

                <div class="panel-body">
                    <div class="col-md-12">
                        <table id="montenegro-expenses-table" class="display" cellspacing="0" width="100%">
                            <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>Year</th>
                                    <th>Activity</th>
                                    <th>Cost</th>
                                </tr>
                            </thead>
                        </table>
                    </div>
                </div>
            </div>
        </div>


        <div class="row serbia-expenses-row" style="display:none;padding-top:25px;">
            <div class="panel panel-success">
                <div class="panel-heading">
                    <h3 class="panel-title">Serbia Open Dataset</h3>
                </div>

                <div class="panel-body">
                    <div class="col-md-12">
                        <table id="serbia-expenses-table" class="display" cellspacing="0" width="100%">
                            <tr>
                                <th>ID</th>
                                <th>Year</th>
                                <th>Activity</th>
                                <th>Cost</th>
                            </tr>
                        </table>
                    </div>
                </div>
            </div>
        </div>

        <div class="row button-row" style="padding-top:25px; padding-bottom:50px;">
            <div class="col-md-12 text-center">
                <button type="submit" class="btn btn-primary">Submit</button>
            </div>
        </div>
    </div>
{% endblock %}
{'fraction_non_alphanumeric': 0.15948546834953334, 'fraction_numerical': 0.005319406160839499, 'mean_word_length': 1.17615489845312, 'pattern_counts': {'":': 4, '<': 235, '<?xml version=': 0, '>': 233, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 36, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4423045', 'n_tokens_mistral': 5439, 'n_tokens_neox': 5066, 'n_words': 761}