Skip to content

Commit

Permalink
feat: Pin Post Feature #6450
Browse files Browse the repository at this point in the history
- add activity hash
  • Loading branch information
developerfred committed Apr 28, 2020
1 parent 0a5ed29 commit 4b55c43
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 5 deletions.
21 changes: 20 additions & 1 deletion app/assets/v2/css/activity_stream.css
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,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 @@ -350,6 +351,24 @@ iframe.popout{
margin: 0px auto;
}
}

.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 (max-width: 1100px) {
.activity_stream .avatar {
width: 3.5rem;
Expand Down
31 changes: 30 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 @@ -1045,6 +1045,35 @@ $(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);
} else 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
14 changes: 14 additions & 0 deletions app/retail/templates/shared/activity.html
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,17 @@


<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}}"
data-what="tribe">

<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 @@ -371,6 +382,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
7 changes: 6 additions & 1 deletion app/townsquare/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.utils.html import format_html

from .models import (
Announcement, Comment, Flag, Like, MatchRanking, MatchRound, Offer, OfferAction, SquelchProfile, SuggestedAction,
Announcement, Comment, Flag, Like, Pin, MatchRanking, MatchRound, Offer, OfferAction, SquelchProfile, SuggestedAction,
)


Expand All @@ -30,6 +30,10 @@ class MatchRankingAdmin(admin.ModelAdmin):
list_display = ['created_on', '__str__']
raw_id_fields = ['profile', 'round']

class PinAdmin(admin.ModelAdmin):
list_display = ['created_on', '__str__']
raw_id_fields = ['user', 'activity']
fields = ['hash_what']

class OfferActionAdmin(admin.ModelAdmin):
list_display = ['created_on', 'github_created_on', 'from_ip_address', '__str__']
Expand Down Expand Up @@ -152,6 +156,7 @@ class AnnounceAdmin(admin.ModelAdmin):
admin.site.register(Comment, GenericAdmin)
admin.site.register(Like, GenericAdmin)
admin.site.register(Flag, GenericAdmin)
admin.site.register(Pin, PinAdmin)
admin.site.register(MatchRound, ActuallyGenericAdmin)
admin.site.register(MatchRanking, MatchRankingAdmin)
admin.site.register(Announcement, AnnounceAdmin)
32 changes: 32 additions & 0 deletions app/townsquare/migrations/0019_pin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Generated by Django 2.2.4 on 2020-04-22 22:11

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import economy.models


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('dashboard', '0101_auto_20200420_1427'),
('townsquare', '0018_comment_is_edited'),
]

operations = [
migrations.CreateModel(
name='Pin',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_on', models.DateTimeField(db_index=True, default=economy.models.get_time)),
('modified_on', models.DateTimeField(default=economy.models.get_time)),
('created', models.DateTimeField(auto_now=True)),
('activity', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='dashboard.Activity')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='pins', to=settings.AUTH_USER_MODEL)),
],
options={
'abstract': False,
},
),
]
23 changes: 23 additions & 0 deletions app/townsquare/migrations/0020_auto_20200427_1901.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 2.2.4 on 2020-04-27 19:01

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('townsquare', '0019_pin'),
]

operations = [
migrations.RemoveField(
model_name='pin',
name='user',
),
migrations.AlterField(
model_name='pin',
name='activity',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='pins', to='dashboard.Activity'),
),
]
23 changes: 23 additions & 0 deletions app/townsquare/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,29 @@ 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, related_name='pins')
hash_what = models.CharField(max_length=32,
default='', unique=True)
created = models.DateTimeField(auto_now=True)


def __str__(self):
return f"Pin {self.activity.activity_type}:{self.activity_id} by {self.user}"

@property
def url(self):
return self.activity.url

def get_absolute_url(self):
return self.activity.url


class SquelchProfile(SuperModel):
"""Squelches a profile from earning in CLR"""

Expand Down
22 changes: 20 additions & 2 deletions app/townsquare/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import re
import time
import hashlib

from django.conf import settings
from django.contrib import messages
Expand All @@ -20,7 +21,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, Pin, MatchRanking, MatchRound, Offer, OfferAction, SuggestedAction,
)
from .tasks import increment_offer_view_counts
from .utils import is_user_townsquare_enabled
Expand Down Expand Up @@ -521,7 +522,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 @@ -530,6 +531,23 @@ 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':
hash = hashlib.sha256()
hash.update(str(time.time()))
hash_what = hash.hexdigest()

if request.POST['direction'] == 'pin':
already_pins = Pin.objects.filter(activity=activity, user=request.user, hash_what=hash_what).exists()
if not already_pins:
Pin.objects.create(activity=activity, user=request.user, hash_what=hash_what)
else:
Pin.objects.filter(activity=activity, user=request.user, hash_what=hash_what).delete()
Pin.objects.create(activity=activity, user=request.user, hash_what=hash_what)

elif request.POST['direction'] == 'unpin':
Pin.objects.filter(activity=activity, user=request.user, hash_what=hash_what).delete()

# flag request
elif request.POST.get('method') == 'flag':
if request.POST['direction'] == 'flagged':
Expand Down

0 comments on commit 4b55c43

Please sign in to comment.