-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
209 lines (174 loc) · 6.29 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
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<!DOCTYPE html>
<html>
<head>
<title>HelloAsso to Dolibarr Members/Subscriptions</title>
<link rel="stylesheet" href="css/bulma.css">
<link rel="stylesheet" href="https://bulma.io/vendor/fontawesome-free-5.15.2-web/css/all.min.css">
<style>
textarea {
font-family: monospace;
}
</style>
</head>
<body>
<header>
<nav class="navbar is-primary level" role="navigation">
<div class="level-item has-text-centered navbar-brand">
<a class="navbar-item title" href=".">
HelloAsso ➡ Dolibarr
</a>
</div>
</nav>
</header>
<main class="container">
<section class="section" id="helloasso-records">
<h1 class="title">HelloAsso CSV</h1>
<div class="block">
<div class="file is-medium is-primary">
<label class="file-label">
<input class="file-input" type="file" accept=".csv" name="helloasso-csv-file">
<span class="file-cta">
<span class="file-icon mr-4">
<i class="fas fa-file"></i>
</span>
<span class="file-label">
Sélection du fichier CSV HelloAsso
</span>
</span>
</label>
</div>
</div>
<div class="block">
<div class="notification is-info is-light">
<p>
<i class="fas fa-user-shield fa-lg mr-2"></i>
Le fichier ne sera pas transmis sur Internet : toutes les opérations s'effectuent sur cette page, "hors ligne".
</p>
</div>
</div>
<div class="block table-container">
<table class="table is-striped" hidden>
<thead>
</thead>
<tbody>
</tbody>
</table>
</div>
</section>
<div class="columns">
<div class="column is-half">
<section class="section" id="dolibarr-members">
<h1 class="title">Dolibarr — Membres</h1>
<div class="block">
<a disabled download="dolibarr-members.csv" type="text/csv" class="button is-large">
<span class="icon">
<i class="fas fa-arrow-circle-down"></i>
</span>
<span>Télécharger</span>
</a>
</div>
<div class="block table-container">
<table class="table is-fullwidth is-striped" hidden>
<thead>
</thead>
<tbody>
</tbody>
</table>
</div>
</section>
</div>
<div class="column is-half">
<section class="section" id="dolibarr-subscriptions">
<h1 class="title">Dolibarr — Adhésions</h1>
<div class="block">
<a disabled download="dolibarr-subscriptions.csv" type="text/csv" class="button is-large">
<span class="icon">
<i class="fas fa-arrow-circle-down"></i>
</span>
<span>Télécharger</span>
</a>
</div>
<div class="block table-container">
<table class="table is-fullwidth is-striped" hidden>
<thead>
</thead>
<tbody>
</tbody>
</table>
</div>
</section>
</div>
</div>
</main>
<script src="js/papaparse.js"></script>
<script type="module">
import { helloassoSubscriptionToDolibarrMember } from './js/convert.js'
import { helloassoSubscriptionToDolibarrSubscription } from './js/convert.js'
const $ = (...args) => document.querySelector(...args)
const $$ = (...args) => document.querySelectorAll(...args)
function onCsvReceived (data) {
const { members, subscriptions } = convert(data)
// HelloAsso
displayObjects({ el: $('#helloasso-records table'), data, allowedHeaders: [
'Numéro',
'Montant adhésion',
'Nom',
'Prénom',
'Société',
'Date',
'Email',
] })
// Members
displayObjects({ el: $('#dolibarr-members table'), data: members })
prepareDownload({
el: $('#dolibarr-members a[download]'),
csv: Papa.unparse(members, { header: false })
})
// Subscribers
prepareDownload({
el: $('#dolibarr-subscriptions a[download]'),
csv: Papa.unparse(subscriptions, { header: false })
})
}
function prepareDownload ({ el, csv }) {
const blob = new Blob([csv], { type: 'text/csv' })
const url = URL.createObjectURL(blob)
el.removeAttribute('disabled')
el.classList.add('is-primary')
el.setAttribute('href', url)
}
function convert (parsedCsv) {
const members = parsedCsv.map(row => helloassoSubscriptionToDolibarrMember(row))
const subscriptions = parsedCsv.map(row => helloassoSubscriptionToDolibarrSubscription(row))
return { members, subscriptions }
}
function displayObjects ({ el, data, allowedHeaders }) {
const allowedHeadersLength = Array.isArray(allowedHeaders) ? allowedHeaders.length : 0
// Fill headers
const headers = Object.keys(data[0])
.filter(key => allowedHeadersLength === 0 || allowedHeaders.includes(key))
.map(key => `<th>${key}</th>`)
.join('')
el.querySelector('thead').innerHTML = `<tr>${headers}</tr>`
// Fill body rows
el.querySelector('tbody').innerHTML = data.reduce((html, record) => {
const columns = Object.entries(record)
.filter(([key, value]) => allowedHeadersLength === 0 || allowedHeaders.includes(key))
.map(([key, value]) => `<td>${value}</td>`)
.join('')
return `${html}<tr>${columns}</tr>`
}, '')
// Prepare table
el.removeAttribute('hidden')
}
$('#helloasso-records input[type="file"]').addEventListener('input', (event) => {
const [file] = event.target.files
Papa.parse(file, {
header: true,
skipEmptyLines: true,
complete: ({ data }) => onCsvReceived(data)
})
})
</script>
</body>
</html>