Skip to content

Commit

Permalink
Merge pull request #94 from phot0n/misc-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
shariquerik authored Aug 16, 2022
2 parents 8f324ca + c2baf2d commit 51a6ae5
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 112 deletions.
3 changes: 2 additions & 1 deletion wiki/www/contributions.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,16 @@
frappe.ready(
() => {
$('.get_contributions').click(() => {
let start = $(".list-jobs tbody tr").length;
frappe.call({
method: "wiki.www.contributions.get_contributions",
args: {
start: start,
limit: parseInt($('[name="limit"]').val()) + 10,
},
callback: (response) => {

if (response.message) {
$('.list-jobs tbody').empty()
$('[name="limit"]').val(parseInt($('[name="limit"]').val()) + 10)
for (contribution of response.message.contributions) {
$('.list-jobs tbody').append($(` <tr>
Expand Down
81 changes: 28 additions & 53 deletions wiki/www/contributions.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,26 @@
import frappe
from frappe import _
from wiki.wiki.doctype.wiki_page.wiki_page import get_open_contributions
from frappe.utils.data import cint
from wiki.wiki.doctype.wiki_page.wiki_page import get_open_drafts

color_map = {
"Changes Requested": "blue",
"Under Review": "orange",
"Rejected": "red",
"Approved": "green",
}


def get_context(context):
context.pilled_title = "Contributions " + get_open_contributions()
context.pilled_title = "My Contributions"
context.no_cache = 1
context.no_sidebar = 1
color_map = {
"Changes Requested": "blue",
"Under Review": "orange",
"Rejected": "red",
"Approved": "green",
}

context.contributions = []
contributions = frappe.get_list(
"Wiki Page Patch",
["message", "status", "name", "wiki_page", "creation", "new"],
order_by="modified desc",
limit=10,
filters=[["status", "!=", "Approved"]],
)
for contribution in contributions:
route = frappe.db.get_value("Wiki Page", contribution.wiki_page, "route")
if contribution.new:
contribution.edit_link = f"/{route}/new?wiki_page_patch={contribution.name}"
else:
contribution.edit_link = f"/{route}/edit?wiki_page_patch={contribution.name}"
contribution.color = color_map[contribution.status]
contribution.creation = frappe.utils.pretty_date(contribution.creation)
context.contributions.extend([contribution])

context.contributions = get_user_contributions(0, 10)
context = context.update(
{
"post_login": [
{"label": _("My Account"), "url": "/me"},
{"label": _("Logout"), "url": "/?cmd=web_logout"},
{
"label": _("Contributions ") + get_open_contributions(),
"url": "/contributions",
},
{
"label": _("My Drafts ") + get_open_drafts(),
"url": "/drafts",
Expand All @@ -54,32 +33,28 @@ def get_context(context):


@frappe.whitelist()
def get_contributions(limit):
context = frappe._dict()
context.no_cache = 1
context.no_sidebar = 1
color_map = {
"Changes Requested": "blue",
"Under Review": "orange",
"Rejected": "red",
"Approved": "green",
}
def get_contributions(start, limit):
return {"contributions": get_user_contributions(start, limit)}

context.contributions = []
contributions = frappe.get_list(

def get_user_contributions(start, limit):
contributions = []
wiki_page_patches = frappe.get_list(
"Wiki Page Patch",
["message", "status", "name", "wiki_page", "creation", "new"],
order_by="modified desc",
limit=limit,
start=cint(start),
limit=cint(limit),
filters=[["status", "!=", "Draft"], ["owner", '=', frappe.session.user]],
)
for contribution in contributions:
route = frappe.db.get_value("Wiki Page", contribution.wiki_page, "route")
if contribution.new:
contribution.edit_link = f"/{route}/new?wiki_page_patch={contribution.name}"
for wiki_page_patch in wiki_page_patches:
route = frappe.db.get_value("Wiki Page", wiki_page_patch.wiki_page, "route")
if wiki_page_patch.new:
wiki_page_patch.edit_link = f"/{route}/new-wiki?wiki_page_patch={wiki_page_patch.name}"
else:
contribution.edit_link = f"/{route}/edit?wiki_page_patch={contribution.name}"
contribution.color = color_map[contribution.status]
contribution.creation = frappe.utils.pretty_date(contribution.creation)
context.contributions.extend([contribution])
return context
wiki_page_patch.edit_link = f"/{route}/edit-wiki?wiki_page_patch={wiki_page_patch.name}"
wiki_page_patch.color = color_map[wiki_page_patch.status]
wiki_page_patch.creation = frappe.utils.pretty_date(wiki_page_patch.creation)
contributions.extend([wiki_page_patch])

return contributions
5 changes: 3 additions & 2 deletions wiki/www/drafts.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,24 @@
frappe.ready(
() => {
$('.get_contributions').click(() => {
let start = $(".list-jobs tbody tr").length;
frappe.call({
method: "wiki.www.drafts.get_drafts",
args: {
start: start,
limit: parseInt($('[name="limit"]').val()) + 10,
},
callback: (response) => {

if (response.message) {
$('.list-jobs tbody').empty()
$('[name="limit"]').val(parseInt($('[name="limit"]').val()) + 10)
for (contribution of response.message.contributions) {
$('.list-jobs tbody').append($(` <tr>
<td class="worker-name"><span class="indicator-pill no-margin ${contribution.color}">&nbsp;&nbsp;
${contribution.status}</span></td>
<td>${contribution.message}</td>
<td>${contribution.creation}</td>
<td> <a class="btn btn-default btn-xs center" href="${contribution.edit_link}">Open Contribution</a>
<td> <a class="btn btn-default btn-xs center" href="${contribution.edit_link}">Open Draft</a>
</td>
</tr>
Expand Down
78 changes: 22 additions & 56 deletions wiki/www/drafts.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,14 @@
import frappe
from frappe import _
from frappe.utils.data import cint
from wiki.wiki.doctype.wiki_page.wiki_page import get_open_contributions
from wiki.wiki.doctype.wiki_page.wiki_page import get_open_drafts


def get_context(context):
context.pilled_title = "My Drafts " + get_open_drafts()
context.pilled_title = "My Drafts"
context.no_cache = 1
context.no_sidebar = 1
color_map = {
"Changes Requested": "blue",
"Under Review": "orange",
"Draft": "orange",
"Rejected": "red",
"Approved": "green",
}

context.contributions = []
contributions = frappe.get_list(
"Wiki Page Patch",
["message", "status", "name", "wiki_page", "creation", "new"],
order_by="modified desc",
limit=10,
filters=[["status", "=", "Draft"], ["owner", '=', frappe.session.user]],
)
for contribution in contributions:
route = frappe.db.get_value("Wiki Page", contribution.wiki_page, "route")
if contribution.new:
contribution.edit_link = f"/{route}/new?wiki_page_patch={contribution.name}"
else:
contribution.edit_link = f"/{route}/edit?wiki_page_patch={contribution.name}"
contribution.color = color_map[contribution.status]
contribution.creation = frappe.utils.pretty_date(contribution.creation)
context.contributions.extend([contribution])

context.contributions = get_user_drafts(0, 10)
context = context.update(
{
"post_login": [
Expand All @@ -43,10 +18,6 @@ def get_context(context):
"label": _("My Contributions ") + get_open_contributions(),
"url": "/contributions",
},
{
"label": _("My Drafts ") + get_open_drafts(),
"url": "/drafts",
},
]
}
)
Expand All @@ -55,33 +26,28 @@ def get_context(context):


@frappe.whitelist()
def get_drafts(limit):
context = frappe._dict()
context.no_cache = 1
context.no_sidebar = 1
color_map = {
"Changes Requested": "blue",
"Under Review": "orange",
"Rejected": "red",
"Draft": "orange",
"Approved": "green",
}
def get_drafts(start, limit):
return {"contributions": get_user_drafts(start, limit)}

context.contributions = []
contributions = frappe.get_list(

def get_user_drafts(start, limit):
drafts = []
wiki_page_patches = frappe.get_list(
"Wiki Page Patch",
["message", "status", "name", "wiki_page", "creation", "new"],
order_by="modified desc",
limit=limit,
filters=[["status", "=", "Draft"]],
start=cint(start),
limit=cint(limit),
filters=[["status", "=", "Draft"], ["owner", '=', frappe.session.user]],
)
for contribution in contributions:
route = frappe.db.get_value("Wiki Page", contribution.wiki_page, "route")
if contribution.new:
contribution.edit_link = f"/{route}/new?wiki_page_patch={contribution.name}"
for wiki_page_patch in wiki_page_patches:
route = frappe.db.get_value("Wiki Page", wiki_page_patch.wiki_page, "route")
if wiki_page_patch.new:
wiki_page_patch.edit_link = f"/{route}/new-wiki?wiki_page_patch={wiki_page_patch.name}"
else:
contribution.edit_link = f"/{route}/edit?wiki_page_patch={contribution.name}"
contribution.color = color_map[contribution.status]
contribution.creation = frappe.utils.pretty_date(contribution.creation)
context.contributions.extend([contribution])
return context
wiki_page_patch.edit_link = f"/{route}/edit-wiki?wiki_page_patch={wiki_page_patch.name}"
wiki_page_patch.color = "orange"
wiki_page_patch.creation = frappe.utils.pretty_date(wiki_page_patch.creation)
drafts.extend([wiki_page_patch])

return drafts

0 comments on commit 51a6ae5

Please sign in to comment.