-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
96 lines (95 loc) · 3.58 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<link href='https://fonts.googleapis.com/css?family=Roboto:300,400,500,700|Material+Icons' rel="stylesheet">
<link href="https://unpkg.com/vuetify/dist/vuetify.min.css" rel="stylesheet">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, minimal-ui">
</head>
<body>
<div id="app">
<v-app>
<v-content>
<v-container fluid fill-height>
<v-layout align-center justify-center>
<v-flex xs12 sm8 md4>
<v-card class="elevation-12">
<v-toolbar align-center justify-center dark color="primary">
<v-toolbar-title >Générateur de Tableaux</v-toolbar-title>
</v-toolbar>
<v-card-text style="text-align: center;" ondrop="drop_handler(event);" ondragenter="dragenter_handler(event);" ondragleave="dragleave_handler(event);" ondragover="allowDrop(event);">
<v-icon v-bind:color="iconColor" >file_upload</v-icon>
<br>
Déposez le fichier ici
<br>
<v-btn v-bind:download="fnameBtn" v-bind:href="hrefBtn" v-bind:disabled="disableBtn" color="primary">Télécharger</v-btn>
</v-card-text>
</v-card>
</v-flex>
</v-layout>
</v-container>
<v-content>
</v-app>
</div>
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<script src="https://unpkg.com/vuetify/dist/vuetify.js"></script>
<script>
function sortScore(line) {
return parseInt(line.cat.charCodeAt(0) + '' + line.cat.charCodeAt(1) + '' + line.cat.charCodeAt(2) + '' + line.date.split('/')[2] + '' + line.date.split('/')[1] + '' + line.date.split('/')[0]);
}
function allowDrop(e) {
e.preventDefault();
}
function drop_handler(e) {
e.preventDefault();
app.iconColor = '';
app.fnameBtn = 'format_' + e.dataTransfer.files[0].name + (e.dataTransfer.files[0].name.endsWith('csv') ? '' : '.csv');
var file = e.dataTransfer.files[0],
reader = new FileReader();
reader.onload = function(event) {
app.fileContent = event.target.result;
try {
var result = [];
var lines = event.target.result.split('\n');
for (let i in lines) {
if (i == 0 || i == lines.length - 1) continue;
var line = lines[i].split(' ');
result.push({
date: line[1],
client: line[4],
cat: line[15],
com: line[16],
total_ht: line[20]
});
}
result.sort((a, b) => { return sortScore(a) - sortScore(b); });
var file_output = '"' + lines[0].split(' ')[1] + '","' + lines[0].split(' ')[4] + '","' + lines[0].split(' ')[15] + '","' + lines[0].split(' ')[16] + '","' + lines[0].split(' ')[20].trim() + '"\n' + result.map((item, index) => {
return '"' + item.date.trim() + '","' + item.client.trim() + '","' + item.cat.trim() + '","' + item.com.trim() + '","' + item.total_ht.trim() + '"';
}).join('\n') + '\n"' + lines[lines.length - 1].split(' ')[1] + '","' + lines[lines.length - 1].split(' ')[4] + '","' + lines[lines.length - 1].split(' ')[15] + '","' + lines[lines.length - 1].split(' ')[16] + '","' + lines[lines.length - 1].split(' ')[20].trim() + '"';
app.hrefBtn = 'data:text/plain;charset=utf-8,' + encodeURIComponent(file_output);
app.disableBtn = false;
} catch(ex) {
console.log(ex);
}
};
reader.readAsText(file);
return false;
}
function dragenter_handler(event) {
app.iconColor = 'primary';
}
function dragleave_handler(event) {
app.iconColor = '';
}
var app = new Vue({
el: '#app',
data: {
iconColor: '',
fileContent: '',
disableBtn: true,
hrefBtn: '',
fnameBtn: ''
}
});
</script>
</body>
</html>