added animations and pageLoad and preLoader
This commit is contained in:
@@ -39,9 +39,13 @@ module.exports.create = [
|
||||
|
||||
// short description
|
||||
body('fa_short_description')
|
||||
.notEmpty().withMessage(v_m['fa'].required.description),
|
||||
.notEmpty().withMessage(v_m['fa'].required.description)
|
||||
.bail()
|
||||
.isLength({max: 200}).withMessage(v_m['fa'].max_char.max200),
|
||||
body('en_short_description')
|
||||
.notEmpty().withMessage(v_m['fa'].required.description),
|
||||
.notEmpty().withMessage(v_m['fa'].required.description)
|
||||
.bail()
|
||||
.isLength({max: 200}).withMessage(v_m['fa'].max_char.max200),
|
||||
|
||||
body('category')
|
||||
.notEmpty().withMessage(v_m['fa'].required.category)
|
||||
@@ -157,9 +161,13 @@ module.exports.update = [
|
||||
|
||||
// short description
|
||||
body('fa_short_description')
|
||||
.notEmpty().withMessage(v_m['fa'].required.description),
|
||||
.notEmpty().withMessage(v_m['fa'].required.description)
|
||||
.bail()
|
||||
.isLength({max: 200}).withMessage(v_m['fa'].max_char.max200),
|
||||
body('en_short_description')
|
||||
.notEmpty().withMessage(v_m['fa'].required.description),
|
||||
.notEmpty().withMessage(v_m['fa'].required.description)
|
||||
.bail()
|
||||
.isLength({max: 200}).withMessage(v_m['fa'].max_char.max200),
|
||||
|
||||
|
||||
body('category')
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
const {body, validationResult} = require('express-validator')
|
||||
const v_m = require('../validation_messages')
|
||||
|
||||
const validationMessages = {
|
||||
fa: {},
|
||||
en: {}
|
||||
}
|
||||
|
||||
module.exports = [
|
||||
[
|
||||
body('method')
|
||||
.notEmpty().withMessage(),
|
||||
body('type')
|
||||
.notEmpty().withMessage(),
|
||||
body('class')
|
||||
.notEmpty().withMessage(),
|
||||
body('pointLoad')
|
||||
.notEmpty().withMessage(),
|
||||
body('distributedLoad')
|
||||
.notEmpty().withMessage(),
|
||||
body('bearingBarPitch')
|
||||
.notEmpty().withMessage(),
|
||||
body('crossBarPitCh')
|
||||
.notEmpty().withMessage(),
|
||||
body('clearSpan')
|
||||
.notEmpty().withMessage(),
|
||||
body('bearingBarThickness')
|
||||
.notEmpty().withMessage(),
|
||||
body('bearingBarHeight')
|
||||
.notEmpty().withMessage()
|
||||
],
|
||||
(req, res) => {
|
||||
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,166 @@
|
||||
const History = require('../models/History')
|
||||
const dateformat = require('dateformat')
|
||||
const {body, validationResult} = require('express-validator')
|
||||
const jimp = require('jimp')
|
||||
const fs = require('fs')
|
||||
const v_m = require('../validation_messages')
|
||||
|
||||
|
||||
module.exports.create = [
|
||||
[
|
||||
body('fa_title')
|
||||
.notEmpty().withMessage(v_m['fa'].required.title),
|
||||
|
||||
body('en_title')
|
||||
.notEmpty().withMessage(v_m['fa'].required.title),
|
||||
|
||||
body('year')
|
||||
.notEmpty().withMessage(v_m['fa'].required.date)
|
||||
.bail()
|
||||
.isNumeric().withMessage(v_m['fa'].format.number)
|
||||
.bail()
|
||||
.isLength({min: 4}).withMessage(v_m['fa'].min_char.min4)
|
||||
.bail()
|
||||
.isLength({max: 4}).withMessage(v_m['fa'].max_char.max4)
|
||||
],
|
||||
(req, res) => {
|
||||
const errors = validationResult(req)
|
||||
if (!errors.isEmpty()) return res.status(422).json({validation: errors.mapped()})
|
||||
if (!req.files || !req.files.image) return res.status(422).json({validation: {image: {msg: v_m['fa'].required.image}}})
|
||||
|
||||
const fileName = 'history_' + Date.now() + '.' + req.files.image.mimetype.split('/')[1]
|
||||
|
||||
const data = {
|
||||
image: fileName,
|
||||
year: Number(req.body.year),
|
||||
history_details: {
|
||||
fa: {
|
||||
title: req.body.fa_title,
|
||||
caption: req.body.fa_caption
|
||||
},
|
||||
en: {
|
||||
title: req.body.en_title,
|
||||
caption: req.body.en_caption
|
||||
}
|
||||
},
|
||||
created_at: dateformat(Date.now(), 'yyyy-mm-dd HH:MM:ss')
|
||||
}
|
||||
|
||||
jimp.read(req.files.image.data)
|
||||
.then(img => {
|
||||
img
|
||||
.resize(380, jimp.AUTO)
|
||||
.cover(380, 260)
|
||||
.write(`./static/uploads/images/history/${fileName}`, cb => {
|
||||
const history = new History(data)
|
||||
history.save(err => {
|
||||
if (err) console.log(err)
|
||||
return res.json(v_m['fa'].response.success_save)
|
||||
})
|
||||
})
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(err)
|
||||
})
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
module.exports.getAll = [
|
||||
(req, res) => {
|
||||
History.find({}).sort({year: 1}).exec((err, data) => {
|
||||
if (err) console.log(err)
|
||||
return res.json(data)
|
||||
})
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
module.exports.getOne = [
|
||||
(req, res) => {
|
||||
History.findById(req.params.id, (err, data) => {
|
||||
if (err) return res.status(404).json(err)
|
||||
return res.json(data)
|
||||
})
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
module.exports.update = [
|
||||
[
|
||||
body('fa_title')
|
||||
.notEmpty().withMessage(v_m['fa'].required.title),
|
||||
|
||||
body('en_title')
|
||||
.notEmpty().withMessage(v_m['fa'].required.title),
|
||||
|
||||
body('year')
|
||||
.notEmpty().withMessage(v_m['fa'].required.date)
|
||||
.bail()
|
||||
.isNumeric().withMessage(v_m['fa'].format.number)
|
||||
.bail()
|
||||
.isLength({min: 4}).withMessage(v_m['fa'].min_char.min4)
|
||||
.bail()
|
||||
.isLength({max: 4}).withMessage(v_m['fa'].max_char.max4)
|
||||
],
|
||||
(req, res) => {
|
||||
const errors = validationResult(req)
|
||||
if (!errors.isEmpty()) return res.status(422).json({validation: errors.mapped()})
|
||||
|
||||
const data = {
|
||||
year: Number(req.body.year),
|
||||
history_details: {
|
||||
fa: {
|
||||
title: req.body.fa_title,
|
||||
caption: req.body.fa_caption
|
||||
},
|
||||
en: {
|
||||
title: req.body.en_title,
|
||||
caption: req.body.en_caption
|
||||
}
|
||||
},
|
||||
updated_at: dateformat(Date.now(), 'yyyy-mm-dd HH:MM:ss')
|
||||
}
|
||||
|
||||
if (req.files && req.files.image) {
|
||||
let fileName = 'history_' + Date.now() + '.' + req.files.image.mimetype.split('/')[1]
|
||||
data.image = fileName
|
||||
jimp.read(req.files.image.data)
|
||||
.then(img => {
|
||||
img
|
||||
.resize(380, jimp.AUTO)
|
||||
.cover(380, 260)
|
||||
.write(`./static/uploads/images/history/${fileName}`, cb => {
|
||||
History.findByIdAndUpdate(req.params.id, data, (err, oldData) => {
|
||||
if (err) console.log(err)
|
||||
fs.unlink(`./static/${oldData.image}`, err => {
|
||||
if (err) console.log(err)
|
||||
return res.json(v_m['fa'].response.success_save)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
.catch(err => {
|
||||
console.log(err)
|
||||
})
|
||||
} else {
|
||||
History.findByIdAndUpdate(req.params.id, data, (err, oldData) => {
|
||||
if (err) console.log(err)
|
||||
return res.json(v_m['fa'].response.success_save)
|
||||
})
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
module.exports.delete = [
|
||||
(req, res) => {
|
||||
History.findByIdAndDelete(req.params.id, (err, data) => {
|
||||
if (err) console.log(err)
|
||||
fs.unlink(`./static/${data.image}`, err => {
|
||||
if (err) console.log(err)
|
||||
return res.json(v_m['fa'].response.success_remove)
|
||||
})
|
||||
})
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,27 @@
|
||||
const mongoose = require('mongoose')
|
||||
|
||||
function image(img) {
|
||||
return '/uploads/images/history/' + img
|
||||
}
|
||||
|
||||
const HistorySchema = mongoose.Schema({
|
||||
image: {type: String, get: image},
|
||||
year: Number,
|
||||
history_details: {
|
||||
fa: {
|
||||
title: String,
|
||||
caption: String
|
||||
},
|
||||
en: {
|
||||
title: String,
|
||||
caption: String
|
||||
}
|
||||
},
|
||||
created_at: String,
|
||||
updated_at: String
|
||||
}, {
|
||||
toObject: {getters: true},
|
||||
toJSON: {getters: true}
|
||||
})
|
||||
|
||||
module.exports = mongoose.model('History', HistorySchema)
|
||||
@@ -10,6 +10,7 @@ const projectController = require('../controllers/projectController')
|
||||
const contactPageController = require('../controllers/contactPageController')
|
||||
const contactUsReasonController = require('../controllers/contactUsReasonController')
|
||||
const mainCatalogController = require('../controllers/mainCatalogController')
|
||||
const historyController = require('../controllers/historyController')
|
||||
|
||||
/////////////////////////////////////////////////////////// routes
|
||||
//////////////// slider
|
||||
@@ -63,4 +64,9 @@ router.delete('/contact/reason/:id', contactUsReasonController.delete)
|
||||
///////////////// main catalog
|
||||
router.post('/catalog', mainCatalogController.create)
|
||||
|
||||
///////////////// history
|
||||
router.post('/history', historyController.create)
|
||||
router.put('/history/:id', historyController.update)
|
||||
router.delete('/history/:id', historyController.delete)
|
||||
|
||||
module.exports = router
|
||||
|
||||
@@ -11,6 +11,7 @@ const projectController = require('../controllers/projectController')
|
||||
const contactPageController = require('../controllers/contactPageController')
|
||||
const contactUsReasonController = require('../controllers/contactUsReasonController')
|
||||
const mainCatalogController = require('../controllers/mainCatalogController')
|
||||
const historyController = require('../controllers/historyController')
|
||||
/////////////////////////////////////////////////////////// routes
|
||||
|
||||
//////////////// slider
|
||||
@@ -46,4 +47,8 @@ router.get('/contact/reason', contactUsReasonController.getAll)
|
||||
//////////////// main catalog
|
||||
router.get('/catalog', mainCatalogController.get)
|
||||
|
||||
//////////////// history
|
||||
router.get('/history', historyController.getAll)
|
||||
router.get('/history/:id', historyController.getOne)
|
||||
|
||||
module.exports = router
|
||||
|
||||
Reference in New Issue
Block a user