<commit_before>import { Template } from 'meteor/templating';
import { UserData, developmentValidationEnabledFalse } from '/imports/api/indexDB.js';
import './mainLayout.html'
import './mainLayout.scss'

import swal from 'sweetalert';
import Cookies from 'js-cookie';
import validate from 'jquery-validation'

import '../../components/topNav/topNav'
import '../../components/sideNav/sideNav'

//writes to DB preferences on change and window close/log out
//doesn't run on unload as it should as websocket closes before method reaches server, is an issue in meteor
function saveSidebarPreference(){
  if (Meteor.userId() && (UserData.findOne(Meteor.userId()).screenSize? UserData.findOne(Meteor.userId()).screenSize: 3) != Session.get("openedSidebarPreference")){
    Meteor.call("sidebarPreference", Session.get('openedSidebarPreference'), Meteor.userId())
    Session.set("openedSidebarPreference", undefined) //don't remove this, explanation in init autorun
  }
}

//send preference data to server before closing window for it to decide weather to save it
Meteor.startup(function(){
  $(window).bind('beforeunload', function(){
    closingWindow()
  });
});

function closingWindow(){
  Meteor.call("sidebarPreference", Session.get("openedSidebarPreference"), UserData.findOne(Meteor.userId()).screenSize)
}

Template.mainLayout.events({
  'click #navbar-toggler': function (event) {
    event.preventDefault();
    Session.set("openedSidebar", !Session.get('openedSidebar')) 
    var screen = Session.get("screenSize") 
    //if is mobile then sidebar will just close constantly with no option to keep it open outside actual usage 
    if (screen == 0) { 
      return 
    } 
    var val = Session.get('openedSidebar') 
    var temp = Template.instance() 
    var user = temp.user.get()
    if (!user) { 
      return 
    } 
    var pref = Session.get("openedSidebarPreference")
    if (val == true) { 
      if (screen < pref) { 
        //adjust pref because user wants menu opened at screenSize smaller than current preference 
        Session.set('openedSidebarPreference', screen)
      } 
    } else { 
      if (screen > pref) { 
        //adjust pref because user wants menu closed at screenSize bigger than current preference 
        Session.set('openedSidebarPreference', 1+screen)
      } 
    } 
  },
  "click #hideDevelopmentNotification": (eve, templ) => {
      return Cookies.set('underDevelopmentShown', true, 5)
  },
  "click .registerEmail": (eve, templ) => {

      if ($("#registerEmailForm").valid()) {
          Meteor.call('registerForLaunch', $('#email').val(), (err, data) => {

              if (err) {
                  sAlert.error('Error', err)
              } else {

                  swal({
                      icon: "success",
                      text: 'Thanks for registering! We will drop you an email when we officially launch Block Razor',
                      button: { className: 'btn btn-primary' }
                  });
              }
          })
      }


  },
  'submit #subscribeForAlphaLaunch': (eve)=>{
    eve.preventDefault()
    Meteor.call("subscribeForAlphaLaunch", $(".js-mailSub").val(), (err,res)=>{
      if (res){
        Cookies.set('underDevelopmentShown', true, 5)
        $('.underDev').modal('hide');
        sAlert.success("Email added to the list of subsribers")
      } else {
        sAlert.error(err)
      }
    })
  }
})

Template.mainLayout.helpers({
  registerEmail(){
    console.log(Cookies.get('underDevelopmentShown'))
    return  Cookies.get('underDevelopmentShown');
  }
});

Template.mainLayout.onRendered(function(){
  //used to toggle under development toggle
      if (!developmentValidationEnabledFalse) {
        return 
      } else if (!Cookies.get('underDevelopmentShown')){
        $('.underDev').modal('show');
      }

          $( "form" ).validate(); 
})

Template.mainLayout.onCreated(function () {
  //is used to close sidebar on click outside sidebar
  var handlerForSidebar = function (event) {
    if (!$(event.target).closest('#topnav').length && !$(event.target).closest('#sidebar').length) {
      Session.set("openedSidebar", false)
    }
  }

  function setScreenSize() {
    var width = $(window).width()
    if (width < 577) {
      Session.set("screenSize", 0)
      $(document).bind("click", handlerForSidebar);<commit_msg>Problem: side navigation menu missing #1228<commit_after>import { Template } from 'meteor/templating';
import { UserData, developmentValidationEnabledFalse } from '/imports/api/indexDB.js';
import './mainLayout.html'
import './mainLayout.scss'

import swal from 'sweetalert';
import Cookies from 'js-cookie';
import validate from 'jquery-validation'

import '../../components/topNav/topNav'
import '../../components/sideNav/sideNav'

//writes to DB preferences on change and window close/log out
//doesn't run on unload as it should as websocket closes before method reaches server, is an issue in meteor
function saveSidebarPreference(){
  if (Meteor.userId() && (UserData.findOne(Meteor.userId()).screenSize? UserData.findOne(Meteor.userId()).screenSize: 3) != Session.get("openedSidebarPreference")){
    Meteor.call("sidebarPreference", Session.get('openedSidebarPreference'), Meteor.userId())
    Session.set("openedSidebarPreference", undefined) //don't remove this, explanation in init autorun
  }
}

//send preference data to server before closing window for it to decide weather to save it
Meteor.startup(function(){
  $(window).bind('beforeunload', function(){
    closingWindow()
  });
});

function closingWindow(){
  Meteor.call("sidebarPreference", Session.get("openedSidebarPreference"), UserData.findOne(Meteor.userId()).screenSize)
}

Template.mainLayout.events({
  'click #navbar-toggler': function (event) {
    event.preventDefault();
    Session.set("openedSidebar", !Session.get('openedSidebar')) 
    var screen = Session.get("screenSize") 
    //if is mobile then sidebar will just close constantly with no option to keep it open outside actual usage 
    if (screen == 0) { 
      return 
    } 
    var val = Session.get('openedSidebar') 
    var temp = Template.instance() 
    var user = temp.user.get()
    if (!user) { 
      return 
    } 
    var pref = Session.get("openedSidebarPreference")
    if (val == true) { 
      if (screen < pref) { 
        //adjust pref because user wants menu opened at screenSize smaller than current preference 
        Session.set('openedSidebarPreference', screen)
      } 
    } else { 
      if (screen > pref) { 
        //adjust pref because user wants menu closed at screenSize bigger than current preference 
        Session.set('openedSidebarPreference', 1+screen)
      } 
    } 
  },
  "click #hideDevelopmentNotification": (eve, templ) => {
      return Cookies.set('underDevelopmentShown', true, 5)
  },
  "click .registerEmail": (eve, templ) => {

      if ($("#registerEmailForm").valid()) {
          Meteor.call('registerForLaunch', $('#email').val(), (err, data) => {

              if (err) {
                  sAlert.error('Error', err)
              } else {

                  swal({
                      icon: "success",
                      text: 'Thanks for registering! We will drop you an email when we officially launch Block Razor',
                      button: { className: 'btn btn-primary' }
                  });
              }
          })
      }


  },
  'submit #subscribeForAlphaLaunch': (eve)=>{
    eve.preventDefault()
    Meteor.call("subscribeForAlphaLaunch", $(".js-mailSub").val(), (err,res)=>{
      if (res){
        Cookies.set('underDevelopmentShown', true, 5)
        $('.underDev').modal('hide');
        sAlert.success("Email added to the list of subsribers")
      } else {
        sAlert.error(err)
      }
    })
  }
})

Template.mainLayout.helpers({
  openSidebar() {
    return Session.get('openedSidebar') ? "active" : "";
  },
  registerEmail(){
    console.log(Cookies.get('underDevelopmentShown'))
    return  Cookies.get('underDevelopmentShown');
  }
});

Template.mainLayout.onRendered(function(){
  //used to toggle under development toggle
      if (!developmentValidationEnabledFalse) {
        return 
      } else if (!Cookies.get('underDevelopmentShown')){
        $('.underDev').modal('show');
      }

          $( "form" ).validate(); 
})

Template.mainLayout.onCreated(function () {
  //is used to close sidebar on click outside sidebar
  var handlerForSidebar = function (event) {
    if (!$(event.target).closest('#topnav').length && !$(event.target).closest('#sidebar').length) {
      Session.set("openedSidebar", false)
    }
  }

  function setScreenSize() {
    var width = $(window).width()
    if (width < 577) {
      Session.set("screenSize", 0)
      $(document).bind("click", handlerForSidebar);
{'fraction_non_alphanumeric': 0.1398179749715586, 'fraction_numerical': 0.002502844141069397, 'mean_word_length': 3.039981617647059, 'pattern_counts': {'":': 4, '<': 7, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3423007', 'n_tokens_mistral': 2630, 'n_tokens_neox': 2455, 'n_words': 632}