JavaScript: xstate: DevExpress: show loading panel - devexpress

I have an ajax call that fetches data and I have an xstate state machine that invokes this ajax call. I would like to show a spinning wheel(DevExpress loading panel) while data is being fetched. How do I show this loading panel?
function getTransactions(){
return new Promise((resolve, reject) => {
try {
resolve(0);
} catch (error) { reject('[ErrorCode:-96] Unable to retrieve transactions'); }
});
}
const loadPanel = $('.loadpanel').dxLoadPanel({
shadingColor: 'rgba(0,0,0,0.4)',
position: { of: '#employee' },
visible: false,
showIndicator: true,
showPane: true,
shading: true,
hideOnOutsideClick: false
}).dxLoadPanel('instance');
/* code */
gettingTransactions: {
entry: 'showLoadingPanel',
exit: 'hideLoadingPanel',
invoke: {
src: (context, event) => getTransactions(),
onDone: {
target: 'success',
actions: assign({ returnCode: (context, event) => event.data })
},
onError: {
target: 'showingAlert',
actions: assign({ errorMessage: (context, event) => event.data })
}
}
},
/*code */
I would like to show a loading panel while getTransactions is being executed. The above code is not working and there's no error.

I used activities to code showing a loading panel.
https://xstate.js.org/docs/guides/activities.html#interpretation
function createLoadingActivity(context, activity) {
// Start the beeping activity
var loadPanel = $(".loadpanel").dxLoadPanel({
shadingColor: "rgba(0,0,0,0.4)",
position: { my: 'center', at: 'center', of: window },
visible: false,
showIndicator: true,
showPane: true,
shading: true,
closeOnOutsideClick: false
}).dxLoadPanel("instance");
loadPanel.show();
const interval = setInterval(() => {
console.log('Waiting...');
}, 1000);
// Return a function that stops the beeping activity
return (() => { loadPanel.hide(); clearInterval(interval); });
}

Related

I am using discord.js v14 and I made button. I Get Error Interaction has already been acknowledged

When I Click On It Once It Replies, But Second Time It Replies But Crashes Saying Interaction has already been acknowledged.
I dont wanna Make A Event Handler
I am New
So Can Someone Help Me With Example Code?
Here's My Code
import { Client, GatewayIntentBits, Partials, ActionRowBuilder, ButtonBuilder, ButtonStyle } from "discord.js";
const client = new Client({
'intents': [
GatewayIntentBits.DirectMessages,
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildBans,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
],
'partials': [Partials.Channel]
});
client.once('ready', () =>{
console.log(`${client.user.username} Is Online!`);
client.user.setActivity(`>>rank`, { type: "WATCHING" });
});
client.on("messageCreate", (message) => {
const btn1 = new ButtonBuilder()
.setCustomId('btn1')
.setLabel('Click Me!')
.setStyle('Primary')
if (message.content === 'hi'){
return message.channel.send({
content: 'HI' , components:[new ActionRowBuilder().addComponents(btn1)]
})
}
client.on('interactionCreate', async interaction => {
if(interaction.isButton){
await interaction.deferUpdate();
if(interaction.customId === 'btn1'){
await message.channel.send('Um Hello');
}
}
});
});
client.login('TOKEN');
As #Zsolt Meszaros Said I Removed The Interaction Handler From Message Handler And Placed It Down It So It Fixed The Problem
import { Client, GatewayIntentBits, Partials, ActionRowBuilder, ButtonBuilder, ButtonStyle } from "discord.js";
const client = new Client({
'intents': [
GatewayIntentBits.DirectMessages,
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildBans,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
],
'partials': [Partials.Channel]
});
client.once('ready', () =>{
console.log(`${client.user.username} Is Online!`);
client.user.setActivity(`>>rank`, { type: "WATCHING" });
});
client.on("messageCreate", (message) => {
const btn1 = new ButtonBuilder()
.setCustomId('btn1')
.setLabel('Click Me!')
.setStyle('Primary')
if (message.content === 'hi'){
return message.channel.send({
content: 'HI' , components:[new ActionRowBuilder().addComponents(btn1)]
})
}
});
client.on('interactionCreate', async interaction => {
if(interaction.isButton){
await interaction.deferUpdate();
if(interaction.customId === 'btn1'){
await interaction.channel.send('Um Hello');
}
}
});
client.login('SUPER SECRET TOKEN');

Using Vue, but I can't query information from Firebase to display values in a chart/graph (google charts or GChart). "Error: Table has no columns."

This code is inside a .vue file. Receiving the "Error: Table has no columns." Inside the methods function, it won't receive the values from firebase to display a chart/graph to web app. What am I doing incorrectly? I think the values am I trying to receive inside "chartData:[ ]" or "mounted()" is incorrect and may be causing the issue. Any help is much appreciated.
export default {
name: "App",
components: {
GChart
},
methods: {
getHumidity(){
get(
query(ref(db, auth.currentUser.uid + "/Environment/humidity"),
orderByChild("humidity")
)
).then((snapshot) => {
if (snapshot.exists()) {
console.log(snapshot.val());
for (const item in snapshot.val()) {
this.pgoods.push({
humidity: snapshot.val()[item].humidity,
expir: snapshot.val()[item].humidity,
});
}
} else {
this.pgoods = [];
}
return float(snapshot.val());
});
}
getPressure(){
get(
query(ref(db, auth.currentUser.uid + "/Environment/pressure"),
orderByChild("pressure")
)
).then((snapshot) => {
if (snapshot.exists()) {
console.log(snapshot.val());
for (const item in snapshot.val()) {
this.pgoods.push({
pressure: snapshot.val()[item].pressure,
expir: snapshot.val()[item].pressure,
});
}
} else {
this.pgoods = [];
}
return float(snapshot.val());
});
}
getTime(){
get(
query(ref(db, auth.currentUser.uid + "/Environment/time"),
orderByChild("time")
)
).then((snapshot) => {
if (snapshot.exists()) {
console.log(snapshot.val());
for (const item in snapshot.val()) {
this.pgoods.push({
time: snapshot.val()[item].time,
expir: snapshot.val()[item].time,
});
}
} else {
this.pgoods = [];
}
return float(snapshot.val());
});
},
},
data(){
return{
chartData: [
["Time", "Pressure", "Humidity"],
[this.getTime(), this.getPressure(), this.getHumidity()],
[this.getTime(), this.getPressure(), this.getHumidity()],
],
},
mounted(){
this.getTemperature();
this.getHumidity();
},
}

Multiple delete requests occurred in vue2Dropzone

i use laravel6,vue. in my project i use vue2Dropzone.
i made photo update fuction. but it does not work.
I want to load and delete the image of the server on dropzone.
but after delete image on dropzone and i refresh page or go to another page delete method called as many images as it does.
i cant solve this problem.
In chrome network tab, Requests are generated by the number of photoLen in loadPhoto .
enter image description here
photoEdit.vue
<div class="mt-4">
<vue-dropzone ref="myVueDropzone" id="dropzone" :options="dropzoneOptions" #vdropzone-removed-file="imageRemoved"></vue-dropzone>
</div>
data(){
dropzoneOptions: {
url: `/api/photo/${this.$route.params.id}`,
addRemoveLinks: true,
dictRemoveFile: 'delete',
createImageThumbnails: true,
thumbnailWidth: 150,
parallelUploads: 50,
autoProcessQueue: true,
maxFileSize: 100,
timeout: 100000,
maxFiles: 50,
maxThumbnailFilesize: 100,
uploadMultiple: true,
dictDefaultMessage: "click and drag",
acceptedFiles: 'image/*',
headers: {
"X-CSRF-TOKEN": document.head.querySelector("[name=csrf-token]").content,
}
},
}
mounted() {
this.loadPhoto();
},
methods:{
loadPhoto() {
axios.get(this.apiUrl).then((response) => {
this.photo = response.data.data[0];
var photoLen = this.photo.photo_images.length;
console.log(photoLen);
for (var i = 0; i < photoLen; i++) {
var file = {size: 123, name: this.photo.photo_images[i].image_name};
var url = this.photo.photo_images[i].path;
this.$refs.myVueDropzone.manuallyAddFile(file, url);
}
}).catch(error => {
this.$router.push({name: 'adminPhoto'});
});
},
//vdropzone-removed-file called when dismount the component
imageRemoved(file, error, xhr) {
// alert(file);
//todo 해당경로로 갈시 삭제
var name = file.name;
console.log(file);
axios.post('/api/photo/delete',{
image_name : name,
})
.then((response) => {
console.log(response);
}, (error) => {
// error callback
console.log(error);
})
var _ref;
return (_ref = file.previewElement) != null ? _ref.parentNode.removeChild(file.previewElement) : void 0;
},
}

ASP.NET MVC many to many relationship error

This is my controller :
public ActionResult PPKPIChart()
{
return View();
}
public ActionResult PPKPI()
{
var dt = db.Sales
.Where(ol => ol.SaleId != null)
.GroupBy(ol => ol.PPUsers.Where(p => p.Name != null))
.ToList()
.Select(g => new object[] {
g.Key,
g.Count()
}); ;
return Json(dt, JsonRequestBehavior.AllowGet);
}
Here is my view :
#section foot {
<script src="https://www.gstatic.com/charts/loader.js"></script>
<script>
google.charts.load('current', { packages: ['corechart'] });
google.charts.setOnLoadCallback(init);
let dt, opt, cht;
function init() {
dt = new google.visualization.DataTable();
// TODO: Data table columns
dt.addColumn('string', 'Name');
dt.addColumn('number', 'KPI');
let style = { bold: true, italic: false, fontSize: 20, color: 'purple' };
opt = {
title: 'Prepress Personnel KPI',
fontName: 'calibri',
fontSize: 14,
titleTextStyle: { fontSize: 20 },
chartArea: {
width: '80%',
height: '70%',
top: 60,
left: 80
},
// TODO: vAxis, hAxis, legend, animation, orientation
vAxis: {
title: 'KPI',
titleTextStyle: style
},
hAxis: {
title: 'Name',
titleTextStyle: style
},
legend: 'none',
animation: {
duration: 500,
startup: true
},
orientation: 'horizontal',
};
cht = new google.visualization.ColumnChart($('#chart')[0]);
$('#reload').click();
}
$('#reload').click(function (e) {
e.preventDefault();
let url = '/Home/PPKPI';
let param = {};
$.getJSON(url, param, function (json) {
dt.removeRows(0, dt.getNumberOfRows());
dt.addRows(json);
cht.draw(dt, opt);
});
});
$('#toggle').click(function (e) {
e.preventDefault();
// TODO: Toggle orientation (horizontal <--> vertical)
opt.orientation = opt.orientation == 'horizontal' ?
'vertical' : 'horizontal';
[opt.vAxis, opt.hAxis] = [opt.hAxis, opt.vAxis];
cht.draw(dt, opt);
});
</script>
This is my entity framework which have many to many relationships
I want to show a bar chart but because of many to many relationships I cannot do so especially at
GroupBy(ol => ol.PPUsers.Where(p => p.Name != null)) -- > i guess this is the issues behind it.. my query in this line is not working
Basically the relationships look like this :
It seems related PPUsers entities could not be loaded into Sales entity.
You can follow Eagerly Loading approach:
Eager loading is the process whereby a query for one type of entity
also loads related entities as part of the query. Eager loading is
achieved by use of the Include method.
To do so you can use Include to load related entities as follows:
var dt = db.Sales
.Include(s => s.PPUsers)
.Where(ol => ol.SaleId != null)
.GroupBy(ol => ol.PPUsers.Where(p => p.Name != null))
.ToList()
.Select(g => new object[] {
g.Key,
g.Count()
});
Entity Framework supports three ways to load related data - eager loading, lazy loading and explicit loading. Have a look at Loading Related Entities.
`public ActionResult TotalJobAssignedData()<br/>
{
var dt = db.PPUsers
.ToList()
.Select(g => new object[] {
g.Name,
g.Sales.Count()
});
return Json(dt, JsonRequestBehavior.AllowGet);
}

Why aren't my data points getting placed in the corresponding locations in my chart?

I have a Nuxt component that loads a chart using chart.js, filled with data from a Firestore database. The data points are loading as a flat line at the bottom of my chart. However, the data has different value ranges when hovered.
How do I get the data points to render in the correct locations to produce an actual graph?
I've tried using a loaded variable to load the chart after the Firestore data is retrieved. I end up with the exact same issue.
I've tried adding some static weight array data before the data is pushed to it. When doing that, it showed those points accurately, but the rest laid flat on the bottom (still showing valid data point values on hover).
<template>
<div id="container">
<canvas ref="chart"></canvas>
</div>
</template>
<script>
import { firebase, db } from '#/plugins/firebase'
import Chart from 'chart.js'
const color = ['#3AC', '#D91D63', '#5F6982', '#F4B651', '#3F4952']
export default {
data() {
return {
laoded: false,
weightData: [],
}
},
async mounted() {
// retrieve weight data from firebase
this.getWeightData()
const ctx = this.$refs.chart
const chart = new Chart(ctx, {
type: 'line',
data: {
labels: ['January', 'February', 'March', 'April', 'May', 'June'],
datasets: [{
data: this.weightData,
backgroundColor: color[0],
borderColor: color[0],
borderWidth: 1,
fill: false,
label: 'weight',
responsive: true
}]
},
options: {
legend: {
usePointStyle: true
},
scales: {
yAxes: [{
ticks: {
beginAtZero: true,
stepSize: 10
}
}]
},
tooltips: {
callbacks: {
afterBody(tooltip, dataset) {
let data = 'goal: goal here'
return data
}
}
}
}
})
},
methods: {
getWeightData() {
firebase.auth().onAuthStateChanged(async user => {
if (user) {
const data = await db.collection('users').doc(user.uid).collection('weight').get()
.then(querySnapshot => {
if (!querySnapshot.empty) {
querySnapshot.forEach(doc => {
this.weightData.push(doc.data().weight)
})
}
})
}
})
this.loaded = true
}
}
}
</script>
I expect a line graph with the data points from the weightData array. All I'm getting is a flat line with different values in the tooltips.
Also, the chart's range is 0 to 1, even though weightData values go up as far as 200.
getWeightData() populates weightData asynchronously, so you'd have to await the function call before proceeding with setting up the chart.
First, wrap getWeightData() in a Promise 1️⃣so that you could return the fetched weight data 2️⃣(instead of setting this.weightData inside the Promise):
methods: {
getWeightData() {
return new Promise((resolve, reject) => { /* 1 */
firebase.auth().onAuthStateChanged(user => {
if (user) {
db.collection('users')
.doc(user.uid)
.collection('weight')
.get()
.then(querySnapshot => {
const weightData = []
if (!querySnapshot.empty) {
querySnapshot.forEach(doc => {
weightData.push(doc.data().weight)
})
}
resolve(weightData) /* 2 */
})
.catch(reject)
} else {
reject()
}
})
})
}
}
Then in mounted(), store the awaited result of getWeightData() in this.weightData 3️⃣:
async mounted() {
this.weightData = await this.getWeightData() /* 3 */
/* now, setup chart with `this.weightData` */
}

Resources