forked from twitter/opensource-website
-
Notifications
You must be signed in to change notification settings - Fork 5
/
commentsHandler.js
1 lines (1 loc) · 2.14 KB
/
commentsHandler.js
1
Date.prototype.toIsrealFormat=function(){return this.getDay()+"/"+this.getMonth()+"/"+this.getFullYear()},angular.module("commentsHandler",["HebUtill"]).factory("commentsHandler",function(HebUtill){"use strict";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()}},this.timeSince=function(dateText){var date=new Date(dateText),seconds=Math.floor((new Date-date)/1e3),interval=Math.floor(seconds/31536e3);return interval>1?interval+"years":(interval=Math.floor(seconds/2592e3),interval>1?interval+" months":(interval=Math.floor(seconds/86400),interval>=1?interval+" days":(interval=Math.floor(seconds/3600),interval>=1?interval+" hours":(interval=Math.floor(seconds/60),interval>1?interval+" minutes":Math.floor(seconds)+" seconds"))))};var getRapoName=function(issue){var url=issue.html_url.split("/"),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:return window.console.error(""+name),name}},getInnerLinkFromIssue=function(issue){for(var url=issue.html_url.split("/"),name=url[url.length-3].toLowerCase(),i=0;i<eKnightsData.length;i++)if(-1!==eKnightsData[i].github_repo.toLowerCase().search(name))return eKnightsData[i].slug;return!1};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});