-
Notifications
You must be signed in to change notification settings - Fork 28
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
Link "skip empty diffs" with "without formatting" #1114
Open
cpeel
wants to merge
1
commit into
DistributedProofreaders:master
Choose a base branch
from
cpeel:navigate-without-formatting
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -171,6 +171,42 @@ function copyToClip(textstring) { | |
echo $navigation_text; | ||
} | ||
|
||
// Load an associative array for which pages in the project have diffs. | ||
function load_page_diff_array(Project $project, $L_round, $R_round, bool $include_no_format = false): array | ||
{ | ||
if ($include_no_format) { | ||
$un_formatter = new PageUnformatter(); | ||
$text_columns = " | ||
$L_round->text_column_name as L_text, | ||
$R_round->text_column_name as R_text, | ||
"; | ||
} else { | ||
$text_columns = ""; | ||
} | ||
$sql = " | ||
SELECT image, | ||
$L_round->user_column_name as username, | ||
$text_columns | ||
CAST($L_round->text_column_name AS BINARY) = CAST($R_round->text_column_name AS BINARY) AS is_same | ||
FROM $project->projectid | ||
ORDER BY image ASC | ||
"; | ||
$res = DPDatabase::query($sql); | ||
$result = []; | ||
while ($row = mysqli_fetch_assoc($res)) { | ||
$result[$row["image"]] = [ | ||
"username" => $row["username"], | ||
"is_diff" => ! $row["is_same"], | ||
]; | ||
if ($include_no_format) { | ||
$L_text = $un_formatter->remove_formatting($row["L_text"], false); | ||
$R_text = $un_formatter->remove_formatting($row["R_text"], false); | ||
$result[$row["image"]]["is_diff_without_formatting"] = $L_text != $R_text; | ||
} | ||
} | ||
return $result; | ||
} | ||
|
||
/** | ||
* Build up the text for the navigation bit, so we can repeat it | ||
* again at the bottom of the page | ||
|
@@ -199,27 +235,24 @@ function get_navigation( | |
} | ||
$navigation_text .= "\n" . _("Jump to") . ": <select name='jumpto' onChange='$jump_to_js'>\n"; | ||
|
||
$query = " | ||
SELECT image, | ||
$L_round->user_column_name, | ||
CAST($L_round->text_column_name AS BINARY) = CAST($R_round->text_column_name AS BINARY) AS is_empty_diff | ||
FROM $project->projectid | ||
ORDER BY image ASC | ||
"; | ||
$res = DPDatabase::query($query); | ||
$diff_array = load_page_diff_array($project, $L_round, $R_round, $format == "remove"); | ||
|
||
$prev_image = ""; | ||
$next_image = ""; | ||
$prev_from_proofer = ""; | ||
$next_from_proofer = ""; | ||
$got_there = false; | ||
// construct the dropdown; work out where previous and next buttons should take us | ||
while ([$this_val, $this_user, $is_empty_diff] = mysqli_fetch_row($res)) { | ||
foreach ($diff_array as $this_val => $diff_record) { | ||
$this_user = $diff_record["username"]; | ||
$is_diff = $format == "remove" ? $diff_record["is_diff_without_formatting"] : $diff_record["is_diff"]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you wanted to be slightly cleverer you could push the ternary inside the index:
|
||
|
||
$navigation_text .= "\n<option value='$this_val'"; | ||
|
||
if ($this_val == $image) { | ||
$navigation_text .= " selected"; // make the correct element of the drop down selected | ||
$got_there = true; | ||
} elseif ($only_nonempty_diffs && $is_empty_diff) { | ||
} elseif ($only_nonempty_diffs && !$is_diff) { | ||
$navigation_text .= " disabled"; // Disable empty diffs in the dropdown and skip the other checks | ||
} elseif ($got_there) { | ||
// we are at the one after the current one | ||
|
@@ -270,9 +303,9 @@ function get_navigation( | |
} | ||
|
||
$checked_attribute = $only_nonempty_diffs ? 'checked' : ''; | ||
|
||
$checkbox_title = $format == "remove" ? _('Skip empty diffs, ignoring formatting') : _('Skip empty diffs'); | ||
$navigation_text .= "\n<input type='checkbox' name='only_nonempty_diffs' $checked_attribute id='only_nonempty_diffs' onclick='this.form.submit()'>\n"; | ||
$navigation_text .= "\n<label for='only_nonempty_diffs'>" . html_safe(_('Skip empty diffs')) . "</label>\n"; | ||
$navigation_text .= "\n<label for='only_nonempty_diffs'>" . html_safe($checkbox_title) . "</label>\n"; | ||
$navigation_text .= "\n</form>\n"; | ||
|
||
return $navigation_text; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we're trying to get better about this could we add