* Add ProMembership model * Implement ProMembershipsController#create * Implement basic ProMembershipsController#show * Add ProMembership to ledger * Populate user history after pro subscription is created * Add fields for expiration notifications * Add ProMemberships::ExpirationNotifier to notify users of expiring memberships * Add tasks for recurring jobs to notify users of expiration * Add auto_recharge column to ProMembership * Add ProMemberships::Biller (incomplete) * Fix specs * Add ProMembership to Administrate * Fix spec * Add has_enough_credits? to User and Organization * Add Payments::Customer class * Finish ProMembership::Biller functionality * Fix ProMemberships::Creator check for credits * Disable destroy actions for ProMembershipsController * Correctly authenticate ProMembershipsController actions * Make sure only pro user's history can be indexed * Add ProMembershipsController#update action for auto recharge * Use regular AR to save new credits and add touch to the purchaser * Clarify Pro membership create policy * Display information about an existing pro membership * Add UI to show page * Add system test for Pro membership creation * Implement edit membership * Make sure users with pro memberships can access history and dashboard pro * Fix padding issue * Show a different text for a user that has credits but not enough for Pro * Move Pro Membership functionality inside settings * Update Pro Membership link in email notifications * Bust all relevant caches * Add the Pro checkmark around the website * Use Users::ResaveArticlesJob instead of delay * Add/remove user from pro-members chat channel * Use the appropriate Pro checkmark * Remove unfinished pro elements * Remove checkmark JS
135 lines
7 KiB
Text
135 lines
7 KiB
Text
function buildArticleHTML(article) {
|
|
if (article && article.type_of == "podcast_episodes") {
|
|
return '<div class="single-article single-article-small-pic single-article-single-podcast">\
|
|
<div class="small-pic">\
|
|
<a href="/'+article.podcast.slug+'" class="small-pic-link-wrapper">\
|
|
<img src="'+article.podcast.image_url+'" alt="'+article.podcast.title+' image">\
|
|
</a>\
|
|
</div>\
|
|
<a href="'+article.path+'" class="small-pic-link-wrapper index-article-link" id="article-link-'+article.id+'">\
|
|
<div class="content">\
|
|
<h3><span class="tag-identifier">podcast</span>'+article.title+'</h3>\
|
|
</div>\
|
|
</a>\
|
|
<h4><a href="/'+article.podcast.slug+'">'+article.podcast.title+'</a></h4>\
|
|
</div>';
|
|
}
|
|
else if (article) {
|
|
var container = document.getElementById("index-container");
|
|
var tagString = ""
|
|
var tagList = article.tag_list || article.cached_tag_list_array
|
|
if(tagList) {
|
|
tagList.forEach(function(t){
|
|
tagString = tagString + '<a href="/t/'+t+'"><span class="tag">#'+t+'</span></a>\n'
|
|
});
|
|
}
|
|
var commentsCountHTML = ""
|
|
if ((article.comments_count || '0') > 0 && article.class_name != "User") {
|
|
commentsCountHTML = '<div class="article-engagement-count comments-count"><a href="'+article.path+'#comments"><img src="<%= asset_path("comments-bubble.png") %>" alt="chat" /><span class="engagement-count-number">'+(article.comments_count || '0')+'</span></a></div>'
|
|
}
|
|
var flareTag = ""
|
|
if (container){
|
|
var currentTag = JSON.parse(container.dataset.params).tag
|
|
}
|
|
if (article.flare_tag && currentTag != article.flare_tag.name) {
|
|
flareTag = "<span class='tag-identifier' style='background:"+article.flare_tag.bg_color_hex+";color:"+article.flare_tag.text_color_hex+"'>#"+article.flare_tag.name+"</span>"
|
|
}
|
|
if (article.class_name == "PodcastEpisode"){
|
|
flareTag = "<span class='tag-identifier'>podcast</span>"
|
|
}
|
|
if (article.class_name == "User"){
|
|
flareTag = "<span class='tag-identifier' style='background:#5874d9;color:white;'>person</span>"
|
|
}
|
|
var rc = article.positive_reactions_count || article.reactions_count
|
|
var reactionsCountHTML = ''
|
|
if ((rc || '0') > 0 && article.class_name != "User") {
|
|
var reactionsCountHTML = '<div class="article-engagement-count reactions-count"><a href="'+article.path+'"><img src="<%= asset_path("reactions-stack.png") %>" alt="heart" /><span id="engagement-count-number-'+article.id+'" class="engagement-count-number">'+(rc || '0')+'</span></a></div>'
|
|
}
|
|
var picUrl = article.user.profile_image_90
|
|
var profileUsername = article.user.username
|
|
var orgHeadline = "";
|
|
if (article.organization && !document.getElementById("organization-article-index")) {
|
|
orgHeadline = '<div class="article-organization-headline"><a class="org-headline-filler" href="/'+article.organization.slug+'"><span class="article-organization-headline-inner"><img alt="'+article.organization.name+' logo" src="'+article.organization.profile_image_90+'" loading="lazy">'+article.organization.name+'</span></a></div>'
|
|
}
|
|
var bodyTextSnippet = "";
|
|
var commentsBlobSnippet = "";
|
|
var searchSnippetHTML = "";
|
|
if (article._snippetResult && article._snippetResult.body_text){
|
|
if (article._snippetResult.body_text.matchLevel != "none"){
|
|
var firstSnippetChar = article._snippetResult.body_text.value[0];
|
|
var startingEllipsis = ""
|
|
if (firstSnippetChar.toLowerCase() != firstSnippetChar.toUpperCase()){
|
|
startingEllipsis = "…"
|
|
}
|
|
bodyTextSnippet = startingEllipsis+article._snippetResult.body_text.value + "…"
|
|
}
|
|
if (article._snippetResult.comments_blob.matchLevel != "none" && bodyTextSnippet === ""){
|
|
var firstSnippetChar = article._snippetResult.comments_blob.value[0];
|
|
var startingEllipsis = ""
|
|
if (firstSnippetChar.toLowerCase() != firstSnippetChar.toUpperCase()){
|
|
startingEllipsis = "…"
|
|
}
|
|
commentsBlobSnippet = startingEllipsis+article._snippetResult.comments_blob.value + "… <i>(comments)</i>"
|
|
}
|
|
if ((bodyTextSnippet.length > 0 || commentsBlobSnippet.length > 0) && article.class_name == "Article"){
|
|
searchSnippetHTML = '<div class="search-snippet"><span>'+bodyTextSnippet+commentsBlobSnippet+'</span></div>'
|
|
}
|
|
}
|
|
var saveButton = '';
|
|
if (article.class_name === "Article") {
|
|
saveButton = '<button class="article-engagement-count bookmark-engage" data-reactable-id="'+article.id+'">\
|
|
<span class="bm-initial">SAVE</span>\
|
|
<span class="bm-success">SAVED</span>\
|
|
</button>'
|
|
} else if (article.class_name === "User") {
|
|
saveButton = '<button style="width: 122px" class="article-engagement-count bookmark-engage follow-action-button"\
|
|
data-info=\'{"id":'+article.id+',"className":"User"}\' data-follow-action-button>\
|
|
\
|
|
</button>'
|
|
}
|
|
|
|
var publishDate = '';
|
|
if (article.readable_publish_date) {
|
|
if (article.published_timestamp) {
|
|
publishDate = '・' + '<time datetime="'+article.published_timestamp+'">'+article.readable_publish_date+'</time>';
|
|
} else {
|
|
publishDate = '・' + '<time>'+article.readable_publish_date+'</time>';
|
|
}
|
|
}
|
|
|
|
var readingTimeHTML = '';
|
|
if (article.class_name === "Article") {
|
|
// we have ` ... || null` for the case article.reading_time is undefined
|
|
readingTimeHTML = '<a href="'+article.path+'" class="article-reading-time">'+ ((article.reading_time || null) < 1 ? '1 min' : article.reading_time + ' min') +' read</a>'
|
|
}
|
|
|
|
var videoHTML = '';
|
|
if (article.cloudinary_video_url) {
|
|
videoHTML = '<a href="'+article.path+'" class="single-article-video-preview" style="background-image:url('+article.cloudinary_video_url+')"><div class="single-article-video-duration"><img src="<%= asset_path("video-camera.svg") %>" alt="video camera">'+article.video_duration_in_minutes+'</div></a>'
|
|
}
|
|
|
|
var timeAgoInWords = '';
|
|
if (article.published_at_int) {
|
|
timeAgoInWords = timeAgo(article.published_at_int);
|
|
}
|
|
|
|
return '<div class="single-article single-article-small-pic">\
|
|
'+videoHTML+'\
|
|
'+orgHeadline+'\
|
|
<div class="small-pic">\
|
|
<a href="/'+profileUsername+'" class="small-pic-link-wrapper">\
|
|
<img src="'+picUrl+'" alt="'+profileUsername+' profile" loading="lazy">\
|
|
</a>\
|
|
</div>\
|
|
<a href="'+article.path+'" class="small-pic-link-wrapper index-article-link" id="article-link-'+article.id+'">\
|
|
<div class="content">\
|
|
<h3>'+flareTag+filterXSS(article.title)+'</h3>\
|
|
'+searchSnippetHTML+'\
|
|
</div>\
|
|
</a>\
|
|
<h4><a href="/'+article.user.username+'">'+filterXSS(article.user.name)+publishDate+timeAgoInWords+'</a></h4>\
|
|
<div class="tags">'+tagString+'</div>\
|
|
'+commentsCountHTML+reactionsCountHTML+readingTimeHTML+'\
|
|
'+saveButton+'</div>';
|
|
}
|
|
}
|