From d09cc1611c00182bc9573e996c9cc5c6e52c595c Mon Sep 17 00:00:00 2001 From: Alexandre Jarnoux Date: Tue, 25 Oct 2016 11:38:03 +1100 Subject: [PATCH 1/5] Fix delete button still active when modal is deleting --- src/app/views/apps/modals/app-settings-modal.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/views/apps/modals/app-settings-modal.html b/src/app/views/apps/modals/app-settings-modal.html index 2807ae01..98b3074c 100755 --- a/src/app/views/apps/modals/app-settings-modal.html +++ b/src/app/views/apps/modals/app-settings-modal.html @@ -86,7 +86,7 @@

{{ 'mno_enterprise.templates.impac.dock.settings.confirm_app_deletion' | tra
-
From c6e04c6504330d2888396f41e74045ca2f0addda Mon Sep 17 00:00:00 2001 From: Alexandre Jarnoux Date: Tue, 25 Oct 2016 15:27:57 +1100 Subject: [PATCH 2/5] Fix app purchasing workflow --- .../mnoe-api/organizations.svc.coffee | 8 +-- .../marketplace-app.controller.coffee | 59 ++++++++++--------- .../views/marketplace/marketplace-app.html | 3 +- .../modals/choose-orga-modal.coffee | 55 +++++++++++------ .../marketplace/modals/choose-orga-modal.html | 27 ++++----- src/locales/en.locale.json | 2 +- 6 files changed, 83 insertions(+), 71 deletions(-) diff --git a/src/app/components/mnoe-api/organizations.svc.coffee b/src/app/components/mnoe-api/organizations.svc.coffee index 958b8843..7116f219 100644 --- a/src/app/components/mnoe-api/organizations.svc.coffee +++ b/src/app/components/mnoe-api/organizations.svc.coffee @@ -1,6 +1,6 @@ # Service for managing the users. angular.module 'mnoEnterpriseAngular' - .service 'MnoeOrganizations', ($state, $cookies, $log, $q, MnoeApiSvc, MnoeCurrentUser, toastr) -> + .service 'MnoeOrganizations', ($state, $cookies, $log, $q, MnoeApiSvc, MnoeCurrentUser) -> _self = @ organizationsApi = MnoeApiSvc.all('organizations') @@ -89,13 +89,9 @@ angular.module 'mnoEnterpriseAngular' @purchaseApp = (app, orgId = _self.selectedId) -> MnoeApiSvc.one('organizations', orgId).all('/app_instances').post({nid: app.nid}).then( (response) -> - toastr.success(app.name + " has been successfully added.") - # Change current organization if another one has been selected - organizationPromise = null _self.get(orgId) - (error) -> - toastr.error(app.name + " has not been added, please try again.") + response ) # Accept an array of invites diff --git a/src/app/views/marketplace/marketplace-app.controller.coffee b/src/app/views/marketplace/marketplace-app.controller.coffee index e4e9f34e..39571203 100644 --- a/src/app/views/marketplace/marketplace-app.controller.coffee +++ b/src/app/views/marketplace/marketplace-app.controller.coffee @@ -2,8 +2,8 @@ # #============================================ angular.module 'mnoEnterpriseAngular' - .controller('DashboardMarketplaceAppCtrl', - ($q, $scope, $stateParams, $state, $sce, $window, MnoeMarketplace, $uibModal, MnoeOrganizations, MnoeCurrentUser, MnoeAppInstances, PRICING_CONFIG) -> + .controller('DashboardMarketplaceAppCtrl',($q, $scope, $stateParams, $state, $sce, $window, toastr, + MnoeMarketplace, $uibModal, MnoeOrganizations, MnoeCurrentUser, MnoeAppInstances, PRICING_CONFIG) -> vm = this @@ -17,6 +17,9 @@ angular.module 'mnoEnterpriseAngular' # An already installed app, conflicting with the app because it contains a common subcategory # that is not multi instantiable, if any vm.conflictingApp = null + # Enabling pricing + vm.isPriceShown = PRICING_CONFIG && PRICING_CONFIG.enabled + #==================================== # Scope Management #==================================== @@ -25,19 +28,15 @@ angular.module 'mnoEnterpriseAngular' vm.appInstance = appInstance vm.conflictingApp = conflictingApp vm.app.description = $sce.trustAsHtml(app.description) - vm.isLoading = false + plans = vm.app.pricing_plans currency = (PRICING_CONFIG && PRICING_CONFIG.currency) || 'AUD' vm.pricing_plans = plans[currency] || plans.AUD || plans.default # Get the user role in this organization - MnoeCurrentUser.get().then( - (response) -> - vm.user_role = _.find(response.organizations, {id: parseInt(MnoeOrganizations.selectedId)}).current_user_role - ) + MnoeOrganizations.get().then((response) -> vm.user_role = response.current_user.role) - vm.addApplication = -> - MnoeOrganizations.purchaseApp(vm.app, MnoeOrganizations.selectedId).then(-> $state.go('home.impac')) + vm.isLoading = false # Check that the testimonial is not empty vm.isTestimonialShown = (testimonial) -> @@ -62,18 +61,37 @@ angular.module 'mnoEnterpriseAngular' else "INSTALLABLE" - vm.provisionLink = () -> + vm.provisionApp = () -> + vm.isLoadingButton = true MnoeAppInstances.clearCache() # Get the authorization status for the current organization if MnoeOrganizations.role.atLeastPowerUser(vm.user_role) - vm.addApplication() + purchasePromise = MnoeOrganizations.purchaseApp(vm.app, MnoeOrganizations.selectedId) else # Open a modal to change the organization - vm.openChooseOrgaModal() + purchasePromise = openChooseOrgaModal().result + + purchasePromise.then( + -> + $state.go('home.impac') + toastr.success(vm.app.name + " has been successfully added.") + (error) -> + toastr.error(vm.app.name + " has not been added, please try again.") + MnoErrorsHandler.processServerError(error) + ).finally(-> vm.isLoadingButton = false) vm.launchAppInstance = -> $window.open("/mnoe/launch/#{vm.appInstance.uid}", '_blank') + openChooseOrgaModal = -> + $uibModal.open( + backdrop: 'static' + templateUrl: 'app/views/marketplace/modals/choose-orga-modal.html' + controller: 'MarketplaceChooseOrgaModalCtrl' + resolve: + app: vm.app + ) + #==================================== # App Connect modal #==================================== @@ -93,24 +111,9 @@ angular.module 'mnoEnterpriseAngular' templateUrl: modalInfo.template controller: modalInfo.controller resolve: - app: -> - vm.appInstance - ) - - #==================================== - # Choose App Modal - #==================================== - vm.openChooseOrgaModal = -> - $uibModal.open( - backdrop: 'static' - windowClass: 'inverse' - size: 'lg' - templateUrl: 'app/views/marketplace/modals/choose-orga-modal.html' - controller: 'MarketplaceChooseOrgaModalCtrl' + app: vm.appInstance ) - vm.isPriceShown = PRICING_CONFIG && PRICING_CONFIG.enabled - #==================================== # Cart Management #==================================== diff --git a/src/app/views/marketplace/marketplace-app.html b/src/app/views/marketplace/marketplace-app.html index d32994bc..7a7647f2 100644 --- a/src/app/views/marketplace/marketplace-app.html +++ b/src/app/views/marketplace/marketplace-app.html @@ -43,7 +43,8 @@

{{vm.app.name}}

{{ 'mno_enterprise.templates.dashboard.marketplace.show.conflicting_app' | translate }} {{vm.conflictingApp.name}} - + +   {{ 'mno_enterprise.templates.dashboard.marketplace.show.start_app' | translate }} diff --git a/src/app/views/marketplace/modals/choose-orga-modal.coffee b/src/app/views/marketplace/modals/choose-orga-modal.coffee index 4edbcfdb..928833ec 100644 --- a/src/app/views/marketplace/modals/choose-orga-modal.coffee +++ b/src/app/views/marketplace/modals/choose-orga-modal.coffee @@ -1,5 +1,9 @@ angular.module 'mnoEnterpriseAngular' -.controller('MarketplaceChooseOrgaModalCtrl', ($scope, $uibModalInstance, MnoeOrganizations, MnoeCurrentUser) -> +.controller('MarketplaceChooseOrgaModalCtrl', ($scope, $uibModalInstance, MnoeOrganizations, MnoeCurrentUser, app) -> + + #==================================== + # Pre-Initialization + #==================================== # Initialize the main variables $scope.organizations = {} @@ -7,27 +11,16 @@ angular.module 'mnoEnterpriseAngular' $scope.authorized_organizations = {} # The organizations where the user can add apps $scope.hasAuthorizedOrganizations = false $scope.isLoading = true + $scope.app = app # Get the current organization id $scope.current_organization = { id: MnoeOrganizations.selectedId } - # Get the list of all the user organizations - MnoeCurrentUser.get().then( - (response) -> # Hash of organizations id -> {organization obj} - $scope.filterAuthorizedOrga(response.organizations) - $scope.hasAuthorizedOrganizations = !_.isEmpty($scope.authorized_organizations) - $scope.isLoading = false - ) - - # Filter the authorized organizations for this user - $scope.filterAuthorizedOrga = (organizations) -> - organizations.map( - (org) -> - $scope.organizations[org.id] = org - $scope.authorized_organizations[org.id] = org if MnoeOrganizations.role.atLeastPowerUser(org.current_user_role) - ) + #==================================== + # Scope Management + #==================================== # Check if the user is allowed to add apps to the given organization $scope.isUserAuthorized = (orgId) -> @@ -40,11 +33,37 @@ angular.module 'mnoEnterpriseAngular' # Add a new app instance to the current user organization $scope.addApplication = -> - MnoeOrganizations.purchaseApp($scope.app, $scope.current_organization.id).then(-> $state.go('home.impac')) + MnoeOrganizations.purchaseApp($scope.app, $scope.current_organization.id).then( + (response) -> + $uibModalInstance.close(response) + ) # Close the current modal $scope.closeChooseOrgaModal = -> - $uibModalInstance.close() + $uibModalInstance.dismiss() + + #==================================== + # Private methods + #==================================== + + # Filter the authorized organizations for this user + filterAuthorizedOrga = (organizations) -> + _.forEach(organizations, (org) -> + $scope.organizations[org.id] = org + $scope.authorized_organizations[org.id] = org if MnoeOrganizations.role.atLeastPowerUser(org.current_user_role) + ) + + #==================================== + # Post-Initialization + #==================================== + + # Get the list of all the user organizations + MnoeCurrentUser.get().then( + (response) -> # Hash of organizations id -> {organization obj} + filterAuthorizedOrga(response.organizations) + $scope.hasAuthorizedOrganizations = !_.isEmpty($scope.authorized_organizations) + $scope.isLoading = false + ) return ) diff --git a/src/app/views/marketplace/modals/choose-orga-modal.html b/src/app/views/marketplace/modals/choose-orga-modal.html index f0467ef9..97150913 100644 --- a/src/app/views/marketplace/modals/choose-orga-modal.html +++ b/src/app/views/marketplace/modals/choose-orga-modal.html @@ -2,49 +2,42 @@ + + @@ -49,7 +49,7 @@ -
+
diff --git a/src/app/views/apps/modals/app-deletion-modal.html b/src/app/views/apps/modals/app-deletion-modal.html index f754409d..0592473a 100644 --- a/src/app/views/apps/modals/app-deletion-modal.html +++ b/src/app/views/apps/modals/app-deletion-modal.html @@ -22,7 +22,7 @@
diff --git a/src/app/views/apps/modals/app-settings-modal.html b/src/app/views/apps/modals/app-settings-modal.html index 98b3074c..87ed030c 100755 --- a/src/app/views/apps/modals/app-settings-modal.html +++ b/src/app/views/apps/modals/app-settings-modal.html @@ -87,7 +87,7 @@

{{ 'mno_enterprise.templates.impac.dock.settings.confirm_app_deletion' | tra
diff --git a/src/app/views/company/settings/organization-settings.html b/src/app/views/company/settings/organization-settings.html index 69ae80d8..5e85a297 100644 --- a/src/app/views/company/settings/organization-settings.html +++ b/src/app/views/company/settings/organization-settings.html @@ -33,7 +33,7 @@ diff --git a/src/app/views/marketplace/marketplace-app.html b/src/app/views/marketplace/marketplace-app.html index 7a7647f2..e4eabf3a 100644 --- a/src/app/views/marketplace/marketplace-app.html +++ b/src/app/views/marketplace/marketplace-app.html @@ -44,7 +44,7 @@

{{vm.app.name}}

{{vm.conflictingApp.name}} -   +   {{ 'mno_enterprise.templates.dashboard.marketplace.show.start_app' | translate }} diff --git a/src/app/views/marketplace/modals/choose-orga-modal.coffee b/src/app/views/marketplace/modals/choose-orga-modal.coffee index 928833ec..09c03b8e 100644 --- a/src/app/views/marketplace/modals/choose-orga-modal.coffee +++ b/src/app/views/marketplace/modals/choose-orga-modal.coffee @@ -33,10 +33,11 @@ angular.module 'mnoEnterpriseAngular' # Add a new app instance to the current user organization $scope.addApplication = -> + $scope.isLoading = true MnoeOrganizations.purchaseApp($scope.app, $scope.current_organization.id).then( (response) -> $uibModalInstance.close(response) - ) + ).finally(-> $scope.isLoading = false) # Close the current modal $scope.closeChooseOrgaModal = -> diff --git a/src/app/views/marketplace/modals/choose-orga-modal.html b/src/app/views/marketplace/modals/choose-orga-modal.html index 97150913..ba5bb470 100644 --- a/src/app/views/marketplace/modals/choose-orga-modal.html +++ b/src/app/views/marketplace/modals/choose-orga-modal.html @@ -42,7 +42,8 @@

{{'mno_enterprise.templates.dashboard.ma