<commit_before>define(['jquery', 'backbone', 'underscore', 'app', 'models/TreeCollection',
    'views/packageView', 'views/fileView', 'views/selectionView', 'views/actionbarView'],
    function($, Backbone, _, App, TreeCollection, packageView, fileView, selectionView, actionbarView) {

        // Renders whole dashboard
        return Backbone.View.extend({

            el: '#content',

            events: {
            },

            // <ul> holding the packages
            packageUL: null,
            // <ul> displaying the files
            fileUL: null,
            // Current open files
            files: null,
            // True when loading animation is running
            isLoading: false,

            initialize: function() {
                var self = this;
                this.tree = new TreeCollection();

                var view = new selectionView(this.tree);
                view = new actionbarView();

                // When package is added we reload the data
                App.vent.on('package:added', function() {
                    console.log('Package tree caught, package:added event');
                    self.tree.fetch();
                });

                // TODO file:added

                App.vent.on('dashboard:loading', _.bind(this.loading, this));
                App.vent.on('dashboard:contentReady', _.bind(this.contentReady, this));
            },

            init: function() {
                var self = this;

                // TODO: put in separated function
                // TODO: order of elements?
                // Init the tree and callback for package added
                this.tree.fetch({success: function() {
                    self.render();
                    self.tree.get('packages').on('add', function(pack) {
                        console.log('Package ' + pack.get('pid') + ' added to tree');
                        self.appendPackage(pack, 0, true);

                    });
                }});
            },

            render: function() {
                console.log('Render package list');
                var packs = this.tree.get('packages');
                this.files = this.tree.get('files');

                this.packageUL = this.$('.package-list');
                packs.each(_.bind(this.appendPackage, this));

                this.fileUL = this.$('.file-list');
                if (this.files.length === 0)
                    this.fileUL.append($('<li>No package selected</li>'));
                else
                    this.files.each(_.bind(this.appendFile, this));

                return this;
            },

            // TODO sorting ?!
            // Append a package to the list, index, animate it
            appendPackage: function(pack, i, animation) {
                var el = new packageView({model: pack}).render().el;
                this.packageUL.appendWithAnimation(el, animation);
            },

            appendFile: function(file, i, animation) {
                var el = new fileView({model: file}).render().el;
                this.fileUL.appendWithAnimation(el, animation);
            },

            contentReady: function(files) {
                this.files = files;
                // show the files when no loading animation is running
                if (!this.isLoading && this.files !== files)
                    this.show();
            },

            loading: function(model) {
                // nothing to load when it is already open
                if (model && this.files === model.get('files'))
                    return;

                this.isLoading = true;
                this.files = null;
                var self = this;
                // Render when the files are already set
                this.fileUL.fadeOut({complete: function() {
                    if (self.files)
                        self.show();

                    self.isLoading = false;
                }});
            },

            failure: function() {
                // TODO
            },

            show: function() {
                this.fileUL.empty();
                this.files.each(_.bind(this.appendFile, this));
                this.fileUL.fadeIn();
                App.vent.trigger('dashboard:show', this.files);
            },
        });
    });<commit_msg>fixed showing files after deletion of package<commit_after>define(['jquery', 'backbone', 'underscore', 'app', 'models/TreeCollection',
    'views/packageView', 'views/fileView', 'views/selectionView', 'views/actionbarView'],
    function($, Backbone, _, App, TreeCollection, packageView, fileView, selectionView, actionbarView) {

        // Renders whole dashboard
        return Backbone.View.extend({

            el: '#content',

            events: {
            },

            // <ul> holding the packages
            packageUL: null,
            // <ul> displaying the files
            fileUL: null,
            // Current open files
            files: null,
            // True when loading animation is running
            isLoading: false,

            initialize: function() {
                var self = this;
                this.tree = new TreeCollection();

                var view = new selectionView(this.tree);
                view = new actionbarView();

                // When package is added we reload the data
                App.vent.on('package:added', function() {
                    console.log('Package tree caught, package:added event');
                    self.tree.fetch();
                });

                // TODO file:added

                App.vent.on('dashboard:loading', _.bind(this.loading, this));
                App.vent.on('dashboard:contentReady', _.bind(this.contentReady, this));
            },

            init: function() {
                var self = this;

                // TODO: put in separated function
                // TODO: order of elements?
                // Init the tree and callback for package added
                this.tree.fetch({success: function() {
                    self.render();
                    self.tree.get('packages').on('add', function(pack) {
                        console.log('Package ' + pack.get('pid') + ' added to tree');
                        self.appendPackage(pack, 0, true);

                    });
                }});
            },

            render: function() {
                console.log('Render package list');
                var packs = this.tree.get('packages');
                this.files = this.tree.get('files');

                this.packageUL = this.$('.package-list');
                packs.each(_.bind(this.appendPackage, this));

                this.fileUL = this.$('.file-list');
                if (this.files.length === 0)
                    this.fileUL.append($('<li>No package selected</li>'));
                else
                    this.files.each(_.bind(this.appendFile, this));

                return this;
            },

            // TODO sorting ?!
            // Append a package to the list, index, animate it
            appendPackage: function(pack, i, animation) {
                var el = new packageView({model: pack}).render().el;
                this.packageUL.appendWithAnimation(el, animation);
            },

            appendFile: function(file, i, animation) {
                var el = new fileView({model: file}).render().el;
                this.fileUL.appendWithAnimation(el, animation);
            },

            contentReady: function(files) {
                // show the files when no loading animation is running and not already open
                if (!this.isLoading && this.files !== files) {
                    this.files = files;
                    this.show();
                } else
                    this.files = files;
            },

            // TODO: better state control of dashboard
            loading: function(model) {
                // nothing to load when it is already open, or nothing is shown
                if (!this.files || (model && this.files === model.get('files')))
                    return;

                this.isLoading = true;
                this.files = null;
                var self = this;
                // Render when the files are already set
                this.fileUL.fadeOut({complete: function() {
                    if (self.files)
                        self.show();

                    self.isLoading = false;
                }});
            },

            failure: function() {
                // TODO
            },

            show: function() {
                this.fileUL.empty();
                this.files.each(_.bind(this.appendFile, this));
                this.fileUL.fadeIn();
                App.vent.trigger('dashboard:show', this.files);
            }
        });
    });
{'fraction_non_alphanumeric': 0.11860570393843368, 'fraction_numerical': 0.0004526935264825713, 'mean_word_length': 1.289378238341969, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '7381028', 'n_tokens_mistral': 2191, 'n_tokens_neox': 2008, 'n_words': 522}