2
0

helpers.js 12 KB

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