Generic Feedback Widget, Part IX

“There are three kinds of men. The one that learns by reading. The few who learn by observation. The rest of them have to pee on the electric fence for themselves.”
Will Rogers

Now that we have the Script Include put to bed, the next thing that I need to do to wrap up this little project is to update the widget. I need to add the code that displays a commenter’s rating, and I have also decided to replace the little comment icon next to each comment with the commenter’s avatar. Since ServiceNow already has a nice HTML tag set up for that purpose, all of that turned out to be a fairly simple reorganization of the existing HTML:

<div ng-repeat="item in data.feedback">
  <div class="snc-kb-comment-by" style="margin-top: 10px;">
    <sn-avatar primary="item.userSysId" class="avatar" show-presence="true" enable-context-menu="false" style="margin: 5px; float: left;"></sn-avatar>
    <span class="snc-kb-comment-by-title">
      Posted by <a class="snc-kb-comment-by-user" href="?id=user_profile&table=sys_user&sys_id={{item.userSysId}}">{{item.userName}}</a>
      <span class="snc-kb-comment-by-title">{{item.dateTime}}</span>
      <br/>{{item.rating}}
    </span>
  </div>
  <div style="clear: both;"></div>
  <div>
    <span class="snc-kb-comment-by-text" ng-bind-html="item.comment"></span>
  </div>
</div>

To fetch and format the rating, I added a new function to the server side Javascript:

function formatRating(profile) {
	var rating = '';
	var score = feedbackUtils.currentUserRating(data.table, data.sys_id, profile);
	for (var i=0; i<score; i++) {
		rating += '★';
	}
	return rating;
}

Putting it all together, the final result turns out a page that looks like this:

Formatted feedback with individual ratings and user avatars

… and if you want to see the breakdown of individual vote tallies, you can click on the Show Breakdown option and see this:

User feedback with rating breakdown displayed

I’m still not sure if it would be better to put the new comment input box ahead of the comment history rather than at the end, but I think I will leave things as they are for now. I’m sure that I will eventually come up with some other additions or corrections at some point, so I will put off any further thoughts of making any additional changes until that time. I can’t say that I have thoroughly tested every possible aspect of this process, but what I have spent a little time with all seems to working as it should. I think I will call this one done for today, and go ahead and publish a final(?) Update Set.