From 5e5b37d36890d16a4f92bd32a71fec349501eb54 Mon Sep 17 00:00:00 2001 From: "@codingsh" Date: Thu, 16 Apr 2020 23:02:16 -0300 Subject: [PATCH] feat: Pin Post Feature #6450 --- app/assets/v2/css/activity_stream.css | 18 ++++++++++++- app/assets/v2/js/activity.js | 33 ++++++++++++++++++++++- app/retail/templates/shared/activity.html | 12 +++++++++ app/townsquare/models.py | 9 +++++++ app/townsquare/views.py | 13 +++++++-- 5 files changed, 81 insertions(+), 4 deletions(-) diff --git a/app/assets/v2/css/activity_stream.css b/app/assets/v2/css/activity_stream.css index 80fa298bd19..05cb32916df 100644 --- a/app/assets/v2/css/activity_stream.css +++ b/app/assets/v2/css/activity_stream.css @@ -161,7 +161,8 @@ a .sup { .like_activity:hover, .flag_activity:hover, .comment_activity:hover, -.copy_activity:hover { +.copy_activity:hover, +.pin_activity:hover { text-decoration: none; } .funder-avatar, @@ -299,6 +300,21 @@ iframe.popout{ border: 1px solid; margin-left: 25%; } +.activity_pinned { + display: none; +} +.pinned .activity_pinned { + display: block; +} + +.pinned-activity { + background-color: #e7fff5; + border: 1px solid #82febd; +} + +.activity_stream .box.pinned-activity { + border-bottom-color: #82febd; +} @media (min-width: 768px) { .activity_feed_kudos_image{ diff --git a/app/assets/v2/js/activity.js b/app/assets/v2/js/activity.js index 89c5be32d13..39cb7c59bf8 100644 --- a/app/assets/v2/js/activity.js +++ b/app/assets/v2/js/activity.js @@ -475,7 +475,7 @@ $(document).ready(function() { // like activity - $(document).on('click', '.like_activity, .flag_activity, .favorite_activity', function(e) { + $(document).on('click', '.like_activity, .flag_activity, .favorite_activity, .pin_activity', function(e) { e.preventDefault(); const current_tab = getURLParams('tab'); @@ -889,6 +889,37 @@ $(document).ready(function() { }, 300); }); + // pinned activity tribes + $(document).on('click', '.pin_activity', function(e) { + e.preventDefault(); + + state = $(this).data('state') + + if (state == 'unpin') { + $('.pinned-activity').addClass('bg-white'); + $('.pinned-activity .tip_activity').css({'background-color': 'white'}); + $('.pinned-activity').css({'border-bottom-color':'#EFEFEF;'}) + $('.pinned-activity .activity_pinned').hide(); + $('.box').removeClass('pinned-activity'); + _alert('Sucess unpin.', 'success', 1000); + } + + if (state == 'pinned') { + + $(this).closest('.box').addClass('pinned-activity'); + + + if ($('.pinned-activity')) { + $('.pinned-activity .tip_activity').css({'background-color': '#e7fff5'}); + $('.pinned-activity').removeClass('bg-white'); + $('.pinned-activity .activity_pinned').show(); + } + _alert('Status pinned.', 'success', 1000); + } + + + }); + $(document).on('click', '.fund_issue', function(e) { e.preventDefault(); const url = $(this).data('url'); diff --git a/app/retail/templates/shared/activity.html b/app/retail/templates/shared/activity.html index 3a4bf504a95..5c59076e6a3 100644 --- a/app/retail/templates/shared/activity.html +++ b/app/retail/templates/shared/activity.html @@ -295,6 +295,15 @@ +
+ Pinned +
{% if row.kudos %} diff --git a/app/townsquare/models.py b/app/townsquare/models.py index 884700df770..f15a33b17e3 100644 --- a/app/townsquare/models.py +++ b/app/townsquare/models.py @@ -381,6 +381,15 @@ class Favorite(SuperModel): def __str__(self): return f"Favorite {self.activity.activity_type}:{self.activity_id} by {self.user}" +class Pin(SuperModel): + """Model for each Pinned.""" + user = models.ForeignKey(get_user_model(), on_delete=models.CASCADE, related_name='pins') + activity = models.ForeignKey('dashboard.Activity', on_delete=models.CASCADE) + created = models.DateTimeField(auto_now=True) + + def __str__(self): + return f"Pin {self.activity.activity_type}:{self.activity_id} by {self.user}" + class SquelchProfile(SuperModel): """Squelches a profile from earning in CLR""" diff --git a/app/townsquare/views.py b/app/townsquare/views.py index 64e05bd6d7f..8817a0d119c 100644 --- a/app/townsquare/views.py +++ b/app/townsquare/views.py @@ -20,7 +20,7 @@ from retail.views import get_specific_activities from .models import ( - Announcement, Comment, Favorite, Flag, Like, MatchRanking, MatchRound, Offer, OfferAction, SuggestedAction, + Announcement, Comment, Favorite, Flag, Like, MatchRanking, MatchRound, Offer, OfferAction, Pin, SuggestedAction, ) from .tasks import increment_offer_view_counts from .utils import is_user_townsquare_enabled @@ -519,7 +519,7 @@ def api(request, activity_id): if request.POST['direction'] == 'unliked': activity.likes.filter(profile=request.user.profile).delete() - # like request + # favorite request elif request.POST.get('method') == 'favorite': if request.POST['direction'] == 'favorite': already_likes = Favorite.objects.filter(activity=activity, user=request.user).exists() @@ -528,6 +528,15 @@ def api(request, activity_id): elif request.POST['direction'] == 'unfavorite': Favorite.objects.filter(user=request.user, activity=activity).delete() + # Pin request + elif request.POST.get('method') == 'pin': + if request.POST['direction'] == 'pin': + already_pins = Pin.objects.filter(activity=activity, user=request.user).exists() + if not already_pins: + Pin.objects.create(user=request.user, activity=activity) + elif request.POST['direction'] == 'unpin': + Pin.objects.filter(user=request.user, activity=activity).delete() + # flag request elif request.POST.get('method') == 'flag': if request.POST['direction'] == 'flagged':