forked from twitter/opensource-website
-
Notifications
You must be signed in to change notification settings - Fork 5
/
commentsHandler.js
executable file
·122 lines (106 loc) · 4.1 KB
/
commentsHandler.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
119
120
121
122
Date.prototype.toIsrealFormat = function() {
return this.getDay() + '/' + this.getMonth() + '/' + this.getFullYear();
};
angular.module('commentsHandler', ['HebUtill'
]).factory('commentsHandler', function(HebUtill) {
"use strict";
/**
* @constructor
* @requires HebUtill
*/
var commentsHandler = function() {
this.treatComments = function(list) {
HebUtill.addLanguageAttribute(list);
for (var i = 0; i < list.length; i++) {
var comm = list[i];
comm.timeSince = this.timeSince(comm.created_at);
var d = new Date(comm.created_at);
comm.israelFormatCreated_at = d.toIsrealFormat();
}
};
/**
* @description Format a JavaScript Date as a string stating the time elapsed.
* @param {string} dateText Unix time format.
* @returns {string}
*/
this.timeSince = function(dateText) {
var date = new Date(dateText);
var seconds = Math.floor((new Date() - date) / 1000);
var interval = Math.floor(seconds / 31536000);
if (interval > 1)
return interval + "years";
interval = Math.floor(seconds / 2592000);
if (interval > 1)
return interval + " months";
interval = Math.floor(seconds / 86400);
if (interval >= 1)
return interval + " days";
interval = Math.floor(seconds / 3600);
if (interval >= 1)
return interval + " hours";
interval = Math.floor(seconds / 60);
if (interval > 1)
return interval + " minutes";
return Math.floor(seconds) + " seconds";
};
var getRapoName = function(issue) {
var url = issue.html_url.split('/');
var name = url[url.length - 3];
switch (name.toLowerCase()) {
case "anyway":
return 'anyway';
case "open-knesset":
return "כנסת פתוחה";
case "hasadna.github.io":
return "ארץ החשמבירים";
case "opencommunity":
return "קהילה פתוחה";
case "openpension":
return "פנסיה פתוחה";
case "alaveteli":
return "תביא ת'דאטה";
case "openmuni-budgets":
case "open-budget":
return "התקציב המקומי הפתוח";
case "NeuroNet":
return "הגשמה ציבורית";
case "obudget":
return "התקציב הפתוח";
case "openlaw-bot":
return "ספר החוקים";
case "opentaba-server":
return "תבע פתוחה";
case "openpress":
case "okscraper":
case "okscraper-django":
return name;
default :
window.console.error('' + name);
return name;
}
};
var getInnerLinkFromIssue = function(issue) {
var url = issue.html_url.split('/');
var name = url[url.length - 3].toLowerCase();
for (var i = 0; i < eKnightsData.length; i++) {
if (eKnightsData[i].github_repo.toLowerCase().search(name) !== -1) {
return eKnightsData[i].slug;
}
}
return false;
};
/**
* @description Add repoName and eKnightSlug to each issue
* @param {Array<Object>} list of issues
* @returns {undefined}
*/
this.addRapoAttribute = function(list) {
for (var i = 0; i < list.length; i++) {
var issue = list[i];
issue.repoName = getRapoName(issue);
issue.eKnightSlug = getInnerLinkFromIssue(issue);
}
};
};
return new commentsHandler();
});