Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 63 additions & 4 deletions sloth/app/dashboard.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import inspect

from django.conf import settings
from django.template.loader import render_to_string
from django.utils.safestring import mark_safe

from sloth.app.templatetags.tags import mobile
from sloth.db import models
from sloth.utils import pretty

INITIALIZE = True
Expand Down Expand Up @@ -37,7 +39,7 @@ def __init__(self, request):
self.request = request
self.data = dict(
info=[], warning=[], search=[], menu=[], links=[], shortcuts=[], cards=[],
floating=[], navigation=[], settings=[], center=[], right=[], actions=[]
floating=[], navigation=[], settings=[], center=[], right=[], actions=[], grids=[]
)
if self.request.user.is_authenticated:
self.load(request)
Expand Down Expand Up @@ -111,6 +113,55 @@ def add_action(self, url, label, icon):
def cards(self, *models):
self._load('cards', models)

def grids(self, *grids):
for grid in grids:
self.add_grid(grid)

def add_grid(self, grid, template=None, size=1):
key = 'grids'
if isinstance(grid, (list, tuple)):
html = mark_safe(render_to_string(grid[1], grid[0], request=self.request))
self.data[key].append(
dict(
html=html,
size=size,
)
)
elif isinstance(grid, dict):
html = mark_safe(render_to_string(template, grid, request=self.request))
self.data[key].append(
dict(
html=html,
size=size,
)
)
elif inspect.isclass(grid) and issubclass(grid, models.Model):
model = grid
if model().has_list_permission(self.request.user) or model().has_permission(self.request.user):
if self.request.path == '/app/':
url = model.get_list_url('/app')
add_item = True
# for item in self.data[key]:
# add_item = add_item and not item.get('url') == url
if add_item:
self.data[key].append(
dict(
url=url,
label=model.metaclass().verbose_name_plural,
count=model.objects.all().apply_role_lookups(self.request.user).count(),
icon=getattr(model.metaclass(), 'icon', None),
size=size,
)
)
elif isinstance(grid, models.QuerySet):
if self.request.path == '/app/':
self.data[key].append(
dict(
html=str(grid.contextualize(self.request)),
size=size,
)
)

def floating(self, *models):
self._load('floating', models)

Expand Down Expand Up @@ -145,21 +196,29 @@ def extend(self, data, template, aside=False):
def load(self, request):
pass

def get_qtd_grid(self):
return 3

def get_grid_size(self):
qtd_grid = self.get_qtd_grid()
return 12//qtd_grid


class Dashboards:

def __init__(self, request):
self.request = request
self.data = dict(
info=[], warning=[], search=[], menu=[], links=[], shortcuts=[], cards=[],
floating=[], navigation=[], settings=[], center=[], right=[], actions=[]
floating=[], navigation=[], settings=[], center=[], right=[], actions=[], grids=[]
)
self.data['navigation'].append(
dict(url='/app/', label='Principal', icon='house')
)
initilize()
for cls in DASHBOARDS:
dashboard = cls(request)
self.grid_size = dashboard.get_grid_size()
for key in dashboard.data:
self.data[key].extend(dashboard.data[key])
if self.request.user.is_superuser:
Expand All @@ -184,7 +243,7 @@ def superuser_search(self, items):
return items

def __str__(self):
return mark_safe(render_to_string('app/dashboard/dashboards.html', dict(data=self.data), request=self.request))
return mark_safe(render_to_string('app/dashboard/dashboards.html', dict(data=self.data, grid_size=self.grid_size), request=self.request))



22 changes: 22 additions & 0 deletions sloth/app/static/css/sloth.css
Original file line number Diff line number Diff line change
Expand Up @@ -330,4 +330,26 @@ textarea{
}
.chart-legend li span {
padding-left: 10px;
}
.single_quick_activity .count_content {
margin-left: 30px;
text-align: left;
}
.single_quick_activity {
border-radius: 10px;
-webkit-transition: 0.5s;
padding: 10px;
align-items: center;
justify-content: center;
margin-bottom: 10px;
height: 120px;
box-shadow: 0 0.375rem 0.75rem rgb(140 152 164 / 8%);
border: 0.0625rem solid rgba(231,234,243,.7);
transition: .3s;
}
.single_quick_activity i{
font-size: 90px;
float:left;
margin-left: 20px;
margin-right: 20px;
}
51 changes: 10 additions & 41 deletions sloth/app/templates/app/dashboard/cards.html
Original file line number Diff line number Diff line change
@@ -1,42 +1,11 @@
<style>
.single_quick_activity .count_content {
margin-left: 30px;
text-align: left;
}
.single_quick_activity {
border-radius: 10px;
-webkit-transition: 0.5s;
padding: 10px;
align-items: center;
justify-content: center;
margin-bottom: 10px;
height: 120px;
box-shadow: 0 0.375rem 0.75rem rgb(140 152 164 / 8%);
border: 0.0625rem solid rgba(231,234,243,.7);
transition: .3s;
}
.single_quick_activity i{
font-size: 90px;
float:left;
margin-left: 20px;
margin-right: 20px;
}
</style>

<div class="row">
{% for item in data.cards %}
<div class="col-sm-12 col-md-6 col-lg-4" style="padding:3px">
<a href="{{ item.url }}" style="text-decoration:none;color:white">
<div class="single_quick_activity">
<div class="icon text-primary">
<i class="bi bi-{{ item.icon }}"></i>
</div>
<div class="count_content">
<h3><span class="counter text-primary">{{ item.count }}</span> </h3>
<p class="text-primary">{{ item.label }}</p>
</div>
</div>
</a>
<a href="{{ item.url }}" style="text-decoration:none;color:white">
<div class="single_quick_activity">
<div class="icon text-primary">
<i class="bi bi-{{ item.icon }}"></i>
</div>
{% endfor %}
</div>
<div class="count_content">
<h3><span class="counter text-primary">{{ item.count }}</span> </h3>
<p class="text-primary">{{ item.label }}</p>
</div>
</div>
</a>
12 changes: 11 additions & 1 deletion sloth/app/templates/app/dashboard/dashboards.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
<div class="row clearfix">
<div class="{% if data.right %}col-lg-9 col-md-8 col-sm-12{% else %}col{% endif %}">
{% include "app/dashboard/shortcuts.html" %}
{% include "app/dashboard/cards.html" %}
<div class="row">
{% for grid in data.grids %}
<div class="col-sm-12 col-md-6 col-lg-{% widthratio grid.size 1 grid_size %}" style="padding:3px">
{% if grid.html %}
{{ grid.html }}
{% else %}
{% include "app/dashboard/cards.html" with item=grid %}
{% endif %}
</div>
{% endfor %}
</div>
{% for item in data.center %}
<div class="mb-3">
{{ item }}
Expand Down