<commit_before>import $ from 'jquery';
import _ from 'underscore';

import ItemCollection from '@girder/core/collections/ItemCollection';
import LoadingAnimation from '@girder/core/views/widgets/LoadingAnimation';
import View from '@girder/core/views/View';
import { formatSize } from '@girder/core/misc';
import { restRequest } from '@girder/core/rest';

import ItemListTemplate from '@girder/core/templates/widgets/itemList.pug';

/**
 * This widget shows a list of items under a given folder.
 */
var ItemListWidget = View.extend({
    events: {
        'click a.g-item-list-link': function (event) {
            event.preventDefault();
            var cid = $(event.currentTarget).attr('g-item-cid');
            this.trigger('g:itemClicked', this.collection.get(cid), event);
        },
        'click a.g-show-more-items': function () {
            this.collection.fetchNextPage();
        },
        'change .g-list-checkbox': function (event) {
            const target = $(event.currentTarget);
            const cid = target.attr('g-item-cid');
            if (target.prop('checked')) {
                this.checked.push(cid);
            } else {
                const idx = this.checked.indexOf(cid);
                if (idx !== -1) {
                    this.checked.splice(idx, 1);
                }
            }
            this.trigger('g:checkboxesChanged');
        }
    },

    initialize: function (settings) {
        this.checked = [];
        this._checkboxes = settings.checkboxes;
        this._downloadLinks = (
            _.has(settings, 'downloadLinks') ? settings.downloadLinks : true);
        this._viewLinks = (
            _.has(settings, 'viewLinks') ? settings.viewLinks : true);
        this._showSizes = (
            _.has(settings, 'showSizes') ? settings.showSizes : true);
        this._highlightItem = (
            _.has(settings, 'highlightItem') ? settings.highlightItem : false);
        this._paginated = (
            _.has(settings, 'paginated') ? settings.paginated : false);

        this.accessLevel = settings.accessLevel;
        this.public = settings.public;
        this._selectedItem = settings.selectedItem;

        new LoadingAnimation({
            el: this.$el,
            parentView: this
        }).render();

        this.collection = new ItemCollection();
        this.collection.filterFunc = settings.itemFilter;
        this.currentPage = 1; // By default we want to be on the first page

        if (this._paginated) {
            // Override the default to prevent appending new pages
            this.collection.append = false;
            if (this.collection.filterFunc) {
                console.warn('Pagination cannot be used with a filterFunction');
                this.collection.filterFunc = undefined;
            }
        }

        this.collection.fetch({ folderId: settings.folderId }).done(() => {
            this._totalPages = Math.ceil(this.collection.getTotalCount() / this.collection.pageLimit);
            if (this._paginated && this.collection.hasNextPage && this._selectedItem) {
                // Tells the parent container that the item is paginated so it can render the page selector
                this.trigger('g:paginated');
                // We need to get the position in the list for the selected item
                restRequest({
                    url: `item/position/${this._selectedItem.get('_id')}`,
                    method: 'GET',
                    data: { folderId: this._selectedItem.get('folderId') }
                }).done((val) => {
                    // Now we fetch the correct page for the position
                    val = Number(val);
                    if (val >= this.collection.pageLimit) {<commit_msg>Fixing the endpoint for the position<commit_after>import $ from 'jquery';
import _ from 'underscore';

import ItemCollection from '@girder/core/collections/ItemCollection';
import LoadingAnimation from '@girder/core/views/widgets/LoadingAnimation';
import View from '@girder/core/views/View';
import { formatSize } from '@girder/core/misc';
import { restRequest } from '@girder/core/rest';

import ItemListTemplate from '@girder/core/templates/widgets/itemList.pug';

/**
 * This widget shows a list of items under a given folder.
 */
var ItemListWidget = View.extend({
    events: {
        'click a.g-item-list-link': function (event) {
            event.preventDefault();
            var cid = $(event.currentTarget).attr('g-item-cid');
            this.trigger('g:itemClicked', this.collection.get(cid), event);
        },
        'click a.g-show-more-items': function () {
            this.collection.fetchNextPage();
        },
        'change .g-list-checkbox': function (event) {
            const target = $(event.currentTarget);
            const cid = target.attr('g-item-cid');
            if (target.prop('checked')) {
                this.checked.push(cid);
            } else {
                const idx = this.checked.indexOf(cid);
                if (idx !== -1) {
                    this.checked.splice(idx, 1);
                }
            }
            this.trigger('g:checkboxesChanged');
        }
    },

    initialize: function (settings) {
        this.checked = [];
        this._checkboxes = settings.checkboxes;
        this._downloadLinks = (
            _.has(settings, 'downloadLinks') ? settings.downloadLinks : true);
        this._viewLinks = (
            _.has(settings, 'viewLinks') ? settings.viewLinks : true);
        this._showSizes = (
            _.has(settings, 'showSizes') ? settings.showSizes : true);
        this._highlightItem = (
            _.has(settings, 'highlightItem') ? settings.highlightItem : false);
        this._paginated = (
            _.has(settings, 'paginated') ? settings.paginated : false);

        this.accessLevel = settings.accessLevel;
        this.public = settings.public;
        this._selectedItem = settings.selectedItem;

        new LoadingAnimation({
            el: this.$el,
            parentView: this
        }).render();

        this.collection = new ItemCollection();
        this.collection.filterFunc = settings.itemFilter;
        this.currentPage = 1; // By default we want to be on the first page

        if (this._paginated) {
            // Override the default to prevent appending new pages
            this.collection.append = false;
            if (this.collection.filterFunc) {
                console.warn('Pagination cannot be used with a filterFunction');
                this.collection.filterFunc = undefined;
            }
        }

        this.collection.fetch({ folderId: settings.folderId }).done(() => {
            this._totalPages = Math.ceil(this.collection.getTotalCount() / this.collection.pageLimit);
            if (this._paginated && this.collection.hasNextPage && this._selectedItem) {
                // Tells the parent container that the item is paginated so it can render the page selector
                this.trigger('g:paginated');
                // We need to get the position in the list for the selected item
                restRequest({
                    url: `item/${this._selectedItem.get('_id')}/position`,
                    method: 'GET',
                    data: { folderId: this._selectedItem.get('folderId') }
                }).done((val) => {
                    // Now we fetch the correct page for the position
                    val = Number(val);
                    if (val >= this.collection.pageLimit) {
{'fraction_non_alphanumeric': 0.12038886669330137, 'fraction_numerical': 0.0007990411506192569, 'mean_word_length': 1.9896496815286624, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5826672', 'n_tokens_mistral': 1978, 'n_tokens_neox': 1930, 'n_words': 469}