<commit_before>/* global ngDefine: false, console: false */
ngDefine('cockpit.directives', [
  'angular',
  'jquery',
  'bpmn/Bpmn',
  'jquery-overscroll',
  'jquery-mousewheel'
], function(module, angular, $, Bpmn) {
  'use strict';
  /* jshint unused: false */

  function DirectiveController($scope, $element, $attrs, $filter, $q, $window, $compile, Views) {

    var w = angular.element($window);

    $scope.overlayVars = { read: [ 'processData', 'bpmnElement' ] };
    $scope.overlayProviders = Views.getProviders({ component:  $scope.providerComponent });
    var overlay = '<div view ng-repeat="overlayProvider in overlayProviders" provider="overlayProvider" vars="overlayVars"></div>';

    var bpmnElements,
        selection,
        scrollToBpmnElementId;

    var activityHighligtClass = 'activity-highlight';
    var bpmnRenderer = null;
    var zoomLevel = 1;

    $scope.$on('$destroy', function() {
      bpmnRenderer = null;
      $scope.processDiagram = null;
      $scope.overlayProviders = null;
    });

    /*------------------- Rendering of process diagram ---------------------*/

    /**
     * If the process diagram changes, then the diagram will be rendered.
     */
    $scope.$watch('processDiagram', function(newValue) {
      if (newValue && newValue.$loaded !== false) {
        try {
          bpmnElements = newValue.bpmnElements;
          bpmnRenderer = new Bpmn();
          renderDiagram();
          decorateDiagram(bpmnElements);
          initializeScrollAndZoomFunctions();

          // update selection in case it has been provided earlier
          updateSelection(selection);

          // update scroll to in case it has been provided earlier
          scrollToBpmnElement(scrollToBpmnElementId);
        } catch (exception) {
          console.log('Unable to render diagram for process definition ' + $scope.processDiagram.processDefinition.id + ', reason: ' + exception.message);
          $element.html('<p style="text-align: center;margin-top: 100px;">Unable to render process diagram.</p>');
        }
      }
    });

    function renderDiagram() {

      // set the element id to processDiagram_*
      var elementId = 'processDiagram_' + $scope.processDiagram.processDefinition.id.replace(/[.|:]/g, '_');
      $element.attr('id', elementId);

      // clear innerHTML of element in case that the process diagram has changed
      // and the old one has been rendered.
      $element.empty();

      // set the render options
      $element.addClass('process-diagram');
      var options = {
        diagramElement : $element.attr('id')
      };

      // do the rendering
      bpmnRenderer.renderDiagram($scope.processDiagram.semantic, options);
    }

    /*------------------- Decorate diagram ---------------------*/

    function decorateDiagram(bpmnElements) {
      decorateProcessDiagramWithEventHandlers(bpmnElements);

      angular.forEach(bpmnElements, function (bpmnElement) {
        var activityId = bpmnElement.id,
            elem = bpmnRenderer.getOverlay(activityId);

        if (elem) {
          decorateBpmnElementWithOverlays(bpmnElement, elem);
          decorateBpmnElementWithEventHandlers(bpmnElement, elem);
        }

      });
    }

    function decorateProcessDiagramWithEventHandlers(bpmnElements) {

      var moved = false,
          mousedown = false;

      // register event handler on $element: mousedown, mousemove, mouseup
      $element
        // register mousedown event
        .mousedown(function() {
          mousedown = true;

          // indicates the timestamp, when
          // the mousemove event was
          // triggered.
          var mousemoveTimestamp = 0;

          // The mousemove event will be bind to the
          // $element only if a mousedown event happened
          // before.
          $element.mousemove(function($event) {
            var now = $event.timeStamp;
            // mousemoveTimestamp === 0 means,
            // that the mousemove event was triggered
            // but no mousemovement happened (this
            // is a workaround for chrome.)
            if (mousemoveTimestamp !== 0) {
              moved = true;
            }
            lastMouseMovement = now;
          });
        })

        // register mouseup event
        .mouseup(function($event) {
          var targetId = $($event.target).attr('data-activity-id'),
              bpmnElement = bpmnElements[targetId],
              ctrlKey = $event.ctrlKey;

          if (!ctrlKey) {

            if (!moved && mousedown && (!bpmnElement || !bpmnElement.isSelectable)) {
              // if the mouse have not moved, a mousedown happend and the bpmnElement is null
              // or is not selectable, then you have to deselect the current selection.
              if ($scope.onElementClick) {
                $scope.onElementClick({id: null, $event: $event});
                $scope.$apply();
              }
            }
          }

          // unbind the mousemove event
          $element.unbind('mousemove');
<commit_msg>fix(cockpit/diagram): fix compile failure in directive<commit_after>/* global ngDefine: false, console: false */
ngDefine('cockpit.directives', [
  'angular',
  'jquery',
  'bpmn/Bpmn',
  'jquery-overscroll',
  'jquery-mousewheel'
], function(module, angular, $, Bpmn) {
  'use strict';
  /* jshint unused: false */

  function DirectiveController($scope, $element, $attrs, $filter, $q, $window, $compile, Views) {

    var w = angular.element($window);

    $scope.overlayVars = { read: [ 'processData', 'bpmnElement' ] };
    $scope.overlayProviders = Views.getProviders({ component:  $scope.providerComponent });
    var overlay = '<div view ng-repeat="overlayProvider in overlayProviders" provider="overlayProvider" vars="overlayVars"></div>';

    var bpmnElements,
        selection,
        scrollToBpmnElementId;

    var activityHighligtClass = 'activity-highlight';
    var bpmnRenderer = null;
    var zoomLevel = 1;

    $scope.$on('$destroy', function() {
      bpmnRenderer = null;
      $scope.processDiagram = null;
      $scope.overlayProviders = null;
    });

    /*------------------- Rendering of process diagram ---------------------*/

    /**
     * If the process diagram changes, then the diagram will be rendered.
     */
    $scope.$watch('processDiagram', function(newValue) {
      if (newValue && newValue.$loaded !== false) {
        try {
          bpmnElements = newValue.bpmnElements;
          bpmnRenderer = new Bpmn();
          renderDiagram();
          decorateDiagram(bpmnElements);
          initializeScrollAndZoomFunctions();

          // update selection in case it has been provided earlier
          updateSelection(selection);

          // update scroll to in case it has been provided earlier
          scrollToBpmnElement(scrollToBpmnElementId);
        } catch (exception) {
          console.log('Unable to render diagram for process definition ' + $scope.processDiagram.processDefinition.id + ', reason: ' + exception.message);
          $element.html('<p style="text-align: center;margin-top: 100px;">Unable to render process diagram.</p>');
        }
      }
    });

    function renderDiagram() {

      // set the element id to processDiagram_*
      var elementId = 'processDiagram_' + $scope.processDiagram.processDefinition.id.replace(/[.|:]/g, '_');
      $element.attr('id', elementId);

      // clear innerHTML of element in case that the process diagram has changed
      // and the old one has been rendered.
      $element.empty();

      // set the render options
      $element.addClass('process-diagram');
      var options = {
        diagramElement : $element.attr('id')
      };

      // do the rendering
      bpmnRenderer.renderDiagram($scope.processDiagram.semantic, options);
    }

    /*------------------- Decorate diagram ---------------------*/

    function decorateDiagram(bpmnElements) {
      decorateProcessDiagramWithEventHandlers(bpmnElements);

      angular.forEach(bpmnElements, function (bpmnElement) {
        var activityId = bpmnElement.id,
            elem = bpmnRenderer.getOverlay(activityId);

        if (elem) {
          decorateBpmnElementWithOverlays(bpmnElement, elem);
          decorateBpmnElementWithEventHandlers(bpmnElement, elem);
        }

      });
    }

    function decorateProcessDiagramWithEventHandlers(bpmnElements) {

      var moved = false,
          mousedown = false;

      // register event handler on $element: mousedown, mousemove, mouseup
      $element
        // register mousedown event
        .mousedown(function() {
          mousedown = true;

          // indicates the timestamp, when
          // the mousemove event was
          // triggered.
          var mousemoveTimestamp = 0;

          // The mousemove event will be bind to the
          // $element only if a mousedown event happened
          // before.
          $element.mousemove(function($event) {
            var now = $event.timeStamp;
            // mousemoveTimestamp === 0 means,
            // that the mousemove event was triggered
            // but no mousemovement happened (this
            // is a workaround for chrome.)
            if (mousemoveTimestamp !== 0) {
              moved = true;
            }
            mousemoveTimestamp = now;
          });
        })

        // register mouseup event
        .mouseup(function($event) {
          var targetId = $($event.target).attr('data-activity-id'),
              bpmnElement = bpmnElements[targetId],
              ctrlKey = $event.ctrlKey;

          if (!ctrlKey) {

            if (!moved && mousedown && (!bpmnElement || !bpmnElement.isSelectable)) {
              // if the mouse have not moved, a mousedown happend and the bpmnElement is null
              // or is not selectable, then you have to deselect the current selection.
              if ($scope.onElementClick) {
                $scope.onElementClick({id: null, $event: $event});
                $scope.$apply();
              }
            }
          }

          // unbind the mousemove event
          $element.unbind('mousemove');

{'fraction_non_alphanumeric': 0.12551805802249852, 'fraction_numerical': 0.001381488059996053, 'mean_word_length': 2.1543728602552132, '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': '7489139', 'n_tokens_mistral': 2817, 'n_tokens_neox': 2705, 'n_words': 693}