Skip to content

Commit 0d88a73

Browse files
committed
Merge pull request #572 from apinf/feature/api-backend-ratings
Feature/api backend ratings. Closes #519
2 parents abaf885 + d94df04 commit 0d88a73

File tree

12 files changed

+281
-5
lines changed

12 files changed

+281
-5
lines changed

.jshintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@
139139
// Apinf collections
140140
"ApiBackends": false,
141141
"ApiBackendConfigurations": false,
142+
"ApiBackendRatings": false,
142143
"ApiBookmarks": false,
143144
"ApiDocumentation": false,
144145
"ApiUmbrellaAdmins": false,

.meteor/packages

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ mizzao:sharejs-ace
6666
raix:ui-dropped-event
6767
brylie:accounts-admin-ui
6868
brylie:first-user-admin
69-
70-
7169
npm-container
7270
standard-minifiers
7371
meteor-base
@@ -85,5 +83,6 @@ spacebars
8583
check
8684
useraccounts:iron-routing
8785
pahans:inline-help
86+
dandv:jquery-rateit
8887
zenorocha:clipboard
8988
harrison:papa-parse

.meteor/versions

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ chart:[email protected]
5252
5353
5454
55+
5556
5657
5758

both/catalogue.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,15 @@ TabularTables.ApiTable = new Tabular.Table({
1212
{data: "name", title: "Name"},
1313
{data: "backend_host", title: "Backend host"},
1414
{
15-
data: "_id",
1615
title: "View Details",
1716
tmpl: Meteor.isClient && Template.viewApiBackendButton
1817
},
19-
{tmpl: Meteor.isClient && Template.favourite, title: "Bookmark"}
20-
]
18+
{tmpl: Meteor.isClient && Template.favourite, title: "Bookmark"},
19+
{
20+
tmpl: Meteor.isClient && Template.apiBackendRating,
21+
title: "Rating"
22+
}
23+
],
24+
responsive: true,
25+
autoWidth: false
2126
});

both/collections/apiBackendRatings.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
ApiBackendRatings = new Mongo.Collection('apiBackendRatings');
2+
3+
Schemas.ApiBackendRating = new SimpleSchema({
4+
'apiBackendId': {
5+
type: String,
6+
regEx: SimpleSchema.RegEx.Id
7+
},
8+
'userId': {
9+
type: String,
10+
regEx: SimpleSchema.RegEx.Id
11+
},
12+
'rating': {
13+
type: Number,
14+
min: 0,
15+
max: 4
16+
}
17+
});
18+
19+
ApiBackendRatings.allow({
20+
insert: function () {
21+
return true;
22+
},
23+
update: function () {
24+
return true;
25+
}
26+
});

both/collections/backend.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,3 +694,44 @@ SimpleSchema.messages({
694694
// update password form
695695
"updatePassword_passwordsMismatch": "Passwords do not match"
696696
});
697+
698+
ApiBackends.helpers({
699+
'getRating': function () {
700+
// Get API Backend ID
701+
apiBackendId = this._id;
702+
703+
// Check if user is logged in
704+
if (Meteor.userId()) {
705+
// Check if user has rated API Backend
706+
var userRating = ApiBackendRatings.findOne({
707+
userId: Meteor.userId(),
708+
apiBackendId: apiBackendId
709+
});
710+
711+
if (userRating) {
712+
return userRating.rating;
713+
}
714+
}
715+
716+
// Otherwise, get average rating
717+
718+
// Fetch all ratings
719+
var apiBackendRatings = ApiBackendRatings.find({
720+
apiBackendId: apiBackendId
721+
}).fetch();
722+
723+
// If ratings exist
724+
if (apiBackendRatings) {
725+
// Create array containing only rating values
726+
var apiBackendRatingsArray = _.map(apiBackendRatings, function (rating) {
727+
// get only the rating value; omit User ID and API Backend ID fields
728+
return rating.rating;
729+
});
730+
731+
// Get the average (mean) value for API Backend ratings
732+
var apiBackendRatingsAverage = ss.mean(apiBackendRatingsArray);
733+
734+
return apiBackendRatingsAverage;
735+
}
736+
}
737+
});

client/lib/simple-statistics/simple_statistics.min.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/lib/simple-statistics/simple_statistics.min.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.user-own-rating .rateit-selected {
2+
background: transparent url("packages/dandv_jquery-rateit/rateit/src/star.gif") repeat scroll left -32px;
3+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<template name="apiBackendRating">
2+
<span id="rating-{{ _id }}" class="rateit {{ userRatingClass }}"></span>
3+
{{# unless userHasRating}}
4+
<span class="rating-count badge">
5+
{{ ratingCount }}&nbsp;
6+
<i class="fa fa-user"></i>
7+
</span>
8+
{{/ unless }}
9+
</template>

0 commit comments

Comments
 (0)