SelectMenuPageController.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. app.controller('SelectMenuPageController',['$scope','$firebaseObject','$timeout',function($scope,$firebaseObject,$timeout){
  2. var ref = firebase.database().ref().child('meals');
  3. // var fireObj = $firebaseObject(ref);keys[i]
  4. // var mealItems = fireObj.first;
  5. // fireObj.$loaded().then(function(result){
  6. // console.log(result.first);
  7. // })
  8. $scope.mealType = 'breakfast';
  9. $scope.meals = [];
  10. $scope.selectMeal = function(i){
  11. var keys = Object.keys($scope.meals);
  12. $scope.meals[keys[i]].isSelected = true;
  13. ref.child(keys[i]).set($scope.meals[keys[i]]);
  14. //console.log($scope.meals[keys[i]])
  15. }
  16. ref.on('value', snap => {
  17. // var databaseT0ests = [];
  18. // var retrievedObject = snap.val();
  19. // if(retrievedObject){
  20. // var keys = Object.keys(retrievedObject);
  21. // for (var i = 0; i < keys.length; i++) {
  22. // databaseTests[i] = retrievedObject[keys[i]];
  23. // }
  24. // }
  25. $timeout(function(){
  26. $scope.meals = snap.val();
  27. })
  28. })
  29. $scope.openSelectedMeals = function(){
  30. var selectedMeals = angular.element(document.querySelector('.selected-meals'));
  31. var appRoot = angular.element(document.querySelector('.app-root'));
  32. var overlay2 = angular.element(document.querySelector('.overlay2'));
  33. // selectedMeals.css({'transform': 'translateX(0)'})
  34. appRoot.css({'transform': 'translateX(-281px)'});
  35. overlay2.css({'pointer-events': 'auto','opacity':'1'});
  36. overlay2.on('click',function(){
  37. overlay2.css({'pointer-events': 'none','opacity':'0'});
  38. appRoot.css({'transform': 'translateX(0px)'});
  39. })
  40. }
  41. // Andrii code start
  42. $scope.deleteMeal = function(i){
  43. var keys = Object.keys($scope.meals);
  44. $scope.meals[keys[i]].isSelected = false;
  45. ref.child(keys[i]).set($scope.meals[keys[i]]);
  46. }
  47. /*
  48. // Нужно написать функцию которая будет обнолять все isSelected на false при запуске приложения
  49. $scope.reloadItems = function(){
  50. var keys = Object.keys($scope.meals);
  51. for(var i =0; i<$scope.meals.length; i++) {
  52. $scope.meals[keys[i]].isSelected = false;
  53. ref.child(keys[i]).set($scope.meals[keys[i]]);
  54. }
  55. }
  56. */
  57. // Andrii code end
  58. }])