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