helpers.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  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 = Songs.find({"genres": type}).fetch();
  116. if (data !== undefined) {
  117. data.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;
  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. Songs.find().forEach(function (data) {
  151. if (data.mid === mid) {
  152. likedArr.push({title: data.title, artist: data.artist});
  153. }
  154. });
  155. });
  156. return likedArr;
  157. },
  158. dislikedSongs: function () {
  159. var dislikedArr = [];
  160. Session.get("disliked").forEach(function (mid) {
  161. Songs.find().forEach(function (data) {
  162. if (data.mid === mid) {
  163. dislikedArr.push({title: data.title, artist: data.artist});
  164. }
  165. });
  166. });
  167. return dislikedArr;
  168. },
  169. isUser: function () {
  170. var parts = Router.current().url.split('/');
  171. var username = parts.pop();
  172. if (username === Meteor.user().profile.username) {
  173. return true;
  174. }
  175. }
  176. });
  177. Template.queues.helpers({
  178. songs: function () {
  179. return Queues.find({}).fetch();
  180. },
  181. song_image: function() {
  182. return Session.get("image_url");
  183. }
  184. });
  185. Template.news.helpers({
  186. articles: function() {
  187. return News.find().fetch().reverse();
  188. }
  189. });
  190. Template.manageSongs.helpers({
  191. songs: function () {
  192. var noGenres = Session.get("showNoGenres");
  193. var genres = Session.get("showGenres");
  194. if (noGenres === true && genres === true) {
  195. return Songs.find();
  196. } else if (noGenres === true && genres === false) {
  197. return Songs.find({genres: []});
  198. } else {
  199. return Songs.find({$where : "this.genres.length > 0"});
  200. }
  201. },
  202. song_image: function() {
  203. return Session.get("image_url");
  204. }
  205. });
  206. Template.manageStation.helpers({
  207. editingDesc: function() {
  208. return Session.get("editingDesc");
  209. },
  210. description: function() {
  211. var parts = location.href.split('/');
  212. parts.pop();
  213. var id = parts.pop();
  214. var type = id.toLowerCase();
  215. return Rooms.findOne({type: type}).roomDesc;
  216. },
  217. songs: function () {
  218. var parts = location.href.split('/');
  219. parts.pop();
  220. var id = parts.pop();
  221. var type = id.toLowerCase();
  222. var playlist = Playlists.findOne({type: type});
  223. var songs = [];
  224. if (playlist !== undefined && playlist.songs !== undefined) {
  225. playlist.songs.forEach(function(songMid) {
  226. songs.push(Songs.findOne({mid: songMid}));
  227. });
  228. }
  229. return songs;
  230. },
  231. song_image: function() {
  232. return Session.get("image_url");
  233. },
  234. genre: function() {
  235. var parts = location.href.split('/');
  236. parts.pop();
  237. var id = parts.pop();
  238. var type = id.toLowerCase();
  239. return type;
  240. }
  241. });
  242. Template.room.helpers({
  243. editingSong: function() {
  244. return Session.get("editingSong");
  245. },
  246. singleVideoResults: function () {
  247. return Session.get("songResults");
  248. },
  249. singleVideoResultsActive: function() {
  250. var songs = Session.get("songResults");
  251. if (songs !== undefined && songs.length > 0) {
  252. return true;
  253. } else {
  254. return false;
  255. }
  256. },
  257. importPlaylistVideos: function () {
  258. return Session.get("songResults");
  259. },
  260. playlistImportVideosActive: function() {
  261. var songs = Session.get("songResults");
  262. if (songs !== undefined && songs.length > 0) {
  263. return true;
  264. } else {
  265. return false;
  266. }
  267. },
  268. singleVideo: function () {
  269. return Session.get("si_or_pl") === "singleVideo";
  270. },
  271. chat: function () {
  272. Meteor.setTimeout(function () {
  273. var elem = document.getElementById('chat');
  274. if (elem !== undefined && elem !== null) {
  275. elem.scrollTop = elem.scrollHeight;
  276. }
  277. }, 100);
  278. return Chat.find({type: Session.get("type")}, {sort: {time: -1}, limit: 50}).fetch().reverse();
  279. },
  280. globalChat: function () {
  281. Meteor.setTimeout(function () {
  282. var elem = document.getElementById('global-chat');
  283. if (elem !== undefined && elem !== null) {
  284. elem.scrollTop = elem.scrollHeight;
  285. }
  286. }, 100);
  287. return Chat.find({type: "global"}, {sort: {time: -1}, limit: 50}).fetch().reverse();
  288. },
  289. likes: function () {
  290. var playlist = Playlists.findOne({type: Session.get("type")});
  291. var likes = 0;
  292. playlist.songs.forEach(function (song) {
  293. if (Session.get("currentSong") && song.mid === Session.get("currentSong").mid) {
  294. likes = song.likes;
  295. return;
  296. }
  297. });
  298. return likes;
  299. },
  300. dislikes: function () {
  301. var playlist = Playlists.findOne({type: Session.get("type")});
  302. var dislikes = 0;
  303. playlist.songs.forEach(function (song) {
  304. if (Session.get("currentSong") && song.mid === Session.get("currentSong").mid) {
  305. dislikes = song.dislikes;
  306. return;
  307. }
  308. });
  309. return dislikes;
  310. },
  311. liked: function () {
  312. if (Meteor.userId()) {
  313. var currentSong = Session.get("currentSong");
  314. if (currentSong && Meteor.user().profile.liked.indexOf(currentSong.mid) !== -1) {
  315. return "liked";
  316. } else {
  317. return "";
  318. }
  319. } else {
  320. "";
  321. }
  322. },
  323. disliked: function () {
  324. if (Meteor.userId()) {
  325. var currentSong = Session.get("currentSong");
  326. if (currentSong && Meteor.user().profile.disliked.indexOf(currentSong.mid) !== -1) {
  327. return "disliked";
  328. } else {
  329. return "";
  330. }
  331. } else {
  332. "";
  333. }
  334. },
  335. type: function () {
  336. var parts = location.href.split('/');
  337. var id = parts.pop().toLowerCase();
  338. return Rooms.findOne({type: id}).display;
  339. },
  340. users: function () {
  341. var parts = location.href.split('/');
  342. var id = parts.pop().toLowerCase();
  343. return Rooms.findOne({type: id}).users;
  344. },
  345. title: function () {
  346. return Session.get("title");
  347. },
  348. artist: function () {
  349. return Session.get("artist");
  350. },
  351. loaded: function () {
  352. return Session.get("loaded");
  353. },
  354. paused: function () {
  355. return Session.get("state") === "paused";
  356. },
  357. private: function () {
  358. return Rooms.findOne({type: Session.get("type")}).private === true;
  359. },
  360. report: function () {
  361. return Session.get("reportObj");
  362. },
  363. reportSong: function () {
  364. return Session.get("reportSong");
  365. },
  366. reportTitle: function () {
  367. return Session.get("reportTitle");
  368. },
  369. reportAuthor: function () {
  370. return Session.get("reportAuthor");
  371. },
  372. reportDuration: function () {
  373. return Session.get("reportDuration");
  374. },
  375. reportAudio: function () {
  376. return Session.get("reportAudio");
  377. },
  378. reportAlbumart: function () {
  379. return Session.get("reportAlbumart");
  380. },
  381. reportOther: function () {
  382. return Session.get("reportOther");
  383. },
  384. currentSong: function () {
  385. return Session.get("currentSong");
  386. },
  387. previousSong: function () {
  388. return Session.get("previousSong");
  389. },
  390. currentSongR: function () {
  391. return Session.get("currentSongR");
  392. },
  393. previousSongR: function () {
  394. return Session.get("previousSongR");
  395. },
  396. reportingSong: function () {
  397. if (Session.get("reportPrevious")) {
  398. return Session.get("previousSongR");
  399. } else {
  400. return Session.get("currentSongR");
  401. }
  402. },
  403. votes: function () {
  404. console.log(Rooms.findOne({type: Session.get("type")}).votes);
  405. return Rooms.findOne({type: Session.get("type")}).votes;
  406. }
  407. });
  408. Template.settings.helpers({
  409. username: function () {
  410. if (Meteor.user() !== undefined) {
  411. return Meteor.user().profile.username;
  412. } else {
  413. return "";
  414. }
  415. }
  416. });