GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

directive.message.js ➔ MessageConstructor   F
last analyzed

Complexity

Conditions 28

Size

Total Lines 101
Code Lines 67

Duplication

Lines 101
Ratio 100 %

Importance

Changes 0
Metric Value
cc 28
eloc 67
dl 101
loc 101
rs 0
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

Complexity

Complex classes like directive.message.js ➔ MessageConstructor often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
2 View Code Duplication
app.directive('message', ['$rootScope',
3
    '$timeout',
4
    'Security',
5
    'MessageService',
6
    'ThemeService',
7
    'Core', function($rootScope, $timeout, Security, MessageService, ThemeService, Core) {
8
    function MessageConstructor($scope, $element, $attrs) {
9
        var constructor = this;
0 ignored issues
show
Unused Code introduced by
The variable constructor seems to be never used. Consider removing it.
Loading history...
10
        var $ctrl = $scope.msgCtrl;
11
        var tagName = $element[0].tagName.toLowerCase();
12
13
        $scope.autoClose = false;
14
        var DirectiveProperties = (function () {
15
            var autoClose;
16
            var type;
17
18
            function findAutoClose(){
19
                var object = $attrs.autoClose;
20
                if(typeof(object) != "undefined")
21
                    return true;
22
                else
23
                    return false;
0 ignored issues
show
Comprehensibility introduced by
else is not necessary here since all if branches return, consider removing it to reduce nesting and make code more readable.
Loading history...
24
            }
25
            function findType(){
26
                var object = $attrs.type;
27
                if(typeof(object) != "undefined")
28
                    return object;
29
                else
30
                    return "alert";
0 ignored issues
show
Comprehensibility introduced by
else is not necessary here since all if branches return, consider removing it to reduce nesting and make code more readable.
Loading history...
31
            }
32
33
            return {
34
                getAutoClose: function () {
35
                    if (!autoClose) {
36
                        autoClose = findAutoClose();
37
                    }
38
                    $scope.autoClose = autoClose;
39
                    return autoClose;
40
                },
41
                getType: function () {
42
                    if (!type) {
43
                        type = findType();
44
                    }
45
                    $scope.type = type;
46
                    return type;
47
                }
48
            };
49
        })();
50
51
        function TryToCallInitDirective(){
52
            if(typeof $scope.InitDirective == "function"){
53
                $scope.InitDirective($scope, $element, $attrs, $ctrl);
54
            }else{
55
                $scope.DefaultInitDirective();
56
            }
57
        }
58
        $scope.DefaultInitDirective = function(){
59
            if(Core.GetConfig().debugLog.DirectiveFlow)
60
            console.log("scope.$id:"+$scope.$id+", may implement $scope.InitDirective() function in webapge");
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...
61
        }
62
        function InitializeMessage() {
63
            DirectiveProperties.getAutoClose();
64
            DirectiveProperties.getType();
65
66
            $ctrl.ngModel = [];
67
            
68
            $ctrl.ngModel = MessageService.getMsg();
69
            $scope.ngModel = $ctrl.ngModel;
70
        }
71
        $scope.Test = function(){
72
            console.dir($ctrl)
73
            console.dir($ctrl.ngModel)
74
        }
75
        $scope.Initialize = function(){
76
            $scope.InitScope();
77
            TryToCallInitDirective();
78
        }
79
        $scope.InitScope = function(){
80
            InitializeMessage();
81
        }
82
83
        function InitDirective(){
84
            if(Core.GetConfig().debugLog.DirectiveFlow)
85
            console.log("scope.$id:"+$scope.$id+", may implement $scope.InitDirective() function in webapge");
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...
86
        }
87
//        $scope.Initialize();
88
89
        $scope.$watchCollection(
90
          function() { return $ctrl.ngModel },
91
          function(newValue, oldValue) {
92
             if(typeof(newValue) == "undefined" && typeof(oldValue) == "undefined")
93
                return;
94
95
              var newValueLength = newValue.length;
96
              var oldValueLength = oldValue.length;
97
              
98
            if ( newValueLength !== oldValueLength ) {
99
//                if(newValueLength > oldValueLength){
100
                    if($scope == "alert")
101
                    if($scope.autoClose)
102
                        $timeout(function(){
103
                            MessageService.shiftMsg();
104
                        }, 7000); // (milliseconds),  1s = 1000ms
105
            }
106
          }
107
        );
108
    }
109
    function templateFunction(tElement, tAttrs) {
0 ignored issues
show
introduced by
The function templateFunction does not seem to be used and can be removed.
Loading history...
110
        console.log("Message - templateFunction()");
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...
111
        var globalCriteria = $rootScope.globalCriteria;
112
113
        var template = '' +
114
          '<div class="custom-transclude"></div>';
115
        template = '<div class="" ng-if="msgCtrl.ngModel.length > 0"><div ng-repeat="dspMsg in msgCtrl.ngModel track by $index" ng-bind="dspMsg"></div></div>';
116
        return template;
117
    }
118
    function templateUrlFunction(tElement, tAttrs) {
119
        var directiveName = tElement[0].tagName;
120
121
        directiveName = directiveName.toLowerCase();
122
        var templateURL = ThemeService.GetTemplateURL(directiveName);
123
        return templateURL;
124
    }
125
126
    return {
127
        require: ['ngModel'],
128
        restrict: 'E', //'EA', //Default in 1.3+
129
        transclude: true,
130
        scope: true,
131
132
        controller: MessageConstructor,
133
        controllerAs: 'msgCtrl',
134
135
        //If both bindToController and scope are defined and have object hashes, bindToController overrides scope.
136
        bindToController: {
137
            ngModel: '=',
138
        },
139
//        template: templateFunction,
140
        templateUrl: templateUrlFunction,
141
        compile: function compile(tElement, tAttrs, transclude) {
142
            return {
143
                pre: function preLink(scope, iElement, iAttrs, controller) {
144
//                    console.log("Message - compile preLink()");
145
                },
146
                post: function postLink(scope, iElement, iAttrs, controller) {
147
//                    console.log("Message - compile postLink()");
148
149
                    transclude(scope, function (clone, scope) {
150
                        iElement.find('.custom-transclude').append(clone);
151
                    })
152
153
                    scope.Initialize();
154
                }
155
            }
156
        },
157
    };
158
}]);
159