Skip to content

Commit 3e25107

Browse files
committed
Fixing instance create -> updating instance list
1 parent 8428ad8 commit 3e25107

7 files changed

Lines changed: 24 additions & 15 deletions

File tree

client/controllers/abstractLayouts/controllerInstanceLayout.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ function ControllerInstanceLayout(
3333
githubUsername: account
3434
})
3535
.cacheFetch(function (instances, cached, cb) {
36-
if (account === keypather.get($rootScope, 'dataApp.data.activeAccount.oauthName()') &&
37-
$rootScope.dataApp.data.instances !== instances) {
38-
$rootScope.dataApp.data.instances = instances;
36+
if (account === keypather.get($rootScope, 'dataApp.data.activeAccount.oauthName()')) {
37+
if ($rootScope.dataApp.data.instances !== instances) {
38+
$rootScope.dataApp.data.instances = instances;
39+
}
3940
$scope.dataInstanceLayout.state.loadingInstances = false;
4041
$rootScope.safeApply(cb);
4142
} else {
@@ -51,18 +52,23 @@ function ControllerInstanceLayout(
5152
if (err) { throw err; }
5253
});
5354
}
54-
5555
var dataInstanceLayout = $scope.dataInstanceLayout = {
5656
data: {},
5757
state: {},
5858
actions: {}
5959
};
6060
dataInstanceLayout.data.logoutURL = configLogoutURL();
6161

62-
$rootScope.$watch('dataApp.data.activeAccount.oauthName()', function (n) {
63-
if (n) {
64-
fetchInstances(n);
65-
}
62+
var instanceListUnwatcher = $scope.$on('INSTANCE_LIST_FETCH', function(event, org) {
63+
fetchInstances(org.oauthName());
64+
});
65+
66+
$scope.$on('$destroy', function () {
67+
instanceListUnwatcher();
6668
});
6769

70+
if (keypather.get($rootScope, 'dataApp.data.activeAccount.oauthName()')) {
71+
fetchInstances(keypather.get($rootScope, 'dataApp.data.activeAccount.oauthName()'));
72+
}
73+
6874
}

client/controllers/controllerApp.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ function ControllerApp(
5757
if (!dataApp.data.activeAccount) {
5858
dataApp.data.activeAccount = thisUser;
5959
}
60+
$scope.$broadcast('INSTANCE_LIST_FETCH', dataApp.data.activeAccount);
6061
$rootScope.safeApply();
6162
}
6263
});

client/controllers/instance/controllerInstance.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ require('app')
55
*/
66
function ControllerInstance(
77
async,
8-
determineActiveAccount,
8+
$filter,
99
errs,
1010
keypather,
1111
OpenItems,
@@ -43,8 +43,9 @@ function ControllerInstance(
4343
if (n !== p && n) {
4444
unwatch();
4545
if (n.models.length) {
46+
var models = $filter('orderBy')(n.models, 'attrs.name');
4647
$state.go('instance.instance', {
47-
instanceName: n.models[0].attrs.name,
48+
instanceName: models[0].attrs.name,
4849
userName: $stateParams.userName
4950
}, {location: 'replace'});
5051
} else {

client/controllers/setup/controllerNew.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@ require('app')
66
function ControllerNew(
77
async,
88
hasKeypaths,
9-
QueryAssist,
109
errs,
1110
fetchUser,
1211
$scope,
1312
$state,
1413
uuid,
15-
user
14+
$stateParams
1615
) {
1716

1817
var thisUser;

client/directives/accountsSelect/directiveAccountsSelect.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ function accountsSelect (
3333
var username = userOrOrg.oauthName();
3434
//
3535
$scope.data.activeAccount = userOrOrg;
36+
$scope.$emit('INSTANCE_LIST_FETCH', userOrOrg);
3637
$state.go('^.instance', {
3738
userName: username,
3839
instanceName: ''

client/directives/setupPrimaryActions/directiveSetupPrimaryActions.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ require('app')
66
function setupPrimaryActions(
77
async,
88
$state,
9-
$stateParams
9+
$stateParams,
10+
$rootScope
1011
) {
1112
return {
1213
restrict: 'E',
@@ -50,7 +51,7 @@ function setupPrimaryActions(
5051
};
5152
$scope.instanceOpts.build = $scope.data.build.id();
5253
$scope.instanceOpts.name = $scope.name;
53-
$scope.instance = $scope.data.user.createInstance($scope.instanceOpts, cb);
54+
$scope.instance = $rootScope.dataApp.data.instances.create($scope.instanceOpts, cb);
5455
}
5556
async.series([
5657
build,

client/templates/setup/viewSetup.jade

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ header.box-header
77
)
88

99
setup-primary-actions(
10-
active-account = "activeAccount"
10+
active-account = "dataApp.data.activeAccount"
1111
instance-opts = "dataSetup.data.instanceOpts"
1212
loading = "dataApp.data.loading"
1313
name = "dataSetup.data.newInstanceName"

0 commit comments

Comments
 (0)