can't find country code from Google maps api 3 geocoding request - google-geocoder

In version 2 of google maps geocoder api there was a method
geocoder.getLocations that gave a lot of info about the requested address like : country , street, zip code , lat, lng, etc ...
Seems like the method is gone in v3
and we need to iterate the address_component
when i try to do so i get an error 'j is not defined' when running this
$.each(results[0].address_component, function (index, value) {
alert(index + ': ' + value);
});
http://maps.googleapis.com/maps/api/geocode/xml?address=75001,france&sensor=false
How do i iterate the adress_component or better yet how to i get to
the adress_component->type country -> short name
Thanks

I found how to iterate the collections
$.each(results[0].address_components, function (index, value) {
$.each(value, function (index2, val) {
alert(index2 + ': ' + val);
});
});
but is there a faster jquery way to get to a specific item without iterating ?
I want to get to address_components of type 'Country'
I guess it now a JQuery question

Related

Cypress: Get JQuery value without needing `then` or `each`

I'm hoping someone can help, but I've posted this as a Cypress discussion as well, although it might just be my understanding that's wrong
I need to get the Cypress.Chainable<JQuery<HTMLElement>> of the cell of a table using the column header and another cell's value in the same row.
Here's a working example JQuery TS Fiddle: https://jsfiddle.net/6w1r7ha9/
My current implementation looks as follows:
static findCellByRowTextColumnHeaderText(
rowText: string,
columnName: string,
) {
const row = cy.get(`tr:contains(${rowText})`);
const column = cy.get(`th:contains(${columnName})`)
const columnIndex = ???
return row.find(`td:eq(${columnIndex})`)
}
This function is required because I want to write DRY code to find cells easily for content verification, clicking elements inside of it etc.
The only example I've seen is this https://stackoverflow.com/a/70686525/1321908, but the following doesn't work:
const columns = cy.get('th')
let columnIndex = -1
columns.each((el, index) => {
if (el.text().includes(columnName) {
columnIndex = index
}
cy.log('columnIndex', columnIndex) // Outputs 2 as expected
})
cy.log('finalColumnIndex', columnIndex) // Outputs -1
My current thinking is something like:
const columnIndex: number = column.then((el) => el.index())
This however returns a Chainable<number> How to turn it into number, I have no idea. I'm using this answer to guide my thinking in this regard.
Using .then() in a Cypress test is almost mandatory to avoid flaky tests.
To avoid problems with test code getting ahead of web page updating, Cypress uses Chainable to retry the DOM query until success, or time out.
But the Chainable interface isn't a promise, so you can't await it. You can only then() it.
It would be nice if you could substitute another keyword like unchain
const column = unchain cy.get(`th:contains(${columnName})`)
but unfortunately Javascript can't be extended with new keywords. You can only add methods like .then() onto objects like Chainable.
Having said that, there are code patterns that allow extracting a Chainable value and using it like a plain Javascript variable.
But they are limited to specific scenarios, for example assigning to a global in a before() and using it in an it().
If you give up the core feature of Cypress, the automatic retry feature, then it's just jQuery exactly as you have in the fiddle (but using Cypress.$() instead of $()).
But even Mikhail's thenify relys on the structure of the test when you add a small amount of asynchronicity
Example app
<foo>abc</foo>
<script>
setTimeout(() => {
const foo = document.querySelector('foo')
foo.innerText = 'def'
}, 1000)
</script>
Test
let a = cy.get("foo").thenify()
// expect(a.text()).to.eq('def') // fails
// cy.wrap(a.text()).should('eq', 'def') // fails
cy.wrap(a).should('have.text', 'def') // passes
let b = cy.get("foo") // no thenify
b.should('have.text', 'def') // passes
Based on your working example, you will need to get the headers first, map out the text, then find the index of the column (I've chosen 'Col B'). Afterwards you will find the row containing the other cell value, then get all the cells in row and use .eq() with the column index found earlier.
// get headers, map text, filter to Col B index
cy.get("th")
.then(($headers) => Cypress._.map($headers, "innerText"))
.then(cy.log)
.invoke("indexOf", "Col B")
.then((headerIndex) => {
// find row containing Val A
cy.contains("tbody tr", "Val A")
.find("td")
// get cell containing Val B
.eq(headerIndex)
.should("have.text", "Val B");
});
Here is the example.

How to get length data from a given array?

Query URL - "XYZ "
From the above URL we can see different category's like a, b & c.
Now, my question is how we can get the length present in each category and display in the output?
For example c has 13 count listed, This I want to show case using cypress code.
You can iterate over the tab sections using each(), perform a click, and then calculate the length of all the questions. A simple program demonstrating that -
it('Print the Number of Questions in each Tab', function() {
cy.visit('https://www.kreditbee.in/faq')
cy.get('button[role="tab"]').each(($ele) => {
cy.wrap($ele).click()
cy.get('svg').its('length').then((len) => {
cy.log('The number of questions in ' + $ele.text() + ' tab: ' + len)
})
})
})

In Handsontable How do you save records with specific ids each row?

I have this set of records object-array like for example..
[{firstname:'John',lastname:'Smith'},{firstname:'Jimmy',lastname:'Morre'}]
What I want to do is to enable Saving feature of Handsontable. My problem is I can't update it where column name is "firstname" or "lastname" .. or at least row id (where can I put rowID by the way?) because the getData() function returns only values of the cell not the with the properties of the original data-set such as like 'firstname ' and 'lastname'.
Anyone from here who are more familiar with Handsontable? thank you..
I am not sure to understand what you want.
But in this JSFiddle you can see how to get the property of your data ;)
var datas = hot.getData()
$.each(datas, function(rowIndex, row) {
console.log('The row id is ' + rowIndex);
$.each(row, function(colIndex, value) {
console.log('The column id is ' + colIndex + ' and the property is ' + Object.keys(hot.getSchema())[colIndex]);
console.log(value);
});
console.log("----------------------------");
});
I hope it helps you.

Need to develop cloud function to specify the query

I'm novice in programming. Right now I'm developing my first app with Swift and Parse (for backend). My app is for the survey to know the confidence rating of the politician. The rating is equal to those who voted YES percentage within last day. I want to do all the math on the cloud and just send client the result (a number). So that I've researched the docs on Parse but not quite sure what to do. Below is my tryout (not successful though) and I hope you could help me to find and fix the problems.
So I have the score class (table). A single score object look like:
{
"objectID": 12eroi87,
"vote": 1, // or 0
"createdAt": Nov 5, 2014, 10:35 // Date
}
Now I have to build some cloud function to do all the math.
Parse.Cloud.define("confidenceRating", function(request, response) {
var query = new Parse.Query("score");
query.equalTo("vote", request.params.vote);
query.find({
success: function(results) {
var sum = 0;
for (var i = 0; i < results.length; ++i) {
sum += results[i].get("vote");
}
response.success(100 * sum / results.length);
},
error: function() {
response.error("something went wrong");
}
});
});
I'm aware the code above is some mess (( No idea how to cut the votes within last day. And finally I have no idea how to call the function with Swift.
Hope I could help! I'd appreciate much if you provide some useful links as well.
Look here for an example of calling a cloud code function in Swift:
Calling Parse cloud functions very slow on iOS in mobile network
in order to get records for the specific date you will need to filter by date, below might work with some adaptation to your needs:
var transformedDate = moment(request.params.selectedDate);
var transformedDate2 = moment(request.params.selectedDate).add(1, 'days');
//console.log("transformedDate: " + transformedDate.format());
//console.log("transformedDate2: " + transformedDate2.format());
//console.log("selectedDate: " + selectedDate);
var query = new Parse.Query("score");
query.greaterThan("createdAt", new Date(transformedDate.format("YYYY-MM-DDT00:00:00.000Z")));
query.lessThan("createdAt", new Date(transformedDate2.format("YYYY-MM-DDT00:00:00.000Z")));
I did solved something similar with dates in filter-on-own-date-fields-no-working-and-or-wrong-date-format-used
your friend here will be moment.js module, carefull to use the latest momentjs version to avoid problems as those in trouble-using-the-moment-module

JQGrid Grouping GroupText formatting and modification

I have a grid that implements grouping but would like to expand on the details that display in the groupText: area. Ideally I would be able to take data about that grouping and display in that group row with the group name ({0} default value).
In other words what I am trying to achieve is a way to display not only the group name but also some other data items contained in the JSON feed to the grid.
My searching seems to be coming up short on anyone being able to achieve this but I'm hoping someone can shed some light on expanding this setting and providing access to formating this area.
I find your question interesting, but the implementation is not simple. In the answer I showed before how one could use custom formatter in summary rows of the grouping.
In the demo you can see how to implement custom formatting of the grouping text. The demo display the following:
The implementation consist just from the implementation of the custom formatter which can be used for both purpose: formatting of the content of the corresponding column and formatting of the grouping text in case of grouping by the column. The code is a little tricky, but I hope that all will be able follow it. The code use the differences of the input parameters to define whether the formatter will be called to format the column content or to format the grouping text.
One part of the code which get the texts like "(test4,test7)" is not so effective in case of the usage of large number of rows, but it works.
Below is the code of formatter of the "Date" column which would by typically used with the predefined formatter: 'date'. I called in the part of the code the original Date-formatter, but used for the the grouping text more sophisticated code:
formatter: function (cellval, opts, rowObject, action) {
var fullOpts = $.extend({}, $.jgrid.formatter.date, opts),
formattedDate = $.fmatter.util.DateFormat('Y-m-d', cellval, 'd-M-Y', fullOpts),
groupIdPrefix = opts.gid + "ghead_",
groupIdPrefixLength = groupIdPrefix.length,
month = Number(cellval.split('-')[1]), // input format 'Y-m-d'
names = [], data, i, l, item;
// test wether opts.rowId start with opts.gid + "ghead_" and integer
// and rowObject is the array and action is undefined.
if (opts.rowId.substr(0, groupIdPrefixLength) === groupIdPrefix && typeof action === "undefined") {
// custom formating of the group header
// we just simulate some login by testing of the month > 9
// the next code fragment is not effective, but it can be used
// in case of not so large number of groups and the local data
data = $(this).jqGrid("getGridParam", "data");
for (i = 0, l = data.length; i < l; i++) {
item = data[i];
if (item.invdate === cellval) {
names.push(item.name);
}
}
return (month > 9 ? ('<span class="ui-icon ui-icon-alert" style="float: left;"></span>' +
'<span style="color:tomato; margin-left: 5px;">') : "<span>") +
formattedDate + ' (' + names.join() + ')</span>'
}
return formattedDate;
}
UPDATED: The fixed version of the demo is here. It uses $.fn.fmatter instead of currently removed from jqGrid method $.fmatter.util.DateFormat.

Resources