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>

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">

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,4 +1,4 @@
{{> menu}}
{{> partials/menu}}
<div class="col-lg-9">
<div class="row">
<div class="col-md-12">

View File

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

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">

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">

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">