-
Notifications
You must be signed in to change notification settings - Fork 970
/
citation-model.js
80 lines (69 loc) · 2.31 KB
/
citation-model.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import * as bibtexParse from "libs/bibtexParse";
import baseMVC from "mvc/base-mvc";
/* global Backbone */
var logNamespace = "citation";
//==============================================================================
/** @class model for tool citations.
* @name Citation
* @augments Backbone.Model
*/
var Citation = Backbone.Model.extend(baseMVC.LoggableMixin).extend({
_logNamespace: logNamespace,
defaults: {
content: ""
},
initialize: function() {
var parsed;
try {
// TODO: to model.parse/.validate
parsed = bibtexParse.toJSON(this.attributes.content);
} catch (err) {
this.log("Error parsing bibtex: " + err);
}
this._fields = {};
this.entry = _.first(parsed);
if (this.entry) {
var rawFields = this.entry.entryTags;
for (var key in rawFields) {
var value = rawFields[key];
var lowerKey = key.toLowerCase();
this._fields[lowerKey] = value;
}
}
},
entryType: function() {
return this.entry ? this.entry.entryType : undefined;
},
fields: function() {
return this._fields;
}
});
//==============================================================================
/** @class Backbone collection of citations.
*/
var BaseCitationCollection = Backbone.Collection.extend(baseMVC.LoggableMixin).extend({
_logNamespace: logNamespace,
/** root api url */
urlRoot: `${Galaxy.root}api`,
partial: true, // Assume some tools in history/workflow may not be properly annotated yet.
model: Citation
});
var HistoryCitationCollection = BaseCitationCollection.extend({
/** complete api url */
url: function() {
return `${this.urlRoot}/histories/${this.history_id}/citations`;
}
});
var ToolCitationCollection = BaseCitationCollection.extend({
/** complete api url */
url: function() {
return `${this.urlRoot}/tools/${this.tool_id}/citations`;
},
partial: false // If a tool has citations, assume they are complete.
});
//==============================================================================
export default {
Citation: Citation,
HistoryCitationCollection: HistoryCitationCollection,
ToolCitationCollection: ToolCitationCollection
};