Skip to content

Commit

Permalink
Version history: Show edit button only for latest version.
Browse files Browse the repository at this point in the history
  • Loading branch information
mk-pmb committed Jun 23, 2024
1 parent 2ca1c7d commit 4a1391f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/components/anno-viewer/anno-viewer.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
v-on:mouseover.stop="mouseenter"
v-on:mouseleave.stop="mouseleave"
:data-w3-anno-id="annoIdUrl"
:data-iana-working-copy="annotation['iana:working-copy']"
:data-target-fragment="targetFragment"
>

Expand Down Expand Up @@ -404,10 +405,8 @@ <h5><span class="fa fa-link"></span>

><bootstrap-button @click="revise"
btn-class="default btn-outline-secondary"
:icon-fa="isOwnAnno ? 'pencil' : 'medkit'"
v-if="checkAclAuth({ isOwnAnno, privName: 'revise_‹own›' })"
>
{{ l10n(isOwnAnno ? 'edit' : 'edit_as_moderator') }}
v-if="editable" :icon-fa="editable.icon"
>{{ l10n(editable.voc) }}
</bootstrap-button

><bootstrap-button v-else @click="revise" caption="" btn-class="
Expand Down
31 changes: 31 additions & 0 deletions src/components/anno-viewer/anno-viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,31 @@ module.exports = {
return st;
},


editable() {
const viewer = this;
const anno = viewer.annotation;
const nonDebugEditable = (function decide() {
const { isOwnAnno } = viewer;
const auth = viewer.checkAclAuth({ isOwnAnno,
privName: 'revise_‹own›' });
if (!auth) { return false; }
const wCopy = viewer.findVersNumFromAnnoUrl(anno['iana:working-copy']);
if (wCopy) {
/* Number parsing is necessary: In version history mode, id uses
the standards compliant endpoint while working-copy uses the
author mode endpoint. */
const curVer = viewer.findVersNumFromAnnoUrl(anno.id);
if (curVer !== wCopy) { return false; }
}
return (isOwnAnno ? { icon: 'pencil', voc: 'edit' }
: { icon: 'medkit', voc: 'edit_as_moderator' });
}());
return orf(nonDebugEditable
|| (viewer.$store.state.uiDebugMode && { icon: 'cog', voc: '' }));
},


creatorsList() {
const { creator } = this.annotation;
if (!creator) { return []; }
Expand Down Expand Up @@ -339,6 +364,12 @@ module.exports = {
},


findVersNumFromAnnoUrl(url) {
if (!url) { return 0; }
return (+orf(this.$store.state.versionSuffixRgx.exec(url))[1] || 0);
},


makeEventContext() {
const viewer = this;
return {
Expand Down
3 changes: 3 additions & 0 deletions src/default-config/anno-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ const annoDataCfg = {
// ^- Optional factory function for a function that predicts DOIs
// from their anno ID or version identifier.

versionSuffixRgx: /[~_](\d+)$/,
// ^- For guessing the version number from anno ID URLs.

doiVersionSuffixRgx: /[~_]\d+$/,
// ^- In case the latest version's DOI can be predicted by omitting
// a suffix, this is a RegExp that matches the suffix.
Expand Down

0 comments on commit 4a1391f

Please sign in to comment.