AddCorpus.vue 3.6 KB
Newer Older
1
<template>
Quentin David's avatar
Quentin David committed
2
3
4
  <v-container flex fill-height>
    <v-tabs grow
      v-model="tab"
5
    >
Quentin David's avatar
Quentin David committed
6
7
8
9
      <v-tab
        v-for="item in tab_items"
        :key="item.tab"
      >
Quentin David's avatar
Quentin David committed
10
        {{ $t(item.tab) }}
Quentin David's avatar
Quentin David committed
11
      </v-tab>
12

Quentin David's avatar
Quentin David committed
13
14
      <v-tabs-items v-model="tab" class="my-4" vertical>
        <v-tab-item>
15
          <!-- Local files -->
16
          <LocalFilesTab :isSelectedTab="isSelectedTab(0)"/>
Quentin David's avatar
Quentin David committed
17
18
        </v-tab-item>
        <v-tab-item>
19
          <!-- Input text -->
20
21
22
23
          <InputTextTab
            :isSelectedTab="isSelectedTab(1)"
            @input-text-update="updateChosenCorpus(1, $event)"
          />
Quentin David's avatar
Quentin David committed
24
25
        </v-tab-item>
        <v-tab-item>
26
          <!-- Profile text -->
27
28
29
30
          <ProfileCorporaTab
            :isSelectedTab="isSelectedTab(2)"
            @profile-corpora-update="updateChosenCorpus(2, $event)"
          />
Quentin David's avatar
Quentin David committed
31
32
        </v-tab-item>
        <v-tab-item>
33
          <!-- Shared corpus -->
34
35
36
37
          <PublicCorporaTab
            :isSelectedTab="isSelectedTab(3)"
            @public-corpora-update="updateChosenCorpus(3,$event)"
          />
Quentin David's avatar
Quentin David committed
38
39
40
41
        </v-tab-item>
      </v-tabs-items>
    </v-tabs>
  </v-container>
42
43
</template>
<script>
44
45
46
47
import InputTextTab from '@/components/DefineCorpus/CorpusTabs/InputTextTab';
import LocalFilesTab from '@/components/DefineCorpus/CorpusTabs/LocalFilesTab';
import ProfileCorporaTab from '@/components/DefineCorpus/CorpusTabs/ProfileCorporaTab';
import PublicCorporaTab from '@/components/DefineCorpus/CorpusTabs/PublicCorporaTab';
48

49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
export default {
  data: () => ({
      tab: null,
      tab_items: [
        { tab: 'local-file', content: 'Fichier local'},
        { tab: 'input-text', content: 'Champ de texte'},
        { tab: 'profile-corpus', content: 'Corpora du profil'},
        { tab: 'public-corpus', content: 'Corpora publics'},
      ],
      selected: null,
      test: { "fr": false, "en": false},
      inputText: '',
      profileCorpus : null,
      publicCorpus: null
  }),
  components: {
    InputTextTab,
    LocalFilesTab,
    ProfileCorporaTab,
    PublicCorporaTab
  },
  methods: {
    isSelectedTab(tabNumber) {
      return tabNumber == this.tab;
    },
    // emit here ?
    // { activeTab: tabName, corpus: corpus}
    updateChosenCorpus(tabNumber, corpus) {
      switch (tabNumber) {
        case 0:
          this.localFile = corpus;
          break;
        case 1:
          this.inputText = corpus;
          break;
        case 2:
          this.profileCorpus = corpus;
          break;
        case 3:
          this.publicCorpus = corpus;
          break;
      }
      this.emitUpdate(tabNumber, corpus);
    },
    emitUpdate(tabNumber, corpus) {
      const tabNumberToString = { 0: 'local-file', 1: 'input-text', 2: 'profile-corpus', 3: 'public-corpus'};
      // If this function is called when tabNumber !== this.tab
      // this means that we asked for a reset of 'tabNumber'
      // So we can emit corpus null
      if (!this.isSelectedTab(tabNumber)) {
        this.$emit('chosen-corpus-update', { activeTab: tabNumberToString[this.tab], corpus: null});
100
      }
101
102
103
104
105
      // Else it means the user has just modified in the same tab its input
      else {
        this.$emit('chosen-corpus-update', { activeTab: tabNumberToString[tabNumber], corpus: corpus });
      }
    }
106
  }
107
}
Quentin David's avatar
Quentin David committed
108
109
110
111
112
113
114
</script>
<i18n>
{
  "fr":{
    "local-file":"Depuis un fichier local",
    "input-text":"Depuis un champ de texte",
    "profile-corpus":"Depuis un corpus du profil",
115
    "public-corpus":"Depuis un corpus partagé"
Quentin David's avatar
Quentin David committed
116
117
118
119
120
  },
  "en":{
    "local-file":"From a local file",
    "input-text":"From a text field",
    "profile-corpus":"From a profile corpus",
121
    "public-corpus":"From a shared corpus"
Quentin David's avatar
Quentin David committed
122
123
124
  }
}
</i18n>