overview.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  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 = '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. 'errors': '1',
  83. 'all': '',
  84. 'missing': '',
  85. 'flawless': '0'
  86. },
  87. 'fehlend': {
  88. '1': 'fehlt',
  89. '0': 'vorhanden'
  90. },
  91. 'date': {
  92. 'all': moment().subtract(32, 'days').format('YYYY-MM-DD'),
  93. 'today': moment().format('YYYY-MM-DD'),
  94. 'yesterday': moment().subtract(1, 'days').format('YYYY-MM-DD')
  95. },
  96. 'benutzer': []
  97. };
  98. $scope.benutzer = window.localStorage.getItem("Benutzer");
  99. $scope.benutzer2 = 'bitte auswählen';
  100. $scope.overview = [];
  101. $scope.comments = {};
  102. $scope.comments2 = {};
  103. $scope.datum = [];
  104. $scope.current = {
  105. 'zeile' : {},
  106. 'fehler': {},
  107. 'details': null,
  108. 'status': 2,
  109. 'kommentar': {},
  110. 'fehlerdetails': null
  111. };
  112. $scope.Filter = {
  113. 'kunde': ($routeParams.customer === 'all' || _.contains($scope.domain.system, $routeParams.customer)) ? '' : $routeParams.customer,
  114. 'fehler': $scope.domain.status[$routeParams.status],
  115. 'fehlend': ($routeParams.status === 'missing') ? '1' : '',
  116. 'system': (_.contains($scope.domain.system, $routeParams.customer)) ? $routeParams.customer : '',
  117. 'benutzer': ''
  118. };
  119. $scope.DatumFilter = {
  120. 'von': (moment($routeParams.date, 'YYYY-MM-DD').isValid()) ? $routeParams.date : $scope.domain.date[$routeParams.date],
  121. 'bis': moment().format('YYYY-MM-DD'),
  122. 'datum': function (z) {
  123. return z.datum >= $scope.DatumFilter.von && z.datum <= $scope.DatumFilter.bis;
  124. }
  125. };
  126. $scope.Predicate = (function () {
  127. if ($routeParams.customer !== 'all') {
  128. return 'datum';
  129. }
  130. if ($routeParams.date === 'today' && $routeParams.status === 'errors') {
  131. return 'ende_soll';
  132. }
  133. return ['kunde','datum'];
  134. })();
  135. $scope.Reverse = ($routeParams.customer !== 'all');
  136. $scope.SearchText = '';
  137. $scope.removeItem = function (index) {
  138. // Beispiel
  139. $scope.Bestellungen = $scope.Bestellungen.splice(index, 1);
  140. };
  141. $http.get(webservice + 'a=benutzer').success(function (data) {
  142. $scope.domain.benutzer = _.unique(_.pluck(data, 'benutzer'));
  143. });
  144. $http.get(webservice + 'a=kommentar&kunde=' + $scope.Filter.kunde + '&datum=' + $scope.DatumFilter.von + '&datum_bis=' + $scope.DatumFilter.bis).success(function (data) {
  145. $scope.comments = _.groupBy(data, 'kunde');
  146. $scope.comments2 = _.indexBy(data, 'id');
  147. });
  148. $scope.refresh = function () {
  149. $http.get(webservice + 'a=liste&kunde=' + $scope.Filter.kunde + '&datum=' + $scope.DatumFilter.von + '&datum_bis=' + $scope.DatumFilter.bis).success(function (data) {
  150. if (JSON.stringify($scope.overview) !== JSON.stringify(data)) {
  151. $scope.overview = data;
  152. }
  153. //$scope.domain.benutzer = _.unique(_.pluck(data, 'benutzer'));
  154. });
  155. };
  156. $scope.importData = function () {
  157. $scope.error.level = 0;
  158. $scope.error.message = "Aktualisierung läuft!";
  159. $http.get('http://rbs06/GlobalCube/Fehlerbericht/app/import.php').success(function (data) {
  160. if (Array.isArray(data)) {
  161. $scope.error.info = data;
  162. if (data.length === 0) {
  163. $scope.error.level = 0;
  164. $scope.error.message = "Keine neuen Datensätze!";
  165. } else {
  166. $scope.error.message = "Neue Datensätze:";
  167. $scope.error.level = 0;
  168. $scope.refresh();
  169. }
  170. } else {
  171. $scope.error.info = [];
  172. $scope.error.level = 1;
  173. $scope.error.message = data;
  174. }
  175. });
  176. };
  177. $scope.refresh();
  178. var refreshTimer = $interval($scope.refresh, PERIOD_VISIBLE);
  179. if (document.addEventListener) {
  180. document.addEventListener("visibilitychange", visibilityChanged);
  181. }
  182. function visibilityChanged() {
  183. $interval.cancel(refreshTimer);
  184. if (document.visible) {
  185. $scope.refresh();
  186. }
  187. refreshTimer = $interval($scope.refresh, (document.hidden) ? PERIOD_NOT_VISIBLE : PERIOD_VISIBLE);
  188. }
  189. $scope.minuten = function (t) {
  190. var faktor, m, mins;
  191. if (!t) {
  192. return '';
  193. }
  194. faktor = 1;
  195. if (t < '00:00:00') {
  196. t = t.substring(1);
  197. faktor = -1;
  198. }
  199. m = moment(t, 'HH:mm:ss');
  200. mins = faktor * (m.minutes() + m.hours() * 60);
  201. return mins + " Min.";
  202. };
  203. $scope.timeDiffStart = function (z) {
  204. if (z.start === null) {
  205. return '';
  206. }
  207. var duration = 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 + ' Minuten';
  211. }
  212. return '';
  213. };
  214. $scope.timeDiff = function (z) {
  215. if (z.start === null) {
  216. return '';
  217. }
  218. 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();
  219. if (duration !== 0) {
  220. var plus = (duration > 0) ? '+' : '';
  221. return '(' + plus + duration + ' Min.)';
  222. }
  223. return '';
  224. };
  225. $scope.dateFormat = function (date) {
  226. var d = moment(date, 'YYYY-MM-DD');
  227. if (d.isValid()) {
  228. if (date === $scope.domain.date.today) {
  229. return 'Heute';
  230. }
  231. if (date === $scope.domain.date.yesterday) {
  232. return 'Gestern';
  233. }
  234. return d.format('dd, DD.MM.YYYY');
  235. }
  236. return date;
  237. };
  238. $scope.dateTimeFormat = function (date) {
  239. var d = moment(date, 'YYYY-MM-DD HH:mm:ss');
  240. if (d.isValid()) {
  241. return d.format('DD.MM.YYYY, HH:mm');
  242. }
  243. return date;
  244. };
  245. $scope.timeFormat = function (t) {
  246. var d = moment(t, 'YYYY-MM-DD HH:mm:ss');
  247. if (d.isValid()) {
  248. return d.format('HH:mm:ss');
  249. }
  250. return t;
  251. };
  252. $scope.mailFormat = function (t) {
  253. if (t === undefined) {
  254. return '';
  255. }
  256. return _.map(t.split(';'), function (e) { return '<a href="mailto:' + e + '">' + e + '</a>'; }).join('<br/>');
  257. };
  258. $scope.left = function (text, length) {
  259. if (text.length === 0) {
  260. return '?';
  261. }
  262. return text.substring(0, length);
  263. };
  264. $scope.errorCount = function (e) {
  265. if (e === null) {
  266. return '0';
  267. }
  268. if (e.Errors.length === 0 || e.Errors.length === 1 && e.Errors[0] === '') {
  269. return $scope.daysCount(e);
  270. }
  271. var type = 'Info';
  272. if (e.ErrorLevel < 3) {
  273. type = 'Fehler';
  274. }
  275. return _.values(e.Errors).length + ' ' + type;
  276. };
  277. $scope.daysCount = function (e) {
  278. if (e.LastChangedDays === 0) {
  279. return '0';
  280. }
  281. return e.LastChangedDays + ' Tage alt';
  282. };
  283. $scope.errorLevel = function (e) {
  284. return e.ErrorLevel <= 2 || e.Name.indexOf('bat') > -1 || e.LastChangedDays >= 3;
  285. };
  286. $scope.setCurrent = function (row) {
  287. $scope.current.zeile = row;
  288. $scope.current.fehler = {};
  289. $scope.current.details = null;
  290. $scope.current.fehlerdetails = null;
  291. $scope.current.limit = 7;
  292. $scope.current.status = 2;
  293. $scope.current.kommentar = {};
  294. $scope.current.template = {
  295. 'id': '',
  296. 'datum': row.datum,
  297. 'kunde': row.kunde,
  298. 'start': row.start,
  299. 'benutzer': $scope.benutzer,
  300. 'fehler': (row.anzahl === null) ? 0 : parseInt(row.anzahl, 10),
  301. 'status': '0',
  302. 'kommentar': '',
  303. 'benutzer2': ''
  304. };
  305. $http.get(webservice + 'a=liste&kunde=' + $scope.current.zeile.kunde + '&datum=').success(function (data) {
  306. $scope.current.overview = data;
  307. });
  308. $http.get(webservice + 'a=fehlerbericht&kunde=' + $scope.current.zeile.kunde + '&datum=' + $scope.current.zeile.datum + '&start=' + $scope.current.zeile.start).success(function (data) {
  309. $scope.current.fehler = data;
  310. if (data.whitelist === undefined || data.whitelist === null) {
  311. data.whitelist = {
  312. 'User': [],
  313. 'Report': [],
  314. 'Layer': []
  315. };
  316. }
  317. if (data.kommentar.id !== undefined) {
  318. $scope.current.kommentar = data.kommentar;
  319. $scope.current.kommentar.fehler = parseInt(data.kommentar.fehler, 10);
  320. } else {
  321. $scope.current.kommentar = $scope.current.template;
  322. }
  323. if (data.fehlerbericht === undefined) {
  324. return;
  325. }
  326. data.fehlerbericht = _.sortBy(data.fehlerbericht, function(e) { return moment(e.Modified); });
  327. data.weitere = _.chain(data.fehlerbericht).reject($scope.errorLevel).groupBy(function (e) { return e.Type; }).value();
  328. 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()) }; });
  329. var chart = AmCharts.makeChart( "durationChart", {
  330. "type": "pie",
  331. "theme": "light",
  332. "dataProvider": duration,
  333. "titleField": "title",
  334. "valueField": "value",
  335. "labelRadius": 5,
  336. "radius": "35%",
  337. "innerRadius": "40%",
  338. "labelText": "[[title]]",
  339. "export": {
  340. "enabled": false
  341. }
  342. } );
  343. });
  344. };
  345. $scope.getComments = function (zeile, today) {
  346. if ($scope.comments[zeile.kunde]) {
  347. var comments = _.filter($scope.comments[zeile.kunde], function (row) { return (today === '1') ? row.datum === zeile.datum : row.datum <= zeile.datum; });
  348. if (zeile.fehlend === '1') {
  349. return comments;
  350. }
  351. if (zeile.bearbeitet === '0') {
  352. var lastErrorComments = _.filter(comments, function (row) { return row.status > 0; });
  353. if (lastErrorComments.length > 0) {
  354. return lastErrorComments;
  355. }
  356. }
  357. var newComments = _.filter(comments, function (row) { return row.datum === zeile.datum; });
  358. if (newComments.length > 0) {
  359. return newComments;
  360. }
  361. }
  362. return false;
  363. };
  364. $scope.getCommentsInfo = function (comment_id) {
  365. if ($scope.comments2[comment_id] !== undefined) {
  366. var c = $scope.comments2[comment_id];
  367. return '<i>' + $scope.domain.bearbeitet[c.status] + '</i><br/>' + c.kommentar;
  368. }
  369. return 'blubb';
  370. };
  371. $scope.getCommentIcon = function (c) {
  372. var c0 = c;
  373. if (c.length > 0) {
  374. c0 = c[0];
  375. }
  376. if (c0.status) {
  377. return $scope.domain.comment[c0.status];
  378. }
  379. return "glyphicon-question-sign";
  380. };
  381. $scope.shortFilename = function(filename) {
  382. if (filename !== undefined && filename.length > 0 && filename.indexOf("\\") >= 0) {
  383. return filename.substring(filename.lastIndexOf("\\") + 1);
  384. }
  385. return filename;
  386. };
  387. $scope.showDetails = function (entry) {
  388. $scope.current.details = entry;
  389. 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()) }; });
  390. var chart = AmCharts.makeChart( "durationDetailsChart", {
  391. "type": "pie",
  392. "theme": "light",
  393. "dataProvider": duration,
  394. "titleField": "title",
  395. "valueField": "value",
  396. "labelRadius": 5,
  397. "radius": "42%",
  398. "innerRadius": "50%",
  399. "labelText": "[[title]]",
  400. "export": {
  401. "enabled": false
  402. }
  403. } );
  404. };
  405. $scope.saveUser = function (name) {
  406. window.localStorage.setItem("Benutzer", name);
  407. $scope.benutzer = name;
  408. };
  409. $scope.saveComments = function () {
  410. $http.put(webservice + 'a=kommentar&id=' + $scope.current.kommentar.id, $scope.current.kommentar).success(function (data) {
  411. $scope.comments = _.groupBy(data, 'kunde');
  412. if ($scope.current.kommentar.id === '') {
  413. $scope.refresh();
  414. }
  415. });
  416. };
  417. $scope.saveStartTime = function (zeile) {
  418. $http.put(webservice + 'a=zeit&kunde=' + zeile.kunde + '&start_soll=' + zeile.start + '&ende_soll=' + zeile.ende_soll).success(function (data) {
  419. zeile.start_soll = zeile.start;
  420. });
  421. };
  422. $scope.saveEndTime = function (zeile) {
  423. $http.put(webservice + 'a=zeit&kunde=' + zeile.kunde + '&start_soll=' + zeile.start_soll + '&ende_soll=' + zeile.ende).success(function (data) {
  424. zeile.ende_soll = zeile.ende;
  425. });
  426. };
  427. $scope.statusFilter = function (row) {
  428. return (row.status >= $scope.current.status || row.datum === $scope.current.zeile.datum);
  429. };
  430. $scope.editComment = function (c) {
  431. c.fehler = parseInt(c.fehler, 10);
  432. $scope.current.kommentar = c;
  433. };
  434. $scope.whitelistToggle = function (key, value) {
  435. var flag = (!$scope.inWhitelist(key, value)) ? "J" : "N";
  436. $http.put(webservice + 'a=whitelist&kunde=' + $scope.current.zeile.kunde + '&typ=' + key + '&wert=' + value + "&aktiv=" + flag).success(function (data) {
  437. if (data.whitelist !== undefined) {
  438. $scope.current.fehler.whitelist = data.whitelist;
  439. }
  440. });
  441. };
  442. $scope.inWhitelist = function (key, value) {
  443. return $scope.current.fehler.whitelist[key] !== undefined && _.contains($scope.current.fehler.whitelist[key], value);
  444. };
  445. });