portainer/portainer

View on GitHub
app/portainer/views/stacks/edit/stackController.js

Summary

Maintainability
D
2 days
Test Coverage

File stackController.js has 426 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import { ResourceControlType } from '@/react/portainer/access-control/types';
import { AccessControlFormData } from 'Portainer/components/accessControlForm/porAccessControlFormModel';
import { FeatureId } from '@/react/portainer/feature-flags/enums';
import { getEnvironments } from '@/react/portainer/environments/environment.service';
import { StackStatus, StackType } from '@/react/common/stacks/types';
Severity: Minor
Found in app/portainer/views/stacks/edit/stackController.js - About 6 hrs to fix

    Function loadStack has 48 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        function loadStack(id) {
          return $async(async () => {
            var agentProxy = $scope.applicationState.endpoint.mode.agentProxy;
    
            getEnvironments()
    Severity: Minor
    Found in app/portainer/views/stacks/edit/stackController.js - About 1 hr to fix

      Function deployStack has 26 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          $scope.deployStack = function () {
            const stack = $scope.stack;
            const isSwarmStack = stack.Type === 1;
            confirmStackUpdate('Do you want to force an update of the stack?', isSwarmStack).then(function (result) {
              if (!result) {
      Severity: Minor
      Found in app/portainer/views/stacks/edit/stackController.js - About 1 hr to fix

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

            function assignSwarmStackResources(resources, agentProxy) {
              var services = resources.services;
              var tasks = resources.tasks;
        
              if (agentProxy) {
        Severity: Major
        Found in app/portainer/views/stacks/edit/stackController.js and 1 other location - About 7 hrs to fix
        app/docker/views/services/servicesController.js on lines 26..46

        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 181.

        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 3 locations. Consider refactoring.
        Open

            $scope.removeStack = function () {
              confirmDelete('Do you want to remove the stack? Associated services will be removed as well').then((confirmed) => {
                if (!confirmed) {
                  return;
                }
        Severity: Major
        Found in app/portainer/views/stacks/edit/stackController.js and 2 other locations - About 55 mins to fix
        app/docker/views/services/edit/serviceController.js on lines 623..630
        app/portainer/views/users/edit/userController.js on lines 32..39

        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 53.

        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 7 locations. Consider refactoring.
        Open

            $scope.onPruneChange = function (enable) {
              $scope.$evalAsync(() => {
                $scope.formValues.Prune = enable;
              });
            };
        Severity: Major
        Found in app/portainer/views/stacks/edit/stackController.js and 6 other locations - About 40 mins to fix
        app/docker/views/containers/console/containerConsoleController.js on lines 255..259
        app/docker/views/images/build/buildImageController.js on lines 38..42
        app/docker/views/networks/create/createNetworkController.js on lines 208..212
        app/docker/views/networks/create/createNetworkController.js on lines 214..218
        app/portainer/views/stacks/create/createStackController.js on lines 101..105
        app/portainer/views/stacks/edit/stackController.js on lines 99..103

        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 48.

        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 7 locations. Consider refactoring.
        Open

            $scope.onEnableWebhookChange = function (enable) {
              $scope.$evalAsync(() => {
                $scope.formValues.EnableWebhook = enable;
              });
            };
        Severity: Major
        Found in app/portainer/views/stacks/edit/stackController.js and 6 other locations - About 40 mins to fix
        app/docker/views/containers/console/containerConsoleController.js on lines 255..259
        app/docker/views/images/build/buildImageController.js on lines 38..42
        app/docker/views/networks/create/createNetworkController.js on lines 208..212
        app/docker/views/networks/create/createNetworkController.js on lines 214..218
        app/portainer/views/stacks/create/createStackController.js on lines 101..105
        app/portainer/views/stacks/edit/stackController.js on lines 105..109

        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 48.

        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