From a222dafde3b564a50adf439564cb338f72b39e69 Mon Sep 17 00:00:00 2001 From: Matteo Boscolo Date: Thu, 5 Sep 2024 16:51:21 +0200 Subject: [PATCH] IMP: add search on tree with this commit there is a new functionallity for searching data inside the document tree structure and also a cabability to retrive component information from the tree --- plm_web_3d/__manifest__.py | 2 +- plm_web_3d/controllers/main.py | 11 ++++++ .../static/src/js/OdooCADApplication.js | 26 ++++++++++++++ .../static/src/js/lib/odoocad/odoocad.js | 34 ++++++++++++++----- plm_web_3d/views/web_template.xml | 3 ++ 5 files changed, 67 insertions(+), 9 deletions(-) diff --git a/plm_web_3d/__manifest__.py b/plm_web_3d/__manifest__.py index 756407cf..7257b560 100644 --- a/plm_web_3d/__manifest__.py +++ b/plm_web_3d/__manifest__.py @@ -20,7 +20,7 @@ ############################################################################## { "name": "PLM Web 3d Support", - "version": "17.0.0.1", + "version": "17.0.0.2", "author": "OmniaSolutions", "website": "https://odooplm.omniasolutions.website", "category": "Manufacturing/Product Lifecycle Management (PLM)", diff --git a/plm_web_3d/controllers/main.py b/plm_web_3d/controllers/main.py index 4279ccda..381cbe98 100755 --- a/plm_web_3d/controllers/main.py +++ b/plm_web_3d/controllers/main.py @@ -79,4 +79,15 @@ def getProductInfo(self, document_id): components = self.component_extra(components) out['component']=components return json.dumps(out) + + @route('/plm/get_3d_web_document_info', type='http', auth="user") + @webservice + def get_3d_web_document_info(self, src_name): + src_name = src_name.split("(")[0] # this split is needed for solidwoks file the put the configuration on the name filename()description + out = f"""{src_name}""" + for ir_attachment in request.env['ir.attachment'].sudo().search(['|',('name','ilike', src_name),('engineering_code','ilike', src_name)]): + for product_product_id in ir_attachment.linkedcomponents: + out = f"""{product_product_id.engineering_code} Rev. {product_product_id.engineering_revision}""" + break + return out \ No newline at end of file diff --git a/plm_web_3d/static/src/js/OdooCADApplication.js b/plm_web_3d/static/src/js/OdooCADApplication.js index a713a263..9cc9c3ea 100644 --- a/plm_web_3d/static/src/js/OdooCADApplication.js +++ b/plm_web_3d/static/src/js/OdooCADApplication.js @@ -209,6 +209,22 @@ function createMarker(){ return new_point } +function search_document_tree(element) { + var input, filter, ul, li, a, i, txtValue; + input = document.getElementById("input_search_document_tree"); + filter = input.value.toUpperCase(); + ul = document.getElementById("document_tree"); + li = ul.getElementsByTagName("li"); + for (i = 0; i < li.length; i++) { + a = li[i].getElementsByTagName("span")[0]; + txtValue = a.textContent || a.innerText; + if (txtValue.toUpperCase().indexOf(filter) > -1) { + li[i].style.display = ""; + } else { + li[i].style.display = "none"; + } + } +} function init() { /* @@ -264,8 +280,18 @@ function init() { */ OdooCad = new ODOOCAD.OdooCAD(scene); OdooCad.load_document(document_id, document_name); +/* + * Inizialize tree view search + */ + var input_document_tree = document.getElementById('input_search_document_tree'); + input_document_tree.addEventListener("keyup", search_document_tree); } + + + + + function getCameraCSSMatrix(matrix) { var elements = matrix.elements; diff --git a/plm_web_3d/static/src/js/lib/odoocad/odoocad.js b/plm_web_3d/static/src/js/lib/odoocad/odoocad.js index 7662c1d0..5c256522 100644 --- a/plm_web_3d/static/src/js/lib/odoocad/odoocad.js +++ b/plm_web_3d/static/src/js/lib/odoocad/odoocad.js @@ -71,6 +71,18 @@ class OdooCAD{ // /// + set_str_name(span_element){ + var file_name = span_element.parentElement.attributes['webgl_ref_name'].value; + var xmlhttp = new XMLHttpRequest(); + var url = "../plm/get_3d_web_document_info/?src_name=" + file_name; + xmlhttp.onreadystatechange = function() { + if (this.readyState == 4 && this.status == 200) { + span_element.innerHTML = this.responseText; + } + }; + xmlhttp.open("GET", url, true); + xmlhttp.send(); + } get_li_structure(object, nested=false){ var self = this; var found=false; @@ -86,14 +98,15 @@ class OdooCAD{ if (object.children[i].type=='Group' ||object.children[i].name!=''){ const [inner_html, children_found] = self.get_li_structure(object.children[i], true); var obj_name=object.children[i].name; + var span_lable = "" + obj_name + ""; if(children_found || object.children[i].name!=''){ tree_ref_elements[obj_name]=object.children[i] - out_lis += "
  • " + obj_name + ""+inner_html+"
  • "; + out_lis += "
  • " + span_lable + "" + inner_html + "
  • "; } else{ - out_lis += "
  • " + obj_name + "
  • "; + out_lis += "
  • " + span_lable + "
  • "; } - found=true; + found=true; } } return [out_lis + "", found]; @@ -142,16 +155,16 @@ class OdooCAD{ this.classList.toggle("caret-down"); }); } - + // var tree_item_visibility = document.getElementsByClassName("tree_item_visibility"); for (i = 0; i < tree_item_visibility.length; i++) { tree_item_visibility[i].addEventListener("click", function() { - var groupObj = tree_ref_elements[this.nextElementSibling.innerText]; + var groupObj = tree_ref_elements[this.parentElement.attributes['webgl_ref_name'].value]; var icon = this; if (icon.classList.contains('fa-eye')) { - icon.classList.remove('fa-eye'); - icon.classList.add('fa-eye-slash'); - groupObj.visible=false; + icon.classList.remove('fa-eye'); + icon.classList.add('fa-eye-slash'); + groupObj.visible=false; } else { icon.classList.remove('fa-eye-slash'); @@ -160,6 +173,11 @@ class OdooCAD{ } }); } + // + var span_tree_documents = document.getElementsByClassName("document_tree_span"); + for (i = 0; i < span_tree_documents.length; i++) { + this.set_str_name(tree_item_visibility[i]) + } } removeItemToSeen(object){ diff --git a/plm_web_3d/views/web_template.xml b/plm_web_3d/views/web_template.xml index 73ff635d..94052c0a 100644 --- a/plm_web_3d/views/web_template.xml +++ b/plm_web_3d/views/web_template.xml @@ -100,6 +100,9 @@ Document Structure
    +
    + +