<div class='card' ng-if='mentity.mdoc'>
<div class='card-body'>
+ <div class='pull-right'>
+ <entity-rating mentity='mentity' />
+ </div>
<div ng-bind-html='mentity.mdoc.html_documentation'></div>
</div>
</div>
--- /dev/null
+<span class='stars' ng-repeat='star in [1, 2, 3, 4, 5]' ng-if='ratings' title='mean: {{ratings.mean}} ({{ratings.ratings.length}} stars)'>
+ <span
+ class='star glyphicon'
+ ng-class='star <= ratings.mean? "glyphicon-star": "glyphicon-star-empty"'
+ ng-click='postStar(star)' />
+</span>
}
};
}])
+
+ .directive('entityRating', ['Feedback', function(Feedback, Code) {
+ return {
+ restrict: 'E',
+ scope: {
+ mentity: '='
+ },
+ templateUrl: '/directives/entity/stars.html',
+ link: function ($scope, element, attrs) {
+ $scope.postStar = function(rating) {
+ Feedback.postEntityStar($scope.mentity.full_name, rating,
+ function(data) {
+ $scope.ratings = data;
+ }, function(err) {
+ $scope.err = err;
+ });
+ }
+
+ Feedback.loadEntityStars($scope.mentity.full_name,
+ function(data) {
+ $scope.ratings = data;
+ }, function(err) {
+ $scope.err = err;
+ });
+ }
+ };
+ }])
})();
}
}])
+ .factory('Feedback', [ '$http', function($http) {
+ return {
+ loadEntityStars: function(id, cb, cbErr) {
+ $http.get(apiUrl + '/feedback/stars/' + id)
+ .success(cb)
+ .error(cbErr);
+ },
+ postEntityStar: function(id, rating, cb, cbErr) {
+ $http.post(apiUrl + '/feedback/stars/' + id, {rating: rating})
+ .success(cb)
+ .error(cbErr);
+ }
+ }
+ }])
+
.factory('DocDown', [ '$http', function($http) {
return {
postMarkdown: function(md, cb, cbErr) {
margin-top: 8px;
margin-bottom: 0px;
}
+
+/*
+ * Ratings
+ */
+
+.card .stars {
+ visibility: hidden
+}
+
+.card:hover .stars {
+ visibility: visible
+}
+
+.star {
+ color: grey;
+ cursor: pointer;
+}
+
+.star:hover, .star.active:hover {
+ color: #FF8100
+}
+
+.star.active {
+ color: #FFC000
+}
+
/*
* Users
*/