Scheduler Date Range MVVM - mvvm

My question is very simple:
How do I get the current date range of the Kendo Scheduler?
I have checked out the example that's in the API Reference, but that one doesn't work for me.
Code:
function getCurrentDateRange(){
try{
var view = this.view();
console.log(view);
return "?startdate=" + kendo.toString(view.startDate(), "yyyy-MM-dd")
+ "&enddate=" + kendo.toString(view.endDate(), "yyyy-MM-dd");
}
catch(error){ console.log("Scheduler: Could not get schedulers daterange \n Error: " + error)}
//Default value
return "?startdate=" + kendo.toString(new Date().addDays(-30), "yyyy-MM-dd")
+ "&enddate=" + kendo.toString(new Date().addDays(30), "yyyy-MM-dd");
}

The solution for me was to reference the scheduler directly.
try{
var view = $("#schedulerViewScheduler").data("kendoScheduler").view();
console.log(view);
return "&startdate=" + kendo.toString(view.startDate(), "yyyy-MM-dd")
+ "&enddate=" + kendo.toString(view.endDate(), "yyyy-MM-dd");
}
catch(error){ console.log("Scheduler: Could not get schedulers daterange \n Error: " + error)}
return "&startdate=" + kendo.toString(new Date().addDays(-30), "yyyy-MM-dd")
+ "&enddate=" + kendo.toString(new Date().addDays(30), "yyyy-MM-dd");

Related

Google Calendar API returning generic Bad Request

I'm currently struggling with figuring out what's wrong with a Event insert I'm trying to accomplish in Flutter using Google Calendar V3 API. Initially I thought it's a matter of RFC3339 vs ISO8601 date formats, but I'm grasping at straws.
Unhandled Exception: DetailedApiRequestError(status: 400, message: Bad Request) is what I'm getting from:
import 'package:googleapis/calendar/v3.dart';
import 'package:googleapis_auth/auth.dart';
import 'package:googleapis_auth/auth_io.dart';
...
var calendar = await getCalendar();
var ac = await getOrCreateCredentials();
var client = await getClient(ac);
var calendarId = await storage.read(key: "calendar_id");
var capi = CalendarApi(client);
EventCreator ec = new EventCreator();
ec.displayName = "Display Name";
EventDateTime edt = new EventDateTime();
int hour = int.parse(ds.hour.split(":")[0]);
int min = int.parse(ds.hour.split(":")[1]);
DateTime x = ds.data.add(Duration(hours: hour, minutes: min));
edt.dateTime = x;
edt.timeZone = x.timeZoneName;
EventDateTime edtEnd = new EventDateTime();
DateTime y = x.add(Duration(hours: 1));
edtEnd.dateTime = y;
edtEnd.timeZone = y.timeZoneName;
Event e = new Event();
e.created = DateTime.now();
e.creator = ec;
e.description = d.var + " \n" + d.var;
e.summary = "Summary";
e.etag = d.var;
e.location = d.var;
e.start = edt;
e.end = edtEnd;
try {
capi.events.insert(e, calendarId);
The full JSON response contains nothing else except global domain, badrequest and HTTP 400 code.
I also tried .toUtc() on the DateTime objects to make them RFC3339 compliant, but still the same error presents.
Later Edit
The issue is indeed related to the time, the Dart DateTime class does not format the time in a way Google likes (2021-04-12T08:30:00+03:00 which I've deduced from other languages' API implementations, and the source code of the package which does a .toString() of the DateTime basically).
The way around this is to create the EventDateTime from a JSON object, and to use a hacky Dart extension. I apologize for the naming but it's annoying.
extension FuckyDateTime on DateTime {
Map<dynamic, dynamic> fuckyDateTime() {
Map<dynamic, dynamic> x = new Map();
String formatted = this.year.toString() +
'-' +
(this.month.toString().length == 1
? '0' + this.month.toString()
: this.month.toString()) +
'-' +
(this.day.toString().length == 1
? '0' + this.day.toString()
: this.day.toString()) +
'T' +
(this.hour.toString().length == 1
? '0' + this.hour.toString()
: this.hour.toString()) +
':' +
(this.minute.toString().length == 1
? '0' + this.minute.toString()
: this.minute.toString()) +
':' +
(this.second.toString().length == 1
? '0' + this.second.toString()
: this.second.toString()) +
'+' +
'03:00';
x.putIfAbsent('dateTime', () => formatted);
x.putIfAbsent('timeZone', () => 'Europe/Bucharest');
return x;
}
}
and EventDateTime edt = new EventDateTime.fromJson(x.fuckyDateTime()); where x is a DateTime object.
The issue is indeed related to the time, the Dart DateTime class does not format the time in a way Google likes (2021-04-12T08:30:00+03:00 which I've deduced from other languages' API implementations, and the source code of the package which does a .toString() of the DateTime basically). Fair mention that Dart DateTime does provide a String of ISO8601, Google wants an RFC3339 compliant date.
The way around this is to create the EventDateTime from a JSON object, and to use a hacky Dart extension. I apologize for the naming but it's annoying.
extension FuckyDateTime on DateTime {
Map<dynamic, dynamic> fuckyDateTime() {
Map<dynamic, dynamic> x = new Map();
String formatted = this.year.toString() +
'-' +
(this.month.toString().length == 1
? '0' + this.month.toString()
: this.month.toString()) +
'-' +
(this.day.toString().length == 1
? '0' + this.day.toString()
: this.day.toString()) +
'T' +
(this.hour.toString().length == 1
? '0' + this.hour.toString()
: this.hour.toString()) +
':' +
(this.minute.toString().length == 1
? '0' + this.minute.toString()
: this.minute.toString()) +
':' +
(this.second.toString().length == 1
? '0' + this.second.toString()
: this.second.toString()) +
'+' +
'03:00';
x.putIfAbsent('dateTime', () => formatted);
x.putIfAbsent('timeZone', () => 'Europe/Bucharest');
return x;
}
}
and EventDateTime edt = new EventDateTime.fromJson(x.fuckyDateTime()); where x is a DateTime object.

Google maps downloadUrl does not return 200

My code is based on the example of google code:
https://developers.google.com/maps/articles/phpsqlinfo_v3
and was working fine.
I need to change a former 'gid' (Integer) field to 'id' (String) to get saved to the database and used to display a new labeled symbol on the map.
The strange thing is, that the url, that is build in the code to call the addrow.php file is OK. When I capture this string with alert(url), and I manually use this string, the new data is added to the database.
In my script, the call seems to fail (responseCode == 200 && data.length <=1), since no data is written to the database and the alert from the 'else-clause' is displayed as short pop-up.
Here's the code I use in my project (to save data from a form):
//save new marker to Postgis-database and add new markerwithlabel on the fly
function saveData(){
var gender = escape(document.getElementById("gender").value);
var hoehe = InZahl(document.getElementById("hoehe").value);
var breite = InZahl(document.getElementById("breite").value);
var id = escape(document.getElementById("id").value);
var vital = document.getElementById("vital").value;
var typ = document.getElementById("typ").value;
var ein_mehr = document.getElementById("ein_mehr").value;
var st_durchm = document.getElementById("st_durchm").value;
var frucht = document.getElementById("frucht").value;
var anmerk = document.getElementById("anmerk").value;
var latlng = marker.getPosition();
var url = "./mapdata/addrow.php?gender=" + gender +
"&hoehe=" + hoehe + "&lat=" + latlng.lat() + "&lng=" + latlng.lng() +
"&breite=" + breite + "&id=" + id + "&typ=" + typ + "&ein_mehr=" +ein_mehr + "&st_durchm=" + st_durchm +
"&frucht=" + frucht +
"&vital=" + vital + "&anmerk=" + anmerk;
downloadUrl(url, function (data, responseCode) {
if (responseCode == 200 && data.length <=1) {
infowindow.close();
marker.setDraggable(false);
marker.setIcon('./images/mm_purple.png');
marker.labelContent = id;
marker.setMap(map);
downloadUrl("./mapdata/getxml_get_last.php", function (data1) {
var xml = parseXml(data1);
var ms = xml.documentElement.getElementsByTagName("m");
var gid = ms[0].getAttribute("gid");
var html_n = "<div id='InfoWindow'><p style='font-weight:bold;'>" + id + "</p> \n\<p>Höhe:" + hoehe + " Breite: "+ breite +
"<br />\n\Typ: "+typ+" Stämme: "+ein_mehr+" St-Durchm: "+ st_durchm + "<br />\n\Vitalität: "+vital+" Fruchtbehang: "+frucht+
"<p/>\n\<p style='text-align:right;'><a href='sm_juniperus.php?operation=ssearch&ResetFilter=0&SearchField=gid&FilterType=%3D&FilterText="+ gid +
"' target='_blank'> Daten editieren </a></p></div>";
infowindow.setContent(html_n);
bindInfoWindow(marker, map, infowindow, html_n);
(function(i, marker, gid) {
var origIcon = marker.getIcon();
new LongPress(marker, 1000);
google.maps.event.addListener(marker, 'longpress', function(e) {
marker.setDraggable(true);
marker.setIcon(mmcross);
});
google.maps.event.addListener(marker, 'dragend', function(){
updatePosition(marker, gid);
marker.setIcon(origIcon);
});
})(i,marker,gid);
//add new marker to markerCluster-Array and to markerArray
markerCluster.addMarker(marker,false);
markerArray.push(marker);
i++;
}); // End add new marker
}
else {
alert("Your data couldn't be saved!");
}
}); // End downloadUrl
}; // END saveData()
As I said, my code worked fine, but after 3 evenings passed to solve this, I thought it would be time to ask for help.
If anybody has an idea, where the mistake lies, I would apreciate any hint.
Just to confirm, you're aware that you by doing
if (responseCode == 200 && data.length <=1) {
you are saying 'if the request is successful and the data it returns is only one character or below in length'? I am unsure if this is intended or not, because this way the code inside the if statement is only ran if the response is successful but contains only 1 or 0 characters.

Parse query to print all results in a given time frame

I would like to create a query that will allow a user to type in a starting date, and print out all records of a table from that date until the current time. I keep getting "Error 102: invalid field type for find". Any suggestions?
function billingReport(){
startDate = new Date(document.getElementById("startDate").value);
var caseList = Parse.Object.extend("Cases");
var query = new Parse.Query(caseList);
query.greaterThanOrEqualTo("createdAt", "startDate");
query.find({
success: function(results) {
alert("Successfully retrieved " + results.length + " scores.");
// Do something with the returned Parse.Object values
for (var i = 0; i < results.length; i++) {
var object = results[i];
alert(object.id + ' - ' + object.get('playerName'));
}
},
error: function(error) {
alert("Error: " + error.code + " " + error.message);
}
});
}
mentioned in a comment above, but I just wanted to end this topic correctly. The two date objects were of different types, so i added .toISOString to the startDate object and it worked like a charm

DbCommand , Must Declare a variable error

This is my code. I have added the db parameter too but it still shows me error (on execution). Must declare a scalar variable
DbCommand command;
StringBuilder query = new StringBuilder(
#"SELECT isnull(UpsellService_OID,'') UpsellService_OID," + Environment.NewLine +
" isnull(ServiceName,'') ServiceName," + Environment.NewLine +
" isnull(ServiceDescription,'') ServiceDescription," + Environment.NewLine +
" isnull(Create_By,'') Create_By," + Environment.NewLine +
" isnull(Create_Date,'') Create_Date," + Environment.NewLine +
" isnull(Modify_By,'') Modify_By," + Environment.NewLine +
" isnull(Modify_Date,'') Modify_Date," + Environment.NewLine +
" isnull(Active_f,'') Active_f" + Environment.NewLine +
"FROM TRGPAYROLL.ZONG.UPSELLSERVICES " + Environment.NewLine +
"WHERE 1 = 1");
if (!string.IsNullOrEmpty(idObject.ServiceName))
{
query.Append(" AND ServiceName like '%' #ServiceName '%'");
}
command = db.GetSqlStringCommand(query.ToString());
if (!string.IsNullOrEmpty(idObject.ServiceName))
{
db.AddInParameter(command, "ServiceName", DbType.String, idObject.ServiceName);
}
return command;
I would rewrite the last part of your code in this way
if (!string.IsNullOrEmpty(idObject.ServiceName))
{
query.Append(" AND ServiceName like #ServiceName");
}
command = db.GetSqlStringCommand(query.ToString());
if (!string.IsNullOrEmpty(idObject.ServiceName))
{
db.AddInParameter(command, "#ServiceName", DbType.String, "%" + idObject.ServiceName + "%");
}
The wildcard are added directly to the value of the parameter, while the placeholder of the parameter should be free from any string concatenations. However there are many details missing to be sure of the correctness of this answer. In particular Ican only assume the inner workings of the methods GetSqlStringCommand and AddInParameter
#ServiceName variable is not declared in your SQL statement. Append to beggining of it something like
DECLARE #ServiceName AS nchar(32)
SET #ServiceName = ....

Date.now() returning NaN in PhoneGap

I can't seem to get the timestamp in my phonegap application. A simple call to Date.now(), e.g. the following, results in NaN.
console.log("lastEditedOn: " + Date.now().toString() );
LogCat:
01-26 18:28:59.997: I/Web Console(17970): LastEditedOn: NaN:220
Can anyone see what I am doing wrong?
Cheers,
Don
Managed to get the correct timestamp with this:
var d = new Date();
var lastEditedOn;
lastEditedOn = d.getTime();
console.log(lastEditedOn);
Cheers,
Don
You cannot directly toString the Date.now() because it returns the milliseconds from midnight, Jan 1 1970.
You need to convert them like this:
function printDate() {
var temp = new Date();
var dateStr = padStr(temp.getFullYear()) +
padStr(1 + temp.getMonth()) +
padStr(temp.getDate()) +
padStr(temp.getHours()) +
padStr(temp.getMinutes()) +
padStr(temp.getSeconds());
debug (dateStr );
}
function padStr(i) {
return (i < 10) ? "0" + i : "" + i;
}