@@ -27,6 +27,12 @@ angular
2727 controller : 'AppDefinitionCtrl' ,
2828 icon : 'code'
2929 } ,
30+ {
31+ name : 'App details' ,
32+ url : '/apps/:appName' ,
33+ templateUrl : 'templates/app-details.html' ,
34+ controller : 'AppDetailsCtrl' ,
35+ } ,
3036 {
3137 name : 'Nodes' ,
3238 url : '/nodes' ,
@@ -721,20 +727,14 @@ function AlertsCtrl($scope) {
721727 } ;
722728}
723729angular . module ( 'RDash' )
724- . controller ( 'AppDefinitionCtrl' , [ '$scope' , '$cookieStore' ,
725- '$rootScope' , 'pageDefinitions' , 'apiManager' , 'captainToast' ,
726- '$uibModal' , '$state' , '$location' , '$interval' , AppDefinitionCtrl ] ) ;
730+ . controller ( 'AppDefinitionCtrl' , [ '$scope' , 'apiManager' , 'captainToast' , '$state' , '$location' ,
731+ AppDefinitionCtrl ] ) ;
727732
728- function AppDefinitionCtrl ( $scope , $cookieStore , $rootScope , pageDefinitions ,
729- apiManager , captainToast , $uibModal , $state , $location , $interval ) {
733+ function AppDefinitionCtrl ( $scope , apiManager , captainToast , $state , $location ) {
730734
731- $scope . rootDomainWithProtocol = '' ;
732735 $scope . loadingState = { } ;
733736 $scope . loadingState . enabled = true ;
734737 $scope . search = { } ;
735- $scope . editContent = {
736- appsToEdit : [ ]
737- } ;
738738
739739 $scope . allApps = null ;
740740 apiManager . getAllApps ( function ( data ) {
@@ -758,20 +758,100 @@ function AppDefinitionCtrl($scope, $cookieStore, $rootScope, pageDefinitions,
758758 }
759759 }
760760
761+ $scope . rootDomain = data . rootDomain ;
762+ } ) ;
763+
764+
765+ ( function AppDefinitionsContentCtrl ( ) {
766+
767+ $scope . newAppData = { } ;
768+
769+ $scope . onCreateOneClickAppClick = function ( ) {
770+ $location . path ( '/oneclickapps' ) ;
771+ }
772+
773+ $scope . onCreateNewAppClicked = function ( ) {
774+ $scope . loadingState . enabled = true ;
775+
776+ var appName = $scope . newAppData . newAppToRegister ;
777+ var hasPersistentData = $scope . newAppData . newAppHasPersistentData ;
778+
779+ apiManager . registerNewApp ( appName , hasPersistentData , function ( data ) {
780+
781+ if ( captainToast . showErrorToastIfNeeded ( data ) ) {
782+ $scope . loadingState . enabled = false ;
783+ return ;
784+ }
785+
786+ captainToast . showToastSuccess ( 'You new app is registered ' + appName ) ;
787+ $state . reload ( ) ;
788+
789+ } ) ;
790+ } ;
791+
792+ $scope . openAppEdit = function ( app ) {
793+ $location . url ( '/apps/' + app . appName ) ;
794+ }
795+
796+ } ( ) )
797+
798+ }
799+
800+ angular . module ( 'RDash' )
801+ . controller ( 'AppDetailsCtrl' , [ '$scope' , 'apiManager' , 'captainToast' ,
802+ '$uibModal' , '$state' , '$location' , '$interval' , '$stateParams' , AppDetailsCtrl ] ) ;
803+
804+ function AppDetailsCtrl ( $scope ,
805+ apiManager , captainToast , $uibModal , $state , $location , $interval , $stateParams ) {
806+ $scope . rootDomainWithProtocol = '' ;
807+ $scope . loadingState = { } ;
808+ $scope . loadingState . enabled = true ;
809+ $scope . editContext = {
810+ appToEdit : undefined
811+ }
812+
813+ apiManager . getAllApps ( function ( data ) {
814+ $scope . loadingState . enabled = false ;
815+ if ( captainToast . showErrorToastIfNeeded ( data ) ) {
816+ return ;
817+ }
818+
819+ const allApps = data . data ;
820+
821+ for ( var i = 0 ; i < data . data . length ; i ++ ) {
822+
823+ var app = data . data [ i ] ;
824+
825+ for ( var j = 0 ; j < app . versions . length ; j ++ ) {
826+ if ( app . versions [ j ] . version === app . deployedVersion ) {
827+ app . deployedGitHash = app . versions [ j ] . gitHash || 'n/a' ;
828+ app . deployedTimeStamp = new Date ( app . versions [ j ] . timeStamp ) . toLocaleString ( ) ;
829+ break ;
830+ }
831+ }
832+ }
833+
834+ const appNameInRoute = $stateParams . appName ;
835+ const appToEdit = allApps . find ( app => app . appName === appNameInRoute ) ;
836+ if ( ! appToEdit ) {
837+ $location . url ( '/apps' ) ; // app not found
838+ }
839+ $scope . editContext . appToEdit = appToEdit ;
840+ $scope . app = $scope . editContext . appToEdit ;
841+
761842 $scope . rootDomain = data . rootDomain ;
762843 $scope . defaultNginxConfig = data . defaultNginxConfig ;
763844 $scope . rootDomainWithProtocol = window . location . protocol + '//captain.' + data . rootDomain ;
764-
765845 } ) ;
766846
767847 // it is called via interval and it is also called directly
768848 function fetchBuildLogs ( ) {
769849
770- if ( ! $scope . editContent . appsToEdit . length ) {
850+ if ( ! $scope . editContext . appToEdit ) {
771851 return ;
772852 }
773853
774- var app = $scope . editContent . appsToEdit [ 0 ] ;
854+ var app = $scope . editContext . appToEdit ;
775855
776856 apiManager . fetchBuildLogs ( app . appName , function ( data ) {
777857
@@ -780,9 +860,9 @@ function AppDefinitionCtrl($scope, $cookieStore, $rootScope, pageDefinitions,
780860 }
781861 var logInfo = data . data ;
782862
783- app . isAppBuilding = logInfo . isAppBuilding ;
863+ $scope . isAppBuilding = logInfo . isAppBuilding ;
784864
785- if ( app . isAppBuilding ) {
865+ if ( $scope . isAppBuilding ) {
786866 // forcefully expanding the view such that when building finishes it doesn't collapses automatically
787867 app . expandedLogs = true ;
788868 }
@@ -826,23 +906,26 @@ function AppDefinitionCtrl($scope, $cookieStore, $rootScope, pageDefinitions,
826906 if ( lineAdded ) {
827907 setTimeout ( function ( ) {
828908 var textarea = document . getElementById ( 'buildlog-text-id' ) ;
829- textarea . scrollTop = textarea . scrollHeight ;
909+ if ( textarea ) textarea . scrollTop = textarea . scrollHeight ;
830910 } , 500 ) ;
831911 }
832912
833913 } ) ;
834914 }
835915
916+ // Fetch the build logs immediately...
917+ fetchBuildLogs ( ) ;
918+
919+ // ... and every other second
836920 var promise = $interval ( fetchBuildLogs , 2000 ) ;
837921 $scope . $on ( '$destroy' , function ( ) {
838922 $interval . cancel ( promise ) ;
839923 } ) ;
840924
841925 ( function AppDefinitionsContentCtrl ( ) {
842926
843- $scope . newAppData = { } ;
844-
845- $scope . onExpandLogClicked = function ( app ) {
927+ $scope . onExpandLogClicked = function ( ) {
928+ const app = $scope . editContext . appToEdit ;
846929 app . expandedLogs = ! app . expandedLogs ;
847930 } ;
848931
@@ -866,59 +949,31 @@ function AppDefinitionCtrl($scope, $cookieStore, $rootScope, pageDefinitions,
866949 } ) ;
867950 } ;
868951
869- $scope . onCreateOneClickAppClick = function ( ) {
870- $location . path ( '/oneclickapps' ) ;
871- }
872-
873- $scope . onCreateNewAppClicked = function ( ) {
874- $scope . loadingState . enabled = true ;
875-
876- var appName = $scope . newAppData . newAppToRegister ;
877- var hasPersistentData = $scope . newAppData . newAppHasPersistentData ;
878-
879- apiManager . registerNewApp ( appName , hasPersistentData , function ( data ) {
880-
881- if ( captainToast . showErrorToastIfNeeded ( data ) ) {
882- $scope . loadingState . enabled = false ;
883- return ;
884- }
885-
886- captainToast . showToastSuccess ( 'You new app is registered ' + appName ) ;
887- $state . reload ( ) ;
888-
889- } ) ;
890- } ;
891-
892- $scope . openAppEdit = function ( app ) {
893- // Make a copy of app object to avoid showing the unsaved data in the table
894- $scope . editContent . appsToEdit . push ( JSON . parse ( JSON . stringify ( app ) ) ) ;
895- fetchBuildLogs ( ) ;
896- }
897-
898- $scope . closeAppEdit = function ( app ) {
899- var idx = $scope . editContent . appsToEdit . indexOf ( app ) ;
900- if ( idx > - 1 ) {
901- $scope . editContent . appsToEdit . splice ( idx , 1 ) ;
902- }
952+ $scope . closeAppEdit = function ( ) {
953+ $location . url ( '/apps' ) ;
903954 }
904955
905- $scope . unlockNodeId = function ( app ) {
956+ $scope . unlockNodeId = function ( ) {
957+ const app = $scope . editContext . appToEdit ;
906958 app . unlockNodeIdForEdit = true ;
907959 }
908960
909- $scope . addPortMappingClicked = function ( app ) {
961+ $scope . addPortMappingClicked = function ( ) {
962+ const app = $scope . editContext . appToEdit ;
910963 if ( ! app . ports )
911964 app . ports = [ ] ;
912965 app . ports . push ( { containerPort : '' , hostPort : '' } ) ;
913966 }
914967
915- $scope . addEnvVarClicked = function ( app ) {
968+ $scope . addEnvVarClicked = function ( ) {
969+ const app = $scope . editContext . appToEdit ;
916970 if ( ! app . envVars )
917971 app . envVars = [ ] ;
918972 app . envVars . push ( { key : '' , value : '' } ) ;
919973 }
920974
921- $scope . addVolumeClicked = function ( app ) {
975+ $scope . addVolumeClicked = function ( ) {
976+ const app = $scope . editContext . appToEdit ;
922977 if ( ! app . volumes )
923978 app . volumes = [ ] ;
924979 app . volumes . push ( { volumeName : '' , containerPath : '' } ) ;
@@ -931,7 +986,8 @@ function AppDefinitionCtrl($scope, $cookieStore, $rootScope, pageDefinitions,
931986 }
932987 }
933988
934- $scope . onEditDefaultNginxConfigClicked = function ( app ) {
989+ $scope . onEditDefaultNginxConfigClicked = function ( ) {
990+ const app = $scope . editContext . appToEdit ;
935991 app . customNginxConfig = $scope . defaultNginxConfig ;
936992 }
937993
@@ -955,9 +1011,10 @@ function AppDefinitionCtrl($scope, $cookieStore, $rootScope, pageDefinitions,
9551011 $scope . modalAppDelete = { } ;
9561012 var modalAppDelete = $scope . modalAppDelete ;
9571013
958- $scope . onDeleteAppClicked = function ( appName ) {
1014+ $scope . onDeleteAppClicked = function ( appName , hasPersistentData ) {
9591015
9601016 $scope . modalAppDelete . appName = appName ;
1017+ $scope . modalAppDelete . hasPersistentData = hasPersistentData ;
9611018 $scope . modalAppDelete . appNameConfirm = '' ;
9621019
9631020 $uibModal . open ( {
@@ -995,10 +1052,10 @@ function AppDefinitionCtrl($scope, $cookieStore, $rootScope, pageDefinitions,
9951052 } ) ;
9961053 } ;
9971054
998- $scope . onUploadSourceCodeClicked = function ( app ) {
1055+ $scope . onUploadSourceCodeClicked = function ( ) {
1056+ const app = $scope . editContext . appToEdit ;
9991057
10001058 // file to upload is app.sourceToUpload
1001-
10021059 console . log ( app . sourceToUpload ) ;
10031060
10041061 $uibModal . open ( {
@@ -1029,7 +1086,7 @@ function AppDefinitionCtrl($scope, $cookieStore, $rootScope, pageDefinitions,
10291086 app . lastLineNumberPrinted = undefined ;
10301087 app . buildLogs = undefined ;
10311088 fetchBuildLogs ( ) ;
1032-
1089+
10331090 } ) ;
10341091 } ) ;
10351092 } ;
@@ -1066,7 +1123,8 @@ function AppDefinitionCtrl($scope, $cookieStore, $rootScope, pageDefinitions,
10661123 } ) ;
10671124 } ;
10681125
1069- $scope . onUpdateConfigAndSave = function ( app ) {
1126+ $scope . onUpdateConfigAndSave = function ( ) {
1127+ const app = $scope . editContext . appToEdit ;
10701128 $scope . loadingState . enabled = true ;
10711129
10721130 var appDefinition = {
0 commit comments