1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-24 07:39:43 +02:00

Content liking

New per space option that allows users to like/dislike content.

The prompt is configurable per space, e.g. "Was this useful?".

Enterprise edition gets new Votes report providing insights into most/least liked content.
This commit is contained in:
Harvey Kandola 2018-04-13 11:01:36 +01:00
parent 6c8f23792c
commit 22b6674edb
23 changed files with 1031 additions and 694 deletions

View file

@ -11,11 +11,13 @@
import { set } from '@ember/object';
import { A } from '@ember/array';
import stringUtil from '../utils/string';
import ArrayProxy from '@ember/array/proxy';
import Service, { inject as service } from '@ember/service';
export default Service.extend({
sessionService: service('session'),
storageSvc: service('localStorage'),
folderService: service('folder'),
ajax: service(),
store: service(),
@ -318,6 +320,41 @@ export default Service.extend({
});
},
//**************************************************
// Voting / Liking
//**************************************************
// Vote records content vote from user.
// Anonymous users can vote to and are assigned temp id that is stored
// client-side in browser local storage.
vote(documentId, vote) {
let userId = '';
if (this.get('sessionService.authenticated')) {
userId = this.get('sessionService.user.id');
} else {
let id = this.get('storageSvc').getSessionItem('anonId');
if (is.not.null(id) && is.not.undefined(id) && id.length === 16) {
userId = id;
} else {
userId = stringUtil.anonUserId();
}
this.get('storageSvc').storeSessionItem('anonId', userId);
}
let payload = {
userId: userId,
vote: vote
};
return this.get('ajax').post(`public/document/${documentId}/vote`, {
data: JSON.stringify(payload),
contentType: 'json'
});
},
//**************************************************
// Fetch bulk data
//**************************************************