Skip to content

Suggested clean up and minor issue fixes.#36

Merged
Alex-Jordan merged 1 commit into
Alex-Jordan:conffrom
drgrice1:conf-suggestions
Jun 6, 2026
Merged

Suggested clean up and minor issue fixes.#36
Alex-Jordan merged 1 commit into
Alex-Jordan:conffrom
drgrice1:conf-suggestions

Conversation

@drgrice1
Copy link
Copy Markdown

@drgrice1 drgrice1 commented Jun 6, 2026

The JavaScript needs to not attempt to do anything with the add_on_conf select if it is not present in the page, as that causes errors. For instance if the $webworkDirs{addOnConf} directory is not present, or is empty.

With modern JavaScript, don't use the array forEach method unless it gives a convenient and brief one liner. Generally prefer a for of loop as it is more readable. Another advantage is that for of loops work on HTMLCollections and forEach does not. The result of a querySelectorAll call or the children of an Element are HTMLCollections, and so a for of loop works directly, while Array.from is needed to use forEach. This is a minor inefficiency in this case, but that does require constructing an array from the HTMLCollection.

I rewrote the writeCourseConf POD to clarify its usage some with the new optional parameter.

In the writeCourseConf method, it should be checked that the $addOnConf variable is an array reference, and not that it is not equal to the empty string. Any numeric value or non empty string is not equal to the empty string and would cause an error if $addOnConf is set to any of those. The check should be that ref $addOnConf eq 'ARRAY'. That is the only condition that guarantees an error will not occur and that the value of the variable will work inside the conditional block.

Minor cleanup in the templates/ContentGenerator/CourseAdmin/add_course_form.html.ep file. There is no need to copy the value of $ce->{webworkDirs}{addOnConf} to a local variable. Particularly since that can be used directly even in string interpolation.

The JavaScript needs to not attempt to do anything with the
`add_on_conf` select if it is not present in the page, as that causes
errors. For instance if the `$webworkDirs{addOnConf}` directory is not
present, or is empty.

With modern JavaScript, don't use the array `forEach` method unless it
gives a convenient and brief one liner.  Generally prefer a `for of`
loop as it is more readable. Another advantage is that `for of` loops
work on `HTMLCollection`s and `forEach` does not.  The result of a
`querySelectorAll` call or the `children` of an `Element` are
`HTMLCollection`s, and so a `for of` loop works directly, while
`Array.from` is needed to use `forEach`. This is a minor inefficiency in
this case, but that does require constructing an array from the
`HTMLCollection`.

I rewrote the `writeCourseConf` POD to clarify its usage some with the
new optional parameter.

In the `writeCourseConf` method, it should be checked that the
`$addOnConf` variable is an array reference, and not that it is not
equal to the empty string. Any numeric value or non empty string is not
equal to the empty string and would cause an error if `$addOnConf` is
set to any of those.  The check should be that `ref $addOnConf eq 'ARRAY'`.
That is the only condition that guarantees an error will not occur and
that the value of the variable will work inside the conditional block.

Minor cleanup in the `templates/ContentGenerator/CourseAdmin/add_course_form.html.ep`
file. There is no need to copy the value of `$ce->{webworkDirs}{addOnConf}`
to a local variable.  Particularly since that can be used directly even
in string interpolation.
Copy link
Copy Markdown
Owner

@Alex-Jordan Alex-Jordan left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

@Alex-Jordan Alex-Jordan merged commit e85a7c8 into Alex-Jordan:conf Jun 6, 2026
2 checks passed
@drgrice1 drgrice1 deleted the conf-suggestions branch June 6, 2026 21:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants