Skip to content

Commit b409e5f

Browse files
committed
Funções de adminitradores
### Adicionado - Agora admins podem visualizar e injetar produções em diversas lojas diferentes, tanto usando a url, ou a barra select no topo da pagina principal; A barra tambem so estará disponivel para quem for admin, sendo assim usuarios normais nao devem vê-la - Adicionado uma barra no topo da pagina principal para que admins possam navegar pelas lojas - Adicionado um tema de elemento para os selects
1 parent 65f2fa2 commit b409e5f

File tree

8 files changed

+168
-48
lines changed

8 files changed

+168
-48
lines changed

System/app.py

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,21 @@
1010
app.secret_key = '2222'
1111

1212

13-
def user_data(date_for="1999-01-01"):
13+
def user_data(date_for="1999-01-01", store_to_show=5):
1414

1515
if not date_for == "1999-01-01":
1616
data = {
1717
'username': Session(request.remote_addr).name(),
1818
'level': Session(request.remote_addr).level(),
1919
'articles': Production.articles,
2020
'store_name': Session(request.remote_addr).store_name(),
21-
'total_of_the_day': Production(date_for).get_already_produced(Session(request.remote_addr).store_name(id=True))
21+
'total_of_the_day': Production(date_for).get_already_produced(store_to_show),
22+
'stores': {
23+
3: 'Colombo',
24+
5: 'Odivelas',
25+
11: 'Campo de Ourique',
26+
25: 'Baixa Chiado'
27+
}
2228
}
2329

2430
return data
@@ -27,7 +33,13 @@ def user_data(date_for="1999-01-01"):
2733
'username': Session(request.remote_addr).name(),
2834
'level': Session(request.remote_addr).level(),
2935
'articles': Production.articles,
30-
'store_name': Session(request.remote_addr).store_name()
36+
'store_name': Session(request.remote_addr).store_name(),
37+
'stores': {
38+
3: 'Colombo',
39+
5: 'Odivelas',
40+
11: 'Campo de Ourique',
41+
25: 'Baixa Chiado'
42+
}
3143
}
3244
return data
3345

@@ -89,22 +101,32 @@ def logout():
89101

90102
@app.route('/homepage/')
91103
def redirect_home():
92-
return redirect(f'/homepage/{date.today()}')
104+
user_store = Session(request.remote_addr).store_name(id=True)
105+
return redirect(f'/homepage/{date.today()}/{user_store}')
106+
93107

108+
@app.route('/homepage/<date_for>/<store_to_show>')
109+
def home(date_for, store_to_show):
94110

95-
@app.route('/homepage/<date_for>')
96-
def home(date_for):
111+
user_store = Session(request.remote_addr).store_name(id=True)
97112

98113
if is_user_logged_in(request.remote_addr):
99114
pass
100115
else:
101116
return redirect('/login')
102117

103-
return render_template('homepage.html', data=user_data(date_for), date_for=date_for)
118+
if user_data(date_for=date_for)['level'] == 'Administrador':
119+
user_store = store_to_show
120+
return render_template('homepage.html', data=user_data(date_for, store_to_show=user_store), date_for=date_for, store_to_show=store_to_show)
121+
122+
else:
123+
124+
data = user_data(date_for=date_for, store_to_show=user_store)
125+
return render_template('homepage.html', data=data, date_for=date_for, store_to_show=store_to_show)
104126

105127

106-
@app.route('/production/<date_for>', methods=['GET', 'POST'])
107-
def enter_production(date_for):
128+
@app.route('/production/<date_for>/<store_to_send>', methods=['GET', 'POST'])
129+
def enter_production(date_for, store_to_send):
108130
data = {}
109131

110132
old_production = Production(date_for).get_already_produced(
@@ -124,12 +146,11 @@ def enter_production(date_for):
124146
except KeyError:
125147
data[article_id] = 0
126148

127-
print(data, old_production)
128149
production = Production(date_for, data)
129150
production.store = Session(request.remote_addr).store_name(id=True)
130151
production.send_production()
131152

132-
return redirect(f'/homepage/{date_for}')
153+
return redirect(f'/homepage/{date_for}/{store_to_send}')
133154

134155

135156
@app.route('/user/<user_id>', methods=['GET', 'POST'])

System/managers/dbconnection.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ class DbConnection():
1313
]
1414

1515
stores = {
16-
0: None,
1716
3: 'Colombo',
1817
5: 'Odivelas',
1918
11: 'Campo de Ourique',
@@ -159,7 +158,7 @@ def update_production(self, store, date, old_data, new_data):
159158
{'production': generated_data}, Query().date == str(date))
160159

161160
def get_day_production(self, store, date):
162-
store_name = self.stores[store]
161+
store_name = self.stores[int(store)]
163162

164163
result = self.db.table(store_name).search(Query().date == str(date))
165164

System/managers/production.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,10 @@ def send_production(self):
2323

2424
def get_already_produced(self, store):
2525
return DbConnection('databases/production.json').get_day_production(store, self.date)
26+
27+
28+
class Stores(Production):
29+
30+
def __init__(self):
31+
super().__init__(self.get_already_produced)
32+
self.store = 0

System/static/output.css

Lines changed: 81 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,57 @@ video {
726726
}
727727
}
728728

729+
.select-primary {
730+
display: block;
731+
width: 100%;
732+
border-radius: 0.5rem;
733+
border-width: 1px;
734+
--tw-border-opacity: 1;
735+
border-color: rgb(209 213 219 / var(--tw-border-opacity));
736+
--tw-bg-opacity: 1;
737+
background-color: rgb(249 250 251 / var(--tw-bg-opacity));
738+
padding: 0.625rem;
739+
font-size: 0.875rem;
740+
line-height: 1.25rem;
741+
--tw-text-opacity: 1;
742+
color: rgb(17 24 39 / var(--tw-text-opacity));
743+
}
744+
745+
.select-primary:focus {
746+
--tw-border-opacity: 1;
747+
border-color: rgb(59 130 246 / var(--tw-border-opacity));
748+
--tw-ring-opacity: 1;
749+
--tw-ring-color: rgb(59 130 246 / var(--tw-ring-opacity));
750+
}
751+
752+
@media (prefers-color-scheme: dark) {
753+
.select-primary {
754+
--tw-border-opacity: 1;
755+
border-color: rgb(75 85 99 / var(--tw-border-opacity));
756+
--tw-bg-opacity: 1;
757+
background-color: rgb(55 65 81 / var(--tw-bg-opacity));
758+
--tw-text-opacity: 1;
759+
color: rgb(255 255 255 / var(--tw-text-opacity));
760+
}
761+
762+
.select-primary::-moz-placeholder {
763+
--tw-placeholder-opacity: 1;
764+
color: rgb(156 163 175 / var(--tw-placeholder-opacity));
765+
}
766+
767+
.select-primary::placeholder {
768+
--tw-placeholder-opacity: 1;
769+
color: rgb(156 163 175 / var(--tw-placeholder-opacity));
770+
}
771+
772+
.select-primary:focus {
773+
--tw-border-opacity: 1;
774+
border-color: rgb(59 130 246 / var(--tw-border-opacity));
775+
--tw-ring-opacity: 1;
776+
--tw-ring-color: rgb(59 130 246 / var(--tw-ring-opacity));
777+
}
778+
}
779+
729780
.m-4 {
730781
margin: 1rem;
731782
}
@@ -740,11 +791,6 @@ video {
740791
margin-right: 1rem;
741792
}
742793

743-
.mx-96 {
744-
margin-left: 24rem;
745-
margin-right: 24rem;
746-
}
747-
748794
.my-10 {
749795
margin-top: 2.5rem;
750796
margin-bottom: 2.5rem;
@@ -815,8 +861,8 @@ video {
815861
height: 100vh;
816862
}
817863

818-
.h-96 {
819-
height: 24rem;
864+
.w-1\/6 {
865+
width: 16.666667%;
820866
}
821867

822868
.w-11\/12 {
@@ -855,6 +901,10 @@ video {
855901
width: 100vw;
856902
}
857903

904+
.w-2\/6 {
905+
width: 33.333333%;
906+
}
907+
858908
.flex-col {
859909
flex-direction: column;
860910
}
@@ -895,6 +945,12 @@ video {
895945
margin-left: calc(0.5rem * calc(1 - var(--tw-space-x-reverse)));
896946
}
897947

948+
.space-x-1 > :not([hidden]) ~ :not([hidden]) {
949+
--tw-space-x-reverse: 0;
950+
margin-right: calc(0.25rem * var(--tw-space-x-reverse));
951+
margin-left: calc(0.25rem * calc(1 - var(--tw-space-x-reverse)));
952+
}
953+
898954
.rounded-lg {
899955
border-radius: 0.5rem;
900956
}
@@ -903,6 +959,10 @@ video {
903959
border-width: 1px;
904960
}
905961

962+
.border-4 {
963+
border-width: 4px;
964+
}
965+
906966
.border-emerald-500 {
907967
--tw-border-opacity: 1;
908968
border-color: rgb(16 185 129 / var(--tw-border-opacity));
@@ -913,6 +973,11 @@ video {
913973
border-color: rgb(31 41 55 / var(--tw-border-opacity));
914974
}
915975

976+
.border-red-500 {
977+
--tw-border-opacity: 1;
978+
border-color: rgb(239 68 68 / var(--tw-border-opacity));
979+
}
980+
916981
.bg-emerald-500 {
917982
--tw-bg-opacity: 1;
918983
background-color: rgb(16 185 129 / var(--tw-bg-opacity));
@@ -933,6 +998,11 @@ video {
933998
background-color: rgb(15 23 42 / var(--tw-bg-opacity));
934999
}
9351000

1001+
.bg-white {
1002+
--tw-bg-opacity: 1;
1003+
background-color: rgb(255 255 255 / var(--tw-bg-opacity));
1004+
}
1005+
9361006
.p-2 {
9371007
padding: 0.5rem;
9381008
}
@@ -941,6 +1011,10 @@ video {
9411011
padding: 1rem;
9421012
}
9431013

1014+
.p-0 {
1015+
padding: 0px;
1016+
}
1017+
9441018
.px-4 {
9451019
padding-left: 1rem;
9461020
padding-right: 1rem;
@@ -1021,10 +1095,6 @@ video {
10211095
transition-duration: 1000ms;
10221096
}
10231097

1024-
.duration-300 {
1025-
transition-duration: 300ms;
1026-
}
1027-
10281098
.duration-200 {
10291099
transition-duration: 200ms;
10301100
}
@@ -1033,31 +1103,10 @@ video {
10331103
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
10341104
}
10351105

1036-
.hover\:border-4:hover {
1037-
border-width: 4px;
1038-
}
1039-
1040-
.hover\:border-\[40px\]:hover {
1041-
border-width: 40px;
1042-
}
1043-
1044-
.hover\:border-\[30px\]:hover {
1045-
border-width: 30px;
1046-
}
1047-
1048-
.hover\:border-\[20px\]:hover {
1049-
border-width: 20px;
1050-
}
1051-
10521106
.hover\:border-\[10px\]:hover {
10531107
border-width: 10px;
10541108
}
10551109

1056-
.hover\:border-red-500:hover {
1057-
--tw-border-opacity: 1;
1058-
border-color: rgb(239 68 68 / var(--tw-border-opacity));
1059-
}
1060-
10611110
.hover\:bg-emerald-500:hover {
10621111
--tw-bg-opacity: 1;
10631112
background-color: rgb(16 185 129 / var(--tw-bg-opacity));

System/templates/homepage.html

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,21 @@
55
{% endblock %}
66

77
{% block content %}
8+
<!-- Search Bar if admin -->
9+
{% if data['level'] == 'Administrador' %}
10+
<div class="w-full h-8 flex justify-center mb-4 space-x-1">
11+
<div class="w-1/6">
12+
<h1 class="select-primary p-0 h-full flex justify-center items-center ">Select an store</h1>
13+
</div>
14+
<form action=""></form>
15+
<select name="store" id="" class="select-primary w-2/6 p-0 text-center">
16+
{% for store_id, store_name in data['stores'].items() %}
17+
<option value="{{ store_id }}">{{ store_name }}</option>
18+
{% endfor %}
19+
</select>
20+
21+
</div>
22+
{% endif %}
823
<!-- Production Card -->
924
<div class="w-full flex justify-center">
1025
<!-- Container -->
@@ -13,7 +28,7 @@
1328
<h1 class="font-bold text-emerald-500 text-2xl">Enter the Production</h1>
1429
</div>
1530

16-
<form action="/production/{{ date_for }}" class="flex flex-col m-4" method="POST" id="production-form">
31+
<form action="/production/{{ date_for }}/{{ store_to_show }}" class="flex flex-col m-4" method="POST" id="production-form">
1732
{% for article, article_name in data['articles'].items() %}
1833
<!-- Inputs of production -->
1934
<div class="w-full flex justify-between">

databases/production.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,28 @@
1919
"mozzarela": 0,
2020
"edamer": 0
2121
}
22+
},
23+
"3": {
24+
"date": "2023-11-28",
25+
"production": {
26+
"big_ball": 13,
27+
"small_ball": 2,
28+
"garlic_bread": 33,
29+
"mozzarela": 0,
30+
"edamer": 0
31+
}
32+
}
33+
},
34+
"Campo de Ourique": {
35+
"1": {
36+
"date": "2023-11-28",
37+
"production": {
38+
"big_ball": 28,
39+
"small_ball": 0,
40+
"garlic_bread": 0,
41+
"mozzarela": 0,
42+
"edamer": 0
43+
}
2244
}
2345
}
2446
}

databases/users.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"password": "Dez1633#",
66
"email": "[email protected]",
77
"store": 11,
8-
"last_login": "2023-11-27",
8+
"last_login": "2023-11-28",
99
"level": "Administrador"
1010
},
1111
"2": {
@@ -35,7 +35,7 @@
3535
"email": "[email protected]",
3636
"store": 3,
3737
"level": "Colaborador",
38-
"last_login": "2023-11-27",
38+
"last_login": "2023-11-28",
3939
"when_created": "2023-11-26"
4040
},
4141
"6": {

0 commit comments

Comments
 (0)