helpers.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. Template.admin.helpers({
  2. queueCount: function(display) {
  3. var d = display.toLowerCase();
  4. return queues && "songs" in queues ? queues.songs.length : 0;
  5. var queues = Queues.findOne({type: d});
  6. },
  7. queues: function() {
  8. var queues = Queues.find({}).fetch();
  9. return queues;
  10. },
  11. usersOnline: function(){
  12. Meteor.call("getUserNum", function(err, num){
  13. if(err){
  14. console.log(err);
  15. }
  16. Session.set("userNum", num);
  17. });
  18. return Session.get("userNum");
  19. },
  20. roomUserNum: function(){
  21. var type = this.type;
  22. var userNum = Rooms.findOne({type: type}).users;
  23. return userNum;
  24. },
  25. allUsers: function(){
  26. Meteor.call("getTotalUsers", function(err, num){
  27. Session.set("allUsers", num);
  28. })
  29. return Session.get("allUsers");
  30. },
  31. playlists: function() {
  32. var playlists = Playlists.find({}).fetch();
  33. playlists.map(function(playlist) {
  34. if (Rooms.find({type: playlist.type}).count() !== 1) {
  35. return;
  36. } else {
  37. playlist.display = Rooms.findOne({type: playlist.type}).display;
  38. return playlist;
  39. }
  40. });
  41. return playlists;
  42. },
  43. reportsCount: function(room) {
  44. room = room.toLowerCase();
  45. var reports = Reports.findOne({room:room});
  46. return reports && "report" in reports ? reports.report.length : 0;
  47. }
  48. });
  49. Template.alerts.helpers({
  50. alerts: function() {
  51. return Alerts.find({active: true});
  52. }
  53. });
  54. Template.alertsDashboard.helpers({
  55. "activeAlerts": function() {
  56. return Alerts.find({active: true});
  57. },
  58. "inactiveAlerts": function() {
  59. return Alerts.find({active: false});
  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. var data = Feedback.findOne();
  87. if(data !== undefined) {
  88. return data.messages.reverse();
  89. } else{
  90. return [];
  91. }
  92. }
  93. })
  94. Template.header.helpers({
  95. userId: function() {
  96. return Meteor.userId();
  97. }
  98. });
  99. Template.home.helpers({
  100. currentSong: function(){
  101. var type = this.type;
  102. var room = Rooms.findOne({type: type});
  103. if(room !== undefined){
  104. return room.currentSong;
  105. } else {
  106. return false;
  107. }
  108. },
  109. userNum: function(){
  110. var type = this.type;
  111. var userNum = Rooms.findOne({type: type}).users;
  112. return userNum;
  113. }
  114. });
  115. Template.playlist.helpers({
  116. playlist_songs: function() {
  117. parts = location.href.split('/');
  118. id = parts.pop();
  119. type = id.toLowerCase();
  120. var data = Playlists.findOne({type: type});
  121. if (data !== undefined) {
  122. data.songs.map(function(song) {
  123. if (Session.get("currentSong") !== undefined && song.mid === Session.get("currentSong").mid) {
  124. song.current = true;
  125. } else {
  126. song.current = false;
  127. }
  128. return song;
  129. });
  130. return data.songs;
  131. } else {
  132. return [];
  133. }
  134. }
  135. });
  136. Template.profile.helpers({
  137. "real_name": function(){
  138. return Session.get("real_name");
  139. },
  140. "username": function() {
  141. return Session.get("username")
  142. },
  143. "first_joined": function() {
  144. return moment(Session.get("first_joined")).format("DD/MM/YYYY HH:mm:ss");
  145. },
  146. "rank": function() {
  147. return Session.get("rank");
  148. },
  149. loaded: function() {
  150. return Session.get("loaded");
  151. },
  152. likedSongs: function(){
  153. var likedArr = [];
  154. Session.get("liked").forEach(function(mid){
  155. Rooms.find().forEach(function(room){
  156. Playlists.find({type: room.type}).forEach(function(pl){
  157. for(var i in pl.songs){
  158. if(pl.songs[i].mid === mid){
  159. likedArr.push({title: pl.songs[i].title, artist: pl.songs[i].artist, room: room.display});
  160. }
  161. }
  162. });
  163. })
  164. });
  165. return likedArr;
  166. },
  167. dislikedSongs: function(){
  168. var dislikedArr = [];
  169. Session.get("disliked").forEach(function(mid){
  170. Rooms.find().forEach(function(room){
  171. Playlists.find({type: room.type}).forEach(function(pl){
  172. for(var i in pl.songs){
  173. if(pl.songs[i].mid === mid){
  174. dislikedArr.push({title: pl.songs[i].title, artist: pl.songs[i].artist, room: room.display});
  175. }
  176. }
  177. });
  178. })
  179. });
  180. return dislikedArr;
  181. },
  182. isUser: function(){
  183. var parts = Router.current().url.split('/');
  184. var username = parts.pop();
  185. if(username === Meteor.user().profile.username){
  186. return true;
  187. }
  188. }
  189. });
  190. Template.queues.helpers({
  191. queues: function() {
  192. var queues = Queues.find({}).fetch();
  193. queues.map(function(queue) {
  194. if (Rooms.find({type: queue.type}).count() !== 1) {
  195. return;
  196. } else {
  197. queue.display = Rooms.findOne({type: queue.type}).display;
  198. return queue;
  199. }
  200. });
  201. return queues;
  202. },
  203. song_image: function() {
  204. return Session.get("image_url");
  205. }
  206. });
  207. Template.room.helpers({
  208. singleVideo: function() {
  209. return true;
  210. },
  211. chat: function() {
  212. Meteor.setTimeout(function() {
  213. var elem = document.getElementById('chat');
  214. if (elem !== undefined && elem !== null) {
  215. elem.scrollTop = elem.scrollHeight;
  216. }
  217. }, 100);
  218. return Chat.find({type: Session.get("type")}, {sort: {time: -1}, limit: 50 }).fetch().reverse();
  219. },
  220. globalChat: function() {
  221. Meteor.setTimeout(function() {
  222. var elem = document.getElementById('global-chat');
  223. if (elem !== undefined && elem !== null) {
  224. elem.scrollTop = elem.scrollHeight;
  225. }
  226. }, 100);
  227. return Chat.find({type: "global"}, {sort: {time: -1}, limit: 50 }).fetch().reverse();
  228. },
  229. likes: function() {
  230. var playlist = Playlists.findOne({type: Session.get("type")});
  231. var likes = 0;
  232. playlist.songs.forEach(function(song) {
  233. if (Session.get("currentSong") && song.mid === Session.get("currentSong").mid) {
  234. likes = song.likes;
  235. return;
  236. }
  237. });
  238. return likes;
  239. },
  240. dislikes: function() {
  241. var playlist = Playlists.findOne({type: Session.get("type")});
  242. var dislikes = 0;
  243. playlist.songs.forEach(function(song) {
  244. if (Session.get("currentSong") && song.mid === Session.get("currentSong").mid) {
  245. dislikes = song.dislikes;
  246. return;
  247. }
  248. });
  249. return dislikes;
  250. },
  251. liked: function() {
  252. if (Meteor.userId()) {
  253. var currentSong = Session.get("currentSong");
  254. if (currentSong && Meteor.user().profile.liked.indexOf(currentSong.mid) !== -1) {
  255. return "active";
  256. } else {
  257. return "";
  258. }
  259. } else {
  260. "";
  261. }
  262. },
  263. disliked: function() {
  264. if (Meteor.userId()) {
  265. var currentSong = Session.get("currentSong");
  266. if (currentSong && Meteor.user().profile.disliked.indexOf(currentSong.mid) !== -1) {
  267. return "active";
  268. } else {
  269. return "";
  270. }
  271. } else {
  272. "";
  273. }
  274. },
  275. type: function() {
  276. var parts = location.href.split('/');
  277. var id = parts.pop().toLowerCase();
  278. return Rooms.findOne({type: id}).display;
  279. },
  280. users: function() {
  281. var parts = location.href.split('/');
  282. var id = parts.pop().toLowerCase();
  283. return Rooms.findOne({type: id}).users;
  284. },
  285. title: function(){
  286. return Session.get("title");
  287. },
  288. artist: function(){
  289. return Session.get("artist");
  290. },
  291. loaded: function() {
  292. return Session.get("loaded");
  293. },
  294. paused: function() {
  295. return Session.get("state") === "paused";
  296. },
  297. private: function() {
  298. return Rooms.findOne({type: Session.get("type")}).private === true;
  299. },
  300. report: function() {
  301. return Session.get("reportObj");
  302. },
  303. reportSong: function() {
  304. return Session.get("reportSong");
  305. },
  306. reportTitle: function() {
  307. return Session.get("reportTitle");
  308. },
  309. reportAuthor: function() {
  310. return Session.get("reportAuthor");
  311. },
  312. reportDuration: function() {
  313. return Session.get("reportDuration");
  314. },
  315. reportAudio: function() {
  316. return Session.get("reportAudio");
  317. },
  318. reportAlbumart: function() {
  319. return Session.get("reportAlbumart");
  320. },
  321. reportOther: function() {
  322. return Session.get("reportOther");
  323. },
  324. currentSong: function() {
  325. return Session.get("currentSong");
  326. },
  327. previousSong: function() {
  328. return Session.get("previousSong");
  329. },
  330. currentSongR: function() {
  331. return Session.get("currentSongR");
  332. },
  333. previousSongR: function() {
  334. return Session.get("previousSongR");
  335. },
  336. reportingSong: function() {
  337. if (Session.get("reportPrevious")) {
  338. return Session.get("previousSongR");
  339. } else {
  340. return Session.get("currentSongR");
  341. }
  342. },
  343. votes: function(){
  344. return Rooms.findOne({type: Session.get("type")}).votes;
  345. }
  346. });
  347. Template.settings.helpers({
  348. username: function() {
  349. if (Meteor.user() !== undefined) {
  350. return Meteor.user().profile.username;
  351. } else {
  352. return "";
  353. }
  354. }
  355. });
  356. Template.stations.helpers({
  357. playlist: function() {
  358. var query = {type: Session.get("playlistToEdit").toLowerCase()};
  359. var playlists = Playlists.find(query).fetch();
  360. return playlists;
  361. },
  362. whichStation: function(){
  363. return Session.get("playlistToEdit");
  364. },
  365. reports: function() {
  366. var query = {room: Session.get("playlistToEdit").toLowerCase()};
  367. var reports = Reports.find(query).fetch();
  368. console.log(reports);
  369. return reports;
  370. }
  371. });