js/service/StatusService.js   A
last analyzed

Complexity

Total Complexity 10
Complexity/F 1.25

Size

Lines of Code 54
Function Count 8

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
dl 0
loc 54
rs 10
c 1
b 0
f 0
cc 0
nc 1
mnd 1
bc 9
fnc 8
bpm 1.125
cpm 1.25
noi 1
1
/*
2
 * @copyright Copyright (c) 2016 Julius Härtl <[email protected]>
3
 *
4
 * @author Julius Härtl <[email protected]>
5
 *
6
 * @license GNU AGPL version 3 or any later version
7
 *  
8
 *  This program is free software: you can redistribute it and/or modify
9
 *  it under the terms of the GNU Affero General Public License as
10
 *  published by the Free Software Foundation, either version 3 of the
11
 *  License, or (at your option) any later version.
12
 *  
13
 *  This program is distributed in the hope that it will be useful,
14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 *  GNU Affero General Public License for more details.
17
 *  
18
 *  You should have received a copy of the GNU Affero General Public License
19
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
 *  
21
 */
22
23
app.factory('StatusService', function(){
24
    // Status Helper
25
    var StatusService = function() {
26
        this.active = true;
27
        this.icon = 'loading';
28
        this.title = '';
29
        this.text = '';
30
        this.counter = 0;
31
    };
32
33
34
    StatusService.prototype.setStatus = function($icon, $title, $text) {
35
        this.active = true;
36
        this.icon = $icon;
37
        this.title = $title;
38
        this.text = $text;
39
    };
40
41
    StatusService.prototype.setError = function($title, $text) {
42
        this.active = true;
43
        this.icon = 'error';
44
        this.title = $title;
45
        this.text = $text;
46
        this.counter = 0;
47
    };
48
49
    StatusService.prototype.releaseWaiting = function() {
50
        if(this.counter>0)
51
            this.counter--;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
52
        if(this.counter<=0) {
53
            this.active = false;
54
            this.counter = 0;
55
        }
56
    };
57
58
    StatusService.prototype.retainWaiting = function() {
59
        this.active = true;
60
        this.icon = 'loading';
61
        this.title = '';
62
        this.text = '';
63
        this.counter++;
64
    };
65
66
    StatusService.prototype.unsetStatus = function() {
67
        this.active = false;
68
    };
69
70
    return {
71
        getInstance: function() {
72
            return new StatusService();
73
        }
74
    }
75
76
});
77
78
79