<commit_before>"use strict";
/**
 * Application logic.
 */
var $ = require("jquery"),
    _ = require("underscore"),
    Backbone = require("backbone"),
    Handlebars = require("handlebars"),
    RegisterHandlebarHelpers = require("./handlebarhelpers.js"),
    appSettings = require("./settings.js"),
    NavbarView = require("./views/NavbarView.js"),
    LoginPageView = require("./views/LoginPageView.js"),
    MainPageView = require("./views/MainPageView.js"),
    BooksPageView = require("./views/BooksPageView.js"),
    BookPageView = require("./views/BookPageView.js"),
    AppConfigurationModel = require("./models/Configuration.js"),
    EditBookPageView = require("./views/EditBookPageView.js"),
    GlobalCountModel = require("./models/GlobalCount.js"),
    BookCollection = require("./models/BookCollection.js"),
    BooksByLetterCollection = require("./models/BooksByLetterCollection.js"),
    SpineCollection = require("./models/SpineCollection.js"),
    TagCollection = require("./models/TagCollection.js"),
    BookModel = require("./models/Book.js"),
    HeaderIconsTemplate = require("./views/templates/headericons.html"),
    HeaderMenuTemplate = require("./views/templates/headermenu.html"),
    appevents = require("./appevents.js"),
    appsetup = require("./appsetup.js");

var app = {
    // Catalog: all metadata regarding the library.
    // Typically, these data will change only when a books is added/edited/deleted.
    catalog: {
        spinesInitialized: false,
        booksByLetterInitialized: false,
        metadataUpToDate: false,
        spineCollection: new SpineCollection(),
        booksByLetterCollection: new BooksByLetterCollection(),
        globalCountModel: new GlobalCountModel(),
        bookCollection: new BookCollection(),
        tagCollection: new TagCollection(),
        /**
         * Load the spines collection, fetching only when necessary.
         **/
        loadSpines: function(forceLoad) {
            var deferred = $.Deferred();
            if (!this.spinesInitialized || forceLoad) {
                this.spineCollection.fetch()
                    .done(function() {
                        deferred.resolve();
                    })
                    .fail(function() {
                        deferred.reject();
                    })
                    .always(_.bind(function() {
                        this.spinesInitialized = true;
                    }, this));
            } else {
                deferred.resolve();
            }

            return deferred;
        },
        /**
         * Load the books-by-letter collection, fetching only when necessary.
         **/
        loadBooksByLetter: function(forceLoad) {
            var deferred = $.Deferred();
            if (!this.booksByLetterInitialized || forceLoad) {
                this.booksByLetterCollection.fetch()
                    .done(deferred.resolve)
                    .fail(deferred.reject)
                    .always(_.bind(function() {
                        this.booksByLetterInitialized = true;
                    }, this));
            } else {
                deferred.resolve();
            }

            return deferred;
        },

        /**
         * Load (or reload) the global count and books data.
         * @return Promise
         **/
        updateLibraryMetadata: function() {
            var deferred = $.Deferred();

            if (this.metadataUpToDate) {
                deferred.resolve();
            } else {
                $.when(
                    this.globalCountModel.fetch(),
                    this.bookCollection.fetch()
                ).then(_.bind(function() {
                        this.metadataUpToDate = true;
                        deferred.resolve();
                    }, this),<commit_msg>Reload spine collection as needed<commit_after>"use strict";
/**
 * Application logic.
 */
var $ = require("jquery"),
    _ = require("underscore"),
    Backbone = require("backbone"),
    Handlebars = require("handlebars"),
    RegisterHandlebarHelpers = require("./handlebarhelpers.js"),
    appSettings = require("./settings.js"),
    NavbarView = require("./views/NavbarView.js"),
    LoginPageView = require("./views/LoginPageView.js"),
    MainPageView = require("./views/MainPageView.js"),
    BooksPageView = require("./views/BooksPageView.js"),
    BookPageView = require("./views/BookPageView.js"),
    AppConfigurationModel = require("./models/Configuration.js"),
    EditBookPageView = require("./views/EditBookPageView.js"),
    GlobalCountModel = require("./models/GlobalCount.js"),
    BookCollection = require("./models/BookCollection.js"),
    BooksByLetterCollection = require("./models/BooksByLetterCollection.js"),
    SpineCollection = require("./models/SpineCollection.js"),
    TagCollection = require("./models/TagCollection.js"),
    BookModel = require("./models/Book.js"),
    HeaderIconsTemplate = require("./views/templates/headericons.html"),
    HeaderMenuTemplate = require("./views/templates/headermenu.html"),
    appevents = require("./appevents.js"),
    appsetup = require("./appsetup.js");

var app = {
    // Catalog: all metadata regarding the library.
    // Typically, these data will change only when a books is added/edited/deleted.
    catalog: {
        spinesInitialized: false,
        booksByLetterInitialized: false,
        metadataUpToDate: false,
        spineCollection: new SpineCollection(),
        booksByLetterCollection: new BooksByLetterCollection(),
        globalCountModel: new GlobalCountModel(),
        bookCollection: new BookCollection(),
        tagCollection: new TagCollection(),
        /**
         * Load the spines collection, fetching only when necessary.
         **/
        loadSpines: function(forceLoad) {
            var deferred = $.Deferred();
            if (!this.spinesInitialized || forceLoad) {
                this.spineCollection.fetch()
                    .done(function() {
                        deferred.resolve();
                    })
                    .fail(function() {
                        deferred.reject();
                    })
                    .always(_.bind(function() {
                        this.spinesInitialized = true;
                    }, this));
            } else {
                deferred.resolve();
            }

            return deferred;
        },
        /**
         * Load the books-by-letter collection, fetching only when necessary.
         **/
        loadBooksByLetter: function(forceLoad) {
            var deferred = $.Deferred();
            if (!this.booksByLetterInitialized || forceLoad) {
                this.booksByLetterCollection.fetch()
                    .done(deferred.resolve)
                    .fail(deferred.reject)
                    .always(_.bind(function() {
                        this.booksByLetterInitialized = true;
                    }, this));
            } else {
                deferred.resolve();
            }

            return deferred;
        },

        /**
         * Load (or reload) the global count and books data.
         * @return Promise
         **/
        updateLibraryMetadata: function() {
            var deferred = $.Deferred();

            if (this.metadataUpToDate) {
                deferred.resolve();
            } else {
                $.when(
                    this.globalCountModel.fetch(),
                    this.bookCollection.fetch(),
                    this.spineCollection.fetch()
                ).then(_.bind(function() {
                        this.metadataUpToDate = true;
                        deferred.resolve();
                    }, this),
{'fraction_non_alphanumeric': 0.12324310255075481, 'fraction_numerical': 0.0, 'mean_word_length': 1.8129575402635432, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '864356', 'n_tokens_mistral': 1939, 'n_tokens_neox': 1849, 'n_words': 352}