forked from galaxyproject/galaxy
/
hdca-model.js
118 lines (99 loc) · 4.47 KB
/
hdca-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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import DC_MODEL from "mvc/collection/collection-model";
import HISTORY_CONTENT from "mvc/history/history-content-model";
import _l from "utils/localization";
/*==============================================================================
Models for DatasetCollections contained within a history.
TODO:
these might be compactable to one class if some duplication with
collection-model is used.
==============================================================================*/
var hcontentMixin = HISTORY_CONTENT.HistoryContentMixin;
var FlatDC = DC_MODEL.FlatDatasetCollection;
var NestedDC = DC_MODEL.NestedDatasetCollection;
//==============================================================================
/** Override to post to contents route w/o id. */
function buildHDCASave(_super) {
return function _save(attributes, options) {
if (this.isNew()) {
options = options || {};
options.url = `${this.urlRoot + this.get("history_id")}/contents`;
attributes = attributes || {};
attributes.type = "dataset_collection";
}
return _super.call(this, attributes, options);
};
}
//==============================================================================
/** @class Backbone model for List Dataset Collection within a History.
*/
var HistoryListDatasetCollection = FlatDC.extend(hcontentMixin).extend(
/** @lends HistoryListDatasetCollection.prototype */ {
defaults: _.extend(_.clone(FlatDC.prototype.defaults), {
history_content_type: "dataset_collection",
collection_type: "list",
model_class: "HistoryDatasetCollectionAssociation"
}),
/** Override to post to contents route w/o id. */
save: buildHDCASave(FlatDC.prototype.save),
/** String representation. */
toString: function() {
return `History${FlatDC.prototype.toString.call(this)}`;
}
}
);
//==============================================================================
/** @class Backbone model for Pair Dataset Collection within a History.
* @constructs
*/
var HistoryPairDatasetCollection = FlatDC.extend(hcontentMixin).extend(
/** @lends HistoryPairDatasetCollection.prototype */ {
defaults: _.extend(_.clone(FlatDC.prototype.defaults), {
history_content_type: "dataset_collection",
collection_type: "paired",
model_class: "HistoryDatasetCollectionAssociation"
}),
/** Override to post to contents route w/o id. */
save: buildHDCASave(FlatDC.prototype.save),
/** String representation. */
toString: function() {
return `History${FlatDC.prototype.toString.call(this)}`;
}
}
);
//==============================================================================
/** @class Backbone model for List of Pairs Dataset Collection within a History. */
var HistoryListPairedDatasetCollection = NestedDC.extend(hcontentMixin).extend({
defaults: _.extend(_.clone(NestedDC.prototype.defaults), {
history_content_type: "dataset_collection",
collection_type: "list:paired",
model_class: "HistoryDatasetCollectionAssociation"
}),
/** Override to post to contents route w/o id. */
save: buildHDCASave(NestedDC.prototype.save),
/** String representation. */
toString: function() {
return `History${NestedDC.prototype.toString.call(this)}`;
}
});
//==============================================================================
/** @class Backbone model for List of Lists Dataset Collection within a History. */
var HistoryListOfListsDatasetCollection = NestedDC.extend(hcontentMixin).extend({
defaults: _.extend(_.clone(NestedDC.prototype.defaults), {
history_content_type: "dataset_collection",
collection_type: "list:list",
model_class: "HistoryDatasetCollectionAssociation"
}),
/** Override to post to contents route w/o id. */
save: buildHDCASave(NestedDC.prototype.save),
/** String representation. */
toString: function() {
return `HistoryListOfListsDatasetCollection(${this.get("name")})`;
}
});
//==============================================================================
export default {
HistoryListDatasetCollection: HistoryListDatasetCollection,
HistoryPairDatasetCollection: HistoryPairDatasetCollection,
HistoryListPairedDatasetCollection: HistoryListPairedDatasetCollection,
HistoryListOfListsDatasetCollection: HistoryListOfListsDatasetCollection
};