2
0

helpers.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. Template.admin.helpers({
  2. queueCount: function () {
  3. return Queues.find().count();
  4. },
  5. genreQueue: function(type) {
  6. if (type === "none") {
  7. return Queues.find({genres: []}).count();
  8. } else {
  9. return Queues.find({genres: type}).count();
  10. }
  11. },
  12. alertsList: function() {
  13. return Alerts.find({});
  14. },
  15. queues: function () {
  16. var queues = Queues.find({}).fetch();
  17. return queues;
  18. },
  19. usersOnline: function () {
  20. Meteor.call("getUserNum", function (err, num) {
  21. if (err) {
  22. console.log(err);
  23. }
  24. Session.set("userNum", num);
  25. });
  26. return Session.get("userNum");
  27. },
  28. roomUserNum: function () {
  29. var type = this.type;
  30. var userNum = Rooms.findOne({type: type}).users;
  31. return userNum;
  32. },
  33. allUsers: function () {
  34. Meteor.call("getTotalUsers", function (err, num) {
  35. Session.set("allUsers", num);
  36. })
  37. return Session.get("allUsers");
  38. },
  39. playlists: function () {
  40. var playlists = Playlists.find({}).fetch();
  41. playlists.map(function (playlist) {
  42. if (Rooms.find({type: playlist.type}).count() !== 1) {
  43. return;
  44. } else {
  45. playlist.display = Rooms.findOne({type: playlist.type}).display;
  46. return playlist;
  47. }
  48. });
  49. return playlists;
  50. },
  51. reportsCount: function (room) {
  52. room = room.toLowerCase();
  53. var reports = Reports.findOne({room: room});
  54. return reports && "report" in reports ? reports.report.length : 0;
  55. }
  56. });
  57. Template.alerts.helpers({
  58. alerts: function () {
  59. return Alerts.find({active: true});
  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. songs: function () {
  191. return Queues.find({}).fetch();
  192. },
  193. song_image: function() {
  194. return Session.get("image_url");
  195. }
  196. });
  197. Template.news.helpers({
  198. articles: function() {
  199. return News.find().fetch().reverse();
  200. }
  201. });
  202. Template.manageSongs.helpers({
  203. songs: function () {
  204. var noGenres = Session.get("showNoGenres");
  205. var genres = Session.get("showGenres");
  206. if (noGenres === true && genres === true) {
  207. return Songs.find();
  208. } else if (noGenres === true && genres === false) {
  209. return Songs.find({genres: []});
  210. } else {
  211. return Songs.find({$where : "this.genres.length > 0"});
  212. }
  213. },
  214. song_image: function() {
  215. return Session.get("image_url");
  216. }
  217. });
  218. Template.manageStation.helpers({
  219. editingDesc: function() {
  220. return Session.get("editingDesc");
  221. },
  222. description: function() {
  223. var parts = location.href.split('/');
  224. parts.pop();
  225. var id = parts.pop();
  226. var type = id.toLowerCase();
  227. return Rooms.findOne({type: type}).roomDesc;
  228. },
  229. songs: function () {
  230. var parts = location.href.split('/');
  231. parts.pop();
  232. var id = parts.pop();
  233. var type = id.toLowerCase();
  234. var playlist = Playlists.findOne({type: type});
  235. var songs = [];
  236. if (playlist !== undefined && playlist.songs !== undefined) {
  237. playlist.songs.forEach(function(songMid) {
  238. songs.push(Songs.findOne({mid: songMid}));
  239. });
  240. }
  241. return songs;
  242. },
  243. song_image: function() {
  244. return Session.get("image_url");
  245. },
  246. genre: function() {
  247. var parts = location.href.split('/');
  248. parts.pop();
  249. var id = parts.pop();
  250. var type = id.toLowerCase();
  251. return type;
  252. }
  253. });
  254. Template.room.helpers({
  255. editingSong: function() {
  256. return Session.get("editingSong");
  257. },
  258. singleVideoResults: function () {
  259. return Session.get("songResults");
  260. },
  261. singleVideoResultsActive: function() {
  262. var songs = Session.get("songResults");
  263. if (songs !== undefined && songs.length > 0) {
  264. return true;
  265. } else {
  266. return false;
  267. }
  268. },
  269. importPlaylistVideos: function () {
  270. return Session.get("songResults");
  271. },
  272. playlistImportVideosActive: function() {
  273. var songs = Session.get("songResults");
  274. if (songs !== undefined && songs.length > 0) {
  275. return true;
  276. } else {
  277. return false;
  278. }
  279. },
  280. singleVideo: function () {
  281. return Session.get("si_or_pl") === "singleVideo";
  282. },
  283. chat: function () {
  284. Meteor.setTimeout(function () {
  285. var elem = document.getElementById('chat');
  286. if (elem !== undefined && elem !== null) {
  287. elem.scrollTop = elem.scrollHeight;
  288. }
  289. }, 100);
  290. return Chat.find({type: Session.get("type")}, {sort: {time: -1}, limit: 50}).fetch().reverse();
  291. },
  292. globalChat: function () {
  293. Meteor.setTimeout(function () {
  294. var elem = document.getElementById('global-chat');
  295. if (elem !== undefined && elem !== null) {
  296. elem.scrollTop = elem.scrollHeight;
  297. }
  298. }, 100);
  299. return Chat.find({type: "global"}, {sort: {time: -1}, limit: 50}).fetch().reverse();
  300. },
  301. likes: function () {
  302. var playlist = Playlists.findOne({type: Session.get("type")});
  303. var likes = 0;
  304. playlist.songs.forEach(function (song) {
  305. if (Session.get("currentSong") && song.mid === Session.get("currentSong").mid) {
  306. likes = song.likes;
  307. return;
  308. }
  309. });
  310. return likes;
  311. },
  312. dislikes: function () {
  313. var playlist = Playlists.findOne({type: Session.get("type")});
  314. var dislikes = 0;
  315. playlist.songs.forEach(function (song) {
  316. if (Session.get("currentSong") && song.mid === Session.get("currentSong").mid) {
  317. dislikes = song.dislikes;
  318. return;
  319. }
  320. });
  321. return dislikes;
  322. },
  323. liked: function () {
  324. if (Meteor.userId()) {
  325. var currentSong = Session.get("currentSong");
  326. if (currentSong && Meteor.user().profile.liked.indexOf(currentSong.mid) !== -1) {
  327. return "liked";
  328. } else {
  329. return "";
  330. }
  331. } else {
  332. "";
  333. }
  334. },
  335. disliked: function () {
  336. if (Meteor.userId()) {
  337. var currentSong = Session.get("currentSong");
  338. if (currentSong && Meteor.user().profile.disliked.indexOf(currentSong.mid) !== -1) {
  339. return "disliked";
  340. } else {
  341. return "";
  342. }
  343. } else {
  344. "";
  345. }
  346. },
  347. type: function () {
  348. var parts = location.href.split('/');
  349. var id = parts.pop().toLowerCase();
  350. return Rooms.findOne({type: id}).display;
  351. },
  352. users: function () {
  353. var parts = location.href.split('/');
  354. var id = parts.pop().toLowerCase();
  355. return Rooms.findOne({type: id}).users;
  356. },
  357. title: function () {
  358. return Session.get("title");
  359. },
  360. artist: function () {
  361. return Session.get("artist");
  362. },
  363. loaded: function () {
  364. return Session.get("loaded");
  365. },
  366. paused: function () {
  367. return Session.get("state") === "paused";
  368. },
  369. private: function () {
  370. return Rooms.findOne({type: Session.get("type")}).private === true;
  371. },
  372. report: function () {
  373. return Session.get("reportObj");
  374. },
  375. reportSong: function () {
  376. return Session.get("reportSong");
  377. },
  378. reportTitle: function () {
  379. return Session.get("reportTitle");
  380. },
  381. reportAuthor: function () {
  382. return Session.get("reportAuthor");
  383. },
  384. reportDuration: function () {
  385. return Session.get("reportDuration");
  386. },
  387. reportAudio: function () {
  388. return Session.get("reportAudio");
  389. },
  390. reportAlbumart: function () {
  391. return Session.get("reportAlbumart");
  392. },
  393. reportOther: function () {
  394. return Session.get("reportOther");
  395. },
  396. currentSong: function () {
  397. return Session.get("currentSong");
  398. },
  399. previousSong: function () {
  400. return Session.get("previousSong");
  401. },
  402. currentSongR: function () {
  403. return Session.get("currentSongR");
  404. },
  405. previousSongR: function () {
  406. return Session.get("previousSongR");
  407. },
  408. reportingSong: function () {
  409. if (Session.get("reportPrevious")) {
  410. return Session.get("previousSongR");
  411. } else {
  412. return Session.get("currentSongR");
  413. }
  414. },
  415. votes: function () {
  416. console.log(Rooms.findOne({type: Session.get("type")}).votes);
  417. return Rooms.findOne({type: Session.get("type")}).votes;
  418. }
  419. });
  420. Template.settings.helpers({
  421. username: function () {
  422. if (Meteor.user() !== undefined) {
  423. return Meteor.user().profile.username;
  424. } else {
  425. return "";
  426. }
  427. }
  428. });