PreValidation.vue 3.69 KB
Newer Older
1
<template>
Quentin David's avatar
Quentin David committed
2
3
4
5
6
7
8
9
10
  <v-container class="my-5">
    <div v-if="errorMessage">
      <v-alert type="error">{{ errorMessage}}</v-alert>
    </div>
    <div v-else>
      <v-card outlined class="my-5 px-6">
        <v-card-title class="justify-center py-6">
          <h1 class="display-3">Pré-Validation</h1>
        </v-card-title>
11

Quentin David's avatar
Quentin David committed
12
13
14
15
16
17
18
19
20
21
        <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>
22

Quentin David's avatar
Quentin David committed
23
24
25
26
27
28
29
        <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>
30
        </v-card>
Quentin David's avatar
Quentin David committed
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
      </v-card>
      <v-btn block color="success" @click="submitCorpusProcess"> Valider </v-btn>
    </div>
  </v-container>
</template>
<script>
import axios from  '@/plugins/axios';
import CorporaCard from '@/components/UserPages/ProfileCorporaList/CorporaCard.vue';
import PipelineCard from '@/components/UserPages/PipelineCard.vue';

export default {
  data: () => ({
    corpusSummary: null,
    pipeline: null,
    errorMessage: null
  }),
  created() {
    this.fetchCorpus();
    this.fetchPipeline();
  },
  methods: {
    // Get the corpus from session storage
    fetchCorpus() {
      const corpusId = sessionStorage.getItem('corpusId');
      if (corpusId) {
        axios.get(`/corpora/${corpusId}/summary`)
        .then( res => {
          if (res.data.status !== "success") {
            this.errorMessage = res.data.message
          }
          else {
            this.corpusSummary = res.data.data.corpusSummary;
          }
        })
        .catch( error => {
          this.errorMessage = error;
        });
      }
      else {
        this.errorMessage = "Could not get corpusId from SessionStorage. Maybe user fetched this page without following the normal steps."
      }
    },
    // Get the pipeline from session storage
    // TODO: handle multiple errors
    fetchPipeline() {
      const pipelineId = sessionStorage.getItem('pipelineId');
      if (pipelineId) {
        axios.get(`/pipelines/${pipelineId}`)
        .then( res => {
          if ( res.data.status !== "success") {
            console.log("Fetching pipeline error:")
            console.error(res.data.message);
            this.errorMessage = res.data.message;
          }
          else {
            this.pipeline = res.data.data.pipeline;
          }
        })
        .catch (error => {
          console.log("Fetching pipeline error:");
          console.error(error);
          this.errorMessage = error;
        });
      }
    },
    // Post and start the corpus process given the corpus and the pipeline
97
    async submitCorpusProcess() {
Quentin David's avatar
Quentin David committed
98
99
100
101
102
      const data = {
        corpusId: sessionStorage.getItem('corpusId'),
        pipelineId: sessionStorage.getItem('pipelineId'),
        userId:'5f60db3f30dee22c7d6f6058' // DUMMY ID
      }
103
104
105
106
      try {
        // Create corpus process
        const res = await axios.post('/corpusProcesses', data);
        const corpusProcessId = res.data.data.corpusProcess._id;
107
108
        //Stores it
        sessionStorage.setItem('corpusProcessId', corpusProcessId);
109
110
111
112
113
        // Starts it
        await axios.post(`/corpusProcesses/${corpusProcessId}/start`);
        this.$router.push('/validation');
      }
      catch (error)  {
Quentin David's avatar
Quentin David committed
114
115
        console.error(error);
        this.errorMessage = error;
116
      }
Quentin David's avatar
Quentin David committed
117
118
119
120
121
122
123
124
    }
  },
  components: {
    CorporaCard,
    PipelineCard
  }
}
</script>