helpers.js 16 KB

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