Resources/views/frontend/_public/src/js/view-snapshots.js   A
last analyzed

Complexity

Total Complexity 22
Complexity/F 2

Size

Lines of Code 99
Function Count 11

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
nc 8
dl 0
loc 99
rs 10
c 1
b 0
f 0
wmc 22
mnd 2
bc 20
fnc 11
bpm 1.8181
cpm 2
noi 10

5 Functions

Rating   Name   Duplication   Size   Complexity  
A window.snapshots.record 0 21 3
A window.snapshots.next 0 13 2
A window.snapshots.stop 0 21 3
A window.snapshots.prev 0 13 2
A window.snapshots.request 0 14 1
1
;(function(window) {
2
    'use strict';
3
4
    if (window.snapshots.config.isRecordingSnapshots && !window.snapshots.config.currentStep) {
5
        console.log('📹 This session is currently being recorded. Session ID: ' + window.snapshots.config.sessionId);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
6
    }
7
8
    if (window.snapshots.config.currentStep) {
9
        console.log('📹 Watching step ' + window.snapshots.config.currentStep + ' of recorded session ' + window.snapshots.config.sessionId);
10
    }
11
12
    window.snapshots.request = function(url, callbackSuccess, callbackError) {
13
        var xhr = new XMLHttpRequest();
0 ignored issues
show
Bug introduced by
The variable XMLHttpRequest seems to be never declared. If this is a global, consider adding a /** global: XMLHttpRequest */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
14
        xhr.open('GET', url);
15
        xhr.send(null);
16
        xhr.onreadystatechange = function () {
17
            if (xhr.readyState === 4) {
18
                if (xhr.status === 200) {
19
                    callbackSuccess();
20
                } else {
21
                    callbackError();
22
                }
23
            }
24
        };
25
    };
26
27
    window.snapshots.record = function() {
28
        var me = this;
29
30
        if (me.config.isRecordingSnapshots || !me.config.startUrl) {
31
            console.log('⚠️ Already recording or missing config.');
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
32
33
            return;
34
        }
35
36
        me.request(
37
            me.config.startUrl,
38
            function () {
39
                me.config.isRecordingSnapshots = true;
40
41
                console.log('▶️️ Recording of session starting next request. Session ID: ' + me.config.sessionId);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
42
            },
43
            function () {
44
                console.log('⚠️ Error while starting the recording of session.');
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
45
            }
46
        );
47
    };
48
49
    window.snapshots.stop = function() {
50
        var me = this;
51
52
        if (!me.config.isRecordingSnapshots || !me.config.stopUrl) {
53
            console.log('⚠️ Not recording at the moment.');
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
54
55
            return;
56
        }
57
58
        me.request(
59
            me.config.stopUrl,
60
            function () {
61
                me.config.isRecordingSnapshots = false;
62
63
                console.log('✋️️ Stopped recording current session.');
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
64
            },
65
            function () {
66
                console.log('⚠️ Error while stopping the recording of session.');
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
67
            }
68
        );
69
    };
70
71
    window.snapshots.next = function() {
72
        var me = this;
73
74
        if (!me.config.nextUrl) {
75
            console.log('⚠️ No next snapshot recorded or currently not watching session.');
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
76
77
            return;
78
        }
79
80
        console.log('➡️️ Loading next snapshot.');
81
82
        window.location.href = me.config.nextUrl;
83
    };
84
85
    window.snapshots.prev = function() {
86
        var me = this;
87
88
        if (!me.config.prevUrl) {
89
            console.log('⚠️ No previous snapshot recorded or currently not watching session.');
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
90
91
            return;
92
        }
93
94
        console.log('⬅️️ Loading previous snapshot.');
95
96
        window.location.href = me.config.prevUrl;
97
    };
98
99
})(window);