<commit_before><template>
  <div class="wrapper">
    <headline>
      {{collection}} - Create a document
      <collection-dropdown class="icon-medium icon-black" :index="index" :collection="collection"></collection-dropdown>
    </headline>

    <div class="row">
      <div class="col s12 m10 l8 card">

        <form class="wrapper" @submit.prevent="create">
          <div class="row">
            <!-- Collection name -->
            <div class="col s6">
              <div class="input-field">
                <input id="id" type="text" name="collection" v-model="id" />
                <label for="id">Document identifier (optional)</label>
              </div>
            </div>
          </div>

          <div class="row">
            <div class="divider"></div>
          </div>

          <div class="row">
            <div class="col m11">
              <fieldset>
                <div v-for="(name, content) in mapping">
                  <json-form :name="name" :content="content"></json-form>
                </div>
              </fieldset>
            </div>
          </div>

          <div class="row">
            <div class="col s6">
              <button type="submit" class="btn waves-effect waves-light"><i class="fa fa-plus-circle"></i> Create</button>
              <button @click.prevent="cancel" class="btn-flat waves-effect">Cancel</button>
            </div>
          </div>

        </form>
      </div>
    </div>
  </div>
</template>

<style rel="stylesheet/scss" lang="scss">
  fieldset {
    border: 0;

    legend {
      font-weight: 600;
    }

    fieldset {
      border-left: solid 4px #DDD;
    }
  }
</style>

<script>
  import CollectionDropdown from '../Collections/Dropdown'
  import Headline from '../../Materialize/Headline'
  import kuzzle from '../../../services/kuzzle'
  import JsonForm from './JsonForm'
  import {unsetNewDocument} from '../../../vuex/modules/data/actions'
  import {newDocument} from '../../../vuex/modules/data/getters'

  export default {
    name: 'DocumentCreate',
    components: {
      CollectionDropdown,
      Headline,
      JsonForm
    },
    props: {
      index: String,
      collection: String
    },
    methods: {
      cancel () {
        if (this.$router._prevTransition && this.$router._prevTransition.to) {
          this.$router.go(this.$router._prevTransition.to)
        } else {
          this.$router.go({name: 'DataCollectionBrowse', params: {index: this.index, collection: this.collection}})
        }
      },
      create () {
        if (this.id) {
          this.newDocument._id = this.id
        }
        kuzzle.dataCollectionFactory(this.collection, this.index).createDocument(this.newDocument, (err, res) => {
          if (err) {
            this.$dispatch('toast', err.message, 'error')
            return
          }
          kuzzle.refreshIndex(this.index)
          this.$router.go({name: 'DataCollectionBrowse', params: {index: this.index, collection: this.collection}})
        })
      }
    },
    vuex: {
      actions: {
        unsetNewDocument
      },
      getters: {
        newDocument
      }
    },
    beforeDestroy () {
      this.unsetNewDocument()
    },
    data () {
      return {
        id: '',
        mapping: null
      }
    },
    route: {
      data () {
        kuzzle.dataCollectionFactory(this.collection, this.index).getMapping((err, res) => {
          if (err) {
            return
          }
          this.mapping = res.mapping
        })
      }
    }
  }
</script><commit_msg>reformat code<commit_after><template>
  <div class="wrapper">
    <headline>
      {{collection}} - Create a document
      <collection-dropdown class="icon-medium icon-black" :index="index" :collection="collection"></collection-dropdown>
    </headline>

    <div class="row">
      <div class="col s12 m10 l8 card">

        <form class="wrapper" @submit.prevent="create">
          <div class="row">
            <!-- Collection name -->
            <div class="col s6">
              <div class="input-field">
                <input id="id" type="text" name="collection" v-model="id" />
                <label for="id">Document identifier (optional)</label>
              </div>
            </div>
          </div>

          <div class="row">
            <div class="divider"></div>
          </div>

          <div class="row">
            <div class="col m11">
              <fieldset>
                <div v-for="(name, content) in mapping">
                  <json-form :name="name" :content="content"></json-form>
                </div>
              </fieldset>
            </div>
          </div>

          <div class="row">
            <div class="col s6">
              <button type="submit" class="btn waves-effect waves-light"><i class="fa fa-plus-circle"></i> Create</button>
              <button @click.prevent="cancel" class="btn-flat waves-effect">Cancel</button>
            </div>
          </div>

        </form>
      </div>
    </div>
  </div>
</template>

<style rel="stylesheet/scss" lang="scss">
  fieldset {
    border: 0;

    legend {
      font-weight: 600;
    }

    fieldset {
      border-left: solid 4px #DDD;
    }
  }
</style>

<script>
  import CollectionDropdown from '../Collections/Dropdown'
  import Headline from '../../Materialize/Headline'
  import kuzzle from '../../../services/kuzzle'
  import JsonForm from './JsonForm'
  import {unsetNewDocument} from '../../../vuex/modules/data/actions'
  import {newDocument} from '../../../vuex/modules/data/getters'

  export default {
    name: 'DocumentCreate',
    components: {
      CollectionDropdown,
      Headline,
      JsonForm
    },
    props: {
      index: String,
      collection: String
    },
    methods: {
      cancel () {
        if (this.$router._prevTransition && this.$router._prevTransition.to) {
          this.$router.go(this.$router._prevTransition.to)
        } else {
          this.$router.go({name: 'DataCollectionBrowse', params: {index: this.index, collection: this.collection}})
        }
      },
      create () {
        if (this.id) {
          this.newDocument._id = this.id
        }

        kuzzle
          .dataCollectionFactory(this.collection, this.index)
          .createDocument(this.newDocument, (err, res) => {
            if (err) {
              this.$dispatch('toast', err.message, 'error')
              return
            }

            kuzzle.refreshIndex(this.index)
            this.$router.go({name: 'DataCollectionBrowse', params: {index: this.index, collection: this.collection}})
          })
      }
    },
    vuex: {
      actions: {
        unsetNewDocument
      },
      getters: {
        newDocument
      }
    },
    beforeDestroy () {
      this.unsetNewDocument()
    },
    data () {
      return {
        id: '',
        mapping: null
      }
    },
    route: {
      data () {
        kuzzle
          .dataCollectionFactory(this.collection, this.index)
          .getMapping((err, res) => {
            if (err) {
              return
            }
            
            this.mapping = res.mapping
          })
      }
    }
  }
</script>
{'fraction_non_alphanumeric': 0.1529855964200811, 'fraction_numerical': 0.003915536288630961, 'mean_word_length': 1.7101174687381584, 'pattern_counts': {'":': 0, '<': 107, '<?xml version=': 0, '>': 111, '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': '3856935', 'n_tokens_mistral': 2100, 'n_tokens_neox': 2051, 'n_words': 416}