<commit_before>module App {
    import NotifyType = csComp.Services.NotifyType;
    angular
        .module('csWebApp')
        .directive('simList', [function (): ng.IDirective {
            return {
                templateUrl: 'app/simlist/simlist.directive.html',
                restrict: 'E',
                scope: {
                    webserviceUrl: '@simWebserviceUrl',
                    simulation: '@simName',
                    version: '@simVersion'
                },
                controller: SimListController,
                controllerAs: 'vm',
                bindToController: true
            };
        }]);

    export interface ISimListParameters {
        webserviceUrl: string;
        simulation: string;
        version: string;
    }

    export class SimListController {

        private webserviceUrl: string;
        private simulation: string;
        private version: string;
        private tasks: ITask[];
        private status: string;
        private parameters: ISimListParameters;

        public static $inject = ['SimWebService', 'messageBusService', '$interval', '$scope', '$log', 'SimTaskService'];

        constructor(private SimWebService: App.SimWebService,
                    private messageBusService: csComp.Services.MessageBusService,
                    private $interval: ng.IIntervalService,
                    private $scope: ng.IScope,
                    private $log: ng.ILogService,
                    private SimTaskService: App.SimTaskService) {

            if ($scope.$parent.hasOwnProperty('widget') && $scope.$parent['widget'].hasOwnProperty('parameters')) {
                this.parameters = $scope.$parent['widget']['parameters'];
            }
            if (!this.webserviceUrl) {
                if (this.parameters.hasOwnProperty('webserviceUrl')) {
                    this.webserviceUrl = this.parameters.webserviceUrl;
                } else {
                    $log.error('SimCityDirective.SimListController: no URL provided');
                    return;
                }
            }

            if (!this.simulation) {
                if (this.parameters.hasOwnProperty('simulation')) {
                    this.simulation = this.parameters.simulation;
                } else {
                    $log.error('SimCityDirective.SimListController: No simulation provided');
                    return;
                }
            }

            if (!this.version) {
                if (this.parameters.hasOwnProperty('version')) {
                    this.version = this.parameters.version;
                } else {
                    $log.error('SimCityDirective.SimListController: No simulation version provided');
                    return;
                }
            }

            this.updateView();
            this.messageBusService.subscribe('sim-task', this.updateView);
            this.$interval(this.updateView, 100000);
            this.tasks = [];
        }

        /**
         * Callback function for when the view may be updated.
         * @see http://stackoverflow.com/questions/12756423/is-there-an-alias-for-this-in-typescript
         * @see http://stackoverflow.com/questions/20627138/typescript-this-scoping-issue-when-called-in-jquery-callback
         * @todo notice the strange syntax, which is to preserve the this reference!
         */
        public updateView = (): ng.IPromise<void> => {
            return this.SimWebService.list(this.webserviceUrl, this.simulation, this.version)
                .then((response: ng.IHttpPromiseCallbackArg<ISimWebList<ITask>>) => {<commit_msg>Fixed messageBusSubscription for simlist widget persisting<commit_after>module App {
    import NotifyType = csComp.Services.NotifyType;
    import MessageBusHandle = csComp.Services.MessageBusHandle;

    angular
        .module('csWebApp')
        .directive('simList', [function (): ng.IDirective {
            return {
                templateUrl: 'app/simlist/simlist.directive.html',
                restrict: 'E',
                scope: {
                    webserviceUrl: '@simWebserviceUrl',
                    simulation: '@simName',
                    version: '@simVersion'
                },
                controller: SimListController,
                controllerAs: 'vm',
                bindToController: true
            };
        }]);

    export interface ISimListParameters {
        webserviceUrl: string;
        simulation: string;
        version: string;
    }

    export class SimListController {

        private webserviceUrl: string;
        private simulation: string;
        private version: string;
        private tasks: ITask[];
        private status: string;
        private parameters: ISimListParameters;
        private subscriptions: MessageBusHandle[];

        public static $inject = ['SimWebService', 'messageBusService', '$interval', '$scope', '$log', 'SimTaskService'];

        constructor(private SimWebService: App.SimWebService,
                    private messageBusService: csComp.Services.MessageBusService,
                    private $interval: ng.IIntervalService,
                    private $scope: ng.IScope,
                    private $log: ng.ILogService,
                    private SimTaskService: App.SimTaskService) {

            if ($scope.$parent.hasOwnProperty('widget') && $scope.$parent['widget'].hasOwnProperty('parameters')) {
                this.parameters = $scope.$parent['widget']['parameters'];
            }
            if (!this.webserviceUrl) {
                if (this.parameters.hasOwnProperty('webserviceUrl')) {
                    this.webserviceUrl = this.parameters.webserviceUrl;
                } else {
                    $log.error('SimCityDirective.SimListController: no URL provided');
                    return;
                }
            }

            if (!this.simulation) {
                if (this.parameters.hasOwnProperty('simulation')) {
                    this.simulation = this.parameters.simulation;
                } else {
                    $log.error('SimCityDirective.SimListController: No simulation provided');
                    return;
                }
            }

            if (!this.version) {
                if (this.parameters.hasOwnProperty('version')) {
                    this.version = this.parameters.version;
                } else {
                    $log.error('SimCityDirective.SimListController: No simulation version provided');
                    return;
                }
            }

            this.updateView();
            this.subscriptions = [];
            this.subscriptions.push(this.messageBusService.subscribe('sim-task', this.updateView));
            this.$interval(this.updateView, 100000);
            this.tasks = [];
        }

        /**
         * When the widget is stopped, unsubscribe from the messageBusService
         *
         * The widget is stopped when the dashboard is switched
         */
        public stop() {
            this.subscriptions.forEach((handle: MessageBusHandle) => {
                this.messageBusService.unsubscribe(handle);
            });
            this.subscriptions = [];
        }

        /**
         * Callback function for when the view may be updated.
         * @see http://stackoverflow.com/questions/12756423/is-there-an-alias-for-this-in-typescript
         * @see http://stackoverflow.com/questions/20627138/typescript-this-scoping-issue-when-called-in-jquery-callback
         * @todo notice the strange syntax, which is to preserve the this reference!
         */
        public updateView = (): ng.IPromise<void> => {
            return this.SimWebService.list(this.webserviceUrl, this.simulation, this.version)
                .then((response: ng.IHttpPromiseCallbackArg<ISimWebList<ITask>>) => {
{'fraction_non_alphanumeric': 0.1040152963671128, 'fraction_numerical': 0.005608667941363926, 'mean_word_length': 1.7395251396648044, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 14, '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': '6526481', 'n_tokens_mistral': 1964, 'n_tokens_neox': 1859, 'n_words': 370}