Skip to content

Commit

Permalink
Add view count for admins
Browse files Browse the repository at this point in the history
  • Loading branch information
mithandir committed Sep 15, 2023
1 parent 8da8582 commit 78cadce
Showing 1 changed file with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public class NewsItemComponent {
@Autowired
private CommonComponents commonComponents;

@Autowired
private CommonSessionComponents commonSessionComponents;

@Autowired
private MongoController mongo;

Expand Down Expand Up @@ -79,11 +82,20 @@ public HorizontalLayout buildNewsItem(int index, NewsEntry item) {
Span date = new Span(item.getPublishedDateTime().format(DateTimeFormatter.ISO_LOCAL_DATE));
date.getStyle().set("font-size", "small");

Span voteSum = new Span(String.valueOf(item.getVotes()));

var voteSum = new Span(String.valueOf(item.getVotes()));
voteSum.getStyle().set("font-size", "small");

var viewSum = new Span(String.valueOf(item.getViews()));
viewSum.getStyle().set("font-size", "small");

var viewIcon = VaadinIcon.BAR_CHART.create();
viewIcon.setSize("15px");
viewIcon.setTooltipText("Views");

Icon vote = VaadinIcon.THUMBS_UP.create();
vote.setSize("15px");
vote.setTooltipText("Likes");
vote.addClickListener((ComponentEventListener<ClickEvent<Icon>>) iconClickEvent -> handleVotes(item, voteSum, vote));

Icon viewContent = VaadinIcon.SEARCH.create();
Expand All @@ -92,7 +104,11 @@ public HorizontalLayout buildNewsItem(int index, NewsEntry item) {

commonComponents.checkIconStatus(vote, item.getLink());

rowDateAndLinks.add(date, voteSum, vote);
if (commonSessionComponents.isAdmin()) {
rowDateAndLinks.add(date, viewSum, viewIcon, voteSum, vote);
} else {
rowDateAndLinks.add(date, voteSum, vote);
}

VerticalLayout column = new VerticalLayout();
column.add(rowTitle, rowDateAndLinks);
Expand Down

0 comments on commit 78cadce

Please sign in to comment.