Monday, February 27, 2023

nested array filter data script code

   // searchData(){

  //   let defaultMeshData = this.dataServ.getModelObjectData();
  //   let filterData = []
  //   // if(defaultMeshData.length>0){
  //   //   defaultMeshData.forEach(mesh => {
  //   //     if(mesh.children.length>0){
  //   //       this.getSearchChildren(mesh)
  //   //     }

  //   //   });
  //   // }
  //   // this.meshObject = this.dataServ.getModelObjectData().filter(p => (p.isParentKnowledgeSkills).map(p => ({
  //   //     ...p,
  //   //     subCategories: this.getSearchChildren(p)
  //   // })));

  //   let result = defaultMeshData.reduce((a/*Accumulator*/, o/*Current object in array*/) => {
  //     // 1. We get the events with a specific category  (In this case -> 3)
  //     var filtered = o.children.filter((children) =>  (children.name).toLowerCase().indexOf(this.searchInput.toLowerCase()) > -1);

  //     // 2. If the previous filter returns at least one event, we need to push
  //     //    the current object 'o' with the filtered events.
  //     if (filtered.length) { // if length !== 0 we need to push the object.
  //       // 3. We use Object.assign to avoid any mutation over the original object.
  //       //    So, basically we create a new object with the original properties
  //       //    and finally we assign the filtered events to the property events.
  //       a.push(Object.assign({}, o, {children: filtered}));
  //     }

  //     return a;
  //   }, []/*Initial value (this array will contain the filtered objects)*/);
  //   console.log(result)
  // }
  // getSearchChildren(mesh){
  //   // if(mesh.children.length>0){
  //   //  return mesh.children = mesh.children.filter(children => (children.name).toLowerCase().indexOf(this.searchInput.toLowerCase()) > -1)
  //   // }
  //   let result = mesh.reduce((a/*Accumulator*/, o/*Current object in array*/) => {
  //     // 1. We get the events with a specific category  (In this case -> 3)
  //     var filtered = o.children.filter((children) =>  (children.name).toLowerCase().indexOf(this.searchInput.toLowerCase()) > -1);

  //     // 2. If the previous filter returns at least one event, we need to push
  //     //    the current object 'o' with the filtered events.
  //     if (filtered.length) { // if length !== 0 we need to push the object.
  //       // 3. We use Object.assign to avoid any mutation over the original object.
  //       //    So, basically we create a new object with the original properties
  //       //    and finally we assign the filtered events to the property events.
  //       a.push(Object.assign({}, o, {children: filtered}));
  //     }

  //     return a;
  //   }, []/*Initial value (this array will contain the filtered objects)*/);
  //   return result;
  // }
  // getSearchChildren(mesh){
  //   if(mesh.length>0){
  //     let result = mesh.reduce((a/*Accumulator*/, o/*Current object in array*/) => {
  //       // 1. We get the events with a specific category  (In this case -> 3)
  //       var filtered = o.children.filter((children) =>  (children.name).toLowerCase().indexOf(this.searchInput.toLowerCase()) > -1).map(child=> ({...child, children:this.getSearchChildren(child.children)}));

  //       if (filtered.length) { // if length !== 0 we need to push the object.
  //         a.push(Object.assign({}, o, {children: filtered}));
  //       }

  //       return a;
  //     }, []/*Initial value (this array will contain the filtered objects)*/);
  //     return result;
  //   }else{
  //     return mesh;
  //   }

  // }
  // searchData(){
  //   //     this.meshObject = this.dataServ.getModelObjectData().filter(p => (p.isParentKnowledgeSkills).map(p => ({
  //   //     ...p,
  //   //     subCategories: this.getSearchChildren(p)
  //   // })));
  //   let result =[];
  //   let defaultMeshData = this.dataServ.getModelObjectData();
  //   if(this.searchInput==''){
  //      result = defaultMeshData
  //   }else{

  //     result = defaultMeshData.reduce((a/*Accumulator*/, o/*Current object in array*/) => {
  //   // var filtered = o.children.filter((children) =>  (children.name).toLowerCase().indexOf(this.searchInput.toLowerCase()) > -1).map(child=> ({...child, children:this.getSearchChildren(child)}));
  //   var filtered = o.children.map(child=> ({...child, children:this.getSearchChildren(child.children)}));
  //     if (filtered.length) {
  //     a.push(Object.assign({}, o, {children: filtered}));
  //   }

  //   return a;
  // }, []/*Initial value (this array will contain the filtered objects)*/);
  // console.log(result);
  //   }

  //   this.meshObject = result;
  // }
   /**
   * Dynamic filter child list data filter and return data
   */
  getSearchChildren(mesh) {
    var result = [];
    mesh.children.forEach(child => {
      if (child.name.toLowerCase().indexOf(this.searchInput.toLowerCase()) > -1) {
        result.push(child);
      } else {
        if (child.hasChildren && mesh['children'] && mesh['children'].length > 0) {
          // child list filter
          child['children'] = this.getSearchChildren(child);
          if (child['children'] && child['children'].length > 0) {
            result.push(child);
          }
        }
      }
    });
    return result;
  }

  /***
   * Search mesh parent list and call child list
   */
  searchData() {
    var defaultMeshData = JSON.parse(JSON.stringify(this.dataServ.getModelObjectData()));
    let result = [];
    this.expand = true;
    if (this.searchInput == '') {
      result = defaultMeshData;
      this.expand = false;
    } else {
      defaultMeshData = JSON.parse(JSON.stringify(defaultMeshData.filter(e => e.parent == "")));
      defaultMeshData.forEach(mesh => {
        if (mesh.name.toLowerCase().indexOf(this.searchInput.toLowerCase()) > -1) {
          result.push(mesh);
        } else {
          if (mesh.hasChildren && mesh['children'] && mesh['children'].length > 0) {
           // child list filter
            mesh['children'] = this.getSearchChildren(mesh);
            if (mesh['children'] && mesh['children'].length > 0) {
              result.push(mesh);
            }
          }
        }
      });
    }
    this.meshObject = result;
  }

  /**
   * Search clear list data
   */
  searchClear() {
    this.expand = false;
    this.searchInput = '';
    this.meshObject = JSON.parse(JSON.stringify(this.dataServ.getModelObjectData()));
  }

Monday, May 24, 2021

Monday, July 13, 2020

Show json object in a input field-angularjs

<div class="floating-label">
          <input class="form-control floating-input"  placeholder=" " value="{{field_pluginData}}">
          <span class="highlight"></span>
          <label>Plugin Data</label>
        </div>
this.field_pluginData = JSON.stringify(respData[0]);

Friday, July 10, 2020

Monday, February 11, 2019

How to round float numbers in javascript?

Float value rounded number

javascript "toFixed()" predefined function  using

(6.688689).toFixed(); // equal to 7
(6.688689).toFixed(1); // equal to 6.7
(6.688689).toFixed(2); // equal to 6.69
MDN using rounded value

Math.round10(5.25, 0);  // 5
Math.round10(5.25, -1); // 5.3
Math.round10(5.25, -2); // 5.25
Math.round10(5, 0);     // 5
Math.round10(5, -1);    // 5
Math.round10(5, -2);    // 5

Thursday, January 31, 2019

How can I send a Firebase Cloud Messaging notification without use the Firebase Console?

FCM cloud message notification send mobile device on simple method try this code

$ch = curl_init();
$registration_ids="YOUR DEVICE ID";
ignore_user_abort();
ob_start();
$url = 'https://fcm.googleapis.com/fcm/send';
$message = 'Name:"Vengadeshwaran" Contact number:"888XXXX-XXX"';
$fields = array(
'registration_ids' => array($registration_ids),
'priority' => 10,
'notification' => array('title' => 'Birthday', 'body' => $message ,'sound'=>'Default'),
);
$google_api_key = 'WEB API KEY';
$headers = array(
'Authorization:key='.$google_api_key,
'Content-Type: application/json'
);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$status = curl_exec($ch);
curl_close($ch);
echo $status;