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

[OPAL-560] Cart - Ability to add the same app #545

Open
wants to merge 7 commits into
base: 2.0
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ angular.module 'mnoEnterpriseAngular'
controller: ($q, $state, $window, $uibModal, toastr, MnoeMarketplace, MnoeProvisioning, MnoeCurrentUser, MnoeOrganizations, MnoeAppInstances, MnoeConfig, ProvisioningHelper) ->
vm = this
vm.orderPossible = true
vm.allowCartProductProvision = true
vm.buttonText = ''
vm.buttonDisabledTooltip = ''

Expand Down Expand Up @@ -69,11 +70,13 @@ angular.module 'mnoEnterpriseAngular'
vm.canProvisionApp = false

vm.buttonDisabled = () ->
!vm.canProvisionApp || vm.appInstallationStatus() == "CONFLICT" || !vm.orderPossible
!vm.canProvisionApp || vm.appInstallationStatus() == "CONFLICT" || !vm.orderPossible || !vm.allowCartProductProvision

vm.updateButtonDisabledTooltip = () ->
if !vm.canProvisionApp
'mno_enterprise.templates.components.app_install_btn.insufficient_privilege'
else if !vm.allowCartProductProvision
'mno_enterprise.templates.components.app_install_btn.cart_product'
else if !vm.orderPossible
'mno_enterprise.templates.dashboard.marketplace.show.no_pricing_plans_found_tooltip'

Expand Down Expand Up @@ -234,6 +237,18 @@ angular.module 'mnoEnterpriseAngular'

vm.orderPossible = !_.isEmpty(availablePlans) || (plans.default?[0] && currencySelection) || ProvisioningHelper.skipPriceSelection(product)

# For Admins, check that the app/product is not already added to cart.
# If so, then prevent flow if the app/product is not multi instantiable
if vm.canProvisionApp
params = {where: {subscription_status_in: 'staged'}}
MnoeProvisioning.getSubscriptions(params, true).then(
(resp) ->
cartProducts = _.map(resp, (sub) -> sub?.product?.nid)
isCartProduct = vm.app.nid in cartProducts
vm.allowCartProductProvision = vm.app.multi_instantiable if isCartProduct
)
).finally(
->
vm.buttonText = vm.updateButtonText()
vm.buttonDisabledTooltip = vm.updateButtonDisabledTooltip()
)
Expand Down
164 changes: 88 additions & 76 deletions src/app/views/provisioning/subscriptions.controller.coffee
Original file line number Diff line number Diff line change
@@ -1,79 +1,91 @@
angular.module 'mnoEnterpriseAngular'
.controller('ProvisioningSubscriptionsCtrl', ($q, $scope, $state, $stateParams, toastr, MnoeOrganizations, MnoeProvisioning, MnoeConfig, MnoConfirm, PRICING_TYPES, ProvisioningHelper) ->

vm = this
vm.isLoading = true
vm.cartSubscriptions = $stateParams.subType == 'cart'
vm.skipPriceSelection = ProvisioningHelper.skipPriceSelection

vm.goToSubscription = (subscription) ->
ProvisioningHelper.goToSubscription(subscription, vm.cartSubscriptions)

vm.subscriptionsPromise = ->
if vm.cartSubscriptions
params = { where: {subscription_status_in: 'staged' } }
MnoeProvisioning.getSubscriptions(params)
else
params = { where: {subscription_status_in: 'visible' } }
MnoeProvisioning.getSubscriptions(params)

vm.deleteCart = ->
MnoeProvisioning.deleteCartSubscriptions().then(
(response) ->
MnoeProvisioning.emptyCartSubscriptions()
toastr.info('mno_enterprise.templates.dashboard.provisioning.subscriptions.cart.delete_cart.toastr')
$state.go("home.marketplace")
)

vm.submitCart = ->
MnoeProvisioning.submitCartSubscriptions().then(
(response) ->
# Reload dock apps
MnoeProvisioning.refreshCartSubscriptions()

toastr.success('mno_enterprise.templates.dashboard.provisioning.subscriptions.cart.submit_cart.toastr')
$state.go("home.subscriptions", {subType: 'active'})
)

vm.initialize = ->
vm.isLoading = true
orgPromise = MnoeOrganizations.get()
subPromise = vm.subscriptionsPromise()

$q.all({organization: orgPromise, subscriptions: subPromise}).then(
(response) ->
vm.subscriptions = response.subscriptions
if vm.cartSubscriptions && vm.subscriptions.length < 1
toastr.info('mno_enterprise.templates.dashboard.provisioning.subscriptions.cart.empty')
$state.go('home.marketplace')
return

vm.orgCurrency = response.organization.organization?.billing_currency || MnoeConfig.marketplaceCurrency()

# If a subscription doesn't contains a pricing for the org currency, a warning message is displayed
vm.displayCurrencyWarning = not _.every(response.subscriptions, (subscription) ->
currencies = _.map(subscription?.product_pricing?.prices, 'currency')
_.includes(currencies, vm.orgCurrency) || (subscription?.product_pricing?.pricing_type in PRICING_TYPES['unpriced'])
)
).finally(-> vm.isLoading = false)

#====================================
# Post-Initialization
#====================================
$scope.$watch MnoeOrganizations.getSelectedId, (val) ->
vm.initialize() if val?
.controller('ProvisioningSubscriptionsCtrl',
($q, $scope, $state, $stateParams, toastr, MnoeOrganizations, MnoeProvisioning, MnoeConfig, MnoConfirm, PRICING_TYPES, ProvisioningHelper, MnoeAppInstances, MnoeProductInstances) ->

vm.displayInfoTooltip = (subscription) ->
return subscription.status == 'aborted'

vm.showEditAction = (subscription, editAction) ->
ProvisioningHelper.showEditAction(subscription, editAction)

vm.editSubscription = (subscription, editAction) ->
ProvisioningHelper.editSubscription(subscription, editAction, vm.cartSubscriptions)

vm.pendingSubscription = (subscription) ->
subscription.status in ['pending', 'provisioning']

return
vm = this
vm.isLoading = true
vm.isCartSubmitting = false
vm.isCartDeleting = false
vm.cartSubscriptions = $stateParams.subType == 'cart'
vm.skipPriceSelection = ProvisioningHelper.skipPriceSelection

vm.goToSubscription = (subscription) ->
ProvisioningHelper.goToSubscription(subscription, vm.cartSubscriptions)

vm.subscriptionsPromise = ->
if vm.cartSubscriptions
params = { where: {subscription_status_in: 'staged' } }
MnoeProvisioning.getSubscriptions(params)
else
params = { where: {subscription_status_in: 'visible' } }
MnoeProvisioning.getSubscriptions(params)

vm.deleteCart = ->
return if vm.isCartSubmitting || vm.isCartDeleting
vm.isCartDeleting = true
MnoeProvisioning.deleteCartSubscriptions().then(
(response) ->
MnoeProvisioning.emptyCartSubscriptions()
toastr.info('mno_enterprise.templates.dashboard.provisioning.subscriptions.cart.delete_cart.toastr')
vm.isCartDeleting = false
$state.go("home.marketplace")
)

vm.submitCart = ->
return if vm.isCartSubmitting || vm.isCartDeleting
vm.isCartSubmitting = true
MnoeProvisioning.submitCartSubscriptions().then(
(response) ->
# Reload dock apps
MnoeProvisioning.refreshCartSubscriptions()
MnoeAppInstances.emptyAppInstances()
MnoeProductInstances.emptyProductInstances()
MnoeProductInstances.clearCache()

toastr.success('mno_enterprise.templates.dashboard.provisioning.subscriptions.cart.submit_cart.toastr')
vm.isCartSubmitting = false
$state.go("home.subscriptions", {subType: 'active'})
)

vm.initialize = ->
vm.isLoading = true
orgPromise = MnoeOrganizations.get()
subPromise = vm.subscriptionsPromise()

$q.all({organization: orgPromise, subscriptions: subPromise}).then(
(response) ->
vm.subscriptions = response.subscriptions
if vm.cartSubscriptions && vm.subscriptions.length < 1
toastr.info('mno_enterprise.templates.dashboard.provisioning.subscriptions.cart.empty')
$state.go('home.marketplace')
return

vm.orgCurrency = response.organization.organization?.billing_currency || MnoeConfig.marketplaceCurrency()

# If a subscription doesn't contains a pricing for the org currency, a warning message is displayed
vm.displayCurrencyWarning = not _.every(response.subscriptions, (subscription) ->
currencies = _.map(subscription?.product_pricing?.prices, 'currency')
_.includes(currencies, vm.orgCurrency) || (subscription?.product_pricing?.pricing_type in PRICING_TYPES['unpriced'])
)
).finally(-> vm.isLoading = false)

#====================================
# Post-Initialization
#====================================
$scope.$watch MnoeOrganizations.getSelectedId, (val) ->
vm.initialize() if val?

vm.displayInfoTooltip = (subscription) ->
return subscription.status == 'aborted'

vm.showEditAction = (subscription, editAction) ->
ProvisioningHelper.showEditAction(subscription, editAction)

vm.editSubscription = (subscription, editAction) ->
ProvisioningHelper.editSubscription(subscription, editAction, vm.cartSubscriptions)

vm.pendingSubscription = (subscription) ->
subscription.status in ['pending', 'provisioning']

return
)
6 changes: 4 additions & 2 deletions src/app/views/provisioning/subscriptions.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ <h2 class="section-title" ng-hide="vm.cartSubscriptions" translate>

<div id="provisioning-subscriptions" class="row top-buffer-2">
<div ng-show="vm.cartSubscriptions" class='text-right bottom-buffer-1'>
<button class='btn btn-primary' ng-click="vm.deleteCart()">
<button class='btn btn-primary' ng-disabled="vm.isCartDeleting || vm.isCartSubmitting" ng-click="vm.deleteCart()">
<span ng-show="vm.isCartDeleting"><i class='fa fa-spinner fa-pulse fa-fw'></i></span>
{{ 'mno_enterprise.templates.dashboard.provisioning.subscriptions.cart.delete_cart.title' | translate }}
</button>
<button class='btn btn-primary' ng-click="vm.submitCart()">
<button class='btn btn-primary' ng-disabled="vm.isCartDeleting || vm.isCartSubmitting" ng-click="vm.submitCart()">
<span ng-show="vm.isCartSubmitting"><i class='fa fa-spinner fa-pulse fa-fw'></i></span>
{{ 'mno_enterprise.templates.dashboard.provisioning.subscriptions.cart.submit_cart.title' | translate }}
</button>
</div>
Expand Down
1 change: 1 addition & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,7 @@
"mno_enterprise.templates.components.app_install_btn.access_addon": "Access Add-on",
"mno_enterprise.templates.components.app_install_btn.access_addon_tooltip": "This application requires you to set-up the connection in a separate screen.",
"mno_enterprise.templates.components.app_install_btn.insufficient_privilege": "You do not have the sufficient privileges. Contact your administrator.",
"mno_enterprise.templates.components.app_install_btn.cart_product": "Item is already added to Organization cart.",
"mno_enterprise.templates.components.app_install_btn.success_notification_title": "{name} has been added to your account",
"mno_enterprise.templates.components.app_install_btn.success_launch_notification_body": "To start using {name}, click on the {name} icon then click on \"Launch\".",
"mno_enterprise.templates.components.app_install_btn.success_connect_notification_body": "To start using {name}, click on the {name} icon then click on \"Connect\".",
Expand Down