2
0

helpers.js 16 KB

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