<commit_before><template>
  <div class="roster-vue mb-4">

    <div class="card px-4 mt-4 bg-faded">

      <div class="card-header">
        <span class="float-right">
          <router-link to="/">Home</router-link>
          <button class="btn" :disabled="!dirty"
            v-on:click="saveRoster()">Save</button>
        </span>
      </div>

      <h2 class="my-4 text-center">{{ faction.name }}</h2>
      <ul class="nav mb-4 justify-content-between">
        <li v-for="fighter in faction.fighters" v-if="faction"
          class="nav-item">
          <h4>{{ fighter.name }}</h4>
          <em class="badge badge-info">{{ fighter.cost }} points</em>
          <button class="btn btn-success"
          :disabled="cannotAddFighter(fighter)"
            v-on:click="addFighter(fighter)">Add</button>
        </li>
      </ul>
    </div>

    <div class="card px-4 mt-4 bg-faded">
      <div class="row">
        <div class="col col-12 col-md-6">
          <input class="form-control my-4" type="text" v-model="teamName"
            v-on:change="nameTeam"
            placeholder="Name your kill-team">
        </div>
        <div class="col col-12 col-md-6">
          <h2 class="my-4" v-if="faction">
            {{ totalPointsCost }} points
            <span class="float-right">
              {{ totalNumberFighters }} / {{ faction.size.max }} models
            </span>
          </h2>
        </div>
      </div>
      <div class="card mb-4 px-2 py-4 fighter-background"
        v-for="fighter, index in chosenFighters">
        <fighter
          :index="index"
          :weaponsAvailable="weaponsAvailable(fighter)"
        ></fighter>
      </div>
    </div>

    <modal
      :title="'Unsaved Roster'"
      :body="'You have an unsaved roster, would you like to save it?'"
      :id="modalId"
      :options="modalOptions"
      v-on:selectedOption="processModalOption"
    ></modal>

  </div>
</template>

<script lang="coffee">

  import Fighter from './Fighter.vue'
  import Modal from './Modal.vue'
  import Storage from './Storage.coffee'

  Roster =

    props: ['factionId']

    components: { Fighter, Modal }

    mixins: [ Storage ]

    data: () ->
      teamName: ""
      modalId: "unsavedRosterModal"
      modalOptions: [
        {name: 'discard', text: 'No thanks'}
        {name: 'save', text: 'Yes please'}
      ]
      chosenFaction: null
      discardAction: () -> null

    computed:

      faction: () ->
        try
          Faction = require '../data/' + @factionId + '.toml'
          Faction.fighters = @mapKeys Faction.fighters
          Faction
        catch error
          false

      dirty: () -> @$store.getters.getDirty
      chosenFighters: () -> @$store.getters.getFighters
      totalPointsCost: () -> @$store.getters.getTotalPointsCost
      totalNumberFighters: () -> @$store.getters.getTotalNumberFighters

    mounted: () ->
      @teamName = @$store.getters.getTeamName

    beforeRouteLeave: (to, from, next) ->
      if @totalNumberFighters == 0 || @dirty is false
        next()
      else
        @discardAction = next
        jQuery('#' + @modalId).modal 'show'

    methods:
<commit_msg>Discard roster when leaving non-dirty view directly<commit_after><template>
  <div class="roster-vue mb-4">

    <div class="card px-4 mt-4 bg-faded">

      <div class="card-header">
        <span class="float-right">
          <router-link to="/">Home</router-link>
          <button class="btn" :disabled="!dirty"
            v-on:click="saveRoster()">Save</button>
        </span>
      </div>

      <h2 class="my-4 text-center">{{ faction.name }}</h2>
      <ul class="nav mb-4 justify-content-between">
        <li v-for="fighter in faction.fighters" v-if="faction"
          class="nav-item">
          <h4>{{ fighter.name }}</h4>
          <em class="badge badge-info">{{ fighter.cost }} points</em>
          <button class="btn btn-success"
          :disabled="cannotAddFighter(fighter)"
            v-on:click="addFighter(fighter)">Add</button>
        </li>
      </ul>
    </div>

    <div class="card px-4 mt-4 bg-faded">
      <div class="row">
        <div class="col col-12 col-md-6">
          <input class="form-control my-4" type="text" v-model="teamName"
            v-on:change="nameTeam"
            placeholder="Name your kill-team">
        </div>
        <div class="col col-12 col-md-6">
          <h2 class="my-4" v-if="faction">
            {{ totalPointsCost }} points
            <span class="float-right">
              {{ totalNumberFighters }} / {{ faction.size.max }} models
            </span>
          </h2>
        </div>
      </div>
      <div class="card mb-4 px-2 py-4 fighter-background"
        v-for="fighter, index in chosenFighters">
        <fighter
          :index="index"
          :weaponsAvailable="weaponsAvailable(fighter)"
        ></fighter>
      </div>
    </div>

    <modal
      :title="'Unsaved Roster'"
      :body="'You have an unsaved roster, would you like to save it?'"
      :id="modalId"
      :options="modalOptions"
      v-on:selectedOption="processModalOption"
    ></modal>

  </div>
</template>

<script lang="coffee">

  import Fighter from './Fighter.vue'
  import Modal from './Modal.vue'
  import Storage from './Storage.coffee'

  Roster =

    props: ['factionId']

    components: { Fighter, Modal }

    mixins: [ Storage ]

    data: () ->
      teamName: ""
      modalId: "unsavedRosterModal"
      modalOptions: [
        {name: 'discard', text: 'No thanks'}
        {name: 'save', text: 'Yes please'}
      ]
      chosenFaction: null
      discardAction: () -> null

    computed:

      faction: () ->
        try
          Faction = require '../data/' + @factionId + '.toml'
          Faction.fighters = @mapKeys Faction.fighters
          Faction
        catch error
          false

      dirty: () -> @$store.getters.getDirty
      chosenFighters: () -> @$store.getters.getFighters
      totalPointsCost: () -> @$store.getters.getTotalPointsCost
      totalNumberFighters: () -> @$store.getters.getTotalNumberFighters

    mounted: () ->
      @teamName = @$store.getters.getTeamName

    beforeRouteLeave: (to, from, next) ->
      if @totalNumberFighters == 0 || @dirty is false
        @$store.commit 'discardRoster'
        next()
      else
        @discardAction = next
        jQuery('#' + @modalId).modal 'show'

    methods:

{'fraction_non_alphanumeric': 0.1581832419733751, 'fraction_numerical': 0.007830853563038372, 'mean_word_length': 2.098495875788452, 'pattern_counts': {'":': 0, '<': 95, '<?xml version=': 0, '>': 113, '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': '767014', 'n_tokens_mistral': 2098, 'n_tokens_neox': 2008, 'n_words': 432}