<commit_before>'use strict';

angular.module('sparks').controller('SparksController', ['$scope', 'Authentication', 'Sparks', '$mdDialog',
	function($scope, Authentication, Sparks, $mdDialog) {
		
		/**
         * Spark Dialog
         */
        function sparkDialog($event) {
          // Must be logged in to create Sparks
          if (self.authentication.user){
            $mdDialog.show({
              controller: DialogController,
              template: '<md-dialog aria-label="Form"> <md-content class="md-padding"> <form name="sparkForm"> <div layout layout-sm="column"> <md-input-container flex> <label>Spark Name</label> <input ng-model="spark.name"> </md-input-container> <md-input-container flex> <label>Application</label> <input ng-model="spark.application"> </md-input-container> </div> <md-input-container flex> <label>Repository URL</label> <input ng-model="spark.repositoryUrl"> </md-input-container> <md-input-container flex> <label>Description</label> <textarea ng-model="spark.description" columns="1" md-maxlength="150"></textarea> </md-input-container> </form> </md-content> <div class="md-actions" layout="row"> <span flex></span> <md-button ng-click="cancel()"> Cancel </md-button> <md-button ng-click="save()" class="md-primary"> Save </md-button> </div></md-dialog>',
              targetEvent: $event,
              clickOutsideToClose: true
            })
            .then(function() {
              // Saving Spark
              $mdDialog.hide();
            }, function() {
              // Cancelled
            });
          }
          else{
            // Ask user to log in
            var loginRequiredAlert = $mdDialog.alert()
              .title('Oops!')
              .content('You must be logged in to create new Sparks :-)')
              .clickOutsideToClose(true)
              .ok('Close');

            $mdDialog
              .show( loginRequiredAlert )
              .finally(function() {
                loginRequiredAlert = undefined;
              });
          }
        };

        /**
         * Dialog Controller
         */
        function DialogController($scope, $mdDialog) {
          
          $scope.cancel = function() {
            $mdDialog.cancel();
          };

          $scope.save = function() {
            var spark = new Sparks ($scope.spark);
            spark.$save(function(response) {
            	// Success
            }, function(errorResponse) {
            	// Error
            });
          };
        };

        var self = this;
        self.authentication     = Authentication;
        self.sparkDialog 		= sparkDialog;

	}
]);<commit_msg>Display error message to user upon invalid spark creation error to close #20<commit_after>'use strict';

angular.module('sparks').controller('SparksController', ['$scope', 'Authentication', 'Sparks', '$mdDialog',
	function($scope, Authentication, Sparks, $mdDialog) {
		
		/**
         * Spark Dialog
         */

        var loginRequiredAlert = $mdDialog.alert()
              .title('Oops!')
              .content('You must be logged in to create new Sparks :-)')
              .clickOutsideToClose(true)
              .ok('Close');
        
        var saveErrorAlert = function(errorMessage) {
            return $mdDialog.alert()
              .title('Oops!')
              .content(errorMessage)
              .clickOutsideToClose(true)
              .ok('Close');
        };

        function sparkDialog($event) {
          // Must be logged in to create Sparks
          if (self.authentication.user){
            $mdDialog.show({
              controller: DialogController,
              template: '<md-dialog aria-label="Form"> <md-content class="md-padding"> <form name="sparkForm"> <div layout layout-sm="column"> <md-input-container flex> <label>Spark Name</label> <input ng-model="spark.name"> </md-input-container> <md-input-container flex> <label>Application</label> <input ng-model="spark.application"> </md-input-container> </div> <md-input-container flex> <label>Repository URL</label> <input ng-model="spark.repositoryUrl"> </md-input-container> <md-input-container flex> <label>Description</label> <textarea ng-model="spark.description" columns="1" md-maxlength="150"></textarea> </md-input-container> </form> </md-content> <div class="md-actions" layout="row"> <span flex></span> <md-button ng-click="cancel()"> Cancel </md-button> <md-button ng-click="save()" class="md-primary"> Save </md-button> </div></md-dialog>',
              targetEvent: $event,
              clickOutsideToClose: true
            })
            .then(function() {
              // Saving Spark
              $mdDialog.hide();
            }, function() {
              // Cancelled
            });
          }
          else{
            // Ask user to log in
            
            $mdDialog
              .show( loginRequiredAlert );
          }
        };

        /**
         * Dialog Controller
         */
        function DialogController($scope, $mdDialog) {
          
          $scope.cancel = function() {
            $mdDialog.cancel();
          };

          $scope.save = function() {
            var spark = new Sparks ($scope.spark);
            spark.$save(function(response) {
            	// Success
            }, function(errorResponse) {
            	// Error
              $mdDialog
                .show( saveErrorAlert(errorResponse.data.message) );
            });
          };
        };

        var self = this;
        self.authentication     = Authentication;
        self.sparkDialog 		= sparkDialog;

	}
]);
{'fraction_non_alphanumeric': 0.1464682681964862, 'fraction_numerical': 0.0017927572606669057, 'mean_word_length': 1.9072433559145388, 'pattern_counts': {'":': 0, '<': 77, '<?xml version=': 0, '>': 77, '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': '4822296', 'n_tokens_mistral': 1512, 'n_tokens_neox': 1456, 'n_words': 313}