Adding new line for image id to Crowd Elements Json output result

I’m creating an annotation-tool using the Crowd HTML Elements that let users annotate images with the bounding box format. The form looks like this:https://codepen.io/sagemaker_crowd_html_elements/pen/XWpJGad?editors=1111.

<script src="https://assets.crowd.aws/crowd-html-elements.js"></script>

<crowd-form>
  <crowd-bounding-box
    name="annotatedResult"
    src="https://images.unsplash.com/photo-1533713692156-f70938dc0d54?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=2467&q=80"
    header="Draw bounding boxes around all the cats and dogs in this image"
    labels="['Fish', 'Coral', 'Turtle']"
  >


    <full-instructions header="Bounding Box Instructions" >
      <p>Use the bounding box tool to draw boxes around the requested target of interest:</p>
      <ol>
        <li>Draw a rectangle using your mouse over each instance of the target.</li>
        <li>Make sure the box does not cut into the target, leave a 2 - 3 pixel margin</li>
        <li>
          When targets are overlapping, draw a box around each object,
          include all contiguous parts of the target in the box.
          Do not include parts that are completely overlapped by another object.
        </li>
        <li>
          Do not include parts of the target that cannot be seen,
          even though you think you can interpolate the whole shape of the target.
        </li>
        <li>Avoid shadows, they're not considered as a part of the target.</li>
        <li>If the target goes off the screen, label up to the edge of the image.</li>
      </ol>
    </full-instructions>



    <short-instructions>
      Draw boxes around the requested target of interest.
    </short-instructions>
  </crowd-bounding-box>
</crowd-form>  

JSON OUTPUT:

TaskAnswers
[
  {
    "annotatedResult": {
      "boundingBoxes": [
        {
          "height": 456,
          "label": "Fish",
          "left": 1010,
          "top": 411,
          "width": 1028
        },
        {
          "height": 434,
          "label": "Fish",
          "left": 85,
          "top": 1313,
          "width": 1542
 }
      ],
      "inputImageProperties": {
        "height": 1850,
        "width": 2467
      }
    }
  }
]

But i new a line for image id because i need to save this result in database with image id and i have many images.

I want to take this output with image_id and write it to a database. But I don’t know how to add a new line to JSON and how to save it in a remote database. I tried adding some properties and javascript code but it didn’t help me. If anyone has a solution it would be great! Or where can i find to source code for crowd element?

{
    "image_id": 297992,// what i need
    "annotations": [
      {
    "annotatedResult": {


      "boundingBoxes": [
                {
          "height": 223,
          "label": "placeholder",
          "left": 168,
          "top": 173,
          "width": 238
        }
      ],


      "inputImageProperties": {
        "height": 800,
        "width": 800
      }
    }

How to delete object in arrays of arrays by id?

const arr = [
  {id: 1, children: [{id: 2, children: [{id: 3}]}},
  {id: 4, children: [{id: 5}]},
  {id: 6, children: [{id: 7}, chidlren: [{id: 7}]]}}
]

I have aray with a lot of objects which can have many children arrays but every object has unique key. So How I can loop through main array and delete some object? For example object with id 3

Passing javascript variable to Calendly embed

I’m pre populating a Calendly embed fields with a value that is using an innerText property. However, the Calendly fields are not getting filled and the browser is throwing an error in multiple scenarios.

  1. When the input parent wrapper (‘.form-grid__wrapper’) flexbox direction is set to column the only 1 field is getting filled on the Calendly embed and throwing this error (GET https://connect.facebook.net/en_US/fbevents.js net::ERR_BLOCKED_BY_CLIENT).

  2. Wheres when the parent wrapper flexbox direction is set to row none of the Calendly fields are getting the value.

The JS code pre populating the embed.

<!-- Calendly inline widget begin -->
<script>
const typeOptions = [...document.querySelectorAll('.consultation-slider__content')]
const type = [...document.querySelectorAll('.book-grid__content')]
const submit = document.getElementById('submit');

//Type of apppointment the user has chosen and moves the slider
var chosenType = "";
for (var i = 0; i < type.length; i++) {
    type[i].onclick = e => {
        chosenType = e.target.innerText;
    }
}

//Type of product the user chosen and moves the slider 
var chosenProduct = "";
for (var i = 0; i < typeOptions.length; i++) {
    typeOptions[i].onclick = e => {
        chosenProduct = e.target.innerText;
    }
}

submit.addEventListener('click', () => {
    Calendly.initInlineWidget({
        url: 'https://calendly.com/eric-910?hide_gdpr_banner=1',
        parentElement: document.getElementById('calendly'),
        prefill: {
          name: "",
          email: "",
          customAnswers: {
            a1: chosenType,
            a2: chosenProduct,
          }
        }
   });
})

</script>

Please see the issue here in the multi step slider “Book consultation form”.

https://diamond-elite.webflow.io/book-consultation-js-set-constant-js-settings-adblockerdetection-false

Also, from the browser extention tab I can see that the adblock ads are increasing when I load the Calendly embed so I have disabled my adblock to see if it’s working but ended up facing the same issue again.

How to wrap text in css?

the text just overflows into a vertical direction.How to make it wrap?
css for the div:

.taskdescription{
  display:block;
  word-wrap: break-word;
  overflow: auto;
  color: #673ab7;
  width: 300px;

} 

what its looking like.

enter image description here

AMCharts 5 : Change bullet opacity on legend hover

I’m trying to adapt this amcharts 5 example on how to highlight a series when hovering the legend : https://www.amcharts.com/demos/highlighting-line-chart-series-on-legend-hover/

Here is my codepen : https://codepen.io/rduteil/pen/YzYeKew

What I am trying to do is to make the bullets opacity match the stroke.
But changing the series opacity has no effect on bullet as those are rendered through a function and never updated after that.

I was wondering if there was a way to change the bullets appearance in the legend’s pointerhover event without clearing the series bullets to force a rerender.

I want to get rid of this piece of code :

series.bullets.clear();
series.bullets.push(() => am5.Bullet.new(root, {
  sprite: am5.Circle.new(root, {
    opacity: 0.15,
    fill: series.get("fill"),
    radius: 3
  })
}));

Remove all other properties from object leave only selected

I need to remove all array members that are not based on property given, here is example I have something like this

    const idToStay = ['1'];

    const objList = [{
        id: '1',
        name: 'aaa',
      },
      {
        id: '4',
        name: 'bbb',
      },
      {
        id: '7',
        name: 'ccc',
      },
    ];

I need to remove all others objects that does not have id with number 1, I know how to remove but how to stay and remove all others

Here I can remove like this

const filteredObjList = objList.filter(x => !idsToRemove.includes(x.id));

console.log(filteredObjList);

How to bind Child url with Main url in React js

your textStep-1: i want a link tag where if i will click that link tag the content/page will display below the link tag. The content will come from azure blob via a url (“https://docfxhtml.blob.core.windows.net/pocupload/index.html”)– This is the page i want to see after clcking a link tag.
enter image description here

Step-2: Once the output will come, there are few deep link is there(in the step 1 url). If i will click any menu from the this url(https://docfxhtml.blob.core.windows.net/pocupload/index.html) that url will bind with main url(http://localhost:3001/About) and url will look like below if i will click article from the above url and similarly if i will click any link from the blob url it will be change in main url.

e.g.http://localhost:3001/About/Article/pocupload/articles/docfx_getting_started.html

Note : I used below code and the output is coming like this after clicking on About link

Expecting is :

Once the output will come, there are few deep link is there(in the step 1 url). If i will click any menu from the this url(https://docfxhtml.blob.core.windows.net/pocupload/index.html) that url will bind with main url(http://localhost:3001/About) and url will look like below if i will click article from the above url and similarly if i will click any link from the blob url it will be change in main url.

How to send request to apollo graphql server while doing integration testing in jest?

This is my server file.
In context I am not getting the request while my test is getting pass while test the required scenario.

export async function buildTestServer({
  user,
  headers,
  roles,
}: {
  user?: User;
  headers?: { [key: string]: string };
  roles?: Role;
}) {
  const schema = await tq.buildSchema({
    authChecker: AuthChecker,
    validate: false,
    resolvers: allResolvers(),
    scalarsMap: [{ type: GraphQLScalarType, scalar: DateTimeResolver }],
  });
  const server = new ApolloServer({
    schema,
    context: async ({ req }) => {
      const authHeader = headers?.authorization;
      if (authHeader) {
        const token = extractTokenFromAuthenticationHeader(authHeader);
        try {
          const user = await new UserPermissionsService(token).call();
          return { req, user };
        } catch {
          return { req };
        }
      } else {
        if (user) {
          let capabilities: any = [];
          if (roles) {
            capabilities = roles.capabilities;
          }
          return {
            req,
            user: {
              id: user.id,
              customerId: user.customerId,
              capabilities,
            },
          };
        } else {
          return { req };
        }
      }
    },
  });

  return server;
}

And this is my test file from where I am sending the request to the server.
My test is getting passed but I am not getting the request headers. I want to check the the request. Can anybody help me out ?

const GET_LIST = `
query GetList($listId: String!) {
  GetList(listId: $listId) {
    id
  }
}
`;

test('Get Lists', async () => {
  const customer = await CustomerFactory.create();
  const user = await UserFactory.create({ customerId: customer.id });
  const list = await ListFactory.create({
    customerId: customer.id,
  });
  const server = await buildTestServer({ user });
  const result = await server.executeOperation({
    query: GET_LIST,
    variables: {
     listId: list.id
    },
  });
  var length = Object.keys(result.data?.GetList).length;
  expect(length).toBeGreaterThan(0);
});

How to return the difference value from array of objects?

Here is the item1 data:

const item1 = [
  {
   
    "proposedWaterClosets": 2,
    "proposedToilets": 3,
    "noOfWaterClosets": 3,
    "noOfToilets": 3
  },
  {
    
    "proposedWaterClosets": 2,
    "proposedToilets": 3,
    "noOfWaterClosets": 3,
    "noOfToilets": 2
  }
]

Here is the item2 data:

const item2 = {
    
    "proposedWaterClosets": 2,
    "proposedToilets": 3,
    "noOfWaterClosets": 3,
    "noOfToilets": 3
  }

I want the output to be like this which only return the difference value

expected output:

[{ "noOfToilets": 3 }]

Here I am having issue , I am getting which the value is same .. here is my approach using map and with the help of if condition, the thing is I am getting the output which is equal … Any suggestions would be appreciated

 const result = item1.map((it) => {
    if (it.noOfToilets !== item2.noOfToilets || it.noOfWaterClosets !== item2.noOfWaterClosets) {
      return { oldToilets: it.noOfToilets, oldWaterC: it.noOfWaterClosets };
    }
  });

getting output: [{oldToilets::2,oldWaterC:3}]

bundling typeScript with duplicated import

I am using LigerShark.WebOptimizer.Core package to minimize and bundle css and js files. I have two TypeScript files that import a common utility class. Each file has the declaration like below. At runtime the bundle has the Utility import Utility twice and causes runtime error. How can I resolve the duplicated import? Thanks.

import {Utility} from "./utility.js";

$(function() {
  .....
})
import { ICommonUtility } from "../appModels/ICommonUtility.js";

export class Utility implements ICommonUtility {
......
}
Identifier 'Utility' has already been declared

Display WordPress search results based on the selected Sub-Category

I’m trying to create a search using dropdowns in WordPress.

I’ve got two dropdowns, 1 – Parent Category and 1 – Sub-category.

The Sub-category will show automatically based on the selected Parent category.

My goal is to have the 2 dropdowns with a submit button and have it act as a search, displaying the selected sub-category’s posts on the results page.

I’ve got this far using research but I’m completely lost and struggling as you can see.
Below is my functions.php code and HTML that’s used for the search:

// FUNCTIONS.PHP

// Drop-down Ajax call

add_action('wp_ajax_my_special_action', 'my_action_callback');
add_action('wp_ajax_nopriv_my_special_action', 'my_action_callback');
function my_action_callback() {
    if(isset($_POST['main_catid'])) {
        $categories = get_categories('child_of='.$_POST['main_catid'].'&hide_empty=0');
        foreach ($categories as $cat) {
            $option .= '<option value="'.$cat->term_id.'">';
            $option .= $cat->cat_name;
            $option .= ' ('.$cat->category_count.')';
            $option .= '</option>';
        }
        echo '<option value="-1" selected="selected">Search...</option>'.$option;
        die();
    } // end if
}



// Define search for sub-category
function search_filter( $query ) {
    // only modify your custom search query.
    if ( $query->is_search &&  $_post['my_search'] == "c_search") {
        $args = array(
                'relation' => 'AND',
            array(
                'taxonomy' => 'category',
                'field' => 'id',
                'terms' => array( $_post['main_cat']),
                'operator' => 'IN'
            ),
            array(
                'taxonomy' => 'category',
                'field' => 'id',
                'terms' => array( $_post['sub_cat']),
                'operator' => 'IN'
            )
        );
        $query->set( 'tax_query', $args);
    }
    return $query;
}

// The hook needed to search_filter
add_filter( 'the_search_query','search_filter');
 <!-- BODY HTML CODE -->
<div id="content">

<!-- Search form-->
<form method="get" id="searchform" action="<?php bloginfo('url'); ?>/">
  <div>
    <input type="text" value="<?php the_search_query(); ?>" name="s" id="s" />
    <?php
wp_dropdown_categories('show_count=0&selected=-1&hierarchical=1&depth=1&hide_empty=0&exclude=1&show_option_none=Main Categories&name=main_cat');
?>
    <select name="sub_cat" id="sub_cat" enabled="disabled"></select>
    <input type="hidden" id="my_search" name="my_search" value="c_search" />
    <input type="submit" id="searchsubmit" value="search" />
  </div>
</form>


<!-- Dropdown Ajax call script -->
<script type="text/javascript">
    jQuery(function() {
      jQuery('#main_cat').change(function() {
        var $mainCat = jQuery('#main_cat').val();

        // call ajax
        jQuery("#sub_cat").empty();
        jQuery.ajax({
          url: "https://testdev.co.za/test/macadams_new/wp-admin/admin-ajax.php",
          type: 'POST',
          data: 'action=my_special_action&main_catid=' + $mainCat,

          success: function(results) {
            //  alert(results);
            jQuery("#sub_cat").removeAttr("disabled");
            jQuery("#sub_cat").append(results);
          }
        });
      });
    });
</script>

</div>

Compare custome range in javascript

Is there any way to check range in javascript.
The range can be anything like eg. “a-z”,”1-9″,”aa-zz”,”11-99″,”a1-z9″,”rc1-rc9″

I have try this.
So i make a dynamic regex on it.
for eg. i have range of “rc1-rc9” than my regex becomes like “^[r-r][c-c][1-9]$”,
i have range of “rc1-rc50” than my regex becomes like “^[r-r][c-c][1-50]$”

  1. new RegExp('^[1-99]$').test(27) // false - i want it to be true
  2. new RegExp('^[1-9]$').test(2) // true

Display tool tip on condition

Change the tooltip text when a condition is true, at first displaying default tooltip text but once the changeToolTip function condition is true, change the text.

class Modal extends Component {
  constructor() {
    super();
    this.state = {
      show: false
    };
    this.showModal = this.showModal.bind(this);
    this.hideModal = this.hideModal.bind(this);
  }

  showModal = () => {
    this.setState({ show: true });
  };

  hideModal = () => {
    this.setState({ show: false });
  };

  changeToolTip(){
    if(sessionStorage.getItem("searchData") == null){
      //change tooltip text 
    }
  }
  

  render() {
    return (
      <div>
        <Modal show={this.state.show} handleClose={this.hideModal}  />
        <div data-toggle="tooltip"
          data-class="search-tool-tip"
          data-tip="this is before tooltip"
          data-place="left" type="button" onClick={this.showModal}> 
        </div>
      </div>
    );
  }

}