<commit_before>/* global Scientilla */

(function () {
    'use strict';


    angular.module('references')
            .component('scientillaDocumentsList', {
                templateUrl: 'partials/scientillaDocumentsList.html',
                controller: scientillaDocumentsList,
                controllerAs: 'vm',
                bindings: {
                    researchEntity: "=",
                    editable: "<"
                }
            });


    scientillaDocumentsList.$inject = [
        '$rootScope',
        'Notification',
        'researchEntityService',
        'documentSearchForm'
    ];

    function scientillaDocumentsList($rootScope, Notification, researchEntityService, documentSearchForm) {
        var vm = this;
        vm.documents = [];

        vm.unverifyDocument = unverifyDocument;

        vm.getData = getDocuments;
        vm.onFilter = refreshList;

        vm.searchForm = documentSearchForm;

        var query = {};

        activate();

        function activate() {
            $rootScope.$on('draft.verified', updateList);
        }

        function getDocuments(q) {
            query = q;
            return researchEntityService.getDocuments(vm.researchEntity, query);
        }

        function unverifyDocument(reference) {
            vm.researchEntity
                    .one('references', reference.id)
                    .remove()
                    .then(function (documents) {
                        Notification.success("Document succesfully unverified");
                        updateList(documents);
                    })
                    .catch(function () {
                        Notification.warning("Failed to unverify document");
                    });
        }

        function refreshList(documents) {
            Scientilla.toDocumentsCollection(documents);
            vm.documents = documents;
        }

        //private
        function updateList() {
            getDocuments(query).then(refreshList);
        }
    }

})();<commit_msg>Added confirm modal on unverify action<commit_after>/* global Scientilla */

(function () {
    'use strict';


    angular.module('references')
            .component('scientillaDocumentsList', {
                templateUrl: 'partials/scientillaDocumentsList.html',
                controller: scientillaDocumentsList,
                controllerAs: 'vm',
                bindings: {
                    researchEntity: "=",
                    editable: "<"
                }
            });


    scientillaDocumentsList.$inject = [
        '$rootScope',
        'Notification',
        'researchEntityService',
        'documentSearchForm',
        'ModalService'
    ];

    function scientillaDocumentsList($rootScope, Notification, researchEntityService, documentSearchForm, ModalService) {
        var vm = this;
        vm.documents = [];

        vm.unverifyDocument = unverifyDocument;

        vm.getData = getDocuments;
        vm.onFilter = refreshList;

        vm.searchForm = documentSearchForm;

        var query = {};

        activate();

        function activate() {
            $rootScope.$on('draft.verified', updateList);
        }

        function getDocuments(q) {
            query = q;
            return researchEntityService.getDocuments(vm.researchEntity, query);
        }

        function unverifyDocument(reference) {
            ModalService
                    .confirm('Unverifying','Do you want to unverify the document?')
                    .then(function () {

                        vm.researchEntity
                                .one('references', reference.id)
                                .remove()
                                .then(function (documents) {
                                    Notification.success("Document succesfully unverified");
                                    updateList(documents);
                                })
                                .catch(function () {
                                    Notification.warning("Failed to unverify document");
                                });

                    });
        }

        function refreshList(documents) {
            Scientilla.toDocumentsCollection(documents);
            vm.documents = documents;
        }

        //private
        function updateList() {
            getDocuments(query).then(refreshList);
        }
    }

})();
{'fraction_non_alphanumeric': 0.09669384057971014, 'fraction_numerical': 0.0, 'mean_word_length': 1.4403314917127072, 'pattern_counts': {'":': 0, '<': 5, '<?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': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3749263', 'n_tokens_mistral': 1073, 'n_tokens_neox': 957, 'n_words': 174}