2016-05-16 17:41:39 +02:00
( function ( ) {
'use strict' ;
2017-03-19 16:36:14 +01:00
angular . module ( 'ariaNg' ) . controller ( 'AriaNgSettingsController' , [ '$rootScope' , '$scope' , '$routeParams' , '$window' , '$interval' , '$timeout' , 'ariaNgLanguages' , 'ariaNgCommonService' , 'ariaNgSettingService' , 'ariaNgMonitorService' , 'ariaNgNotificationService' , 'ariaNgTitleService' , function ( $rootScope , $scope , $routeParams , $window , $interval , $timeout , ariaNgLanguages , ariaNgCommonService , ariaNgSettingService , ariaNgMonitorService , ariaNgNotificationService , ariaNgTitleService ) {
2016-11-06 15:41:28 +01:00
var extendType = $routeParams . extendType ;
2017-03-29 03:06:43 +02:00
var lastRefreshPageNotification = null ;
2016-08-13 16:51:42 +02:00
2017-03-05 16:18:09 +01:00
var getFinalTitle = function ( ) {
return ariaNgTitleService . getFinalTitleByGlobalStat ( ariaNgMonitorService . getCurrentGlobalStat ( ) ) ;
} ;
2017-03-29 03:06:43 +02:00
var setNeedRefreshPage = function ( ) {
if ( lastRefreshPageNotification ) {
return ;
}
2017-04-01 17:32:25 +02:00
var noticicationScope = $rootScope . $new ( ) ;
noticicationScope . refreshPage = function ( ) {
$window . location . reload ( ) ;
} ;
2017-03-29 03:06:43 +02:00
lastRefreshPageNotification = ariaNgNotificationService . notifyInPage ( '' , 'Configuration has been modified, please reload the page for the changes to take effect.' , {
delay : false ,
type : 'info' ,
templateUrl : 'setting-changed-notification.html' ,
2017-04-01 17:32:25 +02:00
scope : noticicationScope ,
2017-03-29 03:06:43 +02:00
onClose : function ( ) {
lastRefreshPageNotification = null ;
}
} ) ;
} ;
2016-06-20 18:20:30 +02:00
$scope . context = {
2016-08-13 16:51:42 +02:00
currentTab : 'global' ,
2016-06-20 18:20:30 +02:00
languages : ariaNgLanguages ,
2017-03-05 16:18:09 +01:00
titlePreview : getFinalTitle ( ) ,
2016-06-20 18:20:30 +02:00
availableTime : ariaNgCommonService . getTimeOptions ( [ 1000 , 2000 , 3000 , 5000 , 10000 , 30000 , 60000 ] , true ) ,
2016-06-26 16:52:06 +02:00
trueFalseOptions : [ { name : 'True' , value : true } , { name : 'False' , value : false } ] ,
2016-12-04 14:09:09 +01:00
showRpcSecret : false ,
2017-10-08 16:48:30 +02:00
isInsecureProtocolDisabled : ariaNgSettingService . isInsecureProtocolDisabled ( ) ,
2016-11-06 15:41:28 +01:00
settings : ariaNgSettingService . getAllOptions ( ) ,
2017-03-19 16:36:14 +01:00
sessionSettings : ariaNgSettingService . getAllSessionOptions ( ) ,
rpcSettings : ariaNgSettingService . getAllRpcSettings ( )
2016-06-20 18:20:30 +02:00
} ;
2016-06-26 16:52:06 +02:00
2016-11-06 15:41:28 +01:00
$scope . context . showDebugMode = $scope . context . sessionSettings . debugMode || extendType === 'debug' ;
2016-08-13 16:51:42 +02:00
2017-03-19 16:36:14 +01:00
$scope . changeGlobalTab = function ( ) {
$scope . context . currentTab = 'global' ;
} ;
$scope . isCurrentGlobalTab = function ( ) {
return $scope . context . currentTab === 'global' ;
} ;
$scope . changeRpcTab = function ( rpcIndex ) {
$scope . context . currentTab = 'rpc' + rpcIndex ;
} ;
$scope . isCurrentRpcTab = function ( rpcIndex ) {
return $scope . context . currentTab === 'rpc' + rpcIndex ;
2016-08-13 16:51:42 +02:00
} ;
2017-03-05 16:18:09 +01:00
$scope . updateTitlePreview = function ( ) {
$scope . context . titlePreview = getFinalTitle ( ) ;
} ;
2016-08-13 16:51:42 +02:00
$rootScope . swipeActions . extentLeftSwipe = function ( ) {
2017-03-19 16:36:14 +01:00
var tabIndex = - 1 ;
2016-08-13 16:51:42 +02:00
2017-03-19 16:36:14 +01:00
if ( ! $scope . isCurrentGlobalTab ( ) ) {
tabIndex = parseInt ( $scope . context . currentTab . substring ( 3 ) ) ;
}
if ( tabIndex < $scope . context . rpcSettings . length - 1 ) {
$scope . changeRpcTab ( tabIndex + 1 ) ;
2016-08-13 16:51:42 +02:00
return true ;
} else {
return false ;
}
} ;
$rootScope . swipeActions . extentRightSwipe = function ( ) {
2017-03-19 16:36:14 +01:00
var tabIndex = - 1 ;
if ( ! $scope . isCurrentGlobalTab ( ) ) {
tabIndex = parseInt ( $scope . context . currentTab . substring ( 3 ) ) ;
}
2016-08-13 16:51:42 +02:00
if ( tabIndex > 0 ) {
2017-03-19 16:36:14 +01:00
$scope . changeRpcTab ( tabIndex - 1 ) ;
return true ;
} else if ( tabIndex === 0 ) {
$scope . changeGlobalTab ( ) ;
2016-08-13 16:51:42 +02:00
return true ;
} else {
return false ;
}
} ;
2017-03-19 16:46:16 +01:00
$scope . setLanguage = function ( value ) {
ariaNgSettingService . setLanguage ( value ) ;
2017-05-14 18:00:43 +02:00
$scope . updateTitlePreview ( ) ;
2017-03-19 16:46:16 +01:00
} ;
2017-05-14 08:16:46 +02:00
$scope . setAfterCreatingNewTask = function ( value ) {
ariaNgSettingService . setAfterCreatingNewTask ( value ) ;
} ;
2017-11-03 17:15:19 +01:00
$scope . setRemoveOldTaskAfterRestarting = function ( value ) {
ariaNgSettingService . setRemoveOldTaskAfterRestarting ( value ) ;
} ;
2017-03-19 16:46:16 +01:00
$scope . setDebugMode = function ( value ) {
ariaNgSettingService . setDebugMode ( value ) ;
} ;
$scope . setTitle = function ( value ) {
ariaNgSettingService . setTitle ( value ) ;
} ;
$scope . setTitleRefreshInterval = function ( value ) {
2017-03-29 03:06:43 +02:00
setNeedRefreshPage ( ) ;
2017-03-19 16:46:16 +01:00
ariaNgSettingService . setTitleRefreshInterval ( value ) ;
} ;
$scope . isSupportNotification = function ( ) {
return ariaNgNotificationService . isSupportBrowserNotification ( ) &&
ariaNgSettingService . isCurrentRpcUseWebSocket ( $scope . context . settings . protocol ) ;
} ;
$scope . setEnableBrowserNotification = function ( value ) {
ariaNgSettingService . setBrowserNotification ( value ) ;
if ( value && ! ariaNgNotificationService . hasBrowserPermission ( ) ) {
ariaNgNotificationService . requestBrowserPermission ( function ( permission ) {
if ( ! ariaNgNotificationService . isPermissionGranted ( permission ) ) {
$scope . context . settings . browserNotification = false ;
ariaNgCommonService . showError ( 'You have disabled notification in your browser. You should change your browser\'s settings before you enable this function.' ) ;
}
} ) ;
}
} ;
$scope . setGlobalStatRefreshInterval = function ( value ) {
2017-03-29 03:06:43 +02:00
setNeedRefreshPage ( ) ;
2017-03-19 16:46:16 +01:00
ariaNgSettingService . setGlobalStatRefreshInterval ( value ) ;
} ;
$scope . setDownloadTaskRefreshInterval = function ( value ) {
2017-03-29 03:06:43 +02:00
setNeedRefreshPage ( ) ;
2017-03-19 16:46:16 +01:00
ariaNgSettingService . setDownloadTaskRefreshInterval ( value ) ;
} ;
2016-06-22 16:23:18 +02:00
2017-03-19 16:36:14 +01:00
$scope . addNewRpcSetting = function ( ) {
2017-03-29 03:06:43 +02:00
setNeedRefreshPage ( ) ;
2017-03-19 16:36:14 +01:00
var newRpcSetting = ariaNgSettingService . addNewRpcSetting ( ) ;
$scope . context . rpcSettings . push ( newRpcSetting ) ;
$scope . changeRpcTab ( $scope . context . rpcSettings . length - 1 ) ;
} ;
$scope . updateRpcSetting = function ( setting , field ) {
2017-03-29 03:06:43 +02:00
setNeedRefreshPage ( ) ;
2017-03-19 16:36:14 +01:00
ariaNgSettingService . updateRpcSetting ( setting , field ) ;
} ;
$scope . removeRpcSetting = function ( setting ) {
2017-03-25 06:06:55 +01:00
var rpcName = ( setting . rpcAlias ? setting . rpcAlias : setting . rpcHost + ':' + setting . rpcPort ) ;
ariaNgCommonService . confirm ( 'Confirm Remove' , 'Are you sure you want to remove rpc setting "{{rpcName}}"?' , 'warning' , function ( ) {
2017-03-29 03:06:43 +02:00
setNeedRefreshPage ( ) ;
2017-03-19 16:36:14 +01:00
var index = $scope . context . rpcSettings . indexOf ( setting ) ;
ariaNgSettingService . removeRpcSetting ( setting ) ;
$scope . context . rpcSettings . splice ( index , 1 ) ;
if ( index >= $scope . context . rpcSettings . length ) {
$scope . changeRpcTab ( $scope . context . rpcSettings . length - 1 ) ;
}
2017-03-25 06:06:55 +01:00
} , false , {
textParams : {
rpcName : rpcName
}
2017-03-19 16:36:14 +01:00
} ) ;
} ;
$scope . setDefaultRpcSetting = function ( setting ) {
if ( setting . isDefault ) {
return ;
}
ariaNgSettingService . setDefaultRpcSetting ( setting ) ;
$window . location . reload ( ) ;
} ;
2017-06-18 08:00:14 +02:00
$scope . resetSettings = function ( ) {
ariaNgCommonService . confirm ( 'Confirm Reset' , 'Are you sure you want to reset all settings?' , 'warning' , function ( ) {
ariaNgSettingService . resetSettings ( ) ;
$window . location . reload ( ) ;
} ) ;
} ;
2017-06-18 07:46:34 +02:00
angular . element ( '[data-toggle="popover"]' ) . popover ( ) ;
2016-11-06 08:58:04 +01:00
2016-08-01 16:49:16 +02:00
$rootScope . loadPromise = $timeout ( function ( ) { } , 100 ) ;
2016-05-16 17:41:39 +02:00
} ] ) ;
2016-08-01 16:49:16 +02:00
} ( ) ) ;