summaryrefslogtreecommitdiff
path: root/client/js/models/post.js
diff options
context:
space:
mode:
Diffstat (limited to 'client/js/models/post.js')
-rw-r--r--client/js/models/post.js34
1 files changed, 34 insertions, 0 deletions
diff --git a/client/js/models/post.js b/client/js/models/post.js
index 01f81bf..3df3b2c 100644
--- a/client/js/models/post.js
+++ b/client/js/models/post.js
@@ -9,6 +9,8 @@ const NoteList = require("./note_list.js");
const CommentList = require("./comment_list.js");
const PoolList = require("./pool_list.js");
const Pool = require("./pool.js");
+const PostMetricList = require("./post_metric_list.js");
+const PostMetricRangeList = require("./post_metric_range_list.js");
const misc = require("../util/misc.js");
class Post extends events.EventTarget {
@@ -21,6 +23,8 @@ class Post extends events.EventTarget {
obj._notes = new NoteList();
obj._comments = new CommentList();
obj._pools = new PoolList();
+ obj._metrics = new PostMetricList();
+ obj._metricRanges = new PostMetricRangeList();
}
this._updateFromResponse({});
@@ -126,6 +130,14 @@ class Post extends events.EventTarget {
return this._pools;
}
+ get metrics() {
+ return this._metrics;
+ }
+
+ get metricRanges() {
+ return this._metricRanges;
+ }
+
get score() {
return this._score;
}
@@ -268,6 +280,19 @@ class Post extends events.EventTarget {
text: note.text,
}));
}
+ if (misc.arraysDiffer(this._metrics, this._orig._metrics)) {
+ detail.metrics = this._metrics.map(metric => ({
+ tag_name: metric.tagName,
+ value: metric.value,
+ }));
+ }
+ if (misc.arraysDiffer(this._metricRanges, this._orig._metricRanges)) {
+ detail.metricRanges = this._metricRanges.map(metricRange => ({
+ tag_name: metricRange.tagName,
+ low: metricRange.low,
+ high: metricRange.high,
+ }));
+ }
if (this._newContent) {
files.content = this._newContent;
}
@@ -454,6 +479,13 @@ class Post extends events.EventTarget {
});
}
+ removeMetricsWithoutTag() {
+ this._metrics.filter(pm => !this._tags.findByName(pm.tagName))
+ .map(pm => this._metrics.remove(pm));
+ this._metricRanges.filter(pmr => !this._tags.findByName(pmr.tagName))
+ .map(pmr => this._metricRanges.remove(pmr));
+ }
+
mutateContentUrl() {
this._contentUrl =
this._orig._contentUrl +
@@ -499,6 +531,8 @@ class Post extends events.EventTarget {
obj._notes.sync(response.notes);
obj._comments.sync(response.comments);
obj._pools.sync(response.pools);
+ obj._metrics.sync(response.metrics);
+ obj._metricRanges.sync(response.metricRanges);
}
Object.assign(this, map());