Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Working on #2972 Template Conversion to Twig Format (calendar.php) #2984

Merged
merged 10 commits into from
Jan 14, 2018
Merged

Working on #2972 Template Conversion to Twig Format (calendar.php) #2984

merged 10 commits into from
Jan 14, 2018

Conversation

Starpaul20
Copy link
Member

@Starpaul20 Starpaul20 commented Jan 12, 2018

Working on #2972

This PR is for the calendar (calendar.php).

Copy link
Member

@euantorano euantorano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a big one! Great work so far 😄

calendar.php Outdated
$years[] = $year;
}

$timezones = build_timezone_select("timezone", $timezone);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this is worth making a Twig function - do we use the same function elsewhere (such as the User CP)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I'm aware it's the same everywhere. So it could be a Twig function

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, sounds good. Not sure whether we should have a TimeDateExtension for this and my_date (and whether we have any other time/date related functions to add to it) or if we should just create a CoreExtension/MybbExtension with these kinds of functions...

calendar.php Outdated
// Construct option list for years
for ($year = my_date('Y'); $year < (my_date('Y') + 5); ++$year) {
if ($year == $single_year) {
$select['single_year'] = "selected=\"selected\"";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to do this logic inside the view rather than building HTML in the backend code. Same goes with the other instances of this type of code.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, but I'm not sure how to do that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two options:

  • Do the conditional check in Twig
  • Set a variable such as $select['single_year_selected'] = true and in twig do something like:
<option{%if select.single_year_selected %} selected="selected"{%endif}/>

Option two is the easiest by far.

<tr>
<td class="trow2" style="vertical-align: top;"><strong>{{ lang.event_date }}</strong></td>
<td class="trow1">
<script type="text/javascript">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A note for @justinsoltesz @Eric-Jackson - would be nice to take this inline JS out. The less inline JS we have, the better in my opinion.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be great if we could have none so that admins can use a CSP without unsafe-inline.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah same goes for inline CSS imo, which is happening after the conversion to Twig I believe. Not sure if it would be better to remove JS now, or wait until we're making the changes to the HTML for a responsive theme.

<dl style="margin-top: 0; margin-bottom: 0; width: 100%;">
<dt><input type="radio" name="type" value="single" {{ select.type_single }} id="type_single" onclick="toggleType();" /> <label for="type_single"><strong>{{ lang.type_single }}</strong></label></dt>
<dd style="margin-top: 4px;" id="single_selects">
<select name="single_day">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps a good idea to try and abstract this into a loop and possibly break it into a function or partial view or something?

@Ben-MyBB Ben-MyBB added the b:1.9 Branch: 1.9.x label Jan 13, 2018
@Starpaul20
Copy link
Member Author

I've finished the conversion work on the calendar. Once I fix the above issues (I hope to do them tomorrow) this will be ready to merge.

One thing I want to ask everyone, should we keep the $gobutton function? I've been including it so far as {{ gobutton|raw }} but it seems pointless. All it does is load a template that contains a submit button, something that can be done inline easily.

@euantorano
Copy link
Member

euantorano commented Jan 14, 2018 via email

-Added selected and checked HTML to templates
-Move day select options to array
@Starpaul20
Copy link
Member Author

That should be everything. If there are no other issues this can be merged.

@euantorano euantorano added t:enhancement Type: Enhancement. Contains minor improvements s:in-progress Status: In Progress. Some work completed s:resolved Status: Resolved. Solution implemented or scheduled and removed s:in-progress Status: In Progress. Some work completed labels Jan 14, 2018
Copy link
Member

@euantorano euantorano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Justa few more minor comments. This is a big bunch of templates, thanks a lot for working on it.

Note that I'm not sure the loop idea will work at all, but it's worth testing.

</select>
&nbsp;
<select name="single_month">
<option value="1"{% if select.single_month.1 %} selected="selected"{% endif %}>{{ lang.month_1 }}</option>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big deal, but repeated blocks like these where it's easy to forget to update a single number make me anxious. The problem with using a loop here would be the month language variable, right? If so, you an kind of cheat:

{% for i in 1..12 %}
    <option value="{{ i }}"{% if select.single_month[i] %} selected="selected"{% endif %}>{{ attribute(lang, 'month_' ~ i) }}</option>
{% endfor %}

The trick here is using the [] square brackets for the condition, and the attribute core Twig function to get the language variable (with string concatenation using the ~ operator).

I believe that should work, but I haven't tested it at all.

{% if calendar.prev_link %}
<a href="{{ calendar.prev_link|raw }}">&laquo; {{ calendar.prev_month_name }} {{ calendar.prev_month_year }}</a>
{% endif %}
{% if calendar.sep == true %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could simplify this to {% if calendar.sep %}, since you already use the short form for next_link below (unless this can be a string or some other type or something...).

<select name="month">
<option value="{{ calendar.month }}">{{ calendar.currentmonth }}</option>
<option value="{{ calendar.month }}">----------</option>
<option value="1">{{ lang.alt_month_1 }}</option>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, could use the same loop trick I mentioned in the other template file hopefully.

<select name="month">
<option value="{{ calendar.month }}">{{ calendar.currentmonth }}</option>
<option value="{{ calendar.month }}">----------</option>
<option value="1">{{ lang.alt_month_1 }}</option>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Loop trick again 😉

<select name="month">
<option value="{{ calendar.week_from_month }}">{{ calendar.week_from_one }}</option>
<option value="{{ calendar.week_from_month }}">----------</option>
<option value="1">{{ lang.alt_month_1 }}</option>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Loop again 😄

- Moved month select options to array
- Split bottom calendar jump/month jump into seperate Twig file
- Converted user stars to Twig
@Starpaul20
Copy link
Member Author

I've converted the most months to use for loops. The ones I didn't I moved to their own file and included it where necessary (so there's only one instance instead of four).

@euantorano
Copy link
Member

Nice one, thanks. Looks much cleaner now!

@euantorano euantorano merged commit d398853 into mybb:develop/1.9 Jan 14, 2018
@euantorano
Copy link
Member

@PaulBender Can you update the template list in #2972 with the templates you've sorted with this?

@Starpaul20 Starpaul20 deleted the develop-1.9-calendar branch January 14, 2018 22:23
euantorano pushed a commit that referenced this pull request Mar 16, 2018
…2984)

* Working on #2972 Template Conversion to Twig Format (calendar.php)
Part 1 - Adding an event

* Working on #2972 Template Conversion to Twig Format (calendar.php)
Part 2 - Editing an event

* Working on #2972 Template Conversion to Twig Format (calendar.php)
Part 3 - Moving event

* Working on #2972 Template Conversion to Twig Format (calendar.php)
Part 4 - Viewing an event

* Working on #2972 Template Conversion to Twig Format (calendar.php)
Part 5 - Day view

* Working on #2972 Template Conversion to Twig Format (calendar.php)
Part 6 - Week view

* Working on #2972 Template Conversion to Twig Format (calendar.php)
Part 7 - Calendar

* Moved gobutton to inline

* Code updates
-Added selected and checked HTML to templates
-Move day select options to array

* More code updates
- Moved month select options to array
- Split bottom calendar jump/month jump into seperate Twig file
- Converted user stars to Twig
euantorano pushed a commit to euantorano/mybb that referenced this pull request Mar 23, 2019
mybb#2984)

* Working on mybb#2972 Template Conversion to Twig Format (calendar.php)
Part 1 - Adding an event

* Working on mybb#2972 Template Conversion to Twig Format (calendar.php)
Part 2 - Editing an event

* Working on mybb#2972 Template Conversion to Twig Format (calendar.php)
Part 3 - Moving event

* Working on mybb#2972 Template Conversion to Twig Format (calendar.php)
Part 4 - Viewing an event

* Working on mybb#2972 Template Conversion to Twig Format (calendar.php)
Part 5 - Day view

* Working on mybb#2972 Template Conversion to Twig Format (calendar.php)
Part 6 - Week view

* Working on mybb#2972 Template Conversion to Twig Format (calendar.php)
Part 7 - Calendar

* Moved gobutton to inline

* Code updates
-Added selected and checked HTML to templates
-Move day select options to array

* More code updates
- Moved month select options to array
- Split bottom calendar jump/month jump into seperate Twig file
- Converted user stars to Twig
euantorano pushed a commit to euantorano/mybb that referenced this pull request Mar 23, 2019
mybb#2984)

* Working on mybb#2972 Template Conversion to Twig Format (calendar.php)
Part 1 - Adding an event

* Working on mybb#2972 Template Conversion to Twig Format (calendar.php)
Part 2 - Editing an event

* Working on mybb#2972 Template Conversion to Twig Format (calendar.php)
Part 3 - Moving event

* Working on mybb#2972 Template Conversion to Twig Format (calendar.php)
Part 4 - Viewing an event

* Working on mybb#2972 Template Conversion to Twig Format (calendar.php)
Part 5 - Day view

* Working on mybb#2972 Template Conversion to Twig Format (calendar.php)
Part 6 - Week view

* Working on mybb#2972 Template Conversion to Twig Format (calendar.php)
Part 7 - Calendar

* Moved gobutton to inline

* Code updates
-Added selected and checked HTML to templates
-Move day select options to array

* More code updates
- Moved month select options to array
- Split bottom calendar jump/month jump into seperate Twig file
- Converted user stars to Twig
euantorano pushed a commit that referenced this pull request Jun 2, 2019
…2984)

* Working on #2972 Template Conversion to Twig Format (calendar.php)
Part 1 - Adding an event

* Working on #2972 Template Conversion to Twig Format (calendar.php)
Part 2 - Editing an event

* Working on #2972 Template Conversion to Twig Format (calendar.php)
Part 3 - Moving event

* Working on #2972 Template Conversion to Twig Format (calendar.php)
Part 4 - Viewing an event

* Working on #2972 Template Conversion to Twig Format (calendar.php)
Part 5 - Day view

* Working on #2972 Template Conversion to Twig Format (calendar.php)
Part 6 - Week view

* Working on #2972 Template Conversion to Twig Format (calendar.php)
Part 7 - Calendar

* Moved gobutton to inline

* Code updates
-Added selected and checked HTML to templates
-Move day select options to array

* More code updates
- Moved month select options to array
- Split bottom calendar jump/month jump into seperate Twig file
- Converted user stars to Twig
euantorano pushed a commit that referenced this pull request Jun 2, 2019
…2984)

* Working on #2972 Template Conversion to Twig Format (calendar.php)
Part 1 - Adding an event

* Working on #2972 Template Conversion to Twig Format (calendar.php)
Part 2 - Editing an event

* Working on #2972 Template Conversion to Twig Format (calendar.php)
Part 3 - Moving event

* Working on #2972 Template Conversion to Twig Format (calendar.php)
Part 4 - Viewing an event

* Working on #2972 Template Conversion to Twig Format (calendar.php)
Part 5 - Day view

* Working on #2972 Template Conversion to Twig Format (calendar.php)
Part 6 - Week view

* Working on #2972 Template Conversion to Twig Format (calendar.php)
Part 7 - Calendar

* Moved gobutton to inline

* Code updates
-Added selected and checked HTML to templates
-Move day select options to array

* More code updates
- Moved month select options to array
- Split bottom calendar jump/month jump into seperate Twig file
- Converted user stars to Twig
@euantorano euantorano mentioned this pull request Jan 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
b:1.9 Branch: 1.9.x s:resolved Status: Resolved. Solution implemented or scheduled t:enhancement Type: Enhancement. Contains minor improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants