How to serialise ember date? - serialization

I'm new to ember and I want to post a new record, So I did something like:
App.AdminController = Em.Controller.extend
submit: ->
post = App.Post.createRecord()
post.set('author', $('#author').val())
post.set('title', $('#title').val())
post.set('intro', $('#intro').val())
post.set('description', $('#description').val())
post.set('publishedAt', new Date())
post.get('store').commit()
Everything works like a charm, except the publisedAt attribute e in post request json file is null
I think the problem is due to that I may not serialise it correctly, any idea?
update the model:
App.Post = DS.Model.extend
title: DS.attr('string')
author: DS.attr('string')
intro: DS.attr('string')
description: DS.attr('string')
publishedat:DS.attr('date')

Try using JSON.stringify on the Date object:
post.set('publishedAt', JSON.stringify(new Date()))

For some reason, you can't invoke new Date() inside the .set method. This should work:
var d = new Date();
post.set('publishedAt', d);

Related

Get data from sql server to appear on Kendo Scheduler

I want to know how I can get the information that I have on a sql table into a Kendo scheduler. What I currently have in the server is the Start, End, StartTimeZone, EndTimeZone, Description, Title... etc. All the stuff you need for Kendo Scheduler, but I have many events that I need to make and put into a calendar format and the scheduler seems like the best way to do it. Right now my calendar view looks like this
#(Html.Kendo().Scheduler<**censored**.Models.LeaveRequest>()
.Name("scheduler")
.Date(new DateTime(2013, 6, 13))
.StartTime(new DateTime(2013, 6, 13, 7, 00, 00))
.Height(600)
.Views(views =>
{
views.DayView();
views.WeekView();
views.MonthView(MonthView => MonthView.Selected(true));
})
.Timezone("Etc/UTC")
.DataSource(d => d
.Model(m =>
{
m.Id(f => f.LeaveRequestId);
m.Field(f => f.Title).DefaultValue("No title");
m.Field(f => f.EmployeeId).DefaultValue(1);
m.Field(f => f.Title).DefaultValue("No title");
m.RecurrenceId(f => f.LeaveRequestId);
})
.ServerOperation(true)
.Read(read => read.Action("Read", "Home").Data("getAdditionalData"))
.Create("Create", "Home")
.Destroy("Destroy", "Home")
.Update("Update", "Home")
)
)
<script>
function getAdditionalData() {
var scheduler = $("#scheduler").data("kendoScheduler");
var timezone = scheduler.options.timezone;
var startDate = kendo.timezone.convert(scheduler.view().startDate(), timezone, "Etc/UTC");
var endDate = kendo.timezone.convert(scheduler.view().endDate(), timezone, "Etc/UTC");
//optionally add startTime / endTime of the view
var startTime = kendo.date.getMilliseconds(scheduler.view().startTime());
var endTime = kendo.date.getMilliseconds(scheduler.view().endTime());
endTime = endTime == 0 ? kendo.date.MS_PER_DAY : endTime;
var result = {
Start: new Date(startDate.getTime() - (startDate.getTimezoneOffset() * kendo.date.MS_PER_MINUTE) + startTime),
End: new Date(endDate.getTime() - (endDate.getTimezoneOffset() * kendo.date.MS_PER_MINUTE) + endTime)
}
return result;
}
</script>
<style>
.invalid-slot {
background: red !important;
cursor: no-drop;
}
</style>
</div>
But I don't know what I need to do in the controllers and models, if anything.
I just completed the implementation of KendoUI Scheduler by integrating it with SQL data base. However, I made use of JavaScript API to do so in my MVC project.
To load the data i.e. "read" and perform insert, update and delete just return the model in JSON format from controller. The Scheduler will bind the data for you, if it gets the "know" format.
return Json(**censored**.Models.LeaveRequest, JsonRequestBehavior.AllowGet);
Couple of important points:
1. KendoUI Scheduler depends a lot on unique id, so in case you have anything other than "id" - then "do" configure it in your scheduler.
In JS API it was done using following syntax, where EventID was the unique ID my SQL table.
schema: {
model: {
"id": "EventID",
"fields": {
"EventID": {
"type": "number"
},
....
Always return JSON data from your Insert, Update and Delete method from Controller. For instance:
public JsonResult UpdateCalendarEvent(string models)
{
...
return Json(censored.Models.LeaveRequest, JsonRequestBehavior.AllowGet);
}
In case of Insert, before returning the JSON object, do update the ID or EventID with latest row id, so Scheduler will sync up all data on client side and can perform update and delete operation appropriately.
Hope that helps!

Get all classes in Parse-server

I'm writing a backup job, and need to fetch all classes in Parse-server, so I can then query all rows and export them.
How do I fetch all classes?
Thanks
Query the schemas collection.
GET /parse/schemas
Probably need to use the masterkey on the query. Not sure what language you're writing your job in but should be simple for you to create a REST query or create a node.js script and use the javascript/node api
--Added after comment below --
var Parse = require('parse/node').Parse;
Parse.serverURL = "http://localhost:23740/parse";
Parse.initialize('APP_ID', 'RESTKEY', 'MASTERKEY');
var Schema = Parse.Object.extend("_SCHEMA");
var query = new Parse.Query(Schema);
query.find({
success : (results) => {
console.log(JSON.stringify(results));
},
error : (err) => {
console.log("err : " + JSON.stringify(err));
}});

typeahead bootstrap3: how to pass a parameter into remote?

I am trying to use typeahed twitter for bootstrap
https://github.com/twitter/typeahead.js
I need to change the remote dynamically according to what user types in and ANOTHER parameter.
(The goal is to retrieve the cities of a country)
trying with country="en"; does not affect it
trying with autocompleter.remote=".."; does not work.
Any idea ?
<script>
var country="fr";
var autocompleter = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: 'ajax.php?action=getVilles&country='+country+'&ville=%QUERY'
});
autocompleter.initialize();
$('#city').typeahead(null, {
name: 'city',
displayKey: 'city',
source: autocompleter.ttAdapter()
});
</script>
This is what I've done:
var tagStudies = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('text'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: "autocomplete/study",
replace: function(url, uriEncodedQuery) {
study = $('#study').val();
ssp = $("#social-security").val();
return url + '?q=' + uriEncodedQuery + '&s=' + study + '&ssp=' + ssp
},
filter: function (parsedResponse) {
return parsedResponse.studies;
}
}
});
Take a look at the replace function. The first parameter is the url, and the second is what the user is typing. I made a concatenation to pass the query and 2 extra params.
If you copy the code, make sure you replace 'text' for 'value' in datumTokenizer. Hope it helps

MVC5 Actionlink: Pass data as query string

Following is my Html.Actionlink
#Html.ActionLink("Change Team", "Edit", "UserPlayers", new { MatchId = ViewBag.MatchId, UserId = ViewBag.UserId })
When i run the application I get this
http://localhost:50013/UserPlayers/Edit?Length=11
as a link.
I dont know from where is the "Length=11" coming.
You need to add a null as the last parameter:
#Html.ActionLink("Change Team", "Edit", "UserPlayers", new { MatchId = ViewBag.MatchId, UserId = ViewBag.UserId }, null)
Without this, you are using the wrong method overload for Html.ActionLink()

Mongoskin findAndModify ID object id

Using nodejs, mongoskin.. I'd like to return the updated doc so Im using findAndModify, however the query {_id: "someid"} doesn't work. I think I need to use {id: ObjectID{'someid'} as the query. How do I get the ObjectId type into JS?
try this:
ObjectID = require('mongoskin').ObjectID
{_id: new ObjectID("someid")}
Here is a solution
var mongo = require("mongoskin");
var conn = mongo.db(YOUR_DETAILS);
var BSON = mongo.BSONPure;
this enables you to convert your id int, string or whatever using:
conn.collection(YOUR_COLLECTION).find({_id:new BSON.ObjectID(YOUR_ID)})
Hope that helps!
You can do something like:
yourCollection = db.collections('yourCollection');
Then
{ _id: yourCollection.id("someId") }