{"size": 3458, "ext": "js", "max_stars_repo_path": "app/page/page.js", "max_stars_repo_name": "tiger-am/test-menu", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "app/page/page.js", "max_issues_repo_name": "tiger-am/test-menu", "max_issues_repo_issues_event_min_datetime": "2020-06-18T15:33:15.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-02T08:45:56.000Z", "max_forks_repo_path": "app/page/page.js", "max_forks_repo_name": "tiger-am/test-menu", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 4, "max_forks_count": null, "avg_line_length": 31.4363636364, "max_line_length": 105, "alphanum_fraction": 0.3872180451}
(function () {
    'use strict';

    angular.module('app.page', ['ngRoute'])
        .config(['$routeProvider', function ($routeProvider) {
            $routeProvider.when('/page', {
                templateUrl: 'page/page.html',
                controller: 'PageCtrl',
            });
        }])
        .controller('PageCtrl', ['$uibModal', '$scope', 'dataService', 'localStorageService', menuCtrl]);

    function menuCtrl($uibModal, $scope, dataService, localStorageService) {
        $scope.cols = ['title', 'image', 'rating', 'price'];
        $scope.params = localStorageService.getMenuData();
        $scope.isDesc = false;
        $scope.loading = true;
        $scope.orderProp = 'none';
        $scope.isActiveFilters = false;

        dataService.getMenu().then(function (data) {
            $scope.menu = data;
            $scope.loading = false;
        });

        $scope.orderCol = function (prop) {
            if ($scope.orderProp === prop) {
                $scope.isDesc = !$scope.isDesc;
            } else {
                $scope.isDesc = false;
            }

            $scope.orderProp = prop;

            $scope.updateStorage();
        };

        $scope.openModal = function (id) {
            $uibModal
                .open({
                    component: "myModal",
                    resolve: {
                        modalData: function () {
                            var idx = $scope.menu.findIndex(function (item) {
                                return item.id === id;
                            });

                            return $scope.menu[idx];
                        }
                    }
                }).result.then(function () {
                }, function () {
                }
            );
        };

        $scope.updateStorage = function () {
            $scope.isActiveFilters =
                !!$scope.query.$ ||
                !!$scope.query.title ||
                !!$scope.query.image ||
                !!$scope.query.rating ||
                !!$scope.query.price;

            $scope.params = {
                isDesc: $scope.isDesc,
                orderProp: $scope.orderProp,
                query: $scope.query
            };
            localStorageService.setMenuData($scope.params);
        };

        $scope.resetFilter = function () {
            $scope.query = {
                $: '',
                title: '',
                image: '',
                rating: '',
                price: ''
            };
            $scope.updateStorage();
        };

        return {
            $onInit: function () {
                if (!$scope.params) {
                    $scope.query = {
                        $: '',
                        title: '',
                        image: '',
                        rating: '',
                        price: ''
                    };
                    $scope.updateStorage();
                } else {
                    $scope.isDesc = $scope.params.isDesc;
                    $scope.orderProp = $scope.params.orderProp;
                    $scope.query = $scope.params.query;
                    $scope.isActiveFilters =
                        !!$scope.query.$ ||
                        !!$scope.query.title ||
                        !!$scope.query.image ||
                        !!$scope.query.rating ||
                        !!$scope.query.price;
                }
            }
        };
    }
})();
