CheckCorpusProcess.vue 5.12 KB
Newer Older
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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<template>
  <v-container class="my-5">
    <v-card outlined class="my-5 px-6">
      <v-card-title class="justify-center py-6">
        <h1 class="display-3"> {{ $t('corpus-process-title' )}}</h1>
      </v-card-title>
      <div v-if="this.corpusProcess">

        <!-- État du traitement -->
        <v-card outlined class="my-5">
          <v-card-title class="justify-center py-6">
            <h2 class="display-1"> État du traitement </h2>
          </v-card-title>
          <v-card-text>
            <CorpusProcessCard 
              class="my-5"
              :corpusProcess="corpusProcess"
              :corpusProcessFiles="corpusProcessFiles"/>
          </v-card-text>
        </v-card>

        <!-- Corpus -->
        <v-card outlined class="my-5">
          <v-card-title class="justify-center py-6">
            <h2 class="display-1"> Corpus</h2>
          </v-card-title>
          <v-card-text>
            <CorporaCard 
              class="my-5"
              :corpus="corpusSummary"/>
          </v-card-text>
        </v-card>

        <!-- Chaîne de traitement -->
        <v-card outlined class="my-5">
          <v-card-title class="justify-center py-6">
            <h2 class="display-1"> Chaîne de traitement</h2>
          </v-card-title>
          <v-card-text>
            <PipelineCard :pipeline="pipeline"/>
          </v-card-text>
        </v-card>
      </div>

      <!-- Alerts -->
      <div>
        <v-alert type="error" dismissible v-model="errorMessageToggle"> {{ errorMessage }}
        </v-alert>
      </div>

    </v-card>
  </v-container>
</template>
<script>
import axios from '@/plugins/axios'
import CorporaCard from '@/components/UserPages/ProfileCorporaList/CorporaCard.vue';
import PipelineCard from '@/components/UserPages/PipelineCard.vue';
import CorpusProcessCard from '@/components/CheckCorpusProcess/CorpusProcessCard.vue';



export default {
  name: 'CheckCorpusProcess',
  components: {
    CorporaCard,
    PipelineCard,
    CorpusProcessCard
  },
  data: () => ({
    corpusProcess: null,
    corpusSummary: null,
    pipeline: null,
    corpusProcessFiles: null,
    errorMessageToggle: false,
    errorMessage: null,
  }),
  async mounted () {
    this.corpusProcess = await this.fetchCorpusProcess(this.$route.params.corpusprocessid);
    await this.fetchCorpus();
    await this.fetchPipeline();
    if (this.corpusProcess.status == 'Finished') {
      await this.fetchConlluAndProcessOutputsData();
    }
  },
  methods: {
    fetchCorpusProcess: async function(corpusProcessId) {
      try {
        const corpusProcessRes = await axios.get(`/corpusProcesses/${corpusProcessId}`);
        console.log(corpusProcessRes);
        const corpusProcess = corpusProcessRes.data.data.corpusProcess;
        return corpusProcess;
      }
      catch (error) {
        if (error.response) {
          this.errorMessageToggle = true;
          console.log(error.response);
          if (error.response.status == 500) {
            this.errorMessage = "Server error, bad request?"
          }
          else if (error.response.status == 404) {
            this.errorMessage = "Corpus Process not found"
          }

          console.log("Received error response")
        }
        else if (error.request) {
          this.errorMessageToggle = true;
          this.errorMessage = "Never received any responses, is server up?";
          console.log("Never received any responses, or request never left");
        }
        else {
          console.log("Something else");
        }
        console.error(error);
        return null;
      }
    },
    fetchCorpus: async function() {
      // No corpus process retrieved
      if (!this.corpusProcess) {
        return null;
      }
      const corpusId = this.corpusProcess.corpusId;
      try {
        const corpusRes = await axios.get(`/corpora/${corpusId}/summary`);
        this.corpusSummary = corpusRes.data.data.corpusSummary;
      }
      catch(error) {
        console.error("There was an error while trying to fetch corpus:");
        console.error(error);
      }
    },
    fetchPipeline: async function() {
      // No corpus process retrieved
      if (!this.corpusProcess) {
        return null;
      }
      const pipelineId = this.corpusProcess.pipelineId;
      try {
        const pipelineRes = await axios.get(`/pipelines/${pipelineId}`);
        this.pipeline = pipelineRes.data.data.pipeline;
      }
      catch (error) {
        console.error('There was an error while trying to fetch pipeline:');
        console.error(error);
      }
    },
    fetchConlluAndProcessOutputsData: async function() {
      const corpusProcessId = this.corpusProcess._id;
      try {
        const fetchedDataRes = await axios({
          url: 'http://localhost:3001/get-files/'+corpusProcessId,
          method: 'GET',
          // responseType: 'blob',
        });
        this.corpusProcessFiles = fetchedDataRes.data.data;
      }
      catch(error) {
        console.error(error);
      }
    }
  }
}
</script>
<i18n>
{
  "fr": {
    "corpus-process-title": "Traitement de votre corpus",
    "next": "Suivant"
  },
  "en": {
    "corpus-process-title": "Your corpus process",
    "next": "Next"
  }
}
</i18n>