Node Js - React Js - Django Lab
Node Js - React Js - Django Lab
Node Js - React Js - Django Lab
List of experiments:
1. Build a responsive web application for shopping cart with registration, login, catalog
and cart pages using CSS3 features, flex and grid.
2. Make the above web application responsive web application using Bootstrap framework.
3. Use JavaScript for doing client – side validation of the pages implemented in experiment
1 andexperiment 2.
4. Explore the features of ES6 like arrow functions, callbacks, promises, async/await.
Implementan application for reading the weather information from openweathermap.org
and display the information in the form of a graph on the web page.
5. Develop a java stand alone application that connects with the database (Oracle / mySql)
and perform the CRUD operation on the database tables.
6. Create an xml for the bookstore. Validate the same using both DTD and XSD.
7. Design a controller with servlet that provides the interaction with application developed
inexperiment 1 and the database created in experiment 5.
8. Maintaining the transactional history of any user is very important. Explore the various
sessiontracking mechanism (Cookies, HTTP Session)
9. Create a custom server using http module and explore the other modules of Node JS like
OS,path, event.
10. Develop an express web application that can interact with REST API to perform
14
CRUDoperations on student data. (Use Postman)
11. For the above application create authorized end points using JWT (JSON Web Token).
12. Create a react application for the student management system having registration, login,
contact, about pages and implement routing to navigate through these pages.
13. Create a service in react that fetches the weather information from openweathermap.org
and the display the current and historical weather information using graphical
representation usingchart.js
14. Create a TODO application in react with necessary components and deploy it into
github.
REFERENCE BOOKS
1. Jon Duckett, Beginning HTML, XHTML, CSS, and JavaScript, Wrox Publications, 2010
2. Bryan Basham, Kathy Sierra and Bert Bates, Head First Servlets and JSP, O‟Reilly
Media,2ndEdition, 2008.
3. Vasan Subramanian, Pro MERN Stack, Full Stack Web App Development with
Mongo,Express, React, and Node, 2nd Edition, A Pres
Course Outcomes:
● Build a custom website with HTML, CSS, and Bootstrap and little JavaScript.
● Demonstrate Advanced features of JavaScript and learn about JDBC
● Develop Server – side implementation using Java technologies like
● Develop the server – side implementation using Node JS.
● Design a Single Page Application using React
CO- PO Mapping
(3/2/1 indicates strength of correlation) 3-Strong, 2-Medium, 1-Weak
Program Outcomes (POs) PSOs
Co
s PO PO2 PO PO PO PO PO PO PO PO PO PSO PSO PSO
1 3 4 5 6 7 8 9 10 12 1 2 3
CO1 2 3 1 2 1
CO2 2 2 2 2
CO3 1 2 1 1
1. Build a responsive web application for shopping cart with registration, login,
catalog and cart pages using CSS3 features, flex and grid.
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Shopify</title>
<link rel="stylesheet" href="./css/style.css">
<link rel="stylesheet" href="./css/responsive.css">
<link href="https://fonts.googleapis.com/css2?
family=Poppins:ital,wght@1,900&display=swap" rel="stylesheet">
<script src="https://kit.fontawesome.com/1ba2cf90f3.js"
crossorigin="anonymous"></script>
<link rel="shortcut icon" href="./assests/Citycons_bag-512.webp" type="image/x-icon">
</head>
<body>
<section>
<nav>
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="signup.html">signup</a></li>
<li><a href="login.html">login</a></li>
</ul>
</nav>
<main class="fruits-side">
<span>Buy Fruits</span>
<button><a href="fruit-aisle.html">Shop Now <i class="fas
fa-caret-right"></i></a></button>
</main>
<div class="cart">
<main>
<ol>
<li>Item-Name</li>
<li>Qty</li>
<li>Total</li>
</ol>
<section>
<ul id="ul"></ul>
</section>
</main>
</div>
</section>
<script>
top_items_count.innerHTML = 0;
bottom_items_count.innerHTML = 0;
function openBucket() {
bucket.visibility = "visible";
bucket.opacity = "1";
bucket.zIndex = "9";
bucket.transition = "all 0.5s";
}
exit.addEventListener('click', () => {
bucket.visibility = "hidden";
bucket.opacity = "0";
bucket.zIndex = "-9";
bucket.transition = "all 0.5s";
});
top_items_count.innerHTML = count;
bottom_items_count.innerHTML = count;
</script>
</body>
</html>
Registration: signup.html
<!DOCTYPE html>
<html lang="en">
<html>
<head>
<title>Sign Up</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="signup_style.css" />
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-
awesome.min.css"
/>
<link
href="https://fonts.googleapis.com/css?family=Titillium+Web:400,300,600"
rel="stylesheet"
type="text/css"
/>
<script src="https://unpkg.com/@lottiefiles/lottie-player@latest/dist/lottie-
player.js"></script>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.1/css/all.css"
integrity="sha384-vp86vTRFVJgpjF9jiIGPEEqYqlDwgyBgEF109VFjmqGmIY/Y4HV
4d3Gp2irVfcrp" crossorigin="anonymous">
</head>
<div class="login-page">
<div class="form">
<form>
<lottie-player
src="https://assets4.lottiefiles.com/datafiles/XRVoUu3IX4sGWtiC3MPpFnJvZNq
7lVWDCa8LSqgS/profile.json"
background="transparent"
speed="1"
style="justify-content: center"
loop
autoplay
></lottie-player>
<input type="text" placeholder="full name" />
<input type="text" placeholder="email address" />
<input type="text" placeholder="pick a username" />
<input type="password" id="password" placeholder="set a password" />
<i class="fas fa-eye" onclick="show()"></i>
<br>
<br>
</form>
<form class="login-form">
<button type="button" onclick="window.location.href='login.html'">
SIGN UP
</button>
</form>
</div>
</div>
</body>
<script>
function show() {
var password = document.getElementById("password");
var icon = document.querySelector(".fas");
<div class="login-page">
<div class="form">
<form>
<lottie-player
src="https://assets4.lottiefiles.com/datafiles/XRVoUu3IX4sGWtiC3MPpFnJvZNq7l
VWDCa8LSqgS/profile.json" background="transparent" speed="1" style="justify-
content: center;" loop autoplay></lottie-player>
<input type="text" placeholder=" username"/>
<input type="password" id="password" placeholder=" password"/>
<i class="fas fa-eye" onclick="show()"></i>
<br>
<br>
<button>LOGIN</button>
<p class="message"></p>
</form>
<form class="login-form">
<button type="button" onclick="window.location.href='signup.html'">SIGN
UP</button>
</form>
</div>
</div>
<script>
function show(){
var password = document.getElementById("password");
var icon = document.querySelector(".fas")
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Fruit-Aisle</title>
<link rel="stylesheet" href="./css/style3.css">
<link rel="stylesheet" href="./css/responsive.css">
<link href="https://fonts.googleapis.com/css2?
family=Poppins:ital,wght@1,900&display=swap" rel="stylesheet">
<script src="https://kit.fontawesome.com/1ba2cf90f3.js"
crossorigin="anonymous"></script>
<link rel="shortcut icon" href="./assests/Citycons_bag-512.webp" type="image/x-
icon">
</head>
<body>
<section>
<nav>
<ul>
<li><a href="index.html">Home</a></li>
<li><a href="signup.html">signup</a></li>
<li><a href="login.html">login</a></li>
<li><span onclick="openBucket()"><i class="fas
fa-shopping-cart"></i></span>
<span class="items-count"></span>
</li>
</ul>
</nav>
<main>
</main>
<div class="cart">
<main>
<ol>
<li>Item-Name</li>
<li>Qty</li>
<li>Total</li>
</ol>
<section>
<ul id="ul">
</ul>
</section>
</main>
</div>
</section>
<script src="./js/script3.js"></script>
</body>
</html>
Responsive.css
.cart-icon {
color: #323232;
font-size: 1.3rem;
}
.cart {
position: fixed;
height: 100vh;
width: 100%;
top: 0%;
left: 0%;
transform: scale(0.9);
}
.cart {
position: fixed;
height: 100vh;
width: 100%;
top: 0%;
left: 0%;
transform: scale(0.9);
}
Style.css
*,
body {
margin: 0;
padding: 0;
list-style: none;
text-decoration: none;
outline: none;
letter-spacing: 1px;
transition: all 0.5s;
color: inherit;
scroll-behavior: smooth;
font-family: "Poppins", sans-serif;
}
section {
position: relative;
width: 100%;
display: grid;
grid-template-columns: 0.99fr;
grid-template-rows: 15vh repeat(3, 80vh) 15vh;
align-content: space-around;
justify-content: space-evenly;
}
.cart-icon{
display: none;
}
.items-count {
position: absolute;
padding: 5px;
background-color: red;
color: white;
font-weight: bold;
font-size: 0.9rem;
border-radius: 30px;
top: -40%;
}
.fruits-side {
background-image: url("../assests/62.jpg");
background-size: 100% 100%;
display: grid;
align-content: space-around;
justify-content: space-evenly;
}
.bottom-items-count {
position: absolute;
padding: 5px;
background-color: red;
color: white;
font-weight: bold;
font-size: 0.9rem;
border-radius: 30px;
bottom: 40%;
}
.cart {
position: fixed;
height: 98.5%;
width: 25vw;
background-color: whitesmoke;
top: 0.5%;
right: 0.5%;
display: grid;
grid-template-columns: 0.95fr;
grid-template-rows: 10vh 60vh 10vh;
align-content: space-around;
justify-content: space-evenly;
box-shadow: 0px 0px 10px 5px rgba(0, 0, 0, 0.5);
border-radius: 5px;
opacity: 0;
visibility: hidden;
z-index: -9;
transition: all 0.5s;
}
.exit > i {
font-size: 2rem;
color: #323232;
cursor: pointer;
transition: all 0.5s;
}
Style3.css
*,
body {
margin: 0;
padding: 0;
list-style: none;
text-decoration: none;
outline: none;
letter-spacing: 1px;
transition: all 0.5s;
color: inherit;
scroll-behavior: smooth;
font-family: "Poppins", sans-serif;
}
section {
width: 100%;
display: grid;
grid-template-columns: 0.99fr;
grid-template-rows: 15vh 90vh 15vh;
align-content: space-around;
justify-content: space-evenly;
transition: all 0.5s;
}
.items-count {
position: absolute;
padding: 5px;
background-color: red;
color: white;
font-weight: bold;
font-size: 0.9rem;
border-radius: 30px;
top: -40%;
}
.cart-icon {
display: none;
}
.items {
border-radius: 5px;
position: relative;
transition: all 0.5s;
}
.item-1 {
background-image: url("../assests/fruit-img/close-up-photography-of-apples-
672101.jpg");
background-size: 100% 100%;
}
.item-1::after {
content: "Apples";
position: absolute;
bottom: -13.5%;
left: 0;
font-weight: bold;
font-size: 1.75rem;
color: #323232;
}
.item-1::before {
content: "Add To Cart";
position: absolute;
font-weight: bold;
font-size: 1.2rem;
color: white;
background-color: transparent;
padding: 10px;
border-radius: 20px;
cursor: pointer;
left: 27%;
top: 45%;
cursor: pointer;
opacity: 0;
visibility: hidden;
transition: all 0.5s;
border: 2px solid white;
}
.item-1:hover::before {
opacity: 1;
visibility: visible;
transition: all 0.5s;
}
.item-1:hover {
background-image: linear-gradient(rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0.3)),
url("../assests/fruit-img/close-up-photography-of-apples-672101.jpg");
}
.item-2 {
background-image: url("../assests/fruit-img/three-yellow-citrus-952360.jpg");
background-size: 100% 100%;
}
.item-2::after {
content: "Lemons";
position: absolute;
bottom: -13.5%;
left: 0;
font-weight: bold;
font-size: 1.75rem;
color: #323232;
}
.item-2::before {
content: "Add To Cart";
position: absolute;
font-weight: bold;
font-size: 1.2rem;
color: white;
background-color: transparent;
padding: 10px;
border-radius: 20px;
cursor: pointer;
left: 27%;
top: 45%;
cursor: pointer;
opacity: 0;
visibility: hidden;
transition: all 0.5s;
border: 2px solid white;
}
.item-2:hover::before {
opacity: 1;
visibility: visible;
transition: all 0.5s;
}
.item-2:hover {
background-image: linear-gradient(rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0.3)),
url("../assests/fruit-img/three-yellow-citrus-952360.jpg");
}
.item-3 {
background-image: url("../assests/fruit-img/white-bowl-of-whole-strawberries-
89778.jpg");
background-size: 100% 100%;
}
.item-3::after {
content: "Strawberries";
position: absolute;
bottom: -13.5%;
left: 0;
font-weight: bold;
font-size: 1.75rem;
color: #323232;
}
.item-3::before {
content: "Add To Cart";
position: absolute;
font-weight: bold;
font-size: 1.2rem;
color: white;
background-color: transparent;
padding: 10px;
border-radius: 20px;
cursor: pointer;
left: 27%;
top: 45%;
cursor: pointer;
opacity: 0;
visibility: hidden;
transition: all 0.5s;
border: 2px solid white;
}
.item-3:hover::before {
opacity: 1;
visibility: visible;
transition: all 0.5s;
}
.item-3:hover {
background-image: linear-gradient(rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0.3)),
url("../assests/fruit-img/white-bowl-of-whole-strawberries-89778.jpg");
}
.item-4 {
background-image: url("../assests/fruit-img/yellow-bananas-61127.jpg");
background-size: 100% 100%;
}
.item-4::after {
content: "Bananas";
position: absolute;
bottom: -13.5%;
left: 0;
font-weight: bold;
font-size: 1.75rem;
color: #323232;
}
.item-4::before {
content: "Add To Cart";
position: absolute;
font-weight: bold;
font-size: 1.2rem;
color: white;
background-color: transparent;
padding: 10px;
border-radius: 20px;
cursor: pointer;
left: 27%;
top: 45%;
cursor: pointer;
opacity: 0;
visibility: hidden;
transition: all 0.5s;
border: 2px solid white;
}
.item-4:hover::before {
opacity: 1;
visibility: visible;
transition: all 0.5s;
}
.item-4:hover {
background-image: linear-gradient(rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0.3)),
url("../assests/fruit-img/yellow-bananas-61127.jpg");
}
.item-1::before,
.item-2::before,
.item-3::before,
.item-4::before {
padding: 10px 15px;
left: 20%;
top: 43%;
}
.item-1::after,
.item-2::after,
.item-3::after,
.item-4::after {
bottom: -18%;
font-size: 1.5rem;
}
.item-4 {
margin-bottom: 10%;
}
}
.item-1::before,
.item-2::before,
.item-3::before,
.item-4::before {
padding: 10px 15px;
left: 20%;
top: 43%;
}
.item-1::after,
.item-2::after,
.item-3::after,
.item-4::after {
bottom: -18%;
font-size: 1.5rem;
}
}
OUTPUT:
2. Make the above web application responsive web application using Bootstrap framework
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<title>Bootstrap 4 - Shopping Cart</title>
<link rel="stylesheet" href="assets/bootstrap/bootstrap.min.css">
<script src="assets/js/jquery.min.js"></script>
<link rel="stylesheet" href="assets/fontawesome/css/all.min.css">
<script src="assets/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="assets/css/style.css">
<link rel="icon" href="images/favicon.ico" type="image/x-icon" />
</head>
<body>
<!-- partial:index.partial.html -->
<!-- Nav -->
<nav class="navbar navbar-inverse bg-inverse fixed-top bg-faded">
<div class="row">
<div class="col">
<span data-toggle="modal" data-target="#cart">
<i class="fas fa-shopping-cart fa-2x fa-border icon-grey
zoom-sm"><span class="badge total-count"></span></i>
</span>
</div>
</div>
</nav>
</div>
<!--container.//-->
<!-- Modal -->
<div class="modal fade" id="cart" tabindex="-1" role="dialog" aria-
labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<form action="index.html" method="get" class="cart-form">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel"><i class="fas fa-shopping-
cart text-black"></i> Shopping Cart</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<table class="show-cart table">
</table>
<div class="font-weight-bold">Total price: $<span class="total-cart text-
danger"></span></div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger"
data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-success">Checkout</button>
</div>
</form>
</div>
</div>
</div>
<!-- partial -->
<script src='assets/js/jquery.min.js'></script>
<script src="assets/js/script.js"></script>
</body>
</html>
script.js
// ************************************************
// Shopping Cart API
// ************************************************
// Constructor
function Item(product_id, name, price, pimage, count) {
"use strict";
this.product_id = product_id;
this.name = name;
this.price = price;
this.pimage = pimage;
this.count = count;
}
// Save cart
function saveCart() {
"use strict";
sessionStorage.setItem('shoppingCart', JSON.stringify(cart));
}
// Load cart
function loadCart() {
"use strict";
cart = JSON.parse(sessionStorage.getItem('shoppingCart'));
}
if (sessionStorage.getItem("shoppingCart") != null) {
loadCart();
}
// =============================
// Public methods and propeties
// =============================
var obj = {};
// Add to cart
obj.addItemToCart = function(product_id, name, price, pimage, count) {
"use strict";
for(var item in cart) {
if(cart[item].product_id === product_id) {
cart[item].count ++;
saveCart();
return;
}
}
var item = new Item(product_id, name, price, pimage, count);
cart.push(item);
saveCart();
}
// Set count from item
obj.setCountForItem = function(product_id, count) {
"use strict";
for(var i in cart) {
if (cart[i].product_id === product_id) {
cart[i].count = count;
break;
}
}
};
// Remove item from cart
obj.removeItemFromCart = function(product_id) {
"use strict";
for(var item in cart) {
if(cart[item].product_id === product_id) {
cart[item].count --;
if(cart[item].count === 0) {
cart.splice(item, 1);
}
break;
}
}
saveCart();
}
// Clear cart
obj.clearCart = function() {
"use strict";
cart = [];
saveCart();
}
// Count cart
obj.totalCount = function() {
"use strict";
var totalCount = 0;
for(var item in cart) {
totalCount += cart[item].count;
}
return totalCount;
}
// Total cart
obj.totalCart = function() {
"use strict";
var totalCart = 0;
for(var item in cart) {
totalCart += cart[item].price * cart[item].count;
}
return Number(totalCart.toFixed(2));
}
// List cart
obj.listCart = function() {
var cartCopy = [];
for(i in cart) {
item = cart[i];
itemCopy = {};
for(p in item) {
itemCopy[p] = item[p];
}
itemCopy.total = Number(item.price * item.count).toFixed(2);
cartCopy.push(itemCopy)
}
return cartCopy;
}
// cart : Array
// Item : Object/Class
// addItemToCart : Function
// removeItemFromCart : Function
// removeItemFromCartAll : Function
// clearCart : Function
// countCart : Function
// totalCart : Function
// listCart : Function
// saveCart : Function
// loadCart : Function
return obj;
})();
// *****************************************
// Triggers / Events
// *****************************************
// Add item
$('.add-to-cart').on("click", function(event){
"use strict";
event.preventDefault();
var product_id = $(this).data('product_id');
var name = $(this).data('name');
var price = Number($(this).data('price'));
var pimage = $(this).data('pimage');
shoppingCart.addItemToCart(product_id, name, price, pimage, 1);
displayCart();
});
// Clear items
$('.clear-cart').on("click",function() {
"use strict";
shoppingCart.clearCart();
displayCart();
});
function displayCart() {
"use strict";
var cartArray = shoppingCart.listCart();
var output = "";
var total_order = 0;
for(var i in cartArray) {
total_order++;
output += "<div class='col-12'>"
+ "<div class='row justify-content-center'>"
+ "<div class='col-5'>"
+ "<div class='row'>"
+ "<div class='col-9 text-left'>"
+ "<img src='" + cartArray[i].pimage + "' class='rounded-circle' width='50' height='50' />"
+ "<span class='text-info pl-3 font-weight-bold'>" + cartArray[i].name + "</span>"
+ "</div>"
+ "<div class='col-3'>"
+ "<span class='text-dark pl-2 mr-1'>(" + cartArray[i].price + ")</span>"
+ "</div>"
+ "</div>"
+ "</div>"
+ "<div class='col-4'>"
+ "<div class='input-group'><button class='minus-item input-group-addon btn btn-primary' data-
product_id=" + cartArray[i].product_id + ">-</button>"
+ "<input type='number' class='item-count form-control' data-product_id='" +
cartArray[i].product_id + "' value='" + cartArray[i].count + "'>"
+ "<button class='plus-item btn btn-primary input-group-addon' data-product_id=" +
cartArray[i].product_id + ">+</button></div>"
+ "</div>"
+ "<div class='col-3'>"
+ "<button class='delete-item btn btn-danger' data-product_id=" + cartArray[i].product_id +
">X</button>"
+ "<span class='text-dart pl-2'><kbd>" + cartArray[i].total + "</kbd></span>"
+ "</div>"
+ "</div>"
+ "</div>"
+ "<div class='row' id='hedden-fields'><input type = 'hidden' class='sr-only' name='ProductID[]'
id='ProductName' value='" + cartArray[i].product_id + "'>"
+ "<input type = 'hidden' class='sr-only' name='ProductName[]' id='ProductName' value='" +
cartArray[i].name + "'>"
+ "<input type = 'hidden' class='sr-only' name='ProductPrice[]' id='ProductPrice' value='" +
cartArray[i].price + "'>"
+ "<input type = 'hidden' class='sr-only' name='ProductQuantity[]' id='ProductQuantity' value='" +
cartArray[i].count + "'>"
+ "<input type = 'hidden' class='sr-only' name='TotalOrderedItems' id='TotalOrderedItems'
value='" + total_order + "'></div>"
+ "<hr/>" ;
}
$('.show-cart').html(output);
$('.total-cart').html(shoppingCart.totalCart());
$('.total-count').html(shoppingCart.totalCount());
}
// Delete item button
// -1
$('.show-cart').on("click", ".minus-item", function(event) {
"use strict";
var name = $(this).data('name');
var product_id = $(this).data('product_id');
shoppingCart.removeItemFromCart(product_id);
displayCart();
})
// +1
$('.show-cart').on("click", ".plus-item", function(event) {
"use strict";
var name = $(this).data('name');
var product_id = $(this).data('product_id');
shoppingCart.addItemToCart(product_id);
displayCart();
})
displayCart();
// =============================
// Cart toast display
// =============================
$('.show-toast').on("click",function(){
"use strict";
const x = document.getElementById("product-toast");
var item_name = $(this).data('name');
$("#item-name").text(item_name);
x.className = "show";
setTimeout(function(){ x.className = x.className.replace("show", ""); }, 3000);
});
body {
padding-top: 80px;
}
.card-product .img-wrap {
border-radius: 3px 3px 0 0;
overflow: hidden;
position: relative;
height: 220px;
text-align: center;
}
.card-product .img-wrap img {
max-height: 100%;
max-width: 100%;
object-fit: cover;
}
.card-product .info-wrap {
overflow: hidden;
padding: 15px;
border-top: 1px solid #eee;
}
.card-product .bottom-wrap {
padding: 15px;
border-top: 1px solid #eee;
}
.label-rating { margin-right:10px;
color: #333;
display: inline-block;
vertical-align: middle;
}
.card-product .price-old {
color: #999;
}
.fa-2x-cart{
font-size:24px
}
.label-warning[href],
.badge-warning[href] {
background-color: #c67605;
}
.fa-shopping-cart {
margin-top: 0.2em;
position: relative;
}
.badge {
font-size: .25em;
display: block;
position: absolute;
top: -.70em;
right: -.70em;
width: 2.5em;
height: 2.4em;
line-height: 2em;
border-radius: 50%;
text-align: center;
color: #fff;
background: rgba(207, 0, 15, 1);
}
.zoom-sm:hover {
transform: scale(1.03);
}
position: fixed;
z-index: 1;
left: 0;right:0;
bottom: 30px;
font-size: 17px;
white-space: nowrap;
}
#product-toast #img{
width: 70px;
height: 50px;
float: left;
padding-top: 16px;
padding-bottom: 16px;
box-sizing: border-box;
background-color: #111;
color: #fff;
}
#product-toast #desc{
color: #fff;
padding: 16px;
overflow: hidden;
white-space: nowrap;
}
#product-toast.show {
visibility: visible;
-webkit-animation: fadein 0.5s, expand 0.5s 0.5s,stay 3s 1s, shrink 0.5s 2s, fadeout 0.5s 2.5s;
animation: fadein 0.5s, expand 0.5s 0.5s,stay 3s 1s, shrink 0.5s 4s, fadeout 0.5s 4.5s;
}
@-webkit-keyframes fadein {
from {bottom: 0; opacity: 0;}
to {bottom: 30px; opacity: 1;}
}
@keyframes fadein {
from {bottom: 0; opacity: 0;}
to {bottom: 30px; opacity: 1;}
}
@-webkit-keyframes expand {
from {min-width: 50px}
to {min-width: 350px}
}
@keyframes expand {
from {min-width: 50px}
to {min-width: 350px}
}
@-webkit-keyframes stay {
from {min-width: 350px}
to {min-width: 350px}
}
@keyframes stay {
from {min-width: 350px}
to {min-width: 350px}
}
@-webkit-keyframes shrink {
from {min-width: 350px;}
to {min-width: 50px;}
}
@keyframes shrink {
from {min-width: 350px;}
to {min-width: 50px;}
}
@-webkit-keyframes fadeout {
from {bottom: 30px; opacity: 1;}
to {bottom: 60px; opacity: 0;}
}
@keyframes fadeout {
from {bottom: 30px; opacity: 1;}
to {bottom: 60px; opacity: 0;}
}
3. Use JavaScript for doing client – side validation of the pages
implemented in experiment 1 andexperiment 2.
const top_items_count = document.querySelector('.items-count'),
bottom_items_count = document.querySelector('.bottom-items-count'),
exit = document.querySelector('.exit'),
bucket = document.querySelector('.cart').style;
top_items_count.innerHTML = count;
bottom_items_count.innerHTML = count;
function openBucket() {
bucket.visibility = "visible";
bucket.opacity = "1";
bucket.zIndex = "9";
bucket.transition = "all 0.5s";
}
exit.addEventListener('click', () => {
bucket.visibility = "hidden";
bucket.opacity = "0";
bucket.zIndex = "-9";
bucket.transition = "all 0.5s";
});
() => {
if (localStorage.food_cart) {
food_cart = JSON.parse(localStorage.food_cart);
showCart();
}
}
var qty=1;
var itemArray = {
Product: itemName,
Price: price,
Qty: qty
}
food_cart.push(itemArray)
saveCart();
showCart();
}
function saveCart() {
if (window.localStorage) {
localStorage.food_cart = JSON.stringify(food_cart);
}
}
function deleteItem(index) {
food_cart.splice(index, 1);
showCart();
saveCart();
}
function showCart() {
if (food_cart.length == 0) {
var _ul = document.querySelector('#ul');
_ul.innerHTML = "";
return;
}
4. Explore the features of ES6 like arrow functions, callbacks, promises, async/await.
Implementan application for reading the weather information from
openweathermap.org and display the information in the form of a graph on the web
page.
Arrow functions are introduced in ES6, which provides you a more accurate way to write
the functions in JavaScript. They allow us to write smaller function syntax. Arrow functions
make your code more readable and structured.
1. const functionName = (arg1, arg2, ?..) => {
2. //body of the function
3. }
// function expression
// Anonymous function
//Arrow function
myfun1();
myfun2();
myfun3();
Output
It is a Function Expression
It is an Anonymous Function
It is an Arrow Function
ES6 Promises
A Promise represents something that is eventually fulfilled. A Promise can either be
rejected or resolved based on the operation outcome.
ES6 Promise is the easiest way to work with asynchronous programming in JavaScript.
Asynchronous programming includes the running of processes individually from the
main thread and notifies the main thread when it gets complete. Prior to the
Promises, Callbacks were used to perform asynchronous programming.
Callback
A Callback is a way to handle the function execution after the completion of the
execution of another function.
Syntax
Example
Output
JavaScript Async/Await
JavaScript is always synchronous and single-threaded that provides the event loops. The event loops
enable us to queue up an activity. This activity will not happen until the loops become available after the
program that queued the action has completed the execution. However, our program contains a large
number of functionalities, which causes our code to be asynchronous. The Async/Await functionality is
one of them. Async/Await is an extension of promises that we get as language support.
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <meta charset="utf-8">
5. <title>JavaScript Async</title>
6. </head>
7. <body>
8. <h2>JavaScript Async</h2>
9. <p id="main"></p>
10. <script>
11. function myDisplayer(some) {
12. document.getElementById("main").innerHTML = some;
13. }
14. async function myfirstFunction() {
15. return "Hello World!!!";
16. }
17. myfirstFunction().then(
18. function(value) {myDisplayer(value);},
19. function(error) {myDisplayer(error);}
20. );
21. </script>
22. </body>
23. </html>
Output: After executing the above code, we will get the output shown below in the
screenshot.
JavaScript Await
JavaScript Await function is used to wait for the promise. It could only be used inside the async
block. It instructs the code to wait until the promise returns a response. It only delays the async
block. Await is a simple command that instructs JavaScript to wait for an asynchronous action
to complete before continuing with the feature. It's similar to a "pause until done" keyword.
The await keyword is used to retrieve a value from a function where we will usually be used
the then() function. Instead of calling after the asynchronous function, we'd use await to
allocate a variable to the result and then use the result in the code as we will in the
synchronous code.
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <meta charset="utf-8">
5. <title>JavaScript Await</title>
6. </head>
7. <body>
8. <h2>JavaScript Await</h2>
9. <p id="main"></p>
10. <script>
11. async function myDisplay() {
12. let myPromise = new Promise(function(myResolve, myReject) {
13. myResolve("Hello World!!");
14. });
15. document.getElementById("main").innerHTML = await myPromise;
16. }
17. myDisplay();
18. </script>
19. </body>
20. </html>
Output: After executing this code, we will get the output as shown below in the
screenshot:
Implementan application for reading the weather information from openweathermap.org and display the
information in the form of a graph on the web page.
MainPage.html
<!DOCTYPE html>
<html>
<head>
<title>Weather Report</title>
<link rel="icon" href="favicon.png">
<link rel="stylesheet" href="PageStyle.css">
<link href=
'https://fonts.googleapis.com/css?family=Delius Swash Caps'
rel='stylesheet'>
</head>
<body>
<p id="data" class="styleIt"></p>
<script src="JSPage.js"></script>
</body>
</html>
PageStyle.css
p.styleIt
{
background-color: rgb(182, 182, 182);
border: 2px solid rgb(182, 182, 182);
border-radius: 8px;
text-align: center;
box-shadow: 6px 5px 2px rgb(182, 182, 182), 0 0 25px rgb(0, 0, 0), 0 0
5px rgb(182, 182, 182);
font-family: 'Delius Swash Caps';
}
body{
background:rgb(120, 120, 120);
margin: 0;
position: absolute;
top: 50%;
left: 50%;
margin-right: -50%;
transform: translate(-50%, -50%)
}
JSPage.js
var data =
document.getElementById("dat
a");
var Latitude;
var Longitude;
var key = "------Put Your Own Key-----";
var url =
"http://api.openweathermap.org/data/2.5/weather?";
function getLocation(){
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(showPosition);
}
else{
data_of_Lat_Lon.innerHTML="Geolocation is not
supported by this browser. SORRY!";
}
}
function showPosition(position){
Latitude = position.coords.latitude;
Longitude = position.coords.longitude;
getData(Latitude,Longitude);
}
function getData(Lat,Lon){
const readyToSent =
(url+"lat="+Lat+"&lon="+Lon+"&appid="+key);
fetch(readyToSent)
.then(response=>response.json())
.then(data=>{
console.log(data);
fetchData(data)
})
}
function fetchData(data){
const icon =
"http://openweathermap.org/img/wn/"+data.weather[0].icon+"
@2x.png"
document.getElementById("data").innerHTML =
"<b>The weather report of your Location is
:-</b><br>"+
"<img src="+icon+"><br>"+
"<b>Country :</b>"+data.sys.country+
"<br><b>Local Area Name :</b>"+data.name+
"<br><b>Temp. :</b>"+parseFloat((data.main.temp -
273.15)).toFixed(1)+"℃"+
"<br><b>But You will feel like
:</b>"+parseFloat((data.main.feels_like -
273.15)).toFixed(1)+"℃"+
"<br><b>Min. Temp.
:</b>"+parseFloat((data.main.temp_min -
273.15)).toFixed(1)+"℃"+
"<br><b>Max. Temp.
:</b>"+parseFloat((data.main.temp_max -
273.15)).toFixed(1)+"℃"+
"<br><b>Pressure :</b>"+data.main.pressure+"hPa"+
"<br><b>Humidity :</b>"+data.main.humidity+"%"+
"<br><b>Weather
:</b>"+data.weather[0].description+
"<br>"
}
getLocation();
showPosition();
getData();
To create a Django application that performs CRUD operations, follow the following
steps.
1. Create a Project
2. Create an App
3. Project Structure
Create a database djangodb in mysql, and configure into the settings.py file of
django project. See the example.
// settings.py
1. DATABASES = {
2. 'default': {
3. 'ENGINE': 'django.db.backends.mysql',
4. 'NAME': 'djangodb',
5. 'USER':'root',
6. 'PASSWORD':'mysql',
7. 'HOST':'localhost',
8. 'PORT':'3306'
9. }
10. }
5. Create a Model
// models.py
1. from django.db import models
2. class Employee(models.Model):
3. eid = models.CharField(max_length=20)
4. ename = models.CharField(max_length=100)
5. eemail = models.EmailField()
6. econtact = models.CharField(max_length=15)
7. class Meta:
8. db_table = "employee"
6. Create a ModelForm
// forms.py
// views.py
8. Provide Routing
// urls.py
9. Organize Templates
Create a templates folder inside the employee app and create three (index, edit,
show) html files inside the directory. The code for each is given below
// index.html
1. <!DOCTYPE html>
2. <html lang="en">
3. <head>
4. <meta charset="UTF-8">
5. <title>Index</title>
6. {% load staticfiles %}
7. <link rel="stylesheet" href="{% static 'css/style.css' %}"/>
8. </head>
9. <body>
10. <form method="POST" class="post-form" action="/emp">
11. {% csrf_token %}
12. <div class="container">
13. <br>
14. <div class="form-group row">
15. <label class="col-sm-1 col-form-label"></label>
16. <div class="col-sm-4">
17. <h3>Enter Details</h3>
18. </div>
19. </div>
20. <div class="form-group row">
21. <label class="col-sm-2 col-form-label">Employee Id:</label>
22. <div class="col-sm-4">
23. {{ form.eid }}
24. </div>
25. </div>
26. <div class="form-group row">
27. <label class="col-sm-2 col-form-label">Employee Name:</label>
28. <div class="col-sm-4">
29. {{ form.ename }}
30. </div>
31. </div>
32. <div class="form-group row">
33. <label class="col-sm-2 col-form-label">Employee Email:</label>
34. <div class="col-sm-4">
35. {{ form.eemail }}
36. </div>
37. </div>
38. <div class="form-group row">
39. <label class="col-sm-2 col-form-label">Employee Contact:</label>
40. <div class="col-sm-4">
41. {{ form.econtact }}
42. </div>
43. </div>
44. <div class="form-group row">
45. <label class="col-sm-1 col-form-label"></label>
46. <div class="col-sm-4">
47. <button type="submit" class="btn btn-primary">Submit</button>
48. </div>
49. </div>
50. </div>
51. </form>
52. </body>
53. </html>
// show.html
1. <!DOCTYPE html>
2. <html lang="en">
3. <head>
4. <meta charset="UTF-8">
5. <title>Employee Records</title>
6. {% load staticfiles %}
7. <link rel="stylesheet" href="{% static 'css/style.css' %}"/>
8. </head>
9. <body>
10. <table class="table table-striped table-bordered table-sm">
11. <thead class="thead-dark">
12. <tr>
13. <th>Employee ID</th>
14. <th>Employee Name</th>
15. <th>Employee Email</th>
16. <th>Employee Contact</th>
17. <th>Actions</th>
18. </tr>
19. </thead>
20. <tbody>
21. {% for employee in employees %}
22. <tr>
23. <td>{{ employee.eid }}</td>
24. <td>{{ employee.ename }}</td>
25. <td>{{ employee.eemail }}</td>
26. <td>{{ employee.econtact }}</td>
27. <td>
28. <a href="/edit/{{ employee.id }}"><span class="glyphicon glyphicon-
pencil" >Edit</span></a>
29. <a href="/delete/{{ employee.id }}">Delete</a>
30. </td>
31. </tr>
32. {% endfor %}
33. </tbody>
34. </table>
35. <br>
36. <br>
37. <center><a href="/emp" class="btn btn-primary">Add New Record</a></
center>
38. </body>
39. </html>
// edit.html
1. <!DOCTYPE html>
2. <html lang="en">
3. <head>
4. <meta charset="UTF-8">
5. <title>Index</title>
6. {% load staticfiles %}
7. <link rel="stylesheet" href="{% static 'css/style.css' %}"/>
8. </head>
9. <body>
10. <form method="POST" class="post-form" action="/update/{{employee.id}}">
11. {% csrf_token %}
12. <div class="container">
13. <br>
14. <div class="form-group row">
15. <label class="col-sm-1 col-form-label"></label>
16. <div class="col-sm-4">
17. <h3>Update Details</h3>
18. </div>
19. </div>
20. <div class="form-group row">
21. <label class="col-sm-2 col-form-label">Employee Id:</label>
22. <div class="col-sm-4">
23. <input type="text" name="eid" id="id_eid" required maxlength="20" value
="{{ employee.eid }}"/>
24. </div>
25. </div>
26. <div class="form-group row">
27. <label class="col-sm-2 col-form-label">Employee Name:</label>
28. <div class="col-sm-4">
29. <input type="text" name="ename" id="id_ename" required maxlength="1
00" value="{{ employee.ename }}" />
30. </div>
31. </div>
32. <div class="form-group row">
33. <label class="col-sm-2 col-form-label">Employee Email:</label>
34. <div class="col-sm-4">
35. <input type="email" name="eemail" id="id_eemail" required maxlength="
254" value="{{ employee.eemail }}" />
36. </div>
37. </div>
38. <div class="form-group row">
39. <label class="col-sm-2 col-form-label">Employee Contact:</label>
40. <div class="col-sm-4">
41. <input type="text" name="econtact" id="id_econtact" required maxlength
="15" value="{{ employee.econtact }}" />
42. </div>
43. </div>
44. <div class="form-group row">
45. <label class="col-sm-1 col-form-label"></label>
46. <div class="col-sm-4">
47. <button type="submit" class="btn btn-success">Update</button>
48. </div>
49. </div>
50. </div>
51. </form>
52. </body>
53. </html>
Create migrations for the created model employee, use the following command.
After migrations, execute one more command to reflect the migration into the
database. But before it, mention name of app (employee) in INSTALLED_APPS of
settings.py file.
// settings.py
1. INSTALLED_APPS = [
2. 'django.contrib.admin',
3. 'django.contrib.auth',
4. 'django.contrib.contenttypes',
5. 'django.contrib.sessions',
6. 'django.contrib.messages',
7. 'django.contrib.staticfiles',
8. 'employee'
9. ]
Now, our application has successfully connected and created tables in database. It
creates 10 default tables for handling project (session, authentication etc) and one
table of our model that we created.
Adding Record
Click on the Add New Record button and fill the details. See the example.
Filling the details.
6.Create an xml for the bookstore. Validate the same using both DTD and
XSD
< booksinfor.dtd >
<!ELEMENT books (book+)>
<!ELEMENT book (title,author,ISBN,publisher,edition,price)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT author (#PCDATA)>
<!ELEMENT ISBN (#PCDATA)>
<!ELEMENT publisher (#PCDATA)>
<!ELEMENT edition (#PCDATA)>
<!ELEMENT price (#PCDATA)>
Mysql database
Procedure:
Reg.html:
<html>
<head>
<title> validation </title>
</head>
<body bgcolor="magenta">
<form action="Register.jsp" method="post">
<h1 align="center">REGISTRATION FORM</h1>
<table border="0">
<tr>
<td>Name:</td>
<td><input type="text" name="t1" min length="6"></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="t2"></td>
</tr>
<tr>
<td>Phone number:</td>
<td><input type="text" name="t3"></td>
</tr>
<tr>
<td>E-mail id:</td>
<td><input type="text" name="t4"></td>
</tr>
<tr>
<td><input type="submit" value="submit"></td>
<td><input type="reset" value="cancel"></td>
</tr>
</table>
</form>
</body>
</html>
Register.jsp:
<%@ page language="java" import="java.sql.*,javax.servlet.*" %>
<html>
<form >
<%
String v1,v2,v3,v4,str;
v1=request.getParameter("t1");
v2=request.getParameter("t2");
v3=request.getParameter("t3");
v4=request.getParameter("t4");
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection cn=DriverManager.getConnection("jdbc:odbc:oradsn","system","ravindra");
Statement st=cn.createStatement();
st.executeUpdate("insert into register values('"+v1+"','"+v2+"',"+v3+",'"+v4+"')");
if(cn!=null)
{
%>
</form>
Registration Successful
<%
}
else
{
out.println("Registration failed");
}
st.close();
cn.close();
}catch(Exception e) { out.println(" Registration failed");
%>
<P><a href = "reg.html" target =f2 > <B> Back<B> </a>
<%
}
%>
</body></html>
Execution:
Create a table with name register with name (varchar2 (10)), password (varchar2 (10)),
Phone(number (10)) ,Email-ID (varchar2(10)).
Create the Data source name.
Start->settings->control panel->Administrative Tools->Data Sources.
Under SystemDSN add Microsoft ODBC for Oracle.
Set Data Source name to oradsn.
Output:1
Output:2
8. Maintaining the transactional history of any user is very important. Explore the various
sessiontracking mechanism (Cookies, HTTP Session)
package com.journaldev.servlet.session;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
/**
* Servlet implementation class LoginServlet
*/
@WebServlet("/LoginServlet")
public class LoginServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private final String userID = "admin";
private final String password = "password";
package com.journaldev.servlet.session;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
/**
* Servlet implementation class LogoutServlet
*/
@WebServlet("/LogoutServlet")
public class LogoutServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
The following example demonstrates handling HTTP request and response in Node.js.
}
else if (req.url == "/student") {
}
else
res.end('Invalid Request!');
});
To test it, you can use the command-line program curl, which most Mac and Linux
machines have pre-installed.
curl -i http://localhost:5000
HTTP/1.1 200 OK
Content-Type: text/plain
Connection: keep-alive
This is home page.
10. Develop an express web application that can interact with REST API to perform 14
CRUDoperations on student data. (Use Postman)
#1) Installations.
Installation Required
Create a new folder (at the place you want to keep your project).
Name that folder: node-ex-api
After creating above two files, open your terminal in the "node-ex-
api" folder and run this command:
npm install
Run Project
To test this API — Open your web browser and enter this URL
→ localhost:3000
The localhost:3000 is calling default Server Path. Which returns simple string
“node-ex-api works :-)”
We have tested the GET methods of our API in our web browser
(check #4) and seen responses. But we can’t test POST, PUT and
DELETE http methods in web browser. To test those methods we
use Postman or you may use another http utility to call APIs.
Here we use Postman. So before start click here and install Postman.
After Postman installation skip start window (if comes), then login
with Google or email/password (whichever you prefer) and finally you
must see this screen:
11.For the above application create authorized end points using JWT (JSON Web Token).
Our default endpoint returns string — we see that above. Now we’ll
create another API endpoint, that is another URL which returns some
useful data.
module.exports = router;
🌞 See below ↓↓
Register API endpoints
🌞 See below ↓↓
12.Create a react application for the student management system having registration, login,
contact, about pages and implement routing to navigate through these pages.
app.listen(PORT, () => {
console.log(`Server listening on ${PORT}`);
});
In this section, we'll build the user interface for the application
allowing users to register and sign in to an application. Users can
create an account, log in, and perform 2FA via SMS before they are
authorised to view the dashboard.
Navigate into the src/index.css file and copy the code below. It contains
all the CSS required for styling this project.
@import url("https://fonts.googleapis.com/css2?
family=Space+Grotesk:wght@300;400;500;600;700&display=swap");
*{
box-sizing: border-box;
margin: 0;
padding: 0;
font-family: "Space Grotesk", sans-serif;
}
input {
height: 45px;
padding: 10px 15px;
margin-bottom: 15px;
}
button {
width: 200px;
outline: none;
border: none;
padding: 15px;
cursor: pointer;
font-size: 16px;
}
.login__container,
.signup__container,
.verify,
.dashboard {
width: 100%;
min-height: 100vh;
padding: 50px 70px;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.login__form,
.verify__form,
.signup__form {
width: 100%;
display: flex;
flex-direction: column;
}
.loginBtn,
.signupBtn,
.codeBtn {
background-color: green;
color: #fff;
margin-bottom: 15px;
}
.signOutBtn {
background-color: #c21010;
color: #fff;
}
.link {
cursor: pointer;
color: rgb(39, 147, 39);
}
.code {
width: 50%;
text-align: center;
}
.verify__form {
align-items: center;
}
function App() {
return (
<BrowserRouter>
<Routes>
<Route path='/' element={<Login />} />
<Route path='/register' element={<Signup />} />
<Route path='/dashboard' element={<Dashboard />} />
<Route path='phone/verify' element={<PhoneVerify />} />
</Routes>
</BrowserRouter>
);
}
Copy the code below into the Login.js file. It accepts the email and
password from the user.
import React, { useState } from "react";
import { useNavigate } from "react-router-dom";
return (
<div className='login__container'>
<h2>Login </h2>
<form className='login__form' onSubmit={handleSubmit}>
<label htmlFor='email'>Email</label>
<input
type='text'
id='email'
name='email'
value={email}
required
onChange={(e) => setEmail(e.target.value)}
/>
<label htmlFor='password'>Password</label>
<input
type='password'
name='password'
id='password'
minLength={8}
required
value={password}
onChange={(e) => setPassword(e.target.value)}
/>
<button className='loginBtn'>SIGN IN</button>
<p>
Don't have an account?{" "}
<span className='link' onClick={gotoSignUpPage}>
Sign up
</span>
</p>
</form>
</div>
);
};
Copy the code below into the Signup.js file. It accepts the email,
username, telephone, and password from the user.
import React, { useState } from "react";
import { useNavigate } from "react-router-dom";
return (
<div className='signup__container'>
<h2>Sign up </h2>
<form className='signup__form' onSubmit={handleSubmit}>
<label htmlFor='email'>Email Address</label>
<input
type='email'
name='email'
id='email'
value={email}
required
onChange={(e) => setEmail(e.target.value)}
/>
<label htmlFor='username'>Username</label>
<input
type='text'
id='username'
name='username'
value={username}
required
onChange={(e) => setUsername(e.target.value)}
/>
<label htmlFor='tel'>Phone Number</label>
<input
type='tel'
name='tel'
id='tel'
value={tel}
required
onChange={(e) => setTel(e.target.value)}
/>
<label htmlFor='tel'>Password</label>
<input
type='password'
name='password'
id='password'
minLength={8}
required
value={password}
onChange={(e) => setPassword(e.target.value)}
/>
<button className='signupBtn'>SIGN UP</button>
<p>
Already have an account?{" "}
<span className='link' onClick={gotoLoginPage}>
Login
</span>
</p>
</form>
</div>
);
};
//PAGE LOAD//
//*** GET SAVED ITEMS FROM LOCAL STORAGE ***//
let savedSearchArray =
JSON.parse(localStorage.getItem('savedSearchArray'));
if (!savedSearchArray) {
savedSearchArray = [
'Columbus',
'Bend',
'Los Angeles',
'San Francisco',
'Savannah',
'New York',
'Nashville'
];
}
fetch(currentWeatherUrl).then(function (response) {
if (response.ok) {
response.json().then(function (data) {
console.log(data)
//define function to get 5 day forecast //access lat and lon from previous
function
//use one call API instead of 5 day forecast //better accessibility to needed
information
function getForecast(latitude, longitude) {
const forecastUrl = 'https://api.openweathermap.org/data/2.5/onecall?lat='
+ latitude + '&lon=' + longitude +
'&units=imperial&exclude=hourly,minutely&appid=c6a9bf78cf3b504fe7e8
382ca53765c4';
fetch(forecastUrl).then(function (response) {
if (response.ok) {
response.json().then(function (data) {
console.log(data)
//description forecast
//TODO: for loop
const desc1 = document.querySelector('#desc_1');
desc1.innerHTML = (data.daily[1].weather[0].main);
const desc2 = document.querySelector('#desc_2');
desc2.innerHTML = (data.daily[2].weather[0].main);
const desc3 = document.querySelector('#desc_3');
desc3.innerHTML = (data.daily[3].weather[0].main);
const desc4 = document.querySelector('#desc_4');
desc4.innerHTML = (data.daily[4].weather[0].main);
const desc5 = document.querySelector('#desc_5');
desc5.innerHTML = (data.daily[5].weather[0].main);
//temp forecast
//TODO for loop
// for (i = 0; i < forecast.length; i++)
const temp1 = document.querySelector('#temp_1');
temp1.innerHTML = Math.round(data.daily[1].temp.day) +
`º`;
const temp2 = document.querySelector('#temp_2');
temp2.innerHTML = Math.round(data.daily[2].temp.day) +
`º`;
const temp3 = document.querySelector('#temp_3');
temp3.innerHTML = Math.round(data.daily[3].temp.day) +
`º`;
const temp4 = document.querySelector('#temp_4');
temp4.innerHTML = Math.round(data.daily[4].temp.day) +
`º`;
const temp5 = document.querySelector('#temp_5');
temp5.innerHTML = Math.round(data.daily[5].temp.day) +
`º`;
//humidity forecast
//TODO for loop
// for (i = 0; i < forecast.length; i++)
const humid1 = document.querySelector('#humid_1');
humid1.innerHTML = (data.daily[1].humidity) + `%`;
const humid2 = document.querySelector('#humid_2');
humid2.innerHTML = (data.daily[2].humidity) + `%`;
const humid3 = document.querySelector('#humid_3');
humid3.innerHTML = (data.daily[3].humidity) + `%`;
const humid4 = document.querySelector('#humid_4');
humid4.innerHTML = (data.daily[4].humidity) + `%`;
const humid5 = document.querySelector('#humid_5');
humid5.innerHTML = (data.daily[5].humidity) + `%`;
})
}
})
};
//select each search history list item
const searchHistCon = document.querySelector('#search-history-list')
const searchedItemEl = searchHistCon.querySelectorAll('li.search-history-
item');
console.log(searchedItemEl);
})
}
}
getCurrent(userInput);
localStorage.setItem('savedSearchArray',
JSON.stringify(savedSearchArray));
});
searchHistoryMenuLi.addEventListener('click', renderSearchHistory());
getCurrent('Columbus');
Whether.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<link
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.cs
s" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFs
pd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<link rel="stylesheet"
href="https://use.fontawesome.com/releases/v5.8.1/css/all.css"
integrity="sha384-
50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhn
dOJK28anvf" crossorigin="anonymous" />
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?
family=Josefin+Sans:ital,wght@0,100;0,200;0,300;0,400;0,500;1,100;1,200
;1,300;1,400&family=Montserrat:ital,wght@0,100;0,200;0,300;0,400;0,500;
0,600;0,700;0,800;0,900;1,100;1,200;1,300&family=Noto+Sans:ital,wght@
0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300&
family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,80
0;0,900;1,100;1,200;1,300&family=Roboto:ital,wght@0,100;0,300;0,400;0,
500;0,700;0,900;1,100;1,300;1,400&family=Rubik+80s+Fade&family=Sour
ce+Sans+Pro:wght@300&display=swap" rel="stylesheet">
<link rel="stylesheet" href="assets/css/reset.css" />
<link rel="stylesheet" href="assets/css/style.css" />
<link rel="stylesheet" href="assets/css/responsive.css" />
<title>Current Weather</title>
</head>
<body>
<div class="navbar">
<!-- Dropdown menu -->
<nav class="btn-group dropend">
<button type="button" class="btn dropdown-toggle" data-bs-
toggle="dropdown" aria-expanded="false"></button>
<ul class="dropdown-menu" id="popout-menu">
<div class="hidden">
<div class="" id="current-humid"></div>
<div class="" id="current_wind">Wind Speed: </div>
<div class="" id="current_uv">UV Index: </div>
</div>
</div>
<div class="forecast-card">
<div class="day" id="date_1"></div>
<div class="temperature" id="temp_1"></div>
<div class="description" id="desc_1"></div>
<img class="weather-icon" alt="weather-icon"
id="icon1"></img>
</div>
<div class="forecast-card">
</div>
<div class="forecast-card">
</div>
<div class="forecast-card">
</div>
<div class="forecast-card">
</div>
</div>
<div class="text-muted container" id="city-name">Search a
City</div>
</main>
<script
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.m
in.js" integrity="sha384-
MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcX
n/tWtIaxVXM" crossorigin="anonymous"></script>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></
script>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js
"></script>
<script src="assets/script.js"></script>
</body>
</html>
14.Create a TODO application in react with necessary components and
deploy it into github.
<!DOCTYPE
html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See
https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the
build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>Todo List</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
App.js file:-
import
React
from
"react";
import "./App.css";
import { Button, Card, Form } from 'react-bootstrap';
import 'bootstrap/dist/css/bootstrap.min.css';
>
<span style={{ textDecoration: todo.isDone ? "line-through" :
"" }}>{todo.text}</span>
<div>
<Button variant="outline-success" onClick={() =>
markTodo(index)}>✓</Button>{' '}
<Button variant="outline-danger" onClick={() =>
removeTodo(index)}>✕</Button>
</div>
</div>
);
}
return (
<Form onSubmit={handleSubmit}>
<Form.Group>
<Form.Label><b>Add Todo</b></Form.Label>
<Form.Control type="text" className="input" value={value} onChange={e =>
setValue(e.target.value)} placeholder="Add new todo" />
</Form.Group>
<Button variant="primary mb-3" type="submit">
Submit
</Button>
</Form>
);
}
function App() {
const [todos, setTodos] = React.useState([
{
text: "This is a sampe todo",
isDone: false
}
]);
return (
<div className="app">
<div className="container">
<h1 className="text-center mb-4">Todo List</h1>
<FormTodo addTodo={addTodo} />
<div>
{todos.map((todo, index) => (
<Card>
<Card.Body>
<Todo
key={index}
index={index}
todo={todo}
markTodo={markTodo}
removeTodo={removeTodo}
/>
</Card.Body>
</Card>
))}
</div>
</div>
</div>
);
}
export default App;
Prerequisites
1. Firstly create a React application in your system using the command given below.
We are giving the name “react-deploy” to this application. This is the app you will
deploy to GitHub Pages. This process will create a new folder named “react-deploy”
in your directory.
$ create-react-app react-deploy
2. Now enter your new application and run the following command to start the
application. You will see your application is running on a local development
server http://localhost:3000.
#change directory
$ cd react-deploy
#run application in the development environment
$ npm start
3. After checking that your application runs perfectly without any error on a local
server, create a new repository on GitHub. We are giving this name “my-app” which is
different from the application name you have created in the previous step. However,
you can also choose the same name i.e. “react-deploy” for your GitHub repository
name. It’s totally up to you.
"scripts": {
//...
"predeploy": "npm run build",
"deploy": "gh-pages -d build",
//...
"build": "react-scripts build && cp build/index.html
build/404.html", // this will prevent page reloads to give a 404
error
}
Once the above thing is done your file package.json will look something like this…
Next, if you are using the Router from react-router-dom then you need to change the
Browser router tags to
//...
BrowserRouter basename={process.env.PUBLIC_URL}
//...
6. In this step create a git repository in the app’s folder and add the GitHub repository
as a “remote” in your local git repository. This will make it so the gh-pages package
knows where you want it to deploy your app in step 7. It will also make it so git knows
where you want it to push your source code (i.e. the commits on your master branch)
in step 8.
#create a new git repository
$ git init
#add remote repository
$ git remote add origin https://github.com/anuupadhyay/my-app.git
7. Now here is the magic. Follow the command below and generate a production build
of your app, to deploy your code on GitHub pages.
#deploy application
$ npm run deploy
That’s it. Your React application is published on GitHub pages and if you want to
verify it just go to the settings tab of your application in your Github repository and
scroll down. You will see something like below…