AddCorpus.vue 3.74 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>
Quentin David's avatar
Quentin David committed
15
16
17
18
19
          <!-- File input -->
          <FileInputTab 
            :isSelectedTab="isSelectedTab(0)"
            @file-input-update="updateChosenSelection(0, $event)"
          />
Quentin David's avatar
Quentin David committed
20
21
        </v-tab-item>
        <v-tab-item>
Quentin David's avatar
Quentin David committed
22
23
          <!-- Text input -->
          <TextInputTab
24
            :isSelectedTab="isSelectedTab(1)"
Quentin David's avatar
Quentin David committed
25
            @text-input-update="updateChosenSelection(1, $event)"
26
          />
Quentin David's avatar
Quentin David committed
27
28
        </v-tab-item>
        <v-tab-item>
29
          <!-- Profile text -->
30
31
          <ProfileCorporaTab
            :isSelectedTab="isSelectedTab(2)"
Quentin David's avatar
Quentin David committed
32
            @profile-corpora-update="updateChosenSelection(2, $event)"
33
          />
Quentin David's avatar
Quentin David committed
34
35
        </v-tab-item>
        <v-tab-item>
36
          <!-- Shared corpus -->
37
38
          <PublicCorporaTab
            :isSelectedTab="isSelectedTab(3)"
Quentin David's avatar
Quentin David committed
39
            @public-corpora-update="updateChosenSelection(3,$event)"
40
          />
Quentin David's avatar
Quentin David committed
41
42
43
44
        </v-tab-item>
      </v-tabs-items>
    </v-tabs>
  </v-container>
45
46
</template>
<script>
Quentin David's avatar
Quentin David committed
47
48
import TextInputTab from '@/components/DefineCorpus/CorpusTabs/TextInputTab';
import FileInputTab from '@/components/DefineCorpus/CorpusTabs/FileInputTab';
49
50
import ProfileCorporaTab from '@/components/DefineCorpus/CorpusTabs/ProfileCorporaTab';
import PublicCorporaTab from '@/components/DefineCorpus/CorpusTabs/PublicCorporaTab';
51

Quentin David's avatar
Quentin David committed
52
53
const FILE_INPUT = 0, TEXT_INPUT = 1, PROFILE_CORPUS = 2, PUBLIC_CORPUS = 3;

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