<commit_before>/*
 * LICENCE : CloudUnit is available under the Affero Gnu Public License GPL V3 : https://www.gnu.org/licenses/agpl-3.0.html
 *     but CloudUnit is licensed too under a standard commercial license.
 *     Please contact our sales team if you would like to discuss the specifics of our Enterprise license.
 *     If you are not sure whether the GPL is right for you,
 *     you can always test our software under the GPL and inspect the source code before you contact us
 *     about purchasing a commercial license.
 *
 *     LEGAL TERMS : "CloudUnit" is a registered trademark of Treeptik and can't be used to endorse
 *     or promote products derived from this project without prior written permission from Treeptik.
 *     Products or services derived from this software may not be called "CloudUnit"
 *     nor may "Treeptik" or similar confusing terms appear in their names without prior written permission.
 *     For any questions, contact us : <EMAIL>
 */

(function () {
  'use strict';

  /**
   * @ngdoc function
   * @name webuiApp.controller:MainCtrl
   * @description
   * # MainCtrl
   * Controller of the webuiApp
   */
  angular
    .module('webuiApp')
    .directive('dashboard', Dashboard);

  function Dashboard(){
    return {
      restrict: 'E',
      templateUrl: 'scripts/components/dashboard/dashboard.html',
      scope: {},
      controller: [
        '$scope',
        '$interval',
        'ApplicationService',
        'ErrorService',
        DashboardCtrl
      ],
      controllerAs: 'dashboard',
      bindToController: true
    };
  }




  function DashboardCtrl($scope, $interval, ApplicationService, ErrorService) {
    var timer, vm = this;
    vm.applications = [];
    vm.selectedItem = 'All';
    vm.search = '';
    vm.deleteApplication = deleteApplication;
    vm.toggleServer = toggleServer;
    vm.buffer = '';

    update();

    // Polling on refresh
    timer = $interval(function () {
      update();
    }, 2000);


    $scope.$on('$destroy', function () {
      $interval.cancel(timer);
    });

    $scope.$on('app:creating', function(e, data){
      vm.buffer = data;
    });

    $scope.$on('app:create:fail', function(e, data){
      vm.buffer = '';
    });

    /////////////////////////////////////////////

    // Refresh the application list
    function update() {
      ApplicationService.list()
        .then(success)
        .catch(error);

      function success(applications) {

        var newApp = _.find(applications, function(app){
          return app.name === vm.buffer.toLowerCase();
        });

        // display shadow app while new app is being created
        if(vm.buffer){
          if(!newApp){
            applications.push({
              name: vm.buffer,
              status: 'PENDING'
            })
          } else {
            vm.buffer = '';
          }
        }

        vm.applications = applications;
        return vm.applications;
      }

      function error(response) {
        ErrorService.handle(response);
        if(timer){<commit_msg>Update stop pending board with special char<commit_after>/*
 * LICENCE : CloudUnit is available under the Affero Gnu Public License GPL V3 : https://www.gnu.org/licenses/agpl-3.0.html
 *     but CloudUnit is licensed too under a standard commercial license.
 *     Please contact our sales team if you would like to discuss the specifics of our Enterprise license.
 *     If you are not sure whether the GPL is right for you,
 *     you can always test our software under the GPL and inspect the source code before you contact us
 *     about purchasing a commercial license.
 *
 *     LEGAL TERMS : "CloudUnit" is a registered trademark of Treeptik and can't be used to endorse
 *     or promote products derived from this project without prior written permission from Treeptik.
 *     Products or services derived from this software may not be called "CloudUnit"
 *     nor may "Treeptik" or similar confusing terms appear in their names without prior written permission.
 *     For any questions, contact us : <EMAIL>
 */

(function () {
  'use strict';

  /**
   * @ngdoc function
   * @name webuiApp.controller:MainCtrl
   * @description
   * # MainCtrl
   * Controller of the webuiApp
   */
  angular
    .module('webuiApp')
    .directive('dashboard', Dashboard);

  function Dashboard(){
    return {
      restrict: 'E',
      templateUrl: 'scripts/components/dashboard/dashboard.html',
      scope: {},
      controller: [
        '$scope',
        '$interval',
        'ApplicationService',
        'ErrorService',
        DashboardCtrl
      ],
      controllerAs: 'dashboard',
      bindToController: true
    };
  }




  function DashboardCtrl($scope, $interval, ApplicationService, ErrorService) {
    var timer, vm = this;
    vm.applications = [];
    vm.selectedItem = 'All';
    vm.search = '';
    vm.deleteApplication = deleteApplication;
    vm.toggleServer = toggleServer;
    vm.buffer = '';
    
    update();

    // Polling on refresh
    timer = $interval(function () {
      update();
    }, 2000);


    $scope.$on('$destroy', function () {
      $interval.cancel(timer);
    });

    $scope.$on('app:creating', function(e, data){
      vm.buffer = data;
    });

    $scope.$on('app:create:fail', function(e, data){
      vm.buffer = '';
    });

    /////////////////////////////////////////////

    // Refresh the application list
    function update() {
      ApplicationService.list()
        .then(success)
        .catch(error);

      function success(applications) {

        var newApp = _.find(applications, function(app){
          return app.name === vm.buffer.toLowerCase().replace(/[^a-z0-9]/gi,'');
        });

        // display shadow app while new app is being created
        if(vm.buffer){
          if(!newApp){
            applications.push({
              name: vm.buffer,
              status: 'PENDING'
            })
          } else {
            vm.buffer = '';
          }
        }

        vm.applications = applications;
        return vm.applications;
      }

      function error(response) {
        ErrorService.handle(response);
        if(timer){
{'fraction_non_alphanumeric': 0.12224740932642487, 'fraction_numerical': 0.0025906735751295338, 'mean_word_length': 2.2205422314911365, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '1566941', 'n_tokens_mistral': 1676, 'n_tokens_neox': 1633, 'n_words': 513}