<commit_before>/**
*  Service that provides functionalities to edit nodes secret in a topology.
*/
define(function (require) {
  'use strict';
  var modules = require('modules');
  var _ = require('lodash');

  modules.get('a4c-topology-editor').factory('topoEditSecrets', [
    function() {

      var TopologyEditorMixin = function(scope) {
        this.scope = scope;
      };

      TopologyEditorMixin.prototype = {
        constructor: TopologyEditorMixin,
        init: function() {},
        togglePropertySecret: function(property) {
          var scope = this.scope;
          if (scope.properties.isSecretValue(property.value)) {
            if (property.value.parameters[0] !== "") {
              setTimeout(function () {
                // Send the operation request to unset the property
                scope.execute({
                    type: 'org.alien4cloud.tosca.editor.operations.nodetemplate.secrets.UnsetNodePropertyAsSecretOperation',
                    nodeName: scope.selectedNodeTemplate.name,
                    propertyName: property.key
                  },
                  function(result){
                    // successful callback
                  },
                  null,
                  scope.selectedNodeTemplate.name,
                  true
                );
              }, 0);
            }
            // reset the secret to originalValue
            if (_.defined(property.value)) {
              property.value = property.originalValue;
              property.originalValue = undefined;
            }
          } else {
            property.originalValue = property.value;
            property.value = {function:'get_secret', parameters: ['']};
            // Trigger the editor to enter the secret
            setTimeout(function () {
              $('#p_secret_' + property.key).trigger('click');
            }, 0);

          }
        },
        toggleCapabilitySecret: function(property, capabilityName) {
          var scope = this.scope;
          if (scope.properties.isSecretValue(property.value)) {
            if (property.value.parameters[0] !== "") {
              setTimeout(function () {
                // Send the operation request to unset the capability
                scope.execute({
                    type: 'org.alien4cloud.tosca.editor.operations.nodetemplate.secrets.UnsetNodeCapabilityPropertyAsSecretOperation',
                    nodeName: scope.selectedNodeTemplate.name,
                    propertyName: property.key,
                    capabilityName: capabilityName
                  },
                  function(result){
                    // successful callback
                  },
                  null,
                  scope.selectedNodeTemplate.name,
                  true
                );
              }, 0);
            }
            // reset the secret to originalValue
            if (_.defined(property.value)) {
              property.value = property.originalValue;
              property.originalValue = undefined;
            }

          } else {
            property.originalValue = property.value;
            property.value = {function:'get_secret', parameters: ['']};
            // Trigger the editor to enter the secret
            setTimeout(function () {
              $('#p_secret_' + property.key).trigger('click');
            }, 0);
          }
        }

      };

      return function(scope) {
        var instance = new TopologyEditorMixin(scope);
        scope.secrets = instance;
      };
    }
  ]); // modules
}); // define<commit_msg>ALIEN-2625 Refactoring<commit_after>/**
*  Service that provides functionalities to edit nodes secret in a topology.
*/
define(function (require) {
  'use strict';
  var modules = require('modules');
  var _ = require('lodash');

  modules.get('a4c-topology-editor').factory('topoEditSecrets', [
    function() {

      var TopologyEditorMixin = function(scope) {
        this.scope = scope;
      };

      TopologyEditorMixin.prototype = {
        constructor: TopologyEditorMixin,
        init: function() {},
        togglePropertySecret: function(property) {
          var requestObject = {
              type: 'org.alien4cloud.tosca.editor.operations.nodetemplate.secrets.UnsetNodePropertyAsSecretOperation',
              nodeName: this.scope.selectedNodeTemplate.name,
              propertyName: property.key
            };
          this.toggleSecret(property, requestObject);
        },
        toggleCapabilitySecret: function(property, capabilityName) {
          var requestObject = {
              type: 'org.alien4cloud.tosca.editor.operations.nodetemplate.secrets.UnsetNodeCapabilityPropertyAsSecretOperation',
              nodeName: this.scope.selectedNodeTemplate.name,
              propertyName: property.key,
              capabilityName: capabilityName
            };
          this.toggleSecret(property, requestObject);
        },
        toggleSecret: function(self, requestObject) {
          var scope = this.scope;
          if (scope.properties.isSecretValue(self.value)) {
            if (self.value.parameters[0] !== "") {
              setTimeout(function () {
                scope.execute(requestObject,
                  function(result){
                    // successful callback
                  },
                  null,
                  scope.selectedNodeTemplate.name,
                  true
                );
              }, 0);
            }
            // reset the secret to originalValue
            if (_.defined(self.value)) {
              self.value = self.originalValue;
              self.originalValue = undefined;
            }
          } else {
            self.originalValue = self.value;
            self.value = {function:'get_secret', parameters: ['']};
            // Trigger the editor to enter the secret
            setTimeout(function () {
              $('#p_secret_' + self.key).trigger('click');
            }, 0);
          }
        }
      };

      return function(scope) {
        var instance = new TopologyEditorMixin(scope);
        scope.secrets = instance;
      };
    }
  ]); // modules
}); // define
{'fraction_non_alphanumeric': 0.10425462812601494, 'fraction_numerical': 0.003085417343293277, 'mean_word_length': 1.6141765704584041, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2281232', 'n_tokens_mistral': 1505, 'n_tokens_neox': 1461, 'n_words': 283}