From a63ec56170739851a2b47efda6674e1179ba3a89 Mon Sep 17 00:00:00 2001 From: Sergey Yarkov Date: Wed, 22 Jan 2020 23:05:43 +0300 Subject: [PATCH] theme site --- config/routes/control-panel.js | 32 +++++++++++++++++++- config/routes/main.js | 18 +++++++---- dist/views/admin/assets/templates/header.pug | 4 +++ dist/views/admin/theme.pug | 24 +++++++++++++++ dist/views/main/assets/head.pug | 12 ++++++++ dist/views/main/my-orders.pug | 6 ++-- 6 files changed, 86 insertions(+), 10 deletions(-) create mode 100644 dist/views/admin/theme.pug diff --git a/config/routes/control-panel.js b/config/routes/control-panel.js index 6ba68be..1f576eb 100644 --- a/config/routes/control-panel.js +++ b/config/routes/control-panel.js @@ -143,6 +143,23 @@ module.exports = function (server, db) { } }); + server.get('/control-panel/theme', checkAuthenticated, async (req, res) => { + try { + const store = await db.collection('content').findOne({}); + res.render('admin/theme', { + id: req.user.id, + name: req.user.name, + email: req.user.email, + title: `${store.title} | Оформление`, + host: req.headers.host, + pageName: ['Оформление', 'theme'], + color: store.color + }); + } catch { + res.status(500).render('main/404'); + } + }); + // редактирование категорий server.post('/control-panel/categories/create', checkAuthenticated, (req, res) => { try { @@ -299,5 +316,18 @@ module.exports = function (server, db) { } catch { res.status(500).render('main/404'); } - }) + }); + + // формление + server.post('/control-panel/theme/update', checkAuthenticated, (req, res) => { + try { + const data = { + color: req.body.color + } + db.collection('content').updateOne({}, {$set: {color: data.color}}); + res.redirect('/control-panel/theme'); + } catch { + res.status(500).render('main/404'); + } + }); } \ No newline at end of file diff --git a/config/routes/main.js b/config/routes/main.js index f19a95b..a0e99f2 100644 --- a/config/routes/main.js +++ b/config/routes/main.js @@ -14,7 +14,8 @@ module.exports = function (server, db) { store: { title: store.title, info: store.info, - infoBottom: store.infoBottom + infoBottom: store.infoBottom, + color: store.color } }); }); @@ -30,7 +31,8 @@ module.exports = function (server, db) { title: `${store.title} | Как купить товар`, store: { title: store.title, - howToBuy: store.howToBuy + howToBuy: store.howToBuy, + color: store.color } }); } catch { @@ -45,7 +47,8 @@ module.exports = function (server, db) { title: `${store.title} | Контакты`, store: { title: store.title, - contacts: store.contacts + contacts: store.contacts, + color: store.color } }); } catch { @@ -59,7 +62,8 @@ module.exports = function (server, db) { pageName: 'comments', title: `${store.title} | Отзывы`, store: { - title: store.title + title: store.title, + color: store.color } }); } catch { @@ -73,7 +77,8 @@ module.exports = function (server, db) { pageName: 'my-orders', title: `${store.title} | Мои покупки`, store: { - title: store.title + title: store.title, + color: store.color } }); } catch { @@ -115,7 +120,8 @@ module.exports = function (server, db) { format: category.format, store: { title: store.title, - recommendations: store.recommendations + recommendations: store.recommendations, + color: store.color } }); })) diff --git a/dist/views/admin/assets/templates/header.pug b/dist/views/admin/assets/templates/header.pug index 83fa1cd..231eaeb 100644 --- a/dist/views/admin/assets/templates/header.pug +++ b/dist/views/admin/assets/templates/header.pug @@ -55,6 +55,10 @@ header.admin-header a(href='http://'+host+'/control-panel/content') i.material-icons visibility | Контент на сайте + li(data-page="theme") + a(href='http://'+host+'/control-panel/theme') + i.material-icons create + | Оформление ul.collapsible li a(href="#" class="collapsible-header waves-effect") diff --git a/dist/views/admin/theme.pug b/dist/views/admin/theme.pug new file mode 100644 index 0000000..802c20e --- /dev/null +++ b/dist/views/admin/theme.pug @@ -0,0 +1,24 @@ +include ./assets/head.pug +body.has-fixed-sidenav + include ./assets/templates/header.pug + main.admin-main + .container + .row + .col.s12 + h2 Изменить оформление + p Измените оформление вашего магазине на этой странице. + .col.s12 + #theme.card + .card-content + .theme-change + h5 Общий цвета + .row + form(action="/control-panel/theme/update" method="POST") + #color.input-field.col.s12 + input(id="color" type="text" pattern="^#(?:[0-9a-fA-F]{3}){1,2}$" name="color" value=color required) + label(for="color") Цвет в формате HEX (#000000) + .edit_success.col.s12 + button(type="submit" class="btn waves-effect") Сохранить + + include ./assets/templates/footer.pug + include ./assets/scripts.pug \ No newline at end of file diff --git a/dist/views/main/assets/head.pug b/dist/views/main/assets/head.pug index 8ae94f2..294c287 100644 --- a/dist/views/main/assets/head.pug +++ b/dist/views/main/assets/head.pug @@ -13,4 +13,16 @@ html(lang='ru') link(rel="stylesheet", href="/css/media.css") // Material Icons link(rel="stylesheet", href="https://fonts.googleapis.com/icon?family=Material+Icons") + if store + style. + nav, footer.main-footer, .items-category, .category-items li .active, .category-items li a:hover, .progress .indeterminate, button { + background-color: #{store.color} !important; + } + button:hover { + background-color: #{store.color} !important; + opacity: .7; + } + .progress { + background-color: #deecea; + } body \ No newline at end of file diff --git a/dist/views/main/my-orders.pug b/dist/views/main/my-orders.pug index 6f20aee..a72130f 100644 --- a/dist/views/main/my-orders.pug +++ b/dist/views/main/my-orders.pug @@ -28,13 +28,13 @@ main.main-section .orders-text hr p - strong Введите почту + strong Введите вашу почту и мы вышлем вам ваши товары которые вы оплачивали p   form(action='#') - .email-field(style='max-width: 400px;margin-bottom: 10px;') + .email-field(style='margin-bottom: 10px;') label(for='email') Почта input#email(required='' type='email' name='email') - .show-orders + .show-orders(style='display: flex;justify-content: flex-end;') button.waves-effect.waves-light.btn(type='submit') Узнать