-
Notifications
You must be signed in to change notification settings - Fork 3
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
short description in posts list #15
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -5,7 +5,7 @@ angular | |||||
bindings: { | ||||||
post: '=', | ||||||
}, | ||||||
controller: function ($sce, PostRepository, PostFactory, $q, $routeParams) { | ||||||
controller: function ($sce, PostRepository, $q, $routeParams) { | ||||||
this.commentsLoaded = false; | ||||||
this.showSpinner = true; | ||||||
this.loadComments = () => { | ||||||
|
@@ -15,6 +15,10 @@ angular | |||||
this.dislikesCount = 0; | ||||||
|
||||||
this.$onInit = () => { | ||||||
setTimeout(()=> { | ||||||
console.log(); | ||||||
}, 0) | ||||||
|
||||||
$q | ||||||
.resolve(PostRepository.getReactionCounters(this.post.id)) | ||||||
.then(result => { | ||||||
|
@@ -26,7 +30,7 @@ angular | |||||
const delimiter = '<hr>' | ||||||
|
||||||
if ($routeParams && !$routeParams.id && this.post.body.includes(delimiter)) { | ||||||
description = PostFactory.getShortDescription(this.post, delimiter) | ||||||
description = Post().getShortDescription(this.post) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
|
||||||
this.post.body = $sce.trustAsHtml(description); | ||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -7,7 +7,7 @@ angular | |||||||||||||||||||||
resolve: { | ||||||||||||||||||||||
post: function (PostRepository, $route) { | ||||||||||||||||||||||
post = PostRepository.getById($route.current.params.id); | ||||||||||||||||||||||
return post | ||||||||||||||||||||||
return post; | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please revert any not related changes |
||||||||||||||||||||||
}, | ||||||||||||||||||||||
} | ||||||||||||||||||||||
}) | ||||||||||||||||||||||
|
@@ -19,31 +19,26 @@ angular | |||||||||||||||||||||
let tags = issue.labels.map((label) => label.name); | ||||||||||||||||||||||
|
||||||||||||||||||||||
if (!tags.includesArray(POST_REQUIRED_TAGS)) { | ||||||||||||||||||||||
throw new Error("You can't see unpublished posts.") | ||||||||||||||||||||||
throw new Error('You can\'t see unpublished posts.'); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
tags = tags.filter(n => !POST_REQUIRED_TAGS.includes(n)) | ||||||||||||||||||||||
tags = tags.filter(n => !POST_REQUIRED_TAGS.includes(n)); | ||||||||||||||||||||||
|
||||||||||||||||||||||
return new Post(issue.number, issue.title, issue.body_html, author, tags, issue.comments, issue.created_at); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
function createFromIssueList(issueList) { | ||||||||||||||||||||||
return issueList.map(issue => createFromIssue(issue)) | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
function getShortDescription(post, delimiter) { | ||||||||||||||||||||||
return post.body.substring(0, post.body.indexOf(delimiter)); | ||||||||||||||||||||||
return issueList.map(issue => createFromIssue(issue)); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
return { | ||||||||||||||||||||||
createFromIssue: createFromIssue, | ||||||||||||||||||||||
createFromIssueList: createFromIssueList, | ||||||||||||||||||||||
getShortDescription: getShortDescription, | ||||||||||||||||||||||
} | ||||||||||||||||||||||
}; | ||||||||||||||||||||||
}) | ||||||||||||||||||||||
.factory('PostRepository', function ($http, $log, PostFactory, PromiseCacheService, $q, BASE_API_URL, POST_REQUIRED_TAGS) { | ||||||||||||||||||||||
return { | ||||||||||||||||||||||
getReactionCounters: async (id) => { | ||||||||||||||||||||||
id = Number(id) | ||||||||||||||||||||||
id = Number(id); | ||||||||||||||||||||||
const cacheKey = 'reactions-id-' + id; | ||||||||||||||||||||||
return PromiseCacheService.getOrSet( | ||||||||||||||||||||||
cacheKey, | ||||||||||||||||||||||
|
@@ -55,7 +50,7 @@ angular | |||||||||||||||||||||
cache: true, | ||||||||||||||||||||||
}) | ||||||||||||||||||||||
.then(response => { | ||||||||||||||||||||||
$log.debug('response', response.config.url, response.data) | ||||||||||||||||||||||
$log.debug('response', response.config.url, response.data); | ||||||||||||||||||||||
let reactionCounters = { | ||||||||||||||||||||||
'+1': 0, | ||||||||||||||||||||||
'-1': 0, | ||||||||||||||||||||||
|
@@ -65,21 +60,21 @@ angular | |||||||||||||||||||||
'hooray': 0, | ||||||||||||||||||||||
'rocket': 0, | ||||||||||||||||||||||
'eyes': 0, | ||||||||||||||||||||||
} | ||||||||||||||||||||||
}; | ||||||||||||||||||||||
response.data.map(data => { | ||||||||||||||||||||||
const emoji = data.content; | ||||||||||||||||||||||
if (reactionCounters.hasOwnProperty(emoji)) { | ||||||||||||||||||||||
reactionCounters[emoji]++ | ||||||||||||||||||||||
reactionCounters[emoji]++; | ||||||||||||||||||||||
} | ||||||||||||||||||||||
}) | ||||||||||||||||||||||
}); | ||||||||||||||||||||||
|
||||||||||||||||||||||
const arguments = Object.entries(reactionCounters).map(property => property[1]); | ||||||||||||||||||||||
return ReactionCounters.apply(null, arguments) | ||||||||||||||||||||||
return ReactionCounters.apply(null, arguments); | ||||||||||||||||||||||
}) | ||||||||||||||||||||||
) | ||||||||||||||||||||||
); | ||||||||||||||||||||||
}, | ||||||||||||||||||||||
getById: async (id) => { | ||||||||||||||||||||||
id = Number(id) | ||||||||||||||||||||||
id = Number(id); | ||||||||||||||||||||||
const cacheKey = 'post-id-' + id; | ||||||||||||||||||||||
return PromiseCacheService.getOrSet( | ||||||||||||||||||||||
cacheKey, | ||||||||||||||||||||||
|
@@ -91,31 +86,31 @@ angular | |||||||||||||||||||||
cache: true, | ||||||||||||||||||||||
}) | ||||||||||||||||||||||
.then(response => { | ||||||||||||||||||||||
$log.debug('response', response.config.url, response.data) | ||||||||||||||||||||||
$log.debug('response', response.config.url, response.data); | ||||||||||||||||||||||
const post = PostFactory.createFromIssue(response.data); | ||||||||||||||||||||||
$log.debug('post', post) | ||||||||||||||||||||||
return post | ||||||||||||||||||||||
$log.debug('post', post); | ||||||||||||||||||||||
return post; | ||||||||||||||||||||||
}), | ||||||||||||||||||||||
'5hours' | ||||||||||||||||||||||
) | ||||||||||||||||||||||
); | ||||||||||||||||||||||
}, | ||||||||||||||||||||||
getByFilter: async (filter) => { | ||||||||||||||||||||||
let url = `${BASE_API_URL}/issues`; | ||||||||||||||||||||||
url += '?sort=created' | ||||||||||||||||||||||
url += '?sort=created'; | ||||||||||||||||||||||
if (filter.state) { | ||||||||||||||||||||||
url += '&state=' + filter.state | ||||||||||||||||||||||
url += '&state=' + filter.state; | ||||||||||||||||||||||
} | ||||||||||||||||||||||
if (filter.limit) { | ||||||||||||||||||||||
url += '&per_page=' + filter.limit | ||||||||||||||||||||||
url += '&per_page=' + filter.limit; | ||||||||||||||||||||||
} | ||||||||||||||||||||||
if (filter.offset) { | ||||||||||||||||||||||
url += '&page=' + filter.offset | ||||||||||||||||||||||
url += '&page=' + filter.offset; | ||||||||||||||||||||||
} | ||||||||||||||||||||||
url += '&labels=' + POST_REQUIRED_TAGS.join(',') | ||||||||||||||||||||||
url += '&labels=' + POST_REQUIRED_TAGS.join(','); | ||||||||||||||||||||||
if (filter.tag) { | ||||||||||||||||||||||
url += ',' + filter.tag | ||||||||||||||||||||||
url += ',' + filter.tag; | ||||||||||||||||||||||
} | ||||||||||||||||||||||
const cacheKey = 'posts-filter-' + Object.values(filter).join('-') | ||||||||||||||||||||||
const cacheKey = 'posts-filter-' + Object.values(filter).join('-'); | ||||||||||||||||||||||
return PromiseCacheService.getOrSet( | ||||||||||||||||||||||
cacheKey, | ||||||||||||||||||||||
() => $http | ||||||||||||||||||||||
|
@@ -126,14 +121,14 @@ angular | |||||||||||||||||||||
cache: true, | ||||||||||||||||||||||
}) | ||||||||||||||||||||||
.then(response => { | ||||||||||||||||||||||
$log.debug('response', response.config.url, response.data) | ||||||||||||||||||||||
$log.debug('response', response.config.url, response.data); | ||||||||||||||||||||||
const posts = PostFactory.createFromIssueList(response.data); | ||||||||||||||||||||||
$log.debug('posts', posts) | ||||||||||||||||||||||
$log.debug('posts', posts); | ||||||||||||||||||||||
|
||||||||||||||||||||||
return posts | ||||||||||||||||||||||
return posts; | ||||||||||||||||||||||
}), | ||||||||||||||||||||||
'2hours' | ||||||||||||||||||||||
) | ||||||||||||||||||||||
); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
}; | ||||||||||||||||||||||
}) | ||||||||||||||||||||||
|
@@ -149,7 +144,7 @@ function ReactionCounters(thumbUp, thumbDown, laugh, confused, heart, hooray, ro | |||||||||||||||||||||
hooray: hooray, | ||||||||||||||||||||||
rocket: rocket, | ||||||||||||||||||||||
eyes: eyes, | ||||||||||||||||||||||
} | ||||||||||||||||||||||
}; | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
function PostRepositoryFilter(limit, offset, tag) { | ||||||||||||||||||||||
|
@@ -158,11 +153,12 @@ function PostRepositoryFilter(limit, offset, tag) { | |||||||||||||||||||||
offset: offset, | ||||||||||||||||||||||
state: 'open', | ||||||||||||||||||||||
tag: tag, | ||||||||||||||||||||||
} | ||||||||||||||||||||||
}; | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
||||||||||||||||||||||
function Post(id, title, body, author, tags, commentsCount, createdAt) { | ||||||||||||||||||||||
function Post(id, title, body, author, tags, commentsCount, createdAt, getShortDescription) { | ||||||||||||||||||||||
|
||||||||||||||||||||||
return { | ||||||||||||||||||||||
id: id, | ||||||||||||||||||||||
title: title, | ||||||||||||||||||||||
|
@@ -172,13 +168,17 @@ function Post(id, title, body, author, tags, commentsCount, createdAt) { | |||||||||||||||||||||
selfUrl: id, | ||||||||||||||||||||||
commentsCount: commentsCount, | ||||||||||||||||||||||
createdAt: createdAt, | ||||||||||||||||||||||
} | ||||||||||||||||||||||
getShortDescription: function (post) { | ||||||||||||||||||||||
const delimiter = '<hr>' | ||||||||||||||||||||||
return post.body.substring(0, post.body.indexOf(delimiter)); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
}; | ||||||||||||||||||||||
Comment on lines
+171
to
+175
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
function Author(username, url, avatarUrl) { | ||||||||||||||||||||||
return { | ||||||||||||||||||||||
username: username, | ||||||||||||||||||||||
url: url, | ||||||||||||||||||||||
avatarUrl: avatarUrl, | ||||||||||||||||||||||
} | ||||||||||||||||||||||
}; | ||||||||||||||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Debug code should be removed