Compare commits

..

No commits in common. "d86b582fadf9f0e13e8416ebcc2ef68caba0bdfb" and "40d4acc6bfe3c984ac3b9d4c9505586184b3a05d" have entirely different histories.

7 changed files with 35 additions and 326 deletions

160
README.md
View File

@ -1,159 +1,3 @@
# CostaPy Template - Prime # prime
A prime dashboard based on bootstrap 5 A prime dashboard based on bootstrap 5
## Usage
- Put the folder in your `templates` directory
- Add to handler
```python
import templates.prime.main as template_dashboard
params["mako"] = {
"website" : template_dashboard.main(directory.page["dashboard"], "users")
}
```
- Define a necessary variable on your modules
```python
title = "CostaPy"
user_roles = [1,2] # A roles that user have
active_page = "Users" # Current active page name
copyright = "Copyright (C) 2022 Dita Aji Pratama"
greeting = "Hello world"
```
- Define a navbar menu on your modules
```python
menu_navbar = [
{
"name":"Home",
"target":"_self",
"href":"#",
"notification":0,
"roles":[1,2]
},
{
"name":"Customize",
"href":"#",
"target":"_self",
"notification":0,
"roles":[1,2]
},
{
"name":"Notification",
"href":"#",
"target":"_self",
"notification":1,
"roles":[1,2]
}
]
```
- Define a profile menu on your modules
```python
menu_profile = {
"picture" : "https://ditaajipratama.net/img/no-profile-donut.png",
"name" : "Dita Aji Pratama",
"menu" : [
{
"name" :"Profile",
"href" :"/profile"
"target":"_self",
"roles":[1,2]
},
{
"name" :"Settings",
"href" :"/settings"
"target":"_self",
"roles":[1,2]
},
{
"name" :"Logout",
"href" :"/logout"
"target":"_self",
"roles":[1,2,3]
}
]
}
```
- Define a sidebar menu on your modules
```python
menu_sidebar = [
{
"name":"Dashboard",
"target":"_self",
"href":"#",
"roles":[1,2]
},
{
"name":"Users",
"target":"_self",
"href":"#",
"roles":[1,2]
},
{
"name":"Items",
"target":"_self",
"href":"#",
"roles":[1,2]
},
{
"name":"Analytic",
"target":"_self",
"href":"#",
"roles":[1,2]
},
{
"name":"Reports",
"target":"_self",
"href":"#",
"roles":[1,2]
}
]
```
- Set a template on your modules
```python
return Template(params["mako"]["website"]['index']).render(
title = title,
navbar = Template(params["mako"]["website"]['navbar']).render(
title = title,
menu = menu_navbar,
profile = menu_profile,
user_roles = user_roles,
active_page = active_page
),
sidebar = Template(params["mako"]["website"]['sidebar']).render(
menu = menu_sidebar,
user_roles = user_roles,
active_page = active_page
),
footer = Template(params["mako"]["website"]['footer']).render(
copyright = copyright,
),
container = Template(params["mako"]["website"]['container']).render(
greeting = greeting
)
)
```
## License
MIT License
Copyright (c) 2024 Dita Aji Pratama
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@ -3,9 +3,9 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>${title}</title> <title>Prime</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="/templates/prime/css/style.css"> <link rel="stylesheet" href="style.css">
</head> </head>
<body class="d-flex flex-column"> <body class="d-flex flex-column">
${navbar} ${navbar}

View File

@ -1,41 +1,31 @@
<!-- Navbar --> <!-- Navbar -->
<nav class="navbar navbar-expand-lg navbar-dark bg-dark"> <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container-fluid"> <div class="container-fluid">
<a class="navbar-brand" href="#">${title}</a> <a class="navbar-brand" href="#">Prime Dashboard</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation"> <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span> <span class="navbar-toggler-icon"></span>
</button> </button>
<div class="collapse navbar-collapse" id="navbarNav"> <div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ms-auto"> <ul class="navbar-nav ms-auto">
% for item in menu: <li class="nav-item">
% if any(role in item['roles'] for role in user_roles): <a class="nav-link" href="#">Home</a>
<li class="nav-item"> </li>
<a class="nav-link ${'active' if item['name'] == active_page else ''}" href="${item['href']}" target="${item['target']}"> <li class="nav-item">
% if item['notification'] > 0: <a class="nav-link" href="#">Customize</a>
${item['name']} <sup class="badge bg-danger">${item['notification']}</sup> </li>
% else: <li class="nav-item">
${item['name']} <a class="nav-link" href="#">Notification <sup class="badge bg-danger">1</sup> </a>
% endif </li>
</a>
</li>
% endif
% endfor
<li class="nav-item dropdown"> <li class="nav-item dropdown">
<a class="nav-link dropdown-toggle d-flex align-items-center" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false"> <a class="nav-link dropdown-toggle d-flex align-items-center" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
<img src="${profile['picture']}" alt="Profile" class="profile-image me-2"> <img src="no-profile-donut.png" alt="Profile" class="profile-image me-2">
${profile['name']} Dita Aji Pratama
</a> </a>
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdown"> <ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdown">
% for item in profile['menu']: <li><a class="dropdown-item" href="#">Profile</a></li>
% if any(role in item['roles'] for role in user_roles): <li><a class="dropdown-item" href="#">Settings</a></li>
<li> <li><hr class="dropdown-divider"></li>
<a class="dropdown-item ${'active' if item['name'] == active_page else ''}" href="${item['href']}" target="${item['target']}"> <li><a class="dropdown-item" href="#">Logout</a></li>
${item['name']}
</a>
</li>
% endif
% endfor
<!-- <li><hr class="dropdown-divider"></li> -->
</ul> </ul>
</li> </li>
</ul> </ul>

View File

@ -2,15 +2,21 @@
<div class="sidebar p-3" id="sidebar"> <div class="sidebar p-3" id="sidebar">
<!-- <h5>Sidebar</h5> --> <!-- <h5>Sidebar</h5> -->
<ul class="nav flex-column pb-5"> <ul class="nav flex-column pb-5">
% for item in menu: <li class="nav-item">
% if any(role in item['roles'] for role in user_roles): <a class="nav-link text-white" href="#">Dashboard</a>
<li class="nav-item"> </li>
<a class="nav-link text-white ${'active' if item['name'] == active_page else ''}" href="${item['href']}" target="${item['target']}"> <li class="nav-item">
${item['name']} <a class="nav-link text-white" href="#">Users</a>
</a> </li>
</li> <li class="nav-item">
% endif <a class="nav-link text-white" href="#">Items</a>
% endfor </li>
<li class="nav-item">
<a class="nav-link text-white" href="#">Analytics</a>
</li>
<li class="nav-item">
<a class="nav-link text-white" href="#">Reports</a>
</li>
<!-- Add more items to test scrolling --> <!-- Add more items to test scrolling -->
</ul> </ul>
</div> </div>

View File

@ -1,33 +0,0 @@
# MIT License
#
# Copyright (c) 2024 Dita Aji Pratama
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
from core import html
static = [
{
"route" : "/templates/prime/css/<filepath:re:.*\.(css|sass|css.map)>",
"root" : "./templates/prime/static/css"
},
{
"route" : "/templates/prime/img/<filepath:re:.*\.(jpg|jpeg|svg|png)>",
"root" : "./templates/prime/static/img"
}
]
def main(dir, page):
html_template = html.main.get_html("templates/prime/html")
html_page = html.main.get_html(dir)
return {
"index" : html_template [ "index.html" ],
"navbar" : html_template [ "navbar.html" ],
"sidebar" : html_template [ "sidebar.html" ],
"footer" : html_template [ "footer.html" ],
"container" : html_page [f"{page}.html" ]
}

View File

@ -1,98 +0,0 @@
body {
min-height: 100vh;
}
.navbar {
z-index: 1030; /* Ensure the navbar is above other elements */
}
.sidebar {
height: calc(100vh - 56px); /* 56px is the height of the navbar */
position: fixed;
top: 56px; /* Offset by the navbar height */
left: 0;
width: 250px;
background-color: #343a40;
color: white;
z-index: 1020; /* Lower than navbar to stay behind it */
transition: transform 0.3s ease-in-out;
overflow-y: auto; /* Make sidebar scrollable */
}
.sidebar.minimized {
transform: translateX(-100%);
}
.content {
margin-left: 250px;
padding: 20px;
transition: margin-left 0.3s ease-in-out;
}
.content.full-width {
margin-left: 0;
}
.footer {
position: fixed;
bottom: 0;
width: calc(100% - 250px);
margin-left: 250px;
background-color: #f8f9fa;
padding: 10px;
text-align: center;
transition: margin-left 0.3s ease-in-out;
}
.footer.full-width {
width: 100%;
margin-left: 0;
}
.profile-image {
width: 30px;
height: 30px;
border-radius: 50%;
object-fit: cover;
}
.sidebar-toggle {
position: fixed;
bottom: 20px;
left: 20px;
background-color: #343a40;
color: white;
border: none;
width: 100px;
height: 40px;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
z-index: 1040; /* Above the sidebar and navbar */
padding: 5px;
border-radius: 8px; /* Rounded corners */
}
.sidebar-toggle span {
margin-left: 5px;
}
@media (max-width: 768px) {
.sidebar {
transform: translateX(-100%);
}
.sidebar.show {
transform: translateX(0);
}
.content {
margin-left: 0;
}
.footer {
width: 100%;
margin-left: 0;
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 127 KiB