overview.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  1. 'use strict';
  2. /**
  3. * @ngdoc function
  4. * @name fehlerberichtApp.controller:AboutCtrl
  5. * @description
  6. * # AboutCtrl
  7. * Controller of the fehlerberichtApp
  8. */
  9. angular.module('fehlerberichtApp')
  10. .controller('OverviewCtrl', function ($scope, $http, $routeParams, $interval) {
  11. var webservice = 'http://rbs06/fehlerbericht/db.php?';
  12. $scope.error = {
  13. 'level': -1,
  14. 'info': [],
  15. 'message': ""
  16. };
  17. $scope.domain = {
  18. 'bearbeitet': {
  19. '0': "angesehen",
  20. '1': "behoben",
  21. '2': "zugeteilt",
  22. '3': "Rücksprache mit Kunde",
  23. '4': "Serverproblem",
  24. '5': "Prozess läuft",
  25. '6': "ignoriert / egal",
  26. '7': "weitergeleitet"
  27. },
  28. 'comment': {
  29. '0': "glyphicon-eye-open",
  30. '1': "glyphicon-ok",
  31. '2': "glyphicon-user",
  32. '3': "glyphicon-earphone",
  33. '4': "glyphicon-flash",
  34. '5': "glyphicon-refresh",
  35. '6': "glyphicon-remove",
  36. '7': "glyphicon-share-alt"
  37. },
  38. 'statusfilter': {
  39. '2': 'nicht behoben',
  40. '5': 'läuft',
  41. '6': 'ignoriert'
  42. },
  43. 'fehler': {
  44. '0': "okay",
  45. '1': "fehlerhaft"
  46. },
  47. 'system': [
  48. '?',
  49. 'Autosys',
  50. 'Autosys-Light',
  51. 'EDS',
  52. 'Filaks',
  53. 'GlobalCube',
  54. 'Light',
  55. 'Navision',
  56. 'Optima'
  57. ],
  58. 'datum': {},
  59. 'kunde': {},
  60. 'status': {
  61. 'errors': '1',
  62. 'all': '',
  63. 'missing': '',
  64. 'flawless': '0'
  65. },
  66. 'fehlend': {
  67. '1': 'fehlt',
  68. '0': 'vorhanden'
  69. },
  70. 'date': {
  71. 'all': '',
  72. 'today': moment().format('YYYY-MM-DD'),
  73. 'yesterday': moment().subtract(1, 'days').format('YYYY-MM-DD')
  74. },
  75. 'benutzer': []
  76. };
  77. $scope.benutzer = window.localStorage.getItem("Benutzer");
  78. $scope.benutzer2 = 'bitte auswählen';
  79. $scope.overview = [];
  80. $scope.comments = {};
  81. $scope.datum = [];
  82. $scope.current = {
  83. 'zeile' : {},
  84. 'fehler': {},
  85. 'details': null,
  86. 'status': 2,
  87. 'kommentar': {},
  88. 'fehlerdetails': null
  89. };
  90. $scope.Filter = {
  91. 'datum': (moment($routeParams.date, 'YYYY-MM-DD').isValid()) ? $routeParams.date : $scope.domain.date[$routeParams.date],
  92. 'kunde': ($routeParams.customer === 'all' || _.contains($scope.domain.system, $routeParams.customer)) ? '' : $routeParams.customer,
  93. 'fehler': $scope.domain.status[$routeParams.status],
  94. 'fehlend': ($routeParams.status === 'missing') ? '1' : '',
  95. 'system': (_.contains($scope.domain.system, $routeParams.customer)) ? $routeParams.customer : '',
  96. 'benutzer': ''
  97. };
  98. $scope.Predicate = (function () {
  99. if ($routeParams.customer !== 'all') {
  100. return 'datum';
  101. }
  102. if ($routeParams.date === 'today' && $routeParams.status === 'errors') {
  103. return 'ende_soll';
  104. }
  105. return ['kunde','datum'];
  106. })();
  107. $scope.Reverse = ($routeParams.customer !== 'all');
  108. $scope.SearchText = '';
  109. $scope.removeItem = function (index) {
  110. // Beispiel
  111. $scope.Bestellungen = $scope.Bestellungen.splice(index, 1);
  112. };
  113. $http.get(webservice + 'a=benutzer').success(function (data) {
  114. $scope.domain.benutzer = _.unique(_.pluck(data, 'benutzer'));
  115. });
  116. $http.get(webservice + 'a=kommentar&kunde=' + $scope.Filter.kunde + '&datum=' + $scope.Filter.datum).success(function (data) {
  117. $scope.comments = _.groupBy(data, 'kunde');
  118. });
  119. $scope.refresh = function () {
  120. $http.get(webservice + 'a=liste&kunde=' + $scope.Filter.kunde + '&datum=' + $scope.Filter.datum).success(function (data) {
  121. $scope.overview = data;
  122. //$scope.domain.benutzer = _.unique(_.pluck(data, 'benutzer'));
  123. });
  124. };
  125. $scope.importData = function () {
  126. $scope.error.level = 0;
  127. $scope.error.message = "Aktualisierung läuft!";
  128. $http.get('http://rbs06/GlobalCube/Fehlerbericht/app/import.php').success(function (data) {
  129. if (Array.isArray(data)) {
  130. $scope.error.info = data;
  131. if (data.length === 0) {
  132. $scope.error.level = 0;
  133. $scope.error.message = "Keine neuen Datensätze!";
  134. } else {
  135. $scope.error.message = "Neue Datensätze:";
  136. $scope.error.level = 0;
  137. $scope.refresh();
  138. }
  139. } else {
  140. $scope.error.info = [];
  141. $scope.error.level = 1;
  142. $scope.error.message = data;
  143. }
  144. });
  145. };
  146. $scope.refresh();
  147. $interval($scope.refresh, 5 * 60 * 1000);
  148. $scope.minuten = function (t) {
  149. var faktor, m, mins;
  150. if (!t) {
  151. return '';
  152. }
  153. faktor = 1;
  154. if (t < '00:00:00') {
  155. t = t.substring(1);
  156. faktor = -1;
  157. }
  158. m = moment(t, 'HH:mm:ss');
  159. mins = faktor * (m.minutes() + m.hours() * 60);
  160. return mins + " Min.";
  161. };
  162. $scope.timeDiffStart = function (z) {
  163. if (z.start === null) {
  164. return '';
  165. }
  166. var duration = moment.duration(z.start, 'HH:mm:ss').subtract(moment(z.start_soll, 'HH:mm:ss')).asMinutes();
  167. if (duration !== 0) {
  168. var plus = (duration > 0) ? '+' : '';
  169. return plus + duration + ' Minuten';
  170. }
  171. return '';
  172. };
  173. $scope.timeDiff = function (z) {
  174. if (z.start === null) {
  175. return '';
  176. }
  177. var duration = moment.duration(z.ende, 'HH:mm:ss').subtract(moment(z.ende_soll, 'HH:mm:ss')).asMinutes() - moment.duration(z.start, 'HH:mm:ss').subtract(moment(z.start_soll, 'HH:mm:ss')).asMinutes();
  178. if (duration !== 0) {
  179. var plus = (duration > 0) ? '+' : '';
  180. return '(' + plus + duration + ' Min.)';
  181. }
  182. return '';
  183. };
  184. $scope.dateFormat = function (date) {
  185. var d = moment(date, 'YYYY-MM-DD');
  186. if (d.isValid()) {
  187. if (date === $scope.domain.date.today) {
  188. return 'Heute';
  189. }
  190. if (date === $scope.domain.date.yesterday) {
  191. return 'Gestern';
  192. }
  193. return d.format('dd, DD.MM.YYYY');
  194. }
  195. return date;
  196. };
  197. $scope.dateTimeFormat = function (date) {
  198. var d = moment(date, 'YYYY-MM-DD HH:mm:ss');
  199. if (d.isValid()) {
  200. return d.format('DD.MM.YYYY, HH:mm');
  201. }
  202. return date;
  203. };
  204. $scope.timeFormat = function (t) {
  205. var d = moment(t, 'YYYY-MM-DD HH:mm:ss');
  206. if (d.isValid()) {
  207. return d.format('HH:mm:ss');
  208. }
  209. return t;
  210. };
  211. $scope.mailFormat = function (t) {
  212. if (t === undefined) {
  213. return '';
  214. }
  215. return _.map(t.split(';'), function (e) { return '<a href="mailto:' + e + '">' + e + '</a>'; }).join('<br/>');
  216. };
  217. $scope.left = function (text, length) {
  218. if (text.length === 0) {
  219. return '?';
  220. }
  221. return text.substring(0, length);
  222. };
  223. $scope.errorCount = function (e) {
  224. if (e === null) {
  225. return '0';
  226. }
  227. if (e.Errors.length === 0 || e.Errors.length === 1 && e.Errors[0] === '') {
  228. return $scope.daysCount(e);
  229. }
  230. var type = 'Info';
  231. if (e.ErrorLevel < 3) {
  232. type = 'Fehler';
  233. }
  234. return _.values(e.Errors).length + ' ' + type;
  235. };
  236. $scope.daysCount = function (e) {
  237. if (e.LastChangedDays === 0) {
  238. return '0';
  239. }
  240. return e.LastChangedDays + ' Tage alt';
  241. };
  242. $scope.errorLevel = function (e) {
  243. return e.ErrorLevel <= 2 || e.Name.indexOf('bat') > -1 || e.LastChangedDays >= 3;
  244. };
  245. $scope.setCurrent = function (row) {
  246. $scope.current.zeile = row;
  247. $scope.current.fehler = {};
  248. $scope.current.details = null;
  249. $scope.current.fehlerdetails = null;
  250. $scope.current.limit = 7;
  251. $scope.current.status = 2;
  252. $scope.current.kommentar = {};
  253. $scope.current.template = {
  254. 'id': '',
  255. 'datum': row.datum,
  256. 'kunde': row.kunde,
  257. 'start': row.start,
  258. 'benutzer': $scope.benutzer,
  259. 'fehler': (row.anzahl === null) ? 0 : parseInt(row.anzahl, 10),
  260. 'status': '0',
  261. 'kommentar': '',
  262. 'benutzer2': ''
  263. };
  264. $http.get(webservice + 'a=liste&kunde=' + $scope.current.zeile.kunde + '&datum=').success(function (data) {
  265. $scope.current.overview = data;
  266. });
  267. $http.get(webservice + 'a=fehlerbericht&kunde=' + $scope.current.zeile.kunde + '&datum=' + $scope.current.zeile.datum + '&start=' + $scope.current.zeile.start).success(function (data) {
  268. $scope.current.fehler = data;
  269. if (!data.whitelist) {
  270. data.whitelist = {
  271. 'User': [],
  272. 'Report': [],
  273. 'Layer': []
  274. };
  275. }
  276. if (data.benutzer === '' || data.benutzer !== $scope.benutzer) {
  277. $scope.current.kommentar = $scope.current.template;
  278. } else {
  279. $scope.current.kommentar = $scope.comments[data.kunde][0];
  280. $scope.current.kommentar.fehler = parseInt($scope.current.kommentar.fehler, 10);
  281. }
  282. data.fehlerbericht = _.sortBy(data.fehlerbericht, function(e) { return moment(e.Modified); });
  283. data.weitere = _.chain(data.fehlerbericht).reject($scope.errorLevel).groupBy(function (e) { return e.Type; }).value();
  284. var duration = _.map(_.filter(data.fehlerbericht, function (e) { return e.Summary !== null && e.Summary.Duration !== null && e.Summary.Duration >= '00:01:00'; }), function(e) { return { 'title': e.Type + ': ' + e.Name + ' (' + e.Summary.Duration + ')', 'value': Math.ceil(moment.duration(e.Summary.Duration, 'HH:mm:ss').asMinutes()) }; });
  285. var chart = AmCharts.makeChart( "durationChart", {
  286. "type": "pie",
  287. "theme": "light",
  288. "dataProvider": duration,
  289. "titleField": "title",
  290. "valueField": "value",
  291. "labelRadius": 5,
  292. "radius": "35%",
  293. "innerRadius": "40%",
  294. "labelText": "[[title]]",
  295. "export": {
  296. "enabled": false
  297. }
  298. } );
  299. });
  300. };
  301. $scope.getComments = function (zeile) {
  302. if ($scope.comments[zeile.kunde]) {
  303. var comments = _.filter($scope.comments[zeile.kunde], function (row) { return row.datum <= zeile.datum; });
  304. if (zeile.fehlend === '1') {
  305. return comments;
  306. }
  307. if (zeile.bearbeitet === '0') {
  308. var lastErrorComments = _.filter(comments, function (row) { return row.status > 0; });
  309. if (lastErrorComments.length > 0) {
  310. return lastErrorComments;
  311. }
  312. }
  313. var newComments = _.filter(comments, function (row) { return row.datum === zeile.datum; });
  314. if (newComments.length > 0) {
  315. return newComments;
  316. }
  317. }
  318. return false;
  319. };
  320. $scope.getCommentsInfo = function (kunde) {
  321. var comments = _.filter($scope.comments[kunde], function (row) { return row.status > 0; });
  322. var info = '<table class="table table-bordered table-condensed">';
  323. if (comments) {
  324. for (var i = 0; i < comments.length; i++) {
  325. info += '<tr><td>' + $scope.dateFormat(comments[i].datum) + '</td><td>' + comments[i].benutzer + '</td><td>' + $scope.domain.bearbeitet[comments[i].status] + '</td><td>' + comments[i].kommentar + '</td></tr>';
  326. }
  327. }
  328. return info + '</table>';
  329. };
  330. $scope.getCommentIcon = function (c) {
  331. var c0 = c;
  332. if (c.length > 0) {
  333. c0 = c[0];
  334. }
  335. if (c0.status) {
  336. return $scope.domain.comment[c0.status];
  337. }
  338. return "glyphicon-question-sign";
  339. };
  340. $scope.shortFilename = function(filename) {
  341. if (filename !== undefined && filename.length > 0 && filename.indexOf("\\") >= 0) {
  342. return filename.substring(filename.lastIndexOf("\\") + 1);
  343. }
  344. return filename;
  345. };
  346. $scope.showDetails = function (entry) {
  347. $scope.current.details = entry;
  348. var duration = _.map(_.filter(entry.Sources, function(e) { return e.Duration > '00:01:00'; }), function(e) { return { 'title': $scope.shortFilename(e.Filename) + ' (' + e.Duration + ')', 'value': Math.round(moment.duration(e.Duration, 'HH:mm:ss').asMinutes()) }; });
  349. var chart = AmCharts.makeChart( "durationDetailsChart", {
  350. "type": "pie",
  351. "theme": "light",
  352. "dataProvider": duration,
  353. "titleField": "title",
  354. "valueField": "value",
  355. "labelRadius": 5,
  356. "radius": "42%",
  357. "innerRadius": "50%",
  358. "labelText": "[[title]]",
  359. "export": {
  360. "enabled": false
  361. }
  362. } );
  363. };
  364. $scope.saveUser = function (name) {
  365. window.localStorage.setItem("Benutzer", name);
  366. $scope.benutzer = name;
  367. };
  368. $scope.saveComments = function () {
  369. $http.put(webservice + 'a=kommentar&id=' + $scope.current.kommentar.id, $scope.current.kommentar).success(function (data) {
  370. $scope.comments = _.groupBy(data, 'kunde');
  371. if ($scope.current.kommentar.id === '') {
  372. $scope.refresh();
  373. }
  374. });
  375. };
  376. $scope.saveStartTime = function (zeile) {
  377. $http.put(webservice + 'a=zeit&kunde=' + zeile.kunde + '&start_soll=' + zeile.start + '&ende_soll=' + zeile.ende_soll).success(function (data) {
  378. zeile.start_soll = zeile.start;
  379. });
  380. };
  381. $scope.saveEndTime = function (zeile) {
  382. $http.put(webservice + 'a=zeit&kunde=' + zeile.kunde + '&start_soll=' + zeile.start_soll + '&ende_soll=' + zeile.ende).success(function (data) {
  383. zeile.ende_soll = zeile.ende;
  384. });
  385. };
  386. $scope.statusFilter = function (row) {
  387. return (row.status >= $scope.current.status || row.datum === $scope.current.zeile.datum);
  388. };
  389. $scope.editComment = function (c) {
  390. c.fehler = parseInt(c.fehler, 10);
  391. $scope.current.kommentar = c;
  392. };
  393. $scope.whitelistToggle = function (key, value) {
  394. var flag = (!$scope.inWhitelist(key, value)) ? "J" : "N";
  395. $http.put(webservice + 'a=whitelist&kunde=' + $scope.current.zeile.kunde + '&typ=' + key + '&wert=' + value + "&aktiv=" + flag).success(function (data) {
  396. if (data.whitelist !== undefined) {
  397. $scope.current.fehler.whitelist = data.whitelist;
  398. }
  399. });
  400. };
  401. $scope.inWhitelist = function (key, value) {
  402. return $scope.current.fehler.whitelist[key] !== undefined && _.contains($scope.current.fehler.whitelist[key], value);
  403. };
  404. });