Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Needs Review - Pinned Post - Site Wide Feature #6680

Merged
merged 17 commits into from
May 20, 2020
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions app/assets/v2/css/activity_stream.css
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,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 @@ -363,7 +364,6 @@ iframe.popout{
bottom: 10px;
text-align: center;
width: 50%;
background-color: white;
border: 1px solid;
margin-left: 25%;
}
Expand Down Expand Up @@ -401,6 +401,22 @@ iframe.popout{
margin: 0px auto;
}
}

.activity_pinned {
display: none;
}
.pinned .activity_pinned {
display: block;
}


.pinned-activity {
-webkit-box-shadow: 0px 0px 8px 0px var(--pinned-activity);
-moz-box-shadow: 0px 0px 8px 0px var(--pinned-activity);
box-shadow: 0px 0px 8px 0px var(--pinned-activity);
}


@media (max-width: 1100px) {
.activity_stream .avatar {
width: 3.5rem;
Expand Down
4 changes: 3 additions & 1 deletion app/assets/v2/css/colors.css
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ html {
--townsquare-block-header-color: #626365;
--active-button-border-color: var(--link-color);
--default-text-color: var(--text-dark);
--pinned-activity: var(--gc-green);
}

/* @media screen and (prefers-color-scheme: dark) { */
Expand Down Expand Up @@ -88,6 +89,7 @@ html.dark-mode {
--townsquare-block-header-color: white;
--active-button-border-color: white;
--default-text-color: white;
--pinned-activity: white;
}

.text-highlight-purple {
Expand Down Expand Up @@ -128,4 +130,4 @@ html.dark-mode {

.text-black {
color: #000;
}
}
70 changes: 57 additions & 13 deletions app/assets/v2/js/activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ $(document).ready(function() {
}
if ($('.infinite-more-link').length) {
if (!max_pk) {
max_pk = $('#activities .box').first().data('pk');
max_pk = $('#activities div.box[data-pk]').first().data('pk');

if (!max_pk) {
return;
}
Expand Down Expand Up @@ -280,7 +281,13 @@ $(document).ready(function() {
for (var i = document.buffered_rows.length; i > 0; i -= 1) {
var html = document.buffered_rows[i - 1];

$('.infinite-container').prepend($(html));
let pin = $('.pinned-activity');

if (pin.length > 0) {
$(html).insertAfter($(pin));
} else {
$('.infinite-container').prepend($(html));
}
}
$(this).remove();
document.buffered_rows = [];
Expand Down Expand Up @@ -475,7 +482,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 All @@ -484,14 +491,31 @@ $(document).ready(function() {
return;
}

let method = $(this).data('action');
let state = $(this).data('state');
// remote post
var params = {
'method': method,
'direction': state,
'csrfmiddlewaretoken': $('input[name=csrfmiddlewaretoken]').val()
};


var is_unliked = $(this).data('state') == $(this).data('negative');
var num = $(this).find('span.num').html();

if (is_unliked) { // like
if (method === 'pin') {
let message = state === 'pin' ? 'This action will pin the selected post, only one Pin may be active at a time' : 'This action will un-pin this post, are you sure?';

if (confirm(message)) {
params['what'] = $('.infinite-container').data('what');
} else {
return false;
}
} else if (is_unliked) { // like
$(this).find('span.action').addClass('open');
$(this).data('state', $(this).data('affirmative'));
$(this).addClass('animate-sparkle');

num = parseInt(num) + 1;
$(this).find('span.num').html(num);
$(this).find('i').removeClass('far').addClass('fas');
Expand All @@ -504,14 +528,7 @@ $(document).ready(function() {
$(this).find('i').removeClass('fas').addClass('far');
}

// remote post
var params = {
'method': $(this).data('action'),
'direction': $(this).data('state'),
'csrfmiddlewaretoken': $('input[name=csrfmiddlewaretoken]').val()
};
var url = '/api/v0.1/activity/' + $(this).data('pk');

var parent = $(this).parents('.activity.box');
var self = $(this);

Expand All @@ -523,6 +540,32 @@ $(document).ready(function() {
if (!is_unliked && current_tab === 'my_favorites') {
self.parentsUntil('.activity_stream').remove();
}

if (method === 'pin') {
if (state === 'unpin') {
$('.box').removeClass('pinned-activity');
self.data('state', 'pin');
self.find('.pin-title').html('Pin Post');
parent.remove();
_alert('Sucess unpin.', 'success', 1000);
} else {
let curr_pinn = $('.pinned-activity');

parent.addClass('pinned-activity');

self.data('state', 'unpin');
self.find('.pin-title').html('Unpin Post');
if (curr_pinn.length > 0) {
$(curr_pinn).replaceWith(parent);
} else {
$('.activity_stream').prepend($('<div id="temp-pin"></div>'));
$('#temp-pin').replaceWith(parent);
window.scrollTo(0, 0);
}
_alert('Status pinned.', 'success', 1000);
}
}

}).fail(function() {
parent.find('.error').removeClass('hidden');
});
Expand Down Expand Up @@ -979,7 +1022,7 @@ $(document).ready(function() {
if (response.status <= 204) {
_alert('comment successfully deleted.', 'success', 1000);
$(`.comment_row[data-id='${comment_id}']`).addClass('hidden');
console.log(response);

} else {
_alert(`Unable to delete commment: ${response.message}`, 'error');
console.log(`error deleting commment: ${response.message}`);
Expand Down Expand Up @@ -1045,6 +1088,7 @@ $(document).ready(function() {
}, 300);
});


$(document).on('click', '.fund_issue', function(e) {
e.preventDefault();
const url = $(this).data('url');
Expand Down
24 changes: 20 additions & 4 deletions app/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
from rest_framework.renderers import JSONRenderer
from retail.helpers import get_ip
from retail.utils import programming_languages, programming_languages_full
from townsquare.models import Comment
from townsquare.models import Comment, PinnedPost
from townsquare.views import get_following_tribes, get_tags
from web3 import HTTPProvider, Web3

Expand Down Expand Up @@ -2845,13 +2845,21 @@ def profile(request, handle, tab=None):
if request.user.is_authenticated and not context['is_my_org']:
ProfileView.objects.create(target=profile, viewer=request.user.profile)
try:

what = f'tribe:{profile.handle}'
network = get_default_network()
orgs_bounties = profile.get_orgs_bounties(network=network)
context['count_bounties_on_repo'] = orgs_bounties.count()
context['sum_eth_on_repos'] = profile.get_eth_sum(bounties=orgs_bounties)
context['works_with_org'] = profile.get_who_works_with(work_type='org', bounties=orgs_bounties)
context['currentProfile'] = TribesSerializer(profile, context={'request': request}).data
context['target'] = f'/activity?what=tribe:{profile.handle}'
what = f'tribe:{profile.handle}'
try:
context['pinned'] = PinnedPost.objects.get(what=what)
except PinnedPost.DoesNotExist:
context['pinned'] = None
context['target'] = f'/activity?what={what}'
context['what'] = what
context['is_on_tribe'] = json.dumps(context['is_on_tribe'])
context['is_my_org'] = json.dumps(context['is_my_org'])
context['profile_handle'] = profile.handle
Expand Down Expand Up @@ -3595,13 +3603,21 @@ def hackathon(request, hackathon='', panel='prizes'):
active_tab = 4



what = f'hackathon:{hackathon_event.id}'
from townsquare.utils import can_pin
try:
pinned = PinnedPost.objects.get(what=what)
except PinnedPost.DoesNotExist:
pinned = None
params = {
'active': 'dashboard',
'prize_count': hackathon_event.get_current_bounties.count(),
'type': 'hackathon',
'title': title,
'target': f'/activity?what=hackathon:{hackathon_event.id}',
'what': what,
'can_pin': can_pin(request, what),
'pinned': pinned,
'target': f'/activity?what={what}',
'orgs': orgs,
'keywords': json.dumps([str(key) for key in Keyword.objects.all().values_list('keyword', flat=True)]),
'hackathon': hackathon_event,
Expand Down
4 changes: 2 additions & 2 deletions app/grants/templates/grants/detail/tabs.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
{% include 'profiles/status_box.html' with suppress_tags=1 placeholder="Write on grants wall" what="grant" whatid=grant.pk suppress_data_toggle=1 %}
{% endif %}
<div id="activities" class="activity_stream container px-0">
{% include 'shared/activity_container.html' %}
{% include 'shared/activity_container.html' with pinned=False %}
</div>

</div>
Expand All @@ -72,7 +72,7 @@ <h4 class="m-0 p-0">Activity Feed</h4>
{% include 'profiles/status_box.html' with suppress_tags=1 placeholder="Write on grants wall" what="grant" whatid=grant.pk suppress_data_toggle=1 %}
{% endif %}
<div id="activities" class="activity_stream container px-0">
{% include 'shared/activity_container.html' %}
{% include 'shared/activity_container.html' with pinned=False %}
</div>
{% endif %}

Expand Down
4 changes: 2 additions & 2 deletions app/grants/templates/grants/shared/landing_activity.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<div class="container-fluid grants-container">
<div class="container">
<div id="activities" class="activity_stream container px-0">
{% include 'shared/activity_container.html' %}
{% include 'shared/activity_container.html' with pinned=False %}
</div>
</div>
</div>
</div>
21 changes: 19 additions & 2 deletions app/grants/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
from marketing.models import Keyword, Stat
from ratelimit.decorators import ratelimit
from retail.helpers import get_ip
from townsquare.models import Comment
from townsquare.models import Comment, PinnedPost
from townsquare.utils import can_pin
from web3 import HTTPProvider, Web3

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -350,6 +351,11 @@ def grants(request):
title = f"Round {clr_round} Stats"
cht = []
chart_list = ''
try:
what = 'all_grants'
pinned = PinnedPost.objects.get(what=what)
except PinnedPost.DoesNotExist:
pinned = None
params = {
'active': 'grants_landing',
'title': title,
Expand Down Expand Up @@ -378,6 +384,9 @@ def grants(request):
'avatar_height': 1097,
'avatar_width': 1953,
'grants': grants,
'what': what,
'can_pin': can_pin(request, what),
'pinned': pinned,
'target': f'/activity?what=all_grants',
'bg': bg,
'keywords': get_keywords(),
Expand Down Expand Up @@ -510,6 +519,11 @@ def grant_details(request, grant_id, grant_slug):
)
is_unsubscribed_from_updates_from_this_grant = True

try:
what = f'grant:{grant.pk}'
pinned = PinnedPost.objects.get(what=what)
except PinnedPost.DoesNotExist:
pinned = None
params = {
'active': 'grant_details',
'clr_matching_banners_style': clr_matching_banners_style,
Expand All @@ -527,7 +541,10 @@ def grant_details(request, grant_id, grant_slug):
'is_admin': is_admin,
'grant_is_inactive': not grant.active,
'keywords': get_keywords(),
'target': f'/activity?what=grant:{grant.pk}',
'target': f'/activity?what={what}',
'pinned': pinned,
'what': what,
'can_pin': can_pin(request, what),
'activity_count': activity_count,
'contributors': contributors,
'clr_active': clr_active,
Expand Down
7 changes: 7 additions & 0 deletions app/kudos/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
from marketing.mails import new_kudos_request
from ratelimit.decorators import ratelimit
from retail.helpers import get_ip
from townsquare.models import PinnedPost
from web3 import Web3

from .forms import KudosSearchForm
Expand Down Expand Up @@ -196,6 +197,11 @@ def details(request, kudos_id, name):
if kudos.hidden_token_details_page:
raise Http404

what = f'kudos:{kudos.pk}'
try:
pinned = PinnedPost.objects.get(what=what)
except PinnedPost.DoesNotExist:
pinned = None
context = {
'send_enabled': kudos.send_enabled_for(request.user),
'is_outside': True,
Expand All @@ -206,6 +212,7 @@ def details(request, kudos_id, name):
'card_desc': _('It can be sent to highlight, recognize, and show appreciation.'),
'avatar_url': request.build_absolute_uri(static('v2/images/kudos/assets/kudos-image.png')),
'kudos': kudos,
'pinned': pinned,
'related_handles': list(set(kudos.owners_handles))[:num_kudos_limit],
'target': f'/activity?what=kudos:{kudos.pk}',
}
Expand Down
Loading