overview.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  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, $timeout) {
  11. var webservice = 'db.php?';
  12. var PERIOD_VISIBLE = 60 * 1000;
  13. var PERIOD_NOT_VISIBLE = 5 * 60 * 1000;
  14. $scope.error = {
  15. 'level': -1,
  16. 'info': [],
  17. 'message': ""
  18. };
  19. $scope.domain = {
  20. 'bearbeitet': {
  21. '0': "angesehen",
  22. '1': "behoben",
  23. '2': "zugeteilt",
  24. '3': "Rücksprache mit Kunde",
  25. '4': "Serverproblem",
  26. '5': "Prozess läuft",
  27. '6': "ignoriert / egal",
  28. '7': "weitergeleitet"
  29. },
  30. 'comment': {
  31. '0': "glyphicon-eye-open",
  32. '1': "glyphicon-ok",
  33. '2': "glyphicon-user",
  34. '3': "glyphicon-earphone",
  35. '4': "glyphicon-flash",
  36. '5': "glyphicon-refresh",
  37. '6': "glyphicon-remove",
  38. '7': "glyphicon-share-alt"
  39. },
  40. 'statusfilter': {
  41. '2': 'nicht behoben',
  42. '5': 'läuft',
  43. '6': 'ignoriert'
  44. },
  45. 'fehler': {
  46. '0': "okay",
  47. '1': "fehlerhaft"
  48. },
  49. 'system': [
  50. '?',
  51. 'Autosys',
  52. 'Autosys-Light',
  53. 'CarIT-Audev',
  54. 'EDS',
  55. 'Filaks',
  56. 'GlobalCube',
  57. 'Locosoft',
  58. 'Navision',
  59. 'Optima',
  60. 'Optima-Light'
  61. ],
  62. 'datum': {},
  63. 'kunde': {},
  64. 'status': [
  65. 'fehlerhaft',
  66. 'fehlend',
  67. 'verspaetet',
  68. 'anstehend',
  69. 'manuell',
  70. 'bearbeitet',
  71. 'fehlerfrei',
  72. 'undefiniert'
  73. ],
  74. 'statusinfo': {
  75. 'fehlerhaft': 'glyphicon-exclamation-sign',
  76. 'fehlend': 'glyphicon-question-sign',
  77. 'verspaetet': 'glyphicon-time',
  78. 'anstehend': 'glyphicon-retweet',
  79. 'manuell': 'glyphicon-wrench',
  80. 'bearbeitet': 'glyphicon-ok',
  81. 'fehlerfrei': 'glyphicon-eye-close',
  82. 'fehlerfrei-bearbeitet': 'glyphicon-check',
  83. 'undefiniert': ''
  84. },
  85. 'fehlend': {
  86. '1': 'fehlt',
  87. '0': 'vorhanden'
  88. },
  89. 'date': {
  90. 'all': moment().subtract(32, 'days').format('YYYY-MM-DD'),
  91. 'today': moment().format('YYYY-MM-DD'),
  92. 'yesterday': moment().subtract(1, 'days').format('YYYY-MM-DD')
  93. },
  94. 'benutzer': []
  95. };
  96. $scope.benutzer = window.localStorage.getItem("Benutzer");
  97. $scope.benutzer2 = 'bitte auswählen';
  98. $scope.overview = {
  99. 'all': [],
  100. 'hash': "",
  101. 'status': [],
  102. 'system': []
  103. };
  104. $scope.comments = {};
  105. $scope.comments2 = {};
  106. $scope.datum = [];
  107. $scope.current = {
  108. 'zeile' : {},
  109. 'fehler': {},
  110. 'details': null,
  111. 'status': 2,
  112. 'kommentar': {},
  113. 'fehlerdetails': null
  114. };
  115. $scope.Filter = {
  116. 'kunde': ($routeParams.customer === 'all' || _.contains($scope.domain.system, $routeParams.customer)) ? '' : $routeParams.customer,
  117. 'system': (_.contains($scope.domain.system, $routeParams.customer)) ? $routeParams.customer : '',
  118. 'benutzer': '',
  119. 'status': ''
  120. };
  121. $scope.getFilter = function () {
  122. return true;
  123. }
  124. $scope.DatumFilter = {
  125. 'von': (moment($routeParams.date, 'YYYY-MM-DD').isValid()) ? $routeParams.date : $scope.domain.date[$routeParams.date],
  126. 'bis': moment().format('YYYY-MM-DD'),
  127. 'datum': function (z) {
  128. return z.datum >= $scope.DatumFilter.von && z.datum <= $scope.DatumFilter.bis;
  129. }
  130. };
  131. $scope.Predicate = (function () {
  132. if ($routeParams.customer !== 'all') {
  133. return 'datum';
  134. }
  135. if ($routeParams.date === 'today' && $routeParams.status === 'errors') {
  136. return 'ende_soll';
  137. }
  138. return ['kunde','datum'];
  139. })();
  140. $scope.Reverse = ($routeParams.customer !== 'all');
  141. $scope.SearchText = '';
  142. $scope.removeItem = function (index) {
  143. // Beispiel
  144. $scope.Bestellungen = $scope.Bestellungen.splice(index, 1);
  145. };
  146. $http.get(webservice + 'a=benutzer').success(function (data) {
  147. $scope.domain.benutzer = _.unique(_.pluck(data.result, 'benutzer'));
  148. });
  149. $http.get(webservice + 'a=kommentar&kunde=' + $scope.Filter.kunde + '&datum=' + $scope.DatumFilter.von + '&datum_bis=' + $scope.DatumFilter.bis).success(function (data) {
  150. $scope.comments = _.groupBy(data.result, 'kunde');
  151. $scope.comments2 = _.indexBy(data.result, 'id');
  152. });
  153. $scope.refresh = function () {
  154. $http.get(webservice + 'a=liste&datum=' + $scope.DatumFilter.von).success(function (data) {
  155. if ($scope.overview.hash !== data.hash) {
  156. $('.loading').show();
  157. $scope.overview.all = data.result;
  158. $scope.overview.hash = data.hash;
  159. $scope.overview.status = _.groupBy(data.result, function (row) { return row[0].status; });
  160. $scope.overview.system = _.groupBy(data.result, function (row) { return row[0].system; });
  161. $timeout(function () { $('.loading').hide(); }, 500);
  162. }
  163. //$scope.domain.benutzer = _.unique(_.pluck(data, 'benutzer'));
  164. });
  165. };
  166. $scope.refresh();
  167. var refreshTimer = $interval($scope.refresh, PERIOD_VISIBLE);
  168. if (document.addEventListener) {
  169. document.addEventListener("visibilitychange", visibilityChanged);
  170. }
  171. function visibilityChanged() {
  172. $interval.cancel(refreshTimer);
  173. if (document.visible) {
  174. $scope.refresh();
  175. }
  176. refreshTimer = $interval($scope.refresh, (document.hidden) ? PERIOD_NOT_VISIBLE : PERIOD_VISIBLE);
  177. }
  178. $scope.minuten = function (t) {
  179. var faktor, m, mins;
  180. if (!t) {
  181. return '';
  182. }
  183. faktor = 1;
  184. if (t < '00:00:00') {
  185. t = t.substring(1);
  186. faktor = -1;
  187. }
  188. m = moment(t, 'HH:mm:ss');
  189. mins = faktor * (m.minutes() + m.hours() * 60);
  190. return mins + " Min.";
  191. };
  192. $scope.timeDiffStart = function (z) {
  193. if (z.start === null) {
  194. return '';
  195. }
  196. var duration = moment.duration(z.start, 'HH:mm:ss').subtract(moment(z.start_soll, 'HH:mm:ss')).asMinutes();
  197. if (duration !== 0) {
  198. var plus = (duration > 0) ? '+' : '';
  199. return plus + duration + ' Minuten';
  200. }
  201. return '';
  202. };
  203. $scope.timeDiff = function (z) {
  204. if (z.start === null) {
  205. return '';
  206. }
  207. 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();
  208. if (duration !== 0) {
  209. var plus = (duration > 0) ? '+' : '';
  210. return '(' + plus + duration + ' Min.)';
  211. }
  212. return '';
  213. };
  214. $scope.dateFormat = function (date) {
  215. var d = moment(date, 'YYYY-MM-DD');
  216. if (d.isValid()) {
  217. if (date === $scope.domain.date.today) {
  218. return 'Heute';
  219. }
  220. if (date === $scope.domain.date.yesterday) {
  221. return 'Gestern';
  222. }
  223. return d.format('dd, DD.MM.YYYY');
  224. }
  225. return date;
  226. };
  227. $scope.dateTimeFormat = function (date) {
  228. var d = moment(date, 'YYYY-MM-DD HH:mm:ss');
  229. if (d.isValid()) {
  230. return d.format('DD.MM.YYYY, HH:mm');
  231. }
  232. return date;
  233. };
  234. $scope.timeFormat = function (t) {
  235. var d = moment(t, 'YYYY-MM-DD HH:mm:ss');
  236. if (d.isValid()) {
  237. return d.format('HH:mm:ss');
  238. }
  239. return t;
  240. };
  241. $scope.timeFormat2 = function (t) {
  242. if (t === null) {
  243. return '';
  244. }
  245. return t.substring(0, 5) + ' Uhr';
  246. };
  247. $scope.mailFormat = function (t) {
  248. if (t === undefined) {
  249. return '';
  250. }
  251. return _.map(t.split(';'), function (e) { return '<a href="mailto:' + e + '">' + e + '</a>'; }).join('<br/>');
  252. };
  253. $scope.left = function (text, length) {
  254. if (text.length === 0) {
  255. return '?';
  256. }
  257. return text.substring(0, length);
  258. };
  259. $scope.errorCount = function (e) {
  260. if (e === null) {
  261. return '0';
  262. }
  263. if (e.Errors.length === 0 || e.Errors.length === 1 && e.Errors[0] === '') {
  264. return $scope.daysCount(e);
  265. }
  266. var type = 'Info';
  267. if (e.ErrorLevel < 3) {
  268. type = 'Fehler';
  269. }
  270. return _.values(e.Errors).length + ' ' + type;
  271. };
  272. $scope.getCount = function (e) {
  273. if (e == null || e < 0) {
  274. return 'X';
  275. }
  276. return e;
  277. };
  278. $scope.getCount2 = function (e) {
  279. if (e == null || e < 0) {
  280. return 'X';
  281. }
  282. if (e > 9) {
  283. return '9';
  284. }
  285. if (e > 5) {
  286. return '5';
  287. }
  288. return e;
  289. };
  290. $scope.getStatusIcon = function (e) {
  291. return $scope.domain.statusinfo[e.status];
  292. };
  293. $scope.toggleErrorStatus = function (e) {
  294. $('.row-'+ e).toggle();
  295. };
  296. $scope.daysCount = function (e) {
  297. if (e.LastChangedDays === 0) {
  298. return '0';
  299. }
  300. return e.LastChangedDays + ' Tage alt';
  301. };
  302. $scope.errorLevel = function (e) {
  303. return e.ErrorLevel <= 2 || e.Name.indexOf('bat') > -1 || e.LastChangedDays >= 3;
  304. };
  305. $scope.setCurrent = function (row) {
  306. $scope.current.zeile = row;
  307. $scope.current.fehler = {};
  308. $scope.current.details = null;
  309. $scope.current.fehlerdetails = null;
  310. $scope.current.limit = 7;
  311. $scope.current.status = 2;
  312. $scope.current.kommentar = {};
  313. $scope.current.template = {
  314. 'id': '',
  315. 'datum': row.datum,
  316. 'kunde': row.kunde,
  317. 'start': row.start,
  318. 'benutzer': $scope.benutzer,
  319. 'fehler': (row.anzahl === null) ? 0 : parseInt(row.anzahl, 10),
  320. 'status': '0',
  321. 'kommentar': '',
  322. 'benutzer2': ''
  323. };
  324. $http.get(webservice + 'a=liste&kunde=' + $scope.current.zeile.kunde).success(function (data) {
  325. $scope.current.overview = data.result;
  326. });
  327. $http.get(webservice + 'a=fehlerbericht&kunde=' + $scope.current.zeile.kunde + '&datum=' + $scope.current.zeile.datum + '&start=' + $scope.current.zeile.start).success(function (d) {
  328. if (d.result === undefined) {
  329. console.log(d);
  330. return false;
  331. }
  332. var data = d.result;
  333. $scope.current.fehler = data;
  334. if (data.whitelist === undefined || data.whitelist === null) {
  335. data.whitelist = {
  336. 'User': [],
  337. 'Report': [],
  338. 'Layer': []
  339. };
  340. }
  341. if (data.kommentar !== undefined && data.kommentar.id !== undefined) {
  342. $scope.current.kommentar = data.kommentar;
  343. $scope.current.kommentar.fehler = parseInt(data.kommentar.fehler, 10);
  344. } else {
  345. $scope.current.kommentar = $scope.current.template;
  346. }
  347. if (data.fehlerbericht === undefined) {
  348. return;
  349. }
  350. data.fehlerbericht = _.sortBy(data.fehlerbericht, function(e) { return moment(e.Modified); });
  351. data.weitere = _.chain(data.fehlerbericht).reject($scope.errorLevel).groupBy(function (e) { return e.Type; }).value();
  352. 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()) }; });
  353. var chart = AmCharts.makeChart( "durationChart", {
  354. "type": "pie",
  355. "theme": "light",
  356. "dataProvider": duration,
  357. "titleField": "title",
  358. "valueField": "value",
  359. "labelRadius": 5,
  360. "radius": "35%",
  361. "innerRadius": "40%",
  362. "labelText": "[[title]]",
  363. "export": {
  364. "enabled": false
  365. }
  366. } );
  367. });
  368. };
  369. $scope.getComments = function (zeile, today) {
  370. if ($scope.comments[zeile.kunde]) {
  371. var comments = _.filter($scope.comments[zeile.kunde], function (row) { return (today === '1') ? row.datum === zeile.datum : row.datum <= zeile.datum; });
  372. if (zeile.fehlend === '1') {
  373. return comments;
  374. }
  375. if (zeile.bearbeitet === '0') {
  376. var lastErrorComments = _.filter(comments, function (row) { return row.status > 0; });
  377. if (lastErrorComments.length > 0) {
  378. return lastErrorComments;
  379. }
  380. }
  381. var newComments = _.filter(comments, function (row) { return row.datum === zeile.datum; });
  382. if (newComments.length > 0) {
  383. return newComments;
  384. }
  385. }
  386. return false;
  387. };
  388. $scope.getCommentsInfo = function (comment_id, kunde, datum) {
  389. if ($scope.comments2[comment_id] !== undefined) {
  390. var c = $scope.comments2[comment_id];
  391. return '<i>' + $scope.domain.bearbeitet[c.status] + '</i><br/>' + c.kommentar;
  392. }
  393. return '<b>' + $scope.dateFormat(datum) + '</b>: ' + comment_id;
  394. };
  395. $scope.getCommentIcon = function (c) {
  396. var c0 = c;
  397. if (c.length > 0) {
  398. c0 = c[0];
  399. }
  400. if (c0.status) {
  401. return $scope.domain.comment[c0.status];
  402. }
  403. return "glyphicon-question-sign";
  404. };
  405. $scope.shortFilename = function(filename) {
  406. if (filename !== undefined && filename.length > 0 && filename.indexOf("\\") >= 0) {
  407. return filename.substring(filename.lastIndexOf("\\") + 1);
  408. }
  409. return filename;
  410. };
  411. $scope.showDetails = function (entry) {
  412. $scope.current.details = entry;
  413. 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()) }; });
  414. var chart = AmCharts.makeChart( "durationDetailsChart", {
  415. "type": "pie",
  416. "theme": "light",
  417. "dataProvider": duration,
  418. "titleField": "title",
  419. "valueField": "value",
  420. "labelRadius": 5,
  421. "radius": "42%",
  422. "innerRadius": "50%",
  423. "labelText": "[[title]]",
  424. "export": {
  425. "enabled": false
  426. }
  427. } );
  428. };
  429. $scope.saveUser = function (name) {
  430. window.localStorage.setItem("Benutzer", name);
  431. $scope.benutzer = name;
  432. };
  433. $scope.saveComments = function () {
  434. $http.put(webservice + 'a=kommentar&id=' + $scope.current.kommentar.id, $scope.current.kommentar).success(function (data) {
  435. $scope.comments = _.groupBy(data.result, 'kunde');
  436. if ($scope.current.kommentar.id === '') {
  437. $scope.refresh();
  438. }
  439. });
  440. };
  441. $scope.saveStartTime = function (zeile) {
  442. $http.put(webservice + 'a=zeit&kunde=' + zeile.kunde + '&start_soll=' + zeile.start + '&ende_soll=' + zeile.ende_soll).success(function (data) {
  443. zeile.start_soll = zeile.start;
  444. });
  445. };
  446. $scope.saveEndTime = function (zeile) {
  447. $http.put(webservice + 'a=zeit&kunde=' + zeile.kunde + '&start_soll=' + zeile.start_soll + '&ende_soll=' + zeile.ende).success(function (data) {
  448. zeile.ende_soll = zeile.ende;
  449. });
  450. };
  451. $scope.statusFilter = function (row) {
  452. return (row.status >= $scope.current.status || row.datum === $scope.current.zeile.datum);
  453. };
  454. $scope.editComment = function (c) {
  455. c.fehler = parseInt(c.fehler, 10);
  456. $scope.current.kommentar = c;
  457. };
  458. $scope.whitelistToggle = function (key, value) {
  459. var flag = (!$scope.inWhitelist(key, value)) ? "J" : "N";
  460. $http.put(webservice + 'a=whitelist&kunde=' + $scope.current.zeile.kunde + '&typ=' + key + '&wert=' + value + "&aktiv=" + flag).success(function (data) {
  461. if (data.result.whitelist !== undefined) {
  462. $scope.current.fehler.whitelist = data.result.whitelist;
  463. }
  464. });
  465. };
  466. $scope.inWhitelist = function (key, value) {
  467. return $scope.current.fehler.whitelist[key] !== undefined && _.contains($scope.current.fehler.whitelist[key], value);
  468. };
  469. $('#datum .input-append.date').datepicker({
  470. language: "de"
  471. });
  472. });