Passed
Push — master ( c3d610...926549 )
by Marcel
02:48
created

js/viewer.js   A

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
 * This file is licensed under the Affero General Public License version 3 or
5
 * later. See the LICENSE.md file.
6
 *
7
 * @author Marcel Scherello <[email protected]>
8
 * @copyright 2020 Marcel Scherello
9
 */
10
/** global: OCA */
11
/** global: OCP */
12
/** global: OC */
13
'use strict';
14
15
if (!OCA.Analytics) {
16
    /**
17
     * @namespace
18
     */
19
    OCA.Analytics = {};
20
}
21
/**
22
 * @namespace OCA.Analytics.Viewer
23
 */
24
OCA.Analytics.Viewer = {
25
26
    registerFileActions: function () {
27
        let mime_array = ['text/csv', 'text/plain'];
28
        let icon_url = OC.imagePath('analytics', 'app-dark');
29
30
        for (let i = 0; i < mime_array.length; i++) {
31
            let mime = mime_array[i];
32
            OCA.Files.fileActions.registerAction({
33
                name: 'analytics',
34
                displayName: t('analytics', 'Show in Analytics'),
35
                mime: mime,
36
                permissions: OC.PERMISSION_READ,
37
                icon: icon_url,
38
                actionHandler: OCA.Analytics.Viewer.importFile
39
            });
40
        }
41
    },
42
43
    importFile: function (file, data) {
44
        file = encodeURIComponent(file);
45
        let dirLoad = data.dir.substr(1);
46
        if (dirLoad !== '') {
47
            dirLoad = dirLoad + '/';
48
        }
49
        window.location = OC.generateUrl('/apps/analytics/#/f/') + dirLoad + file;
50
    },
51
};
52
53
document.addEventListener('DOMContentLoaded', function () {
54
    if (typeof OCA !== 'undefined' && typeof OCA.Files !== 'undefined' && typeof OCA.Files.fileActions !== 'undefined' && $('#header').hasClass('share-file') === false) {
55
        OCA.Analytics.Viewer.registerFileActions();
56
    }
57
    return true;
58
});