javascript - Is it Possible/Okay to have two controller files for one view in meteor? -
so heres folder structure client: https://s3.amazonaws.com/f.cl.ly/items/0i0s063e3u0a2o2s3k21/image%202014-12-05%20at%206.42.17%20pm.png
the problem have 2 states tournaments... 1 live , 1 nolive. use exact same views ect potentially have different functionality.
is there trick can use 2 different controllers same view based on data view needs load in iron router or something?
-thanks
for reference here my:
routes.js tourneys:
/* tournaments / browse section */ router.route('/tournaments/:_id', function () { this.fastrender = true; // add subscription handle our waitlist this.wait(meteor.subscribe('campaigns')); // this.ready() true if items in wait list ready // console.log("tournaments.findone({_id: this.params._id}:", campaigns.findone({_id: this.params._id})); if (this.ready()) { this.render('tournament', { data: function () { return campaigns.findone({_id: this.params._id}); } }); } else { this.render('loading'); } });
tournaments.js:
/* globals */ template.tournament.rendered = function () { var self = this; var participants = $('.participant-id'); var currentparticipant; var nextround; var thismatch; var nextmatch; var bracket; participants.map(function(index, value){ if ($(value).text() === meteor.userid()) { if ($(value).parent().find('.participant-status').text() === 'undetermined') { nextround = $(value).parent().find('.participant-round').text(); thismatch = $(value).parent().find('.participant-match').text(); bracket = $(value).parent().parent().parent().find('.participant'); }; }; }); nextround = parseint(nextround) + 1; nextmatch = math.round(parseint(thismatch)/2) - 1; if (parseint(thismatch) % 2 != 0) { currentparticipant = 0; }else{ currentparticipant = 1; } var winneroptions = ''; var winnerbox = $('<div class="select-winner">'); bracket.map(function(index, value) { winneroptions += '<span class="winner-option"> '+$(value).find('.participant-title').text()+' <div class="winner-info"> '+$(value).find('a').html()+' </div> </span>' }); winnerbox.append(winneroptions); $($($('.round'+nextround).find('li')[nextmatch]).find('.participant')[currentparticipant]).removeclass('loser').addclass('undetermined'); $($($('.round'+nextround).find('li')[nextmatch]).find('.participant')[currentparticipant]).find('a').addclass('tooltip').html(winnerbox); var tournamentstarttime = function(){ var d = new date(); var n = d.gettime(); var currenttime = timesync.servertime(n); var starttime = self.data.card.starttime; var difference = starttime - currenttime; var hoursdifference = math.floor(difference/1000/60/60); difference -= hoursdifference*1000*60*60 var minutesdifference = math.floor(difference/1000/60); difference -= minutesdifference*1000*60 var secondsdifference = math.floor(difference/1000); /* if ends (make tournament live server side?) */ if (hoursdifference < 0 || minutesdifference < 0 || secondsdifference < 0) { meteor.clearinterval(tstarttime); session.set("tournamentstarttime", false); }else{ if (hoursdifference < 10) {hoursdifference = "0"+hoursdifference;} if (minutesdifference < 10) {minutesdifference = "0"+minutesdifference;} if (secondsdifference < 10) {secondsdifference = "0"+secondsdifference;} var formattedtime = hoursdifference + ':' + minutesdifference + ':' + secondsdifference; session.set("tournamentstarttime", formattedtime); } }; session.set("tournamentstarttime", '00:00:00'); tournamentstarttime(); var tstarttime = meteor.setinterval(tournamentstarttime, 1000); }; template.tournament.events({ // select winner 2 options in tooltip // previous round given winner class on correct person 'click .winner-option': function(event){ // var self = $(event.target) // var winner = self.text() // self.parent().hide() // self.closest('.participant').removeclass('undetermined') // self.parent().siblings('.participant-title').text(winner) // var classes = self.closest('ul').prev().attr('class') // $('.' + classes.substring(0, classes.indexof(' ')) + ' .participant-title').each(function() { // if ($(this).text() === winner) { // $(this).parent().parent().removeclass('loser').addclass('winner') // } // // else { // // $(this).parent().parent().removeclass('winner').addclass('loser') // // } // }); // // $(.previousulclass . $('#theatermode').show(); } }); template.tournament.helpers({ round: function() { var tournament = this.tournament.brackets; var rounds = tournament.length; var results = []; tournament.map(function(value, index){ var currentround = index + 1; results.push({rounds: rounds, currentround: currentround, matches: value}); }); // console.log("results:", results); return results; }, match: function(){ // console.log("matches:", this.matches); return this.matches; }, participant: function(){ var results = []; // console.log("this:", this); this.map(function (value, index) { // console.log("value, index:", value, index); var type = value['win']; var obj = { id: value['id'], rank: value['id'].slice(0,3), displayname: value['displayname'], thisround: value['round'], thismatch: value['match'], status: type }; if (type === true || type === 'undetermined') { obj.winner = true; }else{ obj.loser = true; } results.push(obj); }); // console.log("results:", results); return results; }, tournamentstarttime: function(){ return session.get('tournamentstarttime'); } });
how recognize state current? should post code, routes.js
, tournament.js
, view.blade
, better understanding wanna , figure out, best pratice is. :)
Comments
Post a Comment