Fixed theme and partials structure

master
Mark Moffat 2018-02-11 20:47:26 +01:00
parent 2990c9e8fe
commit 09cd83352f
29 changed files with 100 additions and 157 deletions

18
app.js
View File

@ -12,7 +12,6 @@ const helmet = require('helmet');
const colors = require('colors');
const common = require('./lib/common');
const mongodbUri = require('mongodb-uri');
let handlebars = require('express-handlebars');
// Validate our settings schema
@ -66,14 +65,16 @@ const app = express();
// view engine setup
app.set('views', path.join(__dirname, '/views'));
app.engine('hbs', handlebars({extname: 'hbs', layoutsDir: path.join(__dirname, 'views', 'layouts'), defaultLayout: 'layout.hbs'}));
app.engine('hbs', handlebars({
extname: 'hbs',
layoutsDir: path.join(__dirname, 'views', 'layouts'),
defaultLayout: 'layout.hbs',
partialsDir: [ path.join(__dirname, 'views') ]
}));
app.set('view engine', 'hbs');
// helpers for the handlebar templating platform
handlebars = handlebars.create({
partialsDir: [
'views/partials/'
],
helpers: {
perRowClass: function(numProducts){
if(parseInt(numProducts) === 1){
@ -159,6 +160,12 @@ handlebars = handlebars.create({
}
return options.inverse(this);
},
toLower: function (value){
if(value){
return value.toLowerCase();
}
return null;
},
formatDate: function (date, format){
return moment(date).format(format);
},
@ -222,6 +229,7 @@ app.use(session({
// serving static content
app.use(express.static(path.join(__dirname, 'public')));
app.use(express.static(path.join(__dirname, 'views', 'themes')));
// Make stuff accessible to our router
app.use((req, res, next) => {

View File

@ -148,7 +148,7 @@ exports.checkDirectorySync = (directory) => {
};
exports.getThemes = () => {
return fs.readdirSync(path.join('public', 'themes')).filter(file => fs.statSync(path.join(path.join('public', 'themes'), file)).isDirectory());
return fs.readdirSync(path.join(__dirname, '../', 'views', 'themes')).filter(file => fs.statSync(path.join(path.join(__dirname, '../', 'views', 'themes'), file)).isDirectory());
};
exports.getImages = (dir, req, res, callback) => {
@ -206,7 +206,7 @@ exports.getConfig = () => {
config.theme = 'Cloth'; // Default to Cloth theme
}
config.themeViews = '../public/themes/' + config.theme + '/';
config.themeViews = '../views/themes/' + config.theme + '/';
// if db set to mongodb override connection with MONGODB_CONNECTION_STRING env var
config.databaseConnectionString = process.env.MONGODB_CONNECTION_STRING || config.databaseConnectionString;
@ -458,6 +458,10 @@ exports.getData = (req, page, query) => {
skip = (page - 1) * numberProducts;
}
if(!query){
query = {};
}
query['productPublished'] = 'true';
// Run our queries

View File

@ -1,64 +0,0 @@
<div class="col-xl-8 col-xl-offset-2 col-xs-12">
<div class="row">
<form action="/search" id="search_form" method="post">
<div class="row">
{{#ifCond config.menuEnabled '==' 'true'}}
{{#ifCond config.menuLocation '==' "side"}}
<div class="col-md-offset-2 col-lg-offset-2 col-xl-9 col-xl-offset-3 search-bar col-md-10 search-bar">
{{else}}
<div class="col-md-8 col-md-offset-2 col-lg-8 col-lg-offset-2 search-bar">
{{/ifCond}}
{{else}}
<div class="col-md-8 col-md-offset-2 col-lg-8 col-lg-offset-2 search-bar">
{{/ifCond}}
<div class="search-bar-input input-group">
<input type="text" name="frm_search" id="frm_search" class="form-control" placeholder="Search the shop">
<span class="input-group-btn">
<button class="btn btn-primary" id="btn_search" type="submit">Search</button>
<a href="/" class="hidden-xs btn btn-primary"><i class="fa fa-times" aria-hidden="true"></i></a>
</span>
</div>
</div>
</div>
</form>
</div>
<div class="row">
{{#ifCond config.menuEnabled '==' 'true'}}
{{#ifCond config.menuLocation '==' "side"}}
<div class="col-xl-3 col-md-2">
<ul class="list-group menu-side">
<li class="list-group-item active">{{config.menuTitle}}</li>
<li class="list-group-item"><a href="/">All</a></li>
{{#each menu.items}}
<li class="list-group-item"><a href="/category/{{this.link}}">{{this.title}}</a></li>
{{/each}}
</ul>
</div>
<div class="col-xl-9 col-md-10">
{{else}}
<div class="row">
<div class="col-md-8 col-md-offset-2 col-lg-8 col-lg-offset-2">
<ol class="breadcrumb menu-top">
<li><a href="/">Home</a></li>
{{#each menu.items}}
<li><a href="/category/{{this.link}}">{{this.title}}</a></li>
{{/each}}
</ol>
</div>
</div>
<div class="col-md-8 col-md-offset-2 col-lg-8 col-lg-offset-2">
{{/ifCond}}
{{else}}
<div class="col-md-8 col-md-offset-2 col-lg-8 col-lg-offset-2">
{{/ifCond}}
{{#if filtered}}
<div class="product-layout left-pad-30 col-md-12">
<strong>Showing results for: {{searchTerm}}</strong>
</div>
{{/if}}
<div class="product-layout">
{{{page.pageContent}}}
</div>
</div>
</div>
</div>

View File

@ -188,7 +188,7 @@ router.post('/admin/settings/option/remove', common.restrict, common.checkAccess
if(err){
console.info(err.stack);
}
if(product.productOptions){
if(product && product.productOptions){
let optJson = JSON.parse(product.productOptions);
delete optJson[req.body.optName];
@ -203,7 +203,7 @@ router.post('/admin/settings/option/remove', common.restrict, common.checkAccess
}
});
}else{
res.status(400).json({message: 'Product not found.'});
res.status(400).json({message: 'Product not found. Try saving before removing.'});
}
});
});

View File

@ -490,6 +490,7 @@ router.get('/:page?', (req, res, next) => {
res.render(`${config.themeViews}page`, {
title: page.pageName,
page: page,
searchTerm: req.params.page,
session: req.session,
message: common.clearSessionValue(req.session, 'message'),
messageType: common.clearSessionValue(req.session, 'messageType'),

View File

@ -1,4 +1,4 @@
{{> menu}}
{{> partials/menu}}
<div class="col-lg-9">
<div class="col-lg-10">
<div class="page-header">

View File

@ -1,4 +1,4 @@
{{> menu}}
{{> partials/menu}}
<div class="col-lg-9">
<div class="row">
<div class="col-lg-12">

View File

@ -1,4 +1,4 @@
{{> menu}}
{{> partials/menu}}
<div class="col-lg-9">
<div class="col-lg-12">
<h2>Customers</h2>

View File

@ -61,7 +61,7 @@
</script>
{{#if config.googleAnalytics}}{{{config.googleAnalytics}}}{{/if}}
{{#if config.customCss}}<style>{{{config.customCss}}}</style>{{/if}}
{{#if config.theme}}<link rel="stylesheet" href="/themes/{{config.theme}}/style.css">{{/if}}
{{#if config.theme}}<link rel="stylesheet" href="/{{config.theme}}/style.css">{{/if}}
<!-- SEO data -->
</head>
{{#if admin}}
@ -120,7 +120,7 @@
<div class="container-fluid">
<div class="row">
<div id="cart" class="col-md-12 pushy pushy-right">
{{> cart}}
{{> partials/cart}}
</div>
</div>
</div>

View File

@ -1,4 +1,4 @@
{{> menu}}
{{> partials/menu}}
<div class="col-lg-9">
<div class="col-lg-12">
<h2>View Order</h2>
@ -38,12 +38,12 @@
<li class="list-group-item"><strong> State: </strong><span class="pull-right">{{result.orderState}}</span></li>
<li class="list-group-item"><strong> Postcode/Zipcode: </strong><span class="pull-right">{{result.orderPostcode}}</span></li>
<li class="list-group-item"><strong> Phone number: </strong><span class="pull-right">{{result.orderPhoneNumber}}</span></li>
<li class="list-group-item">&nbsp;</li>
<li class="list-group-item"><strong class="text-info">Products ordered</strong></li>
{{#each result.orderProducts}}
<li class="list-group-item">
{{this.quantity}} x {{this.title}}
{{this.quantity}} x {{this.title}}
{{#if productOptions}}
&nbsp; > &nbsp;
<span class="text-warning"> Options: </span>
@ -54,13 +54,13 @@
{{else}}
{{this}} /
{{/if}}
{{/each}}
)
{{/if}}
{{/each}}
)
{{/if}}
<div class="pull-right">{{currencySymbol config.currencySymbol}}{{formatAmount this.totalItemPrice}}</div>
</li>
{{/each}}
</ul>
<input type="hidden" id="order_id" value="{{result._id}}">
</div>
</div>
</div>

View File

@ -1,4 +1,4 @@
{{> menu}}
{{> partials/menu}}
<div class="col-lg-9">
<div class="col-lg-12">
<h2>Orders</h2>

View File

@ -1,4 +1,4 @@
{{> menu}}
{{> partials/menu}}
<div class="col-lg-9">
<form method="post" class="form-horizontal" id="insert_form" action="/admin/product/update" data-toggle="validator">
<div class="col-lg-12">

View File

@ -1,4 +1,4 @@
{{> menu}}
{{> partials/menu}}
<div class="col-lg-9">
<form method="post" class="form-horizontal" id="insert_form" action="/admin/product/insert" data-toggle="validator">
<div class="col-lg-12">
@ -112,7 +112,7 @@
<link href="https://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.2/summernote.css" rel="stylesheet">
<script>
$(document).ready(function() {
$('#editor').summernote({
$('#editor').summernote({
height: 300,
minHeight: null
});

View File

@ -1,4 +1,4 @@
{{> menu}}
{{> partials/menu}}
<div class="col-lg-9">
<div class="col-lg-12">
<h2>Products</h2>

View File

@ -1,4 +1,4 @@
{{> menu}}
{{> partials/menu}}
<div class="col-lg-9">
<div class="row">
<div class="col-md-10">
@ -61,7 +61,6 @@
<div class="form-group">
<label>Theme</label>
<select class="form-control" name="theme">
<option {{selectState '' config.theme}} value="">Default</option>
{{#each themes}}
<option {{selectState this ../config.theme}} value="{{this}}">{{this}}</option>
{{/each}}

View File

@ -1,4 +1,4 @@
{{> menu}}
{{> partials/menu}}
<script src="https://code.jquery.com/ui/1.11.3/jquery-ui.min.js"></script>
<div class="col-lg-9">
<div class="row">

View File

@ -1,9 +1,9 @@
{{> menu}}
{{> partials/menu}}
<div class="col-lg-9">
<div class="row">
<div class="col-md-12">
<form id="settingsPageEditor">
<h2 class="clearfix">Static page <div class="pull-right"><button type="submit" id="btnPageUpdate" class="btn btn-success">{{button_text}}</button></div></h2>
<h2 class="clearfix">Static page <div class="pull-right"><button type="submit" id="btnPageUpdate" class="btn btn-success">{{button_text}}</button></div></h2>
<input type="hidden" id="page_id" value="{{page._id}}">
<div class="form-group">
<label>Page name *</label>
@ -34,7 +34,7 @@
<link href="https://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.2/summernote.css" rel="stylesheet">
<script>
$(document).ready(function() {
$('#pageContent').summernote({
$('#pageContent').summernote({
height: 300,
minHeight: null
});

View File

@ -1,12 +1,12 @@
{{> menu}}
{{> partials/menu}}
<div class="col-lg-9">
<div class="row">
<div class="col-md-10">
<h2 class="clearfix">Static pages <div class="pull-right"><a href="/admin/settings/pages/new" class="btn btn-success">New page</a></div></h2>
<h2 class="clearfix">Static pages <div class="pull-right"><a href="/admin/settings/pages/new" class="btn btn-success">New page</a></div></h2>
<p class="text-muted">
Here you can setup and manage static pages for your shopping cart.
You may want to setup a page with a little bit about your business called "About" or "Contact Us" etc.
</p>
Here you can setup and manage static pages for your shopping cart.
You may want to setup a page with a little bit about your business called "About" or "Contact Us" etc.
</p>
{{#if pages}}
<ul class="list-group">
{{#each pages}}

View File

@ -1,5 +1,5 @@
<div class="col-xl-8 col-xl-offset-2 col-xs-12">
<div id="cart">
{{> cart}}
{{> partials/cart}}
</div>
</div>

View File

@ -0,0 +1,25 @@
<nav class="navbar navbar-default navbarMenuWrapper">
<div class="container-fluid">
<div class="col-md-8 col-md-offset-2 navbarMenu">
<ul class="nav navbar-nav">
<li {{#unless searchTerm}}class="navActive"{{/unless}}><a href="/">Home</a></li>
{{#each menu.items}}
<li
{{#ifCond (toLower this.title) '==' (toLower @root.searchTerm)}}class="navActive"{{/ifCond}}
{{#ifCond (toLower this.title) '==' @root.title}}class="navActive"{{/ifCond}}>
<a href="{{this.link}}">{{this.title}}</a>
</li>
{{/each}}
<li class="pull-right col-md-4 searchBarWrapper">
<div class="search-bar-input input-group searchMenuLocation-{{config.menuLocation}} searchProPerRow-{{config.productsPerRow}}">
<input type="text" name="frm_search" id="frm_search" class="form-control" placeholder="Search the shop">
<span class="input-group-btn">
<button class="btn btn-primary" id="btn_search" type="submit">Search</button>
</span>
</div>
</li>
</ul>
</div>
</div>
</nav>

View File

@ -1,23 +1,4 @@
<nav class="navbar navbar-default navbarMenuWrapper">
<div class="container-fluid">
<div class="col-md-8 col-md-offset-2 navbarMenu">
<ul class="nav navbar-nav">
<li {{#unless searchTerm}}class="navActive"{{/unless}}><a href="/">Home</a></li>
{{#each menu.items}}
<li {{#ifCond this.link '==' ../searchTerm}}class="navActive"{{/ifCond}}><a href="/category/{{this.link}}">{{this.title}}</a></li>
{{/each}}
<li class="pull-right col-md-4 searchBarWrapper">
<div class="search-bar-input input-group searchMenuLocation-{{config.menuLocation}} searchProPerRow-{{config.productsPerRow}}">
<input type="text" name="frm_search" id="frm_search" class="form-control" placeholder="Search the shop">
<span class="input-group-btn">
<button class="btn btn-primary" id="btn_search" type="submit">Search</button>
</span>
</div>
</li>
</ul>
</div>
</div>
</nav>
{{> themes/Cloth/front-menu}}
<div class="productsWrapper col-md-8 col-md-offset-2">
{{#if filtered}}
<div class="product-layout col-md-12">
@ -52,7 +33,7 @@
</h3>
</a>
</div>
{{else}}
{{else}}
<a href="/product/{{this._id}}">
<div class="vertical-center thumbnail-image-container">
{{#if productImage}}

View File

@ -0,0 +1,8 @@
{{> themes/Cloth/front-menu}}
<div class="row">
<div class="col-md-8 col-md-offset-2 col-lg-8 col-lg-offset-2">
<div class="product-layout">
{{{page.pageContent}}}
</div>
</div>
</div>

View File

@ -30,7 +30,7 @@
</div>
{{/if}}
<form id="shipping-form" class="shipping-form" action="/{{config.paymentGateway}}/checkout_action" method="post" role="form" data-toggle="validator" novalidate="false">
{{> payments/shipping-form}}
{{> partials/payments/shipping-form}}
{{#if session.customer}}
{{#ifCond config.paymentGateway '==' 'paypal'}}
{{> payments/paypal}}
@ -48,17 +48,17 @@
</form>
{{#if session.customer}}
{{#ifCond config.paymentGateway '==' 'stripe'}}
{{> payments/stripe}}
{{> partials/payments/stripe}}
{{/ifCond}}
{{#ifCond config.paymentGateway '==' 'authorizenet'}}
{{> payments/authorizenet}}
{{> partials/payments/authorizenet}}
{{/ifCond}}
{{/if}}
</div>
</div>
</div>
<div id="cart" class="col-md-7">
{{> cart}}
{{> partials/cart}}
</div>
</div>
</div>

View File

@ -1,23 +1,4 @@
<nav class="navbar navbar-default navbarMenuWrapper">
<div class="container-fluid">
<div class="col-md-8 col-md-offset-2 navbarMenu">
<ul class="nav navbar-nav">
<li {{#unless searchTerm}}class="navActive"{{/unless}}><a href="/">Home</a></li>
{{#each menu.items}}
<li {{#ifCond this.link '==' ../searchTerm}}class="navActive"{{/ifCond}}><a href="/category/{{this.link}}">{{this.title}}</a></li>
{{/each}}
<li class="pull-right col-md-4 searchBarWrapper">
<div class="search-bar-input input-group searchMenuLocation-{{config.menuLocation}} searchProPerRow-{{config.productsPerRow}}">
<input type="text" name="frm_search" id="frm_search" class="form-control" placeholder="Search the shop">
<span class="input-group-btn">
<button class="btn btn-primary" id="btn_search" type="submit">Search</button>
</span>
</div>
</li>
</ul>
</div>
</div>
</nav>
{{> themes/Cloth/front-menu}}
<div class="product-layout col-md-8 col-md-offset-2">
<div class="row">
<div class="col-xs-12 col-md-6 pull-right">
@ -77,26 +58,26 @@
</div>
</div>
</div>
<div class="col-xs-12 col-md-6 pull-left">
<div class="col-xs-12 col-md-6 pull-left">
{{#if result.productImage}}
<div class="title-image-container">
<div class="image-prev image-button"> <i class="fa fa-chevron-left" aria-hidden="true"></i></div>
<img src="{{result.productImage}}" id="product-title-image" class="product-title-image img-responsive" alt="...">
<div class="image-next image-button"> <i class="fa fa-chevron-right" aria-hidden="true"></i></div>
</div>
</div>
{{else}}
<div class="title-image-container">
<img src="/uploads/placeholder.png" id="product-title-image" class="product-title-image img-responsive" alt="...">
</div>
{{/if}}
{{#ifCond images.length '>' 1}}
{{#each images}}
{{#each images}}
<div class="vertical-center top-pad-20 col-xs-6 col-lg-6 col-xl-6">
<img src="{{this.path}}" class="thumbnail-image img-responsive">
</div>
{{/each}}
{{/ifCond}}
{{/ifCond}}
</div>
</div>
</div>
</div>
<input type="hidden" id="productId" value="{{result._id}}">

View File

@ -1,4 +1,4 @@
{{> menu}}
{{> partials/menu}}
<div class="col-lg-9">
<div class="row">
<div class="col-md-8">

View File

@ -1,4 +1,4 @@
{{> menu}}
{{> partials/menu}}
<div class="col-lg-9">
<div class="row">
<div class="col-md-8">

View File

@ -1,4 +1,4 @@
{{> menu}}
{{> partials/menu}}
<div class="col-lg-9">
<div class="row">
<div class="col-md-8">
@ -6,8 +6,8 @@
<ul class="list-group">
{{#each users}}
<li class="list-group-item">
<strong>User:</strong> {{this.usersName}} - ({{this.userEmail}})
<span class="pull-right">
<strong>User:</strong> {{this.usersName}} - ({{this.userEmail}})
<span class="pull-right">
<strong>Role: </strong>
{{#isAnAdmin this.isAdmin}}
<span>Admin</span>