<commit_before><template>
  <Modal :value="isVisible"
         :title="$t('modals.settings')"
         @on-ok="closeModal"
         @on-visible-change="visibleChange"
         :okText="$t('common.add')"
         :scrollable="true"
  >
    <div class="row title-row">
      <div class="title">
        <h2>Backlog</h2>
        <h6>v{{currentVersion}}</h6>
      </div>
      <div class="address"
           @click="open('http://www.backlog.cloud')">
        <a href="#">www.backlog.cloud</a>
      </div>
    </div>

    <Button @click="changeLanguage" icon="md-globe">
      {{$t('modals.change_app_lang')}}
    </Button>

    <updates-check-settings/>

    <h2>
      {{$t('modals.data')}}
    </h2>
    <database-location/>
    <Button @click="createBackup"
            icon="ios-download-outline"
    >
      {{$t('modals.create_backup')}}
    </Button>
    <Button @click="importBackup"
            icon="ios-arrow-round-up"
    >
      {{$t('modals.import_backup')}}
    </Button>

    <h2>
      {{$t('modals.general_settings')}}
    </h2>
    <general-settings/>

    <div slot="footer">
      <Button size="large" @click="closeModal">
        {{$t('common.close')}}
      </Button>
    </div>
  </Modal>
</template>

<script>
  import boardsRepository from "@/repositories/boardsRepository";
  import GeneralSettings from "./GeneralSettings";
  import UpdatesCheckSettings from "./UpdatesCheckSettings";
  import DatabaseLocation from "./DatabaseLocation";

  const {shell} = require("electron");
  const {dialog} = require("electron").remote;

  export default {
    name: "settings-modal",
    components: {
      DatabaseLocation,
      UpdatesCheckSettings,
      GeneralSettings,
    },
    computed: {
      isVisible() {
        return this.$store.state.modals.settings.isVisible;
      },
      currentVersion() {
        return this.$store.state.modals.settings.currentVersion;
      },
    },
    data() {
      return {};
    },
    methods: {
      open(link) {
        shell.openExternal(link);
      },
      changeLanguage() {
        this.$store.dispatch("showLanguageModal");
      },
      createBackup() {
        const vm = this;
        dialog.showSaveDialog({
          filters: [
            {name: "json", extensions: ["json"]},
          ],
        }, function(fileName) {
          boardsRepository
            .exportDbToJSON(fileName)
            .then(() => {
              vm.$Message.success(this.$t('modals.file_saved_success'));
            })
            .catch((err) => {
              vm.$Message.error({content: err.message, duration: 0, closable: true});
            });
        });
      },
      importBackup() {
        const vm = this;
        dialog.showOpenDialog({
          properties: ["openFile"],
          filters: [
            {name: "json", extensions: ["json"]},
          ],
        }, function(filePath) {
          boardsRepository.importDbFromJSON(filePath[0])
            .then(() => {
              vm.$Message.success(this.$t('modals.file_imported_success'));
              vm.$store.dispatch("fetchBoards");
            })
            .catch((err) => {<commit_msg>If user cancel don't display error message<commit_after><template>
  <Modal :value="isVisible"
         :title="$t('modals.settings')"
         @on-ok="closeModal"
         @on-visible-change="visibleChange"
         :okText="$t('common.add')"
         :scrollable="true"
  >
    <div class="row title-row">
      <div class="title">
        <h2>Backlog</h2>
        <h6>v{{currentVersion}}</h6>
      </div>
      <div class="address"
           @click="open('http://www.backlog.cloud')">
        <a href="#">www.backlog.cloud</a>
      </div>
    </div>

    <Button @click="changeLanguage" icon="md-globe">
      {{$t('modals.change_app_lang')}}
    </Button>

    <updates-check-settings/>

    <h2>
      {{$t('modals.data')}}
    </h2>
    <database-location/>
    <Button @click="createBackup"
            icon="ios-download-outline"
    >
      {{$t('modals.create_backup')}}
    </Button>
    <Button @click="importBackup"
            icon="ios-arrow-round-up"
    >
      {{$t('modals.import_backup')}}
    </Button>

    <h2>
      {{$t('modals.general_settings')}}
    </h2>
    <general-settings/>

    <div slot="footer">
      <Button size="large" @click="closeModal">
        {{$t('common.close')}}
      </Button>
    </div>
  </Modal>
</template>

<script>
  import boardsRepository from "@/repositories/boardsRepository";
  import GeneralSettings from "./GeneralSettings";
  import UpdatesCheckSettings from "./UpdatesCheckSettings";
  import DatabaseLocation from "./DatabaseLocation";

  const {shell} = require("electron");
  const {dialog} = require("electron").remote;

  export default {
    name: "settings-modal",
    components: {
      DatabaseLocation,
      UpdatesCheckSettings,
      GeneralSettings,
    },
    computed: {
      isVisible() {
        return this.$store.state.modals.settings.isVisible;
      },
      currentVersion() {
        return this.$store.state.modals.settings.currentVersion;
      },
    },
    data() {
      return {};
    },
    methods: {
      open(link) {
        shell.openExternal(link);
      },
      changeLanguage() {
        this.$store.dispatch("showLanguageModal");
      },
      createBackup() {
        const vm = this;
        dialog.showSaveDialog({
          filters: [
            {name: "json", extensions: ["json"]},
          ],
        }, function(fileName) {
          boardsRepository
            .exportDbToJSON(fileName)
            .then(() => {
              vm.$Message.success(this.$t('modals.file_saved_success'));
            })
            .catch((err) => {
              if(fileName == ''){
                return;
              }
              
              vm.$Message.error({content: err.message, duration: 0, closable: true});
            });
        });
      },
      importBackup() {
        const vm = this;
        dialog.showOpenDialog({
          properties: ["openFile"],
          filters: [
            {name: "json", extensions: ["json"]},
          ],
        }, function(filePath) {
          boardsRepository.importDbFromJSON(filePath[0])
            .then(() => {
              vm.$Message.success(this.$t('modals.file_imported_success'));
              vm.$store.dispatch("fetchBoards");
            })
            .catch((err) => {
{'fraction_non_alphanumeric': 0.16849357970560602, 'fraction_numerical': 0.0031318509238960224, 'mean_word_length': 2.037089871611983, 'pattern_counts': {'":': 0, '<': 71, '<?xml version=': 0, '>': 79, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3427426', 'n_tokens_mistral': 1909, 'n_tokens_neox': 1895, 'n_words': 292}