<commit_before>/* jshint unused: vars */
export default
    [   'templateUrl',
        'Wait',
        'Rest',
        'GetBasePath',
        'ProcessErrors',
        'Prompt',
        '$q',
        function(templateUrl, Wait, Rest, GetBasePath, ProcessErrors, Prompt, $q) {
            return {
                restrict: 'E',
                scope: false,
                templateUrl: templateUrl('job-templates/labels/labelsList'),
                link: function(scope, element, attrs) {
                    scope.seeMoreInactive = true;

                    scope.labels = scope.
                        job_template.summary_fields.labels.results;

                    scope.count = scope.
                        job_template.summary_fields.labels.count;

                    var getNext = function(data, arr, resolve) {
                        Rest.setUrl(data.next);
                        Rest.get()
                            .success(function (data) {
                                if (data.next) {
                                    getNext(data, arr.concat(data.results), resolve);
                                } else {
                                    resolve.resolve(arr.concat(data.results));
                                }
                            });
                    };

                    scope.seeMore = function () {
                        var seeMoreResolve = $q.defer();
                        Rest.setUrl(scope.job_template.related.labels);
                        Rest.get()
                            .success(function(data) {
                                if (data.next) {
                                    getNext(data, data.results, seeMoreResolve);
                                } else {
                                    seeMoreResolve.resolve(data.results);
                                }
                            });

                        seeMoreResolve.promise.then(function (labels) {
                            scope.labels = labels;
                            scope.seeMoreInactive = false;
                        });
                    };

                    scope.deleteLabel = function(templateId, templateName, labelId, labelName) {
                        var action = function () {
                            $('#prompt-modal').modal('hide');
                            Wait('start');
                            var url = GetBasePath("job_templates") + templateId + "/labels/";
                            Rest.setUrl(url);
                            Rest.post({"disassociate": true, "id": labelId})
                                .success(function () {
                                    Wait('stop');
                                    scope.search("job_template");
                                })
                                .error(function (data, status) {
                                    ProcessErrors(scope, data, status, null, { hdr: 'Error!',
                                        msg: 'Could not disacssociate label from JT.  Call to ' + url + ' failed. DELETE returned status: ' + status });
                                });
                        };

                        Prompt({
                            hdr: 'Remove Label from ' + templateName,
                            body: '<div class="Prompt-bodyQuery">Confirm  the removal of the <span class="Prompt-emphasis">' + labelName + '</span> label.</div>',
                            action: action,
                            actionText: 'REMOVE'
                        });
                    };
                }
            };
        }
    ];
<commit_msg>Fixed bug where removing a label from a job template via the list wasn't updating the list without a hard refresh.<commit_after>/* jshint unused: vars */
export default
    [   'templateUrl',
        'Wait',
        'Rest',
        'GetBasePath',
        'ProcessErrors',
        'Prompt',
        '$q',
        function(templateUrl, Wait, Rest, GetBasePath, ProcessErrors, Prompt, $q) {
            return {
                restrict: 'E',
                scope: false,
                templateUrl: templateUrl('job-templates/labels/labelsList'),
                link: function(scope, element, attrs) {
                    scope.seeMoreInactive = true;

                    var getNext = function(data, arr, resolve) {
                        Rest.setUrl(data.next);
                        Rest.get()
                            .success(function (data) {
                                if (data.next) {
                                    getNext(data, arr.concat(data.results), resolve);
                                } else {
                                    resolve.resolve(arr.concat(data.results));
                                }
                            });
                    };

                    scope.seeMore = function () {
                        var seeMoreResolve = $q.defer();
                        Rest.setUrl(scope.job_template.related.labels);
                        Rest.get()
                            .success(function(data) {
                                if (data.next) {
                                    getNext(data, data.results, seeMoreResolve);
                                } else {
                                    seeMoreResolve.resolve(data.results);
                                }
                            });

                        seeMoreResolve.promise.then(function (labels) {
                            scope.labels = labels;
                            scope.seeMoreInactive = false;
                        });
                    };

                    scope.deleteLabel = function(templateId, templateName, labelId, labelName) {
                        var action = function () {
                            $('#prompt-modal').modal('hide');
                            Wait('start');
                            var url = GetBasePath("job_templates") + templateId + "/labels/";
                            Rest.setUrl(url);
                            Rest.post({"disassociate": true, "id": labelId})
                                .success(function () {
                                    Wait('stop');
                                    scope.search("job_template");
                                })
                                .error(function (data, status) {
                                    ProcessErrors(scope, data, status, null, { hdr: 'Error!',
                                        msg: 'Could not disacssociate label from JT.  Call to ' + url + ' failed. DELETE returned status: ' + status });
                                });
                        };

                        Prompt({
                            hdr: 'Remove Label from ' + templateName,
                            body: '<div class="Prompt-bodyQuery">Confirm  the removal of the <span class="Prompt-emphasis">' + labelName + '</span> label.</div>',
                            action: action,
                            actionText: 'REMOVE'
                        });
                    };

                    scope.$watch("job_template.summary_fields.labels.results", function() {
                        // To keep the array of labels fresh, we need to set up a watcher - otherwise, the
                        // array will get set initially and then never be updated as labels are removed
                        scope.labels = scope.job_template.summary_fields.labels.results;
                        scope.count = scope.job_template.summary_fields.labels.count;
                    });
                }
            };
        }
    ];

{'fraction_non_alphanumeric': 0.09534974599452911, 'fraction_numerical': 0.0, 'mean_word_length': 0.8860230901498404, 'pattern_counts': {'":': 4, '<': 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': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '827257', 'n_tokens_mistral': 1690, 'n_tokens_neox': 1597, 'n_words': 340}