I have an app where users can view sporting events for today's date or a given date (if the user manually enters it in the URL). A user can navigate sporting events by date with a UI control, which crudely looks like this:
Tue Nov. 27 | Wed Nov. 28 | Thu Nov. 29
(The dates are links except the current active one in the middle.)
This date nav control works great for sporting events that occur nearly every day. The user is never staring at a blank page of events. However, for sporting events such as the NFL, events only occur on Monday, Thursday, Sunday (sometimes Saturday) and it becomes cumbersome for the user to use the date nav UI control.
What I'd like to do is to change the logic behind the creation of the date nav UI links to include only those dates that have events. The logic would be something like:
Given today's date or a date supplied by the user, return the nearest date which has events (current_date)
Given a current_date, find the nearest previous date which has events (previous_date)
Given a current_date, find the nearest next date which has events (next_date)
So, in the case of the NFL, the date nav UI control might look like, assuming today's date is Nov 27:
Mon Nov. 25 | Thu Nov. 29 | Sun Dec. 2
The way in which to tell if there are any events for a given date is by start_time field in the DB.
I don't like to post a question without some code, but I'm looking for some guidance as to how I should approach this without having to hit the DB a ton of times.
NOTE #1: When you click on a date for a sport, it returns all the events for that date. The date nav is not used for viewing individual events.
Create a scope method in your model that grabs the next two start dates for the given sport, and the most recent start date. Limit it to return only three records.
Use this scope in your controller to fetch only those three game objects. With those three game objects in the controller, pass them to a view partial as an instance variable (e.g. render #games), and in the partial, write the generic link code <%= link_to "#{#games.start_time}", your_path(#game) %>. Rails will automatically iterate this partial for the number of objects in the collection (the three games).
Source: http://guides.rubyonrails.org/layouts_and_rendering.html#using-partials
Related
I am developing an automated calendar for a school on AirTable, but I am struggling to add if there is a bank holiday between the start date and end date. If the bank holiday falls on a weekday, it needs to add +1 day to the end date.
I have created a "bank holiday" table, as well as a full calendar table (containing everyday of the year and what weekday it falls on).
I'd like for the user to have the end date generated automatically by only writing the start date.
For example:
I have a session starting on Monday, 7th of march. The "session type" would be "Course 1", which has a duration of 10 days (two weeks, monday to friday - I don't know if the duration should be 14 days instead?). If there's a bank holiday in the 10 days after the start date, and it's on a weekday, it needs to add +1 to the end date. If the end date falls on a sunday, it needs to add +2 so that it ends on a Monday.
The course is divided in multiple classes, it would also be awesome to have a timeline view with the full Course and all the classes.
Here are some screenshots of my tables :
I know there is a possibility to write a script in Python with an AirTable API... but is there an easier way ?
I've dealt with a problem like this before: when an event happened in relation to other events mattered.
You'd think by the use of the words "in relation" that you could deal with this in a relational way, but I see it as a rule:
If Event A happens at Time 1, and it's so much or so little time from Event B, then do with Event A...
And, again by my way of thinking, rules are expressed in code.
And if you actually even can express that with a relation, I think it'd be very convoluted.
So, for your problem, you need to encode every schedule-able day that's 10 working days or less before a Bank Holiday (BH) so that if the day is selected you know it's less than 10 days from a BH and can conditionally add another day to the end date.
I looked at your examples, and here's my solution. I have a Calendar table which has all days, and two supporting "Bank Holiday" fields: does the date fall on a BH, and if not, is the date 10 days or less from a BH. We're looking at my All view, here:
I also have the view, Weekday, not bank holiday, and that's the view that you can pick a day from to schedule an event from the Event table.
The Event table:
You pick a day from the Start day field. Start day < 10 work days to Bank holiday? is a lookup field from the Calendar table for that day. End day is this formula:
DATETIME_FORMAT(
DATEADD(
{Start date},
IF(
{Start day < 10 work days to Bank holiday?},
14,
13),
'day'),
'ddd, MMM Do')
I am trying to build a timetable setup to work in conjunction with one of my Models. Before I state my question, I will give some context into the problem.
I have a Model called Appointments with the following columns:
Name(String)
Start_time(time)
End_time(time)
Appt_Date(date)
Now I can have multiple appointments in 1 day.
For Example, let's say I have the following 2 Appointment objects:
Appointment 1:
Name: Makeup Appointment
Start_time: 11:00 am
End_time: 1:00 pm
Date: March 30, 2016
Appointment 2:
Name: Daily Meetup
Start-time: 2:00 pm
End_time: 3:00 pm
Date: March 30, 2016
I would like to implement a date-picker form where you can select a date and it would render 24 rows(1 for each hour of the day) and fill in the rows with the times not available based on the appointments on that day.
For example, if I select March 30, 2016 from the date-picker, I would like to render the 24 rows and have the rows for 11am-1pm and 2:00pm-3:00pm shaded out.
The setup is like google calendars(how time slots are colored in) but with a day-to-day basis. I don't need to be able to edit these rows. I just need to view them and have them rendered with colored cells based on Appointment objects for that specific day.
My issue is, I don't know where to begin to be able to design these 24 rows that interact with appointment objects. I was thinking that perhaps I build a helper method, however even that I am pretty lost. I would appreciate some guidance on how to approach this.
Below will help you:
1.Create a file in initializer which contains list of available time slots like 10 am to 10 pm.
2.For displaying date time field , use some jquery date time picker plugin.
3.Fire an ajax when clicked on datetime picker.
4.Ajax request will come on the controller & where you have to create an active record query which will fetch all apointments according to the particular date.
5.MAke an array variable & store the time which are already booked in the above appointments.
6.Compare the available time with the booked time & edit datetimepikcer.js to shaded the booked date.
I am trying to use an HTML5 input in MobileSafari to get date. When I use 'date', it shows three reels, Month, Day (#), Year:
Jan | 4th | 1948
When I select 'datetime', it shows 4 reels for date and time:
Wed Mar 6 | 3 | 05 | PM
Is there a way to make it just show the 'Wed Mar 6' from the 'datetime' and the year in the native selector? I'd like users to be able to see the day when they make the date selection instead of having to count how many days until Friday. I don't need the time selection, But I want the date formatting from that input type.
It's browser-implementation dependant sorry. You'd have to make your own browser and make them use that. As far as I'm aware HTML5 isn't actually 100% out yet; w3c are still tweaking it and browsers can't agree on how to render the new elements.
If it's absolutely essential you may have to consider using a flash or java plugin object.
I change calendar javascript to Hijri, But another problem comes up. It seems that a class (DueDateValidator.class) try to validate input date, while the number of days in month is different to georgian calendar. for example we have 31 days in second month of year but in georgian (february) it is 28 or 29.
I don't think there is an out-of-the-box option to cancel Jira's date validation. You could overwrite Jira's date validation, but I think it will be easier to use a Free Text Field custom field that will hold the date as a string. Then, add to the field js code that will hide this field and copy it's date to the date field.
To keep the right order when searching for issues, you can either use date mapping to keep the georgian calendar up to date, or store the dates in a sortable way (for example YYYY/MM/DD/HH/MM - 201302161334) and order the results according to this field.
UPDATE
Simple example for Jira version 5.2.6, this will copy the text from field id customfield_10001 to the created field:
AJS.$("#create-date").text(AJS.$("#customfield_10001-val").text().trim())
To search easily keep another text field and save the date in the following format :
year month day hour minute
All in digits. for example, today's Gregorian date would be:
2013 02 267 10 26
than, when searching for issues, for example to find issues created after today's date:
custom_filed > "2013 02 267 10 26"
that sorting will work since it will sort issues first by year, than month, day, hour, minute.
I stored date in text field by creating new custom field in system-customfieldtypes-plugin.xml filed but In search it only accept exact text not > or <
custom_filed ~ "2013 02 267 10 26" It is acceptable but
custom_filed > "2013 02 267 10 26" shows jQL error.
I am very new to Ruby/Rails and just I am trying to find the most elegant way to do a table in ERB where the columns are the weekday and the rows are each record for a given model. The concept itself is easy and I can probably do it through a bunch of manual code, but I would like to leverage as much rails/erb magic as possible. To be more specific, here is what I have defined.
A model that lists all users
A model that lists a single status for each user for a given date (each user can only have one status for a given date: say 'on' or 'off')
I want a view that lists all the users in a table with their status for that week. Eg:
Mon | Tue | ... | Fri
User1 on | off | ... |
User2 off | | ... |
A couple things to note:
- (as I already mentioned) A user can only have one status per day
- A user may not have any status for a given day
- No columns for Sat/Sun
- The table will always show the full current week, even if the day is on Tue (ie. in that case the Wed .. Fri entries will just be blank).
Now, again, I am sure I can write a bunch of erb code to do this all manually, but was hoping to use some rails magic. Any pointers or help would greatly be appreciated.
You could always do something like:
#monday = Date.today.at_beginning_of_week
7.times do |x|
#days << x.days.since(#monday)
end
Then loop through #days in your view.
You could print the date, or just the day in hour table rows. Useful in that you can also look up your users status using that date.