helpers.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  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. return Feedback.find().fetch().reverse();
  87. }
  88. })
  89. Template.header.helpers({
  90. userId: function () {
  91. return Meteor.userId();
  92. }
  93. });
  94. Template.home.helpers({
  95. currentSong: function () {
  96. var type = this.type;
  97. var room = Rooms.findOne({type: type});
  98. if (room !== undefined) {
  99. return room.currentSong;
  100. } else {
  101. return false;
  102. }
  103. },
  104. userNum: function () {
  105. var type = this.type;
  106. var userNum = Rooms.findOne({type: type}).users;
  107. return userNum;
  108. }
  109. });
  110. Template.playlist.helpers({
  111. playlist_songs: function () {
  112. parts = location.href.split('/');
  113. id = parts.pop();
  114. type = id.toLowerCase();
  115. var data = Playlists.findOne({type: type});
  116. if (data !== undefined) {
  117. data.songs.map(function (song) {
  118. if (Session.get("currentSong") !== undefined && song.mid === Session.get("currentSong").mid) {
  119. song.current = true;
  120. } else {
  121. song.current = false;
  122. }
  123. return song;
  124. });
  125. return data.songs;
  126. } else {
  127. return [];
  128. }
  129. }
  130. });
  131. Template.profile.helpers({
  132. "real_name": function () {
  133. return Session.get("real_name");
  134. },
  135. "username": function () {
  136. return Session.get("username")
  137. },
  138. "first_joined": function () {
  139. return moment(Session.get("first_joined")).format("DD/MM/YYYY HH:mm:ss");
  140. },
  141. "rank": function () {
  142. return Session.get("rank");
  143. },
  144. loaded: function () {
  145. return Session.get("loaded");
  146. },
  147. likedSongs: function () {
  148. var likedArr = [];
  149. Session.get("liked").forEach(function (mid) {
  150. Rooms.find().forEach(function (room) {
  151. Playlists.find({type: room.type}).forEach(function (pl) {
  152. for (var i in pl.songs) {
  153. if (pl.songs[i].mid === mid) {
  154. likedArr.push({title: pl.songs[i].title, artist: pl.songs[i].artist, room: room.display});
  155. }
  156. }
  157. });
  158. })
  159. });
  160. return likedArr;
  161. },
  162. dislikedSongs: function () {
  163. var dislikedArr = [];
  164. Session.get("disliked").forEach(function (mid) {
  165. Rooms.find().forEach(function (room) {
  166. Playlists.find({type: room.type}).forEach(function (pl) {
  167. for (var i in pl.songs) {
  168. if (pl.songs[i].mid === mid) {
  169. dislikedArr.push({
  170. title: pl.songs[i].title,
  171. artist: pl.songs[i].artist,
  172. room: room.display
  173. });
  174. }
  175. }
  176. });
  177. })
  178. });
  179. return dislikedArr;
  180. },
  181. isUser: function () {
  182. var parts = Router.current().url.split('/');
  183. var username = parts.pop();
  184. if (username === Meteor.user().profile.username) {
  185. return true;
  186. }
  187. }
  188. });
  189. Template.queues.helpers({
  190. queues: function () {
  191. var queues = Queues.find({}).fetch();
  192. queues.map(function (queue) {
  193. if (Rooms.find({type: queue.type}).count() !== 1) {
  194. return;
  195. } else {
  196. queue.display = Rooms.findOne({type: queue.type}).display;
  197. return queue;
  198. }
  199. });
  200. return queues;
  201. },
  202. song_image: function() {
  203. return Session.get("image_url");
  204. }
  205. });
  206. Template.manageStation.helpers({
  207. songs: function () {
  208. var parts = location.href.split('/');
  209. parts.pop();
  210. var id = parts.pop();
  211. var type = id.toLowerCase();
  212. var playlist = Playlists.findOne({type: type});
  213. return playlist.songs;
  214. },
  215. song_image: function() {
  216. return Session.get("image_url");
  217. },
  218. genre: function() {
  219. var parts = location.href.split('/');
  220. parts.pop();
  221. var id = parts.pop();
  222. var type = id.toLowerCase();
  223. return type;
  224. }
  225. });
  226. Template.room.helpers({
  227. singleVideo: function () {
  228. return true;
  229. },
  230. chat: function () {
  231. Meteor.setTimeout(function () {
  232. var elem = document.getElementById('chat');
  233. if (elem !== undefined && elem !== null) {
  234. elem.scrollTop = elem.scrollHeight;
  235. }
  236. }, 100);
  237. return Chat.find({type: Session.get("type")}, {sort: {time: -1}, limit: 50}).fetch().reverse();
  238. },
  239. globalChat: function () {
  240. Meteor.setTimeout(function () {
  241. var elem = document.getElementById('global-chat');
  242. if (elem !== undefined && elem !== null) {
  243. elem.scrollTop = elem.scrollHeight;
  244. }
  245. }, 100);
  246. return Chat.find({type: "global"}, {sort: {time: -1}, limit: 50}).fetch().reverse();
  247. },
  248. likes: function () {
  249. var playlist = Playlists.findOne({type: Session.get("type")});
  250. var likes = 0;
  251. playlist.songs.forEach(function (song) {
  252. if (Session.get("currentSong") && song.mid === Session.get("currentSong").mid) {
  253. likes = song.likes;
  254. return;
  255. }
  256. });
  257. return likes;
  258. },
  259. dislikes: function () {
  260. var playlist = Playlists.findOne({type: Session.get("type")});
  261. var dislikes = 0;
  262. playlist.songs.forEach(function (song) {
  263. if (Session.get("currentSong") && song.mid === Session.get("currentSong").mid) {
  264. dislikes = song.dislikes;
  265. return;
  266. }
  267. });
  268. return dislikes;
  269. },
  270. liked: function () {
  271. if (Meteor.userId()) {
  272. var currentSong = Session.get("currentSong");
  273. if (currentSong && Meteor.user().profile.liked.indexOf(currentSong.mid) !== -1) {
  274. return "active";
  275. } else {
  276. return "";
  277. }
  278. } else {
  279. "";
  280. }
  281. },
  282. disliked: function () {
  283. if (Meteor.userId()) {
  284. var currentSong = Session.get("currentSong");
  285. if (currentSong && Meteor.user().profile.disliked.indexOf(currentSong.mid) !== -1) {
  286. return "active";
  287. } else {
  288. return "";
  289. }
  290. } else {
  291. "";
  292. }
  293. },
  294. type: function () {
  295. var parts = location.href.split('/');
  296. var id = parts.pop().toLowerCase();
  297. return Rooms.findOne({type: id}).display;
  298. },
  299. users: function () {
  300. var parts = location.href.split('/');
  301. var id = parts.pop().toLowerCase();
  302. return Rooms.findOne({type: id}).users;
  303. },
  304. title: function () {
  305. return Session.get("title");
  306. },
  307. artist: function () {
  308. return Session.get("artist");
  309. },
  310. loaded: function () {
  311. return Session.get("loaded");
  312. },
  313. paused: function () {
  314. return Session.get("state") === "paused";
  315. },
  316. private: function () {
  317. return Rooms.findOne({type: Session.get("type")}).private === true;
  318. },
  319. report: function () {
  320. return Session.get("reportObj");
  321. },
  322. reportSong: function () {
  323. return Session.get("reportSong");
  324. },
  325. reportTitle: function () {
  326. return Session.get("reportTitle");
  327. },
  328. reportAuthor: function () {
  329. return Session.get("reportAuthor");
  330. },
  331. reportDuration: function () {
  332. return Session.get("reportDuration");
  333. },
  334. reportAudio: function () {
  335. return Session.get("reportAudio");
  336. },
  337. reportAlbumart: function () {
  338. return Session.get("reportAlbumart");
  339. },
  340. reportOther: function () {
  341. return Session.get("reportOther");
  342. },
  343. currentSong: function () {
  344. return Session.get("currentSong");
  345. },
  346. previousSong: function () {
  347. return Session.get("previousSong");
  348. },
  349. currentSongR: function () {
  350. return Session.get("currentSongR");
  351. },
  352. previousSongR: function () {
  353. return Session.get("previousSongR");
  354. },
  355. reportingSong: function () {
  356. if (Session.get("reportPrevious")) {
  357. return Session.get("previousSongR");
  358. } else {
  359. return Session.get("currentSongR");
  360. }
  361. },
  362. votes: function () {
  363. return Rooms.findOne({type: Session.get("type")}).votes;
  364. }
  365. });
  366. Template.settings.helpers({
  367. username: function () {
  368. if (Meteor.user() !== undefined) {
  369. return Meteor.user().profile.username;
  370. } else {
  371. return "";
  372. }
  373. }
  374. });