Repository: syncthing/syncthing
File: gui/default/untrusted/syncthing/core/syncthingController.js (JavaScript)

Code before:

        function addFolderInit(recvEnc) {
            $scope.editingExisting = false;
            $scope.currentFolder = angular.copy($scope.folderDefaults);
            if (recvEnc) {
                $scope.currentFolder.type = "receiveencrypted";
                $scope.currentFolder.ignorePerms = true;
                delete $scope.currentFolder.versioning;
            }
            initShareEditing('folder');
            $scope.ignores.text = '';
            $scope.ignores.error = null;
            $scope.ignores.disabled = false;
        }

        $scope.addFolder = function () {
            $http.get(urlbase + '/svc/random/string?length=10').success(function (data) {
                addFolderInit(false);
                $scope.currentFolder.id = (data.random.substr(0, 5) + '-' + data.random.substr(5, 5)).toLowerCase();
                $scope.currentSharing.unrelated = $scope.otherDevices();
                $scope.editFolderModal();
            });
        };

        $scope.addFolderAndShare = function (folder, folderLabel, device) {
            var pendingFolder = $scope.pendingFolders[folder];
            var recvEnc = false;
            for (var k in pendingFolder.offeredBy) {
                if (pendingFolder.offeredBy[k].receiveEncrypted) {
                    recvEnc = "receiveencrypted";
                    break;
                }
            }
            addFolderInit(recvEnc);
            $scope.currentFolder.id = folder;
            $scope.currentFolder.label = folderLabel;
            $scope.currentFolder.viewFlags = {
                importFromOtherDevice: true
            };
            $scope.currentSharing.selected[device] = true;
            $scope.currentSharing.unrelated = $scope.deviceList().filter(function (n) {
                return n.deviceID !== $scope.myID;
            });
            $scope.editFolderModal();
        };

        $scope.shareFolderWithDevice = function (folder, device) {
            $scope.folders[folder].devices.push({
                deviceID: device
            });
            $scope.config.folders = folderList($scope.folders);

Review comment (suggestion):
If the addFolderAndShare function needs access to the pendingFolder's details, we could pass the corresponding `offeredBy[k]` object instead of the folderLabel parameter.

Code after:
            return 'fas fa-folder';
        };

        function editFolder() {
            if ($scope.currentFolder.path.length > 1 && $scope.currentFolder.path.slice(-1) === $scope.system.pathSeparator) {
                $scope.currentFolder.path = $scope.currentFolder.path.slice(0, -1);
            } else if (!$scope.currentFolder.path) {
                // undefined path leads to invalid input field
                $scope.currentFolder.path = '';
            }
            initShareEditing('folder');
            editFolderModal();
        }

        function initVersioningEditing() {
            $scope.currentFolder._guiVersioning = angular.copy($scope.versioningDefaults);

            if (!$scope.currentFolder.versioning) {
                return;
            }

            var currentVersioning = $scope.currentFolder.versioning;

            $scope.currentFolder._guiVersioning.cleanupIntervalS = +currentVersioning.cleanupIntervalS;

            // Apply parameters currently in use
            switch (currentVersioning.type) {
            case "trashcan":
                $scope.currentFolder._guiVersioning.selector = "trashcan";
                $scope.currentFolder._guiVersioning.trashcanClean = +currentVersioning.params.cleanoutDays;
                break;
            case "simple":
                $scope.currentFolder._guiVersioning.selector = "simple";
                $scope.currentFolder._guiVersioning.simpleKeep = +currentVersioning.params.keep;
                $scope.currentFolder._guiVersioning.trashcanClean = +currentVersioning.params.cleanoutDays;
                break;
            case "staggered":
                $scope.currentFolder._guiVersioning.selector = "staggered";
                $scope.currentFolder._guiVersioning.staggeredMaxAge = Math.floor(+currentVersioning.params.maxAge / 86400);
                $scope.currentFolder._guiVersioning.staggeredCleanInterval = +currentVersioning.params.cleanInterval;
                $scope.currentFolder._guiVersioning.staggeredVersionsPath = currentVersioning.params.versionsPath;
                break;
            case "external":
                $scope.currentFolder._guiVersioning.selector = "external";
                $scope.currentFolder.externalCommand = currentVersioning.params.command;
                break;
            }
        };

        $scope.editFolderExisting = function(folderCfg) {
            $scope.editingExisting = true;