[aur-dev] [PATCH v6] pkg_details.php: Show keywords
Keywords are hyperlinked so a user can search for other packages with the same name and/or keyword. Signed-off-by: Marcel Korpel <marcel.korpel@gmail.com> --- Small improvement to make the focus border stick out of the focused element. web/html/css/aurweb.css | 23 +++++++++++++++++++++++ web/template/pkg_details.php | 19 +++++++++++++++++-- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/web/html/css/aurweb.css b/web/html/css/aurweb.css index a3f43bd..7f63abb 100644 --- a/web/html/css/aurweb.css +++ b/web/html/css/aurweb.css @@ -53,6 +53,29 @@ text-align:right; } +td#keywords { + white-space: normal; +} + +.keyword:link, .keyword:visited { + float: left; + margin: 1px 2px 1px 0; + border: 1px solid transparent; + padding: 2px .5em; + background: #1794D1; + color: #FFF; + border-radius: 2px; +} + +.keyword:hover { + color: #FFF; + cursor: pointer; +} + +.keyword:focus { + border: 1px dotted #000; +} + .text-button { background: transparent; border: none !important; diff --git a/web/template/pkg_details.php b/web/template/pkg_details.php index ae49e24..8cae135 100644 --- a/web/template/pkg_details.php +++ b/web/template/pkg_details.php @@ -190,11 +190,14 @@ $sources = pkg_sources($row["ID"]); <td><a href="<?= htmlspecialchars($row['URL'], ENT_QUOTES) ?>" title="<?= __('Visit the website for') . ' ' . htmlspecialchars( $row['Name'])?>"><?= htmlspecialchars($row['URL'], ENT_QUOTES) ?></a></td> </tr> <?php -if (has_credential(CRED_PKGBASE_SET_KEYWORDS, array($row["MaintainerUID"]))): +if (has_credential(CRED_PKGBASE_SET_KEYWORDS, array($row["MaintainerUID"])) || count($keywords) > 0): ?> <tr> <th><?= __('Keywords') . ': ' ?></th> - <td> + <td id="keywords"> +<?php + if (has_credential(CRED_PKGBASE_SET_KEYWORDS, array($row["MaintainerUID"]))): +?> <form method="post" action="<?= htmlspecialchars(get_pkgbase_uri($row['BaseName']), ENT_QUOTES); ?>"> <div> <input type="hidden" name="action" value="do_SetKeywords" /> @@ -205,6 +208,18 @@ if (has_credential(CRED_PKGBASE_SET_KEYWORDS, array($row["MaintainerUID"]))): <input type="submit" value="<?= __('Update') ?>"/> </div> </form> +<?php + else: + foreach ($keywords as $kw) { + echo ' <a class="keyword" href="'; + /* Several default search parameters are hard-coded, + perhaps this should be changed/configured somewhere */ + echo get_uri('/packages/') . '?O=0&SeB=nd&K=' . urlencode($kw); + echo '&outdated=&SB=p&SO=a&PP=50&do_Search=Go'; + echo '">' . htmlspecialchars($kw) . "</a>\n"; + } + endif; +?> </td> </tr> <?php endif; ?> -- 2.4.4
On Thu, 18 Jun 2015 at 00:57:14, Marcel Korpel wrote:
Keywords are hyperlinked so a user can search for other packages with the same name and/or keyword.
Nice addition, thanks!
Signed-off-by: Marcel Korpel <marcel.korpel@gmail.com> --- Small improvement to make the focus border stick out of the focused element.
web/html/css/aurweb.css | 23 +++++++++++++++++++++++ web/template/pkg_details.php | 19 +++++++++++++++++-- 2 files changed, 40 insertions(+), 2 deletions(-)
diff --git a/web/html/css/aurweb.css b/web/html/css/aurweb.css index a3f43bd..7f63abb 100644 --- a/web/html/css/aurweb.css +++ b/web/html/css/aurweb.css @@ -53,6 +53,29 @@ text-align:right; }
+td#keywords { + white-space: normal; +}
Is this needed?
+ +.keyword:link, .keyword:visited { + float: left; + margin: 1px 2px 1px 0; + border: 1px solid transparent; + padding: 2px .5em; + background: #1794D1; + color: #FFF; + border-radius: 2px; +} + +.keyword:hover { + color: #FFF; + cursor: pointer; +} + +.keyword:focus { + border: 1px dotted #000; +} +
I tried the following CSS instead: .keyword:link, .keyword:visited { float: left; margin: 1px .5ex 1px 0; padding: 0 1em; color: white; background-color: #36a; border-radius: 2px; } .keyword:hover { cursor: pointer; } I like the darker colors better. Opinions?
.text-button { background: transparent; border: none !important; diff --git a/web/template/pkg_details.php b/web/template/pkg_details.php index ae49e24..8cae135 100644 --- a/web/template/pkg_details.php +++ b/web/template/pkg_details.php @@ -190,11 +190,14 @@ $sources = pkg_sources($row["ID"]); <td><a href="<?= htmlspecialchars($row['URL'], ENT_QUOTES) ?>" title="<?= __('Visit the website for') . ' ' . htmlspecialchars( $row['Name'])?>"><?= htmlspecialchars($row['URL'], ENT_QUOTES) ?></a></td> </tr> <?php -if (has_credential(CRED_PKGBASE_SET_KEYWORDS, array($row["MaintainerUID"]))): +if (has_credential(CRED_PKGBASE_SET_KEYWORDS, array($row["MaintainerUID"])) || count($keywords) > 0): ?> <tr> <th><?= __('Keywords') . ': ' ?></th> - <td> + <td id="keywords"> +<?php + if (has_credential(CRED_PKGBASE_SET_KEYWORDS, array($row["MaintainerUID"]))):
Don't indent here, please.
+?> <form method="post" action="<?= htmlspecialchars(get_pkgbase_uri($row['BaseName']), ENT_QUOTES); ?>"> <div> <input type="hidden" name="action" value="do_SetKeywords" /> @@ -205,6 +208,18 @@ if (has_credential(CRED_PKGBASE_SET_KEYWORDS, array($row["MaintainerUID"]))): <input type="submit" value="<?= __('Update') ?>"/> </div> </form> +<?php + else:
Again, no indentation here.
+ foreach ($keywords as $kw) { + echo ' <a class="keyword" href="';
Please also drop the printed whitespace. We do not care about the formatting of the output and this makes the source code slightly harder to read.
+ /* Several default search parameters are hard-coded, + perhaps this should be changed/configured somewhere */ + echo get_uri('/packages/') . '?O=0&SeB=nd&K=' . urlencode($kw); + echo '&outdated=&SB=p&SO=a&PP=50&do_Search=Go'; + echo '">' . htmlspecialchars($kw) . "</a>\n";
There's no need to specify all these values. Just specify the parameters that are needed (K and SB). The remaining values will be initialized with the corresponding default values automatically.
+ } + endif; +?>
All these changes need to be made in pkgbase_details.php as well. It would be desirable to get rid of this code duplication but for now, every change needs to be made in both places.
</td> </tr> <?php endif; ?> -- 2.4.4
* Lukas Fleischer <lfleischer@archlinux.org> (Thu, 18 Jun 2015 09:14:23 +0200):
+td#keywords { + white-space: normal; +}
Is this needed?
For one reason or another in archweb.css is (l. 246ff.): th, td { white-space: nowrap; text-align: left; } If we don't reset that for this cell, all keywords are attached to eachother in one long line, causing the layout to break. Ah, that was when the float: left wasn't there yet, with that it works without white-space: normal.
I tried the following CSS instead:
.keyword:link, .keyword:visited { float: left; margin: 1px .5ex 1px 0; padding: 0 1em; color: white; background-color: #36a; border-radius: 2px; }
.keyword:hover { cursor: pointer; }
I like the darker colors better. Opinions?
Yes, this looks better, but now the focus border is drawn around a selected tag, that makes the button in the row below jump (and the button itself moves to the right and bottom with 1px. I'll amend your CSS to circumvent this issue.
+<?php + if (has_credential(CRED_PKGBASE_SET_KEYWORDS, array($row["MaintainerUID"]))):
Don't indent here, please.
Okay. It is a nested if, so I thought I should indent it.
+ echo ' <a class="keyword" href="';
Please also drop the printed whitespace. We do not care about the formatting of the output and this makes the source code slightly harder to read.
Okay.
+ echo get_uri('/packages/') . '?O=0&SeB=nd&K=' . urlencode($kw); + echo '&outdated=&SB=p&SO=a&PP=50&do_Search=Go'; + echo '">' . htmlspecialchars($kw) . "</a>\n";
There's no need to specify all these values. Just specify the parameters that are needed (K and SB). The remaining values will be initialized with the corresponding default values automatically.
Done. The only drawback is that when clicking 'Go' on the search result page, the URL is filled with those default values, but the same page appears. This slightly 'breaks' the back button, as going one page back shows the same page again. With all default parameters already sent this behaviour isn't exhibited and the user goes just back to the package page after clicking 'Go' and 'back'.
All these changes need to be made in pkgbase_details.php as well. It would be desirable to get rid of this code duplication but for now, every change needs to be made in both places.
I'll do so and send a new patch soon.
participants (2)
-
Lukas Fleischer
-
Marcel Korpel