Skip to content

Commit

Permalink
Add support for updating offerings categories in the GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
fdelavega committed Apr 29, 2020
1 parent 7a6694e commit c080cb8
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 59 deletions.
5 changes: 0 additions & 5 deletions docker/Dockerfile
Expand Up @@ -23,11 +23,6 @@ RUN wget https://nodejs.org/dist/v8.12.0/node-v8.12.0-linux-x64.tar.xz && \
cp config.js etc/config.js && \
echo "module.exports = require('./etc/config');" > config.js

VOLUME /business-ecosystem-logic-proxy/indexes
VOLUME /business-ecosystem-logic-proxy/themes
VOLUME /business-ecosystem-logic-proxy/static
VOLUME /business-ecosystem-logic-proxy/locales

COPY ./entrypoint.sh /
COPY ./cleanIndex.sh /
COPY ./getConfig.js /business-ecosystem-logic-proxy
Expand Down
120 changes: 83 additions & 37 deletions public/resources/core/js/controllers/product-offering.controller.js
Expand Up @@ -251,6 +251,43 @@
}, offeringSearch);
}

function categoryHandler(vm) {
vm.setCategory = setCategory;
vm.categoryIsDisabled = categoryIsDisabled;
vm.removeChildCategory = removeChildCategory;
vm.isIncluded = isIncluded;

function setCategory(category) {
if (category.id in vm.categories) {
delete vm.categories[category.id];
} else {
removeChildCategory(category);
vm.categories[category.id] = category;
}
}

function categoryIsDisabled(category) {
return Object.keys(vm.categories).some(function(id) {
return isIncluded(vm.categories[id], category);
});
}

function removeChildCategory(parentCategory) {
return parentCategory.getBreadcrumb().some(function(category) {
if (category.id in vm.categories) {
delete vm.categories[category.id];
return true;
}
});
}

function isIncluded(parentCategory, targetCategory) {
return parentCategory.getBreadcrumb().some(function(category) {
return targetCategory.id === category.id;
});
}
}

function ProductOfferingCreateController(
$q,
$scope,
Expand Down Expand Up @@ -358,8 +395,10 @@
vm.toggleOffering = toggleOffering;

vm.categories = {};
vm.setCategory = setCategory;
vm.categoryIsDisabled = categoryIsDisabled;

// Load category management methods
categoryHandler(vm);

vm.hasCategories = hasCategories;

/* PRICE PLANS MEMBERS */
Expand Down Expand Up @@ -778,40 +817,10 @@
return sharingModel;
}

function setCategory(category) {
if (category.id in vm.categories) {
delete vm.categories[category.id];
} else {
removeChildCategory(category);
vm.categories[category.id] = category;
}
}

function hasCategories() {
return Object.keys(vm.categories).length !== 0;
}

function categoryIsDisabled(category) {
return Object.keys(vm.categories).some(function(id) {
return isIncluded(vm.categories[id], category);
});
}

function removeChildCategory(parentCategory) {
return parentCategory.getBreadcrumb().some(function(category) {
if (category.id in vm.categories) {
delete vm.categories[category.id];
return true;
}
});
}

function isIncluded(parentCategory, targetCategory) {
return parentCategory.getBreadcrumb().some(function(category) {
return targetCategory.id === category.id;
});
}

function formatCategory() {
var name,
category = [];
Expand Down Expand Up @@ -973,7 +982,13 @@

vm.update = update;
vm.updateStatus = updateStatus;
vm.hasCategory = hasCategory;

vm.categories = {};

// Load category management methods
categoryHandler(vm);

vm.updateCategories = updateCategories;

vm.pricePlan = new Offering.PricePlan();
vm.pricePlanEnabled = false;
Expand Down Expand Up @@ -1013,7 +1028,11 @@
function(productOffering) {
vm.item = productOffering;
vm.data = angular.copy(productOffering);
vm.categories = productOffering.getCategories();

vm.categories = {};
vm.data.category.forEach((category) => {
vm.categories[category.id] = category;
});
vm.isOpen = isOpenOffering();
},
function(response) {
Expand Down Expand Up @@ -1145,9 +1164,36 @@
vm.statusUpdated = true;
}

function hasCategory(category) {
return vm.categories.some(function(c) {
return c.id === category.id;
function updateCategories() {
let name, category = [];
let updatedData = {
category: []
}

// Add parent categories to update list
for (name in vm.categories) {
category = category.concat(vm.categories[name].getBreadcrumb(), vm.categories[name]);
}

category.forEach((cat) => {
updatedData.category.push({
id: cat.id,
href: cat.href
})
});

vm.catStatus = vm.STATUS.PENDING;
Offering.update(vm.item, updatedData).then((offering) => {
vm.catStatus = vm.STATUS.LOADED;
$rootScope.$broadcast(EVENTS.MESSAGE_ADDED, 'updated', {
resource: 'offering',
name: offering.name
});
}, (response) => {
vm.catStatus = vm.STATUS.LOADED;
$rootScope.$broadcast(EVENTS.MESSAGE_ADDED, 'error', {
error: Utils.parseError(response, 'Unexpected error trying to update the offering.')
});
});
}

Expand Down
44 changes: 27 additions & 17 deletions views/partials/stock/product-offering/update-category.jade
@@ -1,17 +1,27 @@
.row(ng-controller="CategorySearchCtrl as categorySearchVM")
.col-xs-12(ng-if="!categorySearchVM.list.length")
.alert.alert-info #{ __("No categories found.") }
.col-xs-12(ng-if="categorySearchVM.list.length")
.table-responsive
table.table.table-bordered
thead
tr
th #{ __("Name") }
th #{ __("Last Updated") }
tbody
tr(ng-repeat="category in categorySearchVM.list | orderByParentId", ng-class="{ active: updateVM.hasCategory(category) }")
td
span(ng-repeat="parentCategory in category.getBreadcrumb()") {{ parentCategory.name }} /
strong {{ category.name }}
td
time(am-time-ago="category.lastUpdate")
.panel.panel-default.z-depth-1
.panel-body
.row(ng-controller="CategorySearchCtrl as categorySearchVM")
.col-xs-12(ng-if="!categorySearchVM.list.length")
.alert.alert-info #{ __("No categories found.") }
.col-xs-12(ng-if="categorySearchVM.list.length")
.table-responsive(ng-init="updateVM.initCategories(categorySearchVM.list)")
table.table.table-bordered.table-hover.table-selectable
thead
tr
th #{ __("Name") }
th #{ __("Last Updated") }
tbody
tr(ng-repeat="category in categorySearchVM.list | orderByParentId", ng-class="{ active: updateVM.categories[category.id] != null, disabled: updateVM.categoryIsDisabled(category) }", ng-click="updateVM.setCategory(category)")
td
span(ng-repeat="parentCategory in category.getBreadcrumb()") {{ parentCategory.name }} /
strong {{ category.name }}
td
time(am-time-ago="category.lastUpdate")

.form-group.text-right
a.btn.btn-success(
ng-click="updateVM.updateCategories()"
ng-disabled="updateVM.catStatus === updateVM.STATUS.PENDING"
)
span.item-icon.fa.fa-spin.fa-spinner(ng-if="updateVM.catStatus === updateVM.STATUS.PENDING")
span.item-text #{ __("Update") }

0 comments on commit c080cb8

Please sign in to comment.