Skip to content

Commit

Permalink
IMP: add search on tree
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mboscolo committed Sep 5, 2024
1 parent 4188a55 commit a222daf
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 9 deletions.
2 changes: 1 addition & 1 deletion plm_web_3d/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down
11 changes: 11 additions & 0 deletions plm_web_3d/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(<configuration name>)description
out = f"""<span>{src_name}</span>"""
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"""<span title={product_product_id.name}>{product_product_id.engineering_code} Rev. {product_product_id.engineering_revision}</span>"""
break
return out

26 changes: 26 additions & 0 deletions plm_web_3d/static/src/js/OdooCADApplication.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
/*
Expand Down Expand Up @@ -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;
Expand Down
34 changes: 26 additions & 8 deletions plm_web_3d/static/src/js/lib/odoocad/odoocad.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 = "<span class='document_tree_span' webgl_ref_name='" + obj_name + "'>" + obj_name + "</span>";
if(children_found || object.children[i].name!=''){
tree_ref_elements[obj_name]=object.children[i]
out_lis += "<li class='document_tree_line'><i class='tree_item_visibility fa fa-eye' aria-hidden='true'></i><span class='caret'>" + obj_name + "</span>"+inner_html+"</li>";
out_lis += "<li class='document_tree_line' webgl_ref_name="+ obj_name +"><i class='tree_item_visibility fa fa-eye' aria-hidden='true'></i><span class='caret'>" + span_lable + "</span>" + inner_html + "</li>";
}
else{
out_lis += "<li class='document_tree_line'>" + obj_name + "</li>";
out_lis += "<li class='document_tree_line' webgl_ref_name="+ obj_name +">" + span_lable + "</li>";
}
found=true;
found=true;
}
}
return [out_lis + "</ul>", found];
Expand Down Expand Up @@ -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');
Expand All @@ -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){
Expand Down
3 changes: 3 additions & 0 deletions plm_web_3d/views/web_template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@
<b>Document Structure</b>
</div>
<hr class="datacard_line"/>
<div class="search_document_tree">
<input type="text" id="input_search_document_tree" placeholder="Search Here !!"/>
</div>
<lu id="document_tree">
</lu>
</div>
Expand Down

0 comments on commit a222daf

Please sign in to comment.