'use strict';

/**
 * @ngdoc directive
 * @name grafterizerApp.directive:clojurePipeline
 * @description
 * # clojurePipeline
 */
angular.module('grafterizerApp')
  .directive('clojurePipeline', function (generateClojure) {
    return {
      template: '<div ui-codemirror="editorOptions" ng-model="clojure"></div>',
      restrict: 'E',
      scope: {
        transformation: '=',
      },
      link: {
      	pre: function(scope) {
		    scope.editorOptions = {
		        lineWrapping : true, 
		        // lineNumbers: true,
		        mode: 'clojure',
		        readOnly: true
		    };
      	},
      	post: function(scope, element, attrs) {
      		scope.$watch('transformation', function(){
      			if (!scope.transformation) {
              return;
            }
      			// console.log(scope.transformation)
      			scope.clojure = generateClojure.fromTransformation(scope.transformation);
      		}, true);
      	}
      }
    };
  });

@@ -911,16 +911,381 @@
 , true);
+%0A%0A          // TODO%C2%A0workaround random bug%0A          scope.$watch(%22$parent.selectedTabIndex%22, function()%7B%0A            if (scope%5B'$parent'%5D.selectedTabIndex) %7B%0A              window.setTimeout(function()%7B%0A              try %7B%0A                element.children().children()%5B0%5D.CodeMirror.refresh();%0A              %7Dcatch(e)%7B%7D%0A            %7D, 1);%0A            %7D%0A          %7D);
 %0A      %09

Refresh the CodeMirror view if it's inside a md-tabs