How to change dynamically path color in Cesium Viewer

I want to dynamically change the color of my gps path that I put in a czml file depending on the speed of my path. 0% speed = blue, 100%= red.My path which is fixed in blue

Here is my code which displays the viewer :

var viewer = new Cesium.Viewer("cesiumContainer", { terrainProvider: Cesium.createWorldTerrain(), baseLayerPicker: false, shouldAnimate: true, });
viewer.dataSources.add(Cesium.CzmlDataSource.load(tabToCzml)).then(function (ds) {
            viewer.trackedEntity = ds.entities.getById("path");
        });

Currently the color of the path is defined in the czml file as :

"path": { "material": { "polylineOutline": { "color": { "rgba": [255, 255, 255, 200] }, "outlineColor": { "rgba": [0, 173, 253, 200] }, "outlineWidth": 5 } }, "width": 6, "leadTime": 0, "trailTime": 100000, "resolution": 5 } }

How to show options from flexdatalist plugin

I’m new to using the flexdatalist javascript plugin.
What I am trying to do is to display the content of the datalist when a value is set by default on the input like viewing all options as soon as entering the page.
By typing characters in the input, the change event is correctly triggered but when i set a default value on the input, even if the datalist has options it doesn’t show anything.

This is the flexdalist initialization:

$('#search').flexdatalist({
    "noResultsText": 'No result for "{keyword}"'
});

Is there a way to show the datalist using javascript or jquery?

Importing and using vanila JS functions in React component

I am very new to react.js and JavaScript, so apologies in advance. I’m trying to integrate https://diagrams.net into other webpage using the file that’s directly given by diagrams.net here:

https://github.com/jgraph/drawio-integration/blob/master/diagram-editor.js?fbclid=IwAR1FMViVLW3Tba8RqMOUJtv16vIvPPycLYyu4rEtRTbuhbyztlrLXu5UyHo.

So as it can be seen in this example here: http://jgraph.github.io/drawio-integration/javascript.html, when the user double clicks on the diagram, they should be redirected to diagrams.net web and draw their own diagram.

The problem is that my web is currently built on React, and all the diagrams.net is built on vanilla JS. By inspecting the example above, they apparently use:

<img 
style="cursor:pointer;" 
title="Click to edit image" 
onclick="DiagramEditor.editElement(this);" 
src="data:image/png;base64,iVBORw0...

in the HTML to display the image of the diagram. I’ve tried to change it to react-like by changing it to:

<img alt="Click to edit image" 
onClick={EditDiagram.DiagramEditor.editElement(this)}
src="data:image/png;base64,iVBORw0..."/>

and importing the JavaScript file by import * as EditDiagram from "../components/workarea/workarea-diagram-editor";, but it is returning TypeError: Cannot read properties of undefined (reading 'editElement').

I’ve also tried using dangerouslySetInnerHTML like this:

<div
dangerouslySetInnerHTML={{
__html:
"<img style='cursor:pointer;' 
title='Click to edit image' onclick='DiagramEditor.editElement(this);' 
src='data:image/png;base64,iVBORw0...'/>",
}}/>

but this way, that DiagramEditor.editElement(this) cannot be accessed that way.

I’ve been trying to get this to work for past 12 hours, but just can’t get it to work. Is there any way to make this work?

Thank you so much.

Below is the React code that the JavaScript is being added on.

const WorkArea = () => {
  const router = useRouter();
  const formik = useFormik({
    initialValues: {
      scenario: "This is scenario",
    },
    validationSchema: Yup.object({
      scenario: Yup.string().max(255).required("Scenario is required"),
    }),
    onSubmit: () => {
      router.push("/");
    },
  });

  const [countList, setCountList] = useState([0]);
  //   const [inputList, setInputList] = useState([]);

  const AddScenario = () => {
    let countArr = [...countList];
    let counter = countArr.slice(-1)[0];
    counter++;
    countArr.push(counter);
    setCountList(countArr);
  };

  const DeleteScenario = () => {
    let countArr = [...countList];
    let counter = countArr.slice(-1)[0];
    counter--;
    countArr.pop(counter);
    setCountList(countArr);
  };

  //   const onAddBtnClick = (event) => {
  //     setInputList(inputList.concat(<SetScenario key={inputList.length} />));
  //   };

  return (
    <>
      <Head>
        <title>Work Area | Cybersecurity Requirements Generator</title>
      </Head>
      <Box
        component="main"
        sx={{
          alignItems: "center",
          display: "flex",
          flexGrow: 1,
          minHeight: "100%",
        }}
      >
        <Container maxWidth="xl">
          <NextLink href="/projects" passHref>
            <Button component="a" startIcon={<ArrowBackIcon fontSize="small" />}>
              Back to Projects
            </Button>
          </NextLink>
          <form onSubmit={formik.handleSubmit}>
            <Box sx={{ my: 3 }}>
              <Typography color="textPrimary" variant="h4">
                Use Case Diagram
              </Typography>
              <Typography color="textSecondary" gutterBottom variant="body2">
                Make your own diagram!
              </Typography>
            </Box>

            <Box
              sx={{
                py: 2,
              }}
            >
              {/* <div
                dangerouslySetInnerHTML={{
                  __html:
                    "<img style='cursor:pointer;' title='Click to edit image' onclick='DiagramEditor.editElement(this);' src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHkAAAA9CAYAAACJM8YzAAADT3RFWHRteGZpbGUAJTNDbXhmaWxlJTIwaG9zdCUzRCUyMmVtYmVkLmRpYWdyYW1zLm5ldCUyMiUyMG1vZGlmaWVkJTNEJTIyMjAyMS0wMS0xMVQxMCUzQTQxJTNBMzQuMjQ4WiUyMiUyMGFnZW50JTNEJTIyNS4wJTIwKE1hY2ludG9zaCUzQiUyMEludGVsJTIwTWFjJTIwT1MlMjBYJTIwMTFfMV8wKSUyMEFwcGxlV2ViS2l0JTJGNTM3LjM2JTIwKEtIVE1MJTJDJTIwbGlrZSUyMEdlY2tvKSUyMENocm9tZSUyRjg3LjAuNDI4MC44OCUyMFNhZmFyaSUyRjUzNy4zNiUyMiUyMGV0YWclM0QlMjJtNXI1QVhFdDE3eWx2WWlEWXo5UyUyMiUyMHZlcnNpb24lM0QlMjIxNC4xLjklMjIlMjB0eXBlJTNEJTIyZW1iZWQlMjIlM0UlM0NkaWFncmFtJTIwaWQlM0QlMjJlbVlSU0REUmtEUDJZZDNFWnkzciUyMiUyMG5hbWUlM0QlMjJQYWdlLTElMjIlM0VqWkxOVG9Rd0VJQ2ZwbGV6MEloNkZkZjE0Z2tUejVXT3ROblNrbElXOE9sdDdWUm9OaVplWU9hYjZmd1RXdmZMeWJKQnZCb09pcFFIdmhENlJNcXlxS283JTJGd3RramVTV1BrVFFXY2tqT215Z2tWJTJCQUx4T2RKSWNSV1VUT0dPWGtrTVBXYUEydHl4aXoxc3k1MjZkUmVkYUJkWkI1Qk5DMFRGM1RkOG1kaVBTJTJCckRiJTJCQXJJVEtYTlJZWDhmckQxMzFrd2E4Mm1qSVZwNmxzSmdEYU5nM013N1JJJTJCRTF0WVlGNlYlMkJxVUdGc2VZVGUlMkY3RGlpV1BiazFOcEZvdGFQZXZDS21KQz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hITg8ePHWFpaQm9vLzIzM8WiffjwIV6+fImkpCT8/PlTzKkc7+bmpimrY/c/dZBXVlZgaGgojLx586YwTgktLS0N1tbWKCgoQGRkpDBubW0Nly5dOhSyuv3HxsZE+jw9PfHt2zcBmdJM193f9m+3BCsrKwtTU1NQKBQizXSczMzMIDU1Fe/evUNZWRkcHR3x9u1bENTOzs4TbffHpXyqINN2rTy337x5gytXrohXPJSQy8vLhbG0RVIjEJR4BweHQyGr25+KPToK6JgwMjISc9Eu8TvIlGA6Kn5ttCucPXsW4eHhAq6trS1iY2Nx9+7dE5/pOgF5f3V9GGQCSom7cOEC+vr6BAT6uaqq6lDI6vYnCJQ8OkNppwgLCxMJ/B3k5ORkvHr1Cj09PeLam5ubGBkZgYeHBz5+/IiLFy/ix48faGhoQExMjCgsx8fHOcn/BpkqW29vbwwNDYmEEAQqwJqamg6FrG7/gIAAAYWOgcHBQXENGpuSkqIyb3Nzs6gX6HGwq6tLFFuvX78WYKlQe/LkifiOzmhnZ2fQQlheXhbFGM07PT29N54mpp3gxo0bQsufbKdqu/4dZHrGpOdkSlldXZ2ovmlbfP78Oby8vA5A1qR/W1ubAEONCjt6vCMAtJhcXFz25iZIrq6u4rp0BtOWTsUgNbqf6upqXL16VRSL9Knc+umeS0pKBGTleJrbwMAALS0tuH79+p9k/P98q5EAbmxsHDiLj3JKnf70HE4QbGxsRCG1sLAAU1NTlccomp8esajYUwKkflRH2Nvb48yZM3u3QAUj/QHHzs5OFJLK9uv4P0r378n/kyRrQxhf4x8HGLIEq4EhM2QJHJBAIieZIUvggAQSOckMWQIHJJDISWbIEjgggUROMkOWwAEJJHKSGbIEDkggkZPMkCVwQAKJnGSGLIEDEkjkJDNkCRyQQCInmSFL4IAEEjnJDFkCBySQqJJkCfRKK1GhUOz+BbaftLWDFNYjAAAAAElFTkSuQmCC'/>",
                }}
              /> */}

              <img
                alt="Click to edit image"
                onClick={EditDiagram.DiagramEditor.editElement(this)}
                src="data:image/png;base64,iVBORw0KGg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RkpDBubW0Nly5dOhSyuv3HxsZE+jw9PfHt2zcBmdJM193f9m+3BCsrKwtTU1NQKBQizXSczMzMIDU1Fe/evUNZWRkcHR3x9u1bENTOzs4TbffHpXyqINN2rTy337x5gytXrohXPJSQy8vLhbG0RVIjEJR4BweHQyGr25+KPToK6JgwMjISc9Eu8TvIlGA6Kn5ttCucPXsW4eHhAq6trS1iY2Nx9+7dE5/pOgF5f3V9GGQCSom7cOEC+vr6BAT6uaqq6lDI6vYnCJQ8OkNppwgLCxMJ/B3k5ORkvHr1Cj09PeLam5ubGBkZgYeHBz5+/IiLFy/ix48faGhoQExMjCgsx8fHOcn/BpkqW29vbwwNDYmEEAQqwJqamg6FrG7/gIAAAYWOgcHBQXENGpuSkqIyb3Nzs6gX6HGwq6tLFFuvX78WYKlQe/LkifiOzmhnZ2fQQlheXhbFGM07PT29N54mpp3gxo0bQsufbKdqu/4dZHrGpOdkSlldXZ2ovmlbfP78Oby8vA5A1qR/W1ubAEONCjt6vCMAtJhcXFz25iZIrq6u4rp0BtOWTsUgNbqf6upqXL16VRSL9Knc+umeS0pKBGTleJrbwMAALS0tuH79+p9k/P98q5EAbmxsHDiLj3JKnf70HE4QbGxsRCG1sLAAU1NTlccomp8esajYUwKkflRH2Nvb48yZM3u3QAUj/QHHzs5OFJLK9uv4P0r378n/kyRrQxhf4x8HGLIEq4EhM2QJHJBAIieZIUvggAQSOckMWQIHJJDISWbIEjgggUROMkOWwAEJJHKSGbIEDkggkZPMkCVwQAKJnGSGLIEDEkjkJDNkCRyQQCInmSFL4IAEEjnJDFkCBySQqJJkCfRKK1GhUOz+BbaftLWDFNYjAAAAAElFTkSuQmCC"
              />

              {/* <Tester /> */}
            </Box>
            <Box sx={{ my: 3 }}>
              <Typography color="textPrimary" variant="h4">
                Scenario
              </Typography>
              <Typography color="textSecondary" gutterBottom variant="body2">
                Enter scenarios
              </Typography>
            </Box>

            <SetScenario countList={countList} />
            <Box
              sx={{
                alignItems: "center",
                display: "flex",
                ml: -1,
              }}
            ></Box>
            {Boolean(formik.touched.policy && formik.errors.policy) && (
              <FormHelperText error>{formik.errors.policy}</FormHelperText>
            )}
            <Box
              sx={{
                py: 2,
                display: "flex",
                justifyContent: "flex-end",
                justifyContent: "space-between",
              }}
            >
              <Box>
                <Button
                  color="primary"
                  disabled={formik.isSubmitting}
                  size="large"
                  variant="contained"
                  onClick={AddScenario}
                  sx={{
                    marginRight: 1,
                  }}
                >
                  Add Row
                </Button>
                <Button
                  color="primary"
                  disabled={formik.isSubmitting}
                  size="large"
                  variant="contained"
                  onClick={DeleteScenario}
                >
                  Delete Row
                </Button>
              </Box>

              <NextLink href="/requirements" passHref>
                <Button
                  color="primary"
                  disabled={formik.isSubmitting}
                  size="large"
                  type="submit"
                  variant="contained"
                >
                  Submit
                </Button>
              </NextLink>
            </Box>
          </form>
        </Container>
      </Box>
    </>
  );
};

WorkArea.getLayout = (page) => <DashboardLayout>{page}</DashboardLayout>;
export default WorkArea;

Get location redirect url from jquery ajax statuscode 401

I currently have the below code and need to get the location parameter to redirect to. How do I grab it with the statusCode setup?

Ajax Call

$.ajax({
                url: url,
                data: (def.data ? (def.convertToJson ? JSON.stringify(def.data) : def.data) : ''),
                type: def.type,
                dataType: def.dataType,
                cache: def.cache,
                contentType: def.contentType,
                statusCode: {
 401: function (response) {
                        debugger
                        window.location = GET LOCATION URL FROM RESPONSE
                    }}

Response Parameter

response.getAllResponseHeaders()

‘access-control-allow-headers: Origin, X-Requested-With, Content-Type,
Acceptrnaccess-control-allow-origin: *rncache-control:
privaterncontent-length: 58rncontent-type: text/htmlrndate: Mon,
06 Dec 2021 16:51:23 GMTrnlocation:
https://localhost:44360/store?storeorganizationid=24917#/login?returnurl=https%3a%2f%2flocalhost%3a44360%2fstore%2faccount%3fstoreorganizationid%3d24917%26_%3d1638809474810rnserver:
Microsoft-IIS/10.0rnx-aspnet-version:
4.0.30319rnx-aspnetmvc-version: 5.2rnx-exposure-server: EastUS2rnx-exposure-sport: Basketballrnx-powered-by:
ASP.NETrnx-sourcefiles:
=?UTF-8?B?RjpcTXkgV2Vic1xCYXNrZXRiYWxsVG91cm5hbWVudHNcTmV3UmVnaXN0cmF0aW9uXFdlYnNpdGVzXFRvdXJuYW1lbnRzXHN0b3JlXGFjY291bnQ=?=rnx-ua-compatible:
IE=Edge,chrome=1rn’

Text nodes vs Text nodes within Elements – Why do some come with quotes in Chrome

I am trying to produce a match to the output from Chrome Devtools (Elements) view, but I can’t see why some elements on the Chrome view read <P>Lorem ipsum</P> and some read <P>"Lorem Ipsum"</P> as both are text nodes within an element.

I have a demonstrator that shows the problem (both coming out as quoted – see Lorem1 and Lorem5)

var _TAG = 1;
var _TEXT = 3;
var _COMMENT = 8;
// ----------------------------------------------------------
function dge(id) {
  return document.getElementById(id);
}
// ----------------------------------------------------------
function getVisibleHTML(tx) {
  return tx.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
}
// ----------------------------------------------------------
function getTracePart(node) {
  if (node.nodeType == _TEXT) {
    if (node.nodeValue.trim() != '') return '<text>&quot;' + node.nodeValue + '&quot;</text>';
    else return '';
  }
  if (node.nodeType == _TAG) return getVisibleHTML(node.outerHTML);
  if (node.nodeType == _COMMENT) return '<BR><comment>&lt;--' + (node.nodeValue) + '--&gt;</comment><BR>';
  return 'NODE TYPE ' + node.nodeType;
}
// ----------------------------------------------------------
function write(tx) {
  dge('trace').innerHTML += tx;
}
// ----------------------------------------------------------
function doWalkTree(container) {
  for (var c = 0; c < container.childNodes.length; c++) {
    var child = container.childNodes[c];
    if (child.nodeType == _TAG) {
      write('<BR>&lt;' + child.tagName + '&gt;');
      doWalkTree(child);
      if (child.tagName != 'BR') write('&lt;/' + child.tagName + '&gt;');
      write('<BR>');
    } else write(getTracePart(child));
  }
}
// ----------------------------------------------------------

doWalkTree(dge('test'));
div,p, ul {
    border:solid 1px red;
    margin:10px;
    padding:10px;
}
span {
    border-radius:9px;
    padding:2px 8px 2px 8px;
    margin:5px;
    background-color:#e9e9e9;
    display:inline-block;
}
text {
   color:#77c592;
}
comment {
    color:#8facdd;
}
<div id='test'>

  <p>Lorem1 ipsum <b>dolor</b></p>

  <br>Lorem2 ipsum dolor

  <p><!--test-->Lorem3 ipsum dolor</p>

  Lorem4 ipsum dolor
  
  <p>Lorem5 ipsum dolor</p>
</div>

<hr>

<h5>Post Normalized result trace....</h5>
<div id='trace'></div>

I also have a demo running on jsfiddle (https://jsfiddle.net/Abeeee/3ts74boa/95/) but any assistance would be great.

Thanks

Typeerror: cannot set property “password” of null

having some trouble figuring out why I get this error.
I have tried changing syntax but dont get it right, please help.
I think this is just a syntaxerror.

this is how i send my data

const data = { newPassword : newPassword }

const response = await request({ endpoint: `blablabla`, method: "PUT", body: data }

this is how i receive the data

const {newPassword}  = req.body; 

if(token && newPassword) {
    console.log("token and password exist");
    User.findOne({token: token}).then(user=> {
        console.log("password" + newPassword); //prints out correct password
        user.password = newPassword;
        user.usertoken = "";
        user.save(function(err){
          if(err)return next(err);
          else res.json({message:"Password changed",result:true})
        });
      
    }).catch(next)
  }
  else {
    res.status(400).json({message:"Missing information! The password could not be updated.",result:false})
  }

Compare 2 Arrays of Objects

I want to compare 2 Arrays of Objects to find the object or objects which is not matched.
In the example below it should output {label: 'Addition', type: 'address', name: 'address_4', defaultValue: 'test'} as this Object is not matched.

const A = [{
    label: 'Street Name',
    type: 'address',
    name: 'address_1',
    defaultValue: 'test1'
  },
  {
    label: 'House Number',
    type: 'address',
    name: 'address_2',
    defaultValue: '1563l1'
  },
  {
    label: 'Addition',
    type: 'address',
    name: 'address_3',
    defaultValue: 'ABC684'
  }
]

const B = [{
    label: 'Street Name',
    type: 'address',
    name: 'address_1',
    defaultValue: 'test1'
  },
  {
    label: 'House Number',
    type: 'address',
    name: 'address_2',
    defaultValue: '1563l1'
  },
  {
    label: 'Addition',
    type: 'address',
    name: 'address_3',
    defaultValue: 'ABC684'
  },
  {
    label: 'Addition',
    type: 'address',
    name: 'address_4',
    defaultValue: 'test'
  }
]

let difference = currentSet.filter((page1) => !newSet.find(page2 => page1.name === page2.name))

This does not work. It outputs an empty Array. What I’m doing wrong?

How to enable bulk amount of option values in html selection drop down box?

Does anyone know a way to enable all the times in this selection box without having to go through them with “document.getElementById”. There are about 30 of these, for all the times.

In the live code, the option values (times) can be disabled depending on a date selection, so at the start of the function (onchange event) it enables them all for use again (and disables per date selected).

<select name="time" id="time">
<option value="N/A">Select</option>
<option value="12:00pm" id="12:00pm">12:00pm</option>
<option value="12:15pm" id="12:15pm">12:15pm</option>
<option value="12:30pm" id="12:30pm">12:30pm</option>
<option value="12:45pm" id="12:45pm">12:45pm</option>
<option value="13:00pm" id="13:00pm">13:00pm</option>
<option value="13:15pm" id="13:15pm">13:15pm</option>
<option value="13:30pm" id="13:30pm">13:30pm</option>
<option value="13:45pm" id="13:45pm">13:45pm</option>
<option value="14:00pm" id="14:00pm">14:00pm</option>
</select>

<script>
var select = document.getElementById('date');
select.onchange = SetClosed;
window.onload = SetClosed;

function SetClosed(){
document.getElementById("12:00pm").disabled = false;
document.getElementById("12:15pm").disabled = false;
document.getElementById("12:30pm").disabled = false;
document.getElementById("12:45pm").disabled = false;
document.getElementById("13:00pm").disabled = false;
document.getElementById("13:15pm").disabled = false;
document.getElementById("13:30pm").disabled = false;
document.getElementById("13:45pm").disabled = false;
document.getElementById("14:00pm").disabled = false;
}
</script>

i have tried this to replace the large amounts of “getElementById”, but no joy:

document.querySelectorAll('input[name="time"]').forEach(element => {element.removeAttribute("disabled");});

The code works using ID’s of course, but was hoping there could be a way to reduce the code down a bit.

YAML multi line scalars in JSON.stringify with TypeScript

I have a YAML document I’m trying to convert to Pulumi which makes liberal use of multi-line scalar values. Here’s an example:

apiVersion: secrets-store.csi.x-k8s.io/v1
kind: SecretProviderClass
metadata:
  name: azure-secrets
spec:
  provider: azure
  parameters:
    usePodIdentity: "false"
    keyvaultName: "kvname"
    cloudName: ""
    objects:  |
      array:
        - |
          objectName: secret1
          objectType: secret                    # object types: secret, key or cert
    tenantId: "tid"

Note the usage of scalars and a nested yaml pattern for the objects key.

I’m currently manually constructing this pattern like so:

objects: `array:n  - |n    objectName: $CERT_NAMEn    objectType: secretn`,

Which will manually build the correct YAML format, but I’d like to use JSON.stringify to construct this instead so I don’t have to manually build the strings. Is there a way to do it?

How to run a script outside the src folder in react?

My directory is as such:

├Script.js
|
├public/
|     └...
└src/
   └ App.js

and inside App.js I’m trying to invoke the Script.js as such:

import calculations from './../Script' 

...

onclick={()=>{calculations()}}

Script.js:

const calculations=()=>{...}

export default calculations;

but obviously it won’t work, so how do I run a script on the server?
do I make a post request to the server? If so, how do I handle it? (like in express app.post())

How to add anchors to url based on which project in viewport

How can I add / change the #anchor in the url depending on to which project I scrolled?

So, when I scroll over the projects on my one-pager, I want the URL to change dynamically:

www.likethis.com#project-1
www.likethis.com#project-2
www.likethis.com#project-3

In the end, I want to be able to share URLs which link directly to projects on the page.

Everything I found so far is something like “data-url” or setting an article to “active”?

nested select option php mysql jquery

I have an edit form modal with 3 input : name(text), category(select option), subcategory(select option)

I want the subcategory options updated when the category selection is changed. I have done this nested select option on the modal add before, and it works. But it doesn’t work when I’m trying to do the same at the edit modal. The Subcategory select option only displaying the subcategory’s value of the first row when I clicked the first row edit button. When I clicked the other row’s edit button, the subcategory select option in the form didn’t show anything.

On the add modal, I’m using jquery to set the subcategory value when category changed using .change event and make a request to get the subcategory data then I add and also set the id and the text from the subcategory data. Is there a way so the list of subcategory’s option in the edit form modal could be changed by the selected category? And should it using JS or there is any other simple way?

Here is the code

<!-- Table & Modal-->
<div class="table-responsive">
  <table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
    <thead>
      <tr>
        <th>No</th>
        <th>Name</th>
        <th>Category</th>
        <th>Subcategory</th>
        <th>Action</th>
      </tr>
    </thead>
    <tbody>
      <?php $ambilsemuadatastock = mysqli_query($conn, "SELECT n.idname, n.name, c.category, sc.category AS subcategory from name b JOIN category k ON n.idcategory = c.idcategory JOIN category sk ON n.idsubcategory=sc.idcategory");
      $i = 1;
      while ($data = mysqli_fetch_array($ambilsemuadatastock)) {
        $idname = $data['idname'];
        $name = $data['name'];
        $category = $data['category'];
        $subcategory = $data['subcategory'];
      ?>

        <tr>
          <td><?php echo $i++; ?></td>
          <td><?php echo $name; ?></td>
          <td><?php echo $category; ?></td>
          <td><?php echo $subcategory; ?></td>
          <td>
            <button type="button" class="btn btn-warning" data-toggle="modal" data-target="#edit<?= $idname; ?>">Edit</button>
            <button type="button" class="btn btn-danger" data-toggle="modal" data-target="#delete<?= $idname; ?>">Delete</button>
          </td>
        </tr>

        <!-- The Edit Modal -->
        <div class="modal fade modal-editname" id="edit<?= $idname; ?>">
          <div class="modal-dialog">
            <div class="modal-content">

              <!-- Modal Header -->
              <div class="modal-header">
                <h4 class="modal-title">Edit</h4>
                <button type="button" class="close" data-dismiss="modal">&times;</button>
              </div>

              <!-- Modal body -->
              <form method="POST">
                <div class="modal-body">
                  <?php
                  $allcategory = mysqli_query($conn, "SELECT * FROM category WHERE parentcategory = 0");

                  $getdtname = mysqli_query($conn, "SELECT n.idname, n.name, n.idcategory, c.category, n.idsubcategory, sc.category AS subcategory, n.stock from name b JOIN category k ON n.idcategory = c.idcategory JOIN category sk ON n.idsubcategory=sc.idcategory WHERE idname = ('$idname')");

                  while ($dtname = mysqli_fetch_array($getdtname)) {
                  ?>
                    <input type="text" id="nameedit" name="name" value="<?= $dtname['name']?>" class="form-control" required>
                    <br>
                    <select class="form-control" id="selopcatedit" name="category">
                      <?php foreach ($allcategory as $cat) { ?>
                        <option <?php if ($cat['idcategory'] == $dtname['idcategory']) {
                                  echo "selected="selected"";
                                } ?> value="<?= $cat['idcategory']; ?>">
                          <?= $cat['category']; ?>
                        </option>
                      <?php } ?>
                    </select>
                    <br>
                    <select class="form-control" id="selopsubcatedit" name="subcategory">
                      <option value="">Choose Subcategory</option>
                    </select>
                    <br>
                    <input type="hidden" id="idnameedit" name="idname" value="<?= $dtname['name']?>">
                  <?php
                  }
                  ?>
                  <button type="submit" class="btn btn-primary" name="updatename">Edit</button>
                </div>
              </form>

            </div>
          </div>
        </div>
      <?php
      }
      ?>

    </tbody>
  </table>
</div>

Here is the JS

<!-- JS -->
<script>
  $("#selopcatedit").change(function() {
    var parentcat = $(this).val();
    console.log(parentcat);

    $.ajax({
      url: 'getCatValue.php',
      type: 'post',
      data: {
        parentcat: parentcat
      },
      dataType: 'json',
      success: function(response) {
        var len = response.length;
        console.log(response);

        $("#selopsubcatedit").empty();
        for (var i = 0; i < len; i++) {
          var idcategory = response[i]['idcategory'];
          var category = response[i]['category'];

          $("#selopsubcatedit").append("<option value='" + idcategory + "'>" + category + "</option>");
        }
      },
      error: function(req, err) {
        console.log('my message : ' + err);
      }
    });
  });
</script>

I also make an event when the modal is showed, to do the same thing like the event change script above (set the subcategory’s value).

I want to run a JavaScript code synchronously in react native

I’m working in a project where I retrieve data from local database using SQLite then I process the data and finally I use the processed data in a calculation method.

The problem is that the code is running asynchronously so when I call the calculation method in the first time it works before the retrieve and processing methods it only works in the second or third run.

I have 4 retrieve methods :

    retrieve1();
    retrieve2();
    retrieve3();
    retrieve4();

then I want to process the retrieved data so I have the following methods:

processRetrieve1();
processRetrieve2();
processRetrieve3();
processRetrieve4();

finally I want to call the calculation method:

Calculate();

How can I run this code in the following order?
Retrieve methods -> Processing methods -> Calculating method

How to merge 2 objects based on a property value to create new object?

Please see raw dataset below:

[
    {
        "date": "2021-12-03",
        "minutes": 132.00001,
        "category": "RSVR"
    },
    {
        "date": "2021-12-03",
        "minutes": 4.95,
        "category": "DMND"
    },
    {
        "date": "2021-12-03",
        "minutes": 127.03218,
        "category": "SLIP"
    },
    {
        "date": "2021-12-04",
        "minutes": 113.97533,
        "category": "SLIP"
    },
    {
        "date": "2021-12-04",
        "minutes": 11.55,
        "category": "DMND"
    },
    {
        "date": "2021-12-04",
        "minutes": 105.30001,
        "category": "RSVR"
    }
]

Expected:
would like generate new array where:

  • objects with category: 'DMND' are added as it is
  • new object is created using structure (example of new object provided below):
    • {
        date: unique date from the objects with  category: 'RSVR' and category: 'SLIP'
        minutes: add minutes from category: 'RSVR' and category: 'SLIP'
        category: 'SPLY'
      }
      
      Example
      
      {
        "date": "2021-12-03",
        "minutes": 132.00001,
        "category": "RSVR"                                 {
      },                                                     "date": "2021-12-03",
      {                                            =         "minutes": 259.03219,
        "date": "2021-12-03",                                "category": "SPLY"
        "minutes": 127.03218,                              }
        "category": "SLIP"
      }
      

    (basically merging 2 objects with category: 'RSVR' and category: 'SLIP' by adding their minutes to create a new object and add that new object to the array)

New array will look like this:
[
    {
        "date": "2021-12-03",
        "minutes": 4.95,
        "category": "DMND"
    },
    {
        "date": "2021-12-03",
        "minutes": 259.03219,
        "category": "SPLY"
    },
    {
        "date": "2021-12-04",
        "minutes": 11.55,
        "category": "DMND"
    },
    {
        "date": "2021-12-04",
        "minutes": 219.275331,
        "category": "SPLY"
    }
]

Not quite sure how to go about doing this yet. any help would be appreciated

i have this error :exceeded maximum execution time (line 0)?

I call the api to search into the json based on skus ,the user will put the sku and the start time ,dthen the function will bee count how many orders we have for this sku on this day

This is my code:

// to call the page 
    function firstCall(pag,start){
    
    
      try{

    var url ='https://*****************************?Page=' + pag + '&shopId%5B%5D=90841&pageSize=250' + '&' + 'minOrderDate='+ start;
        var res =UrlFetchApp.fetch(url);
        var content = res.getContentText();
        
        var json= JSON.parse(content);
       
    var node = json.data;
    
     return node;
    
    
      }
      catch(err){
          return "Error getting data" + err;
      }
    }
    
    //to count how many order per day and per sku
    function getInven3(sKu,start){
     if(start == "")  return "!";
     start ="2021-11-17T";
    
      try{
        
    
    
          var url ='https://*********************************?shopId%5B%5D=90841&pageSize=250' + '&' + 'minOrderDate='+ start;
    
        var res = UrlFetchApp.fetch(url);
        var content = res.getContentText();
        var json = JSON.parse(content);
    
    
      var count =0 ;
      var count_tow =0 ;
    
    
      if (json.paging.TotalPages===1){
     for (var i=0; i<firstCall(1,start).length; i++) {
      if(firstCall(1,start)[i].state == 7){
      for (var j=0; j<firstCall(1,start)[i].orderItems.length; j++) {
        var node3=firstCall(1,start)[i].orderItems[j].product.sku;
    
    
     if ((node3 == sKu)) {
         
       
     count++;
    
     } 
       
     }
     
     
      }
      
     }
     return count;
        
      
    
    
      
     
    
    
      }
     else  if (json.paging.TotalPages>1)
                    {
                      console.log("2 page");
    var d=0;
    for (var x = 0, ln = json.paging.TotalPages; x < ln; x++) {
    
    
    
      d++;
      if(d<=json.paging.TotalPages){
    
                                               
                     
        for (var i=0; i<firstCall(d,start).length; i++) {
       
      
      if(firstCall(d,start)[i].state == 7){
      for (var j=0; j<firstCall(d,start)[i].orderItems.length; j++) {
        var node3=firstCall(d,start)[i].orderItems[j].product.sku;
    
      
    
     if ((node3 == sKu)) {
            
       
      count_tow++;
    
       
       
     }
     
     
      }
       
     
    
        
      }
      
      }
    
      }
     }
        return count_tow;
      }
      }
      catch(err){
          return "Error getting data" + err;
      }
    }
    

Error messages keep saying “Exceeded maximum execution time (line 0).”

Could anyone help? Thank you a lot!