Last active
December 13, 2016 22:04
-
-
Save mokolodi1/5319409b5dbe4ab38a5475936bfaa3bc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SampleGroups = new Meteor.Collection("sample_groups"); | |
var filterOptionsSchemas = { | |
include_sample_list: new SimpleSchema({ | |
sample_labels: { type: [String] }, | |
sample_count: { type: Number }, | |
}), | |
exclude_sample_list: new SimpleSchema({ | |
sample_labels: { type: [String] }, | |
sample_count: { type: Number }, | |
}), | |
form_values: new SimpleSchema({ | |
form_id: { type: String }, | |
// Use JSON.parse & JSON.stringify to translate | |
mongo_query: { type: String}, | |
// TODO: perhaps? | |
// matching_sample_count: { type: Number }, | |
}), | |
}; | |
SimpleSchema.messages({ | |
filterOptionsInvalid: "Options provided in a filter are invalid", | |
}); | |
SampleGroups.attachSchema(new SimpleSchema({ | |
name: { type: String }, | |
version: { type: Number, min: 1 }, | |
// only optinal because SimpleSchema causes problems when validating a | |
// single object using a context | |
date_created: { | |
type: Date, | |
autoValue: dateCreatedAutoValue, | |
optional: true | |
}, | |
// administrators: { type: [String] }, | |
collaborations: { type: [String] }, | |
value_type: DataSets.simpleSchema().schema().value_type, | |
sample_labels: { type: [String] }, | |
feature_labels: { type: [String] }, | |
// where the sample data is from | |
data_sets: { | |
type: [ | |
new SimpleSchema({ | |
data_set_id: { type: String }, | |
data_set_name: { type: String }, | |
sample_labels: { type: [String] }, | |
sample_count: { | |
type: Number, | |
min: 0, | |
autoValue: function () { | |
return this.siblingField("sample_labels").value.length; | |
}, | |
}, | |
}) | |
], | |
min: 1 | |
}, | |
// the various data sets/sample groups that were filtered to get this | |
// sample group | |
sample_source: { | |
type: [ | |
new SimpleSchema({ | |
collection_name: { | |
type: String, | |
allowedValues: [ | |
"DataSets", | |
"SampleGroups", | |
], | |
}, | |
mongo_id: { type: String }, | |
name: { type: String }, | |
version: { | |
type: Number, | |
min: 0, | |
custom: function () { | |
// only required if it's from a sample group | |
if (this.siblingField("collection_name").value === "SampleGroups") { | |
if (!this.value) { | |
return "required"; | |
} | |
} else { | |
if (this.value) { | |
return "notAllowed"; | |
} | |
} | |
}, | |
}, | |
sample_labels: { type: [String] }, | |
sample_count: { | |
type: Number, | |
min: 0, | |
autoValue: function () { | |
return this.siblingField("sample_labels").value.length; | |
}, | |
}, | |
unfiltered_sample_count: { | |
type: Number, | |
autoValue: function () { | |
var collection_name = this.siblingField("collection_name").value; | |
var mongo_id = this.siblingField("mongo_id").value; | |
var collection = MedBook.collections[collection_name]; | |
return collection.findOne(mongo_id).sample_labels.length; | |
}, | |
}, | |
filters: { | |
type: [ new SimpleSchema({ | |
type: { | |
type: String, | |
allowedValues: Object.keys(filterOptionsSchemas), | |
}, | |
options: { | |
type: Object, | |
blackbox: true, | |
custom: function () { | |
var type = this.siblingField("type").value; | |
var isValid = filterOptionsSchemas[type] | |
.newContext() | |
.validate(this.value); | |
if (!isValid) { | |
return "filterOptionsInvalid"; | |
} | |
}, | |
}, | |
// TODO: should we do something like this? | |
// // the number of samples after this filter was applied | |
// // (so that users can see that a certain filter filtered from | |
// // 143 samples to 59 samples) | |
// sample_count_after_filter: { type: Number }, | |
}) ], | |
defaultValue: [], | |
}, | |
}) | |
], | |
min: 1 | |
}, | |
})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment