<commit_before><template>
  <div id="editor">
    <b-tabs>
      <b-tab title="Preview" active>
        <saver-preview
           v-bind:preview="saver"
           v-bind:screenshot="screenshot"
           v-if="isLoaded"></saver-preview>
      </b-tab>
      <b-tab title="Settings">
        <saver-form
           v-bind:saver="saver"
             v-if="isLoaded"></saver-form>
        <!--
          note: is track-by ok here?
          https://v1.vuejs.org/guide/list.html#track-by-index 
        -->
        <saver-option-input
           v-on="$listeners"
           v-for="option in options"
           track-by="$index"
           v-bind:option="option"
           v-bind:key="option.name"
           v-on:deleteOption="deleteOption(option)"
           v-if="isLoaded"></saver-option-input>      
        <button type="button" class="btn btn-positive" v-on:click="addSaverOption">Add</button>

      </b-tab>
    </b-tabs>
    <footer class="footer d-flex justify-content-between">
      <div>
        <button class="btn btn-large btn-default cancel" v-on:click="closeWindow">Cancel</button>
        <button class="btn btn-large btn-positive save" v-on:click="saveData">Save</button>
        <button class="btn btn-large btn-positive save" v-on:click="saveDataAndClose">Save and Close</button>        
      </div>
    </footer>
  </div> <!-- #editor -->
</template>

<script>
  import SaverPreview from '@/components/SaverPreview';
  import SaverForm from '@/components/SaverForm';  
  import SaverOptionInput from '@/components/SaverOptionInput';
  
export default {
  name: 'editor',
  components: {
    SaverForm, SaverPreview, SaverOptionInput
  },
  mounted() {
    var self = this;
    console.log("Watcher mounted", this);
    if ( this.src === null ) {
      return;
    }
    console.log("LOAD", this.src);
    this.manager.loadFromFile(this.src).then((result) => {
      self.saver = result;
      self.options = result.options;
    });
  },
  data() {
    return {
      saver: undefined,
      options: []
    }
  },
  computed: {
    currentWindow: function() {
      return this.$electron.remote.getCurrentWindow();
    },
    manager: function() {
      return this.currentWindow.savers;
    },
    ipcRenderer: function() {
      return this.$electron.ipcRenderer;
    },
    isLoaded: function() {
      return typeof(this.saver) !== "undefined";
    },
    params: function() {
      // parse incoming URL params -- we'll get a link to the current screen images for previews here
      return new URLSearchParams(document.location.search);
    },
    src: function() {
      return this.params.get("src");
    },
    screenshot: function() {
      return this.params.get("screenshot");
    }
  },
  methods: {
    onChange(e) {
      console.log(this);
    },
    deleteOption(opt) {
      console.log("DELETE", opt);
      let index = this.options.indexOf(opt);
      this.options.splice(index, 1);
    },
    addSaverOption(e) {
      this.options.push({
        "name": "New Option",
        "type": "slider",
        "description": "Description",
        "min": "1",
        "max": "100",
        "default": "75"
      });
      console.log(this.options);
    },   
    closeWindow() {
      this.currentWindow.close();
    },
    saveData() {
      this.saver.attrs.options = this.options;
      console.log("SAVE", this.saver.attrs);
      this.saver.write(this.saver.attrs);
      this.ipcRenderer.send("savers-updated", this.saver.key);
    },
    saveDataAndClose() {
      this.saveData();
      this.closeWindow();
    }
  }
} 
</script>

<style>
  /* CSS */
</style><commit_msg>Cleanup option indexing<commit_after><template>
  <div id="editor">
    <b-tabs>
      <b-tab title="Preview" active>
        <saver-preview
           v-bind:preview="saver"
           v-bind:screenshot="screenshot"
           v-if="isLoaded"></saver-preview>
      </b-tab>
      <b-tab title="Settings">
        <saver-form
           v-bind:saver="saver"
             v-if="isLoaded"></saver-form>
        <!--
          note: is track-by ok here?
          https://v1.vuejs.org/guide/list.html#track-by-index 
        -->
        <saver-option-input
           v-for="option in options"
           v-bind:option="option"
           v-bind:key="option.index"
           v-on:deleteOption="deleteOption(option)"
           v-if="isLoaded"></saver-option-input>      
        <button type="button" class="btn btn-positive" v-on:click="addSaverOption">Add</button>

      </b-tab>
    </b-tabs>
    <footer class="footer d-flex justify-content-between">
      <div>
        <button class="btn btn-large btn-default cancel" v-on:click="closeWindow">Cancel</button>
        <button class="btn btn-large btn-positive save" v-on:click="saveData">Save</button>
        <button class="btn btn-large btn-positive save" v-on:click="saveDataAndClose">Save and Close</button>        
      </div>
    </footer>
  </div> <!-- #editor -->
</template>

<script>
  import SaverPreview from '@/components/SaverPreview';
  import SaverForm from '@/components/SaverForm';  
  import SaverOptionInput from '@/components/SaverOptionInput';
  
export default {
  name: 'editor',
  components: {
    SaverForm, SaverPreview, SaverOptionInput
  },
  mounted() {
    var self = this;
    if ( this.src === null ) {
      return;
    }
    this.manager.loadFromFile(this.src).then((result) => {
      self.saver = result;
      self.options = result.options;
      self.lastIndex = result.options.length;
    });
  },
  data() {
    return {
      saver: undefined,
      lastIndex: 0,
      options: []
    }
  },
  computed: {
    currentWindow: function() {
      return this.$electron.remote.getCurrentWindow();
    },
    manager: function() {
      return this.currentWindow.savers;
    },
    ipcRenderer: function() {
      return this.$electron.ipcRenderer;
    },
    isLoaded: function() {
      return typeof(this.saver) !== "undefined";
    },
    params: function() {
      // parse incoming URL params -- we'll get a link to the current screen images for previews here
      return new URLSearchParams(document.location.search);
    },
    src: function() {
      return this.params.get("src");
    },
    screenshot: function() {
      return this.params.get("screenshot");
    }
  },
  methods: {
    deleteOption(opt) {
      let index = this.options.indexOf(opt);
      this.options.splice(index, 1);

      // rewrite indexes
//      for(var i = 0; i < this.options.length; i++ ) {
//        console.log(this.options[i].index, i);
//        this.options[i].index = i;
//      }
    },
    addSaverOption(e) {
      this.options.push({
        "index": this.lastIndex + 1,
        "name": "New Option",
        "type": "slider",
        "description": "Description",
        "min": "1",
        "max": "100",
        "default": "75"
      });
      console.log("index", this.lastIndex);
      this.lastIndex = this.lastIndex + 1;
    },   
    closeWindow() {
      this.currentWindow.close();
    },
    saveData() {
      this.saver.attrs.options = this.options;
      this.saver.write(this.saver.attrs);
      this.ipcRenderer.send("savers-updated", this.saver.key);
    },
    saveDataAndClose() {
      this.saveData();
      this.closeWindow();
    }
  }
} 
</script>

<style>
  /* CSS */
</style>
{'fraction_non_alphanumeric': 0.15992345544013123, 'fraction_numerical': 0.002733734281027884, 'mean_word_length': 2.257791629563669, 'pattern_counts': {'":': 13, '<': 72, '<?xml version=': 0, '>': 73, 'https://': 2, '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': '6852965', 'n_tokens_mistral': 2348, 'n_tokens_neox': 2320, 'n_words': 421}