Created
May 6, 2016 20:07
-
-
Save adastreamer/be746a36b8be5ddedf06d942dd0c3e63 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module 'dokkurFrontend' | |
.controller 'AppSettingsController', ( | |
$timeout | |
$q | |
$interval | |
$state | |
$scope | |
$rootScope | |
SEO | |
dkSubscriberService | |
AsyncAction | |
dkInstancesService | |
dkKeysService | |
dkAppsService | |
dkAppCreateService | |
checkAuthAndGoTo | |
userStore | |
dkSignoutService | |
dkGetAppService | |
dkInstancePs | |
dkConfirm | |
dkPrompt | |
dkAlert | |
dkInstanceAppsCreate | |
dkInstanceAppsDestroy | |
dkAppDestroyService | |
dkInstanceConfig | |
dkInstanceConfigSetunset | |
dkInstanceConfigUnsetWithoutRestart | |
dkInstanceConfigSetWithoutRestart | |
dkInstancePsRestart | |
) -> | |
'ngInject' | |
vm = this | |
checkAuthAndGoTo 'app.settings', 'signin' | |
vm.user = userStore.get() | |
return if not vm.user | |
$("body").scrollTop(0) | |
# SEO section | |
$rootScope.pageTitle = 'App Settings | Dokkur' | |
$rootScope.pageDescription = '' | |
$rootScope.pageKeywords = '' | |
# end of SEO section | |
vm.filterVariable = (variable) -> | |
not variable.isDeleted | |
vm.appName = $state.params.name | |
vm.getConfigs = () -> | |
vm.loading = true | |
dkInstanceConfig( | |
vm.instance | |
vm.key | |
vm.app.name | |
(instanceData) -> | |
vm.loading = false | |
vm.configData = instanceData.data | |
vm.variables = vm.configData.parsed_result.variables | |
vm.editableVariables = angular.copy(vm.variables) | |
(instanceErr) -> | |
vm.loading = false | |
dkAlert.show('Error!', 'Error while getting configs!', 'Got it!') | |
) | |
vm.loading = true | |
dkGetAppService.get( | |
{ app_name: vm.appName } | |
(data) -> | |
vm.app = data.app | |
vm.key = data.app.instance_id.keys_set[0] | |
vm.instance = vm.app.instance_id | |
vm.loading = false | |
vm.getConfigs() | |
(err) -> | |
vm.loading = false | |
checkAuthAndGoTo 'apps', 'signin' | |
) | |
vm.getGitUrl = (app) -> | |
return if not app | |
vm.user.username + '@' + app.instance_id.ip_hostname + ':' + app.name | |
vm.confirmDelete = () -> | |
dkPrompt.show( | |
'Delete app' | |
'Deleting your app is irreversible. Enter your app\'s name (' + vm.app.name + ') below to confirm you want to permanently delete it:' | |
'Delete app' | |
'Cancel' | |
(enteredName) -> | |
if (enteredName != vm.app.name) | |
return dkAlert.show('Error!', 'Name mismatch!', 'Got it!') | |
vm.deleteInProgress = true | |
dkInstanceAppsDestroy( | |
vm.instance | |
vm.key | |
vm.app.name | |
(instanceData) -> | |
dkAppDestroyService.save( | |
{application_id: vm.app.id} | |
(data) -> | |
checkAuthAndGoTo 'apps', 'signin' | |
(err) -> | |
vm.deleteInProgress = false | |
dkAlert.show('Error!', 'Error while deleting the app!', 'Got it!') | |
) | |
(instanceErr) -> | |
dkAlert.show('Error!', 'Error while deleting the app on instance!', 'Got it!') | |
) | |
() -> | |
console.log("canceled") | |
) | |
vm.cancelVariablesEditing = () -> | |
vm.editableVariables = angular.copy(vm.variables) | |
vm.variablesEditMode = false | |
vm.startVariablesEditing = () -> | |
vm.variablesEditMode = true | |
vm.addNewVariable = () -> | |
vm.editableVariables.push({name: '', value: ''}) | |
vm.unsetVariables = [] | |
vm.removeVariable = (variable) -> | |
inVarList = vm.variables.filter( (v) -> | |
v.name == variable | |
).length > 0 | |
vm.unsetVariables.push(variable.name) if (vm.unsetVariables.indexOf(variable.name) < 0) and not inVarList | |
vm.editableVariables = vm.editableVariables.filter (v) -> | |
v != variable | |
vm.unsetWithoutRestart = (successCallback, errorCallback) -> | |
dkInstanceConfigUnsetWithoutRestart( | |
vm.instance | |
vm.key | |
vm.app.name + ' ' + vm.unsetVariables.join(' ') | |
successCallback | |
errorCallback | |
) | |
vm.setWithoutRestart = (successCallback, errorCallback) -> | |
configsString = '' | |
for v in vm.editableVariables | |
configsString = configsString + v.name + '=' + v.value + ' ' if v.name | |
dkInstanceConfigSetWithoutRestart( | |
vm.instance | |
vm.key | |
vm.app.name + ' ' + configsString | |
successCallback | |
errorCallback | |
) | |
vm.restartApp = (successCallback, errorCallback) -> | |
dkInstancePsRestart( | |
vm.instance | |
vm.key | |
vm.app.name | |
() -> | |
vm.loading = false | |
dkAlert.show('Success!', '', 'Got it!') | |
() -> | |
vm.loading = false | |
dkAlert.show('Warning!', 'Unable to restart app', 'Got it!') | |
) | |
vm.saveVariables = () -> | |
vm.variablesEditMode = false | |
vm.loading = true | |
vm.setWithoutRestart( | |
() -> | |
if (vm.unsetVariables.length > 0) | |
vm.unsetWithoutRestart( | |
() -> | |
vm.restartApp() | |
() -> | |
vm.restartApp() | |
) | |
else | |
vm.restartApp() | |
() -> | |
if (vm.unsetVariables.length > 0) | |
vm.unsetWithoutRestart( | |
() -> | |
vm.restartApp() | |
() -> | |
vm.restartApp() | |
) | |
else | |
dkAlert.show('Error!', 'Unable to set variables', 'Got it!') | |
) | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment