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
<template>
<div id="export_data">
<b-overlay
:show="loading"
rounded="lg"
:style="'padding: 5px;'"
variant="white"
:spinner-small="true"
spinner-type="grow"
spinner-variant="primary"
>
<div
v-if="lastDemand && !isLastDemandFinished"
class="export_data-demande in-progress"
>
<div>
La demande d'export de vos données personnelles du
<i>{{ new Date(lastDemand.creation_date).toLocaleDateString() }}</i> à
<i>{{ new Date(lastDemand.creation_date).toLocaleTimeString([], { hour: '2-digit', minute:'2-digit' }) }}</i>
est en attente.
</div>
</div>
<div
v-else-if="lastDemand && isLastDemandFinished"
class="export_data-demande"
>
<div>
La demande d'export de vos données personnelles du
<i>{{ new Date(lastDemand.creation_date).toLocaleDateString() }}</i> à
<i>{{ new Date(lastDemand.creation_date).toLocaleTimeString([], { hour: '2-digit', minute:'2-digit' }) }}</i>
a aboutie.
</div>
<div style="display: flex; justify-content: center;">
<b-button
variant="success"
@click="downloadPersonalData"
>
Télécharger
</b-button>
</div>
</div>
<b-button
id="export_data-button"
variant="primary"
:disabled="!isLastDemandFinished"
@click="demandPersonalData"
>
{{ $t('profile.personalDataExport.newDemand') }}
</b-button>
</b-overlay>
</div>
</template>
<script>
import personalDataAPI from '@/api/personalDataAPI.js';
import { downloadFile } from '@/utils';
export default {
name: 'PersonalDataExport',
data() {
return {
loading: false,
lastDemand: null
};
},
computed: {
isLastDemandFinished() {
if (this.lastDemand && !this.lastDemand.stop_date) {
return false;
}
return true;
}
},
created() {
this.getDemands();
},
methods: {
async demandPersonalData() {
try {
this.loading = true;
const newDemand = await personalDataAPI.postPersonalDataDemand();
this.lastDemand = newDemand;
this.loading = false;
await this.getDemands();
} catch {
this.loading = false;
}
},
async getDemands() {
try {
this.loading = true;
const demands = await personalDataAPI.getPersonalDataDemands();
if (demands && demands.results && demands.results.length) {
this.lastDemand = demands.results[0];
}
this.loading = false;
} catch {
this.loading = false;
}
},
async downloadPersonalData() {
try {
if (this.lastDemand && this.lastDemand.download_href) {
this.loading = true;
const link = document.createElement('a');
link.href = this.lastDemand.download_href;
link.setAttribute('download', `personal_data-${this.lastDemand.id}`);
link.setAttribute('target', '_blank');
document.body.appendChild(link);
link.click();
link.remove();
this.loading = false;
}
} catch {
this.loading = false;
}
}
}
};
</script>
<style scoped lang="less">
#export_data {
width: 100%;
.export_data-demande {
margin: 0 2px 1.5rem;
padding: 0.5rem 0.75rem;
background-color: #effff4;
border-radius: 2px;
box-shadow: 0px 1px 4px rgba(14, 31, 53, 0.12), 0px 4px 8px rgba(14, 31, 53, 0.08);
color: #495057;
font-weight: 600;
text-align: center;
button {
margin: 0.5rem;
font-weight: 600;
}
}
.export_data-demande.in-progress {
background-color: #fdf6e4;
}
#export_data-button {
width: 100%;
font-size: 1rem;
border: 2px solid #9BD0FF;
border-radius: 8px;
font-weight: 600;
}
}
</style>