Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TEAMFOUR-713 - move cluster actions to common controller #480

Merged
merged 4 commits into from
Jul 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/app/view/endpoints/clusters/cluster/cluster.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
<div class="cluster">
<span class="cluster-breadcrumb" ncy-breadcrumb></span>
<ui-view/>
<ui-view></ui-view>
<ul class="col-md-3 hidden-sm hidden-xs list-unstyled application-action-col">
<li ng-repeat="clusterAction in clusterController.clusterActions">
<button class="btn btn-link btn-border-less"
ng-disabled="clusterAction.disabled"
ng-hide="clusterAction.hidden"
ng-click="clusterAction.execute()">
<i ng-class="clusterAction.icon"></i> {{ clusterAction.name }}
</button>
</li>
</ul>
</div>

93 changes: 82 additions & 11 deletions src/app/view/endpoints/clusters/cluster/cluster.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,42 +24,110 @@
}

ClusterController.$inject = [
'app.model.modelManager',
'$stateParams',
'$log',
'app.utils.utilsService',
'$state',
'$q'
'$q',
'app.model.modelManager',
'helion.framework.widgets.asyncTaskDialog'
];

function ClusterController(modelManager, $stateParams, $log, utils, $state, $q) {
function ClusterController($stateParams, $log, utils, $state, $q, modelManager, asyncTaskDialog) {
var that = this;

this.guid = $stateParams.guid;
var organizationModel = modelManager.retrieve('cloud-foundry.model.organization');
var serviceBindingModel = modelManager.retrieve('cloud-foundry.model.service-binding');
var privateDomains = modelManager.retrieve('cloud-foundry.model.private-domain');
var sharedDomains = modelManager.retrieve('cloud-foundry.model.shared-domain');
var appModel = modelManager.retrieve('cloud-foundry.model.application');
var stackatoInfo = modelManager.retrieve('app.model.stackatoInfo');

this.initialized = false;
this.guid = $stateParams.guid;
this.userServiceInstanceModel = modelManager.retrieve('app.model.serviceInstance.user');

this.getEndpoint = function () {
return utils.getClusterEndpoint(that.userServiceInstanceModel.serviceInstances[that.guid]);
};

this.clusterActions = [
{
name: gettext('Create Organization'),
disabled: true,
execute: function () {
return asyncTaskDialog(
{
title: gettext('Create Organization'),
templateUrl: 'app/view/endpoints/clusters/cluster/detail/actions/create-organization.html',
buttonTitles: {
submit: gettext('Create')
}
},
{
data: {
// Make the form invalid if the name is already taken
organizationNames: organizationModel.organizationNames[that.guid]
}
},
function (orgData) {
if (orgData.name && orgData.name.length > 0) {
return organizationModel.createOrganization(that.guid, orgData.name);
} else {
return $q.reject('Invalid Name!');
}

}
);
},
icon: 'helion-icon-lg helion-icon helion-icon-Tree'
},
{
name: gettext('Create Space'),
disabled: true,
execute: function () {
},
icon: 'helion-icon-lg helion-icon helion-icon-Tree'
},
{
name: gettext('Assign User(s)'),
disabled: true,
execute: function () {
},
icon: 'helion-icon-lg helion-icon helion-icon-Add_user'
}
];

/**
* Enable actions based on admin status
* N.B. when finer grain ACLs are wired in this should be updated
* */
function enableActions() {
if (stackatoInfo.info.endpoints.hcf[that.guid].user.admin) {
_.forEach(that.clusterActions, function (action) {
action.disabled = false;
});
// Disable these until implemented!
that.clusterActions[1].disabled = that.clusterActions[2].disabled = true;
}
}

function init() {

// Cache all organizations associated with this cluster
var orgPromise = organizationModel.listAllOrganizations(that.guid, {}).then(function (orgs) {
var promises = [];
var allDetailsP = [];
_.forEach(orgs, function (org) {
var promise = organizationModel.getOrganizationDetails(that.guid, org).catch(function () {
//Swallow errors for individual orgs
var orgDetailsP = organizationModel.getOrganizationDetails(that.guid, org).catch(function () {
// Swallow errors for individual orgs
$log.error('Failed to fetch details for org - ' + org.entity.name);
});
promises.push(promise);
allDetailsP.push(orgDetailsP);
});
return $q.all(allDetailsP).then(function (val) {
enableActions();
that.organizationNames = organizationModel.organizationNames[that.guid];
return val;
});
return $q.all(promises);
}).catch(function (error) {
$log.error('Error while listing organizations', error);
});
Expand All @@ -82,7 +150,10 @@
// Reset any cache we may be interested in
delete appModel.appSummary;

return $q.all([orgPromise, servicesPromise, serviceBindingPromise, privateDomainsPromise, sharedDomainsPromise]);
return $q.all([orgPromise, servicesPromise, serviceBindingPromise, privateDomainsPromise, sharedDomainsPromise])
.finally(function () {
that.initialized = true;
});
}

utils.chainStateResolve('endpoint.clusters.cluster', $state, init);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</div>
<div class="cluster-gallery-card-container" ng-if="clusterDetailController.organizations">
<div class="cluster-gallery-card-parent" ng-repeat="organization in clusterDetailController.organizations track by organization.guid">
<organization-tile organization="organization" organization-names="clusterDetailController.organizationNames"></organization-tile>
<organization-tile organization="organization" organization-names="clusterController.organizationNames"></organization-tile>
</div>
</div>

Expand Down
13 changes: 0 additions & 13 deletions src/app/view/endpoints/clusters/cluster/detail/cluster-detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,3 @@ <h3>{{ clusterController.userServiceInstanceModel.serviceInstances[clusterContro
<ui-view></ui-view>

</div>

<ul class="col-md-3 hidden-sm hidden-xs list-unstyled application-action-col">
<li ng-repeat="clusterAction in clusterDetailController.clusterActions">
<button class="btn btn-link btn-border-less"
ng-disabled="clusterAction.disabled"
ng-hide="clusterAction.hidden"
ng-click="clusterAction.execute()">
<i ng-class="clusterAction.icon"></i> {{ clusterAction.name }}
</button>
</li>
</ul>


Original file line number Diff line number Diff line change
Expand Up @@ -28,69 +28,21 @@
'$scope',
'app.utils.utilsService',
'$state',
'$q',
'helion.framework.widgets.asyncTaskDialog'
'$q'
];

function ClusterDetailController(modelManager, $stateParams, $scope, utils, $state, $q, asyncTaskDialog) {
function ClusterDetailController(modelManager, $stateParams, $scope, utils, $state, $q) {
var that = this;
this.guid = $stateParams.guid;

this.$scope = $scope;

this.organizations = [];
this.organizationNames = [];

this.totalApps = 0;

var organizationModel = modelManager.retrieve('cloud-foundry.model.organization');

this.clusterActions = [
{
name: gettext('Create Organization'),
disabled: true,
execute: function () {
return asyncTaskDialog(
{
title: gettext('Create Organization'),
templateUrl: 'app/view/endpoints/clusters/cluster/detail/actions/create-organization.html',
buttonTitles: {
submit: gettext('Create')
}
},
{
data: {
// Make the form invalid if the name is already taken
organizationNames: that.organizationNames
}
},
function (orgData) {
if (orgData.name && orgData.name.length > 0) {
return organizationModel.createOrganization(that.guid, orgData.name);
} else {
return $q.reject('Invalid Name!');
}

}
);
},
icon: 'helion-icon-lg helion-icon helion-icon-Tree'
},
{
name: gettext('Create Space'),
disabled: true,
execute: function () {
},
icon: 'helion-icon-lg helion-icon helion-icon-Tree'
},
{
name: gettext('Assign User(s)'),
disabled: true,
execute: function () {
},
icon: 'helion-icon-lg helion-icon helion-icon-Add_user'
}
];

this.updateTotalApps = function () {
that.totalApps = 0;
var totalMemoryMb = 0;
Expand All @@ -110,28 +62,9 @@
return o1.created_at - o2.created_at;
});
that.updateTotalApps();
that.organizationNames = _.map(that.organizations, function (org) {
return org.org.entity.name;
});
}

/**
* Enable actions based on admin status
* N.B. when finer grain ACLs are wired in this should be updated
* */
function enableActions() {
var stackatoInfo = modelManager.retrieve('app.model.stackatoInfo');
if (stackatoInfo.info.endpoints.hcf[that.guid].user.admin) {
_.forEach(that.clusterActions, function (action) {
action.disabled = false;
});
// Disable these until implemented!
that.clusterActions[1].disabled = that.clusterActions[2].disabled = true;
}
}

function init() {
enableActions();

// Start watching for further model changes after parent init chain completes
$scope.$watchCollection(function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
cursor: default;
float: left;
margin: 0 8px 8px 0;
padding: 0 4px 4px 4px;
padding: 1px 4px 4px 4px;
border: solid 2px $gray-light;
border-radius: 5px;
}
Expand All @@ -38,6 +38,7 @@
font-weight: bolder;
color: #aaa;
margin-left: 10px;
cursor: pointer;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
_.forEach(that.organizationModel.organizations[that.guid], function (org) {
var roles = org.roles[aUser.metadata.guid];
if (!_.isUndefined(roles)) {
myRoles[org.details.name] = roles;
myRoles[org.details.org.entity.name] = roles;
}
});
that.userRoles[aUser.metadata.guid] = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,3 @@ <h3>Organization : {{ clusterOrgDetailController.organization().details.org.enti
<ui-view></ui-view>

</div>

<ul ng-if="clusterOrgDetailController.organization().details" class="col-md-3 hidden-sm hidden-xs list-unstyled application-action-col">
<li ng-repeat="action in clusterOrgDetailController.actions">
<button class="btn btn-link btn-border-less"
ng-disabled="action.disabled"
ng-hide="action.hidden"
ng-click="action.execute()">
<i ng-class="action.icon"></i> {{ action.name }}
</button>
</li>
</ul>
Original file line number Diff line number Diff line change
Expand Up @@ -37,34 +37,8 @@
this.organizationModel = modelManager.retrieve('cloud-foundry.model.organization');
this.orgPath = this.organizationModel.fetchOrganizationPath(this.clusterGuid, this.organizationGuid);

this.actions = [
{
name: gettext('Create Organization'),
icon: 'helion-icon-lg helion-icon helion-icon-Tree',
disabled: true,
execute: function () {
}
},
{
name: gettext('Create Space'),
icon: 'helion-icon-lg helion-icon helion-icon-Tree',
disabled: true,
execute: function () {
}
},
{
name: gettext('Assign User(s)'),
icon: 'helion-icon-lg helion-icon helion-icon-Add_user',
disabled: true,
execute: function () {
}
}
];

function init() {
that.organizationNames = _.map(that.organizationModel.organizations[that.clusterGuid], function (org) {
return org.details.org.entity.name;
});
that.organizationNames = that.organizationModel.organizationNames[that.clusterGuid];
return $q.resolve();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,3 @@ <h3>Space : {{ clusterSpaceController.space().details.space.entity.name }}</h3>
</ul>
<ui-view></ui-view>
</div>




<ul class="col-md-3 hidden-sm hidden-xs list-unstyled application-action-col" ng-if="clusterSpaceController.space()">
<li ng-repeat="action in clusterSpaceController.spaceActions">
<button class="btn btn-link btn-border-less"
ng-disabled="action.disabled"
ng-hide="action.hidden"
ng-click="action.execute()">
<i ng-class="action.icon"></i> {{ action.name }}
</button>
</li>
</ul>
Loading