How I can Update only relevant data with this Update Controller?

Update Controller

exports.UpdatePanelMembers = (req, res) => {
  const { panelId } = req.params;
  if (panelId) {
    Panel.findOneAndUpdate(
      { _id: panelId },
      {
        panelMembers: {
          member1: {
            memberId: req.body.panelMembers.member1.memberId,
            fullName: req.body.panelMembers.member1.fullName,
            username: req.body.panelMembers.member1.username,
          },
          member2: {
            memberId: req.body.panelMembers.member2.memberId,
            fullName: req.body.panelMembers.member2.fullName,
            username: req.body.panelMembers.member2.username,
          },
          member3: {
            memberId: req.body.panelMembers.member3.memberId,
            fullName: req.body.panelMembers.member3.fullName,
            username: req.body.panelMembers.member3.username,
          },
        },
      }
    ).exec((error, result) => {
      if (error) return res.status(400).json({ error });
      if (result) {
        res.status(202).json({ result });
      }
    });
  }
};

In this code, if I update member1 details only, other data will be erased. So I want to update only relevant data like this postman JSON.

Postmen JSON Code

{
    "panelMembers": {
        "member1": {
            "username":"john.j",
            "fullName":"John Jade",
            "memberId":"member123"
        }
    }
}

Postmen ScreenShot
enter image description here

How to use regex to match an IPFS URL?

I have the following IPFS URL.

https://ipfs.moralis.io:2053/ipfs/QmPQeMz2vzeLin5HcNYinVoSggPsaXh5QiKDBFtxMREgLf/images/0000000000000000000000000000000000000000000000000000000000000001.png

I want to use regex to match this file, but instead of writing the full URL, I want to just match something like https*00000001.png.

The problem is that when I use

  paddedHex = '00000001';
      let tmpSearchQuery = `https*${paddedHex}.png`;

It doesn’t really match anything. Why?

how to display different colors on each column of a row using ngClass in agular?

I have 4 rows, each row contains 3 cards.
I am fetching information for these cards from db then rendering them using ngfor in html.
The problem is I want each of card of a row to show different color.

Example:->

ROW 1:
BLUECARD | WHITECARD | REDCARD

ROW 2:
BLUECARD | WHITECARD | REDCARD

as of now I able to do for two colors but how can I make it for 3 colors as I stated in example.

<div *ngFor="let r of rates; let i=index;"> 
  <div class="box" [ngClass]="i % 2 == 0 ? 'BLUECARD' : 'REDCARD'">
   <!-- card contents -->
  </div>
</div>

As you can see I am able to show 2 colors alternatively but how can I show 3 colors instead?

Remove /#/ from link?

I’m trying to write a single page application and I’m using this class for routing:
class code

then I add routes

export const routes = [
  {
    path: /task-list/,
    callback: () => {
      console.log('callback');
    }
  }
];

export const router = new Router({
  root: '/task-list',
  mode: 'hash',
  routes
});

I expect that when loading the site, I will get a link localhost:3000/task-list, but for some reason I get localhost:3000/#/task-list, I can’t figure out how to remove this /#/

Problem with Jquery in django project template

I’m facing a problem in this Django project where I’m working to get a dynamic dependent drop-down.

This part of the script is not sending any Ajax request.
As a beginner, I’m trying to do random projects.
I didn’t know more about Ajax and Javascript.
Is there any problem in this code?

Image

JavaScript OpenLayers: add attributes to a drawn feature (point, polygon, circle)

I want to create a webapp in which the user can draw features on a raster and add attributes to it. Sadly, I am a bit of a newbie.

Using OpenLayers and a GeoServer, I succesfully managed to display a raster on the OpenLayers. Furthermore, I also managed to create a draw layer, in which the user can choose between options: point, circle and polygon.

Now I only want to add the option to add attributes to the feature that has been drawn. (And subsequently for example, click afterwards on it to see said attributes).

Creating the map (‘…’ for working stuff that I don’t necessarily want to disclose):

var mapView = new ol.View ({
  center: ol.proj.fromLonLat([..., ...]),
  zoom: ...,
});

var map = new ol.Map ({
  target: 'map',
  view: mapView,
})

var noneTile = new ol.layer.Tile({
  title: 'None',
  type: 'base',
  visible: false
});

var osmTile = new ol.layer.Tile ({
  title: 'Open Street Map',
  visible: true,
  type: 'base',
  source: new ol.source.OSM()
});

// map.addLayer(osmTile)
var baseGroup = new ol.layer.Group({
  title: 'Base Maps',
  fold: true,
  layers: [osmTile, noneTile]
});

map.addLayer(baseGroup)

var Raster = new ol.layer.Tile({
  title: 'Raster',
  source: new ol.source.TileWMS({
      url: ...,
      params: {'LAYERS':..., 'TILED': true},
      serverType: 'geoserver',
      visible: true
  })
});

// map.addLayer(Raster);

So this works, now I add the draw function:

// Add draw layer


const source = new ol.source.Vector({wrapX: false});

const drawLayer = new ol.layer.Vector({
  source: source,
});

const typeSelect = document.getElementById('type');

let draw; // global so we can remove it later

function addInteraction() {
const value = typeSelect.value;
if (value !== 'None') {
  draw = new ol.interaction.Draw({
    source: source,
    type: typeSelect.value,
  });
  map.addInteraction(draw);
}

}

/**
* Handle change event.
*/
typeSelect.onchange = function () {
  map.removeInteraction(draw);
  addInteraction();
};

document.getElementById('undo').addEventListener('click', function () {
  draw.removeLastPoint();
});

addInteraction();

I think these are the most important parts of the code. Now, this gives me nicely the map with the raster on it and the ability to draw features. But I cannot add attributes yet, and I am stuck there.

What I tried (following: Assign Id / name attribute for uniquely identifying drawn polygon):

let draw; // global so we can remove it later

function addInteraction() {
const value = typeSelect.value;
if (value !== 'None') {
  draw = new ol.interaction.Draw({
    source: source,
    type: typeSelect.value,
  });
  map.addInteraction(draw);

draw.on('drawend', function(evt){
    var feature = evt.feature;

    feature.setId(some_uniq_id);

    //do you want to set other properties?
    feature.setProperties({
        name: 'some_name'
    });
});
}

}

But this does not work for me. At least, I cannot see the id and attributes and the drawn polygon removes from itself.

What am I doing wrong or what do I need to do/add?

Making neat variable lists from multiple arrays to use as ‘clean’ arguments in a later function (javascript)

okay I’m pretty noob but have been enjoying the recursive-ness of js

I’m [hopefully] making expandable info boxes that operate independently.

Instead of making 5 different animation/onClick() behaviours for each one, I figure I’ll name all the elements to a specification i made up (because sadly i’m in wix/velo and I need to refer to them as $(‘#element’), etc) and then generate an object that contains the strings to plug in as arguments.
After some mind blowing moments, I was successful (yes I’m dumb).
here is my final output that gives me each category and their array with the strings

heres the code if the image didn’t load:

let parts = ["Win')", "List')", "Text')", "ArL')", "ArR')"];
let cats = ["$w('fam", "$w('mwl", "$w('aes", "$w('hrm"];

function merger(c, p) {
   let result = [];
   let i;
   for (i = 0; i != p.length; i++) result[i] = c + p[i];
   return result;
}

const final = {
   fam: merger(cats[0], parts),
   mwl: merger(cats[1], parts),
   aes: merger(cats[2], parts),
   hrm: merger(cats[3], parts)
};
//object made with category: [string1, string2,...] for each
console.log (final);

I know {final} could be improved but that brings me to my actual question(s).

My animation/onClick() function (not pictured, happens after); if it was to run independently for each category, it needs the strings in the array of each category, which thankfully I managed to generate.

However I’d rather not refer to them literally from the array like categoryStr[0] because then I’d still kinda have to copy/paste the function [i] times for each category, no?

So how can I turn all the strings in each array of this object I’ve made into objects themselves, so that way the functions I do later only need to refer to a single object like ‘for each {category}Str.Text” instead of for famStr[i], for hrmStr[i], etc.

Like later I’d hope to make a for loop or something that executes my future “interactiveFunction(category)” for all my categories using each of their variable lists in a tidy way, but hitting that goal is just beyond me, I figure I can do that if the variable list is clean and I just reference a neat object like ‘category.param’ instead of ‘category[2]’. idk data types and valid references haven’t quite settled for me yet. I figure a first post would usually be embarrassing but hey I’m drunk, head-scratching, and an outside perspective from StackOverflow peeps would really help me rn along with all the docs i’ve been reading. Maybe it’s time to hire a tutor…

Uv map not loading correctly in three.js

My uv map is loading like it’s one side of a block:
enter image description here

Here is my code:

    const grass = new THREE.TextureLoader().load( 'https://raw.githubusercontent.com/Isaiah08-D/namelater/main/textures/blocks/grass.png' );
    
    
    const geometry = new THREE.BoxGeometry();
    const material = new THREE.MeshBasicMaterial({map:grass});
    ...

  var noise = new noisejs.Noise(Math.random());



    for (let x=0; x < 201; x += 10) {
      for (let z=0; z<201; z+=10) {
        //const chunk = getChunk(x, z)
        const cube = new THREE.Mesh(geometry, material)
        cube.position.x = x
        cube.position.z = z
        cube.position.y = noise.perlin2(x/100, z/100) * 100;
        cube.scale.set(10,10,10);
        blocklist.push(cube);
        scene.add( cube );
      }
    };

And you can find the uv map here.
What is wrong? Thanks in advance!

R script calling in PHP for online statistical analysis of the HTML input data

After the varibles as $alldata; I wrote this for call an R script called rCommands

        echo "<p>Saving the received json into file dataReceived/input_".$timeStamp.".json</p>"; 
        file_put_contents("dataReceived/input_".$timeStamp.".json", json_encode($allData)); 
        echo "<p>Calling R code to compute min, mean, and max values</p>";
        exec("Rscript rCommands.txt ".$timeStamp);
        echo "<p>Parsing the result dataReceived/output_".$timeStamp.".json of the R code</p>";
        $result = json_decode(file_get_contents("dataReceived/output_".$timeStamp.".json"), true);
        echo "<p>Result: ".print_r($result, true)."</p>";```

Here the R code in which I want to obtain a data.frame, and then use for the statistical analysis
library("RJSONIO")
args = commandArgs(trailingOnly=TRUE)
if (length(args) != 1) {
  stop("Exactly one argument must be supplied (timestamp).n", call.=FALSE)
}
allData<- fromJSON(paste("dataReceived/input_", args[1], ".json", sep = ""))
data= as.data.frame(allData)
x <- toJSON(data)
fileConn<-file(paste("dataReceived/output_", args[1], ".json", sep = ""))
writeLines(x, fileConn)
close(fileConn) ```

Material table datasource storing data in filteredData property instead of data property

In my angular project, I have a table on a page that contains a list of bank accounts with their balance and other data etc (ref pic below).
Bank list table

My aim is to make table entries clickable so that every time someone clicks a row in the table, another component that contains bank transactions in a material table, Bank Ledger, opens in a dialog and shows record of the corresponding bank account, row of which has been clicked in the Bank Balance table.

To do that, I send account number to a function in service which pushes it to an observable subject. And the bank ledger component is subscribed to the aforementioned observable. Refer below code:

Component on which Bank Balance table is:

  constructor(private Fin:Finservice) {}

  acnum:number;

  viewBankLedger(): void {
    const dialogRef = this.dialog.open( BankledgerComponent , { width: '40vw', height: '80vh', disableClose: true, panelClass: "foo" } ); 
  }

  openLedger(row) {
    this.acnum = row.bank_acnum;
    this.Fin.getBankACNum(this.acnum);
    this.viewBankLedger();
  }

Fin Service:

  private _subject = new Subject<any>();
  changebank = this._subject.asObservable();

  getBankACNum(acnum: number){
    this._subject.next(acnum);
  }

Bank Ledger component:

export class BankledgerComponent implements OnInit {

  constructor(private Fin: Finservice, private LS: LedgerService) {}

  ngOnInit() {
    this.Fin.changebank.subscribe( result => {
      this.acnum = result;
      const bankACNum = {
        acnum: this.acnum,
      };
      this.getLedger(bankACNum);  
    })
  }
  
  BankLedgerDataSource = new MatTableDataSource<BankLedger>();
  bankLedger: BankLedger[];
  acnum:number;
  ledgerColumns: string[] = ['serial', 'bl_date', 'bl_part', 'bl_debit', 'bl_credit', 'bl_balance'];

  getLedger(bankACNum:ACNum){
    this.LS.showBankLedger(bankACNum).subscribe((results:BankLedger[])=>{
      this.bankLedger = results;
      this.BankLedgerDataSource.data = this.bankLedger;
      console.log(this.BankLedgerDataSource);
    })
  }

}

Bank Ledger template:

<div mat-dialog-content style="background-color: white; border-radius: 5px; padding: 1%;">

        <table style="width: 100%;" mat-table [dataSource]="BankLedgerDataSource" class="mat-elevation-z8">
            
        <ng-container matColumnDef="serial">
            <th mat-header-cell *matHeaderCellDef> S.No. </th>
            <td mat-cell *matCellDef="let element; let i = index;"> {{i+1}} </td>
        </ng-container>
                
        <ng-container matColumnDef="bl_date">
            <th mat-header-cell *matHeaderCellDef> Date </th>
            <td mat-cell *matCellDef="let element">{{element.bl_date | date:'dd/MM/yyyy'}} </td>
        </ng-container>
                
        <ng-container matColumnDef="bl_part">
            <th mat-header-cell *matHeaderCellDef> Particulars </th>
            <td mat-cell *matCellDef="let element"> {{element.bl_part}} </td>
        </ng-container>

        <ng-container matColumnDef="bl_debit">
            <th mat-header-cell *matHeaderCellDef> Debit Amount</th>
            <td mat-cell *matCellDef="let element"> {{element.bl_debit  | INRCurrency}} </td>
        </ng-container>

        <ng-container matColumnDef="bl_credit">
            <th mat-header-cell *matHeaderCellDef> Credit Amount</th>
            <td mat-cell *matCellDef="let element"> {{element.bl_credit  | INRCurrency}} </td>
        </ng-container>
            
        <ng-container matColumnDef="bl_balance">
            <th mat-header-cell *matHeaderCellDef> Balance </th>
            <td mat-cell *matCellDef="let element"> {{element.bl_balance  | CreditDebit}} </td>
        </ng-container>

        <tr mat-header-row *matHeaderRowDef="ledgerColumns"></tr>
        <tr class="tablerow" mat-row *matRowDef="let row; columns: ledgerColumns;"> </tr>

    </table>
La la la
</div>

<div mat-dialog-actions style="margin-top: 2%; border-top: 1px solid black;">
    <button type="button" class="btn btn-outline-dark" [mat-dialog-close]="true">Close</button>
</div>

As you can see above, have subscribed to the subject, created a json package and sent it to a method that retrieves corresponding data from the api using another service, called Ledger Service.

export class LedgerService {

  constructor(private httpClient: HttpClient) { }
  
showBankLedger(acnum: ACNum): Observable<BankLedger[]> {
    return this.httpClient.post<any>(`${this.PHP_API_SERVER}/apiroute.php`, acnum);
  }

While everything should work fine, I am facing multiple problems God kows why. Here are the problem I am facing:

  1. After the component that contains Bank Balance table loads for the first time; the first time I click any row, the dialog pops up but data does not seem to go through because there are no logs in the console.

  2. After I close the dialog, second click onward, data does seem to go to the Bank Ledger Component, but the table does not show any data. Also, data gets stored din the filteredData property of MatDataSource.

Console log of bankLedger property

Console log of BankLedgerDataSource

  1. The results after are same 3rd click onward, but with an exception; after the 3rd click, console logs data 2 times instead of 1. In the 4th click, data is logged 3 times. And it continues so on and so forth.

Console log of corresponding clicks

Please help. I am stumped.

How to override javascript function “_title_changed” in webclient odoo

My goal is to change the Page title using the company name. I am trying to change the function but still there’s no effect. Any idea on how to achieve this?

var session = require('web.session');
var AbstractWebClient = require('web.AbstractWebClient');

AbstractWebClient.include({
    _title_changed: function () {
        this._super();
        var company_name = session.user_companies.current_company[1];
        document.title = company_name;
        console.log('_title_changed function');
    },
});

Fluent UI style not working in passed commands with buttons to CommandBar

i am using Fluent UI in my project. I dont know how to change hoover style in CommandBar.

I initializing my buttons with this simple code in javascript:

// inside `buttons` array
key: 'newfolder',
text: 'New Folder',
iconProps: { 
    iconName: 'NewFolder',
        styles: {
           root: { 
              color: 'orange' 
           }, 
           rootHovered: { 
              color: 'red' 
           }
    } 
},
onClick: ...

Then i am passing this buttons to CommandBar:

<CommandBar
    items={buttons}
        styles={{
            root: {
                paddingLeft: '5px'
            },
    }}
/>

and i can override default color to asked one.
enter image description here

My question is, how to set mouse hover color over button in CommandBar component? enter image description here

As you can see, it is still blue even if i passed red as rootHovered color

Boolean flickering from true to false

I’m trying to switch the position of an element between fixed and absolute based on how close the element is to the other. So I have a button which is fixed from the top to the bottom till it’s bottom value + 25px is less or equal to footers y value so that it stops to the top. My problem is that the button stops in the right place so the switch from fixed to absolute goes well but while the relative position of the button to the footer are negative the boolean which toggles the classes of the button flickers between true and false so that it goes from absolute to fixed back and forth very quickly.

This is my code that is tracking the position & switching the boolean:

Is there a logic issue or what? I cannot figure this out:(

var button = document.querySelector('.bottomCtaFixed')
            var footer = document.querySelector('.footer')
            window.addEventListener('scroll', (e) => {

                var buttonRect = button.getBoundingClientRect()
                var buttonBottom = buttonRect.bottom + 25

                var footerRect = footer.getBoundingClientRect()
                var footerTop = footerRect.y

                var relativePos = footerTop - buttonBottom
                console.log('button', buttonRect)
                console.log('footer', footerRect)
                console.log('buttonBottom', buttonBottom)
                console.log('relativePos', relativePos)

                if(relativePos <= 0) {
                    this.isStill = true
                    if(footerTop >= buttonBottom) {
                        this.isStill = false
                    } else {
                        this.isStill = true
                    }
                } else {
                    this.isStill = false
                }
                console.log(this.isStill)
            })

And here’s the classes:

.bottomCtaFixed {
        position: fixed;
        bottom: 25px;
        left: 25px;
        margin-top: 25px;
        width: calc(100% - 50px);
        z-index: 101;
        @media screen and (max-width: 290px) {
            display: none
        }
        @media screen and (min-width: $bp-xs) {
            display: none
        }
    }
    .bottomCtaStill {
        position: absolute; 
        top: calc(-9vh - 25px);
        left: 25px;
        width: calc(100% - 50px);
        z-index: 101;
        @media screen and (max-width: 290px) {
            display: none
        }
        @media screen and (min-width: $bp-xs) {
            display: none
        }
    }

Understand the following exercise of js loops and strings in array

I’m trying to make sense of the following javascript exercise but can’t seem to make sense of it, all I know for now is that I can access each string with “acrostic[i]” where the i would be the number in the array but don’t know where to go from there.

const acrostic = [
  "Give me your patience, sister, while I frame",
  "Exact in capitals your golden name;",,
  "Or sue the fair Apollo and he will",
  "Rouse from his heavy slumber and instill",
  "Great love in me for thee and Poesy.",
  "Imagine not that greatest mastery",
  "And kingdom over all the Realms of verse,",
  "Nears more to heaven in aught, than when we nurse",
  "And surety give to love and Brotherhood.",
  " ",
  "Anthropophagi in Othello's mood;",
  "Ulysses storm'd and his enchanted belt",
  "Glow with the Muse, but they are never felt",
  "Unbosom'd so and so eternal made,",
  "Such tender incense in their laurel shade",
  "To all the regent sisters of the Nine",
  "As this poor offering to you, sister mine.",
  " ",
  "Kind sister! aye, this third name says you are;",
  "Enchanted has it been the Lord knows where;",
  "And may it taste to you like good old wine,",
  "Take you to real happiness and give",
  "Sons, daughters and a home like honied hive."
];

/* Declare a variable that will return the final string */
let georgianaAugustaKeats = "acrostic[i][0]";

for (let i = 0; i < acrostic.length; i += 1) {
  /* add each first character of each string to the array
   to the georgianaAugustaKeats variable*/
 
}
console.log(georgianaAugustaKeats);