<commit_before>define(['logManager', 'js/NodePropertyNames', 'text!./ConstraintManager.html'], 
  function (logManager, nodePropertyNames, constraintManagerDialogTemplate) {
  
  "use strict";

  var self, logger, client;
  var territoryId, selfPatterns, toBeValidated;
  var constraintManagerDialog;
  var $cmb;

  var ConstraintManager = function(client_) {
    self = this;
    logManager.setLogLevel(logManager.logLevels.INFO);
    logger = logManager.create('ConstraintManager');
    client = client_;
    constraintManagerDialog = $(constraintManagerDialogTemplate);
    constraintManagerDialog.on('hidden', function() {
      $cmb.html('');
    });
  };

  ConstraintManager.prototype.validateAll = function(id) {

    constraintManagerDialog.one('shown', function () {
      toBeValidated = id;
      territoryId = client.addUI(self, true);
      selfPatterns = {};
      selfPatterns[id] = { children: Number.MAX_VALUE };
      $cmb = $("#ConstraintModalBody");
      client.updateTerritory(territoryId, selfPatterns);
    });
    constraintManagerDialog.modal('show');

  };

  ConstraintManager.prototype.validate = function(id) {
    // Validate the node itself..
    var node = client.getNode(id);
    var node_name = node.getAttribute('name');
    // logger.info('Validating node: ' + id + ' ' + node_name);
    
    var constraints = node.getConstraintNames().map(function(constraint_name) {
      var constraint_obj = node.getConstraint(constraint_name);
      constraint_obj.name = constraint_name;
      return constraint_obj;
    }).sort(function(a, b) {
      return a.priority - b.priority;
    });

    if (constraints.length == 0 ) {
      create_alert('There are no constraints to run on <strong>{' +
        node_name + '}</strong>', 'alert-success').appendTo($cmb);
    }

    var flag = false;
    constraints.forEach(function(constraint) {
      if (flag) return;
      var result = eval("(" + constraint.script + ")(client, node);");

      var msg = '<strong>{' + node_name  + ' ' + constraint.name+ '}</strong>';
      
      if (result) {
        var no_violation_message = 'No violation: ' + msg;
        create_alert(no_violation_message, 'alert-success').appendTo($cmb);
      } else {
        var violation_message = '!!!Violation: ' + msg;
        create_alert(violation_message).appendTo($cmb);
        if ( constraint.priority == 0) {
          create_alert('Please fix the last constraint violation to run'
            + ' the remaining constraints, if there are more', 'alert-error')
            .appendTo($cmb);
          flag = true;
        }
      }
    });
    
    if (flag) {
      logger.warning('no more validation');
    }

    // var y = function(input, callback) {
    //   //
    //   callback(withsomething);<commit_msg>create alert-error for priority 0<commit_after>define(['logManager', 'js/NodePropertyNames', 'text!./ConstraintManager.html'], 
  function (logManager, nodePropertyNames, constraintManagerDialogTemplate) {
  
  "use strict";

  var self, logger, client;
  var territoryId, selfPatterns, toBeValidated;
  var constraintManagerDialog;
  var $cmb;

  var ConstraintManager = function(client_) {
    self = this;
    logManager.setLogLevel(logManager.logLevels.INFO);
    logger = logManager.create('ConstraintManager');
    client = client_;
    constraintManagerDialog = $(constraintManagerDialogTemplate);
    constraintManagerDialog.on('hidden', function() {
      $cmb.html('');
    });
  };

  ConstraintManager.prototype.validateAll = function(id) {

    constraintManagerDialog.one('shown', function () {
      toBeValidated = id;
      territoryId = client.addUI(self, true);
      selfPatterns = {};
      selfPatterns[id] = { children: Number.MAX_VALUE };
      $cmb = $("#ConstraintModalBody");
      client.updateTerritory(territoryId, selfPatterns);
    });
    constraintManagerDialog.modal('show');

  };

  ConstraintManager.prototype.validate = function(id) {
    // Validate the node itself..
    var node = client.getNode(id);
    var node_name = node.getAttribute('name');
    // logger.info('Validating node: ' + id + ' ' + node_name);
    
    var constraints = node.getConstraintNames().map(function(constraint_name) {
      var constraint_obj = node.getConstraint(constraint_name);
      constraint_obj.name = constraint_name;
      return constraint_obj;
    }).sort(function(a, b) {
      return a.priority - b.priority;
    });

    if (constraints.length == 0 ) {
      create_alert('There are no constraints to run on <strong>{' +
        node_name + '}</strong>', 'alert-success').appendTo($cmb);
    }

    var flag = false;
    constraints.forEach(function(constraint) {
      if (flag) return;
      var result = eval("(" + constraint.script + ")(client, node);");

      var msg = '<strong>{' + node_name  + ' ' + constraint.name+ '}</strong>';
      
      if (result) {
        var no_violation_message = 'No violation: ' + msg;
        create_alert(no_violation_message, 'alert-success').appendTo($cmb);
      } else {
        var violation_message = '!!!Violation: ' + msg;
        var cls = constraint.priority == 0 ? 'alert-error' : '';
        create_alert(violation_message, cls).appendTo($cmb);
        if ( constraint.priority == 0) {
          create_alert('Please fix the last constraint violation to run'
            + ' the remaining constraints, if there are more', 'alert-error')
            .appendTo($cmb);
          flag = true;
        }
      }
    });
    
    if (flag) {
      logger.warning('no more validation');
    }

    // var y = function(input, callback) {
    //   //
    //   callback(withsomething);
{'fraction_non_alphanumeric': 0.13829787234042554, 'fraction_numerical': 0.0010638297872340426, 'mean_word_length': 3.0149466192170817, 'pattern_counts': {'":': 0, '<': 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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5424563', 'n_tokens_mistral': 1643, 'n_tokens_neox': 1612, 'n_words': 339}