Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apis/client/view/header/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ <h1 id="api-header">
</div>
<div class="page-head-bookmarks pull-right">
{{# if currentUser }}
{{> bookmark api=api }}
{{> apiBookmark api=api }}
{{else}}
<a href="#" class="bookmark-button">
<div
Expand Down
2 changes: 1 addition & 1 deletion bookmarks/client/bookmark.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<template name="bookmark">
<template name="apiBookmark">
{{# if isBookmarked }}
<button class="bookmark-button bookmark bookmarked">
<i class="fa fa-bookmark"></i>
Expand Down
40 changes: 22 additions & 18 deletions bookmarks/client/bookmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import { Template } from 'meteor/templating';

import { ApiBookmarks } from '/bookmarks/collection';

Template.bookmark.created = function () {
Template.apiBookmark.created = function () {
// Get reference to template instance
const instance = this;

// subscribe to user bookmarks, creating reference to subscription
instance.bookmarksSubscription = instance.subscribe('myApiBookmarks');
// subscribe to user API bookmarks
instance.subscribe('userApiBookmarks');
};

Template.bookmark.events({
Template.apiBookmark.events({
'click .bookmark': function () {
// Get api backend Id from the context
const apiId = (this.api) ? this.api._id : this._id;
Expand All @@ -24,25 +24,29 @@ Template.bookmark.events({
},
});

Template.bookmark.helpers({
Template.apiBookmark.helpers({
isBookmarked () {
// Get api backend Id from the context
const apiId = (this.api) ? this.api._id : this._id;
// Placeholder to see if API is bookmarked
let isBookmarked;

// Get reference to template instance
const instance = Template.instance();

// Make sure bookmark subscription is ready
if (instance.bookmarksSubscription.ready()) {
// Get current user bookmark (should be only one API Bookmarks result available)
const userBookmarks = ApiBookmarks.findOne({ userId: Meteor.user()._id, apiIds: apiId });

// Make sure user has bookmarks
if (userBookmarks) {
return true;
}

return false;
// Get API ID from instance data context
const apiId = instance.data.api._id;

// Get current user bookmarks, only if this API is bookmarked
const userBookmarks = ApiBookmarks.findOne({
userId: Meteor.user()._id,
apiIds: apiId,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also make sure to check case "undefined" by using if (apiId) structure before using apiId.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes even i got it while testing , but didnt know how to fix it .. will try what you have suggested.

Copy link
Copy Markdown
Contributor

@brylie brylie Dec 30, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is resolved by fixing line 36. Change line 36 to instance.data.api._id

});
// Check if user has bookmarked current API
if (userBookmarks) {
isBookmarked = true;
} else {
isBookmarked = false;
}

return isBookmarked;
},
});
2 changes: 1 addition & 1 deletion bookmarks/collection/server/publications.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Meteor } from 'meteor/meteor';
import { ApiBookmarks } from '/bookmarks/collection';

Meteor.publish('myApiBookmarks', function () {
Meteor.publish('userApiBookmarks', function () {
if (this.userId) {
// get current user id
const userId = this.userId;
Expand Down
60 changes: 36 additions & 24 deletions catalogue/client/catalogue.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,28 @@ import { FlowRouter } from 'meteor/kadira:flow-router';
import { Apis } from '/apis/collection';
import { ApiBookmarks } from '/bookmarks/collection';

import $ from 'jquery';

Template.catalogue.onCreated(function () {
// Get reference to template instance
const instance = this;
// Get user id
const userId = Meteor.userId();

// Set filters
// Subscribe to all API logos
instance.subscribe('allApiLogo');

// Subscribe to all users, returns only usernames
instance.subscribe('allUsers');

// subscribe to user API bookmarks
instance.subscribe('userApiBookmarks');

// Set filters
// On default: Show all public apis for anonymous users
let filters = { isPublic: true };

// Get user id
const userId = Meteor.userId();

if (userId) {
// Show all available apis for registered users
filters = {
Expand All @@ -41,65 +53,65 @@ Template.catalogue.onCreated(function () {
filters,
});

// Subscribe to API logo collection
instance.subscribe('allApiLogo');
// Subscribe to all users, returns only usernames
instance.subscribe('allUsers');

// Watch for changes in the sort and filter settings
instance.autorun(() => {
// Check URL parameter for sorting
const sortByParameter = FlowRouter.getQueryParam('sortBy');
const sortBy = FlowRouter.getQueryParam('sortBy');

// Check URL parameter for sort direction and convert to integer
const sortDirectionParameter =
FlowRouter.getQueryParam('sortDirection') === 'ascending' ? 1 : -1;

// Check URL parameter for filtering
const filterByParameter = FlowRouter.getQueryParam('filterBy');
const sortDirection = FlowRouter.getQueryParam('sortDirection') === 'ascending' ? 1 : -1;

// Create a object for storage sorting parameters
const sort = {};
// GCheck of existing parameters
if (sortByParameter && sortDirectionParameter) {
// Get field and direction of sorting
sort[sortByParameter] = sortDirectionParameter;

// Check for sort parameters
if (sortBy && sortDirection) {
// Set field and direction of sorting
sort[sortBy] = sortDirection;
} else {
// Otherwise get it like default value
// Otherwise sort by name in ascending order
sort.name = 1;
}

// Change sorting
instance.pagination.sort(sort);

// Placeholder for filter values
let currentFilters = filters;

// Check URL parameter for filtering
const filterBy = FlowRouter.getQueryParam('filterBy');

// Filtering available for registered users
if (userId) {
switch (filterByParameter) {
case 'all':
switch (filterBy) {
case 'all': {
// Delete filter for managed apis & bookmarks
delete currentFilters.managerIds;
delete currentFilters._id;
break;
case 'my-apis':
}
case 'my-apis': {
// Delete filter for bookmarks
delete currentFilters._id;
// Set filter for managed apis
currentFilters.managerIds = userId;
break;
case 'my-bookmarks':
}
case 'my-bookmarks': {
// Delete filter for managed apis
delete currentFilters.managerIds;
// Get user bookmarks
const userBookmarks = ApiBookmarks.findOne({ userId }) || '';
// Set filter for bookmarks
currentFilters._id = { $in: userBookmarks.apiIds };
break;
default:
}
default: {
// Otherwise get it like default value
currentFilters = { isPublic: true };
break;
}
}
} else {
// Otherwise get it like default value
Expand Down
2 changes: 1 addition & 1 deletion catalogue/client/grid/grid.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
data-toggle="tooltip"
data-placement="bottom"
title="{{_ 'catalogue_BookmarkTooltip_user' }}">
{{> bookmark api=api catalogueView=true }}
{{> apiBookmark api=api catalogueView=true }}
</div>
</li>
{{ else }}
Expand Down
2 changes: 1 addition & 1 deletion catalogue/client/table/table.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ <h4 class="api-catalogue-table-title">
<td class="col-sm-1 text-center">
{{# if currentUser }}
<span class="api-card-bookmark">
{{> bookmark api=api catalogueView=true }}
{{> apiBookmark api=api catalogueView=true }}
</span>
{{ else }}
<span class="api-card-bookmark">
Expand Down
24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,30 @@
"doc": "docs"
},
"dependencies": {
"babel-runtime": "^6.18.0",
"babel-runtime": "^6.20.0",
"bcrypt": "^0.8.7",
"clipboard": "^1.5.12",
"clipboard": "^1.5.16",
"crossfilter": "^1.3.12",
"d3": "^3.5.17",
"datatables": "^1.10.12",
"dc": "^2.0.0-beta.32",
"dc": "^2.0.0-beta.33",
"elasticsearch": "^11.0.1",
"github": "^1.4.0",
"intro.js": "^2.3.0",
"intro.js": "^2.4.0",
"jquery": "^2.2.4",
"jquery-bbq": "^1.0.0",
"jquery.rateit": "^1.0.23",
"js-yaml": "^3.6.1",
"lodash": "^4.15.0",
"meteor-node-stubs": "^0.2.3",
"moment": "^2.14.1",
"simple-statistics": "^2.1.0",
"swagger-client": "^2.1.0",
"js-yaml": "^3.7.0",
"lodash": "^4.17.3",
"meteor-node-stubs": "^0.2.4",
"moment": "^2.17.1",
"simple-statistics": "^2.2.0",
"swagger-client": "^2.1.26",
"swagger-parser": "^3.4.1",
"swagger-ui": "^2.2.3",
"swagger-ui": "^2.2.8",
"swagger-ui-browserify": "^2.2.3-a",
"tinycolor2": "^1.4.1",
"urijs": "^1.18.1"
"urijs": "^1.18.4"
},
"devDependencies": {
"babel-eslint": "^6.1.2",
Expand Down