I just found the Firebase API and really like it. However, I was looking at the Leader board sample and was wondering if add a new column:
userScoreRef.setWithPriority({ name:name, score:newScore, board:myboard }, newScore);
can I use this to separate the return to add it to different boards? Something like:
if (prevScoreName === null) {
if (myBoaard == 'Board1') { $("#leaderboardTable1").append(newScoreRow); }
if (myBoaard == 'Board2') { $("#leaderboardTable2").append(newScoreRow); }
if (myBoaard == 'Board3') { $("#leaderboardTable3").append(newScoreRow); }
if (myBoaard == 'Board4') { $("#leaderboardTable4").append(newScoreRow); }
if (myBoaard == 'Board5') { $("#leaderboardTable5").append(newScoreRow); }
}
else {
var lowerScoreRow = htmlForPath[prevScoreName];
lowerScoreRow.before(newScoreRow);
}
Or is there a better way to do this without rewriting the entire code 5 times?
Thanks
You should get the number of the current board and use that to add the score to different boards, like this:
if (prevScore === null) {
var leaderBoardTable = "leaderboardTable" + myBoard.charAt(myBoard.length-1);
$("#" + leaderBoardTable).append(newScoreRow);
}
Related
I want to check my URL content and do something like this:
if (URL.include('path')) {
//do something
} else {
// do something else
}
I can check my URL like this
cy.url().should('include', 'path');
but when I am pasting it in if operator it is not working.
Will recommend you to use .includes() method. It determines whether a string contains the characters of a specified string:
const path = 'user/survey';
cy.url().then(($url) => {
if($url.includes(path)) {
cy.log("Yes")
} else {
cy.log("No")
}
})
You can combine location() with then().
Here is how I do it:
cy.location('pathname').then((loc) => {
if(loc == '/my/path') {
...do
} else {
...smth else
}
})
I hope it solves your issue,
Best
I found The answer, but its vary long. Any ideas pls.
cy.url().then(url => {
const currentURL = url.split('/path/');
const pathURL = currentURL[1];
if(pathURL === 'user/survey')
{
cy.log('aaaaaaaaaa')
} else {
cy.log('bbbbbbbbb')
}
})
I am able to show marker/icons using google map data layer and geoJson file(s). But instead of icons, is it possible to show a text (at particular location on map)?
It should not be part of InfoWindow. I am looking for something like Sample
I have tried using 'title' but it's just a label shown on mouse over of icon. Please help.
gmap.addListener('zoom_changed', function () {
var gmapZoom = gmap.GetZoom();
if (gmapZoom >= 0 && gmapZoom <= 21)
{
if (bJSONLoaded === false)
{
var setDataStyle = function (feature) {
var status = feature.getProperty('status');
switch (status) {
case "Active":
return {
icon: 'http://maps.google.com/mapfiles/ms/icons/green-dot.png',
title: 'test 1'
};
case "Pending":
return {
icon: 'http://maps.google.com/mapfiles/ms/icons/orange-dot.png'
};
}
};
pendingJSON.loadGeoJson('http://url/GoogleTestPending.json');
pendingJSON.setStyle(setDataStyle);
pendingJSON.setMap(gmap);
activeJSON.loadGeoJson('http://url/GoogleTestActive.json');
activeJSON.setStyle(setDataStyle);
activeJSON.setMap(gmap);
bJSONLoaded = true;
}
else
{
if (!testJSON.getMap()) {
console.log('setting map');
pendingJSON.setMap(gmap);
activeJSON.setMap(gmap);
testJSON.setMap(gmap);
}
}
}
else
{
if (bJSONLoaded === true && testJSON.getMap() != null)
{
//remove pins
pendingJSON.setMap(null);
activeJSON.setMap(null);
testJSON.setMap(null);
}
}
});
Solved it by using OverlayView.
customEntity.prototype = new google.maps.OverlayView();
And then implemented required functions like draw, onAdd, onRemove, etc.
I would like to count how many entreprise are in some category but I'm stuck with the asynchrone concept.
Here's what I already have:
Category.getall(function(err, cat){
if(err) return res.negotiate(err);
catIds = []
for( var iCat in cat){
catIds.push(cat[iCat].id)
// and here I would like do something like
Entreprise.count({category_id: cat[iCat].id}, function(err, nbr){
categoriesOUT.push({categorie: cat, entreprise_number: nbr })
// I know that i can not do it but it's just to help to understand the logic I would like to have.
if(cat.length==iCat){
return res.json({categories: categoriesOUT})
}
})
}
})
There are a couple of ways to handle this. One would be to bring in a promise library like Q. Another would be a single database call that can count up enterprise objects grouped by category_id... however, I think that would go beyond Waterline's normal queries, you would have to use .query or .native or something.
The easiest quick fix for you is to just keep a counter of how many results you have handled. You may get tired of this approach after using it a couple of times, but it would look something like this:
Category.getall(function(err, cat){
if(err) { return res.negotiate(err); }
var catIds = [], categoriesOut = [], processedCategories = 0;
for( var iCat in cat){
catIds.push(cat[iCat].id)
Entreprise.count({category_id: cat[iCat].id}, function(err, nbr) {
if (err) {
categoriesOUT.push({categorie: cat, entreprise_number: 0});
} else {
categoriesOUT.push({categorie: cat, entreprise_number: nbr });
}
processedCategories += 1;
if (processedCategories >= cat.length) {
return res.json({categories: categoriesOUT});
}
});
}
});
Here's how I finaly get it only with MySQL request as suggered by #arbuthnott
(The category field is call domaine here)
Domaine.getall(function(err, domaines){
if(err){return res.negotiate(err)}
var domNames = {}, domContain = {}, domOut = [];
Entreprise.query('SELECT domaine_id, COUNT(*) FROM entreprise GROUP BY domaine_id', function(err, entreprises){
if(err){return res.negotiate(err)}
entreprises = JSON.parse(JSON.stringify(entreprises));
for(var ent of entreprises){
domContain[ent['domaine_id']] = ent['COUNT(*)'];
}
for(var iDom in domaines){
var countAdded = false;
for(var dc in domContain){
if(dc==domaines[iDom].id) {
domaines[iDom].entreprises_count = domContain[dc];
countAdded = true;
}
}
if(!countAdded) domaines[iDom].entreprises_count = 0;
}
res.json({domaines:domaines})
})
})
I need to use bulk operations with aggregate in order to delete duplicates with a certain condition in my database. I tried to use rawCollection() but I don't really know how.
Here's the code I need to execute with cron every x hours
function removeDups() {
var count = 0,
collection = Beatmaps.rawCollection(),
bulk = collection.initializeUnorderedBulkOp();
collection.aggregate([
{ '$sort': { 'difficultyrating': -1 }},
{ '$group': { '_id': '$beatmapset_id', 'ids': { '$push': '$_id' }, 'count': { '$sum': 1 }}},
{ '$match': { 'count': { '$gt': 1 }}}
]).forEach(function(doc) {
doc.ids.shift();
bulk.find({'_id': { '$in': doc.ids }}).remove();
count++;
if(count === 100) {
bulk.execute();
bulk = collection.initializeUnorderedBulkOp();
}
});
if(count !== 0) {
bulk.execute();
}
}
but it produces an error: Cannot call method 'forEach' of undefined
So what should I do?
Okay, after a bit of research I found similar question and here's what I did to make this work:
var aggregate = Meteor.wrapAsync(collection.aggregate, collection);
and then
aggregate(parameters).forEach(...);
I have a Wordpress site with a long table of people and data and I need to add a search filter which shows only the people who match the typed in words. Here is the code I'm using:
$(document).ready(function() {
$('input[name=searchFilterInput]').keyup(function() {
var searchFilterVal = $('input[name=searchFilterInput]').val();
searchFilterVal = searchFilterVal.replace(/ /g, '-');
searchFilterVal = searchFilterVal.toLowerCase();
if(searchFilterVal == '') {
$('tr.hide').fadeIn('slow').removeClass('hide');
} else {
$('tr.fellows').each(function() {
if(!$(this).hasClass(searchFilterVal)) {
$(this).fadeOut('normal').addClass('hide');
} else {
$(this).fadeIn('slow').removeClass('hide');
}
});
}
});
});
This works great as long as the input exactly matches the class. I need if(!$(this).hasClass(searchFilterVal)) {
to basically say "If (this) .hasClass(if the input matches any portion of the class)"
Does that make sense? Here is the page:
http://cambridgefellows.com/directory-of-fellows/?searchFilterInput=Media
Is is the second search field - the one on the right hand side of the drop down menus.
I'm sorry if this question is not asked clearly - please let me know if I can make it more clear. Thanks!
Try this .. I've cheked it , it's working
$(document).ready(function() {
$('input[name=searchFilterInput]').keyup(function() {
var searchFilterVal = $('input[name=searchFilterInput]').val();
searchFilterVal = searchFilterVal.replace(/ /g, '-');
searchFilterVal = searchFilterVal.toLowerCase();
if(searchFilterVal == '') {
$('tr.hide').fadeIn('slow').removeClass('hide');
} else {
$('tr.fellows').each(function() {
var pattern = $(this).attr('class'); // the pattern to be matched
var match = pattern.match(searchFilterVal);//If pattern matches it returns the match
if(!match) {
$(this).fadeOut('normal').addClass('hide');
} else {
$(this).fadeIn('slow').removeClass('hide');
}
});
}
});
});