How to sync a computed property from child component to parent component in Vue?

I am learning vue and trying to propagate a value of an input component to the parent. in the real code, this is a text field with autocomplete suggestion. But for this question I have much simpler example.

Here is a simple component that counts how many times you clicked it:

const UpdateParentTest = {
    data()  {
        return {
            lastClickCount: 0
        }
    },
    methods: { 
        //When one of the suggestion is clicked
        clicked() {
            this.lastClickCount++;
            console.log("Clicked, new count: ", this.lastClickCount);
            this.updateClicks();
        },
        updateClicks() {
            console.log("Emit update:lastClickCount with: ", this.lastClickCount);
            this.$emit('update:lastClickCount', this.lastClickCount);
        },
    },
    computed: {
        computedClickCount() {
            return this.lastClickCount;
        }
    },
    watch: {
        computedClickCount(newVal) {
            console.log("Update click count: ", newVal);
            this.lastClickCount = newVal;
        }
    },
    template: "<span @click="clicked()">Clicks in child: {{computedClickCount}}</span>"
};

export default UpdateParentTest;

Note that even though I could use the lastClickCount, in real life there will usually be some kind of post-processing on the value, and thus I will always want to bind to the computed wrapper.

Here’s how I embed it into an app:

import UpdateParentTest from "./UpdateParentTest.js";
const app = {
  data() {
    return {
      boundClickCount: -1
    };
  },
  template: "#vue-select-station-template",
  components: {"updateparenttest": UpdateParentTest},
  computed: {
    calculatedClickCount() {
      if(this.boundClickCount < 0) {
        return "no click updates";
      }
      else {
        return this.boundClickCount.toString();
      }
    }
  }
};

const vueApp = vue_core.createApp(app);
vueApp.mount('#vue-app');

Using this HTML:

<template id="vue-select-station-template">
<div class="form-like">
  <div>
    Click count parent: {{calculatedClickCount}}
  </div>
  <div>
    <UpdateParentTest :computed-click-count.sync="boundClickCount"></UpdateParentTest>
  </div>
</div>
</template>

Once again, computed wrapper is used, here to determine if the value is valid. However, testing this code I get no updates in the parent. How to get it to work so I can recursively propagate changes from nested components to the main app?

d3.js pie chart replace an existing slice with multiple subslices

I’m trying to create a pie chart using d3js. When you click on a slice, an ajax is sent to the server and retrieve the children of the slice. The children always have a value which the sum is the value of the parent. I could use a zoomable sunburst, but I want only one level visible at all time, which to me is more of a pie chart than a sunburst.

My idea is to subdivide the clicked pie slice with its children (returned by an ajax) and animate the pie so the parents are completely squished (with a value of zero) and the children occupy the whole pie and replace the parents (which are remove from the data).

But I don’t really understand how I can update the pie to add the sub slices without removing the whole pie.

I have the following codepen that illustrate the issue:
https://codepen.io/jberli/pen/jEOrNjq
And here the javascript part of the codepen:

// The current slices of the pie
var parents = [
  // Only parent1 have children
  { 'name': 'parent1', 'value': 50 },
  { 'name': 'parent2', 'value': 20 },
  { 'name': 'parent3', 'value': 80 },
  { 'name': 'parent4', 'value': 40 },
]

// Those are the children of the parent1
var children = [
  { 'name': 'children1', 'value': 10 },
  { 'name': 'children2', 'value': 5 },
  { 'name': 'children3', 'value': 20 },
  { 'name': 'children4', 'value': 15 },
]

var data = parents;
data.sort((a, b) => b.value - a.value);

var container = document.getElementById('chart');

const width = container.offsetWidth;
const height = width;
const outer = height / 2;
const inner = outer * .5;
const radius = width / 4;
const tau = 2 * Math.PI;

const color1 = d3.color("hsl(0, 45%, 55%)");
const color2 = d3.color("hsl(360, 45%, 55%)");
const interpolation = d3.interpolateHslLong(color1, color2);

var color = d3.scaleOrdinal(d3.quantize(interpolation, data.length + 1));
var svg = d3.create("svg").attr("viewBox", [-width/2, -height/2, width, height]);
var arc = d3.arc().innerRadius(inner).outerRadius(outer);

// Create the pie chart
var pie = d3.pie().value((d) => d["value"]);

const path = svg.datum(data).selectAll("path")
  .data(pie)
  .join("path")
  .attr("fill", (d, i) => color(i))
  .attr("d", arc)
  .style("cursor", "pointer")
  .each(function(d) { this._current = d; })
    .on("click", (e, d) => {
      // Check if parent1 is clicked
      if (d.data.name === 'parent1') {
          // Set children as current data
          data = children;
          // Sort the data by value
          data.sort((a, b) => b.value - a.value);
          // Recalculate the color scale
          color = d3.scaleOrdinal(d3.quantize(interpolation, data.length + 1));
          
          // NEED TO REPLACE THE CLICKED SLICE WITH ITS CHILDREN
          // THEN ANIMATE THE PIE FOR THE CHILDREN TO GROW
          // WHILE PARENTS ARE SQUISHED (VALUE TO 0) AND REMOVED FROM THE DATA
      }
    })

container.append(svg.node());

How to detect when the user lifts their fingers after a touchpad wheel event in JavaScript?

I’m working on a Chrome extension and need to detect when the user lifts their fingers off the touchpad after scrolling. In Flutter, there’s an event like dragEnd, but I couldn’t find an equivalent for wheel events triggered by touchpad gestures in JavaScript.

I want to detect when the user stops interacting (i.e., when they remove their fingers from the touchpad), not just when the scrolling momentum slows down.

So far, I’ve tried this approach using setTimeout():

let wheelTimeout;
document.addEventListener("wheel", () => {
   clearTimeout(wheelTimeout); // Reset the timer
   wheelTimeout = setTimeout(() => {
       console.log("User lifted fingers from touchpad!");
       // Perform actions when scrolling stops
   }, 200); // Adjust delay as needed
});

This works by setting a timeout on every wheel event and assuming the scroll has “ended” if no new event occurs within 200ms.

My questions:

  • Is this the best way to detect when the user removes their fingers from the touchpad?
  • Are there any better or more accurate methods in JavaScript or the Chrome extension API?
    Thanks in advance!

Optional dynamic import that both Webpack and Vite are happy with?

I have a library that has an optional dependency and handles it using a dynamic import in a try catch block, like so:

let someModule = null;
try {
  someModule = await import ("may-not-exist"); // Webpack and Vite erroring
} catch (e) {
  // pass
}

// ... check if someModule is null

Webpack and Vite (and possibly others?) both try to statically analyze imports and so when this is used inside a project that relies on Webpack or Vite, they fail to build if the module is not found.

The standard fix for Webpack would be to add /* webpackIgnore: true */ comment in the import:

someModule = await import (/* webpackIgnore: true */"may-not-exist"); // Webpack happy, not Vite

That works for Webpack, but not Vite . I couldn’t find a similar workaround for Vite. The only solution I found was to force the module name to be dynamic, for example:

const tryImport = async (path) => {
  try {
    return await import(path); // Vite happy, not Webpack
  } catch (e__ignored) {
    // module doesn't exist
    return null;
  }
};
const someModule = await tryImport("may-not-exist");

Now Vite is not showing any errors or warnings, but although Webpack is not throwing fatal errors, it is showing very persistent warnings:

Critical dependency: the request of a dependency is an expression

It seems like Webpack requires dynamic imports to use statically known paths and not even /* webpackIgnore: true */ silences it (I tried adding it both inside the import and inside tryImport in front of the path).


QUESTION:

How can I implement optional dependencies in a library that is to work in various environments including Webpack and Vite? I obviously don’t want to require users to modify their configuration to suppress or ignore warnings like that.

How can I create a hover area that shows buttons on mouseover and keeps the cursor pointer over the buttons?

I’m working on a project where I have a hover area, and when the user hovers over it, I want some buttons to appear. I need these buttons to stay visible while the mouse is over them and make sure the cursor shows a pointer over the buttons.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Invisible Hover Area with Buttons</title>
    <style>
        /* The main element */
        .hover-target {
            position: relative;
            width: 200px;
            height: 200px;
            background-color: lightblue;
            transition: background-color 0.3s;
        }

        /* Invisible hover area (larger than the target) */
        .hover-area {
            position: absolute;
            top: -100px;  /* 200px larger, half above the target */
            left: -100px;  /* 200px larger, half left of the target */
            width: 400px;  /* 200px larger than the target (width and height) */
            height: 400px;  /* 200px larger than the target (width and height) */
            background: transparent;  /* Invisible */
        }

        /* Button group - initially hidden */
        .button-group {
            display: none;
            position: absolute;
            top: 220px;
            left: 0;
        }

        .button-group button {
            margin: 5px;
            padding: 10px;
            background-color: lightcoral;
            border: none;
            cursor: pointer;
            transition: background-color 0.3s;
        }

        .button-group button:hover {
            background-color: coral;
        }
    </style>
</head>
<body>

    <div class="hover-target">
        <div class="hover-area"></div>
        Hover over this area (invisible area around the box).
        
        <!-- Button group (initially hidden) -->
        <div class="button-group">
            <button>Button 1</button>
            <button>Button 2</button>
            <button>Button 3</button>
        </div>
    </div>

    <script>
        // JavaScript to track hover and perform actions
        const hoverTarget = document.querySelector('.hover-target');
        const hoverArea = document.querySelector('.hover-area');
        const buttonGroup = document.querySelector('.button-group');

        // Function to trigger when hovering in the invisible area
        function handleHoverEnter() {
            hoverTarget.style.backgroundColor = 'lightgreen';  // Change color
            buttonGroup.style.display = 'block';  // Show the button group
            console.log('Hovered over the invisible area!');
        }

        function handleHoverLeave() {
            hoverTarget.style.backgroundColor = 'lightblue';  // Reset color
            buttonGroup.style.display = 'none';  // Hide the button group
            console.log('Left the invisible area.');
        }

        // Add event listeners to the invisible hover area
        hoverArea.addEventListener('mouseenter', handleHoverEnter);
        hoverArea.addEventListener('mouseleave', handleHoverLeave);
    </script>

</body>
</html>

The buttons are being shown when I hover over the hoverArea, but when I move the cursor over the buttons, they disappear, and I can’t click on them. I also want the cursor to change to a pointer when hovering over the buttons.

How can I make sure that:

The buttons stay visible when the mouse is over them.
The cursor shows a pointer when hovering over the buttons.
Any help would be greatly appreciated!

Apply a class to first (left) visible slide in a Keen Slider carousel

The carousel plugin I’m using is Keen Slider. I basically want to apply an active class to visible slides – or due to the problem I’m trying to resolve, a better option might just be to apply the class to the left-most (first) in-view slide.

My carousel displays multiple slides, the amount visible varies depending on the size of the viewport. For example:

  • Mobile = 1.5 slides
  • Tablet = 3 slides
  • Desktop = 5 slides.

The reason I need this class is on mobile (when 1.5 slides are visible), I don’t want the figcaption to display unless it’s fully in the viewport. So I can fade/change the opacity when the slide is on the left edge.

A secondary reason for this might be on the tablet/desktop views I only indent the first figcatpion. Hence why only applying the class to the first visible slide might be fine. But if a class was added to all active slides I guess I could target with keen-slider__slide.active:first-child {};

Hope that explanation helps, thanks in advance!

new KeenSlider("#gallery-slider", {
    loop: true,
    mode: "free-snap",
    slides: {
        perView: 1.5,
        renderMode: "precision",
        spacing: 8
    },
    breakpoints: {
        '(min-width: 768px)': {
            slides: {
                perView: 3,
                spacing: 8
            }
        },
        '(min-width: 1024px)': {
            slides: {
                perView: 5,
                spacing: 8
            }
        }
    },
    created: function(instance) {
        document.getElementById("gallery-slider").classList.add("loaded");
        document
        .getElementById("arrow-left")
        .addEventListener("click", function() {
                instance.prev();
        });
        document
        .getElementById("arrow-right")
        .addEventListener("click", function() {
            instance.next();
        });
    }
});
/* ==========================================================================
   #BASE
   ========================================================================== */

html {
  font-size: 62.5%;
  margin: 0;
  padding: 0;
}

body {
  font-size: 12px;
  font-family: "Arial", sans-serif;
  margin: 0;
  padding: 64px 0 0;
  text-transform: uppercase;
}

h2 {
  font-size: 12px;
  font-weight: 400;
  margin: 0 16px 16px;
  padding: 0;
}

figure {
  margin: 0;
  padding: 0;
}

img {
  height: auto;
  width: 100%;
  max-width: 100%;
}


/* ==========================================================================
   #KEEN SLIDER
   ========================================================================== */

.keen-slider {
  display: flex;
  align-content: flex-start;
  overflow: hidden;
  position: relative;
  touch-action: pan-y;
  user-select: none;
  width: 100%;
  -webkit-tap-highlight-color: transparent;
}

.keen-slider .keen-slider__slide {
  min-height: 100%;
  overflow: hidden;
  position: relative;
  width: 100%;
}

.keen-slider .keen-slider__slide figcaption {
  margin: 8px 0 0 16px;
}


/* ==========================================================================
   #GALLERY
   ========================================================================== */


/**
 * My overrides for the Keen Slider gallery.
 *
 * 1. Remove `overflow: hidden` from the slider and add it to the parent. This
 *    allows the slider to align with the grid but also bleed off the edges of
 *    the page.
 * 2. Align container with the global grid.
 */

.gallery {
  margin-bottom: 64px;
  overflow: hidden;
}


/**
 * As the widths for each slide are set in Javascript. We add widths to slides
 * before `.keen-slider` has loaded to keep the layout consistent and help with
 * the Cumulative Layout Shift (CLS) and performance.
 */

.keen-slider:not(.loaded) .keen-slider__slide {
  width: calc((100vw / 1.5) - 24px);
}

@media(min-width: 48em) {
  .keen-slider:not(.loaded) .keen-slider__slide {
    width: calc((100vw - 48px) / 3);
  }
}

@media(min-width: 64rem) {
  .keen-slider:not(.loaded) .keen-slider__slide {
    width: calc((100vw - 56px) / 4);
  }
}

/**
 * Navigation for the gallery (prev/next).
 */

.gallery__nav {
  display: flex;
  justify-content: space-between;
  margin: 0 16px 16px;
}

.gallery__nav .arrow {
  cursor: pointer;
  user-select: none;
}


/* ==========================================================================
   #PIXEL LOAD
   ========================================================================== */


/**
 * Add a pixelated effect to images while the load.
 */

.pixel-load {
  overflow: hidden;
  position: relative;
}

.pixel-load__preload img {
  image-rendering: pixelated;
  position: absolute;
  inset: 0;
  opacity: 1;
  pointer-events: none;
}

.loaded .pixel-load__preload img {
  animation: loaded .32s .16s steps(1, end) both;
}

@keyframes loaded {
  0% {
    scale: 2;
  }

  33% {
    scale: 1.5;
  }

  66% {
    scale: 1;
  }

  100% {
    opacity: 0;
    z-index: 1;
  }
}
<script src="https://cdn.jsdelivr.net/npm/[email protected]/keen-slider.min.js"></script>
<!-- Keen Slider -->
<div class="gallery">
  <div class="gallery__nav grid">
    <div class="grid__col">
      <a id="arrow-left" class="arrow arrow--left shuffle">Previous</a>
    </div>
    <div class="grid__col">
      <a id="arrow-right" class="arrow arrow--right shuffle">Next</a>
    </div>
  </div>
  <div id="gallery-slider" class="keen-slider">
    <div class="keen-slider__slide">
      <figure data-label="Hover Label 1" class="has-label">
        <div class="pixel-load">
          <div class="pixel-load__preload">
            <img src="https://placebeard.it/18/24" width="18" height="24" loading="eager">
          </div>
          <img src="https://placebeard.it/768/1024" width="768" height="1024" loading="lazy" />
        </div>
        <figcaption>Slide 1</figcaption>
      </figure>
    </div>
    <div class="keen-slider__slide">
      <figure data-label="Hover Label 2" class="has-label">
        <div class="pixel-load">
          <div class="pixel-load__preload">
            <img src="https://placebeard.it/18/24" width="18" height="24" loading="eager">
          </div>
          <img src="https://placebeard.it/768/1024" width="768" height="1024" loading="lazy" />
        </div>
        <figcaption>Slide 2</figcaption>
      </figure>
    </div>
    <div class="keen-slider__slide">
      <figure data-label="Hover Label 3" class="has-label">
        <div class="pixel-load">
          <div class="pixel-load__preload">
            <img src="https://placebeard.it/18/24" width="18" height="24" loading="eager">
          </div>
          <img src="https://placebeard.it/768/1024" width="768" height="1024" loading="lazy" />
        </div>
        <figcaption>Slide 3</figcaption>
      </figure>
    </div>
    <div class="keen-slider__slide">
      <figure data-label="Hover Label 4" class="has-label">
        <div class="pixel-load">
          <div class="pixel-load__preload">
            <img src="https://placebeard.it/18/24" width="18" height="24" loading="eager">
          </div>
          <img src="https://placebeard.it/768/1024" width="768" height="1024" loading="lazy" />
        </div>
        <figcaption>Slide 4</figcaption>
      </figure>
    </div>
    <div class="keen-slider__slide">
      <figure data-label="Hover Label 5" class="has-label">
        <div class="pixel-load">
          <div class="pixel-load__preload">
            <img src="https://placebeard.it/18/24" width="18" height="24" loading="eager">
          </div>
          <img src="https://placebeard.it/768/1024" width="768" height="1024" loading="lazy" />
        </div>
        <figcaption>Slide 5</figcaption>
      </figure>
    </div>
    <div class="keen-slider__slide">
      <figure data-label="Hover Label 6" class="has-label">
        <div class="pixel-load">
          <div class="pixel-load__preload">
            <img src="https://placebeard.it/18/24" width="18" height="24" loading="eager">
          </div>
          <img src="https://placebeard.it/768/1024" width="768" height="1024" loading="lazy" />
        </div>
        <figcaption>Slide 6</figcaption>
      </figure>
    </div>
    <div class="keen-slider__slide">
      <figure data-label="Hover Label 7" class="has-label">
        <div class="pixel-load">
          <div class="pixel-load__preload">
            <img src="https://placebeard.it/18/24" width="18" height="24" loading="eager">
          </div>
          <img src="https://placebeard.it/768/1024" width="768" height="1024" loading="lazy" />
        </div>
        <figcaption>Slide 7</figcaption>
      </figure>
    </div>
    <div class="keen-slider__slide">
      <figure data-label="Hover Label 8" class="has-label">
        <div class="pixel-load">
          <div class="pixel-load__preload">
            <img src="https://placebeard.it/18/24" width="18" height="24" loading="eager">
          </div>
          <img src="https://placebeard.it/768/1024" width="768" height="1024" loading="lazy" />
        </div>
        <figcaption>Slide 8</figcaption>
      </figure>
    </div>
  </div>
</div>
<!-- End Keen Slider -->

Grease monkey sript for google lens

long seems I scripted any scripts and forgot most, plus I relied on a collection of scripts that I don’t have.

my 1st idea was to build a script to arrange the results by size, but this will be to complicate for me, my 2nd idea was to simple return the biggest resolution available but it may not be of the correct image, so I decided on the list of available resolutions, them I can go from there.

I managed to zero in to the node
span.cyspcb.DH9lqb.VBZLA> span
it selects all the resolutions but it also select post lapse of time (found no way to differentiated further)

so I need to get all those spans, filter duplicates and lapse stamps and print to the results in the console

any pointers? I need a good site like w3schools for scripting for the monkey

What would be the total unit time for this program?

This is a javascript program to calculate the factorial of 6 using recursion. How would I calculate the total unit time?

function Factorial(a){
  if(a === 0 || a === 1) 2 units of time
  return 1; 1 unit of time

  return a*Factorial(n-1); n
}

console.log(Factorial(6));

I have found three different answers: 21, 43 and 18

How to disable mouse right click by default, but enable right click on press ctrl + perticular key

in jQuery i use this code to disable mouse right click by default but it’s enable right click only on images

$(document).bind( "contextmenu", function(e) {
            if(e.target.tagName.toLowerCase() === 'img'){
                return true;
        } else {
              e.preventDefault();
              return false;
           }
    });

But now i want to add in above code if i press CTRL + P then it completely Enable the right click.

How is this possible? you answer will be appreciated. Thanks

URL string to text case conversion getting wrong

<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js"></script>

const urlObjects = [
{title: "Core Details", label: "Details"},
{title: 'Characteristics', label: ''},
{title: 'Personal Details', label: 'Addresses'},
{title: 'Personal Details', label: 'Contact information'},
{title: 'Personal Details', label: 'Personal information'},
{title: "Personal Details", label: "Miscellaneous"}
]
const urlParams = urlObjects.map(urlOb => `${_.camelCase(urlOb.title)}/${_.camelCase(urlOb.label)}`)
console.log('urlParams', urlParams);
const urlParamsToObject = urlParams.map((param) => {
  const title = param.split("/")[0];
  const lable = param.split("/")[1] ? param.split("/")[1] : ""
  return {title:_.startCase(title), label: _.startCase(lable)}
})
console.log("urlParamsToObject", urlParamsToObject)

From Object I am converting to hash param. then same need to convert back to Object. I am using lodash to convert. but some help needs in the label side.

converting back to object, labels are not in correct case as per object. both first second word are converted to upperCase. in label

{label: 'Contact Information'},
{label: 'Personal Information'},

it should be

{title: 'Personal Details', label: 'Contact information'},
{title: 'Personal Details', label: 'Personal information'},

need help.

JasperReports Not Populating Data from JRBeanCollectionDataSource into Detail Band

I’m working on generating a report in JasperReports using JRBeanCollectionDataSource to pass dynamically retrieved data to my report template. The data extraction works correctly (confirmed through debugging), but the report remains blank—the Detail Band does not display any data.

JRXML report template

<!-- Created with Jaspersoft Studio version 7.0.1.final -->
<jasperReport name="TestReport" language="java"
    pageWidth="900" pageHeight="842" columnWidth="860"
    leftMargin="20" rightMargin="20" topMargin="40"
    bottomMargin="30" uuid="12345678-90ab-cdef-1234-567890abcdef">

    <!-- Define the parameter for data source -->
    <parameter name="TEST_DATA_SOURCE" class="net.sf.jasperreports.engine.JRDataSource"/>

    <!-- Define fields expected in the dataset -->
    <field name="TEST1" class="java.lang.String"/>
    <field name="TEST2" class="java.lang.String"/>
    <field name="TEST3" class="java.lang.String"/>
    <field name="TEST4" class="java.lang.String"/>
    <field name="TEST5" class="java.lang.String"/>

    <title>
        <band height="50">
            <staticText>
                <reportElement x="150" y="10" width="600" height="30"/>
                <textElement textAlignment="Center">
                    <font size="16" isBold="true"/>
                </textElement>
                <text><![CDATA[Test Report]]></text>
            </staticText>
        </band>
    </title>

    <columnHeader>
        <band height="40">
            <staticText>
                <reportElement x="0" y="0" width="172" height="30"/>
                <text><![CDATA[Test1]]></text>
            </staticText>
            <staticText>
                <reportElement x="172" y="0" width="172" height="30"/>
                <text><![CDATA[Test2]]></text>
            </staticText>
            <staticText>
                <reportElement x="344" y="0" width="172" height="30"/>
                <text><![CDATA[Test3]]></text>
            </staticText>
            <staticText>
                <reportElement x="516" y="0" width="172" height="30"/>
                <text><![CDATA[Test4]]></text>
            </staticText>
            <staticText>
                <reportElement x="688" y="0" width="172" height="30"/>
                <text><![CDATA[Test5]]></text>
            </staticText>
        </band>
    </columnHeader>

    <detail>
        <band height="30">
            <textField>
                <reportElement x="0" y="0" width="172" height="30"/>
                <textFieldExpression><![CDATA[$F{TEST1}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="172" y="0" width="172" height="30"/>
                <textFieldExpression><![CDATA[$F{TEST2}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="344" y="0" width="172" height="30"/>
                <textFieldExpression><![CDATA[$F{TEST3}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="516" y="0" width="172" height="30"/>
                <textFieldExpression><![CDATA[$F{TEST4}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="688" y="0" width="172" height="30"/>
                <textFieldExpression><![CDATA[$F{TEST5}]]></textFieldExpression>
            </textField>
        </band>
    </detail>

    <noData>
        <band height="30">
            <staticText>
                <reportElement x="0" y="0" width="860" height="20"/>
                <text><![CDATA[No Data Available]]></text>
            </staticText>
        </band>
    </noData>

</jasperReport>

JavaScript function (fillParameters()) used for data retrieval:

function fillParameters() {
    try {
        var rawData = datasourceHelper.get("testDataSource").getRows();

        if (!rawData || rawData.length === 0) {
            throwError("No data retrieved from 'testDataSource'.");
        }

        var extractedData = [];

        for (var i = 0; i < rawData.length; i++) {
            var row = rawData[i];

            var extractedRow = {
                TEST1: parseInt(row.getFieldAsString("TEST1")) || 0,
                TEST2: row.getFieldAsString("TEST2") || "",
                TEST3: row.getFieldAsString("TEST3") || "",
                TEST4: row.getFieldAsString("TEST4") || "",
                TEST5: row.getFieldAsString("TEST5") || ""
            };

            extractedData.push(extractedRow);
        }

        var JRBeanCollectionDataSource = Java.type("net.sf.jasperreports.engine.data.JRBeanCollectionDataSource");
        var jrDataSource = new JRBeanCollectionDataSource(extractedData, false);
        parameterMap.put("TEST_DATA_SOURCE", jrDataSource);

    } catch (e) {
        throwError("ERROR: " + e.message);
    }
}

What I Need Help With:

  • How can I make JasperReports recognize and iterate over TEST_DATA_SOURCE?

  • Is there a missing configuration in the JRXML template to properly bind the data?

  • Does JasperReports require an explicit connection setting for this approach?

  • Is the JRBeanCollectionDataSource being handled incorrectly in fillParameters()?

  • The data extraction works correctly (confirmed via debugging).

  • TEST_DATA_SOURCE is assigned properly.

  • The Detail Band remains empty—no data rows appear.

  • The “No Data Available” message appears, suggesting that JasperReports does not recognize the data source.

Custom control in smart filterbar

I have created a Fiori app where I am using smart filter bar and smart table which are mapped to same entityset.

Now my requirement is to add one F4 searchvaluehelp which calls different entityset.

Can someone advise how can I achieve it ? Should I use annotations or any other way? Please suggest

How to change shortcode within my wordpress website after user interacts with front-end button?

I”m using royal audio player as a plugin for a website i’m creating, and I want to have something similar to what this guy created for his voiceover website. Essentially, I want text above the audio player with the different categories available to click on, and when one is clicked on by the user then it will change the player to the respective playlist depending on which one was clicked on. So far, i’ve got 2 shortcodes for the audio player:

[fwdrap preset_id="VOICEOVER" playlist_id="VoiceOvers" start_playlist_id="Audiobooks" start_track_id="preset"]
[fwdrap preset_id="VOICEOVER" playlist_id="VoiceOvers" start_playlist_id="Narration" start_track_id="preset"]

The audio player does have a dropdown that the user can use, which when clicked on will show the other categories and they can choose from there. But I want the user to be able to see all of the categories at a given time with a single player. To my knowledge, changing the shortcode using AJAX is the only way I can really achieve my goal.

I tried following this stack overflow post: https://stackoverflow.com/q/54442781/29746210

So i got code like this:

add_action('wp_ajax_switch_audio_playlist', 'switch_audio_playlist');
add_action('wp_ajax_nopriv_switch_audio_playlist', 'switch_audio_playlist');

function switch_audio_playlist() {
    if (isset($_POST['playlist'])) {
        $playlist = sanitize_text_field($_POST['playlist']);

        echo do_shortcode('[fwdrap preset_id="VOICEOVER" playlist_id="VoiceOvers"            start_playlist_id="' . $playlist . '" start_track_id="preset"]');
        $html = ob_get_clean();

        wp_send_json_success($html);
    } else {
        wp_send_json_error('No playlist provided.');
    }
}
function enqueue_custom_ajax_script() {
    wp_enqueue_script('custom-ajax-script', get_template_directory_uri() . '/js/custom-ajax.js', array('jquery'), null, true);
    
    wp_localize_script('custom-ajax-script', 'ajax_object', array(
        'ajax_url' => admin_url('admin-ajax.php'),
    ));
}
add_action('wp_enqueue_scripts', 'enqueue_custom_ajax_script');

html/js:

<div class="playlist-container">
    <a class="switch-playlist" data-playlist="Audiobooks">Audiobooks</a> |
    <a class="switch-playlist" data-playlist="Narration">Narration</a>
</div>
<div id="audio-player-container">
    [fwdrap preset_id="VOICEOVER" playlist_id="VoiceOvers" start_playlist_id="Audiobooks" start_track_id="preset"]
</div>

<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
jQuery(document).ready(function($) {
    $('.switch-playlist').on('click', function() {
        let playlist = $(this).data('playlist');
        console.log('Switching to playlist:', playlist);

        $.ajax({
            url: ajax_object.ajax_url, // This comes from wp_localize_script
            method: "POST",
            data: {
                action: 'fetch_shortcode',
                playlist: playlist
            },
            success: function(response) {
                console.log('AJAX response:', response);
                $('#audio-player-container').html(response.data);
            }
        });
    });
});

</script>

After fixing a localization issue, i’ve come to this error:

When i load the page, the audio player is loading as intended:My inspector before I click on the Narration Button
But when I press on the narration button the page shows nothing and the inspector looks like this:
Inspector after I click on the narration button
Is there something wrong that i’m doing, and if so what could it be?

WebGL Matrixes Translate wrap instead of move

So, I tried creating my own WebGL Matrixes. Rotate and Scale worked properly, except for Translate. For some reason, it has wrapped (large on the bottom and small on the top). You can test this by changing the translate.y on the functions.js. I also made my function to simplify the WebGL code, so is it possibly messes this matrix up?

index.html

<canvas width="500px" height="500px" id="canvas"></canvas>
<script src="WebGLMatrix.js"></script>
<script src="WebGL.js"></script>
<script src="functions.js"></script>

WebGLMatrix.js

function GLMatrix4(){
    this.Translate = {
        x:0,
        y:0,
        z:0
    }
    this.Scale = {
        x:1,
        y:1,
        z:1
    }
    this.Rotate = {
        x:0,
        y:0,
        z:0
    }
    this.Create = function(){
        var m4 = new Float32Array(16)
        m4[0] = 1
        m4[5] = 1
        m4[10] = 1
        m4[15] = 1
        return m4
    }
    this.MatrixMulit4 = function(m1,m2){
        var r1 = m1[0]*m2[0] + m1[1]*m2[4] + m1[2]*m2[8] + m1[3]*m2[12]
        var r2 = m1[0]*m2[1] + m1[1]*m2[5] + m1[2]*m2[9] + m1[3]*m2[13]
        var r3 = m1[0]*m2[2] + m1[1]*m2[6] + m1[2]*m2[10] + m1[3]*m2[14]
        var r4 = m1[0]*m2[3] + m1[1]*m2[7] + m1[2]*m2[11] + m1[3]*m2[15]
        var r5 = m1[4]*m2[0] + m1[5]*m2[4] + m1[6]*m2[8] + m1[7]*m2[12]
        var r6 = m1[4]*m2[1] + m1[5]*m2[5] + m1[6]*m2[9] + m1[7]*m2[13]
        var r7 = m1[4]*m2[2] + m1[5]*m2[6] + m1[6]*m2[10] + m1[7]*m2[14]
        var r8 = m1[4]*m2[3] + m1[5]*m2[7] + m1[6]*m2[11] + m1[7]*m2[15]
        var r9 = m1[8]*m2[0] + m1[9]*m2[4] + m1[10]*m2[8] + m1[11]*m2[12]
        var r10 = m1[8]*m2[1] + m1[9]*m2[5] + m1[10]*m2[9] + m1[11]*m2[13]
        var r11 = m1[8]*m2[2] + m1[9]*m2[6] + m1[10]*m2[10] + m1[11]*m2[14]
        var r12 = m1[8]*m2[3] + m1[9]*m2[7] + m1[10]*m2[11] + m1[11]*m2[15]
        var r13 = m1[12]*m2[0] + m1[13]*m2[4] + m1[14]*m2[8] + m1[15]*m2[12]
        var r14 = m1[12]*m2[1] + m1[13]*m2[5] + m1[14]*m2[9] + m1[15]*m2[13]
        var r15 = m1[12]*m2[2] + m1[13]*m2[6] + m1[14]*m2[10] + m1[15]*m2[14]
        var r16 = m1[12]*m2[3] + m1[13]*m2[7] + m1[14]*m2[11] + m1[15]*m2[15]
        return new Float32Array([r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12,r13,r14,r15,r16])
    }
    this.getMatrix = function(){
        var Scale = this.Create()
        Scale[0] = this.Scale.x
        Scale[5] = this.Scale.y
        Scale[10] = this.Scale.z

        var Translate = this.Create()
        Translate[3] = this.Translate.x
        Translate[7] = this.Translate.y
        Translate[11] = this.Translate.z

        var RotateX = this.Create()
        RotateX[5] = Math.cos(this.Rotate.x)
        RotateX[6] = -Math.sin(this.Rotate.x)
        RotateX[9] = Math.sin(this.Rotate.x)
        RotateX[10] = Math.cos(this.Rotate.x)

        var RotateY = this.Create()
        RotateY[0] = Math.cos(this.Rotate.y)
        RotateY[2] = Math.sin(this.Rotate.y)
        RotateY[8] = -Math.sin(this.Rotate.y)
        RotateY[10] = Math.cos(this.Rotate.y)

        var RotateZ = this.Create()
        RotateZ[0] = Math.cos(this.Rotate.z)
        RotateZ[1] = -Math.sin(this.Rotate.z)
        RotateZ[4] = Math.sin(this.Rotate.z)
        RotateZ[5] = Math.cos(this.Rotate.z)

        var res1 = this.MatrixMulit4(RotateX,Scale)
        var res2 = this.MatrixMulit4(RotateY,res1)
        var res3 = this.MatrixMulit4(RotateZ,res2)
        var res4 = this.MatrixMulit4(Translate,res3)
        return res4
    }
}

WebGL.js

function SimpleGL(gl){
    this.shaderArr = []
    this.sProgram = undefined
    this.makeBuffer = function(arr){
        var buffer = gl.createBuffer()
        gl.bindBuffer(gl.ARRAY_BUFFER, buffer)
        gl.bufferData(gl.ARRAY_BUFFER, arr, gl.STATIC_DRAW)
        return buffer
    }
    this.addShader = function(str,type){
        var shader = gl.createShader(type)
        gl.shaderSource(shader, str)
        gl.compileShader(shader)
        this.shaderArr.push(shader)
    }
    this.makeShaderProgram = function(){
        var shaderProgram = gl.createProgram()
        for(var i=0;i<this.shaderArr.length;i++){
            gl.attachShader(shaderProgram, this.shaderArr[i])
        }
        gl.linkProgram(shaderProgram)
        gl.useProgram(shaderProgram)
        this.sProgram = shaderProgram
    }
    this.linkAttribute = function(variable,buffer,readnum){
        var location = gl.getAttribLocation(this.sProgram, variable)
        gl.enableVertexAttribArray(location)
        gl.bindBuffer(gl.ARRAY_BUFFER,buffer)
        gl.vertexAttribPointer(location,readnum,gl.FLOAT,false,0,0)
    }
    this.linkMatrix4 = function(variable,mat4){
        var mat4Location = gl.getUniformLocation(this.sProgram,variable)
        gl.uniformMatrix4fv(mat4Location,false,mat4)
    }
}

functions.js

var c = document.getElementById('canvas')
var gl = c.getContext('webgl')
var webgl = new SimpleGL(gl)
var m4 = new GLMatrix4()

const vertices = new Float32Array([
    0, 0.5, 0,
   -.5, -0.5, 0,
    .5, -.5, 0
]);
const colors = new Float32Array([
    1,0,0,
    0,1,0,
    0,0,1
]);
const vertexShaderSource = `
    precision mediump float;
    attribute vec3 a_position;
    attribute vec3 a_color;
    varying vec3 vColor;
    uniform mat4 matrix;

    void main() {
        vColor = a_color;
        gl_Position = matrix * vec4(a_position, 1);
    }
`;
const fragmentShaderSource = `
    precision mediump float;
    varying vec3 vColor;

    void main() {
        gl_FragColor = vec4(vColor, 1.0);
    }
`;

const vertexBuffer = webgl.makeBuffer(vertices)
const colorBuffer = webgl.makeBuffer(colors)
webgl.addShader(vertexShaderSource,gl.VERTEX_SHADER)
webgl.addShader(fragmentShaderSource,gl.FRAGMENT_SHADER)
webgl.makeShaderProgram()
webgl.linkAttribute('a_position',vertexBuffer,3)
webgl.linkAttribute('a_color',colorBuffer,3)

m4.Translate.y = 1 //Supposed to be move up
webgl.linkMatrix4('matrix',m4.getMatrix())
gl.clearColor(0,0,0,1);
gl.clear(gl.COLOR_BUFFER_BIT);
gl.drawArrays(gl.TRIANGLES,0,3);