Fix image directories issue
parent
c4e59e9cd0
commit
cdcc2791cd
|
@ -571,7 +571,7 @@ router.get('/product/delete/:id', common.restrict, (req, res) => {
|
||||||
// users
|
// users
|
||||||
router.get('/users', common.restrict, (req, res) => {
|
router.get('/users', common.restrict, (req, res) => {
|
||||||
let db = req.app.db;
|
let db = req.app.db;
|
||||||
common.dbQuery(db.users, {}, null, null, (err, users) => {
|
db.users.find({}).toArray((err, users) => {
|
||||||
if(err){
|
if(err){
|
||||||
console.info(err.stack);
|
console.info(err.stack);
|
||||||
}
|
}
|
||||||
|
@ -1083,7 +1083,6 @@ router.post('/product/setasmainimage', common.restrict, (req, res) => {
|
||||||
|
|
||||||
// update the productImage to the db
|
// update the productImage to the db
|
||||||
db.products.update({_id: common.getId(req.body.product_id)}, {$set: {productImage: req.body.productImage}}, {multi: false}, (err, numReplaced) => {
|
db.products.update({_id: common.getId(req.body.product_id)}, {$set: {productImage: req.body.productImage}}, {multi: false}, (err, numReplaced) => {
|
||||||
console.log(err, numReplaced);
|
|
||||||
if(err){
|
if(err){
|
||||||
res.status(400).json({message: 'Unable to set as main image. Please try again.'});
|
res.status(400).json({message: 'Unable to set as main image. Please try again.'});
|
||||||
}else{
|
}else{
|
||||||
|
@ -1162,7 +1161,7 @@ router.post('/file/upload', common.restrict, upload.single('upload_file'), (req,
|
||||||
});
|
});
|
||||||
|
|
||||||
// get the product form the DB
|
// get the product form the DB
|
||||||
db.products.findOne({_id: common.getId(req.body.directory)}, (err, product) => {
|
db.products.findOne({_id: common.getId(req.body.productId)}, (err, product) => {
|
||||||
if(err){
|
if(err){
|
||||||
console.info(err.stack);
|
console.info(err.stack);
|
||||||
}
|
}
|
||||||
|
@ -1170,24 +1169,24 @@ router.post('/file/upload', common.restrict, upload.single('upload_file'), (req,
|
||||||
|
|
||||||
// if there isn't a product featured image, set this one
|
// if there isn't a product featured image, set this one
|
||||||
if(!product.productImage){
|
if(!product.productImage){
|
||||||
db.products.update({_id: common.getId(req.body.directory)}, {$set: {productImage: imagePath}}, {multi: false}, (err, numReplaced) => {
|
db.products.update({_id: common.getId(req.body.productId)}, {$set: {productImage: imagePath}}, {multi: false}, (err, numReplaced) => {
|
||||||
if(err){
|
if(err){
|
||||||
console.info(err.stack);
|
console.info(err.stack);
|
||||||
}
|
}
|
||||||
req.session.message = 'File uploaded successfully';
|
req.session.message = 'File uploaded successfully';
|
||||||
req.session.messageType = 'success';
|
req.session.messageType = 'success';
|
||||||
res.redirect('/admin/product/edit/' + req.body.directory);
|
res.redirect('/admin/product/edit/' + req.body.productId);
|
||||||
});
|
});
|
||||||
}else{
|
}else{
|
||||||
req.session.message = 'File uploaded successfully';
|
req.session.message = 'File uploaded successfully';
|
||||||
req.session.messageType = 'success';
|
req.session.messageType = 'success';
|
||||||
res.redirect('/admin/product/edit/' + req.body.directory);
|
res.redirect('/admin/product/edit/' + req.body.productId);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}else{
|
}else{
|
||||||
req.session.message = 'File upload error. Please select a file.';
|
req.session.message = 'File upload error. Please select a file.';
|
||||||
req.session.messageType = 'danger';
|
req.session.messageType = 'danger';
|
||||||
res.redirect('/admin/product/edit/' + req.body.directory);
|
res.redirect('/admin/product/edit/' + req.body.productId);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -110,11 +110,11 @@
|
||||||
<h2>Product images</h2>
|
<h2>Product images</h2>
|
||||||
{{#if images}}
|
{{#if images}}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-10 col-md-offset-2">
|
<div class="col-md-10 col-md-offset-2">
|
||||||
{{#each images}}
|
{{#each images}}
|
||||||
<div class="col-md-3">
|
<div class="col-md-3">
|
||||||
<p>
|
<p>
|
||||||
<a data-id="{{this.path}}" class="btn-delete-image btn btn-danger btn-sm">Delete</a>
|
<a data-id="{{this.path}}" class="btn-delete-image btn btn-danger btn-sm">Delete</a>
|
||||||
{{#ifCond this.productImage '==' true}}
|
{{#ifCond this.productImage '==' true}}
|
||||||
<span class="label label-info">main image</span>
|
<span class="label label-info">main image</span>
|
||||||
{{else}}
|
{{else}}
|
||||||
|
@ -148,7 +148,8 @@
|
||||||
<span class="btn btn-info btn-file">
|
<span class="btn btn-info btn-file">
|
||||||
Select file<input type="file" name="upload_file" id="upload_file">
|
Select file<input type="file" name="upload_file" id="upload_file">
|
||||||
</span>
|
</span>
|
||||||
<input type="hidden" id="directory" name="directory" value="{{result._id}}"/>
|
<input type="hidden" id="productId" name="productId" value="{{result._id}}"/>
|
||||||
|
<input type="hidden" id="directory" name="directory" value="{{result.productPermalink}}"/>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
|
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
|
||||||
|
@ -162,7 +163,7 @@
|
||||||
<link href="https://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.2/summernote.css" rel="stylesheet">
|
<link href="https://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.2/summernote.css" rel="stylesheet">
|
||||||
<script>
|
<script>
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
$('#editor').summernote({
|
$('#editor').summernote({
|
||||||
height: 300,
|
height: 300,
|
||||||
minHeight: null
|
minHeight: null
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue