Skip to content

Commit

Permalink
WIP Citations/Vue
Browse files Browse the repository at this point in the history
  • Loading branch information
dannon committed Nov 14, 2017
1 parent c03d011 commit fc58c45
Show file tree
Hide file tree
Showing 13 changed files with 241 additions and 42 deletions.
11 changes: 6 additions & 5 deletions client/galaxy/scripts/apps/analysis.js
Expand Up @@ -20,7 +20,8 @@ import Utils from "utils/utils";
import Ui from "mvc/ui/ui-misc";
import DatasetError from "mvc/dataset/dataset-error";
import DatasetEditAttributes from "mvc/dataset/dataset-edit-attributes";
import Citations from "mvc/citations";
import Citations from "components/citations.vue";
import Vue from "libs/vue";

/** define the 'Analyze Data'/analysis/main/home page for Galaxy
* * has a masthead
Expand Down Expand Up @@ -122,10 +123,10 @@ window.app = function app(options, bootstrapped) {
},

show_history_citations: function() {
var citations = new Citations.HistoryCitationCollection();
citations.history_id = QueryStringParsing.get("id");
this.page.display(new Citations.CitationListView({ collection: citations }));
citations.fetch();
var citationInstance = Vue.extend(Citations);
var vm = document.createElement('div');
this.page.display(vm);
new citationInstance({propsData: {id: QueryStringParsing.get("id"), source: 'histories'}}).$mount(vm);
},

show_histories_rename: function() {
Expand Down
197 changes: 197 additions & 0 deletions client/galaxy/scripts/components/citations.vue
@@ -0,0 +1,197 @@
<template>
<div class="toolForm">
<div class="toolFormTitle">
Citations
<button v-if="viewRender" v-on:click="toggleViewRender" type="button" class="btn btn-xs citations-to-bibtex" title="Show all in BibTeX format.">
<i class="fa fa-pencil-square-o"></i>
Show BibTeX
</button>
<button v-else type="button" v-on:click="toggleViewRender" class="btn btn-xs citations-to-formatted" title="Return to formatted citation list.">
<i class="fa fa-times"></i>
Hide BibTeX
</button>
</div>
<div class="toolFormBody" style="padding:5px 10px">
<div v-if="source == 'history'" style="padding:5px 10px">
<b>Warning: This is a experimental feature.</b> Most Galaxy
tools will not annotate citations explicitly at this time. When
writing up your analysis, please manually review your histories
and find all references that should be cited in order to
completely describe your work. Also, please remember to <a
href="https://galaxyproject.org/citing-galaxy">cite Galaxy</a>.
</div>
</div>
<div class="citations-bibtex toolFormBody" style="padding:5px 10px">
<span v-if="viewRender" class="citations-formatted" style="word-wrap: break-word;">
<p v-html="formattedReferences">
</p>
</span>
<textarea v-else style="width: 100%; height: 500px;" class="citations-bibtex-text">
{{ content }}
</textarea>
</div>
</div>
</template>
<script>
import axios from "axios";
import * as bibtexParse from "libs/bibtexParse";
import { convertLaTeX } from "latex-to-unicode-converter";
import { stringifyLaTeX } from "latex-parser";
export default {
props: {
source: {
type: String,
required: true
},
id: {
type: String,
required: true
},
viewRender: {
type: Boolean,
requried: false,
default: true
}
},
data() {
return {
citations: [],
content: "",
errors: []
};
},
computed: {
formattedReferences: function() {
return this.citations.reduce((a, b) => a.concat(`<p>${this.formattedReference(b)}</p>`), "");
}
},
created: function() {
axios
.get(`${Galaxy.root}api/${this.source}/${this.id}/citations`)
.then(response => {
this.content = "";
for (var rawCitation of response.data) {
try {
var citation = {
fields: {},
entryType: undefined
};
var parsed = bibtexParse.toJSON(rawCitation.content);
if (parsed) {
parsed = _.first(parsed);
citation.entryType = parsed.entryType || undefined;
for (var key in parsed.entryTags) {
citation.fields[key.toLowerCase()] = parsed.entryTags[key];
}
}
this.citations.push(citation);
this.content += rawCitation.content;
} catch (err) {
console.warn("Error parsing bibtex: " + err);
}
}
})
.catch(e => {
console.error(e);
});
},
methods: {
formattedReference: function(citation) {
var entryType = citation.entryType;
var fields = citation.fields;
var ref = "";
var authorsAndYear = `${this._asSentence(
(fields.author ? fields.author : "") + (fields.year ? ` (${fields.year})` : "")
)} `;
var title = fields.title || "";
var pages = fields.pages ? `pp. ${fields.pages}` : "";
var address = fields.address;
if (entryType == "article") {
var volume =
(fields.volume ? fields.volume : "") +
(fields.number ? ` (${fields.number})` : "") +
(pages ? `, ${pages}` : "");
ref = `${authorsAndYear +
this._asSentence(title) +
(fields.journal ? `In <em>${fields.journal}, ` : "") +
this._asSentence(volume) +
this._asSentence(fields.address)}</em>`;
} else if (entryType == "inproceedings" || entryType == "proceedings") {
ref = `${authorsAndYear +
this._asSentence(title) +
(fields.booktitle ? `In <em>${fields.booktitle}, ` : "") +
(pages ? pages : "") +
(address ? `, ${address}` : "")}.</em>`;
} else if (entryType == "mastersthesis" || entryType == "phdthesis") {
ref =
authorsAndYear +
this._asSentence(title) +
(fields.howpublished ? `${fields.howpublished}. ` : "") +
(fields.note ? `${fields.note}.` : "");
} else if (entryType == "techreport") {
ref =
authorsAndYear +
this._asSentence(title) +
this._asSentence(fields.institution) +
this._asSentence(fields.number) +
this._asSentence(fields.type);
} else if (entryType == "book" || entryType == "inbook" || entryType == "incollection") {
ref = `${authorsAndYear} ${this._formatBookInfo(fields)}`;
} else {
ref = `${authorsAndYear} ${this._asSentence(title)}${this._asSentence(
fields.howpublished
)}${this._asSentence(fields.note)}`;
}
var doiUrl = "";
if (fields.doi) {
doiUrl = `http://dx.doi.org/${fields.doi}`;
ref += `[<a href="${doiUrl}" target="_blank">doi:${fields.doi}</a>]`;
}
var url = fields.url || doiUrl;
if (url) {
ref += `[<a href="${url}" target="_blank">Link</a>]`;
}
return convertLaTeX({ onError: (error, latex) => `{${stringifyLaTeX(latex)}}` }, ref);
},
_formatBookInfo: function(fields) {
var info = "";
if (fields.chapter) {
info += `${fields.chapter} in `;
}
if (fields.title) {
info += `<em>${fields.title}</em>`;
}
if (fields.editor) {
info += `, Edited by ${fields.editor}, `;
}
if (fields.publisher) {
info += `, ${fields.publisher}`;
}
if (fields.pages) {
info += `, pp. ${fields.pages}`;
}
if (fields.series) {
info += `, <em>${fields.series}</em>`;
}
if (fields.volume) {
info += `, Vol.${fields.volume}`;
}
if (fields.issn) {
info += `, ISBN: ${fields.issn}`;
}
return `${info}.`;
},
_asSentence: function(str) {
return str && str.trim() ? `${str}. ` : "";
},
toggleViewRender: function() {
this.viewRender = !this.viewRender;
console.debug(this.viewRender);
}
}
};
</script>
<style>
</style>
19 changes: 10 additions & 9 deletions client/galaxy/scripts/mvc/tool/tool-form-base.js
Expand Up @@ -5,7 +5,8 @@ import Utils from "utils/utils";
import Deferred from "utils/deferred";
import Ui from "mvc/ui/ui-misc";
import FormBase from "mvc/form/form-view";
import Citations from "mvc/citations";
import Citations from "components/citations.vue";
import Vue from "libs/vue";
export default FormBase.extend({
initialize: function(options) {
var self = this;
Expand Down Expand Up @@ -223,14 +224,14 @@ export default FormBase.extend({
var options = this.model.attributes;
var $el = $("<div/>").append(this._templateHelp(options));
if (options.citations) {
var citations = new Citations.ToolCitationCollection();
citations.tool_id = options.id;
var citation_list_view = new Citations.CitationListView({
collection: citations
});
citation_list_view.render();
citations.fetch();
$el.append(citation_list_view.$el);
var citationInstance = Vue.extend(Citations);
var vm = document.createElement('div');
$el.append(vm);
new citationInstance({
propsData: {
id: options.id,
source: 'tools'}})
.$mount(vm);
}
return $el;
},
Expand Down

0 comments on commit fc58c45

Please sign in to comment.