emile 1 year ago
parent cd429ec385
commit 1cc23d56b9

Binary file not shown.

@ -35,4 +35,5 @@ admin.site.register(Tag)
admin.site.register(Point) admin.site.register(Point)
admin.site.register(DailyReport) admin.site.register(DailyReport)
admin.site.register(BusinessType) admin.site.register(BusinessType)
admin.site.register(PointActivity)

@ -0,0 +1,29 @@
# Generated by Django 4.2.5 on 2024-01-31 13:37
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('osinacore', '0053_pointactivity'),
]
operations = [
migrations.RemoveField(
model_name='point',
name='date_completed',
),
migrations.RemoveField(
model_name='point',
name='date_workingon',
),
migrations.RemoveField(
model_name='point',
name='time_completed',
),
migrations.RemoveField(
model_name='point',
name='time_workingon',
),
]

@ -0,0 +1,18 @@
# Generated by Django 4.2.5 on 2024-01-31 13:40
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('osinacore', '0054_remove_point_date_completed_and_more'),
]
operations = [
migrations.AlterField(
model_name='point',
name='status',
field=models.CharField(choices=[('Not Completed', 'Not Completed'), ('Working On', 'Working On'), ('Paused', 'Paused'), ('Completed', 'Completed')], max_length=200, null=True),
),
]

@ -0,0 +1,18 @@
# Generated by Django 4.2.5 on 2024-01-31 14:00
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('osinacore', '0055_alter_point_status'),
]
operations = [
migrations.AlterField(
model_name='pointactivity',
name='end_time',
field=models.DateTimeField(blank=True, null=True),
),
]

@ -0,0 +1,28 @@
# Generated by Django 4.2.5 on 2024-01-31 14:36
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('osinacore', '0056_alter_pointactivity_end_time'),
]
operations = [
migrations.AddField(
model_name='point',
name='total_time_hours',
field=models.IntegerField(default=0),
),
migrations.AddField(
model_name='point',
name='total_time_minutes',
field=models.IntegerField(default=0),
),
migrations.AddField(
model_name='point',
name='total_time_seconds',
field=models.IntegerField(default=0),
),
]

@ -0,0 +1,25 @@
# Generated by Django 4.2.5 on 2024-01-31 14:47
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('osinacore', '0057_point_total_time_hours_point_total_time_minutes_and_more'),
]
operations = [
migrations.RemoveField(
model_name='point',
name='total_time_hours',
),
migrations.RemoveField(
model_name='point',
name='total_time_minutes',
),
migrations.RemoveField(
model_name='point',
name='total_time_seconds',
),
]

@ -4,6 +4,8 @@ from colorfield.fields import ColorField
from datetime import datetime from datetime import datetime
from django.db.models import Max from django.db.models import Max
from django.utils import timezone from django.utils import timezone
from django.db.models import Sum
from datetime import timedelta
# Create your models here. # Create your models here.
@ -249,20 +251,43 @@ class Point(models.Model):
STATUS_CHOICES = ( STATUS_CHOICES = (
('Not Completed', 'Not Completed'), ('Not Completed', 'Not Completed'),
('Working On', 'Working On'), ('Working On', 'Working On'),
('Paused', 'Paused'),
('Completed', 'Completed') ('Completed', 'Completed')
) )
status = models.CharField(max_length=200, choices=STATUS_CHOICES, null=True) status = models.CharField(max_length=200, choices=STATUS_CHOICES, null=True)
task = models.ForeignKey(Task, on_delete=models.CASCADE, null=True) task = models.ForeignKey(Task, on_delete=models.CASCADE, null=True)
date_workingon = models.CharField(max_length=200, null=True, blank=True) def total_time(self):
date_completed = models.CharField(max_length=200, null=True, blank=True) # Calculate the total time for ongoing activities
time_workingon = models.CharField(max_length=200, null=True, blank=True) ongoing_total_time_timedelta = timedelta()
time_completed = models.CharField(max_length=200, null=True, blank=True) ongoing_activities = self.pointactivity_set.filter(end_time__isnull=True)
for activity in ongoing_activities:
start_time_aware = activity.start_time
current_time_aware = timezone.now()
ongoing_total_time_timedelta += current_time_aware - start_time_aware
# Calculate the total time for completed activities
completed_total_time_timedelta = self.pointactivity_set.filter(end_time__isnull=False).aggregate(total_time=Sum(models.F('end_time') - models.F('start_time')))['total_time']
# Add the total times together
total_time_timedelta = ongoing_total_time_timedelta + (completed_total_time_timedelta or timedelta())
# Convert total seconds to timedelta
total_time_timedelta = timedelta(seconds=total_time_timedelta.total_seconds())
# Extract hours, minutes, and seconds from timedelta
hours, remainder = divmod(total_time_timedelta.seconds, 3600)
minutes, seconds = divmod(remainder, 60)
# Return the total time as a tuple (hours, minutes, seconds)
return hours, minutes, seconds
class PointActivity(models.Model): class PointActivity(models.Model):
point = models.ForeignKey(Point, on_delete=models.CASCADE, null=True) point = models.ForeignKey(Point, on_delete=models.CASCADE, null=True)
start_time = models.DateTimeField() start_time = models.DateTimeField()
end_time = models.DateTimeField() end_time = models.DateTimeField(null=True, blank=True)

@ -1192,100 +1192,6 @@ def save_point(request):
@login_required
def mark_point_working_on(request, point_id, task_id):
task = get_object_or_404(Task, id=task_id)
point = get_object_or_404(Point, id=point_id)
point.status = 'Working On'
current_datetime = datetime.now()
point.date_workingon = current_datetime.date()
point.time_workingon = current_datetime.strftime("%I:%M %p")
point.save()
# Create a new Status object
status_text = f'Working On: {point.text}'
status = Status(text=status_text, date=current_datetime.date(), time=current_datetime.strftime("%I:%M %p"), staff=request.user.staffprofile)
status.save()
task_id_str = task.task_id
showpoints_url = reverse('showpoints', args=[task_id_str])
return HttpResponseRedirect(showpoints_url)
@login_required
def mark_point_working_on_task_page(request, point_id, task_id):
task = get_object_or_404(Task, id=task_id)
point = get_object_or_404(Point, id=point_id)
point.status = 'Working On'
current_datetime = datetime.now()
point.date_workingon = current_datetime.date()
point.time_workingon = current_datetime.strftime("%I:%M %p")
point.save()
# Create a new Status object
status_text = f'Working On: {point.text}'
status = Status(text=status_text, date=current_datetime.date(), time=current_datetime.strftime("%I:%M %p"), staff=request.user.staffprofile)
status.save()
return redirect('detailed-task', task_id=task.task_id)
@login_required
def mark_point_completed(request, point_id, task_id):
task = get_object_or_404(Task, id=task_id)
point = get_object_or_404(Point, id=point_id)
point.status = 'Completed'
current_datetime = datetime.now()
point.date_workingon = current_datetime.date()
point.time_workingon = current_datetime.strftime("%I:%M %p")
point.save()
# Create a new Status object
status_text = f'{point.text} - Completed'
status = Status(text=status_text, date=current_datetime.date(), time=current_datetime.strftime("%I:%M %p"), staff=request.user.staffprofile)
status.save()
task_id_str = task.task_id
showpoints_url = reverse('showpoints', args=[task_id_str])
return HttpResponseRedirect(showpoints_url)
@login_required
def mark_point_completed_task_page(request, point_id, task_id):
task = get_object_or_404(Task, id=task_id)
point = get_object_or_404(Point, id=point_id)
point.status = 'Completed'
current_datetime = datetime.now()
point.date_workingon = current_datetime.date()
point.time_workingon = current_datetime.strftime("%I:%M %p")
point.save()
# Create a new Status object
status_text = f'{point.text} - Completed'
status = Status(text=status_text, date=current_datetime.date(), time=current_datetime.strftime("%I:%M %p"), staff=request.user.staffprofile)
status.save()
task_id_str = task.task_id
return redirect('detailed-task', task_id=task.task_id)
@login_required @login_required
def save_dailyreport(request): def save_dailyreport(request):
if request.method == 'POST': if request.method == 'POST':
@ -1858,4 +1764,161 @@ def delete_task_modal(request, task_id):
context = { context = {
'task': task, 'task': task,
} }
return render(request, "delete_modals/delete-task-modal.html", context) return render(request, "delete_modals/delete-task-modal.html", context)
#Mark points
@login_required
def mark_point_working_on(request, point_id, task_id):
task = get_object_or_404(Task, id=task_id)
point = get_object_or_404(Point, id=point_id)
point.status = 'Working On'
current_datetime = datetime.now()
point.save()
activity = PointActivity(
point = point,
start_time = datetime.now(),
)
activity.save()
if PointActivity.objects.filter(point=point).count() == 1:
status_text = f'Started Working On: {point.text}'
status = Status(text=status_text, date=current_datetime.date(), time=current_datetime.strftime("%I:%M %p"), staff=request.user.staffprofile)
status.save()
else:
status_text = f'Resumed Working On: {point.text}'
status = Status(text=status_text, date=current_datetime.date(), time=current_datetime.strftime("%I:%M %p"), staff=request.user.staffprofile)
status.save()
task_id_str = task.task_id
showpoints_url = reverse('showpoints', args=[task_id_str])
return HttpResponseRedirect(showpoints_url)
@login_required
def mark_point_working_on_task_page(request, point_id, task_id):
task = get_object_or_404(Task, id=task_id)
point = get_object_or_404(Point, id=point_id)
point.status = 'Working On'
current_datetime = datetime.now()
point.save()
activity = PointActivity(
point = point,
start_time = datetime.now(),
)
activity.save()
if PointActivity.objects.filter(point=point).count() == 1:
status_text = f'Started Working On: {point.text}'
status = Status(text=status_text, date=current_datetime.date(), time=current_datetime.strftime("%I:%M %p"), staff=request.user.staffprofile)
status.save()
else:
status_text = f'Resumed Working On: {point.text}'
status = Status(text=status_text, date=current_datetime.date(), time=current_datetime.strftime("%I:%M %p"), staff=request.user.staffprofile)
status.save()
return redirect('detailed-task', task_id=task.task_id)
@login_required
def mark_point_paused(request, point_id, task_id):
task = get_object_or_404(Task, id=task_id)
point = get_object_or_404(Point, id=point_id)
point.status = 'Paused'
current_datetime = datetime.now()
point.save()
last_activity = PointActivity.objects.filter(point=point).last()
last_activity.end_time = datetime.now()
last_activity.save()
status_text = f'{point.text} - Paused'
status = Status(text=status_text, date=current_datetime.date(), time=current_datetime.strftime("%I:%M %p"), staff=request.user.staffprofile)
status.save()
task_id_str = task.task_id
showpoints_url = reverse('showpoints', args=[task_id_str])
return HttpResponseRedirect(showpoints_url)
@login_required
def mark_point_completed(request, point_id, task_id):
task = get_object_or_404(Task, id=task_id)
point = get_object_or_404(Point, id=point_id)
point.status = 'Completed'
current_datetime = datetime.now()
point.save()
last_activity = PointActivity.objects.filter(point=point).last()
last_activity.end_time = datetime.now()
last_activity.save()
status_text = f'{point.text} - Completed'
status = Status(text=status_text, date=current_datetime.date(), time=current_datetime.strftime("%I:%M %p"), staff=request.user.staffprofile)
status.save()
task_id_str = task.task_id
showpoints_url = reverse('showpoints', args=[task_id_str])
return HttpResponseRedirect(showpoints_url)
@login_required
def mark_point_completed_task_page(request, point_id, task_id):
task = get_object_or_404(Task, id=task_id)
point = get_object_or_404(Point, id=point_id)
point.status = 'Completed'
current_datetime = datetime.now()
point.save()
last_activity = PointActivity.objects.filter(point=point).last()
last_activity.end_time = datetime.now()
last_activity.save()
status_text = f'{point.text} - Completed'
status = Status(text=status_text, date=current_datetime.date(), time=current_datetime.strftime("%I:%M %p"), staff=request.user.staffprofile)
status.save()
task_id_str = task.task_id
return redirect('detailed-task', task_id=task.task_id)

@ -140,6 +140,7 @@ urlpatterns = [
path('mark_point_working_on_task_page/<int:point_id>/<str:task_id>/', views.mark_point_working_on_task_page, name='mark_point_working_on_task_page'), path('mark_point_working_on_task_page/<int:point_id>/<str:task_id>/', views.mark_point_working_on_task_page, name='mark_point_working_on_task_page'),
path('mark_point_completed/<int:point_id>/<str:task_id>/', views.mark_point_completed, name='mark_point_completed'), path('mark_point_completed/<int:point_id>/<str:task_id>/', views.mark_point_completed, name='mark_point_completed'),
path('mark_point_completed_task_page/<int:point_id>/<str:task_id>/', views.mark_point_completed_task_page, name='mark_point_completed_task_page'), path('mark_point_completed_task_page/<int:point_id>/<str:task_id>/', views.mark_point_completed_task_page, name='mark_point_completed_task_page'),
path('mark_point_paused/<int:point_id>/<str:task_id>/', views.mark_point_paused, name='mark_point_paused'),

@ -21,53 +21,46 @@
<div class="w-full pr-4"> <div class="w-full pr-4">
{% for point in points %} {% for point in points %}
{% if point.status == 'Not Completed' %}
<div class="w-full flex flex-col gap-1"> <div class="w-full flex flex-col gap-1">
<div class="w-full flex justify-between items-end py-2 border-b border-gray-200"> <div class="w-full flex justify-between items-end py-2 border-b border-gray-200">
<div class="w-[380px]"> <div class="w-[380px]">
{% if point.status == 'Completed' %}
<p class="text-slate-800 line-through">{{point.text}}</p>
{% else %}
<p class="text-slate-800">{{point.text}}</p> <p class="text-slate-800">{{point.text}}</p>
{% endif %}
</div> </div>
<!-- <div class="flex justify-end items-center gap-2">
<form method="post" action="{% url 'mark_point_working_on' point.id task.id %}">
{% csrf_token %}
<button type="submit"
class="w-[120px] px-2 py-1 bg-transparent border border-yellow-500 rounded-md text-yellow-500 hover:bg-yellow-500 hover:text-white">Working
On</button>
</form>
<form method="post" action="{% url 'mark_point_completed' point.id task.id %}">
{% csrf_token %}
<button type="submit"
class="w-[120px] px-2 py-1 bg-transparent border border-blue-500 rounded-md text-blue-500 hover:bg-blue-500 hover:text-white">Complete</button>
</form>
<form method="post" action="{% url 'deletepointmodal' point.id task.id %}">
{% csrf_token %}
<button type="submit"
class="w-fit px-2 py-1 bg-white border border-red-500 rounded-md text-red-500 hover:bg-red-500 hover:text-white cursor-pointer">
<i class="fa fa-trash"></i>
</button>
</form>
</div> -->
<div class="flex justify-end items-center gap-2"> <div class="flex justify-end items-center gap-2">
<button {% if point.status == 'Not Completed' or point.status == 'Paused' and not point.status == 'Completed' %}
class="w-[40px] h-[40px] rounded-full bg-gray-50 shadow-md text-gray-500 border border-gray-100 flex justify-center items-center hover:scale-105 transition-transform duration-300" <a href="{% url 'mark_point_working_on' point.id task.id %}"><button
id="startPointButton"> class="w-[40px] h-[40px] rounded-full bg-gray-50 shadow-md text-gray-500 border border-gray-100 flex justify-center items-center hover:scale-105 transition-transform duration-300"
<i class="fa fa-play"></i> id="startPointButton">
</button> <i class="fa fa-play"></i>
<button </button></a>
class="w-[40px] h-[40px] rounded-full bg-gray-50 shadow-md text-gray-500 border border-gray-100 justify-center items-center hidden hover:scale-105 transition-transform duration-300" {% endif %}
{% if point.status == 'Working On' and not point.status == 'Completed' %}
<a href="{% url 'mark_point_paused' point.id task.id %}"><button
class="w-[40px] h-[40px] rounded-full bg-gray-50 shadow-md text-gray-500 border border-gray-100 justify-center items-center hover:scale-105 transition-transform duration-300"
id="pausePointButton"> id="pausePointButton">
<i class="fa fa-pause"></i> <i class="fa fa-pause"></i>
</button> </button></a>
<button {% endif %}
{% if not point.status == 'Completed' and not point.status == 'Paused' %}
<a href="{% url 'mark_point_completed' point.id task.id %}"><button
class="w-[40px] h-[40px] rounded-full bg-green-700 shadow-md text-white border border-green-700 flex justify-center items-center hover:scale-105 transition-transform duration-300"> class="w-[40px] h-[40px] rounded-full bg-green-700 shadow-md text-white border border-green-700 flex justify-center items-center hover:scale-105 transition-transform duration-300">
<i class="fa fa-check"></i> <i class="fa fa-check"></i></a>
</button> </button>
{% endif %}
<!-- COMPLETED BUTTON --> {% if point.status == 'Completed' %}
<!-- <button <button
class="w-[40px] h-[40px] rounded-full bg-green-700 shadow-md text-white border border-green-700 flex justify-center items-center opacity-20 cursor-default"> class="w-[40px] h-[40px] rounded-full bg-green-700 shadow-md text-white border border-green-700 flex justify-center items-center opacity-20 cursor-default">
<i class="fa fa-check"></i> <i class="fa fa-check"></i>
</button> --> </button>
{% endif %}
<form method="post" action="{% url 'deletepointmodal' point.id task.id %}"> <form method="post" action="{% url 'deletepointmodal' point.id task.id %}">
{% csrf_token %} {% csrf_token %}
@ -80,57 +73,34 @@
</div> </div>
<div class="w-full"> <div class="w-full">
<p class="text-gray-500 text-sm">Total Time: <span <p class="text-gray-500 text-sm">Total Time:
class="font-semibold pointTotalTime text-red-500">0min</span></p> <span class="font-semibold pointTotalTime text-red-500">
</div> {% if point.total_time.0 > 0 %}
</div> {{ point.total_time.0 }}hr
{% if point.total_time.1 > 0 %}
{% endif %} ,
{% endif %}
{% if point.status == 'Completed' %} {% endif %}
<div class="w-full flex justify-between items-center py-2 border-b border-gray-200">
<div class="w-[380px]"> {% if point.total_time.1 > 0 %}
<p class="text-slate-800 line-through">{{point.text}}</p> {{ point.total_time.1 }}min
</div> {% if point.total_time.2 > 0 %}
<div class="w-[150px]"> ,
<button class="w-full px-2 py-1 bg-blue-500 border border-blue-500 rounded-md text-white opacity-40" {%endif%}
value="Completed" disabled>Completed</button> {% endif %}
</div>
</div> {% if point.total_time.2 > 0 %}
{% endif %} {{ point.total_time.2 }}sec
{% endif %}
</span>
{% if point.status == 'Working On' %} </p>
<div class="w-full flex justify-between items-center py-2 border-b border-gray-200">
<div class="w-[380px]">
<p class="text-slate-800">{{point.text}}</p>
</div>
<div class="flex justify-end items-center gap-2">
<button
class="w-[120px] px-2 py-1 border border-yellow-500 rounded-md bg-yellow-500 text-white opacity-40"
disabled>Working On</button>
<form method="post" action="{% url 'mark_point_completed' point.id task.id %}">
{% csrf_token %}
<button type="submit"
class="w-[120px] px-2 py-1 bg-transparent border border-blue-500 rounded-md text-blue-500 hover:bg-blue-500 hover:text-white">Complete</button>
</form>
<form method="post" action="{% url 'deletepointmodal' point.id task.id %}">
{% csrf_token %}
<button type="submit"
class="w-fit px-2 py-1 bg-white border border-red-500 rounded-md text-red-500 hover:bg-red-500 hover:text-white cursor-pointer">
<i class="fa fa-trash"></i>
</button>
</form>
</div> </div>
</div>
{% endif %}
{% endfor %} {% endfor %}
</div> </div>
</div> </div>
<!---------------------- JS SCRIPTS --------------------> <!---------------------- JS SCRIPTS -------------------->
<script type="text/javascript" src='{% static "js/points.js" %}'></script>
</body> </body>
</html> </html>
Loading…
Cancel
Save