Skip to content
Open
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
1 change: 1 addition & 0 deletions control/content/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<script src="../../widget/global/js/constants/index.js"></script>
<script src="../../widget/global/js/models/Setting.js"></script>
<script src="../../widget/global/js/repositories/Settings.js"></script>
<script src="../../widget/global/js/services/AuthManager.js"></script>
<script src="../../widget/global/js/services/Analyutics.js"></script>
<!-- endbuild -->

Expand Down
2 changes: 1 addition & 1 deletion control/content/js/content.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const contentController = {
Settings.get().then((result) => {
if (!result || !Object.keys(result).length) {
Analytics.init(); // init analytics only for the first time of installing the plugin
Settings.save(new Setting({ navigateToCwByDefault: true })).then((settings) => {
Settings.save(new Setting({ navigateToCwByDefault: true, createdBy: authManager.currentUser.userId })).then((settings) => {
state.settings = new Setting();
resolve();
}).catch((err) => { // don't blok the ui, just print the error and resolve
Expand Down
4 changes: 3 additions & 1 deletion control/content/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,7 @@ const contentPage = {
};

window.onload = () => {
contentPage.init();
authManager.enforceLogin().then(() => {
contentPage.init();
});
};
1 change: 1 addition & 0 deletions control/settings/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<script src="../../widget/global/js/models/Setting.js"></script>
<script src="../../widget/global/js/repositories/Settings.js"></script>
<script src="../../widget/global/js/constants/index.js"></script>
<script src="../../widget/global/js/services/AuthManager.js"></script>
<!-- endbuild -->


Expand Down
7 changes: 5 additions & 2 deletions control/settings/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@ const settingsPage = {
}));
this.updateDeepSettingValue(`${settingKey}.tags`, updatedTags);
};
tagsInput.set(settingValue.tags);
const tags = settingValue.tags.map(tag => ({...tag, tagName: tag.tagName ? tag.tagName : tag.value}));
tagsInput.set(tags);
},

initDropdown(options) {
Expand Down Expand Up @@ -385,5 +386,7 @@ const settingsPage = {
};

window.onload = () => {
settingsPage.init();
authManager.enforceLogin().then(() => {
settingsPage.init();
});
};
2 changes: 2 additions & 0 deletions widget/global/js/repositories/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class Settings {

static save(settings) {
return new Promise((resolve, reject) => {
settings.lastUpdatedOn = new Date();
settings.lastUpdatedBy = authManager.currentUser.userId;
buildfire.datastore.save(new Setting(settings), this.TAG, (err, res) => {
if (err) {
reject(err);
Expand Down
1 change: 1 addition & 0 deletions widget/global/js/repositories/UserCredits.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class UserCredits {
if (!results || !results.length) {
const data = new UserCredit({
userId,
createdBy: userId,
}).toJSON();
this.insert(data).then((res) => {
res.data.id = res.id;
Expand Down
20 changes: 10 additions & 10 deletions widget/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,16 @@ <h4 id="suggestionTitle" class="word--break body-text font-weight-600"></h4>
<div class="button__panel">
<span class="suggestion-icon-holder">
<button class="voteButton btn btn--icon--text">
<i id="upvote_icon" class="padding-zero iconsTheme material-icons-outlined"
aria-hidden="true">thumb_up</i>
<i id="upvote_icon" class="padding-zero margin--zero bodyTextTheme material-icons"
aria-hidden="true">arrow_upward</i>
</button>
<p id="suggestionVotesCount" class="pill-count shrink--0">
<span class="margin--0 iconsTheme"></span>
<span class="margin--0 bodyTextTheme"></span>
</p>
</span>
<span id="suggestionCommentContainer" class="suggestion-icon-holder">
<i class="iconsTheme material-icons-outlined" aria-hidden="true">chat_bubble_outline</i>
<span class="iconsTheme margin-left-five" bfString="mainScreen.commentButton"></span>
<i class="bodyTextTheme material-icons-outlined" aria-hidden="true">chat_bubble_outline</i>
<span class="bodyTextTheme margin-left-five" bfString="mainScreen.commentButton"></span>
</span>
</div>
</div>
Expand All @@ -129,16 +129,16 @@ <h4 class="body-text font-weight-600" id="suggestionTitle"></h4>
<div class="button__panel">
<span class="suggestion-icon-holder">
<button class="voteButton btn btn--icon--text">
<i id="upvote_icon" class="padding-zero iconsTheme material-icons-outlined"
aria-hidden="true">thumb_up</i>
<i id="upvote_icon" class="padding-zero margin--zero bodyTextTheme material-icons"
aria-hidden="true">arrow_upward</i>
</button>
<p id="suggestionVotesCount" class="pill-count shrink--0">
<span class="margin--0 iconsTheme"></span>
<span class="margin--0 bodyTextTheme"></span>
</p>
</span>
<span id="suggestionCommentContainer" class="suggestion-icon-holder">
<i class="iconsTheme material-icons-outlined" aria-hidden="true">chat_bubble_outline</i>
<span class="iconsTheme margin-left-five" bfString="mainScreen.commentButton"></span>
<i class="bodyTextTheme material-icons-outlined" aria-hidden="true">chat_bubble_outline</i>
<span class="bodyTextTheme margin-left-five" bfString="mainScreen.commentButton"></span>
</span>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion widget/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const hasPermission = (permissionType) => {
const permissionTags = state.settings.permissions[permissionType].tags;

for (let i = 0; i < permissionTags.length; i++) {
if (userTags.some((_tag) => _tag.tagName === permissionTags[i].tagName)) {
if (userTags.some((_tag) => (_tag.tagName === permissionTags[i].tagName || _tag.tagName === permissionTags[i].value))) {
userPermitted = true;
break;
}
Expand Down
22 changes: 9 additions & 13 deletions widget/js/pages/home/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,24 @@ const homePage = {
suggestionTitle.innerHTML = suggestion.title;
suggestionBodyText.innerHTML = suggestion.suggestion;
widgetPagesShared.validateSuggestionImage(suggestionBodyText);
suggestionVotesCount.innerHTML = `<span class="margin--0 iconsTheme">${Object.keys(suggestion.upVotedBy).length}</span>`;
let suggestionVotesCountClasses = 'margin--0';

if (!state.settings.enableComments) {
suggestionCommentContainer.classList.add('hidden');
}

if (authManager.currentUser && suggestion.upVotedBy && suggestion.upVotedBy[authManager.currentUser.userId]) {
upvote_icon.className = 'padding-zero margin--zero iconsTheme material-icons';
suggestionVotesCountClasses += ' iconsTheme'
} else {
suggestionVotesCountClasses += ' bodyTextTheme'
}
if (suggestion.status === SUGGESTION_STATUS.COMPLETED) {
upvote_icon.classList.add('disabled');
}

suggestionVotesCount.innerHTML = `<span class="${suggestionVotesCountClasses}">${Object.keys(suggestion.upVotedBy).length}</span>`;

suggestionCommentContainer.onclick = () => widgetPagesShared.navigateToSuggestionComments(suggestion);
upvote_icon.onclick = () => widgetPagesShared.voteToSuggestion(suggestion);
suggestionStatus.onclick = () => widgetPagesShared.updateSuggestionStatus(suggestion);
Expand Down Expand Up @@ -223,20 +228,11 @@ const homePage = {
});

if (suggestions.length < state.pageSize) {
if (state.currentStatusSearch === SUGGESTION_STATUS.COMPLETED) {
if (state.startFetchingCompleted) {
state.isAllSuggestionFetched = true;
if (!state.suggestionsList.length) this.printEmptyState();
} else if (state.currentStatusSearch === SUGGESTION_STATUS.INPROGRESS) {
state.currentStatusSearch = SUGGESTION_STATUS.COMPLETED;
state.page = 0;

widgetController.getSuggestions().then((suggestions) => {
this.handleSuggestionPage(suggestions)
}).catch((err) => {
console.error(err);
});
} else {
state.currentStatusSearch = SUGGESTION_STATUS.INPROGRESS;
state.startFetchingCompleted = true;
state.page = 0;

widgetController.getSuggestions().then((suggestions) => {
Expand All @@ -251,7 +247,7 @@ const homePage = {
init() {
this.initSelectors();

widgetController.getSuggestions().then((suggestions) => {
widgetController.getFirstSuggestionsPage().then((suggestions) => {
setTimeout(() => {
this.destroySkeleton();

Expand Down
7 changes: 6 additions & 1 deletion widget/js/pages/suggestion/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,24 @@ const suggestionDetailsPage = {
suggestionTitle.innerHTML = state.activeSuggestion.title;
suggestionBodyText.innerHTML = state.activeSuggestion.suggestion;
widgetPagesShared.validateSuggestionImage(suggestionBodyText);
suggestionVotesCount.innerHTML = `<span class="margin--0 iconsTheme">${Object.keys(state.activeSuggestion.upVotedBy).length}</span>`;
let suggestionVotesCountClasses = 'margin--0';

if (!state.settings.enableComments) {
suggestionCommentContainer.classList.add('hidden');
}

if (authManager.currentUser && state.activeSuggestion.upVotedBy && state.activeSuggestion.upVotedBy[authManager.currentUser.userId]) {
upvote_icon.className = 'padding-zero margin--zero iconsTheme material-icons';
suggestionVotesCountClasses += ' iconsTheme'
} else {
suggestionVotesCountClasses += ' bodyTextTheme'
}
if (state.activeSuggestion.status === SUGGESTION_STATUS.COMPLETED) {
upvote_icon.classList.add('disabled');
}

suggestionVotesCount.innerHTML = `<span class="${suggestionVotesCountClasses}">${Object.keys(state.activeSuggestion.upVotedBy).length}</span>`;

suggestionCommentContainer.onclick = () => widgetPagesShared.navigateToSuggestionComments(state.activeSuggestion);
upvote_icon.onclick = () => widgetPagesShared.voteToSuggestion(state.activeSuggestion);
suggestionStatus.onclick = () => widgetPagesShared.updateSuggestionStatus(state.activeSuggestion);
Expand Down
8 changes: 4 additions & 4 deletions widget/js/pages/widgetPagesShared.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,11 @@ const widgetPagesShared = {
}).then((isConfirmed) => {
if (isConfirmed) {
widgetController.handleSuggestionUnVote(suggestion).then((updatedSuggestion) => {
if (upvote_icon) upvote_icon.className = 'padding-zero margin--zero iconsTheme material-icons-outlined';
if (suggestionVotesCount) suggestionVotesCount.innerHTML = `<span class="margin--0 iconsTheme">${Object.keys(updatedSuggestion.upVotedBy).length}</span>`;
if (upvote_icon) upvote_icon.className = 'padding-zero margin--zero bodyTextTheme material-icons';
if (suggestionVotesCount) suggestionVotesCount.innerHTML = `<span class="margin--0 bodyTextTheme">${Object.keys(updatedSuggestion.upVotedBy).length}</span>`;

if (detailsVoteIcon) detailsVoteIcon.className = 'padding-zero margin--zero iconsTheme material-icons-outlined';
if (detailsVotesCount) detailsVotesCount.innerHTML = `<span class="margin--0 iconsTheme">${Object.keys(updatedSuggestion.upVotedBy).length}</span>`;
if (detailsVoteIcon) detailsVoteIcon.className = 'padding-zero margin--zero bodyTextTheme material-icons';
if (detailsVotesCount) detailsVotesCount.innerHTML = `<span class="margin--0 bodyTextTheme">${Object.keys(updatedSuggestion.upVotedBy).length}</span>`;
}).catch((err) => {
console.error(err);
if (upvote_icon) upvote_icon.classList.remove('disabled');
Expand Down
2 changes: 1 addition & 1 deletion widget/js/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ const state = {
settings: new Setting(),
page: 0,
pageSize: 50,
currentStatusSearch: SUGGESTION_STATUS.BACKLOG,
fetching: false,
isAllSuggestionFetched: false,
startFetchingCompleted: false,
validUserImages: {},
suggestionsList: [],
updatedUsersData: [],
Expand Down
38 changes: 32 additions & 6 deletions widget/js/widget.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,17 @@ const widgetController = {

getSuggestions() {
return new Promise((resolve) => {
const { page, pageSize, settings, currentStatusSearch } = state;
const { page, pageSize, settings, startFetchingCompleted } = state;
const searchOptions = { page, pageSize };
let $match = {
"_buildfire.index.string1": { $exists: false }
}, $sort = {};

if (currentStatusSearch === SUGGESTION_STATUS.COMPLETED) {
if (startFetchingCompleted) {
// hide completed immediately
if (settings.hideCompletedItems === 0) return resolve([]);

// hide completed after a certain period
if (settings.hideCompletedItems > 0) {
const startDate = new Date();
startDate.setDate(startDate.getDate() - settings.hideCompletedItems);
Expand All @@ -71,10 +73,14 @@ const widgetController = {
{ modifiedOn: { $gte: startDate } }
];
} else {
$match.status = { $eq: currentStatusSearch };
// never hide the completed items
$match.status = { $eq: SUGGESTION_STATUS.COMPLETED };
}
} else {
$match.status = { $eq: currentStatusSearch };
$match['$or'] = [
{ status: SUGGESTION_STATUS.BACKLOG },
{ status: SUGGESTION_STATUS.INPROGRESS },
];
}

switch (settings.defaultItemSorting) {
Expand Down Expand Up @@ -124,6 +130,23 @@ const widgetController = {
});
},

getFirstSuggestionsPage() {
return new Promise((resolve, reject) => {
this.getSuggestions().then((suggestions) => {
if (suggestions.length >= 10) {
resolve(suggestions);
} else {
state.startFetchingCompleted = true;
state.page = 0;

this.getSuggestions().then(() => {
resolve(state.suggestionsList);
});
}
})
})
},

getSuggestionById(suggestionId) {
return new Promise((resolve, reject) => {
Suggestions.getById(suggestionId).then((suggestion) => {
Expand Down Expand Up @@ -221,6 +244,8 @@ const widgetController = {
const payload = {
$set: {
credits: encryptedCredits,
lastUpdatedBy: authManager.currentUser._id,
lastUpdatedOn: new Date(),
},
};
return UserCredits.update(authManager.currentUser._id, payload).then((updatedCredits) => {
Expand All @@ -242,14 +267,15 @@ const widgetController = {
const encryptedCredits = widgetUtils.encryptCredit(state.settings.inAppPurchase.votesPerPurchase, ENUMS.SECRET_KEY);
const payload = {
$set: {
createdBy: authManager.currentUser._id,
lastUpdatedBy: authManager.currentUser._id,
lastUpdatedOn: new Date(),
credits: encryptedCredits,
firstTimePurchase: true,
},
};
UserCredits.update(authManager.currentUser._id, payload).then((updatedCredits) => {
state.userCredits = {
createdBy: authManager.currentUser._id,
lastUpdatedBy: authManager.currentUser._id,
credits: encryptedCredits,
firstTimePurchase: true,
};
Expand Down