js/viewer.js   A
last analyzed

Complexity

Total Complexity 7
Complexity/F 2.33

Size

Lines of Code 46
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 26
c 0
b 0
f 0
dl 0
loc 46
rs 10
wmc 7
mnd 4
bc 4
fnc 3
bpm 1.3333
cpm 2.3333
noi 0
1
/**
2
 * Analytics
3
 *
4
 * SPDX-FileCopyrightText: 2019-2022 Marcel Scherello
5
 * SPDX-License-Identifier: AGPL-3.0-or-later
6
 */
7
8
/** global: OCA */
9
/** global: OCP */
10
/** global: OC */
11
'use strict';
12
13
if (!OCA.Analytics) {
14
    /**
15
     * @namespace
16
     */
17
    OCA.Analytics = {};
18
}
19
/**
20
 * @namespace OCA.Analytics.Viewer
21
 */
22
OCA.Analytics.Viewer = {
23
24
    registerFileActions: function () {
25
        let mime_array = ['text/csv'];
26
        let icon_url = OC.imagePath('analytics', 'app-dark');
27
28
        for (let i = 0; i < mime_array.length; i++) {
29
            let mime = mime_array[i];
30
            OCA.Files.fileActions.registerAction({
31
                name: 'analytics',
32
                displayName: t('analytics', 'Show in Analytics'),
33
                mime: mime,
34
                permissions: OC.PERMISSION_READ,
35
                icon: icon_url,
36
                actionHandler: OCA.Analytics.Viewer.importFile
37
            });
38
        }
39
    },
40
41
    importFile: function (file, data) {
42
        file = encodeURIComponent(file);
43
        let dirLoad = data.dir.substr(1);
44
        if (dirLoad !== '') {
45
            dirLoad = dirLoad + '/';
46
        }
47
        window.location = OC.generateUrl('/apps/analytics/#/f/') + dirLoad + file;
48
    },
49
};
50
51
document.addEventListener('DOMContentLoaded', function () {
52
    if (typeof OCA !== 'undefined' && typeof OCA.Files !== 'undefined' && typeof OCA.Files.fileActions !== 'undefined' && $('#header').hasClass('share-file') === false) {
53
        OCA.Analytics.Viewer.registerFileActions();
54
    }
55
    return true;
56
});