From e0cdb10fabebd9780cf88dd013acba93883f8732 Mon Sep 17 00:00:00 2001 From: emile Date: Fri, 22 Mar 2024 19:45:46 +0200 Subject: [PATCH] New changes --- osinaweb/celerybeat-schedule.db | Bin 16384 -> 16384 bytes osinaweb/db.sqlite3 | Bin 962560 -> 974848 bytes .../__pycache__/admin.cpython-310.pyc | Bin 1827 -> 1851 bytes .../__pycache__/models.cpython-310.pyc | Bin 11458 -> 11708 bytes .../__pycache__/urls.cpython-310.pyc | Bin 3399 -> 3481 bytes .../__pycache__/views.cpython-310.pyc | Bin 11026 -> 11823 bytes osinaweb/osinacore/admin.py | 1 + .../osinacore/migrations/0064_reaction.py | 25 +++++++++++ .../__pycache__/0064_reaction.cpython-310.pyc | Bin 0 -> 1022 bytes osinaweb/osinacore/models.py | 6 +++ osinaweb/osinacore/templates/main.html | 1 + .../templates/recent-activities.html | 39 +++++++++++++++--- osinaweb/osinacore/urls.py | 2 +- osinaweb/osinacore/views.py | 29 ++++++++++++- osinaweb/static/js/emoji-picker.js | 4 +- 15 files changed, 98 insertions(+), 9 deletions(-) create mode 100644 osinaweb/osinacore/migrations/0064_reaction.py create mode 100644 osinaweb/osinacore/migrations/__pycache__/0064_reaction.cpython-310.pyc diff --git a/osinaweb/celerybeat-schedule.db b/osinaweb/celerybeat-schedule.db index 6507ddcc8613758f731f4b45721c993058090466..931ef97d7a8341841d7c31cf46d4527328e62b30 100644 GIT binary patch delta 36 rcmZo@U~Fh$+^|EA)slfh(|Yn=xj@FM$^7z}tP++?{aTxA<(m}%$*2mF delta 36 scmZo@U~Fh$+^|EARf2&*r)lzDxj@Fq$^7z}tYVrheHS;^$~P+j0L|T}TvB6ux(6c4l|4cgD?ZwUQksMP+rG-F3B;exxk0(lR5$hjntNnyB5{T`eC< zSNfrcqEMRXr2^5HB4QsFBHb+rf_;g!UVQ1Hhk~*&2qJ>+GC7$`4SZbY@SX2`=bV{4 z{I+>G+j4!4D+2(SC;0uqYd7iwF!QK)+(TER+$bmRp-?X68tzAHOLx&eM>MWS)V^p; z3&k|GFQG>xS@(v5^62b(uYJ%-gk=;RRi5Vsga{g!qX)TtfFK!9R8y)mA*HD`y6YF@B$EC3*$mu*dbK#^L&OMj` zz8o)*re5Kp%H&oXfYs~&wy;f&h5nbJrdT=TKlrb6Y7s^v5+1P9of(jJgjL-AqC7EzWYqs&|?1uDU#UP zAxedbl2{}CmX~Uio{?hCeUMmb{g;(^LQV9?^JW@1YQaYT5p}7i-Tdvqr)6#mv;ODD zVoS9nJtG3=_W7s_p@e$)gtoMpS*tJtK5px3Ywd0mjTbj*7fnWD?47~QmDnhTnY4{d>7g!rjIgmcli;8~%!?2WY delta 400 zcmZoTVBPS*YJ#-jCI$wE*FX#fjNKD;j2Sm=Ojsh%tj7IlGP{EBX2FJ9Zb2SJ1|5#P z)bjZFl&r)&-av-UkF=#28TV}dt8vZ-5jL|^zmATtnPcs5B6A&{4F$)m0 z0x=s9vjZ^)5OV@C*Y?)a-1S$)IC)(e_?Pns@_pl5#+S$^#e0ailh+k!k~Z&l*R?$R zKQX7WEu7B2fcG@e!t<=#7cS#X<`m)Jo5H|OW@9&G H5?}-XWA6;7 diff --git a/osinaweb/osinacore/__pycache__/models.cpython-310.pyc b/osinaweb/osinacore/__pycache__/models.cpython-310.pyc index 9bf61668731b4eac3bee8163141fb35fc52bca22..1d7b0e945711f600f2f3e89ee6ef0627901f1b50 100644 GIT binary patch delta 310 zcmX>UxhI-0pO=@50SI_^{!Kk(GLcV)@ykZ-hl~>L3@OGbCM^spCaH{Be9g>JDk-MH z44P(}g_tg?bFlz*H~?|6#pJ(S;*%W&xXqb+8KXE;nX_0@xqu{F3S%!*6n6>>P!H=Z zj-b@U0Y)B15yr{>T4IwQYsT}R0Sa0JWs6P%8AWF%2WnLao&z#9 znQpQBr={g&=A{;$pL|QJQ2s1X)EQ(B$m1LgEQ|syAd`wf;(nT{le4rxvw=)2Iy>2) WReW-(4nL#K`+5*)UgG}aNU||$s n;b9bEECPx9X{t<))%nbLdU7JG_~cw&enzXwwYpZ!oMIdR=szaS diff --git a/osinaweb/osinacore/__pycache__/urls.cpython-310.pyc b/osinaweb/osinacore/__pycache__/urls.cpython-310.pyc index 45facdba352acd7f3cdd8e46fc34c9773a4b9bf0..bb1d3cc2f850e5b551fe3edd31d21052d72b9adb 100644 GIT binary patch delta 184 zcmX>uHB*`|pO=@50SJut|4lXFo5&}_IB%nNIg?H*Q;L5oYnFCOKnhp1w_HUWrw4Nn%N9 zaeQWqoxV+RNs(1*Zhls#o&GHzWTlfgaK8dB#w8`OwH#evUKs)`FyS|lV4m2o|ru*O-3*>P#2 z*}5X-f@C3Bi4%wT1_)YJDR6^QBo0kMK|(^Z5dQ%u#03$-n{{G>y4LFRcWAOK_NB#txE?-wlkJIxnD$a$SY4X*>@JaORiL3Bg zR2d(Mg5pWI5p{|i@OgB6;u7raT%Gt0;C6IzY7V}L-kF+&FQbpA!qzvqbrocQgC~ch zj_-5$24|4rN)2j+0wrzOR;k*7n#OgiZ2{HW5W=bw5&>tGi^WhC$RATe4Mzh4peJBE?!wQNo@>xL~~$I_3fsw(R3?J&~#{ugfJgc!X(db=P-;VES{|m&#VWj)t`3DWiRlX^*S5F56+GwIM5xaSGXJSa<$?6Zk2lt zpWTrRVWmSaHiEOLIMamRqYr0Jfg0`3%(c2h4ZrUBZZAf;7sL%VhnZV-eSWfnn_c#} z=LUD&%qHcAQxcw(a0{VpR(!v~F@>)BLgh+VU-4ML*{Gz9%KEzN(_XfxrD9yd zGZL~&54qv`YLvDxW!IW~{>QvQL{1nfH`y4I2N#Rt11-Lv(||BfELHtWE*(Yv!J zjJwFQucMo@&pv+!rv?zv{xOLG#=fSTAb$n0AOqxD4)QoRVFX4&BN~{*RC8)U&8S2r zs5AC0!zAopbbh7~EzUKwe_^i&8t$qQTVuP?Ph&IDFLTRTjVQ_=v0X*`{n-A>JZ)vr z&VG;y{fJOi5e}aOPWpG~5-zyHK>&p|!8@YVNT_kOrqy(z3Jvd7?`G&iXOn^my_^vG zw%JiY;Yq4e%>&s(vBE+HL5<#Ssi6_mMvrz9OYBn&g*_q*6&I+RSaXA*vg&S*UvOpV z8-B65PO-4G7&NO@Bv-KYHWnSVS6$s*Yt+10yE)dER49EwkZLjcP1wu*SmvSsk#724 zvU>5u8Na8r>w`1>OwG9*y1pOT9GUUhx9%`Kx7ikb24X-M9Ly)69{Z z#jqeF*qCOYJ%+^z@@Tffz&6mpAST$5S8ZTFqj|}BVrOrD1DqRjlN|~2pOD>?uq)xd h1XAM|8nB!ohj*lw+pIn-k|`TicYpv4_w>=k(36jlc0T!G?8SZ1Vd%cEmVWu|W8 z3tKo%=x3Rg_UMZ!OSp8AobZ+*vxP5u7MZdyum)s~GL$27_j%@~d68FcgJ)hED6auD zxnM$`WcY1F!VX@poC1zmiSS+Js9TUldbb?JokP6`&QSQlnwh&=Pvu#P@my54eOcAv zN)*Fu+>VCqHGcbEe$DRy=~^@nqpQ z@jp7eLHs81O9z3I*p^m&OE3|iZhsxU2IW=FtZC4nCf7A=XxP-Cx5^kxeZ6?E7Qiih OP`mDh-1mWd0sIH`UzIBW diff --git a/osinaweb/osinacore/admin.py b/osinaweb/osinacore/admin.py index f5010357..70367cb4 100644 --- a/osinaweb/osinacore/admin.py +++ b/osinaweb/osinacore/admin.py @@ -45,4 +45,5 @@ admin.site.register(DailyReport) admin.site.register(BusinessType) admin.site.register(PointActivity) admin.site.register(Connection) +admin.site.register(Reaction) diff --git a/osinaweb/osinacore/migrations/0064_reaction.py b/osinaweb/osinacore/migrations/0064_reaction.py new file mode 100644 index 00000000..d751036c --- /dev/null +++ b/osinaweb/osinacore/migrations/0064_reaction.py @@ -0,0 +1,25 @@ +# Generated by Django 4.2.5 on 2024-03-22 17:00 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('osinacore', '0063_alter_connection_date'), + ] + + operations = [ + migrations.CreateModel( + name='Reaction', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('emoji', models.CharField(max_length=15)), + ('status', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='osinacore.status')), + ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ], + ), + ] diff --git a/osinaweb/osinacore/migrations/__pycache__/0064_reaction.cpython-310.pyc b/osinaweb/osinacore/migrations/__pycache__/0064_reaction.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..760d351abe0b37274aab02c0243e90c46e465fd9 GIT binary patch literal 1022 zcmY*Y&2G~`5caMe$99q?MHQkwAuf!09tC@B{t zxaJ+;$RqG7d*#$uKu{Rl{bQwF&CHH>zVDlH+G;r(uGJrZ;G?c-KMUvfGSJz;EuY~b zG(jRQCLSS$O(PoXo*o;XQTlpR^UPP8FhuQ(CTgIE_0PIj7y3x+n&eaE9C8*HB z4jrtI2!tu>3*(3i3u6so3ui&lYoOPJR=5<}VLR-Irf4lF#+Uw&7jIWLz9HHR>Jx8S zbdblgvUjdPBLh2?LBc0#25N16{pn-IqZ~3eNs|O71u-Ug4$9gGUb>0~;$TbBH^Z)> zntYb0Y?1+{2-TQoLCmu`JAt{fC1e4Qf-_Lf_mGWK2`u3;s2ap+7@W6J3l!6d`3Dw3 z;^)W8lsV65@~m?WsaHixmI7innwXdLhg3&D2tU<7*h^o*pOKS zXg3*qH{(%}%vgp~qNx>m%BNF4#(M!%NCYI4c}9z?cK`6;H9H(_?z5e};pVn#US|X# zRbx={-6^`A71O1fF9W}iN^BJ{ls!1+S!Fs~sB7RSZ&46aggo(6Ma5WIB^4A`)d&62 zpg-JHPCA9lN&2p35AoUZ_$A##q$*vAg9spsf;qTDkSBRMbw{Xge1Dry3ujLT`6P|q zQam?-)6%GlR>4ykS4Poo_hxck?E4djq{;^Ort_?Z0QZ?Jt+7VRd1MA)+3B5>v`45 Q7X&?70Bh0?vB+KhAO7AhJ^%m! literal 0 HcmV?d00001 diff --git a/osinaweb/osinacore/models.py b/osinaweb/osinacore/models.py index a593b39d..f7115cf5 100644 --- a/osinaweb/osinacore/models.py +++ b/osinaweb/osinacore/models.py @@ -304,6 +304,12 @@ class Status(models.Model): staff = models.ForeignKey(StaffProfile, on_delete=models.CASCADE, null=True,blank=True, related_name='staff') +class Reaction(models.Model): + status = models.ForeignKey(Status, on_delete=models.CASCADE) + emoji = models.CharField(max_length=15) + user = models.ForeignKey(User, on_delete=models.CASCADE) + + class DailyReport(models.Model): diff --git a/osinaweb/osinacore/templates/main.html b/osinaweb/osinacore/templates/main.html index 0a3c9f4b..80b25c03 100644 --- a/osinaweb/osinacore/templates/main.html +++ b/osinaweb/osinacore/templates/main.html @@ -3,6 +3,7 @@ + {% block title %} Osina {% endblock %} diff --git a/osinaweb/osinacore/templates/recent-activities.html b/osinaweb/osinacore/templates/recent-activities.html index a41f2863..8574451b 100644 --- a/osinaweb/osinacore/templates/recent-activities.html +++ b/osinaweb/osinacore/templates/recent-activities.html @@ -15,7 +15,7 @@

Add Reaction

- + {% csrf_token %}
@@ -43,6 +43,31 @@
+ + +
@@ -150,9 +175,9 @@ {%endif%}
- +
-
+
@@ -177,11 +202,13 @@
+ {% if latest.status.reaction_set.all %}
-

😄

-

😅

-

🍀

+ {% for reaction in latest.status.reaction_set.all %} +

{{reaction.emoji}}

+ {% endfor %}
+ {% endif %} {% endfor %} diff --git a/osinaweb/osinacore/urls.py b/osinaweb/osinacore/urls.py index bf889493..baaa66f6 100644 --- a/osinaweb/osinacore/urls.py +++ b/osinaweb/osinacore/urls.py @@ -68,7 +68,7 @@ urlpatterns = [ path('fetch_epics/', views.fetch_epics, name='fetch_epics'), - + path('add_reaction///', views.add_reaction, name='add_reaction'), #CUSTOMER DASHBOARD path('customerdashboard/', views.customer_index, name='customerdashboard'), diff --git a/osinaweb/osinacore/views.py b/osinaweb/osinacore/views.py index cc031b27..98690d3c 100644 --- a/osinaweb/osinacore/views.py +++ b/osinaweb/osinacore/views.py @@ -456,6 +456,18 @@ def get_updated_last_status(request): # TO GET USER ACTIVITIES def get_latest_activities(request): + latest_connections = Connection.objects.filter( + user__staffprofile__isnull=False + ).values('user').annotate( + latest_connection=Max('date') + ) + online_staff_profiles = [] + for connection in latest_connections: + user_id = connection['user'] + latest_connection = connection['latest_connection'] + last_connection = Connection.objects.filter(user_id=user_id, date=latest_connection).first() + if last_connection.status == 'Online': + online_staff_profiles.append(last_connection.user.staffprofile) 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() @@ -482,7 +494,8 @@ def get_latest_activities(request): response_data = { 'total_tasks': total_tasks, - 'latest_statuses_time_ago': latest_statuses_time_ago, # Include latest_statuses_time_ago in the context + 'latest_statuses_time_ago': latest_statuses_time_ago, + 'online_staff_profiles' : online_staff_profiles, } recent_activities = render_to_string('recent-activities.html', response_data) @@ -520,3 +533,17 @@ def customer_invoices(request, *args, **kwargs): return render(request, 'customer_dashboard/listing_pages/customer-invoices.html', context) + +def add_reaction(request, status_id, emoji): + status = get_object_or_404(Status, pk=status_id) + user = request.user + existing_reaction = Reaction.objects.filter(status=status, user=user).first() + if existing_reaction: + # If the user has already reacted, update the reaction + existing_reaction.emoji = emoji + existing_reaction.save() + return JsonResponse({'message': 'Reaction updated successfully.'}) + else: + # If the user hasn't reacted yet, create a new reaction + new_reaction = Reaction.objects.create(status=status, emoji=emoji, user=user) + return JsonResponse({'message': 'Reaction added successfully.'}) diff --git a/osinaweb/static/js/emoji-picker.js b/osinaweb/static/js/emoji-picker.js index 2fd3cab5..9292019f 100644 --- a/osinaweb/static/js/emoji-picker.js +++ b/osinaweb/static/js/emoji-picker.js @@ -4,16 +4,18 @@ document.addEventListener('DOMContentLoaded', function () { const emojiPicker = document.getElementById('emojiPicker'); const closeEmojiPicker = document.getElementById('closeEmojiPicker'); const emojiPickerContainer = document.getElementById('emojiPickerContainer'); + let statusId; emojiPicker.addEventListener('click', function () { + statusId = emojiPicker.dataset.statusId; emojiPickerContainer.classList.remove('hidden'); + console.log(statusId); }); closeEmojiPicker.addEventListener('click', function () { emojiPickerContainer.classList.add('hidden'); }); - // To navigate between categories const categories = document.querySelectorAll('.emoji-category'); const categoryContainers = document.querySelectorAll('.emoji-category-container');