<commit_before>kd                   = require 'kd'
jspath               = require 'jspath'

KDView               = kd.View
KDTabView            = kd.TabView
KDModalView          = kd.ModalView
KDButtonView         = kd.ButtonView
KDTabPaneView        = kd.TabPaneView
KDCustomHTMLView     = kd.CustomHTMLView


whoami               = require 'app/util/whoami'
curryIn              = require 'app/util/curryIn'
applyMarkdown        = require 'app/util/applyMarkdown'
{ yamlToJson }       = require './yamlutils'
providersParser      = require './providersparser'

requirementsParser   = require './requirementsparser'
updateStackTemplate  = require './updatestacktemplate'
parseTerraformOutput = require './parseterraformoutput'

ProvidersView        = require './providersview'
VariablesView        = require './variablesview'
StackTemplateView    = require './stacktemplateview'


module.exports = class DefineStackView extends KDView


  constructor: (options = {}, data) ->

    options.cssClass = kd.utils.curry 'define-stack-view', options.cssClass

    super options, data

    { stackTemplate } = @getData()

    # I'm not sure about this usage.
    options.delegate = this

    @addSubView @tabView = new KDTabView hideHandleCloseIcons: yes

    @tabView.addPane stackTemplate = new KDTabPaneView name: 'Stack Template'

    # Close for now.
    #@tabView.addPane variables     = new KDTabPaneView name: 'Variables'
    #variables.addSubView @variablesView         = new VariablesView

    @tabView.addPane providers     = new KDTabPaneView name: 'Providers'

    stackTemplate.addSubView @stackTemplateView = new StackTemplateView options, data

    { @credentials } = stackTemplate or {}

    providers.addSubView @providersView = new ProvidersView
      selectedCredentials: @credentials
      stackTemplate       : stackTemplate
      selectedCredentials : @credentials

    @tabView.showPaneByIndex 0

    @createMainButtons()

    @providersView.on 'ItemSelected', (credential) =>

      # After adding credential, we are sharing it with the current
      # group, so anyone in this group can use this credential ~ GG
      { slug } = kd.singletons.groupsController.getCurrentGroup()

      credential.shareWith { target: slug }, (err) =>
        console.warn 'Failed to share credential:', err  if err
        @stackTemplateView.credentialStatus.setCredential credential


    # TODO getrid off from these css properties ~ GG
    @previewButton.setCss      'right', '110px'
    @setAsDefaultButton.setCss 'right', '265px'

    @stackTemplateView.on 'CredentialStatusChanged', (status) =>
      if status is 'verified'
        @saveButton.enable()
        @tabView.showPaneByIndex 0
      else
        @saveButton.disable()

    stackTemplate.on 'PaneDidShow', =>
      @buttons.show()

    providers.on 'PaneDidShow', =>
      @buttons.hide()


  createMainButtons: ->

    @addSubView @buttons = new KDCustomHTMLView


    @buttons.addSubView @cancelButton  = new KDButtonView
      title          : 'Cancel'
      cssClass       : 'solid compact light-gray nav cancel'
      callback       : => @emit 'Cancel'

    @buttons.addSubView @saveButton    = new KDButtonView
      title          : 'Save & Test'
      cssClass       : 'solid compact green nav next'
      disabled       : yes
      loader         : yes
      callback       : @bound 'handleSave'

    @buttons.addSubView @previewButton = new KDButtonView
      title          : 'Template Preview'
      cssClass       : 'solid compact light-gray nav next'
      loader         : yes
      callback       : @bound 'handlePreview'<commit_msg>Renaming the TabPane views.<commit_after>kd                   = require 'kd'
jspath               = require 'jspath'

KDView               = kd.View
KDTabView            = kd.TabView
KDModalView          = kd.ModalView
KDButtonView         = kd.ButtonView
KDTabPaneView        = kd.TabPaneView
KDCustomHTMLView     = kd.CustomHTMLView


whoami               = require 'app/util/whoami'
curryIn              = require 'app/util/curryIn'
applyMarkdown        = require 'app/util/applyMarkdown'
{ yamlToJson }       = require './yamlutils'
providersParser      = require './providersparser'

requirementsParser   = require './requirementsparser'
updateStackTemplate  = require './updatestacktemplate'
parseTerraformOutput = require './parseterraformoutput'

ProvidersView        = require './providersview'
VariablesView        = require './variablesview'
StackTemplateView    = require './stacktemplateview'


module.exports = class DefineStackView extends KDView


  constructor: (options = {}, data) ->

    options.cssClass = kd.utils.curry 'define-stack-view', options.cssClass

    super options, data

    { stackTemplate } = @getData()

    # I'm not sure about this usage.
    options.delegate = this

    @addSubView @tabView = new KDTabView hideHandleCloseIcons: yes

    @tabView.addPane stackTemplatePane = new KDTabPaneView name: 'Stack Template'

    # Close for now.
    #@tabView.addPane variables        = new KDTabPaneView name: 'Variables'
    #variables.addSubView @variablesView         = new VariablesView

    @tabView.addPane providersPane     = new KDTabPaneView name: 'Providers'

    stackTemplatePane.addSubView @stackTemplateView = new StackTemplateView options, data

    { @credentials } = @stackTemplateView.credentialStatus or {}

    providersPane.addSubView @providersView = new ProvidersView
      stackTemplate       : stackTemplate
      selectedCredentials : @credentials

    @tabView.showPaneByIndex 0

    @createMainButtons()

    @providersView.on 'ItemSelected', (credential) =>

      # After adding credential, we are sharing it with the current
      # group, so anyone in this group can use this credential ~ GG
      { slug } = kd.singletons.groupsController.getCurrentGroup()

      credential.shareWith { target: slug }, (err) =>
        console.warn 'Failed to share credential:', err  if err
        @stackTemplateView.credentialStatus.setCredential credential


    # TODO getrid off from these css properties ~ GG
    @previewButton.setCss      'right', '110px'
    @setAsDefaultButton.setCss 'right', '265px'

    @stackTemplateView.on 'CredentialStatusChanged', (status) =>
      if status is 'verified'
        @saveButton.enable()
        @tabView.showPaneByIndex 0
      else
        @saveButton.disable()

    stackTemplatePane.on 'PaneDidShow', =>
      @buttons.show()

    providersPane.on 'PaneDidShow', =>
      @buttons.hide()


  createMainButtons: ->

    @addSubView @buttons = new KDCustomHTMLView


    @buttons.addSubView @cancelButton  = new KDButtonView
      title          : 'Cancel'
      cssClass       : 'solid compact light-gray nav cancel'
      callback       : => @emit 'Cancel'

    @buttons.addSubView @saveButton    = new KDButtonView
      title          : 'Save & Test'
      cssClass       : 'solid compact green nav next'
      disabled       : yes
      loader         : yes
      callback       : @bound 'handleSave'

    @buttons.addSubView @previewButton = new KDButtonView
      title          : 'Template Preview'
      cssClass       : 'solid compact light-gray nav next'
      loader         : yes
      callback       : @bound 'handlePreview'
{'fraction_non_alphanumeric': 0.08692657390825183, 'fraction_numerical': 0.0022041603526656564, 'mean_word_length': 2.6209476309226933, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '7553139', 'n_tokens_mistral': 2099, 'n_tokens_neox': 1988, 'n_words': 520}