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

[MNOE-1034] WIP Migrate marketplace to products #461

Open
wants to merge 9 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

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
angular.module 'mnoEnterpriseAngular'
.component('mnoAppListing', {
templateUrl: 'app/components/mno-apps/mno-app-listing.html',
.component('mnoProductListing', {
templateUrl: 'app/components/mno-products/mno-product-listing.html',
bindings: {
isPublic: '@'
isPublic: '@',
isLocal: '<'
}
controller: ($scope, toastr, MnoeOrganizations, MnoeMarketplace, MnoeConfig) ->
vm = this
Expand All @@ -17,16 +18,19 @@ angular.module 'mnoEnterpriseAngular'
vm.searchTerm = ''
vm.isMarketplaceCompare = MnoeConfig.isMarketplaceComparisonEnabled()
vm.showCompare = false
vm.nbAppsToCompare = 0
vm.appState = if vm.publicPage then "public.product" else "home.marketplace.app"
vm.nbProductsToCompare = 0
vm.productState = if vm.publicPage then "public.product" else "home.marketplace.product"
vm.displayAll = {label: "", active: 'active'}
vm.selectedPublicCategory = vm.displayAll
vm.productRef = (product) ->
vm.productState + "({productId: '#{product.id}'})"

vm.initialize()
#====================================
# Scope Management
#====================================

vm.appsFilter = (app) ->
vm.productsFilter = (app) ->
vm.currentSelectedCategory = if vm.publicPage then vm.selectedPublicCategory.label else vm.selectedCategory
if (vm.searchTerm? && vm.searchTerm.length > 0) || !vm.currentSelectedCategory
return true
Expand All @@ -43,40 +47,43 @@ angular.module 'mnoEnterpriseAngular'
vm.showCompare = false

# Uncheck all checkboxes
vm.uncheckAllApps = () ->
angular.forEach(vm.apps, (items) ->
items.toCompare = false
uncheckAllProducts = () ->
angular.forEach(vm.products, (product) ->
product.toCompare = false
)

# Toggle compare block
vm.enableComparison = ->
vm.nbAppsToCompare = 0
vm.uncheckAllApps()
vm.nbProductsToCompare = 0
uncheckAllProducts()
vm.showCompare = true

vm.toggleAppToCompare = (app) ->
selected = app.toCompare
if selected && vm.nbAppsToCompare >= 4
vm.toggleProductToCompare = (product) ->
selected = product.toCompare
if selected && vm.nbProductsToCompare >= 4
toastr.info("mno_enterprise.templates.dashboard.marketplace.index.toastr.error")
app.toCompare = false
product.toCompare = false
else
vm.nbAppsToCompare += if selected then 1 else (-1)
vm.nbProductsToCompare += if selected then 1 else (-1)

vm.canBeCompared = ->
return vm.nbAppsToCompare <= 4 && vm.nbAppsToCompare >=2
return vm.nbProductsToCompare <= 4 && vm.nbProductsToCompare >=2

vm.initialize = ->
vm.isLoading = true
MnoeMarketplace.getApps().then(
MnoeMarketplace.getMarketplace().then(
(response) ->
# Remove restangular decoration
response = response.plain()

vm.categories = response.categories
vm.publicCategories = _.map(response.categories, (c) -> {label: c, active: ''})
vm.apps = response.apps
vm.products = if vm.isLocal
_.filter(response.products, (product) -> product.local)
else
_.filter(response.products, (product) -> !product.local)

if vm.publicPage
vm.apps = _.filter(vm.apps, (app) -> _.includes(MnoeConfig.publicApplications(), app.nid))
vm.products = _.filter(vm.products, (product) -> _.includes(MnoeConfig.publicProducts(), product.nid))
).finally(-> vm.isLoading = false)

$scope.$watch MnoeOrganizations.getSelectedId, (val) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<!-- Marketplace nav -->
<div class="row">
<div class="marketplace-nav" ng-hide="$ctrl.publicPage">
<div class="col-sm-4">
<div ng-hide="$ctrl.isLocal" class="col-sm-4">
<select class="form-control" ng-model="$ctrl.selectedCategory" ng-options="c for c in $ctrl.categories" ng-change="$ctrl.searchTerm = ''">
<option value=''>{{ 'mno_enterprise.templates.dashboard.marketplace.index.select_all' | translate }}</option>
</select>
Expand All @@ -22,9 +22,9 @@
<span>{{ 'mno_enterprise.templates.dashboard.marketplace.index.compare' | translate }}</span>
</button>
<div ng-show="$ctrl.showCompare" class="marketplace-compare-action">
<div>{{'mno_enterprise.templates.dashboard.marketplace.index.select_apps' | translate }}</div>
<div>{{'mno_enterprise.templates.dashboard.marketplace.index.select_products' | translate }}</div>
<button class="btn btn-primary" ui-sref="home.marketplace.compare" ng-disabled="!$ctrl.canBeCompared()">
{{'mno_enterprise.templates.dashboard.marketplace.index.compare_apps' | translate}} ({{$ctrl.nbAppsToCompare}})
{{'mno_enterprise.templates.dashboard.marketplace.index.compare_products' | translate}} ({{$ctrl.nbProductsToCompare}})
</button>
<button class="btn btn-primary" ng-click="$ctrl.cancelComparison()">{{ 'mno_enterprise.templates.dashboard.marketplace.index.cancel' | translate }}</button>
</div>
Expand Down Expand Up @@ -53,23 +53,23 @@
<div class="row" ng-hide="$ctrl.publicPage">
<div class="marketplace-list">

<!-- App Cards-->
<div class="col-sm-6 col-md-4" ng-repeat="app in $ctrl.apps | filter:$ctrl.appsFilter | filter:$ctrl.searchTerm">
<div class="marketplace-app-card-checkbox" ng-show="$ctrl.showCompare">
<!-- Product Cards-->
<div class="col-sm-6 col-md-4" ng-repeat="product in $ctrl.products | filter:$ctrl.productsFilter | filter:$ctrl.searchTerm">
<div class="marketplace-product-card-checkbox" ng-show="$ctrl.showCompare">
<label>
<input type="checkbox"
ng-click="$ctrl.toggleAppToCompare(app)"
ng-model="app.toCompare">
ng-click="$ctrl.toggleProductToCompare(product)"
ng-model="product.toCompare">
</label>
</div>
<a class="marketplace-app-card" ui-sref="{{$ctrl.appState}}({appId: app.nid})">
<a class="marketplace-product-card" ui-sref="{{$ctrl.productRef(product)}}">
<div class="media">
<div class="pull-left">
<img class="media-object" ng-src="{{::app.logo}}" ng-alt="{{::app.name}}">
<img class="media-object" ng-src="{{::product.logo}}" ng-alt="{{::product.name}}">
</div>
<div class="media-body">
<h4 class="media-heading">{{::app.name}}</h4>
{{::app.tiny_description}}
<h4 class="media-heading">{{::product.name}}</h4>
{{::product.values_attributes.tiny_description}}
</div>
<div class="arrow">
<i class="fa fa-caret-right fa-2x"></i>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
angular.module 'mnoEnterpriseAngular'
.controller('mnoApp',($q, $scope, $stateParams, $state, $sce, $window, $uibModal, $anchorScroll,
$location, isPublic, parentState, toastr, MnoeMarketplace, MnoeOrganizations, MnoeCurrentUser, MnoeAppInstances, MnoConfirm, MnoeConfig, ProvisioningHelper) ->
.controller('mnoProduct',($q, $scope, $stateParams, $state, $sce, $window, $uibModal, $anchorScroll,
$location, isPublic, parentState, toastr, MnoeMarketplace, MnoeOrganizations, MnoeCurrentUser, MnoConfirm, MnoeConfig, ProvisioningHelper) ->

vm = this
#====================================
Expand All @@ -13,7 +13,7 @@ angular.module 'mnoEnterpriseAngular'
vm.app = {}
vm.searchWord = ""
# The already installed app instance of the app, if any
vm.appInstance = null
vm.productInstalled = 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
Expand All @@ -37,44 +37,61 @@ angular.module 'mnoEnterpriseAngular'

vm.pricedPlan = ProvisioningHelper.pricedPlan

getPricingPlans = (app) ->
if vm.isPriceShown
plans = vm.app.pricing_plans
currency = MnoeConfig.marketplaceCurrency()
vm.pricing_plans = plans[currency] || plans.AUD || plans.default

# Public initialization - app only, without considering reviews/org
MnoeMarketplace.getApps().then(
(response) ->
apps = response.apps
# MnoeMarketplace.getApps().then(
# (response) ->
# apps = response.apps
#
# # App to be displayed
# appId = $stateParams.appId
# vm.app = _.findWhere(apps, { nid: appId })
# vm.app ||= _.findWhere(apps, { id: appId })
#
# $state.go(parentState) unless vm.app?
# vm.isLoading = false
# )

# App to be displayed
appId = $stateParams.appId
vm.app = _.findWhere(apps, { nid: appId })
vm.app ||= _.findWhere(apps, { id: appId })
#====================================
# Pricings
#====================================
# Return true if the plan has a dollar value
vm.pricedPlan = ProvisioningHelper.pricedPlan

# Init Pricing Plans
getPricingPlans(vm.app)
vm.pricingPlans = () ->
_.map(vm.product.pricing_plans, (pricingPlan) ->
return pricingPlan unless vm.pricedPlan(pricingPlan)
# If its a pricedPlan, only show prices of appropriate currency.
pricingPlan.prices = _.filter(pricingPlan.prices, (price) ->
price.currency == vm.currency
)

$state.go(parentState) unless vm.app?
vm.isLoading = false
pricingPlan
)

vm.showNoPricingFound = (plan) ->
_.isEmpty(plan.prices) && vm.pricedPlan(plan)

#====================================
# Scope Management
#====================================
vm.initialize = (app, appInstance, product) ->

vm.initialize = (product) ->
# Variables initialization
vm.userId = MnoeCurrentUser.user.id
vm.adminRole = MnoeCurrentUser.user.admin_role

# Init current app and app instance
vm.app = app
vm.appInstance = appInstance
vm.product = product
vm.productInstalled = !_.isEmpty(product.productInstances)

# Is the product externally provisioned
vm.isExternallyProvisioned = (vm.isProvisioningEnabled && product?.externally_provisioned)

# Init pricing plans
vm.currency = MnoeConfig.marketplaceCurrency()
vm.pricing_plans = vm.pricingPlans()

# Get the user role in this organization
MnoeOrganizations.get().then((response) -> vm.user_role = response.current_user.role)

# Init initials reviews if enabled
Expand Down Expand Up @@ -443,30 +460,10 @@ angular.module 'mnoEnterpriseAngular'
if val?
vm.isLoading = true

productPromise = if MnoeConfig.isProvisioningEnabled() then MnoeMarketplace.getProducts() else $q.resolve()

# Retrieve the apps and if any the current app instance
$q.all(
marketplace: MnoeMarketplace.getApps(),
appInstances: MnoeAppInstances.getAppInstances(),
products: productPromise
).then(
# Retrieve the product and if any the current product instance
MnoeMarketplace.getProduct($stateParams.productId).then(
(response) ->
apps = response.marketplace.apps
appInstances = response.appInstances
products = response.products?.products

# App to be displayed
appId = $stateParams.appId
app = _.findWhere(apps, { nid: appId })
app ||= _.findWhere(apps, { id: appId })

$state.go(parentState) unless app?

# Find if we already have it
appInstance = _.find(appInstances, { app_nid: app.nid })
product = _.find(products, { nid: app.nid })
vm.initialize(app, appInstance, product)
vm.initialize(response)
)

return
Expand Down
Loading