helpers.js 13 KB

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