aboutsummaryrefslogtreecommitdiffstats
path: root/dashboard/src/views/Admin.vue
blob: 414e68a0da16bdfa2f606357a03bcf1333d929e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<template>
  <div>
    <div v-if="isLoading" >
      <div class="d-flex justify-content-center">
        <div class="spinner-border" role="status">
          <span class="sr-only">Loading...</span>
        </div>
      </div>
    </div>
    <div  v-else class="row justify-content-center">
      <label for="file" class="label-file btn btn-primary">
        <span class="fa fa-upload"></span>
        Import
      </label>
      <input
              id="file"
              class="input-file"
              type="file"
              @change="readFile"
              accept="application/json, .json"
      />


  </div>
  </div>
</template>

<script>
import ImportService from "./../services/Import.service.js";

export default {
  data(){
    return {
      isLoading: false
    }
  },
  methods: {
     readFile(event) {
      var reader = new FileReader();
      reader.onload = async function() {
        this.isLoading = true;
        var fileContents = reader.result;
        await ImportService.importData(JSON.parse(fileContents));
        this.isLoading = false;
      }.bind(this);
       reader.readAsText(event.target.files[0]);
    },
  }
};
</script>