fix: pre commit issues

This commit is contained in:
Jannat Patel
2022-11-04 11:47:09 +05:30
parent cda26ab248
commit 603eddf878
210 changed files with 10725 additions and 6733 deletions

View File

@@ -1,5 +1,4 @@
frappe.ready(() => {
setup_file_size();
$(".join-batch").click((e) => {
@@ -17,18 +16,15 @@ frappe.ready(() => {
$(document).on("click", ".btn-save-chapter", (e) => {
save_chapter(e);
});
});
const setup_file_size = () => {
frappe.provide("frappe.form.formatters");
frappe.form.formatters.FileSize = file_size;
};
const file_size = (value) => {
if(value > 1048576) {
if (value > 1048576) {
value = flt(flt(value) / 1048576, 1) + "M";
} else if (value > 1024) {
value = flt(flt(value) / 1024, 1) + "K";
@@ -36,7 +32,6 @@ const file_size = (value) => {
return value;
};
const join_course = (e) => {
e.preventDefault();
let course = $(e.currentTarget).attr("data-course");
@@ -48,27 +43,29 @@ const join_course = (e) => {
let batch = $(e.currentTarget).attr("data-batch");
batch = batch ? decodeURIComponent(batch) : "";
frappe.call({
"method": "lms.lms.doctype.lms_batch_membership.lms_batch_membership.create_membership",
"args": {
"batch": batch ? batch : "",
"course": course
method: "lms.lms.doctype.lms_batch_membership.lms_batch_membership.create_membership",
args: {
batch: batch ? batch : "",
course: course,
},
"callback": (data) => {
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);
}
}
})
},
});
};
const notify_user = (e) => {
e.preventDefault();
var course = decodeURIComponent($(e.currentTarget).attr("data-course"));
@@ -80,22 +77,26 @@ const notify_user = (e) => {
frappe.call({
method: "lms.lms.doctype.lms_course_interest.lms_course_interest.capture_interest",
args: {
"course": course
course: course,
},
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);
}
})
},
});
};
const add_chapter = (e) => {
if ($(".new-chapter").length) {
scroll_to_chapter_container();
@@ -103,28 +104,33 @@ const add_chapter = (e) => {
}
let next_index = $("[data-index]").last().data("index") + 1 || 1;
let add_after = $(`.chapter-parent:last`).length ? $(`.chapter-parent:last`) : $("#outline-heading");
let add_after = $(`.chapter-parent:last`).length
? $(`.chapter-parent:last`)
: $("#outline-heading");
$(`<div class="chapter-parent chapter-edit new-chapter">
<div contenteditable="true" data-placeholder="${__('Chapter Name')}" class="chapter-title-main"></div>
<div contenteditable="true" data-placeholder="${__(
"Chapter Name"
)}" class="chapter-title-main"></div>
<div class="chapter-description small my-2" contenteditable="true"
data-placeholder="${__('Short Description')}"></div>
data-placeholder="${__("Short Description")}"></div>
<button class="btn btn-sm btn-secondary d-block btn-save-chapter"
data-index="${next_index}"> ${__('Save')} </button>
data-index="${next_index}"> ${__("Save")} </button>
</div>`).insertAfter(add_after);
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");
@@ -132,11 +138,11 @@ const save_chapter = (e) => {
frappe.call({
method: "lms.lms.doctype.lms_course.lms_course.save_chapter",
args: {
"course": $("#title").data("course"),
"title": parent.find(".chapter-title-main").text(),
"chapter_description": parent.find(".chapter-description").text(),
"idx": target.data("index"),
"chapter": target.data("chapter") ? target.data("chapter") : ""
course: $("#title").data("course"),
title: parent.find(".chapter-title-main").text(),
chapter_description: parent.find(".chapter-description").text(),
idx: target.data("index"),
chapter: target.data("chapter") ? target.data("chapter") : "",
},
callback: (data) => {
frappe.show_alert({
@@ -146,7 +152,6 @@ const save_chapter = (e) => {
setTimeout(() => {
window.location.reload();
}, 1000);
}
},
});
};

File diff suppressed because one or more lines are too long

View File

@@ -1,13 +1,12 @@
function getLiveCodeOptions() {
var START = `
var START = `
import sketch
code = open("main.py").read()
env = dict(sketch.__dict__)
exec(code, env)
`
`;
var SKETCH = `
var SKETCH = `
import json
def sendmsg(msgtype, function, args):
@@ -50,57 +49,57 @@ def clear():
# clear the canvas on start
clear()
`
const CANVAS_FUNCTIONS = {
circle: function(ctx, args) {
ctx.beginPath();
ctx.arc(args.x, args.y, args.d/2, 0, 2*Math.PI);
ctx.stroke();
},
line: function(ctx, args) {
ctx.beginPath();
ctx.moveTo(args.x1, args.y1);
ctx.lineTo(args.x2, args.y2);
ctx.stroke();
},
rect: function(ctx, args) {
ctx.beginPath();
ctx.rect(args.x, args.y, args.w, args.h);
ctx.stroke();
},
clear: function(ctx, args) {
var width = 300;
var height = 300;
ctx.clearRect(0, 0, width, height);
`;
const CANVAS_FUNCTIONS = {
circle: function (ctx, args) {
ctx.beginPath();
ctx.arc(args.x, args.y, args.d / 2, 0, 2 * Math.PI);
ctx.stroke();
},
line: function (ctx, args) {
ctx.beginPath();
ctx.moveTo(args.x1, args.y1);
ctx.lineTo(args.x2, args.y2);
ctx.stroke();
},
rect: function (ctx, args) {
ctx.beginPath();
ctx.rect(args.x, args.y, args.w, args.h);
ctx.stroke();
},
clear: function (ctx, args) {
var width = 300;
var height = 300;
ctx.clearRect(0, 0, width, height);
},
};
function drawOnCanvas(canvasElement, funcName, args) {
var ctx = canvasElement.getContext("2d");
var func = CANVAS_FUNCTIONS[funcName];
var scalex = canvasElement.width / 300;
var scaley = canvasElement.height / 300;
ctx.save();
ctx.scale(scalex, scaley);
func(ctx, args);
ctx.restore();
}
}
function drawOnCanvas(canvasElement, funcName, args) {
var ctx = canvasElement.getContext('2d');
var func = CANVAS_FUNCTIONS[funcName];
var scalex = canvasElement.width/300;
var scaley = canvasElement.height/300;
ctx.save();
ctx.scale(scalex, scaley);
func(ctx, args);
ctx.restore();
}
return {
runtime: "python",
files: [
{filename: "start.py", contents: START},
{filename: "sketch.py", contents: SKETCH},
],
command: ["python", "start.py"],
codemirror: true,
onMessage: {
draw: function(editor, msg) {
const canvasElement = editor.parent.querySelector("canvas");
drawOnCanvas(canvasElement, msg.function, msg.args);
}
}
}
return {
runtime: "python",
files: [
{ filename: "start.py", contents: START },
{ filename: "sketch.py", contents: SKETCH },
],
command: ["python", "start.py"],
codemirror: true,
onMessage: {
draw: function (editor, msg) {
const canvasElement = editor.parent.querySelector("canvas");
drawOnCanvas(canvasElement, msg.function, msg.args);
},
},
};
}

View File

@@ -1,10 +1,14 @@
frappe.ready(() => {
hide_profile_and_dashboard_for_guest_users();
hide_profile_and_dashboard_for_guest_users();
});
const hide_profile_and_dashboard_for_guest_users = () => {
if (frappe.session.user == "Guest") {
let links = $('.nav-link').filter((i, elem) => $(elem).text().trim() === "My Profile" || $(elem).text().trim() === "Dashboard");
links.length && links.each((i, elem) => $(elem).addClass("hide"));
}
if (frappe.session.user == "Guest") {
let links = $(".nav-link").filter(
(i, elem) =>
$(elem).text().trim() === "My Profile" ||
$(elem).text().trim() === "Dashboard"
);
links.length && links.each((i, elem) => $(elem).addClass("hide"));
}
};

View File

@@ -1,3 +1,3 @@
import "./profile.js"
import "./common_functions.js"
import "../../../../frappe/frappe/public/js/frappe/ui/chart.js"
import "./profile.js";
import "./common_functions.js";
import "../../../../frappe/frappe/public/js/frappe/ui/chart.js";