fix: display of likes
This commit is contained in:
@@ -1,43 +1,46 @@
|
|||||||
$('#req-evals').on('click', () => {
|
$('#req-evals').on('click', () => {
|
||||||
frappe.msgprint("The evaluations have been moved to <a href='https://t.me/fossunited'>Telegram</a>")
|
frappe.msgprint("The evaluations have been moved to <a href='https://t.me/fossunited'>Telegram</a>")
|
||||||
})
|
})
|
||||||
var set_likes = function(liked, likes) {
|
var set_likes = function (liked, likes) {
|
||||||
let $btn = $('.btn-like');
|
let $btn = $('.btn-like');
|
||||||
$btn.text(`${likes} 👍`);
|
likes ? $btn.text(`${likes} 👍`): $btn.text(`👍`);
|
||||||
if (liked) {
|
if (liked) {
|
||||||
$btn.addClass('btn-secondary').removeClass('btn-default');
|
$btn.addClass('btn-dark').removeClass('btn-default');
|
||||||
} else {
|
} else {
|
||||||
$btn.addClass('btn-default').removeClass('btn-secondary');
|
$btn.addClass('btn-default').removeClass('btn-dark');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// set initial
|
// set initial likes
|
||||||
/* frappe.call('community.www.hackathons.project.like', {project: frappe.form_dict.project}, (data) => {
|
frappe.ready(() => {
|
||||||
set_likes(data.message.action =="Liked", data.message.likes)
|
var url_params = new URLSearchParams(window.location.search);
|
||||||
}) */
|
frappe.call('community.www.hackathons.project.like', { project: url_params.get("project"), initial: true }, (data) => {
|
||||||
|
set_likes(data.message.action == "Liked", data.message.likes)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
// like - unlike
|
// like - unlike
|
||||||
$('.btn-like').on('click', (e) => {
|
$('.btn-like').on('click', (e) => {
|
||||||
frappe.call('community.www.hackathons.project.like', {project: $(e.target).attr("data-project")}, (data) => {
|
frappe.call('community.www.hackathons.project.like', { project: $(e.target).attr("data-project") }, (data) => {
|
||||||
set_likes(data.message.action =="Liked", data.message.likes);
|
set_likes(data.message.action == "Liked", data.message.likes);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// accept / reject
|
// accept / reject
|
||||||
$('.btn-accept').on('click', (e) => {
|
$('.btn-accept').on('click', (e) => {
|
||||||
frappe.call('community.www.hackathons.project.join_request', {id: $(e.target).attr('data-request-id'), action: 'Accept'}, (data) => {
|
frappe.call('community.www.hackathons.project.join_request', { id: $(e.target).attr('data-request-id'), action: 'Accept' }, (data) => {
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
$('.btn-reject').on('click', (ev) => {
|
$('.btn-reject').on('click', (ev) => {
|
||||||
frappe.call('community.www.hackathons.project.join_request', {id: $(ev.target).attr('data-request-id'), action: 'Reject'}, (data) => {
|
frappe.call('community.www.hackathons.project.join_request', { id: $(ev.target).attr('data-request-id'), action: 'Reject' }, (data) => {
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
$('.btn-leave').on('click', (ev) => {
|
$('.btn-leave').on('click', (ev) => {
|
||||||
frappe.call('community.www.hackathons.project.join_request', {id: $(ev.target).attr('data-request-id'), action: 'Reject'}, (data) => {
|
frappe.call('community.www.hackathons.project.join_request', { id: $(ev.target).attr('data-request-id'), action: 'Reject' }, (data) => {
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -14,7 +14,6 @@ def get_context(context):
|
|||||||
context.hackathon = hackathon
|
context.hackathon = hackathon
|
||||||
context.members = get_members(project)
|
context.members = get_members(project)
|
||||||
context.confirmed_members = get_comfirmed_members(project)
|
context.confirmed_members = get_comfirmed_members(project)
|
||||||
context.likes = get_project_likes(project)
|
|
||||||
context.updates = get_updates(project)
|
context.updates = get_updates(project)
|
||||||
if frappe.session.user != "Guest":
|
if frappe.session.user != "Guest":
|
||||||
context.my_project = get_my_projects()
|
context.my_project = get_my_projects()
|
||||||
@@ -35,9 +34,6 @@ def get_members(project_name):
|
|||||||
def get_comfirmed_members(project_name):
|
def get_comfirmed_members(project_name):
|
||||||
return frappe.get_all("Community Project Member", {"project": project_name, "status": ("=", "Accepted") }, ['name'])
|
return frappe.get_all("Community Project Member", {"project": project_name, "status": ("=", "Accepted") }, ['name'])
|
||||||
|
|
||||||
def get_project_likes(project_name):
|
|
||||||
return frappe.get_all("Community Project Like", {"project": project_name})
|
|
||||||
|
|
||||||
def get_updates(project_name):
|
def get_updates(project_name):
|
||||||
return frappe.get_all('Community Project Update', {"project": project_name}, ['owner', 'creation', '`update` as project_update'])
|
return frappe.get_all('Community Project Update', {"project": project_name}, ['owner', 'creation', '`update` as project_update'])
|
||||||
|
|
||||||
@@ -68,25 +64,27 @@ def join_request(id, action):
|
|||||||
frappe.db.set_value('Community Project Member', id, 'status', 'Rejected')
|
frappe.db.set_value('Community Project Member', id, 'status', 'Rejected')
|
||||||
|
|
||||||
def has_already_liked(project):
|
def has_already_liked(project):
|
||||||
try:
|
likes = frappe.db.get_value('Community Project Like', {"owner": frappe.session.user, "project": project})
|
||||||
likes = frappe.get_doc("Community Project Like", {"project": project, "owner": frappe.session.user})
|
return likes
|
||||||
return likes
|
|
||||||
except frappe.DoesNotExistError:
|
|
||||||
return None
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def like(project):
|
def get_project_likes(project):
|
||||||
liked_project = has_already_liked(project)
|
return len(frappe.get_all("Community Project Like", {"project": project}))
|
||||||
if liked_project:
|
|
||||||
action= "Unliked"
|
|
||||||
liked_project.delete()
|
|
||||||
else:
|
|
||||||
action= "Liked"
|
|
||||||
frappe.get_doc({"doctype": "Community Project Like","project": project}).save()
|
|
||||||
|
|
||||||
likes = frappe.db.get_all("Community Project Like", {"project": project})
|
@frappe.whitelist()
|
||||||
frappe.db.set_value("Community Project", project, "likes", len(likes))
|
def like(project, initial=False):
|
||||||
|
liked_project = has_already_liked(project)
|
||||||
|
action = "Liked" if (liked_project and initial) else "Unliked"
|
||||||
|
if not initial:
|
||||||
|
if liked_project:
|
||||||
|
action = "Unliked"
|
||||||
|
frappe.get_doc("Community Project Like", liked_project).delete()
|
||||||
|
else:
|
||||||
|
action = "Liked"
|
||||||
|
frappe.get_doc({"doctype": "Community Project Like","project": project}).save()
|
||||||
|
|
||||||
|
frappe.db.set_value("Community Project", project, "likes", get_project_likes(project))
|
||||||
return {
|
return {
|
||||||
"action": action,
|
"action": action,
|
||||||
"likes": len(likes)
|
"likes": get_project_likes(project)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user