<commit_before>/*
 *     Copyright 2012-2015 (c) CoNWeT Lab., Universidad Politécnica de Madrid
 *
 *     This file is part of Wirecloud Platform.
 *
 *     Wirecloud Platform is free software: you can redistribute it and/or
 *     modify it under the terms of the GNU Affero General Public License as
 *     published by the Free Software Foundation, either version 3 of the
 *     License, or (at your option) any later version.
 *
 *     Wirecloud is distributed in the hope that it will be useful, but WITHOUT
 *     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 *     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
 *     License for more details.
 *
 *     You should have received a copy of the GNU Affero General Public License
 *     along with Wirecloud Platform.  If not, see
 *     <http://www.gnu.org/licenses/>.
 *
 */

/*global gettext, LayoutManagerFactory, StyledElements, Wirecloud*/

(function () {

    "use strict";

    var UploadWindowMenu, upload_wgt_files, acceptListener, updateEmptyStatus, onUploadSuccess;

    /*************************************************************************
     *                            Private methods                            *
     *************************************************************************/

    onUploadSuccess = function onUploadSuccess() {
        this.mainview.viewsByName.search.mark_outdated();
    };

    upload_wgt_files = function upload_wgt_files() {
        var monitor, entries, count, failures, onComplete, onUploadFailure;

        monitor = LayoutManagerFactory.getInstance()._startComplexTask(gettext("Uploading packaged components"), 1);
        entries = this.fileTable.source.elements;
        count = entries.length;
        failures = [];

        onComplete = function () {
            if (--count === 0) {
                var layoutManager = LayoutManagerFactory.getInstance();
                layoutManager._notifyPlatformReady();
                if (failures.length > 0) {
                    var msg = document.createElement('p');
                    msg.textContent = gettext('Error uploading the following components:');
                    var details = document.createElement('ul');
                    for (var i = 0; i < failures.length; i++) {
                        var item = document.createElement('li');
                        var file_name = document.createElement('b');
                        file_name.textContent = failures[i].file;
                        item.appendChild(file_name);

                        var error_description = document.createTextNode(": " + failures[i].msg);
                        item.appendChild(error_description);

                        details.appendChild(item);
                    }
                    msg = new StyledElements.Fragment([msg, details]);
                    (new Wirecloud.ui.MessageWindowMenu(msg, Wirecloud.constants.LOGGING.ERROR_MSG)).show();
                }
            }
        };

        onUploadFailure = function onUploadFailure(file_entry, msg) {
            failures.push({'file': file_entry.name, 'msg': msg});
        };

        for (var i = 0; i < entries.length; i++) {
            this.catalogue.addPackagedResource(entries[i].file, {
                force_create: true,
                monitor: monitor,
                onSuccess: onUploadSuccess.bind(this),
                onFailure: onUploadFailure.bind(this, entries[i]),
                onComplete: onComplete
            });
        }
        this.fileTable.source.changeElements([]);
        updateEmptyStatus.call(this);
    };

    acceptListener = function acceptListener() {
        upload_wgt_files.call(this);
        this.hide();
    };

    updateEmptyStatus = function updateEmptyStatus() {
        var empty = this.fileTable.source.elements.length === 0;
        this.acceptButton.setDisabled(empty);
        if (empty) {
            this.htmlElement.classList.add('wc-upload-mac-dialog-empty');
        } else {
            this.htmlElement.classList.remove('wc-upload-mac-dialog-empty');<commit_msg>Refresh local catalogue view after uploading resources<commit_after>/*
 *     Copyright 2012-2015 (c) CoNWeT Lab., Universidad Politécnica de Madrid
 *
 *     This file is part of Wirecloud Platform.
 *
 *     Wirecloud Platform is free software: you can redistribute it and/or
 *     modify it under the terms of the GNU Affero General Public License as
 *     published by the Free Software Foundation, either version 3 of the
 *     License, or (at your option) any later version.
 *
 *     Wirecloud is distributed in the hope that it will be useful, but WITHOUT
 *     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 *     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
 *     License for more details.
 *
 *     You should have received a copy of the GNU Affero General Public License
 *     along with Wirecloud Platform.  If not, see
 *     <http://www.gnu.org/licenses/>.
 *
 */

/*global gettext, LayoutManagerFactory, StyledElements, Wirecloud*/

(function () {

    "use strict";

    var UploadWindowMenu, upload_wgt_files, acceptListener, updateEmptyStatus, onUploadSuccess;

    /*************************************************************************
     *                            Private methods                            *
     *************************************************************************/

    onUploadSuccess = function onUploadSuccess() {
        this.mainview.viewsByName.search.mark_outdated();
    };

    upload_wgt_files = function upload_wgt_files() {
        var monitor, entries, count, failures, onComplete, onUploadFailure;

        monitor = LayoutManagerFactory.getInstance()._startComplexTask(gettext("Uploading packaged components"), 1);
        entries = this.fileTable.source.elements;
        count = entries.length;
        failures = [];

        onComplete = function () {
            if (--count === 0) {
                var layoutManager = LayoutManagerFactory.getInstance();
                layoutManager._notifyPlatformReady();
                if (failures.length > 0) {
                    var msg = document.createElement('p');
                    msg.textContent = gettext('Error uploading the following components:');
                    var details = document.createElement('ul');
                    for (var i = 0; i < failures.length; i++) {
                        var item = document.createElement('li');
                        var file_name = document.createElement('b');
                        file_name.textContent = failures[i].file;
                        item.appendChild(file_name);

                        var error_description = document.createTextNode(": " + failures[i].msg);
                        item.appendChild(error_description);

                        details.appendChild(item);
                    }
                    msg = new StyledElements.Fragment([msg, details]);
                    (new Wirecloud.ui.MessageWindowMenu(msg, Wirecloud.constants.LOGGING.ERROR_MSG)).show();
                }
                this.mainview.viewsByName.search.refresh_if_needed();
            }
        };

        onUploadFailure = function onUploadFailure(file_entry, msg) {
            failures.push({'file': file_entry.name, 'msg': msg});
        };

        for (var i = 0; i < entries.length; i++) {
            this.catalogue.addPackagedResource(entries[i].file, {
                force_create: true,
                monitor: monitor,
                onSuccess: onUploadSuccess.bind(this),
                onFailure: onUploadFailure.bind(this, entries[i]),
                onComplete: onComplete.bind(this)
            });
        }
        this.fileTable.source.changeElements([]);
        updateEmptyStatus.call(this);
    };

    acceptListener = function acceptListener() {
        upload_wgt_files.call(this);
        this.hide();
    };

    updateEmptyStatus = function updateEmptyStatus() {
        var empty = this.fileTable.source.elements.length === 0;
        this.acceptButton.setDisabled(empty);
        if (empty) {
            this.htmlElement.classList.add('wc-upload-mac-dialog-empty');
        } else {
            this.htmlElement.classList.remove('wc-upload-mac-dialog-empty');
{'fraction_non_alphanumeric': 0.1295187933923869, 'fraction_numerical': 0.0035910940866650705, 'mean_word_length': 2.1421587062805565, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7395771', 'n_tokens_mistral': 2078, 'n_tokens_neox': 1968, 'n_words': 522}