Flex AsyncToken implementation on Rails - ruby-on-rails

i'm using a Rails backend with my App and getting a AsyncToken returned from it (a DB-Call to be specific)
As far as i know the AsyncToken returns a result event when done loading all data from the request, this way its possible to make sure all data was loaded before executing some function which uses the data.
i tried the following implementation to get the AsyncToken converted into an Array and plotting its objects as strings to the user:
var dataSrv:services.databaseservice.DatabaseService = new services.databaseservice.DatabaseService;
dataSrv.addEventListener(ResultEvent.RESULT, dbListener);
//DBOPERATION returns my AsyncToken
var listData:AsyncToken = dataSrv.DBOPERATION;
var responder:AsyncResponder = new AsyncResponder( resultHandler, faultHandler );
listData.addResponder(responder);
public function resultHandler(event:ResultEvent, token:Object=null):void{
var output: Array = (event.result as Array);
for (var i:int = 0; i<output.length; i++){
Alert.show( output[i].toString() );
}
}
public function faultHandler(event:FaultEvent, token:Object=null):void{
Alert.show( "FAULT: " + event.fault.message );
}
But i keep getting a "null object-pointer" error!

Ok here how it works:
var output:ArrayCollection = (event.result as ArrayCollection);
for (var i:int = 0; i<output.length; i++)
{
// where VARIABLE is the name of the transmitted data-variable
Alert.show(output[i].VARIABLE);
}
hope this helps others. Thx for Help Guys, stackoverflow is just awesome!

You could add a breakpoint on the following line
var output: Array = (event.result as Array);
Then go to the Flash Debug perspective, in the "Variables" pane you should be able to access the properties of the event and see the content of the result property.
If the result property is null, you may want to double check what is returned from Rails

Related

generate/making a grahic for each student in googlesheet and auto save the graphic image to gdrive

need your help again..
so I have many student. and every week we have exam.
so I want to make individual Graphic of their progress for every week.. and send it ass attachment with autocrat to their email.
my problem is
how do I make an individual graphic continuedly (i mean not one by one change the name)
how to save that individual graphic to google drive
how to get the link image on google drive
those 3 problem is to make report for my student one by one like this pic
please share idea with me.. I'm really thank you for helping me here..
here the spreadsheet link : https://docs.google.com/spreadsheets/d/1fmS7PM65CMGGe5g00ojqqiK2CFr5HFgo_6L_Qki7QLw/edit#gid=1364826426
I can't understand and solve your problem all, since your problem seems a bit too complex.
However, I know how to save a sheet as a PDF easier and get the PDF's URL automatically.
It needs a script program.
I made a sample program based on another answer.
This is my code.
function exportPDF(){
// get parameters
var sheet = SpreadsheetApp.getActiveSheet();
var sheetName = sheet.getRange("B2").getValue();
var fileName = sheet.getRange("B3").getValue();
sheet.getRange("B4").setValue("");
// export the sheet
var fileUrl = exportSheet(sheetName, fileName);
// show the url
sheet.getRange("B4").setValue(fileUrl);
}
// based on https://stackoverflow.com/questions/38335143/export-single-sheet-to-pdf-in-apps-script
function exportSheet(sheetName, fileName) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheets = ss.getSheets();
var fileUrl = "";
try{
for (var i = 0; i < sheets.length; i++) {
if (sheets[i].getSheetName() !== sheetName) {
sheets[i].hideSheet()
}
}
var file = DriveApp.createFile(ss.getBlob());
file.setName(fileName);
file.setSharing(DriveApp.Access.ANYONE, DriveApp.Permission.VIEW);
fileUrl = file.getUrl();
}
catch(e){
console.log(e);
throw e;
}
finally{
for (var i = 0; i < sheets.length; i++) {
sheets[i].showSheet()
}
}
return fileUrl;
}
If this can help, check this sample sheet and make a copy. ([File]-[Make a copy])
https://docs.google.com/spreadsheets/d/1lCxNSaXsd9tno4xdog6Usa0l1SZeuXrc62Oi6TK-VsY/edit?usp=sharing
I have created three charts in the spreadsheet for you.
Save or publish your chart

"CS0162: Warning as Error: Unreachable code detected" on Razor View

I have the following code within a script tag on my razor view:
self.regions = [];
#foreach(var region in Model.OperationRegions)
{
<text>
self.regions.push({
regionid: '#region.Region_Id',
regionname: '#region.Title',
selected: ko.observable(#(Model.RegionsList.Contains(region.Region_Id).ToString().ToLower()))
});
</text>
}
self.categories = [];
#foreach(var category in Model.Categories)
{
<text>
self.categories.push({
categoryid: '#category.Category_Id',
title: '#category.Title'
});
</text>
}
For clarity, the code outside of the foreach loops and within the text tags are Javascript and the purpose of the razor code is to populate my Javascript arrays with data from the server.
When I run this I am currently getting a server error saying "CS0162: Warning as Error: Unreachable code detected"
The error is thrown on the second "foreach" in the snippet.
Surprisingly I couldn't find another question referring to this error message on an MVC razor page so I'm posting this here.
My question is why is that line of code considered to be unreachable? I will update this question if I find anything else on my page to be relevant to the issue as I try to debug.
The error has disappeared now. I had renamed a property of my model and not recompiled before trying to load the page again. Recompiling made the error go away. I have no idea how the root cause translated to the error message shown but its fixed now in any case.
This is an extremely poor way to handle this. There's no need to build an array piece by piece like this. Just convert your list to JSON.
self.regions = #Html.Raw(Json.Encode(Model.OperationRegions.Select(region => new {
regionid = region.Region_Id,
regionname = region.Title,
selected = Model.RegionsList.Contains(region.Region_Id)
})));
The only thing this can't handle is making selected an observable. However, you can simply loop through the array and fix this:
for (var i = 0; i < self.regions.length; i++) {
self.regions[i].selected = ko.observable(self.regions[i].selected);
}
However, the better approach is to use another view model:
var OperationRegionViewModel = function (data) {
var self = {};
self.regionid = ko.observable(data.regionid);
self.regionname = ko.observable(data.regionname);
self.selected = ko.observable(data.selected);
return self;
};
Then, you can just do something like:
var regions = #Html.Raw(Json.Encode(Model.OperationRegions.Select(region => new {
regionid = region.Region_Id,
regionname = region.Title,
selected = Model.RegionsList.Contains(region.Region_Id)
})));
self.regions = $.map(regions, new OperationRegionViewModel);
Or, even better build your JSON all at once:
var json = #Html.Raw(Json.Encode(new {
regions = Model.OperationRegions.Select(r => new { ... }),
categories = Model.Categories.Select(c => new { ... }),
// etc
});
Then, inject this all into your view model:
var viewModel = (function (json) {
// other stuff
self.regions = $.map(json.regions, new OperationRegionViewModel);
self.categories = $.map(json.categories, new CategoryViewModel);
// etc
})(json);

Retrieve url of uploaded file from google form

I have found an extremely good google script for a google form that allows me to retrieve the answers of a google form in a spreadsheet along with the "getEditResponseUrl()" that will help me build a database that can be modified through the google form.
However, I am struggling in getting the url of an "upload file question". The question where the user is supposed to upload a file is the fourth one "facture".
The answer I get in my spreadsheet is only "[Ljava.lang.Object;#508c8b8b" but not the file.
Any idea how to make this work so that I get the url of the file that was uploaded by the user ?
Thank you and Kind regards
var ss = SpreadsheetApp.openById("spreadsheeturl"); // to be customised
var responseSheet = "Database"; // to be customised
function submitFormFunc(e) {
var items = e.response.getItemResponses();
var responses={};
for(var i = 0; i< items.length; i++) {
responses[items[i].getItem().getTitle()]=items[i].getResponse();
}
var responseRow = [];
responseRow.push(e.response.getTimestamp().toString());
responseRow.push(e.response.getId());
responseRow.push(responses["Challenge"]); // to be customised
responseRow.push(responses["Client"]);
responseRow.push(responses["Date"]);
responseRow.push(responses["Facture"]);
// to be customised
// add as many as needed
responseRow.push(FormApp.getActiveForm().getResponse(e.response.getId()).getEditResponseUrl());
var isNewItem = alreadyExist(ss,e.response.getId());
if(isNewItem<0){
ss.getSheetByName(responseSheet).appendRow(responseRow);
}
else{
ss.getSheetByName(responseSheet).getRange(isNewItem+2, 1, 1, 6).setValues([responseRow]);
}
}
function alreadyExist(ss,id){
var ids = ss.getSheetByName(responseSheet).getRange("B2:B").getValues();
for(var i=0; i< ids.length; i++){
if(ids[i][0]===id){
return(i);
}
}
return(-1);
}
Here's a snippet from the Form Notifications add-on that converts the uploaded file ids into Google Drive URLs and concatenates the result in case of multiple uploads.
var urls = answer.toString().split(",").map(function(f) {
return "https://drive.google.com/open?id=" + f;
}).join(", ");

Using fetch in a loop in code by zapier

I want to do 3 different api call from my zapier code, get their returns in variables and merge them. I can't figure out how to do that. It will be like:
var urls = [apiUrl1, apiUrl2, apiUrl3];
var output = [];
for ( i = 0; i < urls.length; i++ ) {
output[i] = fetch( urls[i] );
}
This is an example code. I can't get response to output, it gets only a blank object {}. What will be the procedure to save the fetch return values in the output array?
Since apparently the folks at Zapier do not like to give out working examples or any sort of decent documentation for this level of code intricacy... here is a working example:
var promises = [];
for (var i = urls.length - 1; i >= 0; i--) {
promises.push(fetch(urls[i]));
}
Promise.all(promises).then(function(res){
var blobPromises = [];
for (var i = res.length - 1; i >= 0; i--) {
blobPromises.push(res[i].text());
}
return Promise.all(blobPromises);
}).then(function(body){
var output = {id: 1234, rawData: body};
callback(null, output);
}).catch(callback);
This may not be the cleanest solution, but it works for me. Cheers!
Two things you'll need to brush up on:
Promises - especially Promise.all() - there is lots out there about that.
Callback to return the data asynchronously. Our help docs describe this.
The main reason your code fails is because you are assuming the fetch happens immediately. In JavaScript that is not the case - it happens Async and you have to use promises and callbacks to wait until they are done before returning the output via the callback!

I need to filter the yui datatable which has inline cell editing. and the data is coming from the groovy controller in key:value pair form. as JSON

hi i am also facing the data error problem. i wanted to filter the data coming from json result from the groovy controller in key:value pair. even if i chage the TYPE_JSON to TYPE_JSARRAY,i am getting NoRecordas found in data table but the json result has the data.
please can u correct me.
Thanks in advance!!
dobMenuButton.subscribe("selectedMenuItemChange",function(e) {
var value =e.newValue.value;
if(YAHOO.lang.isValue(value)) {
myDataTable.getDataSource().sendRequest(null, {
success:function(request, response, payload) {
this.initializeTable();
var rs = response.results;
var filtered = [];
for(var i = 0; i < rs.length; i++) {
if(((rs[i].dateOfBirth).format("MM/dd/yyyy")) == value) {
filtered[filtered.length] = rs[i];
}
}
this.getRecordSet().reset();
MCMPagination.paginatorvar.setTotalRecords(filtered.length,true);
this.getRecordSet().setRecords(filtered, 0);
this.render();
},
scope:myDataTable,
argument:myDataTable.getState()
});
}
});

Resources