Page 1 of 2

List Events by Date on Results Page and Disable Expired Events by Date

Posted: Mon Nov 28, 2016 8:23 pm
by Ed

Hello,

I have a Database Collection that stores Events (Event Name, Description, Event Date, Venue, Start Time, End Time, etc..).

My question is, how can I accomplish the following:

a) List the events on the Results page by Date (most recent date)?

b) Disable Events (keep from showing) after the Date has passed?

Thank you in advance!


List Events by Date on Results Page and Disable Expired Events by Date

Posted: Tue Nov 29, 2016 6:41 am
by Serhii Kulibaba

Hello Ed,

a) You can sort your results by any parameter you want. Please look at the example here: https://docs.appery.io/reference#data...

b) Yes, it is possible to show results only for the selected date. Please look at the example how to use the parameter "where" with dates: https://blog.appery.io/2015/06/how-to...


List Events by Date on Results Page and Disable Expired Events by Date

Posted: Tue Nov 29, 2016 7:14 am
by Ed

Hello Sergiy,

Answer # b above does not help with what I wish to accomplish.

I am looking for a Javascript that will only show the events with dates that are equal to or greater than the current date.


List Events by Date on Results Page and Disable Expired Events by Date

Posted: Tue Nov 29, 2016 8:00 am
by Ed

Under mapping in the "where" JS I have the following existing script which is working fine:

var currentValue = Apperyio("Search_by_State_List").val();
var whereObject = {"venue_state_province": currentValue};
return JSON.stringify(whereObject);

What are the steps needed to ALSO add the following JS to "where" which I assume will show the events with dates that are equal to or greater than the current date?

var d = new Date();
d.setDate(d.getDate());
var dateStr = d.toISOString();
return '{"start_date":{"$gte":"'+ dateStr +'"}}';

I tried to create a new mapping and add the above JS to "where" but it did not work. I am also wondering, do I have to select "date" for the Date field (not "string") in order for the above JS to work? Thanks.


List Events by Date on Results Page and Disable Expired Events by Date

Posted: Tue Nov 29, 2016 1:51 pm
by Serhii Kulibaba

Please check the simpler solution:

prereturn {"start_date":{"$gte":(new Date()).toISOString()}};/pre


List Events by Date on Results Page and Disable Expired Events by Date

Posted: Tue Nov 29, 2016 3:56 pm
by Ed

Thanks, but I am not sure what to do with the script that you provided. You did not really answer my question.

As mentioned above, since I already have an existing "where" JS ("Search_by_State_List"), what specific steps do I need to take to add this new JS (please be as specific as possible with the steps needed)? Do I need to create a new mapping with a new "where" JS? Please specify.

Also, regarding the source DB collection, do I have to select "date" for the Date field instead of "string" in order for the above JS to work?

Once again, please be as specific as as possible. Thank you in advance!


List Events by Date on Results Page and Disable Expired Events by Date

Posted: Wed Nov 30, 2016 12:49 pm
by Serhii Kulibaba

Do I need to create a new mapping with a new "where" JS?

Please use the same "where" parameter. Just add a filtering by date here: https://docs.appery.io/reference#data...

Also, regarding the source DB collection, do I have to select "date" for the Date field instead of "string" in order for the above JS to work?

Do you want to use your own column date, instead of default _createdAt? If so - yes, please change data type from "String" to "Date"


List Events by Date on Results Page and Disable Expired Events by Date

Posted: Wed Nov 30, 2016 4:45 pm
by Ed

Thanks. The filtering by date examples at the link above want you to use a specific date. However, I want to always use the present date.

Can you please show me what the final script will be when combining the two scripts below into the same "where" parameter? Thank you in advance!

var currentValue = Apperyio("Search_by_State_List").val();
var whereObject = {"venue_state_province": currentValue};
return JSON.stringify(whereObject);

var d = new Date();
d.setDate(d.getDate());
var dateStr = d.toISOString();
return '{"start_date":{"$gte":"'+ dateStr +'"}}';


List Events by Date on Results Page and Disable Expired Events by Date

Posted: Thu Dec 01, 2016 8:19 am
by Serhii Kulibaba

Please use JS below for that:

prevar today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();

if (dd < 10) {
dd='0'+dd;
}

if(mm < 10) {
mm = '0'+mm;
}

today = new Date(mm+'/'+dd+'/'+yyyy);

var currentValue = Apperyio("Search_by_State_List")&#46;val();
return {"$and":[
{"venue_state_province": currentValue},
{"start_date":{"$gte":today&#46;toISOString()}
]};/pre


List Events by Date on Results Page and Disable Expired Events by Date

Posted: Thu Dec 01, 2016 12:38 pm
by Ed

Thank you so much Sergiy!! It is working beautifully! I appreciate very much.

One last thing I noticed though. The Events do not appear in chronological order (Starting with the closest date and Ending with the farthest date). Would you mind adding a script to the JS your provided that will also Sort the events in chronological order (Starting with the closest date and Ending with the farthest date) as per the following Example:

Example:
12-01-2016
12-10-2016
12-15-2016
01-06-2017
02-10-2017

Again, thank you for all your help!