04
2022
07

Mixing for refer component (Version 1) (Old Version)

//first, opening the master job mixing page, and copy below script in the console.

//============================================================mom window=========================================================================

function getRowsTotal() { //get row total of table.

  var count = 0;

  while(true) {

    if(!document.querySelector(`#Detail > tbody > tr:nth-child(${count+3}) > td:nth-child(4)`)) //if selector did not exist, return count number.

      return count;

 

    count++; //accumulate of the row count.

  }

}

 

var obj = {}; //master information, keys = test standard name, values = mixing Array. 

var standards = []; //test standard name keys 

var indexes = []; // index of test standard name keys

var mixing = []; // mixing Array values

var rowsTotal = getRowsTotal();

 

for(var i=0; i<rowsTotal; i++) {

  var standardName = document.querySelector(`#Detail > tbody > tr:nth-child(${i+3}) > td:nth-child(2)`).innerText; //column 2 test standard name.

  if(standardName) {   //standardName != "" => exists.

    standards.push(standardName);

    indexes.push(i);

  }

}

 

for(var i=0; i<rowsTotal; i++) { //push the mixing and split '+' in the mixing array, so this array is 2D array.

  mixing.push(document.querySelector(`#Detail > tbody > tr:nth-child(${i+3}) > td:nth-child(5)`).innerText.split("+"));

}

 

for(var i=0; i<standards.length; i++) {

  obj[standards[i]] = mixing.slice(indexes[i], (indexes[i+1] || rowsTotal+1)); //combine the keys (standard) and values (mixing) into objects.

}

 

localStorage.setItem('master', JSON.stringify(obj)) //storage string object in browser, then it can close the window of master job to avoid modification of master job.

 

// then open the child job mixing window, and copy the script below in the console.

 

/*

 

************************************************************************************************************************************************

 

 

*/

 

 

 

//=========================================================son window==============================================================================

function txt_download (content, filename) { //download txt function.

  var el = document.createElement('a');

  el.download = filename;

  el.style.display = 'none';

  var blob = new Blob([content]);

  el.href = URL.createObjectURL(blob);

  document.body.appendChild(el);

  el.click();

  document.body.removeChild(el);

};

 

var obj = JSON.parse(localStorage.getItem('master')); //get the object data from master job.

var arr = [];

var standardName = document.querySelector("#lblTestStd").innerText.trim(); //get the standard name in the child job, you can modify the standardName since it is variable.

console.log(standardName);

 

if(!obj[standardName]) 

  throw `No data for ${standardName} in master job`; //the standard name for child job is different to master job, you can modify the standardName since it is variable.

 

var componentNumbers = [...document.querySelectorAll("td:nth-child(4)")]

                       .map(item => item.innerText)

                       .filter(item => item.match(/^\d+$/));

 

var referNumbers = [...document.querySelectorAll("td:nth-child(6)")]

                   .slice(-componentNumbers.length)

                   .map(item => item.innerText.split("-")[1] || null);

 

/*var referNumbers = [...document.querySelectorAll("td:nth-child(3)")]

                     .slice(-componentNumbers.length)

                     .map(item => item.innerText.match(/^\d+$/)|| null);

                     

Components have been setted refer in the sorting programme. Therefore, the focus column is 3.

*/

 

var dict = {};

 

for(var i=0; i<referNumbers.length; i++) {

  if(!referNumbers[i])

    continue;

  

  dict[referNumbers[i]] = componentNumbers[i];

}

 

for(var i=0; i<referNumbers.length; i++) { //loop for refer component number and compare master job component number is equal or not, push the match data into arr array.

  if(!referNumbers[i])

    continue; //refer component number like regex HJ0\d{7}-(\d+) in the internal remark (column 6) and continue the components that cannot be referred.

 

  try

    arr.push(obj[standardName].filter(item => item.indexOf(referNumbers[i]) !== -1)[0].join("+")) //analysis the duplicate data from two array, and try to join "+" if array[0] is not undefined.

  } catch(e) {

      //since the component has been setted refer or enter in the internal remark, if no match data in the master job number, then this component should not exist in this test.

      arr.push(`component ${dict[referNumbers[i]]} cannot refer master job`); //or this component cannot be referred. 

  }  

}

 

var newArr = arr.filter((item, i) => arr.indexOf(item) === i).map(item => item.split("+"));

var newData = newArr.map(arr => arr.map(item => dict[item] || `Error: ${item}`).join("+"));

 

var content = newData.join("\r\n");

var filename = `${standardName}_mixing.txt`;

txt_download(content, filename);

    

 

 

/*

localStorage.removeItem('master'); //Optional, when the mixing is complete, can remove the storage data in the browser.

*/

 

 

 



« 上一篇 下一篇 »

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。