UNPKG

2.02 kBJavaScriptView Raw
1var ChangesetComment = require('./ChangesetComment');
2
3var Changeset = function(data, comments) {
4 this.id = data.id;
5 this.createdAt = data.created_at;
6 this.closedAt = data.closed_at || null;
7 this.discussionCount = data.discussion_count;
8 this.isOpen = data.is_open;
9 this.userID = data.user_id;
10 this.userName = data.user_name;
11 this.numChanges = data.num_changes;
12 this.bbox = JSON.parse(data.bbox);
13 if (data.last_comment_comment) {
14 this.lastCommentComment = data.last_comment_comment || null;
15 this.lastCommentTimestamp = data.last_comment_timestamp || null;
16 this.lastCommentUserName = data.last_comment_user_name || null;
17 this.lastCommentUserID = data.last_comment_user_id || null;
18 }
19 this.changesetComment = data.changeset_comment || '';
20 if (comments) {
21 this.comments = comments.map(function(comment) {
22 return new ChangesetComment(comment);
23 });
24 } else {
25 this.comments = null;
26 }
27 return this;
28};
29
30Changeset.prototype.getGeoJSON = function() {
31 return {
32 'type': 'Feature',
33 'geometry': this.bbox,
34 'properties': this.getProperties()
35 };
36};
37
38Changeset.prototype.getProperties = function() {
39 var props = {
40 'id': this.id,
41 'createdAt': this.createdAt,
42 'closedAt': this.closedAt,
43 'discussionCount': this.discussionCount,
44 'isOpen': this.isOpen,
45 'userID': this.userID,
46 'userName': this.userName,
47 'numChanges': this.numChanges,
48 'changesetComment': this.changesetComment,
49 'lastCommentComment': this.lastCommentComment,
50 'lastCommentTimestamp': this.lastCommentTimestamp,
51 'lastCommentUserName': this.lastCommentUserName,
52 'lastCommentUserID': this.lastCommentUserID
53 };
54 if (this.comments) {
55 props.comments = this.comments.map(function(comment) {
56 return comment.getJSON();
57 });
58 }
59 return props;
60};
61
62module.exports = Changeset;
\No newline at end of file