Skip to content

Commit

Permalink
feat: Pin Post Feature #6450
Browse files Browse the repository at this point in the history
  • Loading branch information
developerfred committed Apr 17, 2020
1 parent 9b7852d commit 5e5b37d
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 4 deletions.
18 changes: 17 additions & 1 deletion app/assets/v2/css/activity_stream.css
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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{
Expand Down
33 changes: 32 additions & 1 deletion app/assets/v2/js/activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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');
Expand Down
12 changes: 12 additions & 0 deletions app/retail/templates/shared/activity.html
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,15 @@


<div class="dropdown-menu dropdown-menu-right shadow font-smaller-4 px-0">
{% if row.profile.organizations|length %}
<a class="pin_activity mr-2 dropdown-item px-3 font-smaller-5" data-toggle="tooltip" title="Pinned post will display at the top of the Tribe Town Square." href=#
data-url={{row.url}}
data-affirmative=pinned
data-negative=unpin data-state="{% if row.metadata.pin%}pinned{% else %}unpin{%endif%}"
data-pk="{{row.pk}}">
<i class="fas fa-map-pin mr-2"></i>Pin Post
</a>
{% endif %}
<a class="copy_activity mr-2 dropdown-item px-3 font-smaller-5" data-toggle="tooltip" title="Copy a link to this feed item." href=# data-url={{row.url}}>
<i class="fas fa-link mr-2"></i> Copy Link
</a>
Expand Down Expand Up @@ -369,6 +378,9 @@
{{ row.created_human_time }}
{% endif %}
</div>
<div class="activity_pinned font-smaller-5 text-right">
<i class="fas fa-map-pin mr-2"></i> Pinned
</div>
<div class="mt-3 text-right pr-3 activity-img">
{% if row.kudos %}
<a href="{{row.kudos.external_url}}">
Expand Down
9 changes: 9 additions & 0 deletions app/townsquare/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
13 changes: 11 additions & 2 deletions app/townsquare/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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':
Expand Down

0 comments on commit 5e5b37d

Please sign in to comment.