File manager - Edit - /usr/local/cpanel/whostmgr/docroot/templates/feature/views/editFeatureListController.min.js
Back
define(["angular","lodash","jquery","cjt/util/locale","uiBootstrap","cjt/directives/searchDirective","cjt/directives/spinnerDirective","cjt/services/alertService","app/services/featureListService"],(function(angular,_,$,LOCALE){"use strict";var app=angular.module("App");var controller=app.controller("editFeatureListController",["$scope","$location","$anchorScroll","$routeParams","spinnerAPI","alertService","featureListService","$sce","PAGE",function($scope,$location,$anchorScroll,$routeParams,spinnerAPI,alertService,featureListService,$sce,PAGE){$scope.featureListName=$routeParams.name;$scope.featureListHeading=LOCALE.maketext("Select all features for: [_1]",$scope.featureListName);$scope.isDisabledFeatureList=$scope.featureListName==="disabled";$scope.validateOnlyOneRules=function(newValue){if(!newValue){return{valid:true}}if($scope.isDisabledFeatureList){return{valid:true}}const checkedFeatureNames=$scope.featureList.filter((feature=>feature.value)).map((feature=>feature.name));const allRules=$scope.featureList.filter((feature=>feature.onlyOneRules)).flatMap((feature=>feature.onlyOneRules));for(const rule of allRules){const violation=$scope.checkRuleViolation(rule,checkedFeatureNames);if(violation){return violation}}return{valid:true}};$scope.matches=function(name,pattern){try{const patternStr=pattern.pattern||pattern;if(!patternStr||patternStr==="(?^u:)"||patternStr==="(?-u:)"){return false}return new RegExp(patternStr,pattern.flags||"").test(name)}catch(e){void e;return false}};$scope.getAllowedNames=function(feature){if(!feature.allowList||!feature.allowList.length){return null}const allowed={};allowed[feature.name]=true;if(feature.dependencies&&feature.dependencies.length){feature.dependencies.forEach((dep=>{allowed[dep]=true}))}$scope.featureList.forEach((f=>{if(feature.allowList.some((pattern=>$scope.matches(f.name,pattern)))){allowed[f.name]=true}}));return allowed};$scope.getBlockedNames=function(feature){if(!feature.blockList||!feature.blockList.length){return null}const blocked={};$scope.featureList.forEach((f=>{if(feature.blockList.some((pattern=>$scope.matches(f.name,pattern)))){blocked[f.name]=true}}));return blocked};$scope.shouldRestrict=function(feature,allowedNames,blockedNames){if(allowedNames&&!allowedNames[feature.name]){return true}if(blockedNames&&blockedNames[feature.name]){return true}return false};$scope.restrictFeature=function(targetFeature,sourceFeatureName){const wasSelected=targetFeature.value;if(wasSelected){targetFeature.value=false}targetFeature.restrictedBy=targetFeature.restrictedBy||{};targetFeature.restrictedBy[sourceFeatureName]=true;targetFeature.isRestricted=true;return wasSelected};$scope.applyRestrictions=function(feature){if($scope.isDisabledFeatureList){return{deselected:[]}}const deselected=[];const allowedNames=$scope.getAllowedNames(feature);const blockedNames=$scope.getBlockedNames(feature);$scope.featureList.forEach((f=>{if($scope.shouldRestrict(f,allowedNames,blockedNames)){if($scope.restrictFeature(f,feature.name)){deselected.push(f)}}}));return{deselected:deselected}};$scope.removeRestrictions=function(feature){$scope.featureList.forEach((f=>{if(f.restrictedBy&&f.restrictedBy[feature.name]){delete f.restrictedBy[feature.name];if(Object.keys(f.restrictedBy).length===0){delete f.restrictedBy;delete f.isRestricted}}}));return{valid:true}};$scope.getRestrictionMessage=function(feature){if(!feature.isRestricted||!feature.restrictedBy){return""}const restrictingFeatures=Object.keys(feature.restrictedBy);if(restrictingFeatures.length===0){return""}const restrictingFeatureObjects=restrictingFeatures.map((name=>{const foundFeature=$scope.featureList.find((f=>f.name===name));return foundFeature||{name:name,label:name}}));const labels=$scope.formatFeatureLabelsWithBadges(restrictingFeatureObjects);return LOCALE.maketext("This feature is disabled because it is incompatible with: “[_1]”.",labels.join(", "))};$scope.checkRuleViolation=function(rule,checkedFeatureNames){const pattern=rule.pattern||rule;const flags=rule.flags||"";let regex;try{regex=new RegExp(pattern,flags)}catch(e){console.warn("Invalid onlyOneRules pattern:",pattern,flags,e);return null}const matchingFeatures=checkedFeatureNames.filter((name=>regex.test(name)));if(matchingFeatures.length<=1){return null}const matchingFeatureObjects=matchingFeatures.map((name=>{const foundFeature=$scope.featureList.find((feature=>feature.name===name));return foundFeature||{name:name,label:name}}));const matchingLabels=$scope.formatFeatureLabelsWithBadges(matchingFeatureObjects);return{valid:false,error:LOCALE.maketext("Your feature list can only include one of the following features: “[_1]”.",matchingLabels.join(", "))}};$scope.enableDependencies=function(targetFeature,changedFeatures=[]){if($scope.isDisabledFeatureList){return changedFeatures}if(!targetFeature.dependencies||!targetFeature.dependencies.length){return changedFeatures}const dependencyFeatures=$scope.featureList.filter((candidateFeature=>targetFeature.dependencies.includes(candidateFeature.name)));dependencyFeatures.forEach((dependencyFeature=>{if(dependencyFeature.disabled){dependencyFeature.value=false;return}if(!dependencyFeature.value){dependencyFeature.value=true;changedFeatures.push(dependencyFeature);$scope.enableDependencies(dependencyFeature,changedFeatures)}}));return changedFeatures};$scope.disableDependentFeatures=function(targetFeature,changedFeatures=[]){if($scope.isDisabledFeatureList){return changedFeatures}const dependentFeatures=$scope.featureList.filter((candidateFeature=>candidateFeature.dependencies&&candidateFeature.dependencies.includes(targetFeature.name)&&candidateFeature.value&&!candidateFeature.disabled));dependentFeatures.forEach((dependentFeature=>{dependentFeature.value=false;changedFeatures.push(dependentFeature);$scope.removeRestrictions(dependentFeature);alertService.removeById("warningOnlyOneRule_"+dependentFeature.name);alertService.removeById("warningRestrict_"+dependentFeature.name);alertService.removeById("errorDisabledDependency_"+dependentFeature.name);$scope.disableDependentFeatures(dependentFeature,changedFeatures)}));return changedFeatures};$scope.getDisabledDependencyError=function(feature){if(!feature||!feature.disabledDependencies||!feature.disabledDependencies.length){return null}const disabledDepLabels=feature.disabledDependencies.map((depName=>{const depFeature=$scope.featureList.find((f=>f.name===depName));return depFeature?depFeature.label||depFeature.name:depName}));return{feature:feature.name,featureLabel:feature.label||feature.name,disabledDependencies:feature.disabledDependencies,disabledDependencyLabels:disabledDepLabels}};$scope.validateDisabledDependencies=function(){if($scope.isDisabledFeatureList){return{valid:true,errors:[]}}const errors=[];$scope.featureList.filter((f=>f.value&&!f.disabled)).forEach((feature=>{const error=$scope.getDisabledDependencyError(feature);if(error){errors.push(error)}}));return{valid:errors.length===0,errors:errors}};$scope.formatDisabledDependencyErrors=function(errors){return errors.map((error=>LOCALE.maketext("The “[_1]” feature requires “[_2]” which [numerate,_3,is,are] globally disabled.",error.featureLabel,error.disabledDependencyLabels.join(", "),error.disabledDependencies.length)))};$scope.notifyFeatureChanges=function(changedFeatures,action){if(!changedFeatures.length){return}const featureLabels=$scope.formatFeatureLabelsWithBadges(changedFeatures);let message;if(action==="enabled"){message=LOCALE.maketext("The following features were automatically enabled due to dependencies: “[_1]”.",featureLabels.join(", "))}else{message=LOCALE.maketext("The following features were automatically disabled because they depend on unselected features: “[_1]”.",featureLabels.join(", "))}alertService.add({type:"info",message:message,id:"infoDependencyChanges",replace:true})};$scope.handleFeatureChange=function(feature){if(!feature){return}let changedFeatures=[];if(!feature.value){if(!$scope.isDisabledFeatureList){changedFeatures=$scope.disableDependentFeatures(feature);$scope.notifyFeatureChanges(changedFeatures,"disabled")}$scope.removeRestrictions(feature);alertService.removeById("warningOnlyOneRule_"+feature.name);alertService.removeById("warningRestrict_"+feature.name);alertService.removeById("errorDisabledDependency_"+feature.name);return}if($scope.isDisabledFeatureList){return true}const disabledDependencyError=$scope.getDisabledDependencyError(feature);if(disabledDependencyError){feature.value=false;alertService.add({type:"danger",message:LOCALE.maketext("Cannot enable “[_1]” because it requires “[_2]” which [numerate,_3,is,are] globally disabled. To use this feature, first remove [numerate,_3,this feature,these features] from the “disabled” feature list.",disabledDependencyError.featureLabel,disabledDependencyError.disabledDependencyLabels.join(", "),disabledDependencyError.disabledDependencies.length),id:"errorDisabledDependency_"+feature.name,replace:true});return false}changedFeatures=$scope.enableDependencies(feature);const restrictResult=$scope.applyRestrictions(feature);const validation=$scope.validateOnlyOneRules(feature.value);if(!validation.valid){feature.value=false;changedFeatures.forEach((changedFeature=>{changedFeature.value=false}));$scope.removeRestrictions(feature);alertService.add({type:"warning",message:validation.error,id:"warningOnlyOneRule_"+feature.name,replace:true});return false}$scope.notifyFeatureChanges(changedFeatures,"enabled");if(restrictResult.deselected&&restrictResult.deselected.length){const count=restrictResult.deselected.length;const featureName=feature.label||feature.name;let message=LOCALE.maketext("The system automatically deselected [quant,_1,feature,features] because [numerate,_1,it conflicts,they conflict] with “[_2]”.",count,featureName);alertService.add({type:"info",message:message,id:"infoRestrict_"+feature.name,replace:false})}alertService.removeById("warningOnlyOneRule_"+feature.name);alertService.removeById("warningRestrict_"+feature.name);return true};$scope.formatFeatureLabelsWithBadges=function(features){const featureArray=Array.isArray(features)?features:[features];return featureArray.map((feature=>{const label=feature.label||feature.name;return feature.badgeLabel?`${label} (${feature.badgeLabel})`:label}))};$scope.getExclusiveFeatures=function(){if($scope.isDisabledFeatureList){return[]}const allRules=$scope.featureList.filter((feature=>feature.onlyOneRules&&feature.onlyOneRules.length)).flatMap((feature=>feature.onlyOneRules));const exclusiveFeatures={};allRules.forEach((rule=>{const pattern=rule.pattern||rule;const flags=rule.flags||"";try{const regex=new RegExp(pattern,flags);$scope.featureList.filter((feature=>regex.test(feature.name))).forEach((feature=>exclusiveFeatures[feature.name]=true))}catch(e){console.warn("Invalid onlyOneRules pattern:",pattern,flags,e)}}));return Object.keys(exclusiveFeatures)};$scope.toggleAllFeatures=function(){const isSelecting=!$scope.allFeaturesChecked();if(!isSelecting){$scope.featureList.forEach((f=>{const wasSelected=f.value;f.value=false;if(wasSelected){$scope.removeRestrictions(f)}}));alertService.removeById("infoExclusiveFeaturesSkipped");alertService.removeById("warningOnlyOneRuleSelectAll");return}const exclusiveFeatureNames={};$scope.getExclusiveFeatures().forEach((name=>exclusiveFeatureNames[name]=true));const skippedFeatures=$scope.featureList.filter((feature=>!feature.disabled&&!feature.isRestricted&&isSelecting&&exclusiveFeatureNames[feature.name]&&!feature.value)).map((feature=>{feature.value=false;return feature}));const skippedLabels=$scope.formatFeatureLabelsWithBadges(skippedFeatures);$scope.featureList.filter((feature=>!feature.disabled&&!feature.isRestricted&&!exclusiveFeatureNames[feature.name])).forEach((feature=>{feature.value=isSelecting}));const hasSkippedFeatures=skippedLabels.length&&isSelecting;if(hasSkippedFeatures){alertService.add({type:"info",message:LOCALE.maketext("The “Select All” action skipped features that override the standard login process. You can manually select them if needed: “[_1]”.",skippedLabels.join(", ")),id:"infoExclusiveFeaturesSkipped",replace:true})}else{alertService.removeById("infoExclusiveFeaturesSkipped")}alertService.removeById("warningOnlyOneRuleSelectAll")};$scope.allFeaturesChecked=function(){if($scope.loadingPageData||!$scope.featureList){return false}const exclusiveFeatures=$scope.getExclusiveFeatures();for(let i=0,length=$scope.featureList.length;i<length;i++){const currentFeature=$scope.featureList[i];if(currentFeature.disabled||currentFeature.isRestricted||exclusiveFeatures.includes(currentFeature.name)){continue}if(currentFeature.value===false){return false}}return true};$scope.save=function(list){const validation=$scope.validateDisabledDependencies();if(!validation.valid){const errorMessages=$scope.formatDisabledDependencyErrors(validation.errors);alertService.add({type:"danger",message:LOCALE.maketext("Cannot save feature list: “[_1]”. To fix this, remove the required features from the “disabled” feature list.",errorMessages.join(" ")),id:"errorCannotSaveDisabledDeps",replace:true});return}return featureListService.save($scope.featureListName,list).then((function success(){alertService.add({type:"success",message:LOCALE.maketext("You have successfully updated the “[_1]” feature list.",_.escape($scope.featureListName)),id:"alertSaveSuccess",replace:true});$scope.loadView("featureList")}),(function failure(error){alertService.add({type:"danger",message:error,id:"errorSaveFeatureList"})}))};$scope.fetch=function(){$scope.loadingPageData=true;spinnerAPI.start("featureListSpinner");alertService.removeById("errorFetchFeatureList");return featureListService.load($scope.featureListName,$scope.featureDescriptions).then((function success(results){$scope.featureList=results.items;if(!$scope.isDisabledFeatureList){$scope.featureList.filter((f=>f.value)).forEach((f=>$scope.applyRestrictions(f)))}const validation=$scope.validateDisabledDependencies();if(!validation.valid){const errorMessages=$scope.formatDisabledDependencyErrors(validation.errors);alertService.add({type:"warning",message:LOCALE.maketext("This feature list cannot be saved in its current state: “[_1]”. To fix this, remove the required features from the “disabled” feature list.",errorMessages.join(" ")),id:"warningDisabledDepsOnLoad",replace:false,autoClose:0})}$scope.loadingPageData=false}),(function failure(error){alertService.add({type:"danger",message:error,id:"errorFetchFeatureList"});throw error})).finally((function(){$scope.loadingPageData=false;spinnerAPI.stop("featureListSpinner")}))};$scope.$on("$viewContentLoaded",(function(){alertService.clear();var featureDescriptions=featureListService.prepareList(PAGE.featureDescriptions);$scope.featureDescriptions=_.fromPairs(_.zip(_.map(featureDescriptions.items,"id"),featureDescriptions.items));if(!featureDescriptions.status){$scope.loadingPageData="error";alertService.add({type:"danger",message:LOCALE.maketext("There was a problem loading the page. The system is reporting the following error: [_1].",PAGE.featureDescriptions.metadata.reason),id:"errorFetchFeatureDescriptions"})}else{$scope.fetch()}}))}]);return controller}));
| ver. 1.4 |
Github
|
.
| PHP 8.1.34 | Generation time: 0.02 |
proxy
|
phpinfo
|
Settings