Angular - can't sum point - angular8

I want to sum point but now I try write function and console.log(total) but it happens is 'undefined'
app.ts
saveTasks() {
if (this.tasksToSave.length != 0) {
for (let i = 0; this.tasksToSave.length > i; i++) {
this.ticketService.setAddTasks(
this.id,
this.tasksToSave[i]
)
}
}
}
sumPoint() {
let total = 0
if (this.tasksToSave.length != 0) {
for (let i = 0; i < this.tasksToSave.length; i++) {
total = total + this.tasksToSave[i].point
}
}
}
app.html
total = {{total}}

Put the total variable in the export block in the component like below:
export class YourComponent implements OnInit {
...
total: number = 0;
...
sumPoint() {
if (this.tasksToSave.length != 0) {
for (let i = 0; i < this.tasksToSave.length; i++) {
this.total = this.total + this.tasksToSave[i].point
}
}
}
...
}

Related

My Vue.js code is giving me null, instead of adm's ID with idRecord comparison

I am just receiving the null as return after trying to solve by using the forEach() and I don't knw what to do from now on.
`/*
console.log(this.optionIdRecord)
console.log(this.Business)
for (let i = 0; i < this.optionIdRecord.length; i++) {
for (let j = 0; j < this.Business.length; j++) {
if (this.Business[j].idRecord == this.optionIdRecord[i].id) {
console.log(this.Business[j])
console.log(this.optionIdRecord[i])
}
}
}
*/
this.optionIdRecord.forEach((admElement) => {
this.Business.forEach((businessElement) => {
if (admElement.id === businessElement.idRecord) {
console.log(admElement)
console.log(businessElement)
}
})
})`

calling a function inside mongoose hook 'post save' returns same doc

In my schema I'm having a post save hook like
DateInfoSchema.post('save', function (doc) {
var newDoc = helper. getListTimeRate(doc);
console.log(newDoc);
});
Then I'm having a helper module in that I'm having a function to calculate date range
lets consider 'doc' startdate and enddate so I want to calculate date range from start date to enddate
module.exports = {
getListTimeRate: function (data, yearEndDate) {
var toDate = new Date(),
weekName = ["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];
Date.prototype.addDays = function(days) {
var dateAdd = new Date(this.valueOf());
dateAdd.setDate(dateAdd.getDate() + days);
return dateAdd;
};
function getDates(startDate, stopDate) {
var dateArray = [];
var currentDate = startDate;
if (currentDate == undefined){
while (currentDate <= stopDate) {
dateArray.push(currentDate);
currentDate = currentDate.addDays(1);
}
return dateArray;
}else {
var newCurrentDate = new Date(currentDate.toISOString().substr(0,10));
var newStopDate = new Date(stopDate.toISOString().substr(0,10));
while (newCurrentDate <= newStopDate) {
dateArray.push(newCurrentDate);
newCurrentDate = newCurrentDate.addDays(1);
}
return dateArray;
}
}
function calcRange(entry) {
// function get time
var dateList = [],
newList = [];
if (toDate < entry.endDate) {
// calc from endDate
newList = getDates(entry.startDate, entry.endDate);
//status often
selectDateFromOften();
} else {
if (yearEndDate) {
newList = getDates(entry.startDate, entry.endDate);
} else {
newList = getDates(entry.startDate, toDate);
}
// calc from toDate
//status often
selectDateFromOften();
}
function getDateTimeAnother() {
if (entry.hour) {
var setHour = entry.hour.getHours(),
setMin = entry.hour.getMinutes(),
setSecond = entry.hour.getSeconds();
}
dateList.forEach(function(entryDate){
entryDate.setHours(setHour);
entryDate.setMinutes(setMin);
entryDate.setSeconds(setSecond);
});
entry.rangeDate = dateList;
var compareUsedDate = [];
_.forEach(entry.frequencyId, function(value) {
compareUsedDate.push(value.dateRated);
});
entry.rangeDate = _.differenceBy(entry.rangeDate, compareUsedDate,Math.floor);
entry.rangeDate = entry.rangeDate.filter(function( element ) {
return element !== undefined;
});
console.log(dateList);
if (yearEndDate) {
return dateList;
}
}
function selectDateFromOften() {
switch(entry.oftenStatus) {
// Daily
case "0":
for (var i = 0; i< newList.length; i++) {
dateList.push(newList[i]);
}
getDateTimeAnother();
break;
//Weekly
case "1":
for (var i = 0; i< newList.length; i++) {
if (i == 0 || i % 7 == 0) {
dateList.push(newList[i]);
}
}
getDateTimeAnother();
break;
//Bi-Weekly
case "2":
for (var i = 0; i< newList.length; i++) {
if (i == 0 || i % 14 == 0) {
dateList.push(newList[i]);
}
}
getDateTimeAnother();
break;
//Monthly
case "3":
// for (var i = newList.length-1; i >= 0; i--) {
for (var i = 0; i< newList.length; i++) {
if (i == 0 || i % 28 == 0) {
dateList.push(newList[i]);
}
}
getDateTimeAnother();
break;
//Custom Date
case "4":
dateList = newList;
getDateCustom();
break;
default:
}
}
}
if (data.length) {
_.forEach(data, function(entry) {
if(entry.startDate != undefined){
calcRange(entry);
}
});
} else {
if(data.startDate != undefined){
calcRange(data);
}
}
return data;
}
};
But inside the hook 'newDoc' doesn't have 'rangeDate' field in it. Can anyone help me solve this issue? Thank you.

how to execute a function after end another in react native?

I have a query that I have a function which response to a server, so it takes a while and when it tries to execute the other function, an error occurs. Since the function responds an array from which comes from the server and when the other function requests that, even It does not have. Have to solve this. example :
responseServer(tarea) {
return fetch(url)
.then((response) => response.json())
.then((responseJson) => {
this.setState({ refresh: false })
global.refresh = false
let data = [];
let Milestone = [];
Object.values(responseJson.summary).forEach(item => {
data = data.concat(item);
});
const result = ["Milestone"]
.reduce((total, category) => ({
...total,
[category]: data.filter(line => line.includes(category))
}), {})
Object.values(result.Milestone).forEach(item => {
Milestone = Milestone.concat(item)
});
this.setState({
Milestone: Milestone
})
})
}
and another function
sacarPorcentaje(item) {
this.responseServer(item)
let summaryCopy = this.state.Milestone.map(data => {return data.split(",")})
console.log(summaryCopy)
var Okeys = 0;
var total = 0;
for (var i = 0; i < summaryCopy.length; i++){
for(var j = 0; j < summaryCopy[i].length; j++){
if(summaryCopy[i][j] === "OK") {
Okeys = Okeys + 1
}
}
total = total + 1
}
console.log(Okeys)
console.log(total)
}
You should update sacarPorcentaje() to async function. then await the function call, will resolve your issue
async sacarPorcentaje (item) {
await this.responseServer(item)
let summaryCopy = this.state.Milestone.map(data => {return data.split(",")})
console.log(summaryCopy)
var Okeys = 0;
var total = 0;
for (var i = 0; i < summaryCopy.length; i++){
for(var j = 0; j < summaryCopy[i].length; j++){
if(summaryCopy[i][j] === "OK") {
Okeys = Okeys + 1
}
}
total = total + 1
}
console.log(Okeys)
console.log(total)
}
There is also one more solution for this issue. please search how to use Promise in JS
I think you need to use then when you call responseServer function in sacarPorcentaje function.
sacarPorcentaje(item) {
this.responseServer(item).then(() => {
let summaryCopy = this.state.Milestone.map(data => {return data.split(",")})
console.log(summaryCopy)
var Okeys = 0;
var total = 0;
for (var i = 0; i < summaryCopy.length; i++){
for(var j = 0; j < summaryCopy[i].length; j++){
if(summaryCopy[i][j] === "OK") {
Okeys = Okeys + 1
}
}
total = total + 1
}
console.log(Okeys)
console.log(total)
}
}

Tedious node.js SQL connection; want to insert multiple values from an array

I'm running a loop and trying to insert the multiple values from an array while running it.
Here is the code:
function GetJobsToCourseID(index, jobData){
if((jobData != undefined)||(jobData != null)){
var extrArray = [];
for(var i = 0 ; i< jobData.length; i++){
extrArray = jobData[i];
for (var j=0; j<extrArray.length; j++)
{
console.log(extrArray[j]);
requestID = new Request("SELECT IDKey from dbo.Jobz where SubJobFamily ='"+extrArray[j]+"'", function(err, rowCount){
if (err) {
console.log(err);
}
else { connection111.reset(function(err){});
}
});
}
}
}
requestID.on('row', function(columns) {
for (var i = 0; i <columns.length; i++)
{
console.log(columns[i].value, "Please work");
if (columns[i].value == null || columns[i].value == undefined) {
console.log('NULL');
} else {
}
}
connection111.execSql(requestID);
});
}
As you can see I'm trying to insert the j element of my tempArray(I dont think it should work anyways, because of how Tedious connections work)
What would be the approach then - extracting each array element and populating it withing the SQL table using Tedious?
Fixed it by adding a connection pool and an changing the second loops var j to let j ... 'tedious' is really tedious...
here is the code:
function GetJobsToCourseID(index, jobData){
if((jobData != undefined)&&(jobData != null)){
var extrArray = [];
var newArray = [];
for(var i = 0 ; i< jobData.length; i++){
extrArray = jobData[i];}
for (let j=0; j<extrArray.length; j++){
pool.acquire(function (err, connection1111) {
if (err)
console.error(err);
requestID = new Request("SELECT IDkey from dbo.Jobz where SubJobFamily ='"+extrArray[j]+"'", function(err, rowCount){
if (err) {
console.log(err);
}
else {connection1111.reset(function(err){});}});
requestID.on('row', function(columns) {
for (var i = 0; i <columns.length; i++){
if (columns[i].value == null || columns[i].value == undefined) {
console.log('NULL');
} else {
arty.push(columns[i].value);
console.log(arty);
}}
});
connection1111.execSql(requestID);
});}
pool.on('error', function (err) {
console.error(err);
});
}}

FBJS image slider

Im trying to recreate a slider similar to:
http://www.facebook.com/BacardiLimon?v=app_146177448730789
but apparently there is zero documentation on how to do something like this with FBJS :'(
var eCardPos = 0;
var totalCards = 4;
var animationFadeTime = 300;
var cardUrls = [];
cardUrls[0]= '';
cardUrls[1]= '';
cardUrls[2]= '';
cardUrls[3]= '';
function changeEcardPrev()
{
eCardPos--;
if (eCardPos < 0) {
eCardPos = totalCards-1;
}
showEcard();
}
function changeEcardNext()
{
eCardPos++;
if (eCardPos > totalCards-1) {
eCardPos = 0;
}
showEcard();
}
function changeEcard(pos)
{
eCardPos = pos;
showEcard();
}
function showEcard()
{
var elCard = document.getElementById('cardImage');
var elLink = document.getElementById('cardLink');
var elPreload = document.getElementById('preload_card_'+eCardPos);
for (var i=0;i<totalCards;i++)
{
document.getElementById('cardButton_'+i).removeClassName('active');
}
document.getElementById('cardButton_'+eCardPos).addClassName('active');
elLink.setHref(cardUrls[eCardPos]);
Animation(elCard).to("opacity", 0).duration(animationFadeTime).checkpoint(1, function() {
elCard.setSrc(elPreload.getSrc());
}).to("opacity", 1).duration(animationFadeTime).go();
//Animation(elCard).to("opacity", 1).duration(animationFadeTime).go();
}
I happened to find the src but I dont even know where to start :\
EDIT:
I think I found something that might help but the images slide :\ I just want them to appear when a direction is pressed.
var numslides = 3;
var slidesvisible = 1;
var currentslide = 0;
var slidewidth = 300;
function goright() {
if (currentslide <= (numslides-slidesvisible-1)) {
Animation(document.getElementById('slideshow_inner')).by('right', slidewidth+'px').by('left', '-'+slidewidth+'px').go();
if (currentslide == (numslides-slidesvisible-1)) {
Animation(document.getElementById('right_button')).to('opacity', '0.3').go();
Animation(document.getElementById('left_button')).to('opacity', '1').go();
}
if (currentslide < (numslides-slidesvisible-1)) { Animation(document.getElementById('left_button')).to('opacity', '1').go(); }
currentslide++;
}
}
function goleft() {
if (currentslide > 0) {
Animation(document.getElementById('slideshow_inner')).by('left', slidewidth+'px').by('right', '-'+slidewidth+'px').go();
if (currentslide == 1) {
Animation(document.getElementById('left_button')).to('opacity', '0.3').go();
Animation(document.getElementById('right_button')).to('opacity', '1').go();
}
if (currentslide > 1) { Animation(document.getElementById('right_button')).to('opacity', '1').go(); }
currentslide--;
}
}
How would I get the image to fade in and out rather than slide?