'use strict'; angular.module('fehlerberichtApp') .controller('ConfigCtrl', function ($scope, $http, $routeParams) { var webservice = 'http://rbs06/fehlerbericht/db.php?'; $scope.current = { 'kunde': $routeParams.customer, 'datum': $routeParams.date }; $scope.data = {}; $scope.domain = {}; $scope.filter = {}; $scope.options = { 'kunde': [], 'datum': {} }; $scope.dateFormat = function (date) { var d = moment(date, 'YYYY-MM-DD'); if (d.isValid()) { return d.format('dd, DD.MM.YYYY'); } return date; }; $scope.refresh = function () { $scope.data = {}; $http.get(webservice + 'a=config&kunde=' + $scope.current.kunde + '&datum=' + $scope.current.datum).success(function (data) { $scope.options.datum = data.options; $scope.options.datum[undefined] = []; $scope.options.kunde = _.keys(data.options); if (data.current) { $scope.current.datum = data.current.datum; $scope.options.tabelle = _.keys(data.current.info); $scope.current.tabelle = _.first($scope.options.tabelle); $scope.data = data.current.info; _.each($scope.data, function (table, t) { $scope.domain[t] = {}; $scope.filter[t] = {}; _.each(table[0], function (col, k) { $scope.domain[t][k] = _.uniq(_.pluck(table, k)); $scope.filter[t][k] = ''; }); }); } $scope.options.datum[undefined] = []; }); }; $scope.refresh(); });