diff --git a/config/passport.config.js b/config/passport.config.js index d50607f..9164603 100644 --- a/config/passport.config.js +++ b/config/passport.config.js @@ -5,14 +5,14 @@ function initialize(passport, getUserByEmail, getUserById) { const authenticateUser = async (email, password, done) => { const user = getUserByEmail(email); if (user == null) { - return done(null, false, { message: 'Пользователь с такой почтой не найден' }); + return done(null, false, { message: 'Администратор с такой почтой не найден!' }); } try { if (await bcrypt.compare(password, user.password)) { return done(null, user); } else { - return done(null, false, { message: 'Неверный пароль' }); + return done(null, false, { message: 'Неверный пароль!' }); } } catch (error) { return done(error); diff --git a/config/routes/admin.js b/config/routes/admin.js index c1c5490..192fa93 100644 --- a/config/routes/admin.js +++ b/config/routes/admin.js @@ -11,8 +11,9 @@ function checkNotAuthenticated(req, res, next) { } function loginRoute(req, res) { - res.render('admin') - + res.render('admin/admin', { + title: 'Digital-Store | Вход в панель управления сайтом' + }) } // function registerRoute(req, res) { diff --git a/config/routes/routes.js b/config/routes/routes.js index e991c29..59a5624 100644 --- a/config/routes/routes.js +++ b/config/routes/routes.js @@ -13,6 +13,7 @@ function indexRoute(req, res, dbo) { const categories = result.map(category => category.title[0].toUpperCase() + category.title.slice(1)); res.render('index', { pageName: 'index', + title: 'Digital-Store | Главная', categories }); }); @@ -134,30 +135,37 @@ function onePageItemRoute(req, res, dbo) { function howToBuyRoute(req, res) { res.render('how-to-buy', { - pageName: 'how-to-buy' + pageName: 'how-to-buy', + title: 'Digital-Store | Как купить товар' }); } function contactsRoute(req, res) { res.render('contacts', { - pageName: 'contacts' + pageName: 'contacts', + title: 'Digital-Store | Контакты' }); } function commentsRoute(req, res) { res.render('comments', { - pageName: 'comments' + pageName: 'comments', + title: 'Digital-Store | Отзывы' }); } function myOrdersRoute(req, res) { res.render('my-orders', { - pageName: 'my-orders' + pageName: 'my-orders', + title: 'Digital-Store | Мои покупки' }); } function controlPanelRoute(req, res) { - res.render('control-panel', {name: req.user.name}); + res.render('admin/control-panel', { + name: req.user.name, + title: 'Digital-Store | Панель управления сайтом' + }); } module.exports = function (server, db) { diff --git a/dist/public/css/style.css b/dist/public/css/style.css index ba94fd6..411cc52 100644 --- a/dist/public/css/style.css +++ b/dist/public/css/style.css @@ -49,7 +49,7 @@ hr { width: 300px; position: fixed; right: 30px; - z-index: 1; + z-index: 2; } .block-title { @@ -654,4 +654,20 @@ footer { display: flex; justify-content: center; align-items: center; +} + +/* Control Panel login */ +.login-form { + margin-top: 7rem; +} +.login-form__title h1 { + text-align: center; + font-weight: 400; + font-size: 18px; +} +.login-form__content { + margin-top: 2rem; +} +.login-form__content button { + width: 100%; } \ No newline at end of file diff --git a/dist/public/js/bundle.js b/dist/public/js/bundle.js index c3b8ef0..99fec62 100644 --- a/dist/public/js/bundle.js +++ b/dist/public/js/bundle.js @@ -3918,7 +3918,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) * /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"HeaderComponent\", function() { return HeaderComponent; });\n/* harmony import */ var _core_component__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../core/component */ \"./src/core/component.js\");\n/* harmony import */ var _other_counter__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../other/counter */ \"./src/other/counter.js\");\nfunction _typeof(obj) { if (typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; }; } return _typeof(obj); }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }\n\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }\n\nfunction _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === \"object\" || typeof call === \"function\")) { return call; } return _assertThisInitialized(self); }\n\nfunction _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\"); } return self; }\n\nfunction _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }\n\nfunction _inherits(subClass, superClass) { if (typeof superClass !== \"function\" && superClass !== null) { throw new TypeError(\"Super expression must either be null or a function\"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }\n\nfunction _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }\n\n\n\nvar HeaderComponent =\n/*#__PURE__*/\nfunction (_Component) {\n _inherits(HeaderComponent, _Component);\n\n function HeaderComponent(id) {\n _classCallCheck(this, HeaderComponent);\n\n return _possibleConstructorReturn(this, _getPrototypeOf(HeaderComponent).call(this, id));\n }\n\n _createClass(HeaderComponent, [{\n key: \"init\",\n value: function init() {\n var currentPage = this.$el.querySelector('#desktop-nav');\n var pages = Array.from(this.$el.querySelectorAll('#page'));\n pages.forEach(function (li) {\n return li.dataset.page === currentPage.dataset.current ? li.classList.add('active') : false;\n }); // ф-я счетика товаров\n\n localStorage.getItem('cart') ? Object(_other_counter__WEBPACK_IMPORTED_MODULE_1__[\"insertCount\"])('counter', JSON.parse(localStorage.getItem('cart'))) : false;\n }\n }]);\n\n return HeaderComponent;\n}(_core_component__WEBPACK_IMPORTED_MODULE_0__[\"Component\"]);\n\n//# sourceURL=webpack:///./src/components/header.component.js?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"HeaderComponent\", function() { return HeaderComponent; });\n/* harmony import */ var _core_component__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../core/component */ \"./src/core/component.js\");\n/* harmony import */ var _other_counter__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../other/counter */ \"./src/other/counter.js\");\nfunction _typeof(obj) { if (typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; }; } return _typeof(obj); }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }\n\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }\n\nfunction _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === \"object\" || typeof call === \"function\")) { return call; } return _assertThisInitialized(self); }\n\nfunction _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\"); } return self; }\n\nfunction _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }\n\nfunction _inherits(subClass, superClass) { if (typeof superClass !== \"function\" && superClass !== null) { throw new TypeError(\"Super expression must either be null or a function\"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }\n\nfunction _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }\n\n\n\nvar HeaderComponent =\n/*#__PURE__*/\nfunction (_Component) {\n _inherits(HeaderComponent, _Component);\n\n function HeaderComponent(id) {\n _classCallCheck(this, HeaderComponent);\n\n return _possibleConstructorReturn(this, _getPrototypeOf(HeaderComponent).call(this, id));\n }\n\n _createClass(HeaderComponent, [{\n key: \"init\",\n value: function init() {\n if (this.$el) {\n var currentPage = this.$el.querySelector('#desktop-nav');\n var pages = Array.from(this.$el.querySelectorAll('#page'));\n pages.forEach(function (li) {\n return li.dataset.page === currentPage.dataset.current ? li.classList.add('active') : false;\n }); // ф-я счетика товаров\n\n localStorage.getItem('cart') ? Object(_other_counter__WEBPACK_IMPORTED_MODULE_1__[\"insertCount\"])('counter', JSON.parse(localStorage.getItem('cart'))) : false;\n }\n }\n }]);\n\n return HeaderComponent;\n}(_core_component__WEBPACK_IMPORTED_MODULE_0__[\"Component\"]);\n\n//# sourceURL=webpack:///./src/components/header.component.js?"); /***/ }), @@ -3990,7 +3990,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) * /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"Modal\", function() { return Modal; });\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }\n\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }\n\nvar Modal =\n/*#__PURE__*/\nfunction () {\n function Modal(id, open, close) {\n _classCallCheck(this, Modal);\n\n this.$el = document.getElementById(id);\n this.open = document.getElementById(open);\n this.close = document.getElementById(close);\n this.init();\n }\n\n _createClass(Modal, [{\n key: \"init\",\n value: function init() {\n if (this.open != null) {\n this.open.addEventListener('click', openHandler.bind(this));\n this.close.addEventListener('click', closeHandler.bind(this));\n }\n }\n }, {\n key: \"show\",\n value: function show() {\n this.$el.classList.remove('hide');\n document.body.style.overflowY = 'hidden';\n }\n }, {\n key: \"hide\",\n value: function hide() {\n this.$el.classList.add('hide');\n document.body.style.overflowY = '';\n }\n }]);\n\n return Modal;\n}();\n\nfunction openHandler(e) {\n this.show();\n}\n\nfunction closeHandler() {\n this.hide();\n}\n\n//# sourceURL=webpack:///./src/core/modal.js?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"Modal\", function() { return Modal; });\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }\n\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }\n\nvar Modal =\n/*#__PURE__*/\nfunction () {\n function Modal(id, open, close) {\n _classCallCheck(this, Modal);\n\n this.$el = document.getElementById(id);\n this.open = document.getElementById(open);\n this.close = document.getElementById(close);\n this.init();\n }\n\n _createClass(Modal, [{\n key: \"init\",\n value: function init() {\n if (this.open != null) {\n this.open.addEventListener('click', openHandler.bind(this));\n this.close.addEventListener('click', closeHandler.bind(this));\n }\n }\n }, {\n key: \"show\",\n value: function show() {\n this.$el.classList.remove('hide');\n document.body.style.overflowY = 'hidden';\n }\n }, {\n key: \"hide\",\n value: function hide() {\n this.$el.classList.add('hide');\n document.body.style.overflowY = '';\n }\n }]);\n\n return Modal;\n}();\n\nfunction openHandler() {\n this.show();\n}\n\nfunction closeHandler() {\n this.hide();\n}\n\n//# sourceURL=webpack:///./src/core/modal.js?"); /***/ }), @@ -4014,7 +4014,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _com /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"CartModal\", function() { return CartModal; });\n/* harmony import */ var _core_modal__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../core/modal */ \"./src/core/modal.js\");\n/* harmony import */ var _other_counter__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../other/counter */ \"./src/other/counter.js\");\nfunction _typeof(obj) { if (typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; }; } return _typeof(obj); }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }\n\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }\n\nfunction _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === \"object\" || typeof call === \"function\")) { return call; } return _assertThisInitialized(self); }\n\nfunction _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }\n\nfunction _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\"); } return self; }\n\nfunction _inherits(subClass, superClass) { if (typeof superClass !== \"function\" && superClass !== null) { throw new TypeError(\"Super expression must either be null or a function\"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }\n\nfunction _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }\n\n\n\nvar CartModal =\n/*#__PURE__*/\nfunction (_Modal) {\n _inherits(CartModal, _Modal);\n\n function CartModal(id, open, close, _ref) {\n var _this;\n\n var items = _ref.items;\n\n _classCallCheck(this, CartModal);\n\n _this = _possibleConstructorReturn(this, _getPrototypeOf(CartModal).call(this, id, open, close));\n _this.items = items;\n\n _this.open.addEventListener('click', _this.openHandler.bind(_assertThisInitialized(_this)));\n\n _this.close.addEventListener('click', _this.closeHandler.bind(_assertThisInitialized(_this)));\n\n _this.list = _this.$el.querySelector('#modalList');\n return _this;\n }\n\n _createClass(CartModal, [{\n key: \"closeHandler\",\n value: function closeHandler() {\n this.removeItem = null;\n this.makePay = null;\n }\n }, {\n key: \"openHandler\",\n value: function openHandler() {\n this.removeItem != null ? this.list.addEventListener('click', this.removeItem.bind(this)) : false;\n this.makePay != null ? this.$el.querySelector('#purchaseInfo').addEventListener('submit', this.makePay.bind(this)) : false;\n this.list.innerHTML = '';\n this.insertItems(this.list);\n }\n }, {\n key: \"insertItems\",\n value: function insertItems(list) {\n var _this2 = this;\n\n if (localStorage.getItem('cart')) {\n var items = JSON.parse(localStorage.getItem('cart'));\n\n if (items.length == 0) {\n list.innerHTML = '

Вы не добавили ни один товар

';\n this.$el.querySelector('#purchaseInfo').classList.add('hide');\n } else {\n this.$el.querySelector('#purchaseInfo').classList.remove('hide');\n }\n\n items.forEach(function (item) {\n return _this2.list.innerHTML += \"
\").concat(item.title, \"
\\u0412 \\u043D\\u0430\\u043B\\u0438\\u0447\\u0438\\u0438: \").concat(item.count, \" (\\u0448\\u0442)
\").concat(parseFloat(item.price).toFixed(2), \"\\u20BD
close
\");\n });\n Object(_other_counter__WEBPACK_IMPORTED_MODULE_1__[\"insertCount\"])('modalCounter', this.items.cart);\n Object(_other_counter__WEBPACK_IMPORTED_MODULE_1__[\"insertCount\"])('counter', this.items.cart);\n this.insertTotalPrice('totalPrice', this.items.cart);\n } else {\n list.innerHTML = '

Вы не добавили ни один товар

';\n }\n }\n }, {\n key: \"removeItem\",\n value: function removeItem(e) {\n if (e.target.id === 'removeItem') {\n var id = e.target.dataset.id;\n var index;\n this.items.cart.forEach(function (item, i) {\n return item.id === id ? index = i : false;\n });\n this.items.cart.splice(index, 1);\n localStorage.setItem('cart', JSON.stringify(this.items.cart));\n this.list.innerHTML = '';\n this.insertItems(this.list);\n this.defaultBtnColor(id);\n }\n }\n }, {\n key: \"insertTotalPrice\",\n value: function insertTotalPrice(id, array) {\n var totalPrice = 0;\n array.forEach(function (item) {\n return totalPrice += parseFloat(item.price);\n });\n this.$el.querySelector(\"#\".concat(id)).innerHTML = \"\".concat(totalPrice.toFixed(2), \"\\u20BD\");\n }\n }, {\n key: \"makePay\",\n value: function makePay(e) {\n e.preventDefault();\n var payInfo = {\n items: this.items.cart.map(function (item) {\n return {\n id: item.id,\n title: item.title,\n price: parseFloat(item.price)\n };\n })\n };\n var totalPrice = 0;\n payInfo.items.forEach(function (item) {\n return totalPrice += parseFloat(item.price);\n });\n payInfo.totalPrice = Math.round(totalPrice * 100) / 100;\n payInfo.payMethod = this.$el.querySelector('.payment-field #payment').value;\n payInfo.phone = this.$el.querySelector('.phone-field #phone').value;\n payInfo.email = this.$el.querySelector('.email-field #email').value;\n console.log('Pay info:', payInfo);\n }\n }, {\n key: \"defaultBtnColor\",\n value: function defaultBtnColor(id) {\n if (this.items.roster) {\n if (this.items.roster.querySelector(\"#rosterButtons[data-id=\\\"\".concat(id, \"\\\"] #addItem\"))) {\n this.items.roster.querySelector(\"#rosterButtons[data-id=\\\"\".concat(id, \"\\\"] #addItem\")).classList.remove('orange');\n this.items.roster.querySelector(\"#rosterButtons[data-id=\\\"\".concat(id, \"\\\"] #addItem i\")).innerHTML = 'shopping_cart';\n }\n }\n }\n }]);\n\n return CartModal;\n}(_core_modal__WEBPACK_IMPORTED_MODULE_0__[\"Modal\"]);\n\n//# sourceURL=webpack:///./src/modals/cart.modal.js?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"CartModal\", function() { return CartModal; });\n/* harmony import */ var _core_modal__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../core/modal */ \"./src/core/modal.js\");\n/* harmony import */ var _other_counter__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../other/counter */ \"./src/other/counter.js\");\nfunction _typeof(obj) { if (typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol && obj !== Symbol.prototype ? \"symbol\" : typeof obj; }; } return _typeof(obj); }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if (\"value\" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }\n\nfunction _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }\n\nfunction _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === \"object\" || typeof call === \"function\")) { return call; } return _assertThisInitialized(self); }\n\nfunction _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }\n\nfunction _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\"); } return self; }\n\nfunction _inherits(subClass, superClass) { if (typeof superClass !== \"function\" && superClass !== null) { throw new TypeError(\"Super expression must either be null or a function\"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }\n\nfunction _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }\n\n\n\nvar CartModal =\n/*#__PURE__*/\nfunction (_Modal) {\n _inherits(CartModal, _Modal);\n\n function CartModal(id, open, close, _ref) {\n var _this;\n\n var items = _ref.items;\n\n _classCallCheck(this, CartModal);\n\n _this = _possibleConstructorReturn(this, _getPrototypeOf(CartModal).call(this, id, open, close));\n _this.items = items;\n\n if (_this.$el) {\n _this.open.addEventListener('click', _this.openHandler.bind(_assertThisInitialized(_this)));\n\n _this.close.addEventListener('click', _this.closeHandler.bind(_assertThisInitialized(_this)));\n\n _this.list = _this.$el.querySelector('#modalList');\n }\n\n return _this;\n }\n\n _createClass(CartModal, [{\n key: \"closeHandler\",\n value: function closeHandler() {\n this.removeItem = null;\n this.makePay = null;\n }\n }, {\n key: \"openHandler\",\n value: function openHandler() {\n this.removeItem != null ? this.list.addEventListener('click', this.removeItem.bind(this)) : false;\n this.makePay != null ? this.$el.querySelector('#purchaseInfo').addEventListener('submit', this.makePay.bind(this)) : false;\n this.list.innerHTML = '';\n this.insertItems(this.list);\n }\n }, {\n key: \"insertItems\",\n value: function insertItems(list) {\n var _this2 = this;\n\n if (localStorage.getItem('cart')) {\n var items = JSON.parse(localStorage.getItem('cart'));\n\n if (items.length == 0) {\n list.innerHTML = '

Вы не добавили ни один товар

';\n this.$el.querySelector('#purchaseInfo').classList.add('hide');\n } else {\n this.$el.querySelector('#purchaseInfo').classList.remove('hide');\n }\n\n items.forEach(function (item) {\n return _this2.list.innerHTML += \"
\").concat(item.title, \"
\\u0412 \\u043D\\u0430\\u043B\\u0438\\u0447\\u0438\\u0438: \").concat(item.count, \" (\\u0448\\u0442)
\").concat(parseFloat(item.price).toFixed(2), \"\\u20BD
close
\");\n });\n Object(_other_counter__WEBPACK_IMPORTED_MODULE_1__[\"insertCount\"])('modalCounter', this.items.cart);\n Object(_other_counter__WEBPACK_IMPORTED_MODULE_1__[\"insertCount\"])('counter', this.items.cart);\n this.insertTotalPrice('totalPrice', this.items.cart);\n } else {\n list.innerHTML = '

Вы не добавили ни один товар

';\n }\n }\n }, {\n key: \"removeItem\",\n value: function removeItem(e) {\n if (e.target.id === 'removeItem') {\n var id = e.target.dataset.id;\n var index;\n this.items.cart.forEach(function (item, i) {\n return item.id === id ? index = i : false;\n });\n this.items.cart.splice(index, 1);\n localStorage.setItem('cart', JSON.stringify(this.items.cart));\n this.list.innerHTML = '';\n this.insertItems(this.list);\n this.defaultBtnColor(id);\n }\n }\n }, {\n key: \"insertTotalPrice\",\n value: function insertTotalPrice(id, array) {\n var totalPrice = 0;\n array.forEach(function (item) {\n return totalPrice += parseFloat(item.price);\n });\n this.$el.querySelector(\"#\".concat(id)).innerHTML = \"\".concat(totalPrice.toFixed(2), \"\\u20BD\");\n }\n }, {\n key: \"makePay\",\n value: function makePay(e) {\n e.preventDefault();\n var payInfo = {\n items: this.items.cart.map(function (item) {\n return {\n id: item.id,\n title: item.title,\n price: parseFloat(item.price)\n };\n })\n };\n var totalPrice = 0;\n payInfo.items.forEach(function (item) {\n return totalPrice += parseFloat(item.price);\n });\n payInfo.totalPrice = Math.round(totalPrice * 100) / 100;\n payInfo.payMethod = this.$el.querySelector('.payment-field #payment').value;\n payInfo.phone = this.$el.querySelector('.phone-field #phone').value;\n payInfo.email = this.$el.querySelector('.email-field #email').value;\n console.log('Pay info:', payInfo);\n }\n }, {\n key: \"defaultBtnColor\",\n value: function defaultBtnColor(id) {\n if (this.items.roster) {\n if (this.items.roster.querySelector(\"#rosterButtons[data-id=\\\"\".concat(id, \"\\\"] #addItem\"))) {\n this.items.roster.querySelector(\"#rosterButtons[data-id=\\\"\".concat(id, \"\\\"] #addItem\")).classList.remove('orange');\n this.items.roster.querySelector(\"#rosterButtons[data-id=\\\"\".concat(id, \"\\\"] #addItem i\")).innerHTML = 'shopping_cart';\n }\n }\n }\n }]);\n\n return CartModal;\n}(_core_modal__WEBPACK_IMPORTED_MODULE_0__[\"Modal\"]);\n\n//# sourceURL=webpack:///./src/modals/cart.modal.js?"); /***/ }), diff --git a/dist/public/js/materialize.config.js b/dist/public/js/materialize.config.js index fb2d54e..4094f46 100644 --- a/dist/public/js/materialize.config.js +++ b/dist/public/js/materialize.config.js @@ -2,4 +2,5 @@ document.addEventListener('DOMContentLoaded', function () { // Nav-mobile menu init M.Sidenav.init(document.querySelectorAll('.sidenav')) M.FormSelect.init(document.querySelectorAll('select')) + M.updateTextFields(); }); \ No newline at end of file diff --git a/dist/views/admin.pug b/dist/views/admin.pug deleted file mode 100644 index 1bfbbb9..0000000 --- a/dist/views/admin.pug +++ /dev/null @@ -1,11 +0,0 @@ -if messages.error - h3 #{messages.error} -h1 Login Page -form(action="/admin" method="POST") - div - label(for="email") Email - input(type="email" id="email" name="email" required) - div - label(for="password") Password - input(type="password" id="password" name="password" required) - button(type="submit") Login \ No newline at end of file diff --git a/dist/views/admin/admin.pug b/dist/views/admin/admin.pug new file mode 100644 index 0000000..22eb1b5 --- /dev/null +++ b/dist/views/admin/admin.pug @@ -0,0 +1,25 @@ +include ../assets/head.pug +main + if messages.error + #notification + .card-panel(style="background-color: #f34d53;") + span.white-text #{messages.error} + .container + .row + .col.m6.offset-m3.s12 + .login-form + .login-form__content + .login-form__title + h1 Вход в панель управления + .login-form__content + form(action="/admin" method="POST") + div.input-field + i.material-icons.prefix email + label(for="email") Почта + input(type="email" id="email" name="email" required) + div.input-field + i.material-icons.prefix lock + label(for="password") Пароль + input(type="password" id="password" name="password" required) + button(class="waves-light btn-large" type="submit") Вход +include ../assets/scripts.pug \ No newline at end of file diff --git a/dist/views/control-panel.pug b/dist/views/admin/control-panel.pug similarity index 82% rename from dist/views/control-panel.pug rename to dist/views/admin/control-panel.pug index d0ee6ef..d40fb14 100644 --- a/dist/views/control-panel.pug +++ b/dist/views/admin/control-panel.pug @@ -1,3 +1,4 @@ +include ../assets/head.pug h1 Control-Panel h3 Привет #{name} form(action="/logout?_method=DELETE" method="POST") diff --git a/dist/views/assets/head.pug b/dist/views/assets/head.pug index aa53a9a..c2bb91a 100644 --- a/dist/views/assets/head.pug +++ b/dist/views/assets/head.pug @@ -3,7 +3,7 @@ html(lang='ru') head meta(charset='utf-8') meta(http-equiv='Cоntent-Type' cоntent='text/html;' charset='utf-8') - title Digital Shop + title #{title} // Materialize CSS link(rel="stylesheet", href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css") // Style CSS diff --git a/dist/views/assets/scripts.pug b/dist/views/assets/scripts.pug new file mode 100644 index 0000000..4e41b15 --- /dev/null +++ b/dist/views/assets/scripts.pug @@ -0,0 +1,5 @@ +// Maretialize JS +script(src='https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js') +// Script JS +script(src='../js/bundle.js') +script(src='../js/materialize.config.js') \ No newline at end of file diff --git a/dist/views/assets/templates/footer.pug b/dist/views/assets/templates/footer.pug index 0bfeba9..5c37905 100644 --- a/dist/views/assets/templates/footer.pug +++ b/dist/views/assets/templates/footer.pug @@ -3,8 +3,4 @@ footer .waves-effect.waves-light.pulse.cart-btn(id="cartOpen") i.material-icons shopping_cart span#counter.counter 0 -// Maretialize JS -script(src='https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js') -// Script JS -script(src='../js/bundle.js') -script(src='../js/materialize.config.js') +include ../scripts.pug diff --git a/src/components/header.component.js b/src/components/header.component.js index bae5d3a..d7521ac 100644 --- a/src/components/header.component.js +++ b/src/components/header.component.js @@ -7,10 +7,12 @@ export class HeaderComponent extends Component { } init() { - const currentPage = this.$el.querySelector('#desktop-nav'); - const pages = Array.from(this.$el.querySelectorAll('#page')); - pages.forEach(li => li.dataset.page === currentPage.dataset.current ? li.classList.add('active') : false); - // ф-я счетика товаров - localStorage.getItem('cart') ? insertCount('counter', JSON.parse(localStorage.getItem('cart'))) : false; + if (this.$el) { + const currentPage = this.$el.querySelector('#desktop-nav'); + const pages = Array.from(this.$el.querySelectorAll('#page')); + pages.forEach(li => li.dataset.page === currentPage.dataset.current ? li.classList.add('active') : false); + // ф-я счетика товаров + localStorage.getItem('cart') ? insertCount('counter', JSON.parse(localStorage.getItem('cart'))) : false; + } } } \ No newline at end of file diff --git a/src/core/modal.js b/src/core/modal.js index 096b08b..1c54ed1 100644 --- a/src/core/modal.js +++ b/src/core/modal.js @@ -24,7 +24,7 @@ export class Modal { } } -function openHandler(e) { +function openHandler() { this.show(); } diff --git a/src/modals/cart.modal.js b/src/modals/cart.modal.js index d9178e0..1841c1c 100644 --- a/src/modals/cart.modal.js +++ b/src/modals/cart.modal.js @@ -5,9 +5,11 @@ export class CartModal extends Modal { constructor(id, open, close, {items}) { super(id, open, close); this.items = items; - this.open.addEventListener('click', this.openHandler.bind(this)); - this.close.addEventListener('click', this.closeHandler.bind(this)); - this.list = this.$el.querySelector('#modalList'); + if (this.$el) { + this.open.addEventListener('click', this.openHandler.bind(this)); + this.close.addEventListener('click', this.closeHandler.bind(this)); + this.list = this.$el.querySelector('#modalList'); + } } closeHandler() {