<commit_before>{% extends 'SiteBundle::main.html.twig' %}
{% block content %}
    {{ form_start(form) }}

    <ol class="artists" data-prototype="{{ form_widget(form.artists.vars.prototype)|e }}">
        {% for artist in form.artists %}
            <li>
                {{ form_row(artist) }}
        {% endfor %}
    </ol>
    {{ form_row(form.title) }}
    {{ form_row(form.text) }}
    {{ form_row(form.textBg) }}

    {{ form_end(form) }}

    <script>

        jQuery('select[name^="lyric\["]').select2({
            ajax: {
                url: '/proxy/api/artists?groups%5B0%5D=Acl&groups%5B1%5D=List',
                dataType: "json",
               
                processResults: function(data) {
                    var returnData = {
                        results: [],
                        pagination: {
                            more: true
                        }
                    };
                    
                    var i = 0;
                    for (i = 0; i < data.items.length; i++) {
                        returnData.results.push({
                            id: data.items[i].id,
                            text: data.items[i].name
                        });
                    }
                    
                    return returnData;
                },
                data: function (params) {
                    var filters = [];
                    if (params.term) {
                        filters = [
                            {
                                value: params.term,
                                operator: 'like',
                                field: 'name'
                            }
                        ];
                    }
                    
                    return {
                        filters: filters,
                        page: params.page,
                        perPage: 10
                    };
                }
            }
        });

        var $collectionHolder;

        // setup an "add a tag" link
        var $addTagLink = $('<a href="#" class="add_tag_link">Add a tag</a>');
        var $newLinkLi = $('<li></li>').append($addTagLink);

        jQuery(document).ready(function () {
            // Get the ul that holds the collection of artsts
            $collectionHolder = $('ol.artsts');

            // add the "add a tag" anchor and li to the artsts ul
            $collectionHolder.append($newLinkLi);

            // count the current form inputs we have (e.g. 2), use that as the new
            // index when inserting a new item (e.g. 2)
            $collectionHolder.data('index', $collectionHolder.find(':input').length);

            $addTagLink.on('click', function (e) {
                // prevent the link from creating a "#" on the URL
                e.preventDefault();

                // add a new tag form (see next code block)
                addTagForm($collectionHolder, $newLinkLi);
            });
        });

        function addTagForm($collectionHolder, $newLinkLi) {
            // Get the data-prototype explained earlier
            var prototype = $collectionHolder.data('prototype');

            // get the new index
            var index = $collectionHolder.data('index');

            // Replace '__name__' in the prototype's HTML to
            // instead be a number based on how many items we have
            var newForm = prototype.replace(/__name__/g, index);

            // increase the index with one for the next item
            $collectionHolder.data('index', index + 1);

            // Display the form in the page in an li, before the "Add a tag" link li
            var $newFormLi = $('<li></li>').append(newForm);
            $newLinkLi.before($newFormLi);
        }
    </script>
{% endblock %}
<commit_msg>functionality to add new artist<commit_after>{% extends 'SiteBundle::main.html.twig' %}
{% block content %}
    {{ form_start(form) }}

    <ol class="artists" data-prototype="{{ form_widget(form.artists.vars.prototype)|e }}">
        {% for artist in form.artists %}
            <li>
                {{ form_row(artist) }}
        {% endfor %}
        <li>
            <a href="#" id="addArtist" class="add_tag_link">Add a tag</a>
        </li>
    </ol>
    {{ form_row(form.title) }}
    {{ form_row(form.text) }}
    {{ form_row(form.textBg) }}

    {{ form_end(form) }}

    <script>

        function artistSelect2(element) {
            jQuery(element).select2({
                ajax: {
                    url: '/proxy/api/artists?groups%5B0%5D=Acl&groups%5B1%5D=List',
                    dataType: "json",
                    processResults: function(data) {
                        var returnData = {
                            results: [],
                            pagination: {
                                more: true
                            }
                        };

                        var i = 0;
                        for (i = 0; i < data.items.length; i++) {
                            returnData.results.push({
                                id: data.items[i].id,
                                text: data.items[i].name
                            });
                        }

                        return returnData;
                    },
                    data: function (params) {
                        var filters = [];
                        if (params.term) {
                            filters = [
                                {
                                    value: params.term,
                                    operator: 'like',
                                    field: 'name'
                                }
                            ];
                        }

                        return {
                            filters: filters,
                            page: params.page,
                            perPage: 10
                        };
                    }
                }
            });
        };

        artistSelect2(jQuery('select[name^="lyric\["]'));

        var $collectionHolder;

        // setup an "add a tag" link
        var $addTagLink = $('#addArtist');

        jQuery(document).ready(function () {
            // Get the ul that holds the collection of artsts
            $collectionHolder = $('ol.artists');

            // count the current form inputs we have (e.g. 2), use that as the new
            // index when inserting a new item (e.g. 2)
            $collectionHolder.data('index', $collectionHolder.find(':input').length);

            $addTagLink.on('click', function (e) {
                // prevent the link from creating a "#" on the URL
                e.preventDefault();

                // add a new tag form (see next code block)
                addTagForm($collectionHolder);
            });
        });

        function addTagForm($collectionHolder) {
            // Get the data-prototype explained earlier
            var prototype = $collectionHolder.attr('data-prototype');

            // get the new index
            var index = $collectionHolder.data('index');

            // Replace '__name__' in the prototype's HTML to
            // instead be a number based on how many items we have
            var newForm = prototype.replace(/__name__/g, index);

            // increase the index with one for the next item
            $collectionHolder.data('index', index + 1);

            // Display the form in the page in an li, before the "Add a tag" link li
            var $newFormLi = $('<li></li>').append(newForm);
            $('#addArtist').before($newFormLi);
            artistSelect2($newFormLi.find('select'));
        }
    </script>
{% endblock %}

{'fraction_non_alphanumeric': 0.11524500907441017, 'fraction_numerical': 0.004018667358050298, 'mean_word_length': 1.0981778623878162, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6959141', 'n_tokens_mistral': 1983, 'n_tokens_neox': 1835, 'n_words': 472}