Commit 10daeabb authored by Michal-MK's avatar Michal-MK
Browse files

Initial Commit for Solution

parent 4539d4c4
......@@ -14,6 +14,11 @@ pa165eshopApp.config(['$routeProvider',
when('/category/:categoryId', {templateUrl: 'partials/category_detail.html', controller: 'CategoryDetailCtrl'}).
when('/admin/products', {templateUrl: 'partials/admin_products.html', controller: 'AdminProductsCtrl'}).
when('/admin/newproduct', {templateUrl: 'partials/admin_new_product.html', controller: 'AdminNewProductCtrl'}).
when('/admin/categories', {templateUrl: 'partials/admin_categories.html', controller: 'AdminCategoriesCtrl'}).
when('/admin/newcategory', {
templateUrl: 'partials/admin_new_category.html',
controller: 'AdminNewCategoryCtrl'
otherwise({redirectTo: '/shopping'});
......@@ -210,3 +215,53 @@ eshopControllers.directive('convertToInt', function () {
* Admin categories
function ($scope, $rootScope, $routeParams, $http) {
//initial load of all categories
$http.get('/eshop/api/v1/categories').then(function (response) {
$scope.categories =['_embedded']['categoryDTOList'];
* Page with form for creating new category
eshopControllers.controller('AdminNewCategoryCtrl', function ($scope, $routeParams, $http, $location, $rootScope) {
// Set object bound to form fields
$scope.category = {
'name': ''
// Function called when submit button is clicked, creates category on server
$scope.create = function (category) {
method: 'POST',
url: '/eshop/api/v1/categories/create',
data: category
}).then(function success(response) {
const createdCategory =;
// Display confirmation alert
$rootScope.successAlert = 'A new category "' + + '" was created';
// Change view to list of categories
}, function error(response) {
// Display error
console.log("error when creating category");
switch ( {
case 'PersistenceException':
$rootScope.errorAlert = 'Category with the same name already exists ! ';
case 'InvalidRequestException':
$rootScope.errorAlert = 'Sent data were found to be invalid by server ! ';
$rootScope.errorAlert = 'Cannot create category ! Reason given by the server: ' +;
<h1>Administration of categories</h1>
<!-- button for adding a new category -->
<a href="#!/admin/newcategory" class="btn btn-primary">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
New category
<table class="table">
<th>category name</th>
<tr ng-repeat="category in categories track by $index">
<form name="form" novalidate class="form-horizontal">
<div class="form-group" ng-class="{'has-error': !($valid)}">
<label for="name" class="col-sm-2 control-label">Name</label>
<div class="col-sm-10">
<input placeholder="name" id="name" type="text" ng-minlength="3" name="name" class="form-control"
ng-model="" required/>
<p class="help-block" ng-show="$error.required">name is required</p>
<p class="help-block" ng-show="$error.minlength">name must be at least 3 characters</p>
<!-- show disabled button if form is not valid -->
<button ng-disabled="!form.$valid" ng-click="create(category)" class="btn btn-primary" type="submit" >Create category</button>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment