Wednesday, May 26, 2021

Recent Questions - Stack Overflow

Recent Questions - Stack Overflow

Recent Questions - Stack Overflow


How to assign clearInterval function to the button which would stop the function started by another button?

Posted: 26 May 2021 08:14 AM PDT

As I understood from MDN, I am supposed to make variable and assign setInterval function to it, so that I could use that variable and call clearInterval for it, but for some reason, my code is now working. It is properly fetching data with buttonStart, but will not stop fetching data with buttonStop. Thank you for your time.

const buttonStart = document.querySelector('#start')  const buttonStop = document.querySelector('#stop')  const list = document.querySelector('#list')    class Price {   constructor(time, price) {       this.time = time       this.price = price   }  }    const fetchBitcoin = async () => {   try {       const res = await fetch('https://api.cryptonator.com/api/ticker/btc-usd');       const data = await res.json();       const newPrice = new Price(data.timestamp, data.ticker.price)       return newPrice   } catch (e) {       console.log("Something went wrong in downloading price", e)   }  }    const addNewPrice = async () => {   const newLI = document.createElement('LI')   const newElement = await fetchBitcoin()   const newTime = convertTime(newElement.time)   newLI.append(newTime, ' ', newElement.price.slice(0, 8))   list.append(newLI)  }    function convertTime(time) {   let unix_timestamp = time   var date = new Date(unix_timestamp * 1000);   var hours = date.getHours();   var minutes = "0" + date.getMinutes();   var seconds = "0" + date.getSeconds();   var formattedTime = hours + ':' + minutes.substr(-2) + ':' + seconds.substr(-2);   return formattedTime  }    let interval = buttonStart.addEventListener('click', () => {   setInterval(addNewPrice, 2000)  })    buttonStop.addEventListener('click', () => clearInterval(interval));```  

Can't resolve all parameters for ActivatedRoute : Injecting value from the Parent component to child in angular

Posted: 26 May 2021 08:14 AM PDT

I had added the provider as activateRoute and then trying to override its value in the parent component and then I need to use the overridden value in the child component. The child component is called from the parent component.

import { Component, Input } from '@angular/core';  import { ActivatedRoute } from '@angular/router';    @Component({      selector: `audit-details-ng9-wrapper`,      template: `          <app-audit-tab></app-audit-tab>`,      providers: [ActivatedRoute],  })  export class AuditDetailsNg9WrapperComponent {      @Input() dossierId: number;        constructor(          private route: ActivatedRoute) {          this.route.snapshot.params.dossierId = this.dossierId;      }  }  

I had done the above coding , dossierId is the input field which is now getting set to the ActivateRoute component value through this.route.snapshot.params.dossierId = this.dossierId;

` is the child component in which I need to retrieve the value which is set in this.route.snapshot.params.dossierId

  @Component({          selector: 'app-audit-tab',          templateUrl: './audit-tab.component.html',      })      export class AuditTabComponent implements OnInit, OnDestroy {          private readonly destroy$ = new Subject();          dossierId: number;                constructor(private route: ActivatedRoute) {          }                ngOnInit(): void {              this.dossierId = this.route.snapshot.params.dossierId;                       }          ngOnDestroy() {              this.destroy$.unsubscribe();          }      }  

In the above code I am trying to retrieve the value this.route.snapshot.params.dossierId, which I had set in the parent component (AuditDetailsNg9WrapperComponent ), but while I am encountering the issue Can't resolve all parameters for ActivatedRoute.

How do you add :id to react route

Posted: 26 May 2021 08:14 AM PDT

Totally new to React. Needing t update some code that was not written by me, so I am trying to keep as much as I can (although I'm not sure if I can at this point).

I am passing in a folder_id value to the component like this (I can also get the folder_id value from the props just as is so if there is a way to assign the variable inside the component I could do that, and would prefer to as well)

<div id="react-single-post-viewer">    <%= react_component('SinglePostApp', {folder_id: params[:folder_id]}) %>  </div>  

Inside the component there is this routes assignment

routes =    `<Route handler={SinglePostApp}>      <Route name="recommended" path="/reading/posts/recommended/?:id?" handler={SinglePostViewer} />      <Route name="all" path="/reading/posts/all/?:id?" handler={SinglePostViewer} />      <Route name="folder_all" path="/reading/fo/folder/{this.props.folder_id}/all/?:id?" handler={SinglePostViewer} />    </Route>`  

Right now the {this.props.folder_id} does not fill in the value, I also tried ${this.props.folder_id} from a tutorial I found but that did not work either. If I hard code the id in there is works but I cannot figure out how to get this id value dynamically.

It is included inside the props value so I could access it like this too @props.params.folder_id. I tried using that to assign to a variable and place it inside the route bit but that did not work either.

How to run an open file instead of the main one?

Posted: 26 May 2021 08:13 AM PDT

I'm trying to run a file, but it always run the main one of the project. Is there a way to run the file in the screen without having to create another project?

Xunit | HangFire Jobs : How to write Xunit test case for testing if hangfire recurring jobs are working fine for an api (replication api)?

Posted: 26 May 2021 08:13 AM PDT

I have an API functionality to replicate data from SQL server to PostGres implemented on Hang Fire recurring jobs. I have to write a x-unit test case for verifying whether the hang fire recurring job is working perfectly fine. How can we write such test case?

defining global variables with vite development

Posted: 26 May 2021 08:13 AM PDT

Now I am using vite build tool for my vue SFC app. I read the documentation of vite with the link below:

vite config link

If I am not wrong, the define option in config could be used for defining global constants. What I want to do is to define for example the name of my App in a variable inside this option and then use it in my Vue components. But unfortunately there is no example of code in the documentation about this option.

I tried this code in my vite.config.js file:

import { defineConfig } from 'vite'  import vue from '@vitejs/plugin-vue'    // https://vitejs.dev/config/  export default defineConfig({    define: {        global: {          appName: "my-custom-name"        }    },    plugins: [vue()]  })

I am not sure that the syntax and code is correct! And also if it is correct I don't know how to call (use) this constant in my vue app components (.vue files). For example I want to use it in template or script part of this component:

<template>      <div class="bgNow">        <p class="color1">  {{ use here }}      </p>    </template>    <script>        export default {          data() {              return {                name: use here              };          },                    methods: {              nameMethod() {                                                      console.log(use here);                                }            } // end of method        } // end of export  </script>    <style scoped></style>

I declared the places that want with "use here" in the code. And also if there is any other way that I could define some global constants and variables in my vite vue app, I very much appreciate your help to tell me about that.

Gatsbyjs - GraphQL slug with order number from created_at date

Posted: 26 May 2021 08:13 AM PDT

is it possible to make slug with created_at date that the oldest post would start with slug: "1" and so on like in my example?

Example

Let's say that we have 4 posts(.md files).

  • created_at: "05-26-2021:14:20" -> newest would be slug: "4"
  • created_at: "05-24-2021:11:43" -> would be slug: "3"
  • created_at: "05-24-2021:09:12" -> would be slug: "2"
  • created_at: "05-23-2021:15:34" -> oldest would be slug: "1"
export const pageQuery = graphql`  {    allMarkdownRemark(    filter: {fileAbsolutePath: {regex: "/data/posts/"}}    sort: {order: DESC, fields: frontmatter___created_at}    ) {    edges {        node {        id        fields {            slug        }        frontmatter {            title            created_at        }        html        }    }    }  }  `  

I found a example on how to create new slug node in Gatsbyjs docs, but I'm not able to solve my issue, if anyone could help me with this thank you.

exports.onCreateNode = ({ node, getNode, actions }) => {    const { createNodeField } = actions    if (node.internal.type === `MarkdownRemark`) {      const slug = createFilePath({ node, getNode, basePath: `data` })      createNodeField({        node,        name: `slug`,        value: slug,      })    }  }  

Disable or Hide standard button in Acumatica

Posted: 26 May 2021 08:13 AM PDT

enter image description here

Tell me please how I can Hide the ADD LC button, since it is defined in the acumatica code that it is displayed by condition.

This is the standard acumatica code that displays this button

#region Actions            public PXAction<APInvoice> addLandedCost;          public PXAction<APInvoice> addLandedCost2;            [PXUIField(DisplayName = "Add LC", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select, Visible = true)]          [PXLookupButton]          [APMigrationModeDependentActionRestriction(              restrictInMigrationMode: true,              restrictForRegularDocumentInMigrationMode: true,              restrictForUnreleasedMigratedDocumentInNormalMode: true)]          public virtual IEnumerable AddLandedCost(PXAdapter adapter)          {              if (Base.Document.Current != null &&                  Base.Document.Current.Released != true)              {                  if (LandedCostDetailsAdd.AskExt((graph, view) =>                  {                      landedCostFilter.Cache.ClearQueryCacheObsolete();                      landedCostFilter.View.Clear();                      landedCostFilter.Cache.Clear();                        LandedCostDetailsAdd.Cache.ClearQueryCacheObsolete();                      LandedCostDetailsAdd.View.Clear();                      LandedCostDetailsAdd.Cache.Clear();                  }, true) == WebDialogResult.OK)                  {                      return AddLandedCost2(adapter);                  }              }                return adapter.Get();          }            [PXUIField(DisplayName = "Add LC", MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select, Visible = true)]          [PXLookupButton]          [APMigrationModeDependentActionRestriction(              restrictInMigrationMode: true,              restrictForRegularDocumentInMigrationMode: true,              restrictForUnreleasedMigratedDocumentInNormalMode: true)]          public virtual IEnumerable AddLandedCost2(PXAdapter adapter)          {              if (Base.Document.Current != null &&                  Base.Document.Current.DocType.IsIn(APDocType.Invoice, APDocType.DebitAdj) &&                  Base.Document.Current.Released == false &&                  Base.Document.Current.Prebooked == false)              {                  var landedCostDetails = LandedCostDetailsAdd.Cache.Updated.RowCast<POLandedCostDetailS>().Where(t => t.Selected == true).ToArray();                  Base.AddLandedCosts(landedCostDetails);                  landedCostDetails.ForEach(t => t.Selected = false);              }              return adapter.Get();          }            

No comments:

Post a Comment