<commit_before>define([
  '../../rest-on-couch/Roc',
  '../../rest-on-couch/getChangedGroups',
  'src/util/api',
  'vh/rest-on-couch/showRecordInfo',
  'src/util/ui',
], function (
  Roc,
  getChangedGroups,
  API,
  showRecordInfo,
  UI,
) {

  class TemplatesManager {
    constructor(couchDB, options = {}) {
      this.roc = new Roc({ ...couchDB, database: 'templates' });
      this.roc.getGroupMembership().then(groups => this.allGroups = groups);
      this.basename = options.basename || '';
      if (this.basename && !this.basename.endsWith('.')) this.basename += '.'
      this.refreshTemplates();
    }

    async updateTemplate() {
      console.log('UPDATE TEMPLATE');
      const template = API.getData('currentTemplate');
      await this.roc.update(template.value);
      this.refreshTemplates();
    }

    async deleteTemplate(template) {
      console.log(template);
      return;
      let result = await UI.confirm('Are you sure you want to delete this template ?', 'Delete', 'Cancel', {});

      return;
      if (!result) return;
      await this.roc.delete(template.id);
      this.refreshTemplates();
    }

    async createTemplate(options = {}) {
      const { defaultTwig = '' } = options;
      const form = await UI.form(`
          <div>
          <form>
              <table>
              <tr>
              <th align=right>Category<br><span style='font-size: smaller'>Reaction code</span></th>
              <td>
                  <select name="category">
                    <option value="chemical">Chemical</option><commit_msg>fix: improve and fix TemplatesManager<commit_after>define([
  '../../rest-on-couch/Roc',
  '../../rest-on-couch/getChangedGroups',
  'src/util/api',
  'vh/rest-on-couch/showRecordInfo',
  'src/util/ui',
], function (
  Roc,
  getChangedGroups,
  API,
  showRecordInfo,
  UI,
) {

  class TemplatesManager {
    constructor(couchDB, options = {}) {
      this.roc = new Roc({ ...couchDB, database: 'templates' });
      this.roc.getGroupMembership().then(groups => this.allGroups = groups);
      this.basename = options.basename || '';
      if (this.basename && !this.basename.endsWith('.')) this.basename += '.'
      this.refreshTemplates();
    }

    async updateTemplate() {
      console.log('UPDATE TEMPLATE');
      const template = API.getData('currentTemplate');
      await this.roc.update(template.value);
      this.refreshTemplates();
    }

    async deleteTemplate(template) {
      let result = await UI.confirm('Are you sure you want to delete this template ?', 'Delete', 'Cancel', {});
      if (!result) return;
      await this.roc.delete(template.id);
      this.refreshTemplates();
    }

    async createTemplate(options = {}) {
      const { defaultTwig = '' } = options;
      const form = await UI.form(`
          <div>
          <form>
              <table>
              <tr>
              <th align=right>Category<br><span style='font-size: smaller'>Reaction code</span></th>
              <td>
                  <select name="category">
                    <option value="chemical">Chemical</option>
{'fraction_non_alphanumeric': 0.15848934796642997, 'fraction_numerical': 0.0, 'mean_word_length': 2.4205298013245033, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 31, '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': '2626674', 'n_tokens_mistral': 936, 'n_tokens_neox': 930, 'n_words': 180}