commit ef6289fec9ec0f440133b6d67090e13e58fee9a3
parent cc7f7ad426f7ba1e41907e77e4c66c5f0f647cb4
Author: Brennen T. Mazur <brennen@madis.cool>
Date: Thu, 26 Jan 2023 11:14:26 -0700
refined punchclock widget, fixed counting clock, created tmp data for refining views
Diffstat:
5 files changed, 52 insertions(+), 18 deletions(-)
diff --git a/app/forms.py b/app/forms.py
@@ -1,6 +1,6 @@
from flask_wtf import FlaskForm
-from wtforms import StringField, SubmitField, PasswordField, BooleanField
-from wtforms.validators import DataRequired
+from wtforms import StringField, SubmitField, PasswordField, BooleanField, SelectField
+from wtforms.validators import DataRequired, optional
# Login class currently assumes mongodb collection(Users) with structure
# {
@@ -8,9 +8,15 @@ from wtforms.validators import DataRequired
# Password: [hashed_password]
# }
class LoginForm(FlaskForm):
- username = StringField('username', validators=[DataRequired()])
+ username = StringField('Username', validators=[DataRequired()])
password = PasswordField('Password', validators=[DataRequired()])
remember_me = BooleanField('Remember Me')
login = SubmitField('Login')
-
+class PunchclockWidget(FlaskForm):
+ projectsSel = SelectField('Project', validators=[DataRequired()], coerce=str, choices=[])
+ #clockin = currenttime
+ lunchBox = BooleanField('Lunch')
+ perdiumBox = BooleanField('Perdium')
+ # IFF user.role is_in(trusted_role[]) then allow lunch minute definition
+ clockin = SubmitField('Clock In')
diff --git a/app/routes.py b/app/routes.py
@@ -3,7 +3,7 @@ from app import app
from flask_pymongo import PyMongo
from flask_login import LoginManager
from flask import render_template, url_for, request, flash
-from app.forms import LoginForm
+from app.forms import LoginForm, PunchclockWidget
from flask import request
from werkzeug.urls import url_parse
from werkzeug.security import generate_password_hash, check_password_hash
@@ -32,10 +32,10 @@ def signout():
# User Routes
# Page Routes
-@app.route('/') #main route should check if user is logged in, then redirect to /dashboard else redirect to /login
+@app.route('/')
@app.route('/index')
def hello():
- return render_template('index.html',ORGNAME = OrganizationName) #This implimentation is messy, maybe abstract to a defPage()?
+ return render_template('index.html',ORGNAME = OrganizationName) #This implimentation of ORGNAME is messy, maybe abstract to a defPage()?
@app.route("/login", methods=['GET', 'POST'])
def login():
@@ -61,7 +61,13 @@ def load_user(username):
@app.route("/dashboard")
def dashboard():
- return render_template('dashboard/layout.html',currenttime=datetime.datetime.utcnow(),ORGNAME=OrganizationName)
+ form=PunchclockWidget()
+ currenttime=datetime.datetime.utcnow()
+
+ user_data = {'fname':'Brennen','lname':'Mazur','role':'Crew Lead','clocked_in':True}
+ available_projects = [('stc webapp'),('stcapp','STC Webapp'),('yepsite','YEP Website'),('volday','Volunteer Day')]
+
+ return render_template('dashboard/layout.html',currenttime=currenttime,user=user_data,projects=available_projects,form=form,ORGNAME=OrganizationName)
@app.route("/admin")
def admin():
diff --git a/app/templates/base.html b/app/templates/base.html
@@ -9,7 +9,7 @@
{% endif %}
<link rel="stylesheet" href="{{ url_for('static', filename='css/main.css') }}">
</head>
-<body>
+<body onload="startTime()">
<header>
<div id="logo"><a href="/"><img src="{{ url_for('static', filename='imgs/logo.svg') }}" /></a></div> <!-- should direct to login,dashboard/admin, or main organization webpage? -->
{% block navigation %}{% endblock %} <!-- Above function call adds admin if permissive -->
@@ -24,6 +24,23 @@
<footer>
Engineered with ❤ for {{ ORGNAME }} with Sawtooth Systems
</footer>
+<script>
+function startTime() {
+ const today = new Date();
+ let h = today.getHours();
+ let m = today.getMinutes();
+ let s = today.getSeconds();
+ m = checkTime(m);
+ s = checkTime(s);
+ document.getElementById('clock').innerHTML = h + ":" + m + ":" + s;
+ setTimeout(startTime, 1000);
+}
+
+function checkTime(i) {
+ if (i < 10) {i = "0" + i}; // add zero in front of numbers < 10
+ return i;
+ }
+</script>
</body>
</html>
diff --git a/app/templates/dashboard/punchclock/index.html b/app/templates/dashboard/punchclock/index.html
@@ -10,7 +10,7 @@
<div><!-- abstract to payPeriod() -->
<h6>$payperiod range</h6>
</div>
- <form>
+ <form action="" method="post" novalidate>
<input type="submit" value="Request Changes">
<input type="reset">
<table><!-- replace w/ function getUserHours(username) -->
diff --git a/app/templates/dashboard/punchclock/widget.html b/app/templates/dashboard/punchclock/widget.html
@@ -1,17 +1,22 @@
<section class="punchclock">
- <h2>{{ currenttime }}</h2>
+ <h2 id="clock"></h2>
<button><a href="{{ url_for('hours') }}">Modify Hours</a></button><!--routes to userhours.html-->
- <form>
+ <form action="" method="" novalidate>
<select name="Project Name"><!--replace w/ selectProject() or FOR EACH loop for array passed as available Projects... Leaning towards latter -->
<option value="#">$#</option><!-- for/while loop displaying each $projectName user has permission for -->
<option value="2" selected>second project</option>
<option value="3">third project</option>
</select>
- <input type="submit" value="Clock In"><!--if user.isClockedIn()returns true value="Clock Out" AND Purdium changes to Lunch checkbox, elseif user.isClockedIn() returns true AND Project Name = isClockedIn().projectname CLOCK OUT and CLOCK IN with new PROJECT NAME -->
- <input type="checkbox" name="Lunch" value="lunch">
- <label for="Lunch">Lunch</label>
- <input type="checkbox" name="Perdium" value="perdium">
- <label for="Perdium">Perdium</label>
+ <p>{{ form.projectsSel.label }}<br>{{ form.projectsSel(choices=projects[]) }}</p>
+ <p>{{ form.lunchBox() }} {{ form.lunchBox.label }}
+ {{ form.perdiumBox() }} {{ form.perdiumBox.label }}</p>
+ <p>{{ form.clockin() }}</p>
</form>
- <h2>User.name</h2><!-- something like currenttime above -->
+ <!-- Add iff satement for clocked_in==True
+ <p> form.projects(choices=projects,default=(if(project[0]==0){return project[0].label })</p>
+ <p>{ form.clockout() }}</p>
+ <p>{ form.lunchBox() }} {{ form.lunchBox.label }}</p>
+ <p>{ form.perdiumBox() }} {{ form.perdiumBox.label }}</p>
+ -->
+ <h2>{{ user.fname }} {{ user.lname }}</h2><!-- something like currenttime above -->
</section>