//controllers/admin/user/read.js
import settings from '../../../settings.js'
import read from '../../../models/user/read.js'
import count from '../../../models/count.js'
let mySettings = JSON.parse(JSON.stringify(settings))
export default async (req,res)=>{
mySettings.pageTitle = 'ទំព័រអ្នកប្រើប្រាស់'
mySettings.route = '/admin/user'
if(req.params.id){
mySettings.item = await read(req,mySettings.dItemLimit,req.params.id)
const date = mySettings.item.date.toLocaleDateString('fr-CA')
const time = mySettings.item.date.toLocaleTimeString('it-IT')
mySettings.item.date = date + 'T' + time
}
mySettings.items = await read(req,mySettings.dItemLimit)
mySettings.count = await count(req,'users')
res.render('base',{data:mySettings})
}
//models/user/read.js
export default async (req,amount=10,id=false)=>{
if(id){
return await req.mydb.collection("users").findOne({id:id})
}else if(req.body.page){
const page = req.body.page
return await req.mydb.collection("users")
.find().skip(amount*page).sort({date:-1,_id:-1}).limit(amount).toArray()
}else{
return await req.mydb.collection("users")
.find().sort({date:-1,_id:-1}).limit(amount).toArray()
}
}
<!--views/admin/index.ejs-->
<link href="/styles/admin/index.css" rel="stylesheet">
<script src="/scripts/admin/paginate.js"></script>
<section class="Header">
<div class="wrapper region">
<div class="logo"><%= data.pageTitle %></div>
<form method="post" action="/search">
<select name="type">
<option>ការផ្សាយ</option>
<option>ទំព័រស្តាទិក</option>
<option>អ្នកប្រើប្រាស់</option>
</select>
<input type="text" name="q" placeholder="Search" required>
<input type="submit" value="ស្វែងរក">
</form>
<div class="logout">
<a href="/">ទំព័រមុខ</a> | <a href="/admin/login/logout">ចេញក្រៅ</a>
</div>
</div>
</section>
<section class="Body">
<div class="wrapper region">
<div class="sidebar-wrapper">
<div class="sidebar">
<a href='/admin/post'><img src='/images/movie.png' /></a>
<a href='/admin/post'>ការផ្សាយ</a>
<a href='/admin/category'><img src='/images/category.png' /></a>
<a href='/admin/category'>ជំពូក</a>
<a href='/admin/book'><img src='/images/books.png' /></a>
<a href='/admin/book'>សៀវភៅ</a>
<a href='/admin/upload'><img src='/images/upload.png' /></a>
<a href='/admin/upload'>Upload</a>
<a href='/admin/user'><img src='/images/users.png' /></a>
<a href='/admin/user'>អ្នកប្រើប្រាស់</a>
<a href='/admin/setting'><img src='/images/setting.png' /></a>
<a href='/admin/setting'>Setting</a>
</div>
</div>
<div class="Content">
<% if(data.route.includes('/category')){ %>
<%- include('category.ejs') %>
<% }else if(data.route.includes('/post')){ %>
<%- include('post.ejs') %>
<% }else if(data.route.includes('/book')){ %>
<%- include('book.ejs') %>
<% }else if(data.route.includes('/upload')){ %>
<%- include('upload.ejs') %>
<% }else if(data.route.includes('/user')){ %>
<%- include('user.ejs') %>
<% } %>
</div>
</div>
<div class="Listing region">
<div class="info">សរុបទាំងអស់មានចំនួនៈ <%= data.count %></div>
<ul class="list">
<% if(data.items){ %>
<% for(let item of data.items) { %>
<li>
<div class='thumb'>
<a href='<%= data.route %>/<%= item.id %>'><img src='<%= item.thumb %>'/>
<% if((item.video)&&(item.video !== '[]')){ %>
<img class="play-icon" src="/images/play.png"/>
<% } %>
</a>
</div>
<div class="title">
<a href="<%= data.route %>/<%= item.id %>"><%= item.title %></a>
<div><%= item.date.toLocaleDateString() %></div>
</div>
<div class="edit">
<a href="<%= data.route %>/edit/<%= item.id %>"><img src="/images/edit.png"/></a>
<a href="<%= data.route %>/delete/<%= item.id %>"><img src="/images/delete.png"/></a>
</div>
</li>
<% } %>
<% } %>
</ul>
<% if(data.route === '/admin/user'){ %>
<script>
$('.Listing .list li').css({'grid-template-columns':'13% auto 25%'})
$('.Listing .list li .thumb').css({'padding-top':'100%'})
$('.Listing .list li .thumb img').css({'border-radius':'50%'})
</script>
<% } %>
<div class="paginate region">
<img onclick="paginate('<%= data.route %>')" src="/images/load-more.png"/>
</div>
</div>
</section>