helpers.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  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 songIDs = Playlists.find({"type": Session.get("type")}).fetch()[0].songs
  113. var data = [];
  114. songIDs.forEach(function(id){
  115. var song = Songs.findOne({"mid": id});
  116. data.push(song);
  117. })
  118. console.log(data);
  119. if (data !== undefined) {
  120. data.map(function (song) {
  121. if (Session.get("currentSong") !== undefined && song.mid === Session.get("currentSong").mid) {
  122. song.current = true;
  123. } else {
  124. song.current = false;
  125. }
  126. return song;
  127. });
  128. return data;
  129. } else {
  130. return [];
  131. }
  132. },
  133. nextSong: function(){
  134. var song;
  135. var data = Playlists.find({"type": Session.get("type")}).fetch()[0].songs
  136. for(var i = 0; i < data.length; i++){
  137. if(data[i] === Session.get("currentSong").mid){
  138. if(i === data.length - 1){
  139. song = Songs.findOne({"mid": data[0]});
  140. Session.set("nextSong", [song])
  141. } else{
  142. song = Songs.findOne({"mid": data[i+1]});
  143. Session.set("nextSong", [song]);
  144. }
  145. }
  146. };
  147. return Session.get("nextSong");
  148. }
  149. });
  150. Template.profile.helpers({
  151. "real_name": function () {
  152. return Session.get("real_name");
  153. },
  154. "username": function () {
  155. return Session.get("username")
  156. },
  157. "first_joined": function () {
  158. return moment(Session.get("first_joined")).format("DD/MM/YYYY HH:mm:ss");
  159. },
  160. "rank": function () {
  161. return Session.get("rank");
  162. },
  163. loaded: function () {
  164. return Session.get("loaded");
  165. },
  166. likedSongs: function () {
  167. var likedArr = [];
  168. Session.get("liked").forEach(function (mid) {
  169. Songs.find().forEach(function (data) {
  170. if (data.mid === mid) {
  171. likedArr.push({title: data.title, artist: data.artist});
  172. }
  173. });
  174. });
  175. return likedArr;
  176. },
  177. dislikedSongs: function () {
  178. var dislikedArr = [];
  179. Session.get("disliked").forEach(function (mid) {
  180. Songs.find().forEach(function (data) {
  181. if (data.mid === mid) {
  182. dislikedArr.push({title: data.title, artist: data.artist});
  183. }
  184. });
  185. });
  186. return dislikedArr;
  187. },
  188. isUser: function () {
  189. var parts = Router.current().url.split('/');
  190. var username = parts.pop();
  191. if (username === Meteor.user().profile.username) {
  192. return true;
  193. }
  194. }
  195. });
  196. Template.queues.helpers({
  197. songs: function () {
  198. return Queues.find({}).fetch();
  199. },
  200. song_image: function() {
  201. return Session.get("image_url");
  202. }
  203. });
  204. Template.news.helpers({
  205. articles: function() {
  206. return News.find().fetch().reverse();
  207. }
  208. });
  209. Template.manageSongs.helpers({
  210. songs: function () {
  211. var noGenres = Session.get("showNoGenres");
  212. var genres = Session.get("showGenres");
  213. if (noGenres === true && genres === true) {
  214. return Songs.find();
  215. } else if (noGenres === true && genres === false) {
  216. return Songs.find({genres: []});
  217. } else {
  218. return Songs.find({$where : "this.genres.length > 0"});
  219. }
  220. },
  221. song_image: function() {
  222. return Session.get("image_url");
  223. }
  224. });
  225. Template.manageStation.helpers({
  226. editingDesc: function() {
  227. return Session.get("editingDesc");
  228. },
  229. description: function() {
  230. var parts = location.href.split('/');
  231. parts.pop();
  232. var id = parts.pop();
  233. var type = id.toLowerCase();
  234. return Rooms.findOne({type: type}).roomDesc;
  235. },
  236. songs: function () {
  237. var parts = location.href.split('/');
  238. parts.pop();
  239. var id = parts.pop();
  240. var type = id.toLowerCase();
  241. var playlist = Playlists.findOne({type: type});
  242. var songs = [];
  243. if (playlist !== undefined && playlist.songs !== undefined) {
  244. playlist.songs.forEach(function(songMid) {
  245. songs.push(Songs.findOne({mid: songMid}));
  246. });
  247. }
  248. return songs;
  249. },
  250. song_image: function() {
  251. return Session.get("image_url");
  252. },
  253. genre: function() {
  254. var parts = location.href.split('/');
  255. parts.pop();
  256. var id = parts.pop();
  257. var type = id.toLowerCase();
  258. return type;
  259. },
  260. reports: function() {
  261. var parts = location.href.split('/');
  262. parts.pop();
  263. var id = parts.pop();
  264. var query = {room: id.toLowerCase()};
  265. var reports = Reports.find(query).fetch();
  266. return reports;
  267. }
  268. });
  269. Template.room.helpers({
  270. editingSong: function() {
  271. return Session.get("editingSong");
  272. },
  273. singleVideoResults: function () {
  274. return Session.get("songResults");
  275. },
  276. singleVideoResultsActive: 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. importPlaylistVideos: function () {
  285. return Session.get("songResults");
  286. },
  287. playlistImportVideosActive: function() {
  288. var songs = Session.get("songResults");
  289. if (songs !== undefined && songs.length > 0) {
  290. return true;
  291. } else {
  292. return false;
  293. }
  294. },
  295. singleVideo: function () {
  296. return Session.get("si_or_pl") === "singleVideo";
  297. },
  298. chat: function () {
  299. Meteor.setTimeout(function () {
  300. var elem = document.getElementById('chat');
  301. if (elem !== undefined && elem !== null) {
  302. elem.scrollTop = elem.scrollHeight;
  303. }
  304. }, 100);
  305. return Chat.find({type: Session.get("type")}, {sort: {time: -1}, limit: 50}).fetch().reverse();
  306. },
  307. globalChat: function () {
  308. Meteor.setTimeout(function () {
  309. var elem = document.getElementById('global-chat');
  310. if (elem !== undefined && elem !== null) {
  311. elem.scrollTop = elem.scrollHeight;
  312. }
  313. }, 100);
  314. return Chat.find({type: "global"}, {sort: {time: -1}, limit: 50}).fetch().reverse();
  315. },
  316. likes: function () {
  317. var playlist = Playlists.findOne({type: Session.get("type")});
  318. var likes = 0;
  319. playlist.songs.forEach(function (song) {
  320. if (Session.get("currentSong") && song.mid === Session.get("currentSong").mid) {
  321. likes = song.likes;
  322. return;
  323. }
  324. });
  325. return likes;
  326. },
  327. dislikes: function () {
  328. var playlist = Playlists.findOne({type: Session.get("type")});
  329. var dislikes = 0;
  330. playlist.songs.forEach(function (song) {
  331. if (Session.get("currentSong") && song.mid === Session.get("currentSong").mid) {
  332. dislikes = song.dislikes;
  333. return;
  334. }
  335. });
  336. return dislikes;
  337. },
  338. liked: function () {
  339. if (Meteor.userId()) {
  340. var currentSong = Session.get("currentSong");
  341. if (currentSong && Meteor.user().profile.liked.indexOf(currentSong.mid) !== -1) {
  342. return "liked";
  343. } else {
  344. return "";
  345. }
  346. } else {
  347. "";
  348. }
  349. },
  350. disliked: function () {
  351. if (Meteor.userId()) {
  352. var currentSong = Session.get("currentSong");
  353. if (currentSong && Meteor.user().profile.disliked.indexOf(currentSong.mid) !== -1) {
  354. return "disliked";
  355. } else {
  356. return "";
  357. }
  358. } else {
  359. "";
  360. }
  361. },
  362. type: function () {
  363. var parts = location.href.split('/');
  364. var id = parts.pop().toLowerCase();
  365. return Rooms.findOne({type: id}).display;
  366. },
  367. users: function () {
  368. var parts = location.href.split('/');
  369. var id = parts.pop().toLowerCase();
  370. return Rooms.findOne({type: id}).users;
  371. },
  372. title: function () {
  373. return Session.get("title");
  374. },
  375. artist: function () {
  376. return Session.get("artist");
  377. },
  378. loaded: function () {
  379. return Session.get("loaded");
  380. },
  381. paused: function () {
  382. return Session.get("state") === "paused";
  383. },
  384. private: function () {
  385. return Rooms.findOne({type: Session.get("type")}).private === true;
  386. },
  387. currentSong: function(){
  388. return Session.get("currentSong");
  389. },
  390. reportSong: function(){
  391. Meteor.setInterval(function(){
  392. if($("#report-song").is(":checked")){
  393. Session.set("reportSong", true)
  394. } else { Session.set("reportSong", false) }
  395. }, 500);
  396. return Session.get("reportSong");
  397. },
  398. reportSongOther: function(){
  399. Meteor.setInterval(function(){
  400. if($("#report-song-other").is(":checked")){
  401. Session.set("reportSongOther", true)
  402. } else { Session.set("reportSongOther", false) }
  403. }, 500);
  404. return Session.get("reportSongOther");
  405. },
  406. reportTitle: function(){
  407. Meteor.setInterval(function(){
  408. if($("#report-title").is(":checked")){
  409. Session.set("reportTitle", true)
  410. } else { Session.set("reportTitle", false) }
  411. }, 500);
  412. return Session.get("reportTitle");
  413. },
  414. reportTitleOther: function(){
  415. Meteor.setInterval(function(){
  416. if($("#report-title-other").is(":checked")){
  417. Session.set("reportTitleOther", true)
  418. } else { Session.set("reportTitleOther", false) }
  419. }, 500);
  420. return Session.get("reportTitleOther");
  421. },
  422. reportArtist: function(){
  423. Meteor.setInterval(function(){
  424. if($("#report-artist").is(":checked")){
  425. Session.set("reportArtist", true)
  426. } else { Session.set("reportArtist", false) }
  427. }, 500);
  428. return Session.get("reportArtist");
  429. },
  430. reportArtistOther: function(){
  431. Meteor.setInterval(function(){
  432. if($("#report-artist-other").is(":checked")){
  433. Session.set("reportArtistOther", true)
  434. } else { Session.set("reportArtistOther", false) }
  435. }, 500);
  436. return Session.get("reportArtistOther");
  437. },
  438. reportDuration: function(){
  439. Meteor.setInterval(function(){
  440. if($("#report-duration").is(":checked")){
  441. Session.set("reportDuration", true)
  442. } else { Session.set("reportDuration", false) }
  443. }, 500);
  444. return Session.get("reportDuration");
  445. },
  446. reportDurationOther: function(){
  447. Meteor.setInterval(function(){
  448. if($("#report-duration-other").is(":checked")){
  449. Session.set("reportDurationOther", true)
  450. } else { Session.set("reportDurationOther", false) }
  451. }, 500);
  452. return Session.get("reportDurationOther");
  453. },
  454. reportAlbumart: function(){
  455. Meteor.setInterval(function(){
  456. if($("#report-albumart").is(":checked")){
  457. Session.set("reportAlbumart", true)
  458. } else { Session.set("reportAlbumart", false) }
  459. }, 500);
  460. return Session.get("reportAlbumart");
  461. },
  462. reportAlbumartOther: function(){
  463. Meteor.setInterval(function(){
  464. if($("#report-albumart-other").is(":checked")){
  465. Session.set("reportAlbumartOther", true)
  466. } else { Session.set("reportAlbumartOther", false) }
  467. }, 500);
  468. return Session.get("reportAlbumartOther");
  469. },
  470. reportOther: function(){
  471. Meteor.setInterval(function(){
  472. if($("#report-other").is(":checked")){
  473. Session.set("reportOther", true)
  474. } else { Session.set("reportOther", false) }
  475. }, 500);
  476. return Session.get("reportOther");
  477. },
  478. votes: function () {
  479. console.log(Rooms.findOne({type: Session.get("type")}).votes);
  480. return Rooms.findOne({type: Session.get("type")}).votes;
  481. },
  482. usersInRoom: function(){
  483. return Rooms.findOne({type: Session.get("type")}).userList;
  484. }
  485. });
  486. Template.settings.helpers({
  487. username: function () {
  488. if (Meteor.user() !== undefined) {
  489. return Meteor.user().profile.username;
  490. } else {
  491. return "";
  492. }
  493. }
  494. });