Tracker.autorun(function() {
  var id = Session.get('controller_id');
  if (id) {
    Meteor.subscribe("sensor_data", id);
    Meteor.subscribe("controller_state", id);
    Meteor.subscribe('pictures', id);
  }
});

function safeRoute(route) {
  return function () {
    var controllerId  = this.params.query.controller_id;

    if(controllerId) {
      Session.setPersistent('controller_id', controllerId);
      Session.setPersistent('hide_controller_selection', true);
    } else {
      Session.setPersistent('hide_controller_selection', false);
    }
    console.log('go ', route);
    if (Meteor.zoblak.client.accessible(route)) {
      Session.set('templateName', route);
    } else {
      Session.set('templateName', 'no_access')
    }
  }
}


Router.route('/', safeRoute('start'));
Router.route('/alarm', safeRoute('alarm'));
Router.route('/log', safeRoute('log'));
Router.route('/surveillance', safeRoute('surveillance'));
Router.route('/weather', safeRoute('weather'));
