overview.js 19 KB

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