<commit_before>angular.module('os.administrative.container')
  .directive('osContainerCreator', function(Site, Container, ContainerType, Alerts) {
    function linker(scope, element, attrs) {
      scope.container  = new Container(scope.container || {});
       
      scope.types = []; 
      ContainerType.query().then(
        function(types) {
          scope.types = types;
        }
      );

      scope.sites = [];
      Site.listForContainers('Create').then(
        function(sites) {
          scope.sites = sites;
        }
      );

      scope.createContainer = function() {
        scope.container.$saveOrUpdate().then(
          function(savedContainer) {
            //
            // ID is purposely removed so that same widget can be used for
            // creation of multiple containers
            //
            delete savedContainer.id;
            angular.extend(scope.container, savedContainer);
            Alerts.success('container.creation_success', savedContainer);
          }
        );
      }
    }

    return {
      restrict: 'E',

      templateUrl: 'modules/administrative/container/creator.html',

      scope: {<commit_msg>PLUGINS-103: Enhanced container create widget to show container type dropdown values based on those configured in metadata. If allowed types is not configured, all provisioned/created types are shown.<commit_after>angular.module('os.administrative.container')
  .directive('osContainerCreator', function(Site, Container, ContainerType, Alerts) {
    function selectType(container, types) {
      if (types.length != 1) {
        return;
      }

      container.typeName = types[0].name;
    }

    function linker(scope, element, attrs) {
      scope.container  = new Container(scope.container || {});
       
      var data = {};
      if (!!attrs.data) {
        data = JSON.parse(attrs.data);
      }

      var allowedTypes = data.allowedTypes || [];
      if (allowedTypes.length == 0) {
        scope.types = [];
        ContainerType.query().then(
          function(types) {
            scope.types = types;
            selectType(scope.container, scope.types);
          }
        );
      } else {
        scope.types = allowedTypes.map(function(type) { return {name: type}; });
        selectType(scope.container, scope.types);
      }

      scope.sites = [];
      Site.listForContainers('Create').then(
        function(sites) {
          scope.sites = sites;
        }
      );

      scope.createContainer = function() {
        scope.container.$saveOrUpdate().then(
          function(savedContainer) {
            //
            // ID is purposely removed so that same widget can be used for
            // creation of multiple containers
            //
            delete savedContainer.id;
            angular.extend(scope.container, savedContainer);
            Alerts.success('container.creation_success', savedContainer);
          }
        );
      }
    }

    return {
      restrict: 'E',

      templateUrl: 'modules/administrative/container/creator.html',

      scope: {
{'fraction_non_alphanumeric': 0.11545988258317025, 'fraction_numerical': 0.0019569471624266144, 'mean_word_length': 2.039643211100099, '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': '7054014', 'n_tokens_mistral': 814, 'n_tokens_neox': 785, 'n_words': 168}