38 Commits

Author SHA1 Message Date
Mohammed Ashab Uddin
768f2a596a update 2020-08-20 21:03:28 +04:00
Mohammed Ashab Uddin
c973b988c6 updated readme 2020-08-20 21:00:58 +04:00
Mohammed Ashab Uddin
150a211373 redone user 2020-08-20 20:21:00 +04:00
Mohammed Ashab Uddin
836e9ff128 added Contributers name 2020-08-20 20:19:47 +04:00
Mohammed Ashab Uddin
3e13b37224 Merge branch 'master' of github.com:HWTechClub/Custom-Static-Website-Generator 2020-08-20 20:16:59 +04:00
Mohammed Ashab Uddin
8c0a3a9f9c messages has been updated 2020-08-20 20:14:47 +04:00
Akilan Selvacoumar
b8eb4811fe Update README.md 2020-08-19 11:36:39 +04:00
Akilan
7baf3aa0fa updated README.md file 2020-08-19 11:31:59 +04:00
Akilan
736751afd3 fixed template bugs 2020-08-19 09:05:33 +04:00
Mohammed Ashab Uddin
7c5e343919 documented command.js 2020-08-15 11:17:23 +04:00
Mohammed Ashab Uddin
336470060c template has been added 2020-08-11 12:01:30 +04:00
Mohammed Ashab Uddin
5967fbc35e added csv columns 2020-08-11 11:41:37 +04:00
ashab272000
afe893c1a3 Merge pull request #11 from HWTechClub/newChanges
New changes
2020-08-07 09:20:39 +04:00
Mohammed Ashab Uddin
65c76ac732 able to save images 2020-08-07 09:15:21 +04:00
Mohammed Ashab Uddin
c5329eda93 modified onGetInfo to display images 2020-08-06 14:09:51 +04:00
Mohammed Ashab Uddin
54d3e68d87 modified to use images 2020-08-06 14:07:52 +04:00
Mohammed Ashab Uddin
117e0949d6 added common-tags 2020-08-06 14:07:28 +04:00
Mohammed Ashab Uddin
574b568f94 added base64 decoding method 2020-08-06 13:05:43 +04:00
Mohammed Ashab Uddin
e4df23516f getInput needs await and message as parameter 2020-08-06 13:05:02 +04:00
Mohammed Ashab Uddin
75073e5e03 commands can now get media as input 2020-08-06 13:03:28 +04:00
Mohammed Ashab Uddin
8c12bffb8d Merge branch 'master' of github.com:HWTechClub/Custom-Static-Website-Generator 2020-08-05 12:09:01 +04:00
Mohammed Ashab Uddin
8870677027 fixed getSelectedproduct and website 2020-08-05 12:07:40 +04:00
Mohammed Ashab Uddin
678da0d8cf used the _getInputMessage() 2020-08-05 12:07:22 +04:00
Mohammed Ashab Uddin
3bb0dbd2a4 accepts message with "" 2020-08-03 10:54:48 +04:00
Akilan
d1a38ba1f5 added new route for website generator 2020-08-02 14:14:07 +04:00
ashab272000
758c284787 Merge pull request #10 from HWTechClub/pr9
completed all the commands and functions
2020-07-31 16:05:30 +04:00
ashab272000
46a18489a0 Merge branch 'master' into pr9 2020-07-31 16:05:15 +04:00
ashab272000
e5d1a0096e Merge pull request #9 from pr16-hash/master
website details
2020-07-31 16:03:47 +04:00
Mohammed Ashab Uddin
fc2d0b6e07 merged 2020-07-31 15:55:54 +04:00
Mohammed Ashab Uddin
46aff50616 completed all the commands and functions 2020-07-31 15:46:05 +04:00
Mohammed Ashab Uddin
d0655737f1 structured the logic.js 2020-07-30 11:27:37 +04:00
Mohammed Ashab Uddin
e936c4d312 added selection methods 2020-07-30 09:29:19 +04:00
Mohammed Ashab Uddin
3bf8cf6d03 added selection methods 2020-07-30 09:29:02 +04:00
Preeti Rawat
e4cffc7282 website(II)
website (II) with documentation
2020-07-29 22:29:04 +04:00
ashab272000
09dc41d685 Merge pull request #8 from Baber-Jan/master
Added all the product methods,
2020-07-28 11:01:05 +04:00
Preeti Rawat
9e358e1c24 condition
added condition-1
2020-07-26 17:29:59 +04:00
Preeti Rawat
dc8c28305f just comments
firstname,lastname,logourl,companyname, help are sending comments
2020-07-25 22:26:25 +04:00
Preeti Rawat
6566ba30a0 testing1
create companu_name
2020-07-25 14:04:29 +04:00
22 changed files with 1157 additions and 333 deletions

12
.gitignore vendored
View File

@@ -64,3 +64,15 @@ typings/
#session whatsappwebjs json file #session whatsappwebjs json file
whatsapp-web.js/session.json whatsapp-web.js/session.json
# ignore file in the generated website section
website-generator/public/pages/*
# ignore ejs.html files
website-generator/public/templates/*/*.ejs.html
# Not IPFS file in the direcotry
!website-generator/public/pages/ipfs-deploy.sh

View File

@@ -50,5 +50,12 @@ You need to start both website-generator and whatsapp-bot.
### Contributors ### Contributors
1. Akilan Selvacoumar : as251@hw.ac.uk 1. Akilan Selvacoumar: akilan@hwtech.club (https://akilan.io)
2. Gaurav Gosain : gg68@hw.ac.uk 2. Mohammed Ashab Uddin : https://ashab272000.github.io/dist/
3. Baber Jan
4. Preeti Rawat
5. Gaurav Gosain: gg68@hw.ac.uk
6. Nicole Tobe: https://github.com/tobenxe
7. Humaid AlQassimi: me@humaidq.ae(https://humaidq.ae)
(Website generator based on: https://humaidq.ae/projects/shopsheet/)

View File

@@ -24,8 +24,6 @@ exports.generate = function (req, res) {
//we can now manipulate the data //we can now manipulate the data
let result = req.body.companyName; let result = req.body.companyName;
//console.log(req.body);
let dir = './public/pages/' + req.body.companyName; let dir = './public/pages/' + req.body.companyName;
if (!fs.existsSync(dir)) { if (!fs.existsSync(dir)) {
@@ -52,7 +50,7 @@ exports.generate = function (req, res) {
let templateContent = JSON.parse(template); let templateContent = JSON.parse(template);
for (var i = 0; i < templateContent.templates.length; i++) { for (var i = 0; i < templateContent.templates.length; i++) {
if (templateContent.templates[i].template_name == "Colo_Shop") { if (templateContent.templates[i].template_name == req.body.template) {
for (var j = 0; j < templateContent.templates[i].pages.length; j++) { for (var j = 0; j < templateContent.templates[i].pages.length; j++) {
//Copying html files can be removed in the future stages //Copying html files can be removed in the future stages
@@ -67,18 +65,6 @@ exports.generate = function (req, res) {
} }
} }
/*fs.createReadStream('./public/Colo_Shop/index.html').pipe(fs.createWriteStream(dir + '/index.html'));
fs.createReadStream('./public/Colo_Shop/cart.html').pipe(fs.createWriteStream(dir + '/cart.html'));
fs.createReadStream('./public/Colo_Shop/contact.html').pipe(fs.createWriteStream(dir + '/contact.html'));
copy_folder('./public/Colo_Shop/styles', dir + '/styles');
copy_folder('./public/Colo_Shop/js', dir + '/js');
copy_folder('./public/Colo_Shop/plugins', dir + '/plugins');
copy_folder('./public/Colo_Shop/images', dir + '/images');
ejs2html('./public/Colo_Shop/index.ejs', req.body , dir, "index");
ejs2html('./public/Colo_Shop/cart.ejs', req.body , dir, "cart");
ejs2html('./public/Colo_Shop/contact.ejs', req.body , dir, "contact");*/
const resp = { const resp = {
'directory': result 'directory': result
@@ -112,12 +98,10 @@ exports.deploy_ipfs = function (req, res) {
} }
exports.convertCsv = function (req, res, next) { exports.convertCsv = function (req, res, next) {
console.log(req.body);
const csvStr = req.body.csv; const csvStr = req.body.csv;
csv() csv()
.fromString(csvStr) .fromString(csvStr)
.then((jsonObj) => { .then((jsonObj) => {
console.log(jsonObj)
req.body.csv = jsonObj; req.body.csv = jsonObj;
//delete file at path //delete file at path
next() next()

View File

@@ -8,6 +8,8 @@ module.exports = function (app){
// generate site // generate site
app.post('/generate',home.convertCsv, home.generate); app.post('/generate',home.convertCsv, home.generate);
app.post('/generate_with_json_data', home.generate);
app.get('/template_info',home.template_info); app.get('/template_info',home.template_info);
app.get('/ipfsdeploy', home.deploy_ipfs); app.get('/ipfsdeploy', home.deploy_ipfs);

View File

@@ -117,9 +117,9 @@
<div class="hamburger_close"><i class="fa fa-times" aria-hidden="true"></i></div> <div class="hamburger_close"><i class="fa fa-times" aria-hidden="true"></i></div>
<div class="hamburger_menu_content text-right"> <div class="hamburger_menu_content text-right">
<ul class="menu_top_nav"> <ul class="menu_top_nav">
<li class="menu_item"><a href="#">home</a></li> <li class="menu_item"><a href="index.html">home</a></li>
<li class="menu_item"><a href="#">cart</a></li> <li class="menu_item"><a href="cart.html">cart</a></li>
<li class="menu_item"><a href="#">contact</a></li> <li class="menu_item"><a href="contact.html">contact</a></li>
</ul> </ul>
</div> </div>
</div> </div>

View File

@@ -2,7 +2,7 @@
<html lang="en"> <html lang="en">
<head> <head>
<title>Heriot-Watt</title> <title>Test123</title>
<meta charset="utf-8"> <meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="description" content="Colo Shop Template"> <meta name="description" content="Colo Shop Template">
@@ -86,7 +86,7 @@
<div class="row"> <div class="row">
<div class="col-lg-12 text-right"> <div class="col-lg-12 text-right">
<div class="logo_container"> <div class="logo_container">
<a href="#"><img src="https://www.google.com/url?sa=i&amp;url=https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FHeriot-Watt_University&amp;psig=AOvVaw2fm-eoyZxj8ZIUEULdjZ5_&amp;ust=1589820225686000&amp;source=images&amp;cd=vfe&amp;ved=0CAIQjRxqFwoTCJj1i4Osu-kCFQAAAAAdAAAAABAD" class="img-fluid" style="height:5rem;" /></a> <a href="#"><img src="https://hwtech.club/images/output-onlinepngtools.png" class="img-fluid" style="height:5rem;" /></a>
</div> </div>
<nav class="navbar"> <nav class="navbar">
<ul class="navbar_menu"> <ul class="navbar_menu">
@@ -117,9 +117,9 @@
<div class="hamburger_close"><i class="fa fa-times" aria-hidden="true"></i></div> <div class="hamburger_close"><i class="fa fa-times" aria-hidden="true"></i></div>
<div class="hamburger_menu_content text-right"> <div class="hamburger_menu_content text-right">
<ul class="menu_top_nav"> <ul class="menu_top_nav">
<li class="menu_item"><a href="#">home</a></li> <li class="menu_item"><a href="index.html">home</a></li>
<li class="menu_item"><a href="#">cart</a></li> <li class="menu_item"><a href="cart.html">cart</a></li>
<li class="menu_item"><a href="#">contact</a></li> <li class="menu_item"><a href="contact.html">contact</a></li>
</ul> </ul>
</div> </div>
</div> </div>
@@ -289,19 +289,19 @@
<script> <script>
$(document).ready(function () { $(document).ready(function () {
if (localStorage.getItem('Heriot-Watt') === null) { if (localStorage.getItem('Test123_50') === null) {
console.log("here"); console.log("here");
var arr = new Array(); var arr = new Array();
localStorage.setItem('Heriot-Watt', JSON.stringify(arr)); localStorage.setItem('Test123_50', JSON.stringify(arr));
} }
var arr_json = JSON.parse(localStorage.getItem('Heriot-Watt')); var arr_json = JSON.parse(localStorage.getItem('Test123_50'));
$("#checkout_items").html(arr_json.length); $("#checkout_items").html(arr_json.length);
console.log(arr_json.length); console.log(arr_json.length);
var arr_json = JSON.parse(localStorage.getItem('Heriot-Watt')); var arr_json = JSON.parse(localStorage.getItem('Test123_50'));
$("#table").html(""); $("#table").html("");
var receipt = "<textarea name=\"purchases\">"; var receipt = "<textarea name=\"purchases\">";
var sum = 0; var sum = 0;
@@ -333,12 +333,12 @@
function delete_item(id) { function delete_item(id) {
$("#table").html(""); $("#table").html("");
var arr_json = JSON.parse(localStorage.getItem('Heriot-Watt')); var arr_json = JSON.parse(localStorage.getItem('Test123_50'));
if (id > -1) { if (id > -1) {
arr_json.splice(id, 1); arr_json.splice(id, 1);
} }
console.log(id); console.log(id);
localStorage.setItem('Heriot-Watt', JSON.stringify(arr_json)); localStorage.setItem('Test123_50', JSON.stringify(arr_json));
console.log(arr_json.length); console.log(arr_json.length);
var receipt = "<textarea name=\"purchases\">"; var receipt = "<textarea name=\"purchases\">";
var sum = 0; var sum = 0;

View File

@@ -100,7 +100,7 @@
<li class="checkout"> <li class="checkout">
<a href="cart.html"> <a href="cart.html">
<i class="fa fa-shopping-cart" aria-hidden="true"></i> <i class="fa fa-shopping-cart" aria-hidden="true"></i>
<span id="checkout_items" class="checkout_items">2</span> <span id="checkout_items" class="checkout_items">0</span>
</a> </a>
</li> </li>
</ul> </ul>
@@ -115,6 +115,18 @@
</header> </header>
<div class="fs_menu_overlay"></div>
<div class="hamburger_menu">
<div class="hamburger_close"><i class="fa fa-times" aria-hidden="true"></i></div>
<div class="hamburger_menu_content text-right">
<ul class="menu_top_nav">
<li class="menu_item"><a href="index.html">home</a></li>
<li class="menu_item"><a href="cart.html">cart</a></li>
<li class="menu_item"><a href="#">contact</a></li>
</ul>
</div>
</div>
<div class="container contact_container"> <div class="container contact_container">
<div class="row"> <div class="row">
<div class="col"> <div class="col">

View File

@@ -2,7 +2,7 @@
<html lang="en"> <html lang="en">
<head> <head>
<title>Heriot-Watt</title> <title>Test123</title>
<meta charset="utf-8"> <meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="description" content="Colo Shop Template"> <meta name="description" content="Colo Shop Template">
@@ -89,7 +89,7 @@
<div class="row"> <div class="row">
<div class="col-lg-12 text-right"> <div class="col-lg-12 text-right">
<div class="logo_container"> <div class="logo_container">
<a href="#"><img src="https://www.google.com/url?sa=i&amp;url=https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FHeriot-Watt_University&amp;psig=AOvVaw2fm-eoyZxj8ZIUEULdjZ5_&amp;ust=1589820225686000&amp;source=images&amp;cd=vfe&amp;ved=0CAIQjRxqFwoTCJj1i4Osu-kCFQAAAAAdAAAAABAD" class="img-fluid" style="height:5rem;" /></a> <a href="#"><img src="https://hwtech.club/images/output-onlinepngtools.png" class="img-fluid" style="height:5rem;" /></a>
</div> </div>
<nav class="navbar"> <nav class="navbar">
<ul class="navbar_menu"> <ul class="navbar_menu">
@@ -100,7 +100,7 @@
<li class="checkout"> <li class="checkout">
<a href="cart.html"> <a href="cart.html">
<i class="fa fa-shopping-cart" aria-hidden="true"></i> <i class="fa fa-shopping-cart" aria-hidden="true"></i>
<span id="checkout_items" class="checkout_items">2</span> <span id="checkout_items" class="checkout_items">0</span>
</a> </a>
</li> </li>
</ul> </ul>
@@ -115,6 +115,18 @@
</header> </header>
<div class="fs_menu_overlay"></div>
<div class="hamburger_menu">
<div class="hamburger_close"><i class="fa fa-times" aria-hidden="true"></i></div>
<div class="hamburger_menu_content text-right">
<ul class="menu_top_nav">
<li class="menu_item"><a href="index.html">home</a></li>
<li class="menu_item"><a href="cart.html">cart</a></li>
<li class="menu_item"><a href="#">contact</a></li>
</ul>
</div>
</div>
<div class="container contact_container"> <div class="container contact_container">
<div class="row"> <div class="row">
<div class="col"> <div class="col">
@@ -279,13 +291,13 @@
<script> <script>
$(document).ready(function () { $(document).ready(function () {
if (localStorage.getItem('Heriot-Watt') === null) { if (localStorage.getItem('Test123_50') === null) {
console.log("here"); console.log("here");
var arr = new Array(); var arr = new Array();
localStorage.setItem('Heriot-Watt', JSON.stringify(arr)); localStorage.setItem('Test123_50', JSON.stringify(arr));
} }
var arr_json = JSON.parse(localStorage.getItem('Heriot-Watt')); var arr_json = JSON.parse(localStorage.getItem('Test123_50'));
$("#checkout_items").html(arr_json.length); $("#checkout_items").html(arr_json.length);
console.log(arr_json.length); console.log(arr_json.length);

View File

@@ -120,8 +120,8 @@
<div class="hamburger_menu_content text-right"> <div class="hamburger_menu_content text-right">
<ul class="menu_top_nav"> <ul class="menu_top_nav">
<li class="menu_item"><a href="#">home</a></li> <li class="menu_item"><a href="#">home</a></li>
<li class="menu_item"><a href="#">cart</a></li> <li class="menu_item"><a href="cart.html">cart</a></li>
<li class="menu_item"><a href="#">contact</a></li> <li class="menu_item"><a href="contact.html">contact</a></li>
</ul> </ul>
</div> </div>
</div> </div>
@@ -145,18 +145,15 @@
<div class="col text-center"> <div class="col text-center">
<div class="section_title new_arrivals_title"> <div class="section_title new_arrivals_title">
<h2>Our Products</h2> <h2>Our Products</h2>
<p><%= description %></p>
</div> </div>
</div> </div>
</div> </div>
<!---<div class="row align-items-center"> <!---<div class="row align-items-center">
<div class="col text-center"> <div class="col text-center">
<div class="new_arrivals_sorting"> <div class="new_arrivals_sorting">
<ul class="arrivals_grid_sorting clearfix button-group filters-button-group"> <ul class="arrivals_grid_sorting clearfix button-group filters-button-group">
<li class="grid_sorting_button button d-flex flex-column justify-content-center align-items-center active is-checked" data-filter="*">all</li> <li class="grid_sorting_button button d-flex flex-column justify-content-center align-items-center active is-checked" data-filter="*">all</li>
<li class="grid_sorting_button button d-flex flex-column justify-content-center align-items-center" data-filter=".women">women's</li>
<li class="grid_sorting_button button d-flex flex-column justify-content-center align-items-center" data-filter=".accessories">accessories</li>
<li class="grid_sorting_button button d-flex flex-column justify-content-center align-items-center" data-filter=".men">men's</li>
</ul> </ul>
</div> </div>
</div> </div>
@@ -168,20 +165,21 @@
<!-- Product 3 --> <!-- Product 3 -->
<% for(var i = 0; i < csv.length ; i++) {%> <% for(var i = 0; i < csv.length ; i++) {%>
<div class="product-item women"> <div class="product-item *">
<div class="product product_filter"> <div class="product product_filter">
<div class="product_image"> <div class="product_image">
<img src="<%= csv[i]['product image url'] %>" alt=""> <img src="<%= csv[i]['product image url'] %>" alt="">
</div> </div>
<div class="favorite"></div>
<div class="product_info"> <div class="product_info">
<h6 class="product_name"><a href="#"><a><%= csv[i]["product name"] %></a></h6> <h6 class="product_name"><a href="#"><a><%= csv[i]["product name"] %></a></h6>
<p><%= csv[i]["description"] %></p>
<div class="product_price">$<%= csv[i].cost %></div> <div class="product_price">$<%= csv[i].cost %></div>
</div> </div>
<br>
<div class="cart"><div class="red_button add_to_cart_button"><a onClick="additem('<%= csv[i]['product name'] %>', <%= csv[i].cost %>)" style="color:white">Add to cart</a></div></div>
</div> </div>
<div class="red_button add_to_cart_button"><a onClick="additem('<%= csv[i]['product name'] %>', <%= csv[i].cost %>)" style="color:white">Add to cart</a></div>
</div> </div>
<% } %> <% } %>
</div> </div>
</div> </div>
@@ -190,24 +188,37 @@
</div> </div>
<br> <br>
<br> <br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<!-- Footer -->
<footer class="footer">
<!-- Footer --> <div class="container">
<div class="row">
<footer class="footer"> <div class="col-lg-12">
<div class="container"> <div class="footer_nav_container">
<div class="row"> <div class="cr">©2018 All Rights Reserverd. This template is made with <i
<div class="col-lg-12"> class="fa fa-heart-o" aria-hidden="true"></i> by <a href="#">Colorlib</a></div>
<div class="footer_nav_container">
<div class="cr">©2018 All Rights Reserverd. This template is made with <i
class="fa fa-heart-o" aria-hidden="true"></i> by <a href="#">Colorlib</a></div>
</div>
</div> </div>
</div> </div>
</div> </div>
</footer> </div>
</footer>
</div> </div>
<script src="js/jquery-3.2.1.min.js"></script> <script src="js/jquery-3.2.1.min.js"></script>
<script src="styles/bootstrap4/popper.js"></script> <script src="styles/bootstrap4/popper.js"></script>

View File

@@ -2,7 +2,7 @@
<html lang="en"> <html lang="en">
<head> <head>
<title>Heriot-Watt</title> <title>Test123</title>
<meta charset="utf-8"> <meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="description" content="Colo Shop Template"> <meta name="description" content="Colo Shop Template">
@@ -87,7 +87,7 @@
<div class="col-lg-12 text-right"> <div class="col-lg-12 text-right">
<div class="logo_container"> <div class="logo_container">
<a href="#"><img <a href="#"><img
src="https://www.google.com/url?sa=i&amp;url=https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FHeriot-Watt_University&amp;psig=AOvVaw2fm-eoyZxj8ZIUEULdjZ5_&amp;ust=1589820225686000&amp;source=images&amp;cd=vfe&amp;ved=0CAIQjRxqFwoTCJj1i4Osu-kCFQAAAAAdAAAAABAD" src="https://hwtech.club/images/output-onlinepngtools.png"
class="img-fluid" style="height:5rem;" /></a> class="img-fluid" style="height:5rem;" /></a>
</div> </div>
<nav class="navbar"> <nav class="navbar">
@@ -120,8 +120,8 @@
<div class="hamburger_menu_content text-right"> <div class="hamburger_menu_content text-right">
<ul class="menu_top_nav"> <ul class="menu_top_nav">
<li class="menu_item"><a href="#">home</a></li> <li class="menu_item"><a href="#">home</a></li>
<li class="menu_item"><a href="#">cart</a></li> <li class="menu_item"><a href="cart.html">cart</a></li>
<li class="menu_item"><a href="#">contact</a></li> <li class="menu_item"><a href="contact.html">contact</a></li>
</ul> </ul>
</div> </div>
</div> </div>
@@ -129,7 +129,7 @@
<!-- Slider --> <!-- Slider -->
<div class="main_slider" <div class="main_slider"
style="background-image:url('https://ichef.bbci.co.uk/news/1024/cpsprodpb/E13E/production/_109726675_hwudubaineviewonline.jpg')"> style="background-image:url('https://i.ytimg.com/vi/SIQHKaMOCbU/maxresdefault.jpg')">
<div class="container fill_height"> <div class="container fill_height">
<div class="row align-items-center fill_height"> <div class="row align-items-center fill_height">
@@ -145,18 +145,15 @@
<div class="col text-center"> <div class="col text-center">
<div class="section_title new_arrivals_title"> <div class="section_title new_arrivals_title">
<h2>Our Products</h2> <h2>Our Products</h2>
<p>Loldfsdf sdfsdsdsfsd sd fsdrs d sdf </p>
</div> </div>
</div> </div>
</div> </div>
<!---<div class="row align-items-center"> <!---<div class="row align-items-center">
<div class="col text-center"> <div class="col text-center">
<div class="new_arrivals_sorting"> <div class="new_arrivals_sorting">
<ul class="arrivals_grid_sorting clearfix button-group filters-button-group"> <ul class="arrivals_grid_sorting clearfix button-group filters-button-group">
<li class="grid_sorting_button button d-flex flex-column justify-content-center align-items-center active is-checked" data-filter="*">all</li> <li class="grid_sorting_button button d-flex flex-column justify-content-center align-items-center active is-checked" data-filter="*">all</li>
<li class="grid_sorting_button button d-flex flex-column justify-content-center align-items-center" data-filter=".women">women's</li>
<li class="grid_sorting_button button d-flex flex-column justify-content-center align-items-center" data-filter=".accessories">accessories</li>
<li class="grid_sorting_button button d-flex flex-column justify-content-center align-items-center" data-filter=".men">men's</li>
</ul> </ul>
</div> </div>
</div> </div>
@@ -168,20 +165,36 @@
<!-- Product 3 --> <!-- Product 3 -->
<div class="product-item women"> <div class="product-item *">
<div class="product product_filter"> <div class="product product_filter">
<div class="product_image"> <div class="product_image">
<img src="https://www.raspberrypi.org/homepage-9df4b/static/hero-shot-33d83b8c5fa0933373dabcc9462b32a3.png" alt=""> <img src="https://i.stack.imgur.com/WxVXe.jpg" alt="">
</div> </div>
<div class="favorite"></div>
<div class="product_info"> <div class="product_info">
<h6 class="product_name"><a href="#"><a>Raspberry Pi</a></h6> <h6 class="product_name"><a href="#"><a>java</a></h6>
<div class="product_price">$400</div> <p>We all love java fsdf sdf&#39; sd&#39;f &#39;sdf sfsdf sdf sdf</p>
<div class="product_price">$130</div>
</div> </div>
<br>
<div class="cart"><div class="red_button add_to_cart_button"><a onClick="additem('java', 130)" style="color:white">Add to cart</a></div></div>
</div> </div>
<div class="red_button add_to_cart_button"><a onClick="additem('Raspberry Pi', 400)" style="color:white">Add to cart</a></div>
</div> </div>
<div class="product-item *">
<div class="product product_filter">
<div class="product_image">
<img src="https://images-na.ssl-images-amazon.com/images/I/41IlAcQj9nL.jpg" alt="">
</div>
<div class="product_info">
<h6 class="product_name"><a href="#"><a>C</a></h6>
<p>C lord it is</p>
<div class="product_price">$200</div>
</div>
<br>
<div class="cart"><div class="red_button add_to_cart_button"><a onClick="additem('C', 200)" style="color:white">Add to cart</a></div></div>
</div>
</div>
</div> </div>
</div> </div>
@@ -190,24 +203,37 @@
</div> </div>
<br> <br>
<br> <br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<!-- Footer -->
<footer class="footer">
<!-- Footer --> <div class="container">
<div class="row">
<footer class="footer"> <div class="col-lg-12">
<div class="container"> <div class="footer_nav_container">
<div class="row"> <div class="cr">©2018 All Rights Reserverd. This template is made with <i
<div class="col-lg-12"> class="fa fa-heart-o" aria-hidden="true"></i> by <a href="#">Colorlib</a></div>
<div class="footer_nav_container">
<div class="cr">©2018 All Rights Reserverd. This template is made with <i
class="fa fa-heart-o" aria-hidden="true"></i> by <a href="#">Colorlib</a></div>
</div>
</div> </div>
</div> </div>
</div> </div>
</footer> </div>
</footer>
</div> </div>
<script src="js/jquery-3.2.1.min.js"></script> <script src="js/jquery-3.2.1.min.js"></script>
<script src="styles/bootstrap4/popper.js"></script> <script src="styles/bootstrap4/popper.js"></script>
@@ -220,13 +246,13 @@
<script> <script>
$(document).ready(function () { $(document).ready(function () {
if (localStorage.getItem('Heriot-Watt') === null) { if (localStorage.getItem('Test123_50') === null) {
console.log("here"); console.log("here");
var arr = new Array(); var arr = new Array();
localStorage.setItem('Heriot-Watt', JSON.stringify(arr)); localStorage.setItem('Test123_50', JSON.stringify(arr));
} }
var arr_json = JSON.parse(localStorage.getItem('Heriot-Watt')); var arr_json = JSON.parse(localStorage.getItem('Test123_50'));
$("#checkout_items").html(arr_json.length); $("#checkout_items").html(arr_json.length);
console.log(arr_json.length); console.log(arr_json.length);
@@ -235,11 +261,11 @@
function additem(name, price) { function additem(name, price) {
var data = { 'name': name, 'price': price }; var data = { 'name': name, 'price': price };
var arr_json = JSON.parse(localStorage.getItem('Heriot-Watt')); var arr_json = JSON.parse(localStorage.getItem('Test123_50'));
console.log(typeof (arr_json)); console.log(typeof (arr_json));
arr_json.push(data); arr_json.push(data);
localStorage.setItem('Heriot-Watt', JSON.stringify(arr_json)); localStorage.setItem('Test123_50', JSON.stringify(arr_json));
console.log(JSON.parse(localStorage.getItem('Heriot-Watt'))); console.log(JSON.parse(localStorage.getItem('Test123_50')));
$('#checkout_items').html(arr_json.length); $('#checkout_items').html(arr_json.length);
} }
</script> </script>

View File

@@ -1031,14 +1031,11 @@ section
} }
.product-item:hover::after .product-item:hover::after
{ {
box-shadow: 0 25px 29px rgba(63, 78, 100, 0.15);
border: solid 2px rgba(235,235,235,1);
} }
.product .product
{ {
width: 100%; width: 100%;
height: 340px; height: 340px;
border-right: solid 1px #e9e9e9;
} }
.product_image .product_image
{ {

View File

@@ -334,6 +334,11 @@
"delayed-stream": "~1.0.0" "delayed-stream": "~1.0.0"
} }
}, },
"common-tags": {
"version": "1.8.0",
"resolved": "https://registry.npmjs.org/common-tags/-/common-tags-1.8.0.tgz",
"integrity": "sha512-6P6g0uetGpW/sdyUy/iQQCbFF0kWVMSIVSyYz7Zgjcgh8mgw8PQzDNZeyZ5DQ2gM7LBoZPHmnjz8rUthkBG5tw=="
},
"concat-map": { "concat-map": {
"version": "0.0.1", "version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",

View File

@@ -5,12 +5,13 @@
"main": "test.js", "main": "test.js",
"scripts": { "scripts": {
"test-web": "node website_test.js http://localhost:8004", "test-web": "node website_test.js http://localhost:8004",
"test" : "mocha", "test": "mocha",
"start": "node index.js" "start": "node index.js"
}, },
"author": "", "author": "",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"common-tags": "^1.8.0",
"request": "^2.88.2", "request": "^2.88.2",
"whatsapp-web.js": "^1.7.0" "whatsapp-web.js": "^1.7.0"
}, },

View File

@@ -1,44 +1,628 @@
const { Website } = require("../models/website"); const { Website } = require("../models/website");
const { data } = require("../models/data"); const { data } = require("../models/data");
const { Product } = require('../models/product'); const { Product } = require('../models/product');
const { User } = require('../models/user');
const fs = require('fs');
const request = require('request');
const {stripIndents} = require('common-tags');
/**
* user to be sent the message to
* @type { User }
*/
let user = null;
/**
* input to be used in the function if exists
* @type {string}
*/
let input = null;
const base64_decode = async (base64str, file) => {
var bitmap = await Buffer.from(base64str, 'base64');
await fs.writeFileSync(file, bitmap);
console.log('****** File created from base64 encoded string ******');
module.exports.onWG = () => {
console.log('hello world');
} }
module.exports.onCreate = (id, companyName) => {
//get the user const saveImage = async (messageMedia, fileName) => {
let user = data.getUser(id); let file = `../website-generator/public/images/${fileName}.jpg`;
if(user == undefined) await base64_decode(messageMedia.data, file);
return file;
}
const addProduct = (id) => {
// Create a product and select it.
//At this point all the product properties will be default
var product = new Product({id : id});
// Add a product to the selected website.
user.getSelectedWebsite().addProduct(product);
}
const check = ({checkFunction, callback}) => {
let checkValue = checkFunction();
//if check value is false
if(checkValue == '')
{ {
data.addUser(id); return callback();
user = data.getUser(id);
} }
//add the website with the company name return checkValue;
user.addWebsite(new Website(companyName));
} }
module.exports.addProduct = (id,website) => {
if(id==null) const checkMediaExist = () => {
if(input['media'] == undefined){
return [
`A media should be attached with the message`,
`Please attach an image or file with the caption being the command`
];
}
return '';
}
const checkSelectedWebsiteExist= () => {
if(user.getSelectedWebsite() == null)
{ {
// Setting up the product id if not given return [
id = Math.floor((Math.random() * 100000) + 1); `A website should be selected or created `,
while(website.products.isData(id))// This is will check if the generated id is already used `To create website, please use the following command : `,
{ `*wg create <company-name>*`,
id = Math.floor((Math.random() * 100000) + 1); ];
}
return '';
}
const checkSelectedProductExist = () => {
return check({
checkFunction : checkSelectedWebsiteExist,
callback : () => {
if(user.getSelectedWebsite().getSelectedProduct() == null)
{
return [
`A product should be created or selected`
]
}
return '';
} }
});
}
module.exports.setUser = (id) =>{
if(!data.isUser(id))
{
data.addUser(new User(id));
}
user = data.getUser(id)
};
module.exports.setInput= (value) => {
input = value;
}
module.exports.onCreateProduct = () => {
return check({
checkFunction : checkSelectedWebsiteExist,
callback : () => {
//add the product
addProduct(input['id']);
let selectedId = user.getSelectedWebsite().getSelectedProduct().id;
//mesage to be sent to the user
let message = [
`The product has been created with the id : ${selectedId}` ,
//use stripIndents to strip the indentation
stripIndents`
This product has been selected.
Now you can make change to the product with the following commands :
1. wg product info
2. wg product name <product-name>
3. wg product cost <product-cost>
4. wg product desc <product-desc>
5. wg product image *with an image attached*
`
];
return message;
}
});
}
module.exports.onDeleteProduct = () => {
return check({
checkFunction : checkSelectedWebsiteExist,
callback : () => {
if(!user.getSelectedWebsite().deleteProduct(input['id']))
{
return [
`No product with the given id`
];
}
return [
`The product has been deleted with the id : ` + input['id']
];
}
});
}
module.exports.onSelectProduct = () => {
return check({
checkFunction : checkSelectedWebsiteExist,
callback : () => {
if(!user.getSelectedWebsite().selectProduct(input['id']))
{
return [
`There was no product with the given id. Use the following command to get the list of all products`,
`wg product all`
];
}
return [
`The product has been selected with the id : ${user.getSelectedWebsite().getSelectedProduct().id}` ,
stripIndents`
This product has been selected.
Now you can make change to the product with the following commands :
1. wg product info
2. wg product name <product-name>
3. wg product cost <product-cost>
4. wg product desc <product-desc>
5. wg product image *with an image attached*
`
];
}
});
}
module.exports.onGetAllProducts = () => {
return check({
checkFunction : checkSelectedWebsiteExist,
callback : () => {
let message = [
'Your website has following products: '
];
for(let p of user.getSelectedWebsite().getAllProduct())
{
let m = 'Product id: ' + p.id + '\nProduct Name : ' + p.name + '\nProduct description : '+ p.desc + '\nProduct Cost: ' + p.cost + '\nProduct Image : ';
message.push(m);
message.push(p.image);
}
return message;
}
});
}
module.exports.onGetProductInfo = () => {
return check({
checkFunction : checkSelectedProductExist,
callback : () => {
let selected_product = user.getSelectedWebsite().getSelectedProduct();
return [
stripIndents`
Product id: ${selected_product.id}
Product Name : ${selected_product.name}
Product description : ${selected_product.desc }
Product Cost: ${selected_product.cost}
Product Image :`,
selected_product.image
];
}
});
}
module.exports.onSetProductName = () => {
return check({
checkFunction : checkSelectedProductExist,
callback : () => {
let selected_product = user.getSelectedWebsite().getSelectedProduct();
selected_product.setName(input['product-name']);
return [
'The product name has been set to '+ selected_product.name
];
}
});
}
module.exports.onSetProductCost = () => {
return check ({
checkFunction : checkSelectedProductExist,
callback : () => {
let selected_product = user.getSelectedWebsite().getSelectedProduct();
selected_product.setCost(input['product-cost']);
return[
'The product cost has been set to '+ selected_product.cost
];
}
});
}
module.exports.onSetProductDesc = () => {
return check({
checkFunction : checkSelectedProductExist,
callback : () => {
let selected_product = user.getSelectedWebsite().getSelectedProduct();
selected_product.setDesc(input['product-desc']);
let message = [
'The product desc has been set to '+ selected_product.desc
];
return message;
}
});
}
module.exports.onSetProductImage = () => {
return check({
checkFunction : checkSelectedProductExist,
callback : () => {
return check({
checkFunction : checkMediaExist,
callback : async () => {
let selected_product = user.getSelectedWebsite().getSelectedProduct();
selected_product.setImage(input['media']);
//filename to be set
let filename = `${user.id.slice(3,10)}${user.getSelectedWebsite().companyName}${selected_product.id}`;
//url for the image that are saved
selected_product.imageUrl = await saveImage(input['media'], filename);
let message = [
'The product image has been set to the following image',
selected_product.image
];
return message;
}
});
}
});
}
/**
* A help function
* @param {void} nothing
* @return {help_signal} details on how to use the website
*/
module.exports.help = () =>
{
let help_signal = [
`NOTE : text between '<>' are replaceable.`,
`NOTE : Sentences needs to be between qoutes. For Example "I am a bot" `
`*wg create <company_name> Create a website with the given company_name*`,
`*wg website select <company_name>* Selects a website if exists`,
`*wg website firstname <firstName>* Sets the firstname`,
`*wg website lastname <lastName>* Sets the firstname`,
`*wg website logo (with an image attached)* Sets the logo`,
`*wg website banner (with an image attached)* Sets the banner`,
`*wg website desc <description>* Sets the description`,
`*wg website email <email>* Sets the email`,
`*wg website finished* Completes and creates the website`,
`*wg product new <id>* Creates a new product with an id`,
`*wg product select <id>* Selects a product with a given id`,
`*wg product all* Shows all the products`,
`*wg product info* Shows the information of the selected product`,
`*wg product name <name>* Sets the name of the product`,
`*wg product desc <description>* Sets the description of the product`,
`*wg product cost <cost>* Sets the cost of the product`,
`*wg product image (with an image attached)* Sets the image of the product`,
];
return help_signal;
}
module.exports.onSelectWebsite = () => {
if(user.isWebsite(input['company_name']))
{
user.selectWebsite(input['company_name']);
return [`Website with the company name *${user.getSelectedWebsite().companyName}* is selected`]
} }
// Create a product and select it. At this point all the product properties will be default including the id will be empty return [`No website with the company name *${input['company_name']}* has been selected`];
var product = new Product();
product.setId(id);
// Add a product to the selected website. We will add the id based on the count of the products on the website
website.addProduct(product);
return product;
}
module.exports.deleteProduct = (id,website) => {
return website.deleteProduct(id);
} }
/**
* wg create
* @param {string} input of the company name
* @return {void} gives information on how to add details to website
*/
module.exports.onCreateWebsite = () =>
{
user.addWebsite(new Website(input['company_name']));
return [
`A website with the company name *${user.getSelectedWebsite().companyName}* is created`,
stripIndents`
wg website firstname *<First_Name>*
wg website lastname *<Last_Name>*
wg website logo *with an image attached*
wg website banner *with an image attached*
wg website description *<Description>*
wg website email *<Email>*
For adding information use *wg website <firstname>*`
];
}
module.exports.onGetInfo = () => {
return check({
checkFunction : checkSelectedWebsiteExist,
callback : () => {
let website = user.getSelectedWebsite();
return [
stripIndents`
First Name : ${website.firstName}
Last Name : ${website.lastName}
Company Name (id) : ${website.companyName }
Description : ${website.desc}
Email : ${website.email}
Banner :`,
website.banner,
`Logo :`,
website.logo
];
}
});
}
/**
* wg website firstname
* @param {string} input of the firstname for website
* @return {void} informs you that first name has been added
*/
module.exports.onSetFirstName = () =>
{
return check({
checkFunction : checkSelectedWebsiteExist,
callback : () => {
user.getSelectedWebsite().firstName = input['firstName'];
return [`First name has been set to ${user.getSelectedWebsite().firstName}`];
}
});
}
/**
* wg website lastname
* @param {string} input of the last name for website
* @return {void} informs you that last name has been added
*/
module.exports.onSetLastName = () =>
{
return check({
checkFunction : checkSelectedWebsiteExist,
callback : () => {
user.getSelectedWebsite().lastName = input['lastName'];
return [`Last name has been set to ${user.getSelectedWebsite().lastName}`];
}
});
}
/**
* wg website logo
* @param {string} input of the logo URL for website
* @return {void} informs you that logo URL has been added
*/
module.exports.onSetLogo = () =>
{
return check({
//check if website exist
checkFunction : checkSelectedWebsiteExist,
callback: () => {
return check({
//check if media exist
checkFunction: checkMediaExist,
callback : async () => {
user.getSelectedWebsite().logo = input['media'];
user.getSelectedWebsite().logoUrl = await saveImage(input['media'], `${user.id.slice(3,10)}${user.getSelectedWebsite().companyName}logo`);
return [
`Logo has been set to the following logo`,
user.getSelectedWebsite().logo
];
}
});
}
})
}
/**
* wg website banner
* @param {string} input of the banner URL for website
* @return {void} informs you that banner URL has been added
*/
module.exports.onSetBanner = () =>
{
return check({
//check if website exist
checkFunction : checkSelectedWebsiteExist,
callback : () => {
//check if media exist
return check({
checkFunction : checkMediaExist,
callback : async () => {
user.getSelectedWebsite().banner = input['media'];
user.getSelectedWebsite().bannerUrl = await saveImage(input['media'], `${user.id.slice(3,10)}${user.getSelectedWebsite().companyName}banner`);
return [
`Banner has been set to the following banner`,
user.getSelectedWebsite().banner
];
}
})
}
});
}
/**
* wg website description
* @param {string} input of the company description for website
* @return {void} informs you that description has been added
*/
module.exports.onSetDesc = (descriptiondata) =>
{
return check({
checkFunction : checkSelectedWebsiteExist,
callback : () => {
user.getSelectedWebsite().desc = input['desc'];
return [`Banner has been set to ${user.getSelectedWebsite().desc}`];
}
});
}
/**
* wg website email
* @param {string} input of the email for website
* @return {void} informs you that email has been added
*
*/
module.exports.onSetEmail = () =>
{
return check({
checkFunction : checkSelectedWebsiteExist,
callback : () => {
user.getSelectedWebsite().email = input['email'];
return [`Email has been set to ${user.getSelectedWebsite().email}`];
}
});
}
module.exports.onWebsiteFinished = () => {
return check({
checkFunction : checkSelectedWebsiteExist,
callback : async () => {
//get json from the website
let json = user.getSelectedWebsite().toJson();
//creates a promise
//resolve and reject value is going to be returned
//resolve value = message to be sent
let res = new Promise( (resolve, reject) => {
request({
url: process.argv[2]+"/generate",
method: "POST",
headers: {
"content-type": "application/json", // <--Very important!!!
},
body: json
}, (error, response, body) => {
//send reject value in promise if error exist
if(error)
{
return reject(error);
}
// messsage to be sent
let returnStatement = [
`${process.argv[2]}/pages/${JSON.parse(response.body).directory}`,
`*Website ID:* ${JSON.parse(response.body).directory}`,
`*Important to remember the ID*`
];
//send resolve value id
resolve(returnStatement);
});
});
//waits for request to be completed
let msg = await res;
return msg;
}
});
}
module.exports.onDeployWebsite = () => {
return check({
checkFunction: checkSelectedProductExist,
callback : async () => {
let res = new Promise( (resolve, reject) => {
request({
url: process.argv[2]+"/ipfsdeploy?id="+user.getSelectedWebsite().companyName,
method: "GET",
headers: {
"content-type": "application/json", // <--Very important!!!
}
}, function (error, response, body){
// reject error in promise
if(error)
{
return reject(error);
}
// messsage to be sent
let returnStatement = [
`https://ipfs.io/ipfs/${JSON.parse(response.body).data}`,
`Takes around 10-30 minutues to deploy`,
`Read more about IPFS https://ipfs.io/`
];
//send resolve value id
resolve(returnStatement);
});
});
let msg = await res;
return msg;
}
});
}

View File

@@ -1,19 +1,22 @@
const fs = require('fs');
class Command{ class Command{
/** /**
* *
* @param {{string, function()}} param0 * @param {{string, function(),boolean}} param0
*/ */
constructor({command,callback}){ constructor({command,callback, requireMedia = false}){
this.command = command; this.command = command;
this.callback = callback; this.callback = callback;
this.requireMedia = requireMedia;
this.requireInput = false; this.requireInput = false;
this.inputPos = []; this.inputPos = [];
this._requireInput(); this._requireInput();
} }
/** /**
* * Checks if a message is equal to the command.
* @param {string} message * @param {string} message
*/ */
equals(message){ equals(message){
@@ -28,8 +31,10 @@ class Command{
}else if(this.requireInput){ }else if(this.requireInput){
//the command requires input //the command requires input
let splitCommand = this.command.split(' '); let splitCommand = this.command.split(' ');
let splitMsg = msg.split(' '); let splitMsg = this._getSplitMessage(message);
//check the number of words both has //check the number of words both has
//if not same then return false //if not same then return false
@@ -66,8 +71,17 @@ class Command{
* This determines if the command requires input * This determines if the command requires input
* if the command has <inputName> in the string * if the command has <inputName> in the string
* then the command requires input * then the command requires input
*
* else if the command requires media
* then the command requires input
*/ */
_requireInput(){ _requireInput(){
if(this.requireMedia)
{
this.requireInput = true;
return;
}
let msg = this.command; let msg = this.command;
let matched = msg.match(/[<>]/g); let matched = msg.match(/[<>]/g);
@@ -76,22 +90,68 @@ class Command{
} }
/** /**
* returns an array of string representing the inputs of the command * returns an array of string or MessageMedia representing the inputs of the command
* @param {string} message * @param {import("whatsapp-web.js").Message} message
*/ */
getInput(message){ async getInput(message){
if(this.requireMedia){
return await this._getInputMedia(message);
}else{
return this._getInputMessage(message.body);
}
}
/**
* Returns an object with string input from a message
* The string is mapped to the command variable
* @param {string} msgString
*/
_getInputMessage(msgString){
let splitMsg = message.split(' ');
let splitCommand = this.command.split(' ');
let input = {}; let input = {};
let splitMsg = this._getSplitMessage(msgString);
let splitCommand = this.command.split(' ');
for(let i = 0; i < splitMsg.length; i++){ for(let i = 0; i < splitMsg.length; i++){
if(splitCommand[i].startsWith('<')){ if(splitCommand[i].startsWith('<')){
let key = splitCommand[i].slice(1, splitCommand[i].length-1); let key = splitCommand[i].slice(1, splitCommand[i].length-1);
input[key] = splitMsg[i]; input[key] = splitMsg[i];
} }
} }
return input;
}
/**
* Splits the message into an array of words
* Splits the message by space and ""
* @param {string} msg
*/
_getSplitMessage(msg){
let split = msg.split(/["]/g);
if(split.length > 1)
{
let splitMsg = split[0].trim().split(' ');
let inputs = split.slice(1).filter( el => el.trim() == "" ? null : el);
splitMsg = splitMsg.concat(inputs);
return splitMsg;
}
return msg.split(' ');
}
/**
* Returns an object with a meesageMedia mapped to 'media'
* @param {import("whatsapp-web.js").Message} message
*/
async _getInputMedia(message){
let input = {};
if(message.hasMedia){
let media = await message.downloadMedia();
input['media'] = media;
}
return input; return input;
} }

View File

@@ -4,12 +4,14 @@ class Entity {
constructor(){ constructor(){
this.data = new Map(); this.data = new Map();
this.selectedData = null;
this.count = 0; this.count = 0;
} }
addData(key ,value){ addData(key ,value){
if(!this.isData(key)){ if(!this.isData(key)){
this.data.set(key, value); this.data.set(key, value);
this.selectedData = key;
return true; return true;
} }
return false; return false;
@@ -26,16 +28,40 @@ class Entity {
deleteData(key){ deleteData(key){
if(this.isData(key)){ if(this.isData(key)){
this.data.delete(key); this.data.delete(key);
if(this.selectedData == key){
this.selectedData = null;
}
return true; return true;
} }
return false; return false;
} }
clearData(){ clearData(){
this.selectedData = null;
this.data = new Map(); this.data = new Map();
this.count = 0; this.count = 0;
} }
/**
* Select a specific data with its key
* @param {string} key
* @returns true if a data is selected
* @returns false if data is null
*/
selectData(key){
if(this.isData(key))
{
this.selectedData = key;
return true;
}
return false;
}
/**
*
* @param {string} key
* @returns the value mapped to the key
*/
getData(key){ getData(key){
if(this.isData(key)){ if(this.isData(key)){
return this.data.get(key); return this.data.get(key);
@@ -43,6 +69,9 @@ class Entity {
return null; return null;
} }
/**
* @returns a map of all data
*/
getAllData(){ getAllData(){
return this.data; return this.data;
} }

View File

@@ -7,6 +7,7 @@ class Product {
this.desc = desc; this.desc = desc;
this.cost = cost; this.cost = cost;
this.image = image; this.image = image;
this.imageUrl = '';
} }
/** /**

View File

@@ -29,6 +29,22 @@ class User{
return this.websites.getData(companyName); return this.websites.getData(companyName);
} }
isWebsite(companyName){
return this.websites.isData(companyName);
}
selectWebsite(companyName)
{
return this.websites.selectData(companyName);
}
/**
* @returns {Website}
*/
getSelectedWebsite(){
return this.getWebsite(this.websites.selectedData);
}
} }
module.exports.User = User; module.exports.User = User;

View File

@@ -10,6 +10,8 @@ class Website {
this.firstName = ''; this.firstName = '';
this.lastName = ''; this.lastName = '';
this.companyName = companyName; this.companyName = companyName;
this.logo = '';
this.banner = '';
this.logoUrl = ''; this.logoUrl = '';
this.bannerUrl = ''; this.bannerUrl = '';
this.desc = ''; this.desc = '';
@@ -39,7 +41,7 @@ class Website {
/** /**
* *
* @returns {[]} * returns all the products in the website
*/ */
getAllProduct(){ getAllProduct(){
return this.products.getAllData().values(); return this.products.getAllData().values();
@@ -54,6 +56,40 @@ class Website {
return this.products.deleteData(productId); return this.products.deleteData(productId);
} }
selectProduct(productId){
return this.products.selectData(productId);
}
/**
* @returns {Product}
*/
getSelectedProduct()
{
return this.getProduct(this.products.selectedData);
}
toJson(){
let j = {};
j["firstName"] = this.firstName;
j["lastName"] = this.lastName;
j["companyName"] = this.companyName;
j["logoUrl"] = this.logoUrl;
j["bannerUrl"] = this.bannerUrl;
j["email"] = this.email;
j["description"] = this.desc;
j["template"] = 'Colo_Shop';
let csv = 'product id,product name,description,cost,product image url\n';
for (let prod of this.products.getAllData().values())
{
let m = [prod.id, prod.name, prod.desc, prod.cost, prod.imageUrl].join(',');
csv += `${m}\n`;
}
j['csv'] = csv;
return JSON.stringify(j);
}
} }

View File

@@ -4,14 +4,12 @@ const logic = require("../businessLogic/logic");
const { Website } = require("../models/website"); const { Website } = require("../models/website");
const { Product } = require('../models/product'); const { Product } = require('../models/product');
var selected_product = null;// Will keep track of the selected product
var selected_website = null; // Selected website.
///////////
//add the commands here //commands and the corresponding function to be executed
/////////// //are input in the array
const commands = [ const commands = [
new Command({ new Command({
//User command //User command
command: 'wg', command: 'wg',
@@ -31,258 +29,212 @@ const commands = [
new Command({ new Command({
//User command //User command
command: `wg product new <id>`, command: `wg product new <id>`,
//function to be executed //function to be executed
callback : (input) => { callback : logic.onCreateProduct
if(selected_website==null)
{
let message = [
`A website should be selected or created before creating a product `
];
return message;
}
selected_product= logic.addProduct(input['id'],selected_website);
//mesage to be sent to the user
let message = [
`The product has been created with the id : ` + selected_product.id ,
`This product has been selected . \nNow you can make change to the product with the following commands : \n1. wg product info \n2. wg product name <product-name> \n3. wg product cost <product-cost> \n4. wg product desc <product-desc> \n5. wg product image <product-image>`
];
return message;
}
}), }),
new Command({ new Command({
//User command //User command
command: `wg product delete <id>`, command: `wg product delete <id>`,
//function to be executed //function to be executed
callback : (input) => { callback : logic.onDeleteProduct
if(selected_website==null)
{
let message = [
`A website should be selected or created before deleting a product `
];
return message;
}
if(logic.deleteProduct(input['id'],selected_website) == false)
{
let message = [
`No product with the given id`
];
return message;
}
let message = [
`The product has been deleted with the id : ` + id
];
return message;
}
}), }),
new Command({ new Command({
//User command //User command
command: `wg product select <id>`, command: `wg product select <id>`,
//function to be executed
callback : logic.onSelectProduct
}),
//gives user information on how to create website
new Command({
//User command
command: 'wg help',
//function to be executed
callback : logic.help
}),
//helps user to create a website. The first step.
new Command({
//User command
command: 'wg create <company_name>',
//function to be executed //function to be executed
callback : (input) => { callback : logic.onCreateWebsite
if(selected_website==null)
{
let message = [
`A website should be selected or created before selecting a product `
];
return message;
}
// Find the product with the given id
selected_product = selected_website.getProduct(input['id']);
if(selected_product == null)
{
logic.addProduct(input['id'],selected_website);
selected_product = selected_website.getProduct(input['id']);
let message = [
`There was no product with the give id. So a new product was created and selected with the id : ` + selected_product.id ,
`Now you can make change to the product with the following commands : \n1. wg product info \n2. wg product name <product-name> \n3. wg product cost <product-cost> \n4. wg product desc <product-desc> \n5. wg product image <product-image>`
];
return message;
}
let message = [
`The product has been selected with the id : ` + selected_product.id ,
'Now you can make change to the product with the following commands : \n1. wg product info \n2. wg product name <product-name> \n3. wg product cost <product-cost> \n4. wg product desc <product-desc> \n5. wg product image <product-image>'
];
return message;
}
}), }),
//Inputs user's first name for website
new Command({
//User command
command: 'wg website select <company_name>',
callback : logic.onSelectWebsite
}),
new Command({
//User command
command: 'wg website firstname <firstName>',
//function to be executed
callback : logic.onSetFirstName
}),
//inputs user last name in website
new Command({
//User command
command: 'wg website lastname <lastName>',
//function to be executed
callback : logic.onSetLastName
}),
//inputs the logo of the company to website using url of logo
new Command({
//User command
command: 'wg website logo',
//function to be executed
callback : logic.onSetLogo,
requireMedia : true
}),
//inputs the banner for the company to website using url of banner
new Command({
//User command
command: 'wg website banner',
//function to be executed
callback : logic.onSetBanner,
requireMedia: true,
}),
//inputs the description of the company to be seen in the website
new Command({
//User command
command: 'wg website desc <desc>',
//function to be executed
callback : logic.onSetDesc
}),
//inputs the email of the company for contacting.
new Command({
//User command
command: 'wg website email <email>',
//function to be executed
callback : logic.onSetEmail
}),
new Command({
//User command
command: 'wg website info',
//function to be executed
callback : logic.onGetInfo
}),
new Command({
//User command
command: 'wg website finished',
//function to be executed
callback : logic.onWebsiteFinished
}),
//gives user information on how to create website
new Command({ new Command({
//User command //User command
command: `wg product all`, command: `wg product all`,
//function to be executed //function to be executed
callback : () => { callback : logic.onGetAllProducts
if(selected_website==null)
{
let message = [
`A website should be selected or created `
];
return message;
}
let message = [
'Your website has following products: '
];
for(let p of selected_website.getAllProduct())
{
let m = 'Product id: ' + p.id + '\nProduct Name : ' + p.name + '\nProduct description : '+ p.desc + '\nProduct Cost: ' + p.cost + '\nProduct Image : '+ p.image;
message.push(m);
}
return message;
}
}), }),
new Command({ new Command({
//User command //User command
command: `wg product info`, command: `wg product info`,
//function to be executed //function to be executed
callback : () => { callback : logic.onGetProductInfo
if(selected_product == null)
{
let message = [
`A product should be selected `
];
return message;
}
let message = [
'Product id: ' + selected_product.id,
'Product Name : ' + selected_product.name ,
'Product description : '+ selected_product.desc ,
'Product Cost: ' + selected_product.cost ,
'Product Image : '+ selected_product.image
];
return message;
}
}), }),
new Command({ new Command({
//User command //User command
command: `wg product name <product-name>`, command: `wg product name <product-name>`,
//function to be executed //function to be executed
callback : (input) => { callback : logic.onSetProductName
if(selected_product == null)
{
let message = [
`A product should be selected `
];
return message;
}
selected_product.setName(input['product-name']);
let message = [
'The product name has been set to '+ selected_product.name
];
return message;
}
}), }),
new Command({ new Command({
//User command //User command
command: `wg product cost <product-cost>`, command: `wg product cost <product-cost>`,
//function to be executed //function to be executed
callback : (input) => { callback : logic.onSetProductCost
if(selected_product == null)
{
let message = [
`A product should be selected `
];
return message;
}
selected_product.setCost(input['product-cost']);
let message = [
'The product cost has been set to '+ selected_product.cost
];
return message;
}
}), }),
new Command({ new Command({
//User command //User command
command: 'wg product desc <product-desc>', command: 'wg product desc <product-desc>',
//function to be executed //function to be executed
callback : (input) => { callback : logic.onSetProductDesc
if(selected_product == null)
{
let message = [
`A product should be selected `
];
return message;
}
selected_product.setDesc(input['product-desc']);
let message = [
'The product description has been set to : '+ selected_product.desc
];
return message;
}
}), }),
new Command({ new Command({
//User command //User command
command: 'wg product image <product-image>', command: 'wg product image',
//function to be executed //function to be executed
callback : (input) => { callback : logic.onSetProductImage,
if(selected_product == null) requireMedia: true
{
let message = [
`A product should be selected `
];
return message;
}
selected_product.setImage(input['product-image']);
let message = [
'The product image has been set to : '+ selected_product.image
];
return message;
}
}), }),
]; ];
module.exports= onMessage = async (message, client) => {
module.exports= onMessage = (message, client) => {
let command = null; let command = null;
//if the message start with wg then proceed //if the message start with wg then proceed
if(message.body.startsWith("wg")) if(message.body.startsWith("wg"))
{ {
//loop through all the commands
for (let c of commands){ for (let c of commands){
//check if the message sent is equal to the commands
//if the message matches a command,
//then save the command in the command variable
if(c.equals(message.body)) if(c.equals(message.body))
{ {
command = c; command = c;
break; break;
} }
} }
//if the command is not null, implies, the message sent is a valid command
if(command != null){ if(command != null){
let input = {}; let input = {};
//check if the command requires input
if(command.requireInput){ if(command.requireInput){
input = command.getInput(message.body); input = await command.getInput(message);
} }
//determine the user
logic.setUser(message.id.remote);
//determine the input
logic.setInput(input);
//call callback function in the command
//await is used, so that if a command is an async function
//the program will wait until it is finished
//the callback returns a message to be sent to the user
let messageToBeSent = await command.callback();
let messageToBeSent = command.callback(input); // send the message to the user
for (let msg of messageToBeSent) for (let msg of messageToBeSent)
{ {
client.sendMessage(message.from, msg, new Object()); client.sendMessage(message.from, msg, new Object());
@@ -294,4 +246,5 @@ module.exports= onMessage = (message, client) => {
//export default onMessage; //export default onMessage;

View File

@@ -135,7 +135,7 @@ describe('Command', () => {
expect(a.equals(message)).to.false; expect(a.equals(message)).to.false;
}); });
it('Test : getInput() with 1 input', () => { it('Test : _getInputMessage() with 1 input', () => {
let message = 'wg create p12' let message = 'wg create p12'
@@ -146,10 +146,10 @@ describe('Command', () => {
} }
}); });
expect(a.getInput(message)['id']).to.equal('p12'); expect(a._getInputMessage(message)['id']).to.equal('p12');
}); });
it('Test : getInput() with 2 input', () => { it('Test : _getInputMessage() with 2 input', () => {
let message = 'wg create p12 pikachu' let message = 'wg create p12 pikachu'
@@ -160,10 +160,37 @@ describe('Command', () => {
} }
}); });
expect(a.getInput(message)['id']).to.equal('p12'); expect(a._getInputMessage(message)['id']).to.equal('p12');
expect(a.getInput(message)['name']).to.equal('pikachu'); expect(a._getInputMessage(message)['name']).to.equal('pikachu');
}); });
it('Test : _getSplitMessage() with a sentence', () => {
let a = new Command({command : 'wg website desc <desc>'});
let b = a._getSplitMessage(`wg website desc "Hello everynyan, how are you"`);
expect(b[0]).to.equal('wg');
expect(b[1]).to.equal('website');
expect(b[2]).to.equal('desc');
expect(b[3]).to.equal('Hello everynyan, how are you');
})
it('Test : _getSplitMessage() with multiple sentence input', () => {
let a = new Command({command : 'wg website desc <desc>'});
let b = a._getSplitMessage(`wg website desc "Hello everynyan, how are you" "I am fine thank you"`);
expect(b[0]).to.equal('wg');
expect(b[1]).to.equal('website');
expect(b[2]).to.equal('desc');
expect(b[3]).to.equal('Hello everynyan, how are you');
expect(b[4]).to.equal('I am fine thank you');
})
it('Test : _getSplitMessage() with single word', () => {
let a = new Command({command : 'wg website desc <desc>'});
let b = a._getSplitMessage(`wg website desc Hello`);
expect(b[0]).to.equal('wg');
expect(b[1]).to.equal('website');
expect(b[2]).to.equal('desc');
expect(b[3]).to.equal('Hello');
})
}); });

View File

@@ -29,13 +29,13 @@ describe('Entity', () => {
expect(a.isData('pagol')).to.false; expect(a.isData('pagol')).to.false;
expect(a.isData('hello world')).to.false; expect(a.isData('hello world')).to.false;
}); });
it('Test: getData', () => { it('Test: getData', () => {
let a = new Entity(); let a = new Entity();
a.addData('hello world', new Website('hello world')); a.addData('hello world', new Website('hello world'));
a.addData('gada', new Website('gada')); a.addData('gada', new Website('gada'));
a.addData('pagol', new Website('pagol')); a.addData('pagol', new Website('pagol'));
expect(a.getData('hello world').companyName).to.equal('hello world'); expect(a.getData('hello world').companyName).to.equal('hello world');
expect(a.getData('gada').companyName).to.equal('gada'); expect(a.getData('gada').companyName).to.equal('gada');
expect(a.getData('chu chu')).to.null; expect(a.getData('chu chu')).to.null;
@@ -51,18 +51,67 @@ describe('Entity', () => {
a.deleteData('gada'); a.deleteData('gada');
expect(a.getData('gada')).to.null; expect(a.getData('gada')).to.null;
}) })
it('Test: getAllData', () => { it('Test: getAllData', () => {
let a = new Entity(); let a = new Entity();
a.addData('hello world', new Website('hello world')); a.addData('hello world', new Website('hello world'));
a.addData('gada', new Website('gada')); a.addData('gada', new Website('gada'));
a.addData('pagol', new Website('pagol')); a.addData('pagol', new Website('pagol'));
let websitegen = a.getAllData().values(); let websitegen = a.getAllData().values();
for(let t of websitegen) for(let t of websitegen)
{ {
console.log(t.companyName); console.log(t.companyName);
} }
}) })
it('Test: selectData()', () => {
let a = new Entity();
a.addData('hello world', new Website('hello world'));
a.addData('gada', new Website('gada'));
a.addData('pagol', new Website('pagol'));
a.selectData('gada');
expect(a.selectedData).to.equals('gada');
});
it('Test: selectedData() = false', () => {
let a = new Entity();
a.addData('hello world', new Website('hello world'));
a.addData('gada', new Website('gada'));
a.addData('pagol', new Website('pagol'));
a.selectData('tara');
expect(a.selectedData).to.equals('pagol');
});
it('Test: selectedData when addData() is used', () => {
let a = new Entity();
a.addData('hello world', new Website('hello world'));
a.addData('gada', new Website('gada'));
a.addData('pagol', new Website('pagol'));
expect(a.selectedData).to.equals('pagol');
});
it('Test : selectedData when clearData()', () => {
let a = new Entity();
a.addData('hello world', new Website('hello world'));
a.addData('gada', new Website('gada'));
a.addData('pagol', new Website('pagol'));
a.clearData();
expect(a.count).to.equal(0);
expect(a.isData("kruta")).to.false;
expect(a.isData("hello")).to.false;
expect(a.isData('pagol')).to.false;
expect(a.isData('hello world')).to.false;
expect(a.selectedData).to.null;
});
}) })