feat: add pages to nav after install
This commit is contained in:
@@ -58,6 +58,7 @@ web_include_js = ["website.bundle.js"]
|
||||
# ------------
|
||||
|
||||
# before_install = "lms.install.before_install"
|
||||
after_install = "lms.install.add_pages_to_nav"
|
||||
after_sync = "lms.install.after_sync"
|
||||
after_uninstall = "lms.install.after_uninstall"
|
||||
|
||||
|
||||
@@ -2,6 +2,10 @@ import frappe
|
||||
from frappe.desk.page.setup_wizard.setup_wizard import add_all_roles_to
|
||||
|
||||
|
||||
def after_install():
|
||||
add_pages_to_nav()
|
||||
|
||||
|
||||
def after_sync():
|
||||
create_lms_roles()
|
||||
set_default_home()
|
||||
@@ -91,3 +95,41 @@ def delete_custom_fields():
|
||||
for field in fields:
|
||||
frappe.db.delete("Custom Field", {"fieldname": field})
|
||||
frappe.db.commit()
|
||||
|
||||
|
||||
def add_pages_to_nav():
|
||||
pages = [
|
||||
{"label": "Courses", "url": "/courses", "parent": "Explore", "idx": 2},
|
||||
{"label": "Statistics", "url": "/statistics", "parent": "Explore", "idx": 3},
|
||||
{"label": "Jobs", "url": "/jobs", "parent": "Explore", "idx": 4},
|
||||
{"label": "People", "url": "/community", "parent": "Explore", "idx": 5},
|
||||
]
|
||||
|
||||
if not frappe.db.exists("Top Bar Item", {"label": "Explore"}):
|
||||
frappe.get_doc(
|
||||
{
|
||||
"doctype": "Top Bar Item",
|
||||
"label": "Explore",
|
||||
"parent": "Website Settings",
|
||||
"parenttype": "Website Settings",
|
||||
"parentfield": "top_bar_items",
|
||||
"idx": 1,
|
||||
}
|
||||
).save()
|
||||
|
||||
for page in pages:
|
||||
if not frappe.db.exists(
|
||||
"Top Bar Item", {"url": ["like", "%" + page.get("url") + "%"]}
|
||||
):
|
||||
frappe.get_doc(
|
||||
{
|
||||
"doctype": "Top Bar Item",
|
||||
"label": page.get("label"),
|
||||
"url": page.get("url"),
|
||||
"parent_label": page.get("parent"),
|
||||
"idx": page.get("idx"),
|
||||
"parent": "Website Settings",
|
||||
"parenttype": "Website Settings",
|
||||
"parentfield": "top_bar_items",
|
||||
}
|
||||
).save()
|
||||
|
||||
@@ -659,19 +659,14 @@ def get_chart_data(chart_name, timespan, timegrain, from_date, to_date):
|
||||
@frappe.whitelist(allow_guest=True)
|
||||
def get_course_completion_data():
|
||||
all_membership = frappe.db.count("LMS Batch Membership")
|
||||
completed = frappe.db.count("LMS Batch Membership", {
|
||||
"progress": ["like", "%100%"]
|
||||
})
|
||||
completed = frappe.db.count("LMS Batch Membership", {"progress": ["like", "%100%"]})
|
||||
|
||||
return {
|
||||
"labels": ["Completed", "In Progress"],
|
||||
"datasets": [
|
||||
{
|
||||
"name": "Course Completion",
|
||||
"values": [
|
||||
completed,
|
||||
all_membership - completed
|
||||
],
|
||||
}
|
||||
],
|
||||
}
|
||||
"labels": ["Completed", "In Progress"],
|
||||
"datasets": [
|
||||
{
|
||||
"name": "Course Completion",
|
||||
"values": [completed, all_membership - completed],
|
||||
}
|
||||
],
|
||||
}
|
||||
|
||||
@@ -36,3 +36,4 @@ lms.patches.v0_0.set_dashboard #11-10-2022
|
||||
lms.patches.v0_0.set_courses_page_as_home
|
||||
lms.patches.v0_0.set_member_in_progress #09-11-2022
|
||||
lms.patches.v0_0.convert_progress_to_float
|
||||
lms.patches.v0_0.add_pages_to_nav #11-11-2022
|
||||
|
||||
5
lms/patches/v0_0/add_pages_to_nav.py
Normal file
5
lms/patches/v0_0/add_pages_to_nav.py
Normal file
@@ -0,0 +1,5 @@
|
||||
import frappe
|
||||
from lms.install import add_pages_to_nav
|
||||
|
||||
def execute():
|
||||
add_pages_to_nav()
|
||||
@@ -1,8 +1,11 @@
|
||||
import frappe
|
||||
from frappe.utils import flt
|
||||
|
||||
|
||||
def execute():
|
||||
frappe.reload_doc("lms", "doctype", "lms_course_progress")
|
||||
progress_records = frappe.get_all("LMS Batch Membership", fields=["name", "progress"])
|
||||
for progress in progress_records:
|
||||
frappe.db.set_value("LMS Batch Membership", progress.name, "progress", flt(progress.progress))
|
||||
frappe.db.set_value(
|
||||
"LMS Batch Membership", progress.name, "progress", flt(progress.progress)
|
||||
)
|
||||
|
||||
@@ -23,7 +23,6 @@ frappe.ready(() => {
|
||||
generate_graph("Lesson Completion", "#lesson-completion");
|
||||
generate_course_completion_graph();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
const setup_file_size = () => {
|
||||
@@ -59,10 +58,13 @@ const join_course = (e) => {
|
||||
callback: (data) => {
|
||||
if (data.message == "OK") {
|
||||
$(".no-preview-modal").modal("hide");
|
||||
frappe.show_alert({
|
||||
message: __("Enrolled successfully"),
|
||||
indicator: "green",
|
||||
}, 3);
|
||||
frappe.show_alert(
|
||||
{
|
||||
message: __("Enrolled successfully"),
|
||||
indicator: "green",
|
||||
},
|
||||
3
|
||||
);
|
||||
setTimeout(function () {
|
||||
window.location.href = `/courses/${course}/learn/1.1`;
|
||||
}, 1000);
|
||||
@@ -86,12 +88,15 @@ const notify_user = (e) => {
|
||||
},
|
||||
callback: (data) => {
|
||||
$(".no-preview-modal").modal("hide");
|
||||
frappe.show_alert({
|
||||
message: __(
|
||||
"You have opted to be notified for this course. You will receive an email when the course becomes available."
|
||||
),
|
||||
indicator: "green",
|
||||
}, 3);
|
||||
frappe.show_alert(
|
||||
{
|
||||
message: __(
|
||||
"You have opted to be notified for this course. You will receive an email when the course becomes available."
|
||||
),
|
||||
indicator: "green",
|
||||
},
|
||||
3
|
||||
);
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, 3000);
|
||||
@@ -123,15 +128,16 @@ const add_chapter = (e) => {
|
||||
scroll_to_chapter_container();
|
||||
};
|
||||
|
||||
|
||||
const scroll_to_chapter_container = () => {
|
||||
$([document.documentElement, document.body]).animate({
|
||||
scrollTop: $(".new-chapter").offset().top,
|
||||
}, 1000);
|
||||
$([document.documentElement, document.body]).animate(
|
||||
{
|
||||
scrollTop: $(".new-chapter").offset().top,
|
||||
},
|
||||
1000
|
||||
);
|
||||
$(".new-chapter").find(".chapter-title-main").focus();
|
||||
};
|
||||
|
||||
|
||||
const save_chapter = (e) => {
|
||||
let target = $(e.currentTarget);
|
||||
let parent = target.closest(".chapter-parent");
|
||||
@@ -157,7 +163,7 @@ const save_chapter = (e) => {
|
||||
});
|
||||
};
|
||||
|
||||
const generate_graph = (chart_name, element, type="line") => {
|
||||
const generate_graph = (chart_name, element, type = "line") => {
|
||||
let date = frappe.datetime;
|
||||
|
||||
frappe.call({
|
||||
@@ -167,7 +173,7 @@ const generate_graph = (chart_name, element, type="line") => {
|
||||
timespan: "Select Date Range",
|
||||
timegrain: "Daily",
|
||||
from_date: date.add_days(date.get_today(), -30),
|
||||
to_date: date.add_days(date.get_today(), +1)
|
||||
to_date: date.add_days(date.get_today(), +1),
|
||||
},
|
||||
callback: (data) => {
|
||||
render_chart(data.message, chart_name, element, type);
|
||||
@@ -191,12 +197,16 @@ const render_chart = (data, chart_name, element, type) => {
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
const generate_course_completion_graph = () => {
|
||||
frappe.call({
|
||||
method: "lms.lms.utils.get_course_completion_data",
|
||||
callback: (data) => {
|
||||
render_chart(data.message, "Course Completion", "#course-completion", "pie")
|
||||
}
|
||||
})
|
||||
}
|
||||
render_chart(
|
||||
data.message,
|
||||
"Course Completion",
|
||||
"#course-completion",
|
||||
"pie"
|
||||
);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
0
lms/www/classes/__init__.py
Normal file
0
lms/www/classes/__init__.py
Normal file
@@ -1,5 +1,4 @@
|
||||
frappe.ready(() => {
|
||||
|
||||
$(".nav-link").click((e) => {
|
||||
change_hash(e);
|
||||
});
|
||||
@@ -7,10 +6,8 @@ frappe.ready(() => {
|
||||
if (window.location.hash) {
|
||||
open_tab();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
const change_hash = (e) => {
|
||||
window.location.hash = $(e.currentTarget).attr("href");
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user