<commit_before>Vendors =

  custom                   :
    title                  : "Custom Credential"
    description            : """Custom credentials can include meta
                               credentials for any service"""
    credentialFields       :
      credential           :
        label              : "Credential (JSON)"
        placeholder        : "credential in JSON format"
        type               : "textarea"

  amazon                   :
    title                  : "AWS Credential"
    description            : "Amazon Web Services"
    credentialFields       :
      accessKeyId          :
        label              : "Access Key"
        placeholder        : "aws access key"
      secretAccessKey      :
        label              : "Secret Key"
        placeholder        : "aws secret key"
        type               : "password"
      region               :
        label              : "Region"
        placeholder        : "aws region"
        defaultValue       : "us-east-1"

  koding                   :
    title                  : "Koding Credential"
    description            : "Koding rulez."
    credentialFields       :
      username             :
        label              : "Username"
        placeholder        : "koding username"
      password             :
        label              : "Password"
        placeholder        : "koding password"
        type               : "password"

  google                   :
    title                  : "Google Cloud Credential"
    description            : "Google compute engine"
    credentialFields       :
      projectId            :
        label              : "Project Id"
        placeholder        : "project id in gce"
      clientSecretsContent :
        label              : "Client secrets"
        placeholder        : "content of the client_secrets.xxxxx.json"
        type               : "textarea"
      privateKeyContent    :
        label              : "Private Key"
        placeholder        : "content of the xxxxx-privatekey.pem"
        type               : "textarea"
      zone                 :
        label              : "Zone"
        placeholder        : "google zone"
        defaultValue       : "us-central1-a"

  engineyard               :
    title                  : "EngineYard Credential"
    description            : "EngineYard"
    credentialFields       :
      accountId            :
        label              : "Account Id"
        placeholder        : "account id in engineyard"
      secret               :
        label              : "Secret"
        placeholder        : "engineyard secret"
        type               : "password"

  digitalocean             :
    title                  : "Digitalocean Credential"
    description            : "Digitalocean droplets"
    credentialFields       :
      clientId             :
        label              : "Client Id"
        placeholder        : "client id in digitalocean"
      apiKey               :
        label              : "API Key"
        placeholder        : "digitalocean api key"


class AccountCredentialListController extends AccountListViewController

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

    options.noItemFoundText = "You have no credentials."
    super options, data

    @loadItems()

  loadItems:->

    @removeAllItems()
    @showLazyLoader()

    { JCredential } = KD.remote.api

    JCredential.some {}, { limit: 30 }, (err, credentials)=>

      @hideLazyLoader()

      return if KD.showError err, \
        KodingError : "Failed to fetch credentials, try again later."

      @instantiateListItems credentials
      log credentials

  loadView:->

    super

    view = @getView().parent

    view.addSubView addButton = new KDButtonView
      style     : "solid green small account-header-button"
      iconClass : "plus"
      iconOnly  : yes
      callback  : => new KDNotificationView title : "Coming soon."

class AccountCredentialList extends KDListView

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

    options.tagName  ?= "ul"
    options.itemClass = AccountCredentialListItem

    super options, data

  deleteItem: (item)->

    credential = item.getData()

    modal = KDModalView.confirm
      title       : "Remove credential"
      description : "Do you want to remove ?"
      ok          :
        title     : "Yes"
        callback  : -> credential.delete (err)->

          modal.destroy()

          unless KD.showError err
            item.destroy()


class AccountCredentialListItem extends KDListItemView

  constructor: (options = {}, data)->
    options.cssClass = KD.utils.curry "credential-item", options.cssClass
    super options, data

    delegate = @getDelegate()

    @deleteButton = new KDButtonView
      title    : "Delete"
      cssClass : "solid small red"
      callback : => delegate.deleteItem this

  viewAppended: JView::viewAppended

  pistachio:->
    "{{#(vendor)}} - {{#(title)}} -- {{> @deleteButton}}"<commit_msg>Show a list of Vendors in add button menu of add Credential<commit_after>Vendors =

  custom                   :
    title                  : "Custom Credential"
    description            : """Custom credentials can include meta
                               credentials for any service"""
    credentialFields       :
      credential           :
        label              : "Credential (JSON)"
        placeholder        : "credential in JSON format"
        type               : "textarea"

  amazon                   :
    title                  : "AWS Credential"
    description            : "Amazon Web Services"
    credentialFields       :
      accessKeyId          :
        label              : "Access Key"
        placeholder        : "aws access key"
      secretAccessKey      :
        label              : "Secret Key"
        placeholder        : "aws secret key"
        type               : "password"
      region               :
        label              : "Region"
        placeholder        : "aws region"
        defaultValue       : "us-east-1"

  koding                   :
    title                  : "Koding Credential"
    description            : "Koding rulez."
    credentialFields       :
      username             :
        label              : "Username"
        placeholder        : "koding username"
      password             :
        label              : "Password"
        placeholder        : "koding password"
        type               : "password"

  google                   :
    title                  : "Google Cloud Credential"
    description            : "Google compute engine"
    credentialFields       :
      projectId            :
        label              : "Project Id"
        placeholder        : "project id in gce"
      clientSecretsContent :
        label              : "Client secrets"
        placeholder        : "content of the client_secrets.xxxxx.json"
        type               : "textarea"
      privateKeyContent    :
        label              : "Private Key"
        placeholder        : "content of the xxxxx-privatekey.pem"
        type               : "textarea"
      zone                 :
        label              : "Zone"
        placeholder        : "google zone"
        defaultValue       : "us-central1-a"

  engineyard               :
    title                  : "EngineYard Credential"
    description            : "EngineYard"
    credentialFields       :
      accountId            :
        label              : "Account Id"
        placeholder        : "account id in engineyard"
      secret               :
        label              : "Secret"
        placeholder        : "engineyard secret"
        type               : "password"

  digitalocean             :
    title                  : "Digitalocean Credential"
    description            : "Digitalocean droplets"
    credentialFields       :
      clientId             :
        label              : "Client Id"
        placeholder        : "client id in digitalocean"
      apiKey               :
        label              : "API Key"
        placeholder        : "digitalocean api key"


class AccountCredentialListController extends AccountListViewController

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

    options.noItemFoundText = "You have no credentials."
    super options, data

    @loadItems()

  loadItems:->

    @removeAllItems()
    @showLazyLoader()

    { JCredential } = KD.remote.api

    JCredential.some {}, { limit: 30 }, (err, credentials)=>

      @hideLazyLoader()

      return if KD.showError err, \
        KodingError : "Failed to fetch credentials, try again later."

      @instantiateListItems credentials
      log credentials

  loadView:->

    super

    view = @getView().parent
    vendorList = { }

    Object.keys(Vendors).forEach (vendor)=>
      vendorList[Vendors[vendor].title] =
        callback : =>
          @_addButtonMenu.destroy()
          @showAddCredentialFormFor vendor

    view.addSubView addButton = new KDButtonView
      style     : "solid green small account-header-button"
      iconClass : "plus"
      iconOnly  : yes
      callback  : =>
        @_addButtonMenu = new KDContextMenu
          delegate    : addButton
          y           : addButton.getY() + 35
          x           : addButton.getX() - 142
          width       : 200
          arrow       :
            margin    : -4
            placement : "top"
        , vendorList

class AccountCredentialList extends KDListView

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

    options.tagName  ?= "ul"
    options.itemClass = AccountCredentialListItem

    super options, data

  deleteItem: (item)->

    credential = item.getData()

    modal = KDModalView.confirm
      title       : "Remove credential"
      description : "Do you want to remove ?"
      ok          :
        title     : "Yes"
        callback  : -> credential.delete (err)->

          modal.destroy()

          unless KD.showError err
            item.destroy()


class AccountCredentialListItem extends KDListItemView

  constructor: (options = {}, data)->
    options.cssClass = KD.utils.curry "credential-item", options.cssClass
    super options, data

    delegate = @getDelegate()

    @deleteButton = new KDButtonView
      title    : "Delete"
      cssClass : "solid small red"
      callback : => delegate.deleteItem this

  viewAppended: JView::viewAppended

  pistachio:->
    "{{#(vendor)}} - {{#(title)}} -- {{> @deleteButton}} -- {{#(owner)}}"
{'fraction_non_alphanumeric': 0.0794935262757045, 'fraction_numerical': 0.0016184310738766184, 'mean_word_length': 1.3724028906955736, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 31, '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': '6873871', 'n_tokens_mistral': 2682, 'n_tokens_neox': 2512, 'n_words': 673}