diff --git a/smart_service/phase_2/doctype/instructions/instructions.json b/smart_service/phase_2/doctype/instructions/instructions.json index 025f4fb..e525d7e 100644 --- a/smart_service/phase_2/doctype/instructions/instructions.json +++ b/smart_service/phase_2/doctype/instructions/instructions.json @@ -32,9 +32,11 @@ "fieldname": "content", "fieldtype": "Small Text", "in_list_view": 1, - "label": "Content" + "label": "Content", + "read_only_depends_on": "// eval:doc.content_type=='Image'" }, { + "depends_on": "// eval:doc.content_type == 'Image'", "fieldname": "attach_file", "fieldtype": "Attach", "in_list_view": 1, @@ -51,7 +53,7 @@ "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2023-10-04 11:06:07.232457", + "modified": "2023-10-05 09:59:05.591167", "modified_by": "Administrator", "module": "Phase-2", "name": "Instructions", diff --git a/smart_service/phase_2/doctype/special_tool_information/special_tool_information.js b/smart_service/phase_2/doctype/special_tool_information/special_tool_information.js index eacebcd..f15aac3 100644 --- a/smart_service/phase_2/doctype/special_tool_information/special_tool_information.js +++ b/smart_service/phase_2/doctype/special_tool_information/special_tool_information.js @@ -73,6 +73,25 @@ frappe.ui.form.on('Special Tool Information', { if (!frm.is_new()){ teb_validation(frm) } + if (frm.doc.instructions) { + frappe.call({ + method: "smart_service.phase_2.doctype.special_tool_information.special_tool_information.file_validation_child", + args: { + name: frm.doc.name, + value:"instructions" + }, + callback: function (r) { + console.log(r.message, "----file validation size-------") + if (r.message && r.message[0] == false) { + if (r.message[1]) { + frappe.validated = false; + frm.reload_doc() + frappe.throw("In Special Tool information content " + r.message[1] + " row was invalid file type") + } + } + } + }) + } }, }); function teb_validation(frm){ @@ -158,4 +177,26 @@ frappe.ui.form.on('Instructions', { } refresh_field("instructions"); }, + content_type: function (frm, cdt, cdn) { + // refresh_field("instructions") + var select_value = locals[cdt][cdn]; + var x = select_value.idx - 1; + // let my_row = frm.fields_dict.content.grid.grid_rows[x]; + if (select_value.content_type == 'Image' || select_value.content_type == 'Video' || select_value.content_type == 'PDF'){ + cur_frm.get_field("instructions").grid.grid_rows[x].columns.content.df.read_only = 1; + cur_frm.get_field("instructions").grid.grid_rows[x].columns.attach_file.df.read_only = 0; + cur_frm.get_field("instructions").grid.grid_rows[x].columns.step_name.df.read_only = 0; + cur_frm.get_field("instructions").grid.grid_rows[x].columns.title.df.read_only = 0; + cur_frm.refresh_field("content_type") + } + else { + cur_frm.get_field("instructions").grid.grid_rows[x].columns.attach_file.df.read_only = 1; + cur_frm.get_field("instructions").grid.grid_rows[x].columns.content.df.read_only = 0; + cur_frm.get_field("instructions").grid.grid_rows[x].columns.step_name.df.read_only = 0; + cur_frm.get_field("instructions").grid.grid_rows[x].columns.title.df.read_only = 0; + cur_frm.refresh_fields("content_type") + } + cur_frm.refresh_fields("content_type") + refresh_field("instructions"); + }, }) diff --git a/smart_service/phase_2/doctype/special_tool_information/special_tool_information.json b/smart_service/phase_2/doctype/special_tool_information/special_tool_information.json index 38d9a25..4eadd87 100644 --- a/smart_service/phase_2/doctype/special_tool_information/special_tool_information.json +++ b/smart_service/phase_2/doctype/special_tool_information/special_tool_information.json @@ -11,9 +11,10 @@ "column_break_cyo0a", "vehicle", "tool_type", - "keywords", "image", + "image_preview", "aggregate_image", + "aggregate_image_preview", "column_break_m3p9i", "category", "aggregate_name", @@ -26,7 +27,7 @@ "my_id", "section_break_e91wx", "instructions", - "image_preview" + "keywords" ], "fields": [ { @@ -43,7 +44,8 @@ "fieldname": "display_order", "fieldtype": "Int", "in_list_view": 1, - "label": "Display Order" + "label": "Display Order", + "reqd": 1 }, { "fieldname": "my_id", @@ -89,6 +91,8 @@ "depends_on": "eval:doc.category !='TEB';", "fieldname": "aggregate_name", "fieldtype": "Data", + "in_list_view": 1, + "in_standard_filter": 1, "label": "Aggregate Name", "reqd": 1, "set_only_once": 1 @@ -123,6 +127,8 @@ { "fieldname": "tool_type", "fieldtype": "Select", + "in_list_view": 1, + "in_standard_filter": 1, "label": "Tool Type", "options": "New Tool\nCarry Over", "set_only_once": 1 @@ -146,6 +152,7 @@ "fieldtype": "Column Break" }, { + "depends_on": "eval:doc.image;", "fieldname": "image_preview", "fieldtype": "Image", "label": "Image Preview", diff --git a/smart_service/phase_2/doctype/special_tool_information/special_tool_information.py b/smart_service/phase_2/doctype/special_tool_information/special_tool_information.py index 6787872..6e63e2a 100644 --- a/smart_service/phase_2/doctype/special_tool_information/special_tool_information.py +++ b/smart_service/phase_2/doctype/special_tool_information/special_tool_information.py @@ -6,6 +6,7 @@ from frappe.model.document import Document class SpecialToolInformation(Document): def validate(self): + # self.name="" if self.is_new(): count = frappe.db.sql('''select max(my_id) as max_count from `tabSpecial Tool Information`;''') if count[0][0] is not None: @@ -14,12 +15,71 @@ class SpecialToolInformation(Document): self.my_id = 1 if self.keywords: self.keywords=self.keywords.strip() - if self.aggregate_name: - self.aggregate_name=self.aggregate_name.strip() if self.tool_name: self.tool_name=self.tool_name.strip() + if self.aggregate_name: + self.aggregate_name=self.aggregate_name.strip() + self.name = self.vehicle + '-' + \ + self.tool_type + '-' + self.category + '-' + self.aggregate_name + else: + self.name = self.vehicle + '-' + self.tool_type + '-' + self.category if not self.is_new() and self.published == 1: self.published = 0 +@frappe.whitelist() +def file_validation_child(name, value=None): + from smart_service.apis.utils import check_png_ext, check_img_ext, check_zip_ext, check_pdf_ext, details_of_image, checking_image, check_mp4_ext, get_file_size + if name: + child_data = frappe.db.sql( + """select * from `tabtabInstructions` where parent='%s'"""%(name), as_dict=1) + for d in child_data: + if d['attach_file']: + res = False + res1 = False + res2 = False + res3 = False + if d['content_type'] == "Image": + res = check_img_ext(d['attach_file']) + res1 = check_png_ext(d['attach_file']) + elif d['content_type'] == "PDF": + res3 = check_pdf_ext(d['attach_file']) + else: + res2 = check_mp4_ext(d['attach_file']) + + if res == True or res1 == True: + width, height, size = details_of_image( + d['attach_file']) + if width > 1280 or height > 720 or size > 1*1024 and d['attach_file']: + val = checking_image( + d['attach_file'], "Special Tool Information", value, name, 1) + frappe.delete_doc("Instructions", d['name']) + if val == True: + return False, d['idx'] + else: + return True + elif res2 == True: + video_size_mb = get_file_size(d['attach_file']) + if video_size_mb > 10: + frappe.delete_doc('Instructions', d['name']) + return (False, d['idx']) + elif res3 == True: + pdf_size_mb = get_file_size(d['attach_file']) + if pdf_size_mb > 1: + frappe.delete_doc('Instructions',d['name']) + return (False, d['idx']) + else: + if res == False and res1==False: + ret = res + elif res2 == False: + ret = res2 + else: + ret = res3 + val = checking_image( + d['attach_file'], 'Special Tool Information', value, name, 1) + frappe.delete_doc('Instructions', d['name']) + return (ret, d['idx']) + + + diff --git a/smart_service/phase_2/doctype/training_information/training_information.js b/smart_service/phase_2/doctype/training_information/training_information.js index cd1f977..bfd0a1a 100644 --- a/smart_service/phase_2/doctype/training_information/training_information.js +++ b/smart_service/phase_2/doctype/training_information/training_information.js @@ -22,7 +22,7 @@ frappe.ui.form.on('Training Information', { }, after_save: function (frm) { if (frm.doc.content) { - frappe.call({ + frappe.call({ method: "smart_service.phase_2.doctype.training_information.training_information.file_validation_child", args: { name: frm.doc.name, @@ -82,18 +82,18 @@ frappe.ui.form.on('Training Information Content Reference',{ cur_frm.refresh_field("content"); cur_frm.refresh_field(); }, - validate:function(frm){ - let task_index = row.docfields.findIndex(x => x.fieldname === "content"); - if (row.doc.asset_type == 'Image' || row.doc.asset_type == 'Video') { - row.docfields[task_index].read_only = 0; - // cur_frm.get_field("tool_usage_content").grid.grid_rows[x].columns.content.df.set=[]; - } else { - row.docfields[task_index].read_only = 1; - } - row.toggle_editable_row(true); - refresh_field("content"); - cur_frm.refresh_field("content"); - refresh_field(); + // validate:function(frm){ + // let task_index = row.docfields.findIndex(x => x.fieldname === "content"); + // if (row.doc.asset_type == 'Image' || row.doc.asset_type == 'Video') { + // row.docfields[task_index].read_only = 0; + // // cur_frm.get_field("tool_usage_content").grid.grid_rows[x].columns.content.df.set=[]; + // } else { + // row.docfields[task_index].read_only = 1; + // } + // row.toggle_editable_row(true); + // refresh_field("content"); + // cur_frm.refresh_field("content"); + // refresh_field(); - } + // } }) \ No newline at end of file