Skip to content
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
54 changes: 52 additions & 2 deletions src/app/views/marketplace/marketplace-compare.controller.coffee
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
angular.module 'mnoEnterpriseAngular'
.controller('DashboardMarketplaceCompareCtrl', ($scope, $stateParams, $state,
MnoeMarketplace, PRICING_CONFIG) ->
.controller('DashboardMarketplaceCompareCtrl', ($q, $scope, $stateParams, $state,
MnoeMarketplace, $uibModal, MnoeOrganizations, MnoeCurrentUser, MnoeAppInstances, MnoErrorsHandler, REVIEWS_CONFIG, PRICING_CONFIG) ->

vm = this

vm.app = {}
# The already installed app instance of the app, if any
vm.appInstance = null
# An already installed app, conflicting with the app because it contains a common subcategory
# that is not multi instantiable, if any
vm.conflictingApp = null

vm.isPriceShown = PRICING_CONFIG && PRICING_CONFIG.enabled

#====================================
Expand All @@ -14,6 +21,49 @@ angular.module 'mnoEnterpriseAngular'
currency = (PRICING_CONFIG && PRICING_CONFIG.currency) || 'AUD'
vm.pricing_plans = [currency] || 'AUD' || 'default'

vm.appInstallationStatus = () ->
if vm.appInstance
if vm.app.multi_instantiable
"INSTALLABLE"
else
if vm.app.app_nid != 'office-365' && vm.app.stack == 'connector' && !vm.app.oauth_keys_valid
"INSTALLED_CONNECT"
else
"INSTALLED_LAUNCH"
else
if vm.conflictingApp
"CONFLICT"
else
"INSTALLABLE"

vm.provisionApp = () ->
vm.isLoadingButton = true
MnoeAppInstances.clearCache()

# Get the authorization status for the current organization
if MnoeOrganizations.role.atLeastPowerUser(vm.user_role)
purchasePromise = MnoeOrganizations.purchaseApp(vm.app, MnoeOrganizations.selectedId)
else # Open a modal to change the organization
purchasePromise = openChooseOrgaModal().result

purchasePromise.then(
->
$state.go('home.impac')

switch vm.app.stack
when 'cloud' then displayLaunchToastr(vm.app)
when 'cube' then displayLaunchToastr(vm.app)
when 'connector'
if vm.app.nid == 'office-365'
# Office 365 must display 'Launch'
displayLaunchToastr(vm.app)
else
displayConnectToastr(vm.app)
(error) ->
toastr.error(vm.app.name + " has not been added, please try again.")
MnoErrorsHandler.processServerError(error)
).finally(-> vm.isLoadingButton = false)

#====================================
# Calls
#====================================
Expand Down
20 changes: 19 additions & 1 deletion src/app/views/marketplace/marketplace-compare.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,25 @@ <h1>Comparison</h1>
</tr>
<tr class="text-center">
<th></th>
<td ng-repeat="app in vm.apps | filter:{is_compare: true } | limitTo:4"><button class="btn btn-warning btn-lg">Buy now!</button></td>
<td ng-repeat="app in vm.apps | filter:{is_compare: true } | limitTo:4">
<div ng-switch on="vm.appInstallationStatus()">
<div ng-switch-when="CONFLICT" class="message">
<i class="fa fa-exclamation-triangle"></i>
{{ 'mno_enterprise.templates.dashboard.marketplace.show.conflicting_app' | translate }}
<a ui-sref="home.marketplace.app({appId: vm.conflictingApp.id})">{{vm.conflictingApp.name}}</a>
</div>
<button ng-switch-when="INSTALLABLE" ng-click="vm.provisionApp()" ng-disabled="vm.isLoadingButton" class="btn btn-warning btn-lg">
<span ng-show="vm.isLoadingButton"><i class="fa fa-spinner fa-pulse"></i>&nbsp;</span>
{{ 'mno_enterprise.templates.dashboard.marketplace.show.start_app' | translate }}
</button>
<button ng-switch-when="INSTALLED_LAUNCH" ng-click="vm.launchAppInstance()" class="btn btn-warning btn-lg">
{{ 'mno_enterprise.templates.dashboard.marketplace.show.launch_app' | translate }}
</button>
<button ng-switch-when="INSTALLED_CONNECT" ng-click="vm.connectAppInstance()" class="btn btn-warning btn-lg">
{{ 'mno_enterprise.templates.dashboard.marketplace.show.connect_app' | translate }}
</button>
</div>
</td>
</tr>

</table>
Expand Down