
function picture() {
  var controllerId = Session.get('controller_id');
  result = Picture.findOne({
    controller_id: controllerId
  });
  console.log("rez je", result);
  if (!result) {
    result = {}
  };
  return result;
};



Template.surveillance.helpers({
  controller_state: controller_state,
  picture_src: function() {
    var picture_base64 = picture().picture_base64;
    var picture_src = '/images/noImage.png';
    if (picture_base64) {
      picture_src = 'data:image/jpeg;charset=utf-8;base64,' + picture_base64;
    }
    return picture_src;
  },
  picture_time: function() {
    var picture_entry = picture();
    if (picture_entry) {
      return moment(picture_entry.time).fromNow();
    } else {
      return "Nikad!";
    }
  }
});

Template.surveillance.events({
  'click #request_new_picture': function() {
    var controller_id = Session.get('controller_id');
    Meteor.call('requestNewPicture', controller_id)
  }
});
