DisplayResults.vue 5.68 KB
Newer Older
Quentin David's avatar
Quentin David committed
1
2
<template>
    <v-container fluid>
3
4
        <v-row no-gutters class="fill-height">
            <!-- Left Panel -->
Quentin David's avatar
Quentin David committed
5
6
7
8
9
10
            <v-col cols="3">
              <v-treeview
              class="fixed24"
              :items="items"
              activatable
              return-object
11
              :active.sync="selectionLeft"
Quentin David's avatar
Quentin David committed
12
              >
13
14
15
16
17
18
                <template v-slot:append="{item}">
                  <v-icon 
                    v-if="!isSourceDocumentForIcon(item)"
                    @click="downloadFile(item.link)"  
                  >mdi-download</v-icon>
                </template>
Quentin David's avatar
Quentin David committed
19
              </v-treeview>
Quentin David's avatar
Quentin David committed
20
            </v-col>
21
22
            <!-- Middle Panel -->
            <v-col :cols="mainPanelGridSize">
Quentin David's avatar
Quentin David committed
23
24
25
              <div
              class="pa-5 fixed"
              >
26
27
28
29
30
31
32
33
34
35
36
                <div v-if="selectionLeft != null && selectionLeft[0] != null && selectionLeft[0].content != null">
                  <h1 class="text-center"> {{ selectionLeft[0].content.title }}</h1>
                  <br/>
                  <p class="text-justify" v-html="formatSourceDocument((selectionLeft[0].content.contents))"></p>
                  <!-- <p class="text-justify">{{ formatSourceDocument((selectionLeft[0].content.contents)) }}</p> -->
                </div>
                <div v-else>
                  <h1 class="text-center"> Outil de visualisation </h1>
                  <br>
                  Choisissez un document sur le panneau de gauche.
                </div>
Quentin David's avatar
Quentin David committed
37
              </div>
Quentin David's avatar
Quentin David committed
38
            </v-col>
39
40
            <!-- Right Panel -->
            <v-col cols="3" v-if="isSourceDocument(selectionLeft)">
Quentin David's avatar
Quentin David committed
41
42
              <v-treeview
              class="fixed24"
Quentin David's avatar
Quentin David committed
43
              :items="items_annotation"
Quentin David's avatar
Quentin David committed
44
              activatable
45
46
47
              return-object
              v-model="selectionRight"
              selectable
Quentin David's avatar
Quentin David committed
48
49
              >
              </v-treeview>
Quentin David's avatar
Quentin David committed
50
51
52
53
54
            </v-col>
        </v-row>
    </v-container>
</template>
<script>
55
import axios from 'axios';
Quentin David's avatar
Quentin David committed
56
57
  export default {
    data: () => ({
58
59
      selectionLeft: [],
      selectionRight: [],
Quentin David's avatar
Quentin David committed
60
61
      items_annotation: [
        {
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
          id:1,
          name:'Néologismes - Néoveille (vert)',
          tag_name: 'NEOVEILLE',
          tag_color: 'lightgreen'
        },
        {
          id:2,
          name:"Motifs - SDMC (orange)",
          tag_name: 'SDMC',
          tag_color: 'orange'
        },
        // {
        //   id: 3,
        //   name: 'Entités nommées',
        //   children: [
        //     { id: 4, name: 'Nom', tag_name: 'NAMED_ENTITY_NAME', tag_color: 'chocolate'},
        //     { id: 5, name: 'Lieu',tag_name: 'NAMED_ENTITY_PLACE', tag_color: 'yellow'},
        //     { id: 6, name: 'Date',tag_name: 'NAMED_ENTITY_DATE', tag_color: 'lightblue'}
        //   ]
        // },
        // {
        //   id: 7,
        //   name: 'Locutions - Morfetik',
        //   children: [
        //     { id: 8, name: 'Adverbiale', tag_color: 'chocolate'},
        //     { id: 9, name: 'Noms', tag_color: 'yellow'},
        //   ]
        // },

Quentin David's avatar
Quentin David committed
91
      ],
92
      items2: [
Quentin David's avatar
Quentin David committed
93
94
        {
          id: 1,
Quentin David's avatar
Quentin David committed
95
          name: 'Documents source :',
Quentin David's avatar
Quentin David committed
96
          children: [
Quentin David's avatar
Quentin David committed
97
98
99
            { id: 2, name: 'Fichier1' },
            { id: 3, name: 'Fichier2' },
            { id: 4, name: 'Fichier3' },
Quentin David's avatar
Quentin David committed
100
          ],
Quentin David's avatar
Quentin David committed
101
        }
Quentin David's avatar
Quentin David committed
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
    methods: {
      isSourceDocumentForIcon(item) {
        return (item != null && item.children);
      },
      downloadFile(link) {
        axios({
          url: 'http://localhost:8080' + link,
          method:'GET',
          responseType: 'blob'
        }).then((response) => {
          var fileURL = window.URL.createObjectURL(new Blob([response.data]));
          var fileLink = document.createElement('a');
          fileLink.href = fileURL;
          fileLink.setAttribute('download',link);
          document.body.appendChild(fileLink);
          fileLink.click();
        }).catch(console.error);
        console.log(link);
      },
      isSourceDocument(selection) {
        return (selection != null && selection[0] != null) && selection[0].content != null && (selection[0].id < 5);
      },
      insertBrTags(text) {
        return text.replace(/(?:\r\n|\r|\n)/g, '<br/>');
      },
      setColorTags(text, tag_name, tag_color) {
        var toReplace = tag_name;
        var replace = "span style = \"background-color:" + tag_color + "\"";
        var re = new RegExp(toReplace, "g");

        var updatedText = text.replace(re, replace);
        console.log(updatedText);
        return updatedText;
      },
      formatSourceDocument(text) {
        text = this.insertBrTags(text);
        this.selectionRight.forEach( element => {
          if (element.children && element.children.tag_name) {
            element.children.forEach( child => text = this.setColorTags(text,child.tag_name, child.tag_color) );
            console.log(text);
          }
          else if (element.tag_name) {
            text = this.setColorTags(text,element.tag_name, element.tag_color)
          }
        })
        return text;
      }
    },
    computed : {
      items: function () {
        const items = require('../../json/voixdunord.js').result;
        return items;
      },
      rightPanelOpened: function() {
        return this.isSourceDocument(this.selectionLeft);
      },
      mainPanelGridSize: function() {
        return this.rightPanelOpened ? "6" : "9";
      }
    }
Quentin David's avatar
Quentin David committed
164
  }
Quentin David's avatar
Quentin David committed
165
166
167
168
169
</script>
<style>
.fixed24 {
  background-color: lightblue;
  overflow-y: scroll;
170
171
  min-height: calc(100vh - (48px + 48px + 12px + 12px));

Quentin David's avatar
Quentin David committed
172
173
174
175
176
  border-radius: 5px;
}
.fixed {
  border: 2px solid #00598f;
  overflow-y: scroll;
177
178
  min-height: calc(100vh - (48px + 48px + 12px + 12px));
  max-height: calc(100vh - (48px + 48px + 12px + 12px));
Quentin David's avatar
Quentin David committed
179
180
181
182
  
  border-radius: 5px;
}
</style>