diff --git a/osinaweb/db.sqlite3 b/osinaweb/db.sqlite3 index 2aa2545b..7ab556cc 100644 Binary files a/osinaweb/db.sqlite3 and b/osinaweb/db.sqlite3 differ diff --git a/osinaweb/osinacore/__pycache__/custom_context.cpython-311.pyc b/osinaweb/osinacore/__pycache__/custom_context.cpython-311.pyc index a24bf961..afe8e2ca 100644 Binary files a/osinaweb/osinacore/__pycache__/custom_context.cpython-311.pyc and b/osinaweb/osinacore/__pycache__/custom_context.cpython-311.pyc differ diff --git a/osinaweb/osinacore/__pycache__/views.cpython-311.pyc b/osinaweb/osinacore/__pycache__/views.cpython-311.pyc index 8029e463..9aff7fca 100644 Binary files a/osinaweb/osinacore/__pycache__/views.cpython-311.pyc and b/osinaweb/osinacore/__pycache__/views.cpython-311.pyc differ diff --git a/osinaweb/osinacore/custom_context.py b/osinaweb/osinacore/custom_context.py index 9f509bdc..1b578d5c 100644 --- a/osinaweb/osinacore/custom_context.py +++ b/osinaweb/osinacore/custom_context.py @@ -89,3 +89,5 @@ def last_status(request): return {'last_status' : last_status, 'current_date' : current_date, 'minutes_ago' : minutes_ago, 'hours_minutes_ago': hours_minutes_ago,} + + diff --git a/osinaweb/osinacore/views.py b/osinaweb/osinacore/views.py index 02b2eaa3..beeee3b2 100644 --- a/osinaweb/osinacore/views.py +++ b/osinaweb/osinacore/views.py @@ -12,6 +12,9 @@ from django.http import JsonResponse from .models import Task, Epic from datetime import date from django.http import HttpResponseRedirect +from django.template.loader import render_to_string +from .custom_context import calculate_time_ago + # Pages views @@ -1215,4 +1218,67 @@ def edit_tag(request, tag_id): return redirect('tags') - return render(request, 'edit_pages/edit-tag.html', {'tag': tag}) \ No newline at end of file + return render(request, 'edit_pages/edit-tag.html', {'tag': tag}) + + + +# TO UPDATE THE STATUS CONTAINER +def get_updated_last_status(request): + if request.user.is_authenticated: + last_status = Status.objects.filter(staff=request.user.staffprofile).last() + if last_status: + status_time = datetime.strptime(last_status.time, '%I:%M %p') + current_time = datetime.now().time() + time_difference = abs(datetime.combine(datetime.today(), current_time) - datetime.combine(datetime.today(), status_time.time())) + minutes_ago = int(time_difference.total_seconds() / 60) + else: + minutes_ago = 0 + else: + last_status = None + minutes_ago = 0 + + if minutes_ago > 60: + hours_ago = minutes_ago // 60 + remaining_minutes = minutes_ago % 60 + hours_minutes_ago = f"{hours_ago}hr {remaining_minutes}min ago" + else: + hours_minutes_ago = f"{minutes_ago}min ago" + + response_data = { + 'last_status': last_status, + 'minutes_ago': minutes_ago, + 'hours_minutes_ago': hours_minutes_ago, + } + + recent_status = render_to_string('recent-status.html', response_data) + + return HttpResponse(recent_status) + + +# TO GET USER ACTIVITIES +def get_latest_activities(request): + if request.user.is_authenticated and request.user.is_superuser: + open_task_count = Task.objects.filter(status='Open').count() + working_on_task_count = Task.objects.filter(status='Working On').count() + elif request.user.is_authenticated: + open_task_count = Task.objects.filter(assigned_to=request.user.staffprofile, status='Open').count() + working_on_task_count = Task.objects.filter(assigned_to=request.user.staffprofile, status='Working On').count() + else: + open_task_count = 0 + working_on_task_count = 0 + + total_tasks = open_task_count + working_on_task_count + + latest_statuses = Status.objects.all().order_by('-id')[:12] + + # Calculate time ago for each status and store it in a list of dictionaries + latest_statuses_time_ago = [{'status': status, 'time_ago': calculate_time_ago(status)} for status in latest_statuses] + + response_data = { + 'total_tasks': total_tasks, + 'latest_statuses_time_ago': latest_statuses_time_ago, # Include latest_statuses_time_ago in the context + } + + recent_activities = render_to_string('recent-activities.html', response_data) + + return HttpResponse(recent_activities) diff --git a/osinaweb/osinaweb/__pycache__/urls.cpython-311.pyc b/osinaweb/osinaweb/__pycache__/urls.cpython-311.pyc index 1539f2d0..8215dd62 100644 Binary files a/osinaweb/osinaweb/__pycache__/urls.cpython-311.pyc and b/osinaweb/osinaweb/__pycache__/urls.cpython-311.pyc differ diff --git a/osinaweb/osinaweb/urls.py b/osinaweb/osinaweb/urls.py index 91c542e7..a85cd8b2 100644 --- a/osinaweb/osinaweb/urls.py +++ b/osinaweb/osinaweb/urls.py @@ -52,7 +52,6 @@ urlpatterns = [ path('adddailyreport/', views.add_daily_report, name='adddailyreport'), - #Fetch urls path("fetch_related_tasks/", views.fetch_related_tasks, name="fetch_related_tasks"), @@ -111,6 +110,11 @@ urlpatterns = [ path('mark_point_completed///', views.mark_point_completed, name='mark_point_completed'), path('mark_point_completed_task_page///', views.mark_point_completed_task_page, name='mark_point_completed_task_page'), + + + + path('getupdatedlaststatus/', views.get_updated_last_status, name='getupdatedlaststatus'), + path('getupdatedactivities/', views.get_latest_activities, name='getupdatedactivities'), ] urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) \ No newline at end of file diff --git a/osinaweb/static/js/get-updated-last-status.js b/osinaweb/static/js/get-updated-last-status.js new file mode 100644 index 00000000..f03e8a18 --- /dev/null +++ b/osinaweb/static/js/get-updated-last-status.js @@ -0,0 +1,13 @@ +function refreshStatusContainer() { + + $.ajax({ + url: '/getupdatedlaststatus/', + method: 'GET', + dataType: 'html', + success: function(data) { + $('#statusContainer').html(data); + } + }); +} + +setInterval(refreshStatusContainer, 60000); \ No newline at end of file diff --git a/osinaweb/static/js/get-updated-user-activity.js b/osinaweb/static/js/get-updated-user-activity.js new file mode 100644 index 00000000..8f312e53 --- /dev/null +++ b/osinaweb/static/js/get-updated-user-activity.js @@ -0,0 +1,13 @@ +function refreshUserActivityContainer() { + + $.ajax({ + url: '/getupdatedactivities/', + method: 'GET', + dataType: 'html', + success: function(data) { + $('#activitiesContainer').html(data); + } + }); +} + +setInterval(refreshUserActivityContainer, 60000); \ No newline at end of file diff --git a/osinaweb/static/js/reload-script.js b/osinaweb/static/js/reload-script.js deleted file mode 100644 index aaccee26..00000000 --- a/osinaweb/static/js/reload-script.js +++ /dev/null @@ -1,17 +0,0 @@ -function autoRefreshDiv() { - var statusContainer = document.getElementById('statusContainer'); - var divs = document.querySelectorAll('.userActivityContainer'); - - divs.forEach(function (div) { - setInterval(function () { - div.innerHTML = div.innerHTML; - }, 15000); - }); - - // setInterval(function () { - - // statusContainer.innerHTML = statusContainer.innerHTML; - // }, 60000); -} - -window.onload = autoRefreshDiv; \ No newline at end of file diff --git a/osinaweb/templates/index.html b/osinaweb/templates/index.html index bed60835..d7a030dc 100644 --- a/osinaweb/templates/index.html +++ b/osinaweb/templates/index.html @@ -185,51 +185,9 @@

USERS ACTIVITY

-
- - - {% for latest in latest_statuses_time_ago %} - -
-
-
-
-
- user profile -
-
-

{{latest.status.staff.first_name}} - {{latest.status.staff.last_name}}

- {% if latest.time_ago == '0min ago' %} -

Just Now

- {%else %} -

{{ latest.time_ago}}

- {%endif%} -
-
-
- -
-
- - -
-

{{latest.status.text}}

-
- - -
- - -
-
-
- {% endfor %} +
+ {% include 'recent-activities.html' %}
diff --git a/osinaweb/templates/main.html b/osinaweb/templates/main.html index 02a7ea7e..ca721181 100644 --- a/osinaweb/templates/main.html +++ b/osinaweb/templates/main.html @@ -9,6 +9,8 @@ + + @@ -222,22 +224,8 @@
-
-
-

Recent Status: {{last_status.text}}

-

Last update: - {% if last_status.date == current_date %} - Today | {{last_status.time}}, - {% if minutes_ago == 0 %} - Just Now - {%else%} - {{hours_minutes_ago}} - {%endif%} - {% else %} - {{last_status.date}} | {{last_status.time}} - {%endif %}

-
+
+ {% include 'recent-status.html' %} +
+
+ + +{% endfor %} \ No newline at end of file diff --git a/osinaweb/templates/recent-status.html b/osinaweb/templates/recent-status.html new file mode 100644 index 00000000..62eb1939 --- /dev/null +++ b/osinaweb/templates/recent-status.html @@ -0,0 +1,15 @@ +
+

Recent Status: {{last_status.text}}

+

Last update: + {% if last_status.date == current_date %} + Today | {{last_status.time}}, + {% if minutes_ago == 0 %} + Just Now + {%else%} + {{hours_minutes_ago}} + {%endif%} + {% else %} + {{last_status.date}} | {{last_status.time}} + {%endif %}

+
\ No newline at end of file