helpers.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. Template.admin.helpers({
  2. queueCount: function(display) {
  3. var d = display.toLowerCase();
  4. return queues && "songs" in queues ? queues.songs.length : 0;
  5. var queues = Queues.findOne({type: d});
  6. },
  7. queues: function() {
  8. var queues = Queues.find({}).fetch();
  9. return queues;
  10. },
  11. usersOnline: function(){
  12. Meteor.call("getUserNum", function(err, num){
  13. if(err){
  14. console.log(err);
  15. }
  16. Session.set("userNum", num);
  17. });
  18. return Session.get("userNum");
  19. },
  20. roomUserNum: function(){
  21. var type = this.type;
  22. var userNum = Rooms.findOne({type: type}).users;
  23. return userNum;
  24. },
  25. allUsers: function(){
  26. Meteor.call("getTotalUsers", function(err, num){
  27. Session.set("allUsers", num);
  28. })
  29. return Session.get("allUsers");
  30. },
  31. playlists: function() {
  32. var playlists = Playlists.find({}).fetch();
  33. playlists.map(function(playlist) {
  34. if (Rooms.find({type: playlist.type}).count() !== 1) {
  35. return;
  36. } else {
  37. playlist.display = Rooms.findOne({type: playlist.type}).display;
  38. return playlist;
  39. }
  40. });
  41. return playlists;
  42. },
  43. reportsCount: function(room) {
  44. room = room.toLowerCase();
  45. var reports = Reports.findOne({room:room});
  46. return reports && "report" in reports ? reports.report.length : 0;
  47. }
  48. });
  49. Template.alerts.helpers({
  50. alerts: function() {
  51. return Alerts.find({active: true});
  52. }
  53. });
  54. Template.alertsDashboard.helpers({
  55. "activeAlerts": function() {
  56. return Alerts.find({active: true});
  57. },
  58. "inactiveAlerts": function() {
  59. return Alerts.find({active: false});
  60. }
  61. });
  62. Template.banned.helpers({
  63. bannedAt: function() {
  64. if (Session.get("ban") !== undefined) {
  65. return Session.get("ban").bannedAt;
  66. }
  67. },
  68. bannedBy: function() {
  69. if (Session.get("ban") !== undefined) {
  70. return Session.get("ban").bannedBy;
  71. }
  72. },
  73. bannedUntil: function() {
  74. if (Session.get("ban") !== undefined) {
  75. return Session.get("ban").bannedUntil;
  76. }
  77. },
  78. bannedReason: function() {
  79. if (Session.get("ban") !== undefined) {
  80. return Session.get("ban").bannedReason;
  81. }
  82. }
  83. });
  84. Template.feedback.helpers({
  85. feedback: function(){
  86. var data = Feedback.findOne();
  87. if(data !== undefined) {
  88. return data.messages.reverse();
  89. } else{
  90. return [];
  91. }
  92. }
  93. })
  94. Template.header.helpers({
  95. userId: function() {
  96. return Meteor.userId();
  97. }
  98. });
  99. Template.home.helpers({
  100. currentSong: function(){
  101. var type = this.type;
  102. var room = Rooms.findOne({type: type});
  103. if(room !== undefined){
  104. return room.currentSong;
  105. } else {
  106. return false;
  107. }
  108. },
  109. userNum: function(){
  110. var type = this.type;
  111. var userNum = Rooms.findOne({type: type}).users;
  112. return userNum;
  113. }
  114. });
  115. Template.playlist.helpers({
  116. playlist_songs: function() {
  117. parts = location.href.split('/');
  118. id = parts.pop();
  119. type = id.toLowerCase();
  120. var data = Playlists.findOne({type: type});
  121. if (data !== undefined) {
  122. data.songs.map(function(song) {
  123. if (Session.get("currentSong") !== undefined && song.mid === Session.get("currentSong").mid) {
  124. song.current = true;
  125. } else {
  126. song.current = false;
  127. }
  128. return song;
  129. });
  130. return data.songs;
  131. } else {
  132. return [];
  133. }
  134. }
  135. });
  136. Template.profile.helpers({
  137. "real_name": function(){
  138. return Session.get("real_name");
  139. },
  140. "username": function() {
  141. return Session.get("username")
  142. },
  143. "first_joined": function() {
  144. return moment(Session.get("first_joined")).format("DD/MM/YYYY HH:mm:ss");
  145. },
  146. "rank": function() {
  147. return Session.get("rank");
  148. },
  149. loaded: function() {
  150. return Session.get("loaded");
  151. },
  152. likedSongs: function(){
  153. var likedArr = [];
  154. Session.get("liked").forEach(function(mid){
  155. Rooms.find().forEach(function(room){
  156. Playlists.find({type: room.type}).forEach(function(pl){
  157. for(var i in pl.songs){
  158. if(pl.songs[i].mid === mid){
  159. likedArr.push({title: pl.songs[i].title, artist: pl.songs[i].artist, room: room.display});
  160. }
  161. }
  162. });
  163. })
  164. });
  165. return likedArr;
  166. },
  167. dislikedSongs: function(){
  168. var dislikedArr = [];
  169. Session.get("disliked").forEach(function(mid){
  170. Rooms.find().forEach(function(room){
  171. Playlists.find({type: room.type}).forEach(function(pl){
  172. for(var i in pl.songs){
  173. if(pl.songs[i].mid === mid){
  174. dislikedArr.push({title: pl.songs[i].title, artist: pl.songs[i].artist, room: room.display});
  175. }
  176. }
  177. });
  178. })
  179. });
  180. return dislikedArr;
  181. },
  182. isUser: function(){
  183. var parts = Router.current().url.split('/');
  184. var username = parts.pop();
  185. if(username === Meteor.user().profile.username){
  186. return true;
  187. }
  188. }
  189. });
  190. Template.queues.helpers({
  191. queues: function() {
  192. var queues = Queues.find({}).fetch();
  193. queues.map(function(queue) {
  194. if (Rooms.find({type: queue.type}).count() !== 1) {
  195. return;
  196. } else {
  197. queue.display = Rooms.findOne({type: queue.type}).display;
  198. return queue;
  199. }
  200. });
  201. return queues;
  202. }
  203. });
  204. Template.room.helpers({
  205. singleVideo: function() {
  206. return true;
  207. },
  208. chat: function() {
  209. Meteor.setTimeout(function() {
  210. var elem = document.getElementById('chat');
  211. if (elem !== undefined && elem !== null) {
  212. elem.scrollTop = elem.scrollHeight;
  213. }
  214. }, 100);
  215. return Chat.find({type: Session.get("type")}, {sort: {time: -1}, limit: 50 }).fetch().reverse();
  216. },
  217. globalChat: function() {
  218. Meteor.setTimeout(function() {
  219. var elem = document.getElementById('global-chat');
  220. if (elem !== undefined && elem !== null) {
  221. elem.scrollTop = elem.scrollHeight;
  222. }
  223. }, 100);
  224. return Chat.find({type: "global"}, {sort: {time: -1}, limit: 50 }).fetch().reverse();
  225. },
  226. likes: function() {
  227. var playlist = Playlists.findOne({type: Session.get("type")});
  228. var likes = 0;
  229. playlist.songs.forEach(function(song) {
  230. if (Session.get("currentSong") && song.mid === Session.get("currentSong").mid) {
  231. likes = song.likes;
  232. return;
  233. }
  234. });
  235. return likes;
  236. },
  237. dislikes: function() {
  238. var playlist = Playlists.findOne({type: Session.get("type")});
  239. var dislikes = 0;
  240. playlist.songs.forEach(function(song) {
  241. if (Session.get("currentSong") && song.mid === Session.get("currentSong").mid) {
  242. dislikes = song.dislikes;
  243. return;
  244. }
  245. });
  246. return dislikes;
  247. },
  248. liked: function() {
  249. if (Meteor.userId()) {
  250. var currentSong = Session.get("currentSong");
  251. if (currentSong && Meteor.user().profile.liked.indexOf(currentSong.mid) !== -1) {
  252. return "active";
  253. } else {
  254. return "";
  255. }
  256. } else {
  257. "";
  258. }
  259. },
  260. disliked: function() {
  261. if (Meteor.userId()) {
  262. var currentSong = Session.get("currentSong");
  263. if (currentSong && Meteor.user().profile.disliked.indexOf(currentSong.mid) !== -1) {
  264. return "active";
  265. } else {
  266. return "";
  267. }
  268. } else {
  269. "";
  270. }
  271. },
  272. type: function() {
  273. var parts = location.href.split('/');
  274. var id = parts.pop().toLowerCase();
  275. return Rooms.findOne({type: id}).display;
  276. },
  277. users: function() {
  278. var parts = location.href.split('/');
  279. var id = parts.pop().toLowerCase();
  280. return Rooms.findOne({type: id}).users;
  281. },
  282. title: function(){
  283. return Session.get("title");
  284. },
  285. artist: function(){
  286. return Session.get("artist");
  287. },
  288. loaded: function() {
  289. return Session.get("loaded");
  290. },
  291. paused: function() {
  292. return Session.get("state") === "paused";
  293. },
  294. private: function() {
  295. return Rooms.findOne({type: Session.get("type")}).private === true;
  296. },
  297. report: function() {
  298. return Session.get("reportObj");
  299. },
  300. reportSong: function() {
  301. return Session.get("reportSong");
  302. },
  303. reportTitle: function() {
  304. return Session.get("reportTitle");
  305. },
  306. reportAuthor: function() {
  307. return Session.get("reportAuthor");
  308. },
  309. reportDuration: function() {
  310. return Session.get("reportDuration");
  311. },
  312. reportAudio: function() {
  313. return Session.get("reportAudio");
  314. },
  315. reportAlbumart: function() {
  316. return Session.get("reportAlbumart");
  317. },
  318. reportOther: function() {
  319. return Session.get("reportOther");
  320. },
  321. currentSong: function() {
  322. return Session.get("currentSong");
  323. },
  324. previousSong: function() {
  325. return Session.get("previousSong");
  326. },
  327. currentSongR: function() {
  328. return Session.get("currentSongR");
  329. },
  330. previousSongR: function() {
  331. return Session.get("previousSongR");
  332. },
  333. reportingSong: function() {
  334. if (Session.get("reportPrevious")) {
  335. return Session.get("previousSongR");
  336. } else {
  337. return Session.get("currentSongR");
  338. }
  339. },
  340. votes: function(){
  341. return Rooms.findOne({type: Session.get("type")}).votes;
  342. }
  343. });
  344. Template.settings.helpers({
  345. username: function() {
  346. if (Meteor.user() !== undefined) {
  347. return Meteor.user().profile.username;
  348. } else {
  349. return "";
  350. }
  351. }
  352. });
  353. Template.stations.helpers({
  354. playlist: function() {
  355. var query = {type: Session.get("playlistToEdit").toLowerCase()};
  356. var playlists = Playlists.find(query).fetch();
  357. return playlists;
  358. },
  359. whichStation: function(){
  360. return Session.get("playlistToEdit");
  361. },
  362. reports: function() {
  363. var query = {room: Session.get("playlistToEdit").toLowerCase()};
  364. var reports = Reports.find(query).fetch();
  365. console.log(reports);
  366. return reports;
  367. }
  368. });