basicFoodEditor.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. /**
  2. * A pane that displays/edits basic food objects
  3. */
  4. (function() {
  5. (function() {
  6. try {return angular.module('ieat.ui.editors')}
  7. catch {return angular.module('ieat.ui.editors', ['ndbDatabase','Units'])}}
  8. )().component('basicFoodEditor', {
  9. templateUrl: 'static/templates/basicFoodEditor.html',
  10. bindings: {
  11. ndbKey: '@',
  12. food: '<'
  13. },
  14. controller: [
  15. '$scope', 'NDBList', 'Unit', function($scope, NDBList, Unit) {
  16. var self = this;
  17. $scope.units_symbol = {};
  18. Unit.primary(function(units) {
  19. units.forEach(function(elm) {
  20. $scope.units_symbol[elm.type] = elm.symbol;
  21. });
  22. });
  23. this.$onInit = function() {
  24. $scope.categories = NDBList.get({
  25. key: self.ndbKey,
  26. type: "g"
  27. });
  28. if (!self.food.unit_type) {
  29. self.food.unit_type = "Mass";
  30. self.food.dry = true;
  31. }
  32. };
  33. }]
  34. });
  35. })();