Ag-grid onPasteStart event access to paste data for async process - javascript

Am trying to access user paste data when onPasteStart/onPasteEnd event fires. Running Angular 12. The resulting javascript object includes all ag-grid methods and I cant find the resulting data that is pasted. I cant print the string of the object and ctrl-f because it gives an error with the object being circular.
https://www.ag-grid.com/angular-data-grid/clipboard/#clipboard-events
My intention is to take the paste and use resulting data to make a api request and then use the response to modify the paste. Tried using ag-grid processDataFromClipboard but came across errors as I imagine it doesnt support async functions.
Here is an angular plnkr example. All I need is to consol.log params.value with the pasted data and starting row of the paste.
https://plnkr.co/edit/q6cZQbX7LdHzozy9
console.log('Callback onPasteStart:', params);
}
onPasteEnd(params) {
console.log('Callback onPasteEnd:', params);
}
It sounds simple so I feel like I must be missing an obvious solution

Related

Is there a way in jQuery to modify .html() so that it adds code rather than overwriting?

I'm doing work to retrieve data from APIs. I'm designing my code to make multiple queries to the API and then adding them to the running list of results in my HTML. Due to the data returned by the API, there isn't a way to get it all in one shot and then slice it up, I need to get it in multiple shots.
Look at this code:
function renderResults(results) {
return $('#results-section').html(genResults(results));
}
The function renderResults() is being called inside my API call
.fetch(URL)
.then([code that is working properly])
.then(call renderResults() here)
I've console logged my API results and tested the API call in Postman so I know it's constructed correctly- just trying to give proper context.
To review, results is the data from the API, results-section is how the results container in my HTML is marked, and the function genResults(results) creates the template HTML with values from results stuck into it.
When you use .html it overwrites everything in the section indicated immediately prior. I'm looking for a way to add the template HTML generated by genResults(results) to any HTML already in the container I have ID'd results-section, not replace what's there. I've tried chaining on .append() but can't seem to find a way to do so successfully.
The obvious solution is to have a for loop create as many results sub-sections as I need, but the problem is that I don't know how many sections I need until I get the results from the API.
Any ideas?
Update:
Answer from Souvik Ghosh worked. I was trying to chain .append() on to .html(), I didn't realize it actually replaces it.
$( "#results-section" ).append( "Your data from the last API call" );
You could use jQuery append.
$( "#results-section" ).append( "Your data from the last API call" );
Read more: https://api.jquery.com/append/

Javascript - How to update a document in couchdb?

So we need to be able to update JSON objects in cloudant using javascript. Our teacher told us something about using the _rev number but I've got no clue on how to begin.
Let's say that this is the document I need to update:
{
_id:"bla",
_rev:"blabla",
name:"something"
}
And I want to update it to this:
{
_id:"bla",
_rev:"blabla",
name:"something else"
}
Please see the following docs: http://guide.couchdb.org/editions/1/en/api.html#revisions
Basically you need to fetch the existing document, change the fields and post it back, making sure the revision is correct. Revision is used to prevent updates of documents that have been updated since you got your copy (conflict).

Facebook Graph API - Tagged Places in version 2.0

I used the Graph API with javascript to fetch all of my data contained locations in v1.0.
( I used FB.api("/v1.0/me/locations", function (response) { ... }); )
I know that the updated version is 2.2 and the "locations" node is replaced by "tagged_places" node in v2.0 and above.
I also use the Graph API Explorer to test my results.
I try this, GET: /v2.2/me?fields=tagged_places
and the results are exactly what I want.
However, in my js code, I try: FB.api("/v2.2/me?fields=tagged_places", function (response) { ... });
and there is NO any results!
Besides,
I set version: 'v2.2' in Parse.FacebookUtils.init();
I also ask the permissions :user_tagged_places,user_photos,user_status,user_friends,user_about_me,user_birthday,read_stream in Parse.FacebookUtils.logIn();
I need almost all of the data of my checkins(a.k.a locations in v1.0/tagged_places in v2.0) to add into my database.
I try to fetch /me/photos, but the results are not satisfied. So I still need to use maybe this: FB.api("/v2.2/me?fields=tagged_places", function (response) { ... });
So... can anyone help me? please....
I went through permissions in groups testing them out and I figured out what the problem was.
You need to have the permission of the item you were tagged in.
So in my case I was tagged in photos, so I needed user_photos permission to gain access to user_tagged_places. It actually creates quite an issue because you need to know how a user was tagged to retrieve their tagged_places.
If a user was tagged at a place in a post you need a different permission than if they were tagged in a photo.

Store and Retrieve WinJS.Binding.List in Application Data

I'm developing a Windows 8 Store app using HTML/JavaScript and I've run into an issue storing and retrieving a WinJS.Binding.List into Windows.Storage.ApplicationData.current.roamingSettings.
I DID get this to work by hand rolling my own method of converting the binding list into XML string and storing that, then on retrieval parsing it back out into a list. But, this seems crazy inefficient and I'm trying to find a better way. I've tried JSON.stringify() and JSON.parse() which seem to store and retrieve the right data but as soon as I bind the data to the winControl the application crashes with a 0 (no error message at all).
Here's a bit of my code to demonstrate what I'm attempting (list is a binding list):
function onSaveData() {
if (list) {
Windows.Storage.ApplicationData.current.roamingSettings.values["data"] = JSON.stringify(list);
}
}
function onLoadData() {
var data = Windows.Storage.ApplicationData.current.roamingSettings.values["data"];
if (data) {
list = JSON.parse(data);
var listview = element.querySelector("#mylistview").winControl;
listview.itemsSource = new WinJS.Binding.List(list);
}
}
I know I can get this working the long way, so I'm not looking for any solution... I'm really just hoping there's an easy way to store/retrieve these data objects that I'm missing. If I can find an easier way to do this it will eliminate about 40 lines of code and I can stop using an entire library. Also, as I go forward I plan to have more binding lists that will need to be stored as well. Thanks!
You need to bind to the List's dataSource property, not to the List itself:
listview.itemsSource = new WinJS.Binding.List(list).dataSource;
The dataSource property is specifically the IListDataSource that the ListView requires for a data source. The ListView doesn't understand anything about the WinJS.Binding.List directly, only through that particular interface. (I discuss this in Chapter 7, section "The Structure of Data Sources", in my free ebook, Programming Windows Store Apps with HTML, CSS, and JavaScript, 2nd Edition.)
Your saving and reloading the list with JSON is completely fine.

Returning a value from Javascript to C++

I have tried searching for answers but nothing seems to have worked thus far. I have a GUI application that I am building for WinAPI, and I want to use a Javascript function that will check on the Youtube API for certain videos and such, but I haven't been able to call on any of the functions in Javascript.
The farthest I've seemed to be able to get is to add an HTML file to the external dependencies(.rc), and then the Javasctipt file from there, but I can't seem to be able to just call on the function.
Is there a better way of doing this than trying to interop Javasctipt and C++, or am I just going about calling the function wrong?
/* Pseudocode */
Javascript.js
void callAPI()
{
... Call on the Youtube API, check if there are new videos i'd like...
return boolIfUpdatedOrNot;
}
Source.cpp
... Some includes and such ...
WindowProc and such
{
Case Something:
... Call on the Javascript function ...
... Do something if returned true ...
... or return 0 if false ...
}
Do you really need Javascript to get the videos? If you don't need to authenticate, there is a simple data API that will return up to 50 videos specified by certain parameters such as playlist ID or search term. You can get the results in JSON or XML by using a simple HTTP GET request. I'm not familiar with doing this in WINAPI, but you could probably start here: http://msdn.microsoft.com/en-us/library/aa384110(v=vs.85).aspx
A simple example that will get the 10 most recent uploads from a channel with CHANNEL_NAME:
https://gdata.youtube.com/feeds/api/users/CHANNEL_NAME/uploads?max-results=10
To get this in JSON:
https://gdata.youtube.com/feeds/api/users/CHANNEL_NAME/uploads?v=2&max-results=10&alt=jsonc
You have to use the second version of the API to get it in JSON (hence the v=2 parameter). XML will probably be easier to parse in native C++ though, depending on whether you want to work with another library.
For more: https://gdata.youtube.com/demo/index.html

Categories

Resources