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

Add adApp to the list of projects #3

Merged
merged 1 commit into from
Oct 3, 2017
Merged
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
2 changes: 2 additions & 0 deletions 11- Advertisement management app using Node/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
public/config.json
4 changes: 4 additions & 0 deletions 11- Advertisement management app using Node/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## AdApp is simple CRUD Application made to learn NodeJS ,ExpressJS ,Mongo stack


Next milestone : Adding VueJs to the front-end
21 changes: 21 additions & 0 deletions 11- Advertisement management app using Node/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 Malik

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
20 changes: 20 additions & 0 deletions 11- Advertisement management app using Node/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# adApp
Advertisement management app using node , expressJS , mongo , angular , bootsrap

How to Run App
--------------
1. clone the repository
2. open a cmd line and cd inside adApp directory
3. in the cmd line execute "npm install"
4. copy config.json file inside adApp/public directory
5. execute "node server.js" to run the app
6. open the app in your browser https://localhost:3000


Technology stack used for the app
---------------------------------

1. AngularJS
2. NodeJS
3. ExpressJS
4. Mongo
28 changes: 28 additions & 0 deletions 11- Advertisement management app using Node/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "adapp",
"version": "1.0.0",
"description": "an app using nodejs , angular",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "nodemon server.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/mal90/adApp.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/mal90/adApp/issues"
},
"homepage": "https://github.com/mal90/adApp#readme",
"dependencies": {
"body-parser": "^1.17.1",
"express": "^4.15.2",
"mongodb": "^2.2.25"
},
"devDependencies": {
"nodemon": "^1.11.0"
}
}
96 changes: 96 additions & 0 deletions 11- Advertisement management app using Node/public/checkout.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>adApp</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-notification/0.3.6/angular-ui-notification.min.css">
<style>
.topmargin{
margin-top: 50px;
}

.field-inline{
padding-left: 0px;
}

.list-table{
max-height: 250px;
overflow-y: scroll;
}
</style>
</head>
<body ng-app="adApp" ng-controller="checkoutCtrl">
<div class="container topmargin">
<div class="col-md-12">
<div class="panel panel-info">
<div class="panel-heading">Checkout summery
<a href="" class="pull-right" ng-click="goToDashboard()">Go To Dashboard</a>
</div>
<div class="panel-body">
<div class="col-md-4">
<form>
<div class="col-md-12 field-inline">
<div class="form-group">
<label for="customer">Customer:</label>
<select class="form-control" ng-change='changeCustomer()' ng-model="customerName" ng-options="customer for customer in customers"></select>
</div>
</div>
<div class="col-md-10 field-inline">
<div class="form-group">
<label for="ad">Type of Ad:</label>
<select class="form-control" ng-model="selectedProduct" ng-options="product.name for product in products"></select>
</div>
</div>
<div class="col-md-2 field-inline">
<div class="form-group">
<label for="ad">Count:</label>
<input type="text" ng-model="numberOfItems" class="form-control" id="ad" name="ad">
</div>
</div>
<button ng-click="addItem()" class="btn btn-default">Add</button>
</form>
</div>
<div class="col-md-8">
<div class="list-table">
<table class="table">
<thead>
<tr>
<th>Ad Type</th>
<th>Unit Price</th>
<th>No.of Items</th>
<th>Total Price</th>
<th>Discount applied</th>
<th></th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in totalAddedItems">
<td>{{ item.name }}</td>
<td>${{ item.price }}</td>
<td>{{ item.numberOfItems }}</td>
<td>${{ item.totalPrice }}</td>
<td ng-if="item.discountApplied"><span class="label label-success">Yes</span></td>
<td ng-if="!item.discountApplied"><span class="label label-default">No</span></td>
<td><a href="#" class="btn btn-xs btn-danger" ng-click="removeItem(item)">Delete</a></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="panel-footer panel-primary">
<strong>Total : ${{totalCheckoutValue}}</strong>
</div><!--.panel-footer-->
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-notification/0.3.6/angular-ui-notification.min.js"></script>
<script src="js/app.js"></script>
<script src="js/controllers/checkout.controller.js"></script>
<script src="js/services/products.service.js"></script>
</body>
</html>
Binary file not shown.
44 changes: 44 additions & 0 deletions 11- Advertisement management app using Node/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<title>adApp</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-notification/0.3.6/angular-ui-notification.min.css">
<style>
.topmargin {
margin-top: 50px;
}
</style>
</head>

<body ng-app="adApp" ng-controller="dashboardCtrl">
<div class="container topmargin">
<div class="col-md-12">
<div class="panel panel-info">
<div class="panel-heading">Dashboard</div>
<div class="panel-body">
<div class="col-md-4">
</div>
<div class="col-md-4">
<div class="btn-group">
<button type="button" ng-click="goToAdProduct()" class="btn btn-primary">Manage Products</button>
<button type="button" ng-click="goToAdCheckout()" class="btn btn-success">Checkout</button>
</div>
</div>
<div class="col-md-4">
</div>
</div>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-notification/0.3.6/angular-ui-notification.min.js"></script>
<script src="js/app.js"></script>
<script src="js/controllers/dashboard.controller.js"></script>
</body>

</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var app = angular.module("adApp", ['ui-notification']);
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
(function () {
'use strict';

angular.module('adApp').controller('checkoutCtrl', checkoutCtrl);

checkoutCtrl.$inject = ['$scope', 'productsService','Notification'];

function checkoutCtrl($scope, productsService,Notification) {
$scope.customers = ['Default', 'UNILEVER', 'APPLE', 'NIKE', 'FORD'];
$scope.adTypes = [];
$scope.addItem = addItem;
$scope.changeCustomer = changeCustomer;
$scope.removeItem = removeItem;
$scope.totalAddedItems = [];
$scope.goToDashboard = goToDashboard;
$scope.totalCheckoutValue = 0;
var customerSelected;

getAllProducts();//initialize products

function getAllProducts() {
productsService.getAllProducts()
.success(function (data) {
$scope.products = data;
getAllAdTypes(data);
}).error(function (data) {
console.error("error pccured");
});
}

function getAllAdTypes(products) {
products.forEach(function (product) {
$scope.adTypes.push(product.name);
});
}

function changeCustomer() {
/** If the user change the 'selected' customer */
if (customerSelected != undefined && customerSelected != $scope.customerName) {
var confirmChange = confirm("You will lose your current customer info ! Click OK to proceed");
if (confirmChange) {
$scope.totalAddedItems = [];
} else {
$scope.customerName = customerSelected;
}
}
}

function addItem() {
if (isNaN($scope.numberOfItems)) {
Notification({ message: 'Count should be a valid number', title: 'Count value is not a number' }, 'warning');
return false;
}

var dublicateItem = false;
$scope.totalAddedItems.forEach(function (addedItem, index) {
if ($scope.selectedProduct != undefined && $scope.selectedProduct != null &&
addedItem.name === $scope.selectedProduct.name) {
var confirmOverWright = confirm("Do you want to overwright the current entry under the same Ad type ? Click OK to proceed");
if (confirmOverWright) {
$scope.totalAddedItems.splice(index, 1); //User overwrite an existing ad
} else {
dublicateItem = true; //User choose not add an advertisment which is allready added
}
}
});

if (!dublicateItem)
addToCheckoutList();
}

function addToCheckoutList() {
var addedItem = {};
customerSelected = $scope.customerName;
addedItem.name = $scope.selectedProduct.name;
addedItem.id = $scope.selectedProduct.id;
addedItem.price = $scope.selectedProduct.price;
addedItem.numberOfItems = $scope.numberOfItems;
addedItem.discountApplied = false;
addedItem.totalPrice = discountLogic(addedItem);
$scope.totalAddedItems.push(addedItem);
Notification({ message: 'Item added to checkout list', title: 'Item Added' }, 'success');
calculateTotalCheckoutValue();
}

function calculateTotalCheckoutValue() {
$scope.totalCheckoutValue = 0;
$scope.totalAddedItems.forEach(function (addedItem, index) {
$scope.totalCheckoutValue = $scope.totalCheckoutValue + addedItem.totalPrice;
});
}

function discountLogic(addedItem) {
var totalPrice = addedItem.totalPrice;
if (!addedItem.discountApplied) {
if ($scope.customerName === "UNILEVER") {
if (addedItem.id === 'classic') {
if (addedItem.numberOfItems >= 2) {
addedItem.numberOfItems = parseFloat(addedItem.numberOfItems) + 1;
totalPrice = parseFloat($scope.numberOfItems) * parseFloat(addedItem.price);
addedItem.discountApplied = true;
}
}
}
else if ($scope.customerName === 'APPLE') {
if (addedItem.id === 'standout') {
addedItem.price = 299.99;
totalPrice = parseFloat($scope.numberOfItems) * parseFloat(addedItem.price);
addedItem.discountApplied = true;
}
}
else if ($scope.customerName === 'NIKE') {
if (addedItem.id === 'premium') {
if (addedItem.numberOfItems >= 4) {
addedItem.numberOfItems = parseFloat(addedItem.numberOfItems);
addedItem.price = 379.99;
totalPrice = parseFloat($scope.numberOfItems) * parseFloat(addedItem.price);
addedItem.discountApplied = true;
}
}
}
else if ($scope.customerName === 'FORD') {
if (addedItem.id === 'classic') {
if (addedItem.numberOfItems >= 4) {
addedItem.numberOfItems = parseFloat(addedItem.numberOfItems) + 1;
totalPrice = parseFloat($scope.numberOfItems) * parseFloat(addedItem.price);
addedItem.discountApplied = true;
}
}
if (addedItem.id === 'standout') {
addedItem.price = 309.99;
totalPrice = parseFloat($scope.numberOfItems) * parseFloat(addedItem.price);
addedItem.discountApplied = true;
}
if (addedItem.id === 'premium') {
if (addedItem.numberOfItems >= 3) {
addedItem.numberOfItems = parseFloat(addedItem.numberOfItems);
addedItem.price = 389.99;
totalPrice = parseFloat($scope.numberOfItems) * parseFloat(addedItem.price);
addedItem.discountApplied = true;
}
}
}

totalPrice = totalPrice === addedItem.totalPrice ?
parseFloat($scope.numberOfItems) * parseFloat(addedItem.price) : totalPrice;
return totalPrice;
}

}

function removeItem(item) {
$scope.totalAddedItems.forEach(function (addedItem, index) {
if (addedItem.name === item.name) {
$scope.totalAddedItems.splice(index, 1);
Notification({ message: 'Item removed from checkout list', title: 'Item Removed' }, 'success');
calculateTotalCheckoutValue();//Update the total after removing an item
}
});
}

function goToDashboard() {
window.location = '/';
}
}

})();
Loading