myems-admin/app/controllers/settings/meter/meter.controller.js

Summary

Maintainability
F
1 wk
Test Coverage

File meter.controller.js has 430 lines of code (exceeds 250 allowed). Consider refactoring.
Open

'use strict';

app.controller('MeterController', function($scope,
    $rootScope,
    $window,
Severity: Minor
Found in myems-admin/app/controllers/settings/meter/meter.controller.js - About 6 hrs to fix

    Function editMeter has 53 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        $scope.editMeter = function(meter) {
            var modalInstance = $uibModal.open({
                windowClass: "animated fadeIn",
                templateUrl: 'views/settings/meter/meter.model.html',
                controller: 'ModalEditMeterCtrl',
    Severity: Major
    Found in myems-admin/app/controllers/settings/meter/meter.controller.js - About 2 hrs to fix

      Function addMeter has 52 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          $scope.addMeter = function() {
              var modalInstance = $uibModal.open({
                  templateUrl: 'views/settings/meter/meter.model.html',
                  controller: 'ModalAddMeterCtrl',
                  windowClass: "animated fadeIn",
      Severity: Major
      Found in myems-admin/app/controllers/settings/meter/meter.controller.js - About 2 hrs to fix

        Function deleteMeter has 35 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            $scope.deleteMeter = function(meter) {
                SweetAlert.swal({
                        title: $translate.instant("SWEET.TITLE"),
                        text: $translate.instant("SWEET.TEXT"),
                        type: "warning",
        Severity: Minor
        Found in myems-admin/app/controllers/settings/meter/meter.controller.js - About 1 hr to fix

          Function importMeter has 34 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              $scope.importMeter = function() {
                  var modalInstance = $uibModal.open({
                      templateUrl: 'views/common/import.html',
                      controller: 'ModalImportCtrl',
                      windowClass: "animated fadeIn",
          Severity: Minor
          Found in myems-admin/app/controllers/settings/meter/meter.controller.js - About 1 hr to fix

            Function getAllMeters has 31 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                $scope.getAllMeters = function() {
                    let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token };
                    MeterService.getAllMeters(headers, function (response) {
                        if (angular.isDefined(response.status) && response.status === 200) {
                            $scope.meters = response.data;
            Severity: Minor
            Found in myems-admin/app/controllers/settings/meter/meter.controller.js - About 1 hr to fix

              Function refreshMeterTree has 29 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  $scope.refreshMeterTree = function() {
                      let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token };
                      MeterService.getAllMeters(headers, function (response) {
                          if (angular.isDefined(response.status) && response.status === 200) {
                              $scope.meters = response.data;
              Severity: Minor
              Found in myems-admin/app/controllers/settings/meter/meter.controller.js - About 1 hr to fix

                Similar blocks of code found in 6 locations. Consider refactoring.
                Open

                    $scope.importMeter = function() {
                        var modalInstance = $uibModal.open({
                            templateUrl: 'views/common/import.html',
                            controller: 'ModalImportCtrl',
                            windowClass: "animated fadeIn",
                myems-admin/app/controllers/settings/datasource/datasource.controller.js on lines 226..262
                myems-admin/app/controllers/settings/energystoragepowerstation/energystoragepowerstation.controller.js on lines 252..288
                myems-admin/app/controllers/settings/meter/virtualmeter.controller.js on lines 280..316
                myems-admin/app/controllers/settings/space/space.controller.js on lines 331..367
                myems-admin/app/controllers/settings/tenant/tenant.controller.js on lines 259..295

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 338.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 6 locations. Consider refactoring.
                Open

                    $scope.cloneMeter = function(meter){
                        let headers = { "User-UUID": $scope.cur_user.uuid, "Token": $scope.cur_user.token };
                        MeterService.cloneMeter(meter, headers, function(response) {
                            if (angular.isDefined(response.status) && response.status === 201) {
                                toaster.pop({
                myems-admin/app/controllers/settings/datasource/datasource.controller.js on lines 204..224
                myems-admin/app/controllers/settings/energystoragepowerstation/energystoragepowerstation.controller.js on lines 230..250
                myems-admin/app/controllers/settings/meter/virtualmeter.controller.js on lines 258..278
                myems-admin/app/controllers/settings/space/space.controller.js on lines 309..329
                myems-admin/app/controllers/settings/tenant/tenant.controller.js on lines 237..257

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 250.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Identical blocks of code found in 2 locations. Consider refactoring.
                Open

                            for(var i=0; i < $scope.meters.length; i++) {
                                    if ($scope.meters[i].master_meter == null) {
                                        var node = {"id": $scope.meters[i].id.toString(),
                                                                                "parent": '#',
                                                                                "text": $scope.meters[i].name,
                myems-admin/app/controllers/settings/meter/meter.controller.js on lines 102..116

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 225.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Identical blocks of code found in 2 locations. Consider refactoring.
                Open

                            for(var i=0; i < $scope.meters.length; i++) {
                                if ($scope.meters[i].master_meter == null) {
                                    var node = {"id": $scope.meters[i].id.toString(),
                                                "parent": '#',
                                                "text": $scope.meters[i].name,
                myems-admin/app/controllers/settings/meter/meter.controller.js on lines 64..78

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 225.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 6 locations. Consider refactoring.
                Open

                    $scope.change_energyitems = function(selected_energy_category_id){
                        var i = 0;
                        var j = 0;
                        $scope.energyitems = [];
                        for (; i < params.energyitems.length; i++){
                myems-admin/app/controllers/settings/meter/meter.controller.js on lines 445..465
                myems-admin/app/controllers/settings/meter/offlinemeter.controller.js on lines 317..337
                myems-admin/app/controllers/settings/meter/offlinemeter.controller.js on lines 358..378
                myems-admin/app/controllers/settings/meter/virtualmeter.controller.js on lines 384..404
                myems-admin/app/controllers/settings/meter/virtualmeter.controller.js on lines 510..530

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 196.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 6 locations. Consider refactoring.
                Open

                    $scope.change_energyitems = function(selected_energy_category_id){
                        var i = 0;
                        var j = 0;
                        $scope.energyitems = [];
                        for (; i < params.energyitems.length; i++){
                myems-admin/app/controllers/settings/meter/meter.controller.js on lines 405..425
                myems-admin/app/controllers/settings/meter/offlinemeter.controller.js on lines 317..337
                myems-admin/app/controllers/settings/meter/offlinemeter.controller.js on lines 358..378
                myems-admin/app/controllers/settings/meter/virtualmeter.controller.js on lines 384..404
                myems-admin/app/controllers/settings/meter/virtualmeter.controller.js on lines 510..530

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 196.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Identical blocks of code found in 2 locations. Consider refactoring.
                Open

                            if (angular.isDefined(response.status) && response.status === 200) {
                                $scope.meters = response.data;
                                $scope.parentmeters = response.data;
                            } else {
                                $scope.meters = [];
                myems-admin/app/controllers/settings/meter/meter.controller.js on lines 93..99

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 91.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Identical blocks of code found in 2 locations. Consider refactoring.
                Open

                            if (angular.isDefined(response.status) && response.status === 200) {
                                $scope.meters = response.data;
                                $scope.parentmeters = response.data;
                            } else {
                                $scope.meters = [];
                myems-admin/app/controllers/settings/meter/meter.controller.js on lines 55..61

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 91.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                There are no issues that match your filters.

                Category
                Status