Skip to content

Commit

Permalink
Metadata citation improvements: add option to save the citation to a …
Browse files Browse the repository at this point in the history
…file
  • Loading branch information
josegar74 committed Jan 30, 2025
1 parent 892e45e commit 72130a0
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,23 @@
return "../api/records/" + scope.md.uuid + "/formatters/citation?format=";
}

var getCitationFormatExtension = function (format) {
if (format === "text") {
return "txt";
} else {
return format ? format : "txt";
}
};

scope.getCitationFilename = function () {
return (
"citation-" +
scope.md.uuid +
"." +
getCitationFormatExtension(scope.currentFormat)
);
};

scope.getCitation = function (format) {
return $http
.get(buildUrl() + format, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ <h2>
</h2>
</div>
<div>
<div
class="gn-copy-to-clipboard-button-floatright gn-margin-left-sm"
gn-save-text-button=""
data-file-name="{{ getCitationFilename() }}"
></div>

<div
class="gn-copy-to-clipboard-button-floatright"
gn-copy-to-clipboard-button=""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1194,12 +1194,12 @@
*
* The code to be used in a HTML page:
*
* <span gn-copy-to-clipboard=""></span>
* <span gn-copy-to-clipboard-button=""></span>
* eg. for citation
*
* or
*
* <span gn-copy-to-clipboard="" data-text="{{::r.locUrl}}" gn-copy-button-only="true"></span>
* <span gn-copy-to-clipboard-button="" data-text="{{::r.locUrl}}" gn-copy-button-only="true"></span>
* eg. copy UUID or link URL
*
* or
Expand Down Expand Up @@ -1261,6 +1261,67 @@
}
]);

/*
* @description
* Save a file with a string in an input field, the parent element text
* or the results of a promise.
*
* The code to be used in a HTML page:
*
* <span gn-save-text-button="" data-file-name="citation.txt"></span>
* eg. for citation
*
* <span gn-save-text-button="" data-text="{{::r.locUrl}}"></span>
* eg. save UUID or link URL
*
* or
*
* <button gn-save-text-button="" get-text-fn="getListOfUuids()"/>
* eg. UUID of record with indexing errors
*/
module.directive("gnSaveTextButton", [
"$q",
function ($q) {
return {
restrict: "A",
replace: true,
template:
"<a class=\"{{::btnClass || 'btn btn-default btn-xs'}}\" " +
' ng-click="save()" ' +
' href=""' +
' title="{{::title | translate}}">' +
' <i class="fa fa-download"></i>' +
"</a>",
scope: {
btnClass: "@",
getTextFn: "&?",
fileName: "@"
},
link: function linkFn(scope, element, attr) {
scope.title = attr["tooltip"] || "saveToFile";
scope.fileName = scope.fileName || "file.txt";
scope.save = function () {
var promise = undefined;

if (angular.isFunction(scope.getTextFn)) {
promise = scope.getTextFn();
} else {
promise = $q.when(
attr["text"] ? attr["text"] : element.parent().text().trim()
);
}

promise.then(function (text) {
var blob = new Blob([text], { type: "text/plain;charset=utf-8" });
// Bootstrap FileSaver
saveAs(blob, scope.fileName);
});
};
}
};
}
]);

/**
* @ngdoc directive
* @name gn_utility.directive:gnMetadataPicker
Expand Down
3 changes: 2 additions & 1 deletion web-ui/src/main/resources/catalog/locales/en-core.json
Original file line number Diff line number Diff line change
Expand Up @@ -588,5 +588,6 @@
"mapLegend": "Legend",
"quality": "Quality",
"download": "Download",
"links": "Links"
"links": "Links",
"saveToFile": "Save to file."
}

0 comments on commit 72130a0

Please sign in to comment.