<commit_before><template lang="pug">
  div
    span(v-if="!edit" @click="toggleEdit") {{resource.name}} {{resource.location}} {{resource.website}}
    form(
      v-if="edit"
      @keydown.enter="updateResource"
      @keydown.esc="toggleEdit"
    )
      p
        label Name
        input(v-model="pResource.name" v-focus-auto)

      p
        label Location
        input(v-model="pResource.location")

      p
        label Website
        input(v-model="pResource.website")

      p.error(v-for="error in errors") {{error}}
      
      p
        button(@click="toggleEdit") Cancel
        button(@click="updateResource") Save
</template>

<script>
  import firebase from 'config/firebase';
  import { focusAuto } from 'vue-focus';

  export default {
    data() {
      return {
        edit: false,
        pResource: Object.assign({}, this.resource),
        errors: [],
      };
    },
    props: {
      resource: Object,
    },
    directives: {
      focusAuto,
    },
    methods: {
      toggleEdit: function toggleEdit() {
        this.$set('edit', !this.edit);
      },

      updateResource() {
        firebase
          .database()
          .ref(`/resources/${this.resource.key}`)
          .set(this.pResource)
          .catch(err => {
            this.errors.push(err.message);
          });
      },
    },
  };
</script><commit_msg>Implement skills for resource edit<commit_after><template lang="pug">
  div
    span(v-if="!edit" @click="toggleEdit") {{resource.name}} {{resource.location}} {{resource.website}} 
      span [{{skillList}}]
    form(
      v-if="edit"
      @keydown.enter="updateResource"
      @keydown.esc="toggleEdit"
    )
      p
        label Name
        input(v-model="pResource.name" v-focus-auto)

      p
        label Location
        input(v-model="pResource.location")

      p
        label Website
        input(v-model="pResource.website")

      ul
        li(v-for="skill in skills")
          label
            input(
              type="checkbox"
              v-bind:value="skill.id"
              v-model="pResource.skills"
            )
            span {{skill.name}}

      p.error(v-for="error in errors") {{error}}
      
      p
        button(@click="toggleEdit") Cancel
        button(@click="updateResource") Save
</template>

<script>
  import Resource from 'models/resource';
  import { focusAuto } from 'vue-focus';

  export default {
    data() {
      return {
        edit: false,
        pResource: new Resource(this.resource),
        errors: [],
      };
    },

    props: {
      resource: Object,
    },

    directives: {
      focusAuto,
    },

    computed: {
      skillList() {
        const filtered = this.skills.filter(skill => this.resource.skills.indexOf(skill.id) >= 0);
        return filtered.map(skill => skill.name).join(', ');
      },
    },

    methods: {
      toggleEdit() {
        this.edit = !this.edit;
      },

      updateResource() {
        this.pResource.set()
          .then(() => {
            this.toggleEdit();
          })
          .catch(err => { throw err; });
      },
    },

    vuex: {
      getters: {
        skills: state => state.pool.skills,
      },
      actions: {
        dispatchUpdateResource({ dispatch }) {
          dispatch('UPDATE_RESOURCE', {
            resource: this.pResource,
          });
        },
      },
    },
  };
</script>
{'fraction_non_alphanumeric': 0.14998523767345734, 'fraction_numerical': 0.0002952465308532625, 'mean_word_length': 1.7907742998352554, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 18, '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': '6253284', 'n_tokens_mistral': 1026, 'n_tokens_neox': 1014, 'n_words': 181}