These are chat archives for canjs/canjs

21st
Jun 2016
qantourisc
@qantourisc
Jun 21 2016 15:19
iirc it was impossible to update the ID without some trickery correct ? (like passing id_newval) ?
Sunil George
@georgesunil81
Jun 21 2016 20:40
@phillipskevin I want your help with filtering records on a model's response. Could you help me with it? I have created a gist for you. It is at the link below -
What I want is your help with the activeJobs function that I have put a pseudocode in. It should cause the model's response to findAll to only contain active jobs. In other words, when I call jobs.findAll from my controller, it should only return active job records in the response.
I hope it is possible. Please let me know.
As you see in my gist, in my controller, I have -
jobs.findAll({ queryString: queryString }) .done(function(response) { //response here should only contain active job records.
What I want is that the 'response' contain only the active job records.
qantourisc
@qantourisc
Jun 21 2016 20:45
@georgesunil81 My first response would be: filter on the server, second would be: you can filter in view, and third would be, edit the response array you received from findAll by filtering out recrods.
Sunil George
@georgesunil81
Jun 21 2016 20:46
So, the 'activeJobs' method on the model should cause the response to contain only the records that have status as 'Active' and job_date >= today's date.
@qantourisc thanks for your inputs. I want the filter to happen at the model level
Kevin Phillips
@phillipskevin
Jun 21 2016 20:47
I agree that it probably makes the most sense to filter on the server
Sunil George
@georgesunil81
Jun 21 2016 20:47
When you say server, what do you mean? The database server?
Kevin Phillips
@phillipskevin
Jun 21 2016 20:47
whatever is handling /job/All?' + params.queryString
Sunil George
@georgesunil81
Jun 21 2016 20:47
Oh, I get it.
qantourisc
@qantourisc
Jun 21 2016 20:48
Yes database server / http server or whereever finall is getting it's data
Kevin Phillips
@phillipskevin
Jun 21 2016 20:48
so you can just do Jobs.findAll({ active: true })
Szabolcs Schmidt
@sszabolcs
Jun 21 2016 20:48
Hi! There is a tool named can-compile which compiles EJS and mustache files into JS for better performance in production. Could you please tell me whether I can use this tool to compile stache files, too? Is it compatible with stache files and canjs 2.3? Thanks in advance!
Sunil George
@georgesunil81
Jun 21 2016 20:48
It is a RESTful service that will return all job records (both active and inactive). What I want to do is filter out at the model level once the data is returned back from the rest API. I hope it is possible.
Kevin Phillips
@phillipskevin
Jun 21 2016 20:49
you can do it
just filter the results before calling success
Sunil George
@georgesunil81
Jun 21 2016 20:50
@phillipskevin I think we can implement a get function within activeJobs that will help filter, but not sure how to do it so that the response that I get in the controller will only contain the active records
Kevin Phillips
@phillipskevin
Jun 21 2016 20:50
if that’s how you want to do it
Sunil George
@georgesunil81
Jun 21 2016 20:51
yes @phillipskevin, could you show me how to do it. You may modify my gist.
That will be a great help.
Kevin Phillips
@phillipskevin
Jun 21 2016 20:51
it’s almost the same code I gave yesterday

instead of

    .then(function (data) {
      data.map(function (item) {
        item = new MyMap(item);
      })
      success(data);

do

    .then(function (data) {
      data.filter(function (item) {
        return item.status === ‘Active’ && ...
      })
      success(data);
Sunil George
@georgesunil81
Jun 21 2016 20:52
yesterday's problem was about the define getter. Thanks for your help with it. Today, I stumbled upon the problem of filtering records!
@phillipskevin Oh, let me check into the data.filter...
Kevin Phillips
@phillipskevin
Jun 21 2016 20:54
again, I haven’t tested that, data might not be right
but the idea is using https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter to filter the array sent by the server
I still want to stress that it makes more sense to do this on the server
filtering the results on the client means you’re sending more data than you need across the wire
Sunil George
@georgesunil81
Jun 21 2016 20:56
Okay @phillipskevin, but is there a way that I can use a get within the 'activeJobs' method that will do the filter for me?
Sure @phillipskevin
Kevin Phillips
@phillipskevin
Jun 21 2016 20:56
and means you can’t do smart caching things that can-connect does
Sunil George
@georgesunil81
Jun 21 2016 20:56
Hmmm, I see
Kevin Phillips
@phillipskevin
Jun 21 2016 20:56
you can’t use a getter like that
define is defining instance properties
so each model instance will have those functions
you won’t have access to the array of results
you can do that in a viewModel if you want to
that was the second option @qantourisc suggested
Sunil George
@georgesunil81
Jun 21 2016 20:59
@phillipskevin checking on it...
Szabolcs Schmidt
@sszabolcs
Jun 21 2016 21:00
@phillipskevin could please help me in using can-compile?
Kevin Phillips
@phillipskevin
Jun 21 2016 21:01
I really don’t know a lot about can-compile
I don’t think it works with stache though
Szabolcs Schmidt
@sszabolcs
Jun 21 2016 21:01
and do you know any other tool for this task?
I mean any other tool of Bitovi :)
Kevin Phillips
@phillipskevin
Jun 21 2016 21:02
Steal :smile:
Szabolcs Schmidt
@sszabolcs
Jun 21 2016 21:03
I'm using requirejs. Steal does the same? Helps loading modules?
Kevin Phillips
@phillipskevin
Jun 21 2016 21:03
yes
steal can even load your AMD modules
you don’t need to change your format
Szabolcs Schmidt
@sszabolcs
Jun 21 2016 21:04
ok, that would be my next question
so I don't have to refactor the whole project
Kevin Phillips
@phillipskevin
Jun 21 2016 21:04
right
Szabolcs Schmidt
@sszabolcs
Jun 21 2016 21:05
ok, and Steal work with canjs 2.3?
I mean I don't have to use donejs?
Kevin Phillips
@phillipskevin
Jun 21 2016 21:05
you don’t have to use donejs
should work with any project
Szabolcs Schmidt
@sszabolcs
Jun 21 2016 21:05
ok, thank you, I'll check it!!
qantourisc @qantourisc uses a python web-server returning JSON
Szabolcs Schmidt
@sszabolcs
Jun 21 2016 21:08
By the way I'm using canjs for a year now, I really like it! I have a quite complex app written with it! Nice tool! Keep up the good work!
qantourisc
@qantourisc
Jun 21 2016 21:08
Writing server sided input checks suck though :D
Kevin Phillips
@phillipskevin
Jun 21 2016 21:09
@sszabolcs great to hear, thanks