<commit_before>﻿(function () {
    'use strict';

    angular
        .module('GVA.Creation')
        .factory('ManageService', ManageService);


    ManageService.$inject = ['$location', '$http', '$routeParams', '$localStorage', '$q'];

    function ManageService($location, $http, $routeParams, $localStorage, $q) {
        var self = this;

        var observerCallbacks = [];

        var notifyObservers = function () {
            angular.forEach(observerCallbacks, function (callback) {
                callback();
            });
        };

        self.poll = null;

        self.registerPollObserver = function (callback) {

            if (self.poll === null) {
                self.getPoll($routeParams.manageId);
            }

            observerCallbacks.push(callback);
        };

        self.getPoll = function (manageId, callback, failureCallback) {

            if (!manageId) {
                return null;
            }

            $http.get('/api/manage/' + manageId)
                .success(function (data) {
                    self.poll = data;
                    notifyObservers();
                    if (callback) {
                        callback(data);
                    }
                })
                .error(function (data, status) {
                    if (failureCallback) {
                        failureCallback(data, status);
                    }
                });
        };

        self.updatePollExpiry = function (manageId, expiryDate, callback, failureCallback) {
            $http({
                method: 'PUT',
                url: '/api/manage/' + manageId + '/expiry/',
                data: { ExpiryDate: expiryDate }
            })
            .success(function (data) {
                if (callback) {
                    callback(data);
                }
            })
            .error(function (data, status) {
                if (failureCallback) {
                    failureCallback(data, status);
                }
            });
        };

        self.updatePollType = function (manageId, pollTypeConfig, callback, failureCallback) {
            $http({
                method: 'PUT',
                url: '/api/manage/' + manageId + '/pollType/',
                data: pollTypeConfig
            })
            .success(function (data) {
                if (callback) {
                    callback(data);
                }
            })
            .error(function (data, status) {
                if (failureCallback) {
                    failureCallback(data, status);
                }
            });
        };

        self.updateQuestion = function (manageId, question, callback, failureCallback) {
            $http({
                method: 'PUT',
                url: '/api/manage/' + manageId + '/question/',
                data: { Question: question }
            })
            .success(function (data) {
                if (callback) {
                    callback(data);
                }
            })
            .error(function (data, status) {
                if (failureCallback) {
                    failureCallback(data, status);
                }
            });
        };
        
        self.updatePollMisc = function (manageId, miscConfig, callback, failureCallback) {
            $http({
                method: 'PUT',
                url: '/api/manage/' + manageId + '/misc/',
                data: miscConfig
            })
            .success(function (data) {
                if (callback) {
                    callback(data);
                }
            })
            .error(function (data, status) {
                if (failureCallback) {
                    failureCallback(data, status);
                }
            });
        };

        self.getVotes = function (pollId, callback, failureCallback) {

            $http.get('/api/poll/' + pollId + '/vote')
                .success(function (data) {
                    if (callback) {
                        callback(data);
                    }
                })
                .error(function (data, status) {
                    if (failureCallback) {
                        failureCallback(data, status);
                    }
                });
        };

        self.getVoters = function (manageId) {
            var deferred = $q.defer();

            $http
                .get('/api/manage/' + manageId + '/voters')
                .success(function (data) { deferred.resolve(data); });

            return deferred.promise;
        };

        self.deleteVoters = function (manageId, votersToRemove) {
            var deferred = $q.defer();
<commit_msg>Manage page now uses the results page to get ballots for a poll.<commit_after>﻿(function () {
    'use strict';

    angular
        .module('GVA.Creation')
        .factory('ManageService', ManageService);


    ManageService.$inject = ['$location', '$http', '$routeParams', '$localStorage', '$q'];

    function ManageService($location, $http, $routeParams, $localStorage, $q) {
        var self = this;

        var observerCallbacks = [];

        var notifyObservers = function () {
            angular.forEach(observerCallbacks, function (callback) {
                callback();
            });
        };

        self.poll = null;

        self.registerPollObserver = function (callback) {

            if (self.poll === null) {
                self.getPoll($routeParams.manageId);
            }

            observerCallbacks.push(callback);
        };

        self.getPoll = function (manageId, callback, failureCallback) {

            if (!manageId) {
                return null;
            }

            $http.get('/api/manage/' + manageId)
                .success(function (data) {
                    self.poll = data;
                    notifyObservers();
                    if (callback) {
                        callback(data);
                    }
                })
                .error(function (data, status) {
                    if (failureCallback) {
                        failureCallback(data, status);
                    }
                });
        };

        self.updatePollExpiry = function (manageId, expiryDate, callback, failureCallback) {
            $http({
                method: 'PUT',
                url: '/api/manage/' + manageId + '/expiry/',
                data: { ExpiryDate: expiryDate }
            })
            .success(function (data) {
                if (callback) {
                    callback(data);
                }
            })
            .error(function (data, status) {
                if (failureCallback) {
                    failureCallback(data, status);
                }
            });
        };

        self.updatePollType = function (manageId, pollTypeConfig, callback, failureCallback) {
            $http({
                method: 'PUT',
                url: '/api/manage/' + manageId + '/pollType/',
                data: pollTypeConfig
            })
            .success(function (data) {
                if (callback) {
                    callback(data);
                }
            })
            .error(function (data, status) {
                if (failureCallback) {
                    failureCallback(data, status);
                }
            });
        };

        self.updateQuestion = function (manageId, question, callback, failureCallback) {
            $http({
                method: 'PUT',
                url: '/api/manage/' + manageId + '/question/',
                data: { Question: question }
            })
            .success(function (data) {
                if (callback) {
                    callback(data);
                }
            })
            .error(function (data, status) {
                if (failureCallback) {
                    failureCallback(data, status);
                }
            });
        };
        
        self.updatePollMisc = function (manageId, miscConfig, callback, failureCallback) {
            $http({
                method: 'PUT',
                url: '/api/manage/' + manageId + '/misc/',
                data: miscConfig
            })
            .success(function (data) {
                if (callback) {
                    callback(data);
                }
            })
            .error(function (data, status) {
                if (failureCallback) {
                    failureCallback(data, status);
                }
            });
        };

        self.getVotes = function (pollId, callback, failureCallback) {

            $http.get('/api/poll/' + pollId + '/results')
                .success(function (data) {
                    if (callback) {
                        callback(data);
                    }
                })
                .error(function (data, status) {
                    if (failureCallback) {
                        failureCallback(data, status);
                    }
                });
        };

        self.getVoters = function (manageId) {
            var deferred = $q.defer();

            $http
                .get('/api/manage/' + manageId + '/voters')
                .success(function (data) { deferred.resolve(data); });

            return deferred.promise;
        };

        self.deleteVoters = function (manageId, votersToRemove) {
            var deferred = $q.defer();

{'fraction_non_alphanumeric': 0.11622198505869798, 'fraction_numerical': 0.0, 'mean_word_length': 1.11917684305744, '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': '4557255', 'n_tokens_mistral': 2393, 'n_tokens_neox': 2173, 'n_words': 450}