Skip to content

Commit

Permalink
Merge pull request #10408 from jmchilton/author_license_2009
Browse files Browse the repository at this point in the history
Microdata for tools and workflows.
  • Loading branch information
mvdbeek authored Nov 18, 2020
2 parents bdc63a7 + 90e97c9 commit 670081c
Show file tree
Hide file tree
Showing 43 changed files with 7,120 additions and 144 deletions.
1 change: 1 addition & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@babel/polyfill": "^7.10.1",
"@fortawesome/fontawesome-free": "^5.13.0",
"@fortawesome/fontawesome-svg-core": "^1.2.28",
"@fortawesome/free-brands-svg-icons": "^5.15.1",
"@fortawesome/free-regular-svg-icons": "^5.14.0",
"@fortawesome/free-solid-svg-icons": "^5.13.0",
"@fortawesome/vue-fontawesome": "^0.1.9",
Expand Down
59 changes: 59 additions & 0 deletions client/src/components/Citation/Citation.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<template>
<div>
{{ prefix }}
<span v-html="citationHtml" />
<a v-if="link" :href="link" target="_blank">
<font-awesome-icon v-b-tooltip.hover title="View Citation" icon="external-link-alt" />
</a>
</div>
</template>

<script>
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
import { library } from "@fortawesome/fontawesome-svg-core";
import { faExternalLinkAlt } from "@fortawesome/free-solid-svg-icons";
library.add(faExternalLinkAlt);
export default {
components: {
FontAwesomeIcon,
},
props: {
citation: {
type: Object,
},
outputFormat: {
type: String,
},
prefix: {
type: String,
},
},
computed: {
link() {
const cite = this.citation.cite;
return cite.data && cite.data[0] && cite.data[0].URL;
},
citationHtml() {
const citation = this.citation;
const cite = citation.cite;
const formattedCitation = cite.format(this.outputFormat, {
format: "html",
template: "apa",
lang: "en-US",
});
return formattedCitation;
},
},
};
</script>

<style>
.csl-bib-body {
display: inline;
}
.csl-entry {
display: inline;
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@
<a href="https://galaxyproject.org/citing-galaxy">cite Galaxy</a>.
</div>
<div class="citations-formatted">
<template v-for="citation in formattedCitations">
<div :key="citation" class="formatted-reference" v-html="citation"></div>
</template>
<Citation
class="formatted-reference"
:citation="citation"
:outputFormat="outputFormat"
v-for="(citation, index) in citations"
:key="index"
/>
</div>
</b-card>
<div v-else-if="formattedCitations.length">
<div v-else-if="citations.length">
<b-btn v-b-toggle="id" variant="primary">Citations</b-btn>
<b-collapse
:id="id.replace(/ /g, '_')"
Expand All @@ -37,9 +41,13 @@
@hidden="$emit('hidden')"
>
<b-card>
<template v-for="citation in formattedCitations">
<div :key="citation" class="formatted-reference" v-html="citation"></div>
</template>
<Citation
class="formatted-reference"
:citation="citation"
:outputFormat="outputFormat"
v-for="(citation, index) in citations"
:key="index"
/>
</b-card>
</b-collapse>
</div>
Expand All @@ -48,9 +56,8 @@
<script>
import Vue from "vue";
import BootstrapVue from "bootstrap-vue";
import axios from "axios";
import Cite from "citation-js";
import { getAppRoot } from "onload/loadConfig";
import { getCitations } from "./services";
import Citation from "./Citation";
Vue.use(BootstrapVue);
Expand All @@ -61,6 +68,9 @@ const outputFormats = Object.freeze({
});
export default {
components: {
Citation,
},
props: {
source: {
type: String,
Expand All @@ -85,44 +95,15 @@ export default {
outputFormat: outputFormats.CITATION,
};
},
computed: {
formattedCitations() {
const processed = [];
if (this.citations.length !== 0) {
for (const c of this.citations) {
let link = "";
if (c.cite.data && c.cite.data[0] && c.cite.data[0].URL) {
link = `&nbsp<a href="${c.cite.data[0].URL}" target="_blank">[Link]</a>`;
}
const formattedCitation = c.cite.format(this.outputFormat, {
format: "html",
template: "apa",
lang: "en-US",
append: link,
});
processed.push(formattedCitation);
}
}
return processed;
},
},
updated() {
this.$nextTick(() => {
this.$emit("rendered");
});
},
created() {
axios
.get(`${getAppRoot()}api/${this.source}/${this.id}/citations`)
.then((response) => {
response.data.forEach((rawCitation) => {
try {
const cite = new Cite(rawCitation.content);
this.citations.push({ raw: rawCitation.content, cite: cite });
} catch (err) {
console.warn(`Error parsing bibtex: ${err}`);
}
});
getCitations(this.source, this.id)
.then((citations) => {
this.citations = citations;
})
.catch((e) => {
console.error(e);
Expand Down
23 changes: 23 additions & 0 deletions client/src/components/Citation/services.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import axios from "axios";
import { rethrowSimple } from "utils/simple-error";
import { getAppRoot } from "onload/loadConfig";
import Cite from "citation-js";

export async function getCitations(source, id) {
try {
const request = await axios.get(`${getAppRoot()}api/${source}/${id}/citations`);
const rawCitations = request.data;
const citations = [];
for (const rawCitation of rawCitations) {
try {
const cite = new Cite(rawCitation.content);
citations.push({ raw: rawCitation.content, cite: cite });
} catch (err) {
console.warn(`Error parsing bibtex: ${err}`);
}
}
return citations;
} catch (e) {
rethrowSimple(e);
}
}
81 changes: 81 additions & 0 deletions client/src/components/License/License.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<template>
<loading-span v-if="license == null" message="Loading license information"> </loading-span>
<div class="text-muted" v-else-if="license.name">
<link itemprop="license" :href="license.licenseId" />
<span v-if="title">
{{ title }}
</span>
{{ license.name }}
<a target="_blank" :href="license.url">
<font-awesome-icon icon="external-link-alt" />
</a>
<slot name="buttons"></slot>
</div>
<div v-else>
Unknown License (<i>{{ license.url }}</i
>)
<slot name="buttons"></slot>
</div>
</template>

<script>
import { getAppRoot } from "onload/loadConfig";
import axios from "axios";
import LoadingSpan from "components/LoadingSpan";
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
import { library } from "@fortawesome/fontawesome-svg-core";
import { faExternalLinkAlt } from "@fortawesome/free-solid-svg-icons";
library.add(faExternalLinkAlt);
export default {
components: {
LoadingSpan,
FontAwesomeIcon,
},
props: {
licenseId: {
type: String,
},
inputLicenseInfo: {
type: Object,
required: false,
},
title: {
type: String,
default: null,
},
},
data() {
return {
license: this.inputLicenseInfo,
};
},
created() {
if (this.license == null) {
this.fetchLicense();
}
},
methods: {
fetchLicense() {
this.license = null;
const url = `${getAppRoot()}api/licenses/${this.licenseId}`;
axios
.get(url)
.then((response) => response.data)
.then((data) => {
this.license = data;
});
},
},
watch: {
licenseId: function (newLicense, oldLicense) {
if (newLicense != oldLicense) {
this.fetchLicense();
}
},
},
};
</script>

<style></style>
Loading

0 comments on commit 670081c

Please sign in to comment.