diff --git a/config/routes/routes.js b/config/routes/routes.js index 0121040..af52793 100644 --- a/config/routes/routes.js +++ b/config/routes/routes.js @@ -44,6 +44,20 @@ function getItemsRoute(req, res, db) { items.sort((a, b) => b.price - a.price) // фильтр по убыванию по цене res.send(items); }); + } else if (!req.query.option && req.query.category && req.query.sorting === 'older') { + dbo.collection('storeInfo').find().toArray((err, result) => { + if (err) throw err; + const items = result[0].items[req.query.category]; + items.sort((a, b) => new Date(a.date) - new Date(b.date)); // фильтр по возрастанию пр дате + res.send(items); + }); + } else if (!req.query.option && req.query.category && req.query.sorting === 'newer') { + dbo.collection('storeInfo').find().toArray((err, result) => { + if (err) throw err; + const items = result[0].items[req.query.category]; + items.sort((a, b) => new Date(b.date) - new Date(a.date)) // фильтр по возрастанию пр дате + res.send(items); + }); } else if (!req.query.option && req.query.category) { dbo.collection('storeInfo').find().toArray((err, result) => { if (err) throw err; @@ -68,6 +82,20 @@ function getItemsRoute(req, res, db) { Object.values(items).forEach(arr => arr.sort((a, b) => b.price - a.price)) // фильтр по убыванию по цене res.send(items); }) + } else if (req.query.option && req.query.sorting === 'older') { + dbo.collection('storeInfo').find().toArray((err, result) => { + if (err) throw err; + const items = result[0].items; + Object.values(items).forEach(arr => arr.sort((a, b) => new Date(a.date) - new Date(b.date))) // фильтр по возрастанию пр дате + res.send(items); + }); + } else if (req.query.option && req.query.sorting === 'newer') { + dbo.collection('storeInfo').find().toArray((err, result) => { + if (err) throw err; + const items = result[0].items; + Object.values(items).forEach(arr => arr.sort((a, b) => new Date(b.date) - new Date(a.date))) // фильтр по возрастанию пр дате + res.send(items); + }); } else { res.send('Запрос неверный'); } @@ -95,7 +123,8 @@ function onePageItemRoute(req, res, db) { count: item.count, category: item.category[0].toUpperCase() + item.category.slice(1), price: item.price, - description: item.description + description: item.description, + date: item.date }); } } diff --git a/dist/public/js/bundle.js b/dist/public/js/bundle.js index d61a3c5..b8c2ef5 100644 --- a/dist/public/js/bundle.js +++ b/dist/public/js/bundle.js @@ -3906,7 +3906,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__, \"CategoryComponent\", function() { return CategoryComponent; });\n/* harmony import */ var _core_component__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../core/component */ \"./src/js/core/component.js\");\n/* harmony import */ var _services_api_service__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../services/api.service */ \"./src/js/services/api.service.js\");\n/* harmony import */ var _templates_itemsOne_template__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../templates/itemsOne.template */ \"./src/js/templates/itemsOne.template.js\");\n/* harmony import */ var _templates_items_template__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../templates/items.template */ \"./src/js/templates/items.template.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\n\n\nvar CategoryComponent =\n/*#__PURE__*/\nfunction (_Component) {\n _inherits(CategoryComponent, _Component);\n\n function CategoryComponent(id, _ref, _ref2) {\n var _this;\n\n var items = _ref.items;\n var filter = _ref2.filter;\n\n _classCallCheck(this, CategoryComponent);\n\n _this = _possibleConstructorReturn(this, _getPrototypeOf(CategoryComponent).call(this, id));\n _this.items = items;\n _this.filter = filter;\n return _this;\n }\n\n _createClass(CategoryComponent, [{\n key: \"init\",\n value: function init() {\n if (this.$el) {\n this.$el.addEventListener('click', buttonHandler.bind(this));\n\n if (localStorage.getItem('category')) {\n localStorage.removeItem('sortByAll', 'true'); // установка значения для компонента Filter\n\n var category = localStorage.getItem('category'),\n bounded = breadcrumbActiveLink.bind(this);\n document.querySelector('#loader').classList.add('hide');\n bounded(category); // <- ф-я окраски li по нажатию на breadcrumb\n // отображем данные если был нажат breadcrumb\n\n (function _callee() {\n var fData, html;\n return regeneratorRuntime.async(function _callee$(_context) {\n while (1) {\n switch (_context.prev = _context.next) {\n case 0:\n _context.next = 2;\n return regeneratorRuntime.awrap(_services_api_service__WEBPACK_IMPORTED_MODULE_1__[\"apiService\"].getItemsOne(category));\n\n case 2:\n fData = _context.sent;\n html = Object(_templates_itemsOne_template__WEBPACK_IMPORTED_MODULE_2__[\"renderItemsOne\"])(category, fData);\n document.querySelector('#roster').insertAdjacentHTML('afterbegin', html);\n\n case 5:\n case \"end\":\n return _context.stop();\n }\n }\n });\n })(); // очищаем ключ category чтобы данные не показывались всегда\n\n\n localStorage.removeItem('category');\n }\n }\n }\n }]);\n\n return CategoryComponent;\n}(_core_component__WEBPACK_IMPORTED_MODULE_0__[\"Component\"]);\n\nfunction buttonHandler(e) {\n var category, fData, html, _fData, categories, _html;\n\n return regeneratorRuntime.async(function buttonHandler$(_context2) {\n while (1) {\n switch (_context2.prev = _context2.next) {\n case 0:\n e.preventDefault();\n\n if (!(e.target.dataset.category && e.target.dataset.category != 'all')) {\n _context2.next = 15;\n break;\n }\n\n localStorage.removeItem('sortByAll'); // установка значения для компонента Filter\n\n this.filter.clearChecked();\n this.items.onShow();\n btnActiveLink(e);\n category = e.target.dataset.category.toLowerCase();\n _context2.next = 9;\n return regeneratorRuntime.awrap(_services_api_service__WEBPACK_IMPORTED_MODULE_1__[\"apiService\"].getItemsOne(category));\n\n case 9:\n fData = _context2.sent;\n html = Object(_templates_itemsOne_template__WEBPACK_IMPORTED_MODULE_2__[\"renderItemsOne\"])(category, fData);\n this.items.onHide();\n document.querySelector('#roster').insertAdjacentHTML('afterbegin', html);\n _context2.next = 27;\n break;\n\n case 15:\n if (!(e.target.dataset.category === 'all')) {\n _context2.next = 27;\n break;\n }\n\n localStorage.setItem('sortByAll', 'true'); // установка значения для компонента Filter\n\n this.filter.clearChecked();\n this.items.onShow();\n btnActiveLink(e);\n _context2.next = 22;\n return regeneratorRuntime.awrap(_services_api_service__WEBPACK_IMPORTED_MODULE_1__[\"apiService\"].getItems());\n\n case 22:\n _fData = _context2.sent;\n categories = Object.keys(_fData);\n _html = Object(_templates_items_template__WEBPACK_IMPORTED_MODULE_3__[\"renderItems\"])(categories, _fData);\n this.items.onHide();\n document.querySelector('#roster').insertAdjacentHTML('afterbegin', _html);\n\n case 27:\n case \"end\":\n return _context2.stop();\n }\n }\n }, null, this);\n} // Окраска li по нажатию\n\n\nfunction btnActiveLink(e) {\n Array.from(e.target.parentNode.parentNode.querySelectorAll('#catLi')).forEach(function (li) {\n return li.classList.remove('active');\n });\n e.target.classList.add('active');\n localStorage.setItem('currentCategory', e.target.dataset.category.toLowerCase());\n} // Окраска li по нажатию на breadcrumb\n\n\nfunction breadcrumbActiveLink(category) {\n var links = this.$el.querySelectorAll('#catLi');\n Array.from(links).forEach(function (li) {\n return li.classList.remove('active');\n });\n Array.from(links).forEach(function (li) {\n return li.dataset.category.toLowerCase() === category ? li.classList.add('active') : false;\n });\n Array.from(links).forEach(function (li) {\n return li.dataset.category.toLowerCase() === category ? localStorage.setItem('currentCategory', li.dataset.category.toLowerCase()) : false;\n });\n}\n\n//# sourceURL=webpack:///./src/js/components/category.component.js?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, \"CategoryComponent\", function() { return CategoryComponent; });\n/* harmony import */ var _core_component__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../core/component */ \"./src/js/core/component.js\");\n/* harmony import */ var _services_api_service__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../services/api.service */ \"./src/js/services/api.service.js\");\n/* harmony import */ var _templates_itemsOne_template__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../templates/itemsOne.template */ \"./src/js/templates/itemsOne.template.js\");\n/* harmony import */ var _templates_items_template__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../templates/items.template */ \"./src/js/templates/items.template.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\n\n\nvar CategoryComponent =\n/*#__PURE__*/\nfunction (_Component) {\n _inherits(CategoryComponent, _Component);\n\n function CategoryComponent(id, _ref, _ref2) {\n var _this;\n\n var items = _ref.items;\n var filter = _ref2.filter;\n\n _classCallCheck(this, CategoryComponent);\n\n _this = _possibleConstructorReturn(this, _getPrototypeOf(CategoryComponent).call(this, id));\n _this.items = items;\n _this.filter = filter;\n return _this;\n }\n\n _createClass(CategoryComponent, [{\n key: \"init\",\n value: function init() {\n if (this.$el) {\n this.$el.addEventListener('click', buttonHandler.bind(this));\n\n if (localStorage.getItem('category')) {\n localStorage.removeItem('sortByAll', 'true'); // установка значения для компонента Filter\n\n var category = localStorage.getItem('category'),\n bounded = breadcrumbActiveLink.bind(this);\n document.querySelector('#loader').classList.add('hide');\n bounded(category); // <- ф-я окраски li по нажатию на breadcrumb\n // отображем айтемсы если был нажат breadcrumb\n\n (function _callee() {\n var fData, html;\n return regeneratorRuntime.async(function _callee$(_context) {\n while (1) {\n switch (_context.prev = _context.next) {\n case 0:\n _context.next = 2;\n return regeneratorRuntime.awrap(_services_api_service__WEBPACK_IMPORTED_MODULE_1__[\"apiService\"].getItemsOne(category));\n\n case 2:\n fData = _context.sent;\n html = Object(_templates_itemsOne_template__WEBPACK_IMPORTED_MODULE_2__[\"renderItemsOne\"])(category, fData);\n document.querySelector('#roster').insertAdjacentHTML('afterbegin', html);\n\n case 5:\n case \"end\":\n return _context.stop();\n }\n }\n });\n })(); // очищаем ключ category чтобы данные не показывались всегда\n\n\n localStorage.removeItem('category');\n }\n }\n }\n }]);\n\n return CategoryComponent;\n}(_core_component__WEBPACK_IMPORTED_MODULE_0__[\"Component\"]);\n\nfunction buttonHandler(e) {\n var category, fData, html, _fData, categories, _html;\n\n return regeneratorRuntime.async(function buttonHandler$(_context2) {\n while (1) {\n switch (_context2.prev = _context2.next) {\n case 0:\n e.preventDefault();\n\n if (!(e.target.dataset.category && e.target.dataset.category != 'all')) {\n _context2.next = 15;\n break;\n }\n\n localStorage.removeItem('sortByAll'); // установка значения для компонента Filter\n\n this.filter.clearChecked();\n this.items.onShow();\n btnActiveLink(e);\n category = e.target.dataset.category.toLowerCase();\n _context2.next = 9;\n return regeneratorRuntime.awrap(_services_api_service__WEBPACK_IMPORTED_MODULE_1__[\"apiService\"].getItemsOne(category));\n\n case 9:\n fData = _context2.sent;\n html = Object(_templates_itemsOne_template__WEBPACK_IMPORTED_MODULE_2__[\"renderItemsOne\"])(category, fData);\n this.items.onHide();\n document.querySelector('#roster').insertAdjacentHTML('afterbegin', html);\n _context2.next = 27;\n break;\n\n case 15:\n if (!(e.target.dataset.category === 'all')) {\n _context2.next = 27;\n break;\n }\n\n localStorage.setItem('sortByAll', 'true'); // установка значения для компонента Filter\n\n this.filter.clearChecked();\n this.items.onShow();\n btnActiveLink(e);\n _context2.next = 22;\n return regeneratorRuntime.awrap(_services_api_service__WEBPACK_IMPORTED_MODULE_1__[\"apiService\"].getItems());\n\n case 22:\n _fData = _context2.sent;\n categories = Object.keys(_fData);\n _html = Object(_templates_items_template__WEBPACK_IMPORTED_MODULE_3__[\"renderItems\"])(categories, _fData);\n this.items.onHide();\n document.querySelector('#roster').insertAdjacentHTML('afterbegin', _html);\n\n case 27:\n case \"end\":\n return _context2.stop();\n }\n }\n }, null, this);\n} // Окраска li по нажатию\n\n\nfunction btnActiveLink(e) {\n Array.from(e.target.parentNode.parentNode.querySelectorAll('#catLi')).forEach(function (li) {\n return li.classList.remove('active');\n });\n e.target.classList.add('active');\n localStorage.setItem('currentCategory', e.target.dataset.category.toLowerCase());\n} // Окраска li по нажатию на breadcrumb\n\n\nfunction breadcrumbActiveLink(category) {\n var links = this.$el.querySelectorAll('#catLi');\n Array.from(links).forEach(function (li) {\n return li.classList.remove('active');\n });\n Array.from(links).forEach(function (li) {\n return li.dataset.category.toLowerCase() === category ? li.classList.add('active') : false;\n });\n Array.from(links).forEach(function (li) {\n return li.dataset.category.toLowerCase() === category ? localStorage.setItem('currentCategory', li.dataset.category.toLowerCase()) : false;\n });\n}\n\n//# sourceURL=webpack:///./src/js/components/category.component.js?"); /***/ }), @@ -4014,7 +4014,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__, \"renderItems\", function() { return renderItems; });\nfunction renderItems(categories, items) {\n var html = '';\n categories.forEach(function (category) {\n html += \"