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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
|
<!--
Matomo - free/libre analytics platform
@link https://matomo.org
@license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
-->
<template>
<div class="anonymizeLogData">
<div class="form-group row">
<div class="col s12 input-field">
<div>
<label
for="anonymizeSite"
class="siteSelectorLabel"
>{{ translate('PrivacyManager_AnonymizeSites') }}</label>
<div class="sites_autocomplete">
<SiteSelector
id="anonymizeSite"
v-model="site"
:show-all-sites-item="true"
:switch-site-on-select="false"
:show-selected-site="true"
/>
</div>
</div>
</div>
</div>
<div class="form-group row">
<div class="col s6 input-field">
<div>
<label
for="anonymizeStartDate"
class="active"
>{{ translate('PrivacyManager_AnonymizeRowDataFrom') }}</label>
<input
type="text"
id="anonymizeStartDate"
class="anonymizeStartDate"
ref="anonymizeStartDate"
name="anonymizeStartDate"
:value="startDate"
@keydown="onKeydownStartDate($event)"
@change="onKeydownStartDate($event)"
/>
</div>
</div>
<div class="col s6 input-field">
<div>
<label
for="anonymizeEndDate"
class="active"
>{{ translate('PrivacyManager_AnonymizeRowDataTo') }}</label>
<input
type="text"
class="anonymizeEndDate"
id="anonymizeEndDate"
ref="anonymizeEndDate"
name="anonymizeEndDate"
:value="endDate"
@keydown="onKeydownEndDate($event)"
@change="onKeydownEndDate($event)"
/>
</div>
</div>
</div>
<div name="anonymizeIp">
<Field
uicontrol="checkbox"
name="anonymizeIp"
:title="translate('PrivacyManager_AnonymizeIp')"
v-model="anonymizeIp"
:introduction="translate('General_Visit')"
:inline-help="translate('PrivacyManager_AnonymizeIpHelp')"
>
</Field>
</div>
<div name="anonymizeLocation">
<Field
uicontrol="checkbox"
name="anonymizeLocation"
:title="translate('PrivacyManager_AnonymizeLocation')"
v-model="anonymizeLocation"
:inline-help="translate('PrivacyManager_AnonymizeLocationHelp')"
>
</Field>
</div>
<div name="anonymizeTheUserId">
<Field
uicontrol="checkbox"
name="anonymizeTheUserId"
:title="translate('PrivacyManager_AnonymizeUserId')"
v-model="anonymizeUserId"
:inline-help="translate('PrivacyManager_AnonymizeUserIdHelp')"
>
</Field>
</div>
<div class="form-group row">
<div class="col s12 m6">
<div>
<label for="visit_columns">{{ translate('PrivacyManager_UnsetVisitColumns') }}</label>
<div
:class="`selectedVisitColumns selectedVisitColumns${index} multiple valign-wrapper`"
v-for="(visitColumn, index) in selectedVisitColumns"
:key="index"
>
<div class="innerFormField" name="visit_columns">
<Field
uicontrol="select"
name="visit_columns"
:model-value="visitColumn.column"
@update:model-value="visitColumn.column = $event; onVisitColumnChange()"
:full-width="true"
:options="availableVisitColumns"
>
</Field>
</div>
<span
class="icon-minus valign"
@click="removeVisitColumn(index)"
v-show="index + 1 !== selectedVisitColumns.length"
:title="translate('General_Remove')"
/>
</div>
</div>
</div>
<div class="col s12 m6">
<div class="form-help">
<span class="inline-help">{{ translate('PrivacyManager_UnsetVisitColumnsHelp') }}</span>
</div>
</div>
</div>
<div class="form-group row">
<div class="col s12">
<h3>{{ translate('General_Action') }}</h3>
</div>
</div>
<div class="form-group row">
<div class="col s12 m6">
<div>
<label for="action_columns">{{ translate('PrivacyManager_UnsetActionColumns') }}</label>
<div
:class="`selectedActionColumns selectedActionColumns${index} multiple valign-wrapper`"
v-for="(actionColumn, index) in selectedActionColumns"
:key="index"
>
<div class="innerFormField" name="action_columns">
<Field
uicontrol="select"
name="action_columns"
:model-value="actionColumn.column"
@update:model-value="actionColumn.column = $event; onActionColumnChange()"
:full-width="true"
:options="availableActionColumns"
>
</Field>
</div>
<span
class="icon-minus valign"
@click="removeActionColumn(index)"
v-show="index + 1 !== selectedActionColumns.length"
:title="translate('General_Remove')"
/>
</div>
</div>
</div>
<div class="col s12 m6">
<div class="form-help">
<span class="inline-help">{{ translate('PrivacyManager_UnsetActionColumnsHelp') }}</span>
</div>
</div>
</div>
<p><span class="icon-info" /> {{ translate('PrivacyManager_AnonymizeProcessInfo') }}</p>
<SaveButton
class="anonymizePastData"
@confirm="scheduleAnonymization()"
:disabled="isAnonymizePastDataDisabled"
:value="translate('PrivacyManager_AnonymizeDataNow')"
>
</SaveButton>
<div
class="ui-confirm"
id="confirmAnonymizeLogData"
ref="confirmAnonymizeLogData"
>
<h2>{{ translate('PrivacyManager_AnonymizeDataConfirm') }}</h2>
<input
role="yes"
type="button"
:value="translate('General_Yes')"
/>
<input
role="no"
type="button"
:value="translate('General_No')"
/>
</div>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import {
Matomo,
AjaxHelper,
SiteSelector,
debounce,
} from 'CoreHome';
import { Field, SaveButton } from 'CorePluginsAdmin';
interface Option {
key: string;
value: string;
}
interface AnonymizeLogDataState {
isLoading: boolean;
isDeleting: boolean;
anonymizeIp: boolean;
anonymizeLocation: boolean;
anonymizeUserId: boolean;
site: Record<string, string>;
availableVisitColumns: Option[];
availableActionColumns: Option[];
selectedVisitColumns: Record<string, string>[];
selectedActionColumns: Record<string, string>[];
startDate: string;
endDate: string;
}
function sub(value: number) {
if (value < 10) {
return `0${value}`;
}
return value;
}
export default defineComponent({
components: {
SiteSelector,
Field,
SaveButton,
},
data(): AnonymizeLogDataState {
const now = new Date();
const startDate = `${now.getFullYear()}-${sub(now.getMonth() + 1)}-${sub(now.getDay() + 1)}`;
return {
isLoading: false,
isDeleting: false,
anonymizeIp: false,
anonymizeLocation: false,
anonymizeUserId: false,
site: {
id: 'all',
name: 'All Websites',
},
availableVisitColumns: [],
availableActionColumns: [],
selectedVisitColumns: [{
column: '',
}],
selectedActionColumns: [{
column: '',
}],
startDate,
endDate: startDate,
};
},
created() {
this.onKeydownStartDate = debounce(this.onKeydownStartDate, 50);
this.onKeydownEndDate = debounce(this.onKeydownEndDate, 50);
AjaxHelper.fetch<{ column_name: string }[]>({
method: 'PrivacyManager.getAvailableVisitColumnsToAnonymize',
}).then((columns) => {
this.availableVisitColumns = [];
columns.forEach((column) => {
this.availableVisitColumns.push({
key: column.column_name,
value: column.column_name,
});
});
});
AjaxHelper.fetch<{ column_name: string }[]>({
method: 'PrivacyManager.getAvailableLinkVisitActionColumnsToAnonymize',
}).then((columns) => {
this.availableActionColumns = [];
columns.forEach((column) => {
this.availableActionColumns.push({
key: column.column_name,
value: column.column_name,
});
});
});
setTimeout(() => {
const options1 = Matomo.getBaseDatePickerOptions(null);
const options2 = Matomo.getBaseDatePickerOptions(null);
$(this.$refs.anonymizeStartDate as HTMLElement).datepicker(options1);
$(this.$refs.anonymizeEndDate as HTMLElement).datepicker(options2);
});
},
methods: {
onVisitColumnChange() {
const hasAll = this.selectedVisitColumns.every((col) => !!col?.column);
if (hasAll) {
this.addVisitColumn();
}
},
addVisitColumn() {
this.selectedVisitColumns.push({ column: '' });
},
removeVisitColumn(index: number) {
if (index > -1) {
const lastIndex = this.selectedVisitColumns.length - 1;
if (lastIndex === index) {
this.selectedVisitColumns[index] = { column: '' };
} else {
this.selectedVisitColumns.splice(index, 1);
}
}
},
onActionColumnChange() {
const hasAll = this.selectedActionColumns.every((col) => !!col?.column);
if (hasAll) {
this.addActionColumn();
}
},
addActionColumn() {
this.selectedActionColumns.push({ column: '' });
},
removeActionColumn(index: number) {
if (index > -1) {
const lastIndex = this.selectedActionColumns.length - 1;
if (lastIndex === index) {
this.selectedActionColumns[index] = {
column: '',
};
} else {
this.selectedActionColumns.splice(index, 1);
}
}
},
scheduleAnonymization() {
let date = `${this.startDate},${this.endDate}`;
if (this.startDate === this.endDate) {
date = this.startDate;
}
const params: QueryParameters = { date };
params.idSites = this.site.id;
params.anonymizeIp = this.anonymizeIp ? '1' : '0';
params.anonymizeLocation = this.anonymizeLocation ? '1' : '0';
params.anonymizeUserId = this.anonymizeUserId ? '1' : '0';
params.unsetVisitColumns = this.selectedVisitColumns.filter(
(c) => !!c?.column,
).map((c) => c.column);
params.unsetLinkVisitActionColumns = this.selectedActionColumns.filter(
(c) => !!c?.column,
).map((c) => c.column);
Matomo.helper.modalConfirm(this.$refs.confirmAnonymizeLogData as HTMLElement, {
yes: () => {
AjaxHelper.post({
method: 'PrivacyManager.anonymizeSomeRawData',
}, params).then(() => {
window.location.reload(true);
});
},
});
},
onKeydownStartDate(event: Event) {
this.startDate = (event.target as HTMLInputElement).value;
},
onKeydownEndDate(event: Event) {
this.endDate = (event.target as HTMLInputElement).value;
},
},
computed: {
isAnonymizePastDataDisabled(): boolean {
return !this.anonymizeIp && !this.anonymizeLocation && !this.selectedVisitColumns
&& !this.selectedActionColumns;
},
},
});
</script>
|