<commit_before>class ManageDatabasesModal extends KDModalViewWithForms

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

    options =
      title                   : "Manage Databases"
      content                 : ''
      helpContent             :
        """
          You can create and modify your databases from this modal.
          Under the **Current Databases** tab you can list current databases
          you have created before and you can use same name for your database
          name and database user name.
        """
      overlay                 : yes
      width                   : 500
      height                  : "auto"
      cssClass                : "databases-modal"
      tabs                    :
        navigable             : yes
        goToNextFormOnSubmit  : no
        forms                 :
          "Create New Database":
            buttons           :
              Create          :
                title         : "Create"
                style         : "modal-clean-green"
                type          : "submit"
                loader        :
                  color       : "#444444"
                  diameter    : 12
                callback      : =>
                  form = @modalTabs.forms["Create New Database"]
                  @dbController.addDatabase form.getFormData(), =>
                    form.buttons.Create.hideLoader()
            fields            :
              dbType          :
                label         : "Type"
                itemClass     : KDSelectBox
                type          : "select"
                name          : "dbType"
                defaultValue  : "mysql"
                selectOptions : [
                  { title : "MySql",    value : "mysql" }
                  { title : "Mongo",    value : "mongo" }
                ]
              dbKind          :
                label         : "Kind"
                itemClass     : KDSelectBox
                type          : "select"
                name          : "dbKind"
                defaultValue  : "free"
                selectOptions : [
                  { title : "Free Database for Development", value : "free" }
                ]
              Information     :
                type          : 'hidden'
                cssClass      : 'database-list'
          "Current Databases" :
            fields            :
              Instances       :
                type          : 'hidden'
                cssClass      : 'database-list'
            buttons           :
              Refresh         :
                style         : "modal-clean-gray"
                type          : 'submit'
                loader        :
                  color       : "#444444"
                  diameter    : 12
                callback      : =>
                  form = @modalTabs.forms["Current Databases"]
                  @dbController.loadItems =>
                    form.buttons.Refresh.hideLoader()

    super options, data

    @dbController = new AccountDatabaseListController
      itemClass : DatabaseListItem

    dbList = @dbController.getListView()
    dbList.on "ListUpdated", => @setPositions()

    dbListForm = @modalTabs.forms["Current Databases"]
    dbListForm.fields.Instances.addSubView @dbController.getView()

    @modalTabs.panes[0].on "KDTabPaneInactive", => @setPositions()
    @modalTabs.panes[0].on "KDTabPaneActive", => @setPositions()

    dbCreateForm = @modalTabs.forms["Create New Database"]

    @dbController.on "DatabaseAdded", (data)=>

      dbCreateForm.inputs.dbType.makeDisabled()
      dbCreateForm.inputs.dbKind.makeDisabled()
      @newDBCreatedWidget?.destroy?()

      dbCreateForm.fields.Information.addSubView \
        @newDBCreatedWidget = new NewDBCreatedWidget {}, data

      dbCreateForm.buttons.Create.setTitle "Ok, got it"

      dbCreateForm.buttons.Create.setClass "modal-clean-gray"
      dbCreateForm.buttons.Create.unsetClass "modal-clean-green"

      dbCreateForm.buttons.Create.setCallback =>
        @newDBCreatedWidget.unsetClass 'ready'

        dbCreateForm.inputs.dbType.makeEnabled()
        dbCreateForm.inputs.dbKind.makeEnabled()

        dbCreateForm.buttons.Create.setTitle "Create"
        dbCreateForm.buttons.Create.setClass "modal-clean-green"
        dbCreateForm.buttons.Create.unsetClass "modal-clean-gray"
        dbCreateForm.buttons.Create.hideLoader()

        dbCreateForm.buttons.Create.setCallback =>
          form = @modalTabs.forms["Create New Database"]
          @dbController.addDatabase form.getFormData(), =>
            form.buttons.Create.hideLoader()

        KD.utils.wait 300, => @setPositions()

      @dbController.loadItems()

class AccountDatabaseListController extends KDListViewController

  constructor:->
    super
    @account = KD.whoami()

    @commands =
      mysql    :
        create : "createMysqlDatabase"
        remove : "removeMysqlDatabase"
        update : "changeMysqlPassword"
        fetch  : "fetchMysqlDatabases"
      mongo    :
        create : "createMongoDatabase"
        remove : "removeMongoDatabase"<commit_msg>rollbar: duplicate db views after creating a db<commit_after>class ManageDatabasesModal extends KDModalViewWithForms

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

    ## LOG: Duplicate entries in database.
    @databases = {}
    ##

    options =
      title                   : "Manage Databases"
      content                 : ''
      helpContent             :
        """
          You can create and modify your databases from this modal.
          Under the **Current Databases** tab you can list current databases
          you have created before and you can use same name for your database
          name and database user name.
        """
      overlay                 : yes
      width                   : 500
      height                  : "auto"
      cssClass                : "databases-modal"
      tabs                    :
        navigable             : yes
        goToNextFormOnSubmit  : no
        forms                 :
          "Create New Database":
            buttons           :
              Create          :
                title         : "Create"
                style         : "modal-clean-green"
                type          : "submit"
                loader        :
                  color       : "#444444"
                  diameter    : 12
                callback      : =>
                  form = @modalTabs.forms["Create New Database"]
                  @dbController.addDatabase form.getFormData(), =>
                    form.buttons.Create.hideLoader()
            fields            :
              dbType          :
                label         : "Type"
                itemClass     : KDSelectBox
                type          : "select"
                name          : "dbType"
                defaultValue  : "mysql"
                selectOptions : [
                  { title : "MySql",    value : "mysql" }
                  { title : "Mongo",    value : "mongo" }
                ]
              dbKind          :
                label         : "Kind"
                itemClass     : KDSelectBox
                type          : "select"
                name          : "dbKind"
                defaultValue  : "free"
                selectOptions : [
                  { title : "Free Database for Development", value : "free" }
                ]
              Information     :
                type          : 'hidden'
                cssClass      : 'database-list'
          "Current Databases" :
            fields            :
              Instances       :
                type          : 'hidden'
                cssClass      : 'database-list'
            buttons           :
              Refresh         :
                style         : "modal-clean-gray"
                type          : 'submit'
                loader        :
                  color       : "#444444"
                  diameter    : 12
                callback      : =>
                  form = @modalTabs.forms["Current Databases"]
                  @dbController.loadItems =>
                    form.buttons.Refresh.hideLoader()

    super options, data

    @dbController = new AccountDatabaseListController
      itemClass : DatabaseListItem

    dbList = @dbController.getListView()
    dbList.on "ListUpdated", => @setPositions()

    dbListForm = @modalTabs.forms["Current Databases"]
    dbListForm.fields.Instances.addSubView @dbController.getView()

    @modalTabs.panes[0].on "KDTabPaneInactive", => @setPositions()
    @modalTabs.panes[0].on "KDTabPaneActive", => @setPositions()

    dbCreateForm = @modalTabs.forms["Create New Database"]

    @dbController.on "DatabaseAdded", (data)=>

      @databaseAdded(data)

      dbCreateForm.inputs.dbType.makeDisabled()
      dbCreateForm.inputs.dbKind.makeDisabled()
      @newDBCreatedWidget?.destroy?()

      dbCreateForm.fields.Information.addSubView \
        @newDBCreatedWidget = new NewDBCreatedWidget {}, data

      dbCreateForm.buttons.Create.setTitle "Ok, got it"

      dbCreateForm.buttons.Create.setClass "modal-clean-gray"
      dbCreateForm.buttons.Create.unsetClass "modal-clean-green"

      dbCreateForm.buttons.Create.setCallback =>
        @newDBCreatedWidget.unsetClass 'ready'

        dbCreateForm.inputs.dbType.makeEnabled()
        dbCreateForm.inputs.dbKind.makeEnabled()

        dbCreateForm.buttons.Create.setTitle "Create"
        dbCreateForm.buttons.Create.setClass "modal-clean-green"
        dbCreateForm.buttons.Create.unsetClass "modal-clean-gray"
        dbCreateForm.buttons.Create.hideLoader()

        dbCreateForm.buttons.Create.setCallback =>
          form = @modalTabs.forms["Create New Database"]
          @dbController.addDatabase form.getFormData(), =>
            form.buttons.Create.hideLoader()

        KD.utils.wait 300, => @setPositions()

      @dbController.loadItems()

  ## LOG: Duplicate entries in database.
  databaseAdded: (data)->
    if @databases[data.dbName]
      KD.logToExternal msg:"duplicate database", dbName:data.dbName
    else
      @databases[data.dbName] = true
  ##

class AccountDatabaseListController extends KDListViewController

  constructor:->
    super
    @account = KD.whoami()

    @commands =
      mysql    :
        create : "createMysqlDatabase"
        remove : "removeMysqlDatabase"
        update : "changeMysqlPassword"
        fetch  : "fetchMysqlDatabases"
      mongo    :
        create : "createMongoDatabase"
        remove : "removeMongoDatabase"
{'fraction_non_alphanumeric': 0.08654848800834203, 'fraction_numerical': 0.004550194331216229, 'mean_word_length': 1.399909008189263, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7553142', 'n_tokens_mistral': 2751, 'n_tokens_neox': 2564, 'n_words': 533}