Advertisement
Guest User

Untitled

a guest
Jul 30th, 2017
382
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 71.43 KB | None | 0 0
  1. (function () {
  2.  
  3. 'use strict';
  4.  
  5. console.warn = function () {
  6. };
  7.  
  8. var isProductionApplication = true;
  9.  
  10. function config ( $httpProvider , $stateProvider , $urlRouterProvider , uiGmapGoogleMapApiProvider , $mdThemingProvider , $mdIconProvider , iconsUrls , $provide ) {
  11.  
  12. uiGmapGoogleMapApiProvider.configure ( {
  13. key : 'AIzaSyCsbEsgOYk2FhLgvVp_1Yct-kj5XOueaAE' ,
  14. v : '3.17' ,
  15. libraries : 'geometry,visualization,drawing'
  16. } );
  17. //=====================================================================
  18. //HTTP
  19. //=====================================================================
  20.  
  21. $httpProvider.defaults.withCredentials = true;
  22. $httpProvider.defaults.headers.common[ 'Content-Type' ] = "application/json;charset=utf-8";
  23.  
  24. // # reduce the number of $apply calls
  25.  
  26. $httpProvider.useApplyAsync ( true );
  27. $httpProvider.interceptors.push ( function ( $q , $log , $rootScope , $window ) {
  28. return {
  29. 'response' : function ( response ) {
  30. //detecting login page:
  31. if ( _.has ( response , 'data' ) && typeof response.data === 'string' ) {
  32. if ( response.data.indexOf ( '<!DOCTYPE html>' ) != -1 ) {
  33. //yeap, it's the login page
  34. $window.location = "/";
  35. }
  36. }
  37. return response;
  38. } ,
  39. 'responseError' : function ( rejection ) {
  40. $rootScope.$broadcast ( 'showAPICallError' , rejection );
  41. return $q.reject ( rejection );
  42. }
  43. };
  44. } );
  45.  
  46. $mdThemingProvider.theme ( 'default' ).primaryPalette ( 'light-blue' );
  47.  
  48. //register icons
  49. angular.forEach ( iconsUrls , function ( url ) {
  50. $mdIconProvider.icon ( url.alias , url.uri , 24 );
  51. } );
  52.  
  53. //=====================================================================
  54. // STATES
  55. //=====================================================================
  56. $urlRouterProvider
  57. .when ( '/' , '/main' )
  58. .otherwise ( '/' );
  59.  
  60.  
  61. $stateProvider
  62. .state ( "dashboard" , {
  63. url : "/" ,
  64. templateUrl : 'views/dashboard.html'
  65. } )
  66. .state ( "dashboard.main" , {
  67. url : "main" ,
  68. views : {
  69. '' : {
  70. templateUrl : 'views/main_dashboard.html' ,
  71. controller : "dashboardController"
  72. }
  73. }
  74. } )
  75. .state ( "dashboard.administrare" , {
  76. url : "admin" ,
  77. views : {
  78. '' : {
  79. templateUrl : 'views/admin_dashboard.html' ,
  80. controller : "adminDashboardController"
  81. }
  82. }
  83. } )
  84. .state ( 'lucrari' , {
  85. abstract : true ,
  86. url : '/lucrari' ,
  87. templateUrl : 'views/rapoarte/lucrari_main.html'
  88. } )
  89. .state ( 'lucrari.lista' , {
  90. url : '/lista' ,
  91. views : {
  92. '' : {
  93. templateUrl : 'views/rapoarte/rapoarte_lucrari.html' ,
  94. controller : 'rapoarteLucrariController'
  95. }
  96. }
  97. } )
  98. // .state('lucrari.rapoarte-ferme', {
  99. // url: '/rapoarte-ferme',
  100. // views: {
  101. // '': {
  102. // templateUrl: 'views/rapoarte/rapoarte_ferme.html',
  103. // controller: 'rapoarteFermeController'
  104. // }
  105. // }
  106. // })
  107. .state ( 'lucrari.toate' , {
  108. url : '/toate' ,
  109. views : {
  110. '' : {
  111. templateUrl : 'views/rapoarte/rapoarte_lucrari_all.html' ,
  112. controller : 'rapoarteLucrariToateController'
  113. }
  114. }
  115. } )
  116. .state ( 'lucrari.rapoarte' , {
  117. url : '/rapoarte' ,
  118. views : {
  119. '' : {
  120. templateUrl : 'views/rapoarte/rapoarte_sole.html' ,
  121. controller : "rapoartePeSoleController"
  122. }
  123. }
  124. } )
  125. .state ( 'lucrari.grafice' , {
  126. url : '/grafice' ,
  127. views : {
  128. '' : {
  129. templateUrl : 'views/rapoarte/rapoarte_grafice.html' ,
  130. controller : "rapoarteGraficeController"
  131. }
  132. }
  133. } )
  134. .state ( 'note' , {
  135. abstract : true ,
  136. url : '/note' ,
  137. templateUrl : 'views/note/note_main.html'
  138. } )
  139. .state ( 'note.lista' , {
  140. url : '/lista' ,
  141. views : {
  142. '' : {
  143. templateUrl : 'views/note/note_lista.html' ,
  144. controller : "listaNoteController"
  145. }
  146. }
  147. } )
  148. .state ( 'sole' , {
  149. abstract : true ,
  150. url : '/sole' ,
  151. templateUrl : 'views/sole/sole_main.html'
  152. } )
  153. .state ( 'sole.lista' , {
  154. url : '/lista' ,
  155. views : {
  156. '' : {
  157. templateUrl : 'views/sole/sole_lista.html' ,
  158. controller : "listaSoleController"
  159. }
  160. }
  161. } )
  162. .state ( 'nomenclator' , {
  163. abstract : true ,
  164. url : '/nomenclatoare' ,
  165. templateUrl : 'views/nomenclatoare/nomenclatoare_main.html'
  166. } )
  167. .state ( 'nomenclator.fertilizari' , {
  168. url : '/fertilizari' ,
  169. views : {
  170. '' : {
  171. templateUrl : 'views/nomenclatoare/fertilizari.html' ,
  172. controller : "nomenclatorFertilizariController"
  173. }
  174. }
  175. } )
  176. .state ( 'nomenclator.echipamente' , {
  177. url : '/echipamente' ,
  178. views : {
  179. '' : {
  180. templateUrl : 'views/nomenclatoare/echipamente.html' ,
  181. controller : "nomenclatorEchipamenteController"
  182. }
  183. }
  184. } )
  185. .state ( 'nomenclator.tratamente' , {
  186. url : '/tratamente' ,
  187. views : {
  188. '' : {
  189. templateUrl : 'views/nomenclatoare/tratamente.html' ,
  190. controller : "nomenclatorTratamenteController"
  191. }
  192. }
  193. } )
  194. .state ( 'nomenclator.culturi' , {
  195. url : '/culturi' ,
  196. views : {
  197. '' : {
  198. templateUrl : 'views/nomenclatoare/culturi.html' ,
  199. controller : "nomenclatorCulturiController"
  200. }
  201. }
  202. } )
  203. .state ( 'nomenclator.lucrari' , {
  204. url : '/lucrari' ,
  205. views : {
  206. '' : {
  207. templateUrl : 'views/unused/lucrari.html' ,
  208. controller : "nomenclatorLucrariController"
  209. }
  210. }
  211. } )
  212.  
  213. .state ( 'utilizatori' , {
  214. abstract : true ,
  215. url : '/utilizatori' ,
  216. templateUrl : 'views/utilizatori/utilizatori_main.html'
  217. } )
  218. .state ( 'utilizatori.lista' , {
  219. url : '/lista' ,
  220. views : {
  221. '' : {
  222. templateUrl : 'views/utilizatori/utilizatori_lista.html' ,
  223. controller : "listaUtilizatoriController"
  224. }
  225. }
  226. } )
  227.  
  228. .state ( 'ferme' , {
  229. abstract : true ,
  230. url : '/ferme' ,
  231. templateUrl : 'views/ferme/ferme_main.html'
  232. } )
  233. .state ( 'ferme.lista' , {
  234. url : '/lista' ,
  235. views : {
  236. '' : {
  237. templateUrl : 'views/ferme/ferme_lista.html' ,
  238. controller : "listaFermeController"
  239. }
  240. }
  241. } )
  242. .state ( 'companii' , {
  243. abstract : true ,
  244. url : '/companii' ,
  245. templateUrl : 'views/companii/companii_main.html'
  246. } )
  247. .state ( 'companii.lista' , {
  248. url : '/lista' ,
  249. views : {
  250. '' : {
  251. templateUrl : 'views/companii/companii_lista.html' ,
  252. controller : "listaCompaniiController"
  253. }
  254. }
  255. } );
  256.  
  257. // if(isProductionApplication) {
  258. // $provide.decorator("$exceptionHandler", ['$delegate', '$injector', function ($delegate, $injector) {
  259. // return function (exception, cause) {
  260. // var $rootScope = $injector.get('$rootScope');
  261. //
  262. // function removeAngularTrace(stack) {
  263. // var arr = stack.split('\n'),
  264. // index = arr.length;
  265. // while (index) {
  266. // index -= 1;
  267. // if (arr[index].toLowerCase().indexOf('angular') > -1) {
  268. // arr.splice(index, 1);
  269. // }
  270. // }
  271. // return arr.join("\n");
  272. // }
  273. //
  274. // var smallMessage = removeAngularTrace(exception.stack);
  275. // console.error(smallMessage, cause);
  276. // $rootScope.$broadcast('globalException', {
  277. // exception: smallMessage,
  278. // cause: cause
  279. // });
  280. // // (Optional) Pass the error through to the delegate
  281. // //$delegate(exception, cause);
  282. // }
  283. // }]);
  284. // }
  285.  
  286. //$provide.decorator('$state', function($delegate, $stateParams) {
  287. // $delegate.forceReload = function() {
  288. // return $delegate.go($delegate.current, $stateParams, {
  289. // reload: true,
  290. // inherit: false,
  291. // notify: true
  292. // });
  293. // };
  294. // return $delegate;
  295. //});
  296.  
  297. // # Force reload the page. Hopefully we won't get in an infinite loop. Decorated state provider in app.js,
  298.  
  299. }
  300.  
  301. config.$inject = [ '$httpProvider' , '$stateProvider' , '$urlRouterProvider' , 'uiGmapGoogleMapApiProvider' , '$mdThemingProvider' , '$mdIconProvider' , 'iconsUrls' , '$provide' ];
  302.  
  303. angular.module ( 'sefDeFermaApp' ,
  304. [
  305. 'ngCookies' ,
  306. 'ui.router' ,
  307. 'ngAnimate' ,
  308. 'ngMaterial' ,
  309. 'uiGmapgoogle-maps' ,
  310. 'angularLoad' ,
  311. 'mdTable' ,
  312. 'input-directives' ,
  313. 'ngFileUpload' ,
  314. 'dynamicForm' ,
  315. 'mdDatePicker' ,
  316. 'angularLocalStorage' ,
  317. 'mp.colorPicker' ,
  318. 'ngMessages'
  319. ] )
  320. .constant ( "REPORTS_URL" , isProductionApplication ? "http://clienti.sefdeferma.ro/api/public/" : "http://ferma.dev/api/public/" )
  321. .constant ( "APP_URL" , isProductionApplication ? "http://clienti.sefdeferma.ro/api/v1" : "http://ferma.dev/api/v1" )
  322. .constant ( "IS_PRODUCTION" , isProductionApplication )
  323. .constant ( "BUTTON" , 'BUTTON' )
  324. .constant ( "DAUNATORUL" , 'daunatorul' )
  325. .constant ( "DOZE_RECOMANDATE" , 'doze recomandate' )
  326. .constant ( "DOZA_UTILIZATA" , 'doza utilizata' )
  327. .constant ( "TRATAMENT" , 'tratament' )
  328. .constant ( "CULTURA" , 'cultura' )
  329. .constant ( "FERTILIZATOR" , 'fertil' )
  330. .constant ( "COST" , 'cost' )
  331. .constant ( "KG" , 'kilogr' )
  332. .constant ( "CANTITATE" , 'cantitate' )
  333. .constant ( "INTORS_CULTURA" , 'intors' )
  334. .constant ( "DENSITATE" , 'densitate' )
  335. .constant ( "SEMANAT" , 'semanat' )
  336. .constant ( "KM1" , 'pret pe kilometru' )
  337. .constant ( "KM2" , 'numar kilometri' )
  338. .constant ( 'COSTKG' , 'st kg' )
  339. .constant ( 'iconsUrls' ,
  340. [
  341. {
  342. uri : 'css/icons/album.svg' ,
  343. alias : 'album'
  344. } ,
  345. {
  346. uri : 'css/icons/import.svg' ,
  347. alias : 'import'
  348. } ,
  349. {
  350. uri : 'css/icons/arrow-up.svg' ,
  351. alias : 'arrow-up'
  352. } ,
  353. {
  354. uri : 'css/icons/arrow-down.svg' ,
  355. alias : 'arrow-down'
  356. } ,
  357. {
  358. uri : 'css/icons/alert.svg' ,
  359. alias : 'alert'
  360. } ,
  361. {
  362. uri : 'css/icons/account-key.svg' ,
  363. alias : 'account-key'
  364. } ,
  365. {
  366. uri : 'css/icons/plus.svg' ,
  367. alias : 'plus'
  368. } ,
  369. {
  370. uri : 'css/icons/bookmark-check.svg' ,
  371. alias : 'bookmark-check'
  372. } ,
  373. {
  374. uri : 'css/icons/folder-move.svg' ,
  375. alias : 'folder-move'
  376. } ,
  377. {
  378. uri : 'css/icons/menu.svg' ,
  379. alias : 'menu'
  380. } ,
  381. {
  382. uri : 'css/icons/view-carousel.svg' ,
  383. alias : 'view-carousel'
  384. } ,
  385. {
  386. uri : 'css/icons/logout.svg' ,
  387. alias : 'logout'
  388. } ,
  389. {
  390. uri : 'css/icons/library-plus.svg' ,
  391. alias : 'library-plus'
  392. } ,
  393. {
  394. uri : 'css/icons/dice-2.svg' ,
  395. alias : 'dice-2'
  396. } ,
  397. {
  398. uri : 'css/icons/magnify.svg' ,
  399. alias : 'magnify'
  400. } ,
  401. {
  402. uri : 'css/icons/chevron-left.svg' ,
  403. alias : 'chevron-left'
  404. } ,
  405. {
  406. uri : 'css/icons/chevron-right.svg' ,
  407. alias : 'chevron-right'
  408. } ,
  409. {
  410. uri : 'css/icons/chevron-up.svg' ,
  411. alias : 'chevron-up'
  412. } ,
  413. {
  414. uri : 'css/icons/chevron-down.svg' ,
  415. alias : 'chevron-down'
  416. } ,
  417. {
  418. uri : 'css/icons/close.svg' ,
  419. alias : 'close'
  420. } ,
  421. {
  422. uri : 'css/icons/alarm.svg' ,
  423. alias : 'alarm'
  424. } ,
  425. {
  426. uri : 'css/icons/alert.svg' ,
  427. alias : 'alert'
  428. } ,
  429. {
  430. uri : 'css/icons/account-check.svg' ,
  431. alias : 'account-check'
  432. } ,
  433. {
  434. uri : 'css/icons/account.svg' ,
  435. alias : 'account'
  436. } ,
  437. {
  438. uri : 'css/icons/account-remove.svg' ,
  439. alias : 'account-remove'
  440. } ,
  441. {
  442. uri : 'css/icons/account-key.svg' ,
  443. alias : 'account-key'
  444. } ,
  445. {
  446. uri : 'css/icons/check.svg' ,
  447. alias : 'check'
  448. } ,
  449. {
  450. uri : 'css/icons/check-all.svg' ,
  451. alias : 'check-all'
  452. } ,
  453. {
  454. uri : 'css/icons/cloud-check.svg' ,
  455. alias : 'cloud-check'
  456. } ,
  457. {
  458. uri : 'css/icons/delete.svg' ,
  459. alias : 'delete'
  460. } ,
  461. {
  462. uri : 'css/icons/settings.svg' ,
  463. alias : 'settings'
  464. } ,
  465. {
  466. uri : 'css/icons/database-outline.svg' ,
  467. alias : 'database-outline'
  468. } ,
  469. {
  470. uri : 'css/icons/calendar-multiple-check.svg' ,
  471. alias : 'calendar-multiple-check'
  472. } ,
  473. {
  474. uri : 'css/icons/pencil.svg' ,
  475. alias : 'pencil'
  476. } ,
  477. {
  478. uri : 'css/icons/home.svg' ,
  479. alias : 'home'
  480. } ,
  481. {
  482. uri : 'css/icons/arrow-collapse.svg' ,
  483. alias : 'arrow-collapse'
  484. } ,
  485. {
  486. uri : 'css/icons/arrow-expand.svg' ,
  487. alias : 'arrow-expand'
  488. } ,
  489. {
  490. uri : 'css/icons/watch-export.svg' ,
  491. alias : 'watch-export'
  492. } ,
  493. {
  494. uri : 'css/icons/wizard.svg' ,
  495. alias : 'wizard'
  496. } ,
  497. {
  498. uri : 'css/icons/android-studio.svg' ,
  499. alias : 'android-studio'
  500. } ,
  501. {
  502. uri : 'css/icons/fullscreen.svg' ,
  503. alias : 'fullscreen'
  504. } ,
  505. {
  506. uri : 'css/icons/fullscreen-exit.svg' ,
  507. alias : 'fullscreen-exit'
  508. } ,
  509. {
  510. uri : 'css/icons/people.svg' ,
  511. alias : 'people'
  512. } ,
  513. {
  514. uri : 'css/icons/money.svg' ,
  515. alias : 'money'
  516. } ,
  517. {
  518. uri : 'css/icons/calendar-plus.svg' ,
  519. alias : 'calendar-plus'
  520. } ,
  521. {
  522. uri : 'css/icons/information-outline.svg' ,
  523. alias : 'information-outline'
  524. } ,
  525. {
  526. uri : 'css/icons/ic_account_balance_wallet_black_24px.svg' ,
  527. alias : 'mdi-wallet-membership'
  528. } ,
  529. {
  530. uri : 'css/icons/ic_airline_seat_legroom_normal_black_24px.svg' ,
  531. alias : 'mdi-elevation-rise'
  532. } ,
  533. {
  534. uri : 'css/icons/ic_leak_add_black_24px.svg' ,
  535. alias : 'mdi-calendar-today'
  536. } ,
  537. {
  538. uri : 'css/icons/ic_chrome_reader_mode_black_24px.svg' ,
  539. alias : 'ic_chrome_reader_mode_black_24px'
  540. } ,
  541. {
  542. uri : 'css/icons/ic_build_black_24px.svg' ,
  543. alias : 'ic_build_black_24px'
  544. } ,
  545. {
  546. uri : 'css/icons/ic_invert_colors_black_24px.svg' ,
  547. alias : 'ic_invert_colors_black_24px'
  548. } ,
  549. {
  550. uri : 'css/icons/ic_rounded_corner_black_24px.svg' ,
  551. alias : 'ic_rounded_corner_black_24px'
  552. } ,
  553. {
  554. uri : 'css/icons/ic_perm_identity_black_24px.svg' ,
  555. alias : 'ic_perm_identity_black_24px'
  556. } ,
  557. {
  558. uri : 'css/icons/ic_language_black_24px.svg' ,
  559. alias : 'ic_language_black_24px'
  560. }
  561. ] )
  562. .factory ( 'SessionService' , function () {
  563. return {
  564. get : function ( key ) {
  565. return sessionStorage.getItem ( key );
  566. } ,
  567. set : function ( key , val ) {
  568. return sessionStorage.setItem ( key , val );
  569. } ,
  570. unset : function ( key ) {
  571. return sessionStorage.removeItem ( key );
  572. }
  573. }
  574. } )
  575. .config ( config )
  576. .run ( appStartUp );
  577.  
  578. function appStartUp ( $log , $rootScope , $window , $http , APP_URL , uiGmapGoogleMapApi , $mdToast , angularLoad , nomenclatoareService , $mdDialog , $mdSidenav , $state , storage , $location , iconsUrls , $templateCache ,
  579. BUTTON ,
  580. DAUNATORUL ,
  581. DOZE_RECOMANDATE ,
  582. DOZA_UTILIZATA ,
  583. TRATAMENT ,
  584. CULTURA ,
  585. FERTILIZATOR ,
  586. COST ,
  587. CANTITATE ,
  588. KG ,
  589. DENSITATE ,
  590. SEMANAT ,
  591. KM1 ,
  592. KM2 ,
  593. utilizatorService ) {
  594.  
  595. // # Listen for changes on the dashboard.administrare view changes. Use uiRoute's $state.reload() function to reinitialize the controller
  596. // # and bring it to a clean state.
  597. //$rootScope.$on('$stateChangeSuccess', function (e, to, toParams, from, fromParams) {
  598. // console.log('Logging from', from);
  599. // if (from.name === 'dashboard.administrare') {
  600. // console.info('Exiting `dashboard.administrare`. Controller has been reset.');
  601. // $state.reload();
  602. // }
  603. //});
  604.  
  605. var body = angular.element ( document ).find ( 'body' );
  606. body.css ( 'display' , 'flex' );
  607. angular.forEach ( iconsUrls , function ( url ) {
  608. $http.get ( url.uri , { cache : $templateCache } );
  609. } );
  610.  
  611. $rootScope.APP_URL = APP_URL;
  612. $rootScope.mainLoading = true;
  613. $rootScope.mainMenu = [];
  614. $rootScope.normalLeftMenuButtons = [
  615. {
  616. ariaLabel : "listă rapoarte" ,
  617. uiSRef : "lucrari.rapoarte" ,
  618. buttonLabel : "Rapoarte sole - lucrări" ,
  619. icon : 'mdi-wallet-membership'
  620. } ,
  621. // {
  622. // ariaLabel: "raport ferme",
  623. // uiSRef: "lucrari.rapoarte-ferme",
  624. // buttonLabel: "Rapoarte ferme - lucrări",
  625. // icon: 'mdi-wallet-membership'
  626. // },
  627. {
  628. ariaLabel : "lucrari lista" ,
  629. uiSRef : "lucrari.lista" ,
  630. buttonLabel : "Rapoarte tipuri lucrări" ,
  631. icon : "mdi-elevation-rise"
  632. } ,
  633. {
  634. ariaLabel : "raport grafic lucrari" ,
  635. uiSRef : "lucrari.grafice" ,
  636. buttonLabel : "Evolutie lucrari" ,
  637. icon : "mdi-elevation-rise" ,
  638. } ,
  639. {
  640. ariaLabel : "raport lista lucrari" ,
  641. uiSRef : "lucrari.toate" ,
  642. buttonLabel : "Lucrari An Curent" ,
  643. icon : "mdi-calendar-today" ,
  644. } ,
  645. ];
  646.  
  647. $rootScope.soleSelectate = storage.get ( 'listaSoleSelectate' ) !== undefined ? storage.get ( 'listaSoleSelectate' ) : [];
  648. if ( !angular.isArray ( $rootScope.soleSelectate ) ) {
  649. $rootScope.soleSelectate = [];
  650. }
  651.  
  652. $rootScope.adminLeftMenuButtons = [
  653. {
  654. ariaLabel : "nomenclator fertilizări" ,
  655. uiSRef : "nomenclator.fertilizari" ,
  656. buttonLabel : "Nomenclator fertilizări" ,
  657. icon : "ic_chrome_reader_mode_black_24px" ,
  658. } ,
  659. {
  660. ariaLabel : "nomenclator echipamente" ,
  661. uiSRef : "nomenclator.echipamente" ,
  662. buttonLabel : "Nomenclator echipamente" ,
  663. icon : "ic_build_black_24px" ,
  664. } ,
  665. {
  666. ariaLabel : "nomenclator tratamente" ,
  667. uiSRef : "nomenclator.tratamente" ,
  668. buttonLabel : "Nomenclator tratamente" ,
  669. icon : "ic_invert_colors_black_24px" ,
  670. } ,
  671. {
  672. ariaLabel : "nomenclator culturi" ,
  673. uiSRef : "nomenclator.culturi" ,
  674. buttonLabel : "Nomenclator culturi" ,
  675. icon : "ic_rounded_corner_black_24px" ,
  676. } ,
  677. {
  678. ariaLabel : "listă utilizatori" ,
  679. uiSRef : "utilizatori.lista" ,
  680. buttonLabel : "Listă utilizatori" ,
  681. icon : "ic_perm_identity_black_24px" ,
  682. } ,
  683. {
  684. ariaLabel : "listă ferme" ,
  685. uiSRef : "ferme.lista" ,
  686. buttonLabel : "Listă ferme" ,
  687. icon : "ic_language_black_24px" ,
  688. }
  689. ];
  690.  
  691. $rootScope.logout = function () {
  692. $http.post ( APP_URL + "/post/logout" ).then ( function () {
  693. $state.go ( 'dashboard.main' );
  694. storage.remove ( 'listaSoleSelectate' );
  695. delete $window.sessionStorage[ "userInfo" ];
  696. $rootScope.mainLoading = true;
  697. displayLoginDialog ();
  698. } );
  699. };
  700.  
  701. $rootScope.isInFullscreen = false;
  702.  
  703. function launchIntoFullscreen ( element ) {
  704. if ( element.requestFullscreen ) {
  705. element.requestFullscreen ();
  706. } else if ( element.mozRequestFullScreen ) {
  707. element.mozRequestFullScreen ();
  708. } else if ( element.webkitRequestFullscreen ) {
  709. element.webkitRequestFullscreen ();
  710. } else if ( element.msRequestFullscreen ) {
  711. element.msRequestFullscreen ();
  712. }
  713. }
  714.  
  715. var getFuelCost = $rootScope.getFuelCost = function () {
  716. return utilizatorService.fuelCostForCurrentUser ().then ( function ( res ) {
  717. $rootScope.pretCombustibil = Number ( res );
  718. // console.info('$rootScope.pretCombustibil', $rootScope.pretCombustibil);
  719. } , function ( err ) {
  720. console.error ( 'err in getFuelCost' , err );
  721. $rootScope.displayToast ( 'Eroare ! Nu am putut aduce costul combustibilului de la server ! Daca eroarea persista, va rugam contactati administratorul.' );
  722. } );
  723. };
  724.  
  725. function exitFullscreen () {
  726. if ( document.exitFullscreen ) {
  727. document.exitFullscreen ();
  728. } else if ( document.mozCancelFullScreen ) {
  729. document.mozCancelFullScreen ();
  730. } else if ( document.webkitExitFullscreen ) {
  731. document.webkitExitFullscreen ();
  732. }
  733. }
  734.  
  735. $rootScope.toggleFullscreen = function () {
  736. $rootScope.isInFullscreen = !$rootScope.isInFullscreen;
  737. if ( $rootScope.isInFullscreen ) {
  738. launchIntoFullscreen ( document.documentElement )
  739. } else {
  740. exitFullscreen ();
  741. }
  742. };
  743.  
  744. $rootScope.fullscreenEnabled = document.fullscreenEnabled || document.mozFullScreenEnabled || document.webkitFullscreenEnabled;
  745.  
  746. if ( $rootScope.fullscreenEnabled ) {
  747. //console.log('can use fullscreen');
  748. } else {
  749. console.error ( 'can NOT use fullscreen' );
  750. }
  751.  
  752. $rootScope.toggleMenu = function () {
  753. $mdSidenav ( "left" ).toggle ();
  754. };
  755.  
  756. $rootScope.toggleSettings = function () {
  757. //console.log('TODO : implement user profile');
  758. };
  759.  
  760. $rootScope.isAdmin = function () {
  761. if ( !$rootScope.loggedInUser ) return false;
  762. return $rootScope.loggedInUser.rol === 1;
  763. };
  764.  
  765.  
  766. $rootScope.isUser = function () {
  767. if ( !$rootScope.loggedInUser ) return false;
  768. return $rootScope.loggedInUser.rol === 2;
  769. };
  770. //console.log('$rootScope.loggedInUser', $rootScope.isUser());
  771.  
  772. var changeMenuForAdmin = function () {
  773. if ( $rootScope.isAdmin () ) {
  774. //bottom to top
  775. $rootScope.adminLeftMenuButtons.reverse ();
  776. //inapoi la operare
  777. //$rootScope.adminLeftMenuButtons.pop();
  778. //administrare sole
  779. //$rootScope.adminLeftMenuButtons.pop();
  780. $rootScope.adminLeftMenuButtons.push ( {
  781. ariaLabel : "listă companii" ,
  782. uiSRef : "companii.lista" ,
  783. buttonLabel : "Listă companii"
  784. } );
  785. //top to bottom
  786. $rootScope.adminLeftMenuButtons.reverse ();
  787. $rootScope.mainMenu = $rootScope.adminLeftMenuButtons;
  788. }
  789. };
  790.  
  791. var displayLoginDialog = function () {
  792. $rootScope.inLoginMode = true;
  793. $rootScope.loginError = false;
  794. var dialogScope = $rootScope.$new ();
  795. dialogScope.user = { username : '' , password : '' };
  796.  
  797. dialogScope.submitLogin = function ( ev , user ) {
  798. dialogScope.isWaitingForLogin = true;
  799. $http.post ( APP_URL + "/post/login" , { username : user.username , password : user.password } ).then (
  800. function ( data , status , headers , config ) {
  801. $rootScope.getFuelCost ();
  802. dialogScope.isWaitingForLogin = false;
  803. $rootScope.inLoginMode = false;
  804. $rootScope.loggedInUser = data.data;
  805. changeMenuForAdmin ();
  806. $window.sessionStorage.setItem ( "userInfo" , JSON.stringify ( $rootScope.loggedInUser ) );
  807. aquireInitialData ();
  808. $mdDialog.cancel ();
  809. $rootScope.loginError = true;
  810.  
  811. $location.url ( '/' );
  812. // location.reload();
  813. } , function ( error ) {
  814. dialogScope.isWaitingForLogin = false;
  815. $rootScope.loginError = true;
  816. } );
  817. };
  818. $mdDialog.show ( {
  819. controller : function () {
  820. } ,
  821. templateUrl : 'login.html' ,
  822. scope : dialogScope ,
  823. onComplete : afterShowLoginAnimation
  824. } );
  825. };
  826.  
  827. var afterShowLoginAnimation = function ( scope , element , options ) {
  828. element.find ( 'input' )[ 0 ].focus ();
  829. };
  830.  
  831. $rootScope.proceseazaSola = function ( sola ) {
  832. var polygonCoords = [];
  833. sola.coordonate = JSON.parse ( sola.coordonate.coordonate );
  834. sola.coordonate.forEach ( function ( coord ) {
  835. var coordLatLng = new $rootScope.mapsReference.LatLng ( coord.lat , coord.lng );
  836. polygonCoords.push ( coordLatLng );
  837. $rootScope.mapBounds.extend ( coordLatLng );
  838. } );
  839. if ( !sola.culoare ) {
  840. console.error ( 'Sola #' + sola.id + " nu are culoare!!! Folosim ALB" );
  841. sola.culoare = '#FFFFFF';
  842. }
  843. if ( sola.culoare && sola.culoare.indexOf ( '#' ) < 0 ) {
  844. sola.culoare = '#' + sola.culoare;
  845. }
  846. var aPolygon = new $rootScope.mapsReference.Polygon ( {
  847. path : polygonCoords ,
  848. geodesic : true ,
  849. strokeColor : '#FFFFFF' ,
  850. strokeOpacity : 1.0 ,
  851. strokeWeight : 1 ,
  852. clickable : true ,
  853. fillColor : sola.culoare
  854. } );
  855. aPolygon.solaId = sola.id;
  856. $rootScope.poligoane.push ( aPolygon );
  857. };
  858.  
  859. $rootScope.proceseazaSole = function ( raspunsServer ) {
  860. var testHash = [];
  861. if ( raspunsServer && raspunsServer.length > 0 ) {
  862. raspunsServer.forEach ( function ( sola ) {
  863. if ( testHash[ sola.parcela_nr + "_" + sola.bloc_nr ] ) {
  864. //console.error(sola.id + " -> parcela:" + sola.parcela_nr + " bloc:" + sola.bloc_nr + " exista (" + sola.suprafata + " ha)!");
  865. } else {
  866. testHash[ sola.parcela_nr + "_" + sola.bloc_nr ] = true;
  867. }
  868. if ( sola.coordonate ) {
  869. $rootScope.proceseazaSola ( sola );
  870. $rootScope.hashRelations[ sola.id ] = sola;
  871. } else {
  872. console.error ( 'Sola #' + sola.id + " nu are coordonate!" );
  873. }
  874. if ( sola.subsole ) {
  875. angular.forEach ( sola.subsole , function ( s ) {
  876. s.depth = 1;
  877. $rootScope.proceseazaSola ( s );
  878. $rootScope.hashRelations[ s.id ] = s;
  879. } )
  880. }
  881. } );
  882. } else {
  883. console.error ( 'Nu avem sole!' , raspunsServer );
  884. raspunsServer = [];
  885. }
  886. return raspunsServer;
  887. };
  888.  
  889. /** selectie / deselectie nomenclatoare generale din tabel **/
  890.  
  891. $rootScope.toggleAll = function ( flag , data ) {
  892. data.forEach ( function ( tratament ) {
  893. tratament.selected = flag;
  894. } );
  895. };
  896.  
  897. $rootScope.toastIfEmpty = function () {
  898. if ( $rootScope.echipamente.length === 0 ) {
  899. $rootScope.displayToast ( 'Vă rugăm definiți echipamente în nomenclatorul dvs!' , 'error' , parent );
  900. return true;
  901. }
  902. if ( $rootScope.culturi.length === 0 ) {
  903. $rootScope.displayToast ( 'Vă rugăm definiți culturi în nomenclatorul dvs!' , 'error' , parent );
  904. return true;
  905. }
  906. if ( $rootScope.fertilizari.length === 0 ) {
  907. $rootScope.displayToast ( 'Vă rugăm definiți fertilizari în nomenclatorul dvs!' , 'error' , parent );
  908. return true;
  909. }
  910. };
  911.  
  912. var callInitialAquisition = function () {
  913.  
  914. // var useCachedBulkData = false;
  915. // var cachedBulkData = storage.get('cachedBulkData');
  916. //
  917. // if(useCachedBulkData && cachedBulkData) {
  918. // initialDataDecorator(cachedBulkData);
  919. // } else {
  920. //
  921. // }
  922. nomenclatoareService.getInitialData ().then ( function ( serverResponse ) {
  923. initialDataDecorator ( serverResponse );
  924. } );
  925. function initialDataDecorator ( bulkData ) {
  926. // if(!cachedBulkData) {
  927. // storage.set('cachedBulkData', bulkData);
  928. // }
  929. var echipamente = [];
  930. var implementuri = [];
  931. angular.forEach ( bulkData.echipamente , function ( echipamentSauImplement ) {
  932. if ( echipamentSauImplement.tip.este_implement ) {
  933. implementuri.push ( echipamentSauImplement );
  934. } else {
  935. echipamente.push ( echipamentSauImplement );
  936. }
  937. } );
  938. $rootScope.echipamente = echipamente;
  939. $rootScope.implementuri = implementuri;
  940.  
  941. $rootScope.tipuriEchipamente = bulkData.tipuriEchipamente;
  942. $rootScope.producatoriEchipamente = bulkData.producatoriEchipamente;
  943.  
  944. $rootScope.producatoriCulturi = bulkData.producatoriCulturi;
  945. $rootScope.tipuriCulturi = bulkData.tipuriCulturi;
  946. // console.log('$rootScope.tipuriCulturi', $rootScope.tipuriCulturi);
  947. angular.forEach ( bulkData.culturi , function ( cultura ) {
  948. var producatorExistent = _.findWhere ( bulkData.producatoriCulturi , { id : cultura.id_producator } );
  949. if ( angular.isDefined ( producatorExistent ) ) {
  950. cultura.producator = producatorExistent;
  951. } else {
  952. console.error ( "Producator cultura #" + cultura.id_producator + " nu a fost gasit!" )
  953. }
  954. var tipCulturaExistenta = _.findWhere ( bulkData.tipuriCulturi , { id : cultura.id_tip } );
  955. if ( angular.isDefined ( tipCulturaExistenta ) ) {
  956. cultura.tip = tipCulturaExistenta;
  957. } else {
  958. console.error ( "Tip cultura #" + cultura.id_tip + " nu a fost gasit" );
  959. }
  960. } );
  961.  
  962. $rootScope.culturi = bulkData.culturi;
  963. /**
  964. angular.forEach($rootScope.culturi, function(cultura) {
  965. cultura.nume_complet = cultura.tip.tip + ' (' + cultura.specia + ')';
  966. });
  967. console.info('$rootScope.culturi', $rootScope.culturi);
  968. **/
  969. $rootScope.nomenclatorLucrari = bulkData.tipuriLucrari;
  970. //console.warn('$rootScope.nomenclatorLucrari', $rootScope.nomenclatorLucrari);
  971. $rootScope.culturi_sole = bulkData.culturi_sole;
  972. if ( $rootScope.isAdmin () ) {
  973. $rootScope.companii = bulkData.companii;
  974. //console.warn($rootScope.companii);
  975. }
  976.  
  977. $rootScope.operatori = bulkData.operatori;
  978. $rootScope.fermeDetalii = bulkData.ferme;
  979. //console.info($rootScope.fermeDetalii);
  980. $rootScope.producatoriFertilizari = bulkData.producatoriFertilizari;
  981. angular.forEach ( bulkData.fertilizari , function ( fertilizator ) {
  982. var producatorFertilizator = _.findWhere ( $rootScope.producatoriFertilizari , { id : fertilizator.id_producator } );
  983. if ( angular.isDefined ( producatorFertilizator ) ) {
  984. fertilizator.producator = producatorFertilizator;
  985. } else {
  986. console.error ( "Producator fertilizator #" + fertilizator.id_producator + " nu a fost gasit!" );
  987. }
  988. } );
  989. $rootScope.fertilizari = bulkData.fertilizari;
  990. //tratamente
  991. $rootScope.tipuriTratamente = bulkData.tipuriTratamente;
  992. $rootScope.producatoriTratamente = bulkData.producatoriTratamente;
  993. //restaurare tip, producator, cultura
  994. angular.forEach ( bulkData.tratamente , function ( tratament ) {
  995. var tipTratament = _.findWhere ( $rootScope.tipuriTratamente , { id : tratament.id_tip } );
  996. if ( angular.isDefined ( tipTratament ) ) {
  997. tratament.tip = tipTratament;
  998. } else {
  999. console.error ( "Tip tratament #" + tratament.id_tip + " nu a fost gasit" );
  1000. }
  1001. var producatorTratament = _.findWhere ( $rootScope.producatoriTratamente , { id : tratament.id_producator } );
  1002. if ( angular.isDefined ( producatorTratament ) ) {
  1003. tratament.producator = producatorTratament;
  1004. } else {
  1005. console.error ( "Producator tratament #" + tratament.id_producator + " nu a fost gasit" );
  1006. }
  1007. var culturaTratament = _.findWhere ( $rootScope.tipuriCulturi , { id : tratament.id_cultura } );
  1008. if ( angular.isDefined ( culturaTratament ) ) {
  1009. tratament.cultura = culturaTratament;
  1010. } else {
  1011. console.error ( "Cultura tratament #" + tratament.id_cultura + " nu a fost gasita" );
  1012. }
  1013. } );
  1014. $rootScope.tratamente = bulkData.tratamente;
  1015.  
  1016. if ( $rootScope.isUser () ) {
  1017. //restaurare ferme
  1018. angular.forEach ( bulkData.sole , function ( sola ) {
  1019. var fermaSolei = _.findWhere ( bulkData.ferme , { id : sola.id_ferma } );
  1020. if ( angular.isDefined ( fermaSolei ) ) {
  1021. sola.ferma = fermaSolei;
  1022. } else {
  1023. console.error ( "Ferma #" + sola.id_ferma + " solei nu a fost gasita" );
  1024. }
  1025. } );
  1026. $rootScope.listaSole = $rootScope.proceseazaSole ( bulkData.sole );
  1027. $rootScope.listaLucrari = bulkData.lucrari;
  1028. //console.log($rootScope.listaLucrari);
  1029. }
  1030.  
  1031. // add a 'val' field to 'tratament' so the dynamic directive
  1032. // can display that value as the default one
  1033. _.each ( $rootScope.tratamente , function ( val ) {
  1034. if ( val.nume_popular )
  1035. val.val = val.nume_popular;
  1036. } );
  1037.  
  1038. if ( _.isEmpty ( $rootScope.mainMenu ) ) {
  1039. $rootScope.mainMenu = $rootScope.normalLeftMenuButtons;
  1040. }
  1041.  
  1042. $rootScope.mainLoading = false;
  1043. }
  1044.  
  1045. };
  1046.  
  1047. var aquireInitialData = function () {
  1048. //console.log('post-login data', $rootScope.loggedInUser);
  1049. if ( $rootScope.isUser () ) {
  1050. $rootScope.poligoane = [];
  1051. $rootScope.hashRelations = [];
  1052. uiGmapGoogleMapApi.then ( function ( maps ) {
  1053. //console.log('Maps reference obtained');
  1054. $rootScope.mapsReference = maps;
  1055. $rootScope.mapBounds = new $rootScope.mapsReference.LatLngBounds ();
  1056. angularLoad.loadScript ( './js/vendor/deletemenu.js' ).then ( function () {
  1057. callInitialAquisition ();
  1058. } );
  1059. } );
  1060. } else if ( $rootScope.isAdmin () ) {
  1061. callInitialAquisition ();
  1062. }
  1063.  
  1064. };
  1065.  
  1066. var init = function () {
  1067. var now = moment ();
  1068. var start;
  1069. var end;
  1070.  
  1071. if ( now.month () > 8 ) {
  1072. start = now.clone ().month ( 8 ).startOf ( 'month' );
  1073. end = now.clone ().year ( now.year () + 1 ).month ( 8 ).startOf ( 'month' );
  1074. } else {
  1075. end = now.clone ().month ( 8 ).startOf ( 'month' );
  1076. start = now.clone ().year ( now.year () - 1 ).month ( 8 ).startOf ( 'month' );
  1077. }
  1078. $rootScope.startAnAgricol = start;
  1079. $rootScope.sfarsitAnAgricol = end;
  1080. if ( $window.sessionStorage[ "userInfo" ] ) {
  1081. $rootScope.loggedInUser = angular.fromJson ( $window.sessionStorage.getItem ( "userInfo" ) );
  1082. changeMenuForAdmin ();
  1083. //console.log($rootScope.loggedInUser);
  1084. aquireInitialData ();
  1085. } else {
  1086. if ( !$rootScope.inLoginMode ) {
  1087. displayLoginDialog ();
  1088. }
  1089. }
  1090. };
  1091.  
  1092. $rootScope.$on ( 'showAPICallError' , function ( event , rejection ) {
  1093. var message;
  1094. if ( rejection.status == 401 ) {
  1095. if ( $rootScope.inLoginMode ) return;
  1096. message = "Sesiunea a expirat! Logați-vă din nou!";
  1097. displayLoginDialog ();
  1098. }
  1099. if ( rejection.status == 400 ) {
  1100. if ( angular.isDefined ( rejection.config ) && angular.isDefined ( rejection.config.url ) ) {
  1101. //it's bad username or password
  1102. if ( rejection.config.url.indexOf ( "/post/login" ) >= 0 ) {
  1103. return;
  1104. }
  1105. }
  1106. //message = "Bad username or password";
  1107. }
  1108. message = rejection.data;
  1109. //console.log("============interceptor=============================");
  1110. console.error ( rejection );
  1111. //console.log("============end interceptor=============================");
  1112. var msg = message;
  1113. if ( angular.isDefined ( msg ) && angular.isDefined ( msg.data ) ) {
  1114. msg = msg.data;
  1115. }
  1116. //console.log("Display toast");
  1117. $rootScope.displayToast ( 'Eroare ! ' + msg , 'error' );
  1118. } );
  1119.  
  1120. $rootScope.$on ( '$stateChangeSuccess' , function ( event , toState , toParams , fromState , fromParams ) {
  1121. //console.log('STATE : ' + toState.name);
  1122. if ( $rootScope.isAdmin () ) {
  1123. //cand e admin, fortam starea initiala
  1124. $rootScope.mainMenu = $rootScope.adminLeftMenuButtons;
  1125. if ( toState.name == "dashboard.main" || toState.name == "dashboard.administrare" ) {
  1126. $state.go ( 'companii.lista' );
  1127. }
  1128.  
  1129. return;
  1130. }
  1131.  
  1132. // hide home button when you are on home page
  1133. $rootScope.hideHomeButton = toState.name == "dashboard.main";
  1134. $rootScope.hideDashButton = toState.name == "dashboard.administrare";
  1135.  
  1136. //Atentie : cand se adauga o ruta in meniu, trebuie declarata si aici, ca sa se poata restaura meniul
  1137. if ( toState.name == "dashboard.main"
  1138. || toState.name == "lucrari.lista"
  1139. || toState.name == "lucrari.toate"
  1140. || toState.name == "lucrari.rapoarte"
  1141. || toState.name == "lucrari.grafice"
  1142. || toState.name == "note.lista"
  1143. ) {
  1144. if ( !angular.isDefined ( $rootScope.inMainView ) ) {
  1145. $rootScope.inMainView = true;
  1146. $rootScope.mainMenu = $rootScope.normalLeftMenuButtons;
  1147. } else if ( !$rootScope.inMainView ) {
  1148. $rootScope.inMainView = true;
  1149. $rootScope.mainMenu = $rootScope.normalLeftMenuButtons;
  1150. }
  1151. }
  1152. if ( toState.name == "dashboard.administrare"
  1153. || toState.name == "nomenclator.fertilizari"
  1154. || toState.name == "nomenclator.echipamente"
  1155. || toState.name == "nomenclator.tratamente"
  1156. || toState.name == "nomenclator.culturi"
  1157. || toState.name == "nomenclator.lucrari"
  1158. || toState.name == "utilizatori.lista"
  1159. || toState.name == "ferme.lista"
  1160. || toState.name == "companii.lista"
  1161. ) {
  1162. if ( !angular.isDefined ( $rootScope.inMainView ) ) {
  1163. $rootScope.inMainView = false;
  1164. $rootScope.mainMenu = $rootScope.adminLeftMenuButtons;
  1165. } else if ( $rootScope.inMainView ) {
  1166. $rootScope.inMainView = false;
  1167. $rootScope.mainMenu = $rootScope.adminLeftMenuButtons;
  1168. }
  1169. }
  1170. } );
  1171.  
  1172. $rootScope.$on ( '$stateNotFound' , function ( event , unfoundState , fromState , fromParams ) {
  1173. $log.error ( "State not found : " + unfoundState );
  1174. } );
  1175.  
  1176. $rootScope.changeStateTo = function ( menu ) {
  1177. $state.go ( menu.uiSRef ).then ( function () {
  1178. if ( $mdSidenav ( "left" ) ) {
  1179. if ( $mdSidenav ( "left" ).isOpen () ) {
  1180. $mdSidenav ( "left" ).toggle ();
  1181. }
  1182. }
  1183. } )
  1184. };
  1185.  
  1186. $rootScope.toggleMobileSidenav = function () {
  1187. $mdSidenav ( 'right' )
  1188. .toggle ();
  1189. };
  1190.  
  1191. $rootScope.displayToast = function ( message , toastType , parent ) {
  1192. var hideDelay = 6000;
  1193. var aToast = {
  1194. template : '<md-toast>' +
  1195. '<div class="md-toast-content">' +
  1196. message +
  1197. '</div>' +
  1198. '</md-toast>' ,
  1199. hideDelay : hideDelay ,
  1200. position : 'bottom left'
  1201. };
  1202.  
  1203. if ( parent ) {
  1204. aToast.parent = parent;
  1205. }
  1206.  
  1207. var e = angular.element ( parent || document.body );
  1208. var p = e.parent ();
  1209. var po = p.css ( "overflow" );
  1210. p.css ( "overflow" , "hidden" );
  1211.  
  1212. setTimeout ( function () {
  1213. p.css ( "overflow" , po );
  1214. } , hideDelay + 1000 );
  1215.  
  1216.  
  1217. $mdToast.show ( aToast );
  1218.  
  1219. };
  1220.  
  1221. $rootScope.replaceInCollection = function ( collection , item , newItem ) {
  1222. var existingItem = _.findWhere ( collection , { id : item.id } ) ,
  1223. keys = _.keys ( newItem );
  1224. _.each ( keys , function ( key ) {
  1225. existingItem[ key ] = newItem[ key ];
  1226. } );
  1227.  
  1228. };
  1229.  
  1230. //announcing global exception
  1231. $rootScope.$on ( 'globalException' , function ( event , ex ) {
  1232. if ( $rootScope.hasGlobalException ) {
  1233. //display only one Global Exception message
  1234. return;
  1235. }
  1236. $rootScope.hasGlobalException = true;
  1237. var aToast = {
  1238. template : '<md-toast class="md-toast" style="background-color:red"><b>Ar trebui sa faceti captura de ecran si refresh la pagina (F5)!</b><br/>Eroare:' + ex.exception + '<br/>...</md-toast>' ,
  1239. hideDelay : 0 ,
  1240. position : 'bottom left'
  1241. };
  1242. $mdToast.show ( aToast );
  1243. } );
  1244.  
  1245. $rootScope.traverseAndPrepareData = function ( raportLucrari ) {
  1246. var listaLucrariProcesata = [];
  1247. angular.forEach ( raportLucrari , function ( lucrare ) {
  1248. if ( lucrare.consum == null ) {
  1249. lucrare.consum = undefined;
  1250. }
  1251. var lucrareProcesata = {
  1252. id : lucrare.id ,
  1253. tip : lucrare.tip ? lucrare.tip.nume : "fara tip???" ,
  1254. id_ferma : lucrare.sola.id_ferma ,
  1255. nume_sola : lucrare.sola.nume_comun ? lucrare.sola.nume_comun : lucrare.sola.nume ,
  1256. suprafata : lucrare.suprafata ? lucrare.suprafata : lucrare.sola.suprafata ,
  1257. data_inregistrare : lucrare.data_inregistrare ,
  1258. cost : isNaN ( Number ( lucrare.cost ) ) ? Number ( 0 ) : lucrare.cost ,
  1259. consum : isNaN ( Number ( lucrare.consum ) ) ? Number ( 0 ) : lucrare.consum ,// + (lucrare.consum > 1 ? " litri" : " litru"),
  1260. model_echipament : lucrare.echipament ? lucrare.echipament.model : "fara echipament" ,
  1261. model_implement : lucrare.implement ? lucrare.implement.model : "nici unul" ,
  1262. nume_operator : lucrare.operator ? lucrare.operator.nume : "fara operator" ,
  1263. observatii : lucrare.observatii ,
  1264. cost_total : 0 ,
  1265. cost_exploatare : 0 ,
  1266. cantitate_total : 0 ,
  1267. children : [] ,
  1268. childrenExpanded : true
  1269. };
  1270. var lucrareCuTert = false;
  1271. if ( !isNaN ( Number ( lucrare.cost ) ) ) {
  1272. if ( !isNaN ( Number ( lucrare.consum ) ) && Number ( lucrare.consum ) > 0 ) {
  1273. lucrareProcesata.cost_exploatare = (Number ( lucrareProcesata.suprafata ) * Number ( lucrare.consum ) * Number ( lucrare.cost ));
  1274. } else {
  1275. lucrareCuTert = true;
  1276. lucrareProcesata.cost_exploatare = (Number ( lucrareProcesata.suprafata ) * Number ( lucrare.cost ));
  1277. }
  1278. //row-ul principal in tabel
  1279. listaLucrariProcesata.push ( lucrareProcesata );
  1280. //adaugam row-ul de costuri
  1281. var valoriIntroduse = {
  1282. child : true ,
  1283. visible : true ,
  1284. valoare_introdusa : lucrareProcesata.cost_exploatare.toFixed ( 2 ) + " RON fără TVA" ,
  1285. nume_camp : lucrareCuTert ? "Cost lucrare (terț): " : "Cost lucrare motorina : "
  1286. };
  1287. //punem row-ul de motorina in tabel
  1288. listaLucrariProcesata.push ( valoriIntroduse );
  1289. //punem copilul in parinte (pentru al putea ascunde)
  1290. lucrareProcesata.children.push ( valoriIntroduse );
  1291. } else {
  1292. listaLucrariProcesata.push ( {
  1293. child : true ,
  1294. visible : true ,
  1295. valoare_introdusa : "Cost gresit!" ,
  1296. nume_camp : "Eroare!"
  1297. } );
  1298. //punem copilul in parinte (pentru al putea ascunde)
  1299. lucrareProcesata.children.push ( {
  1300. child : true ,
  1301. visible : true ,
  1302. valoare_introdusa : "Cost gresit!" ,
  1303. nume_camp : "Eroare!"
  1304. } );
  1305. }
  1306. //fiecare camp
  1307. var cost = undefined;
  1308. var doza = undefined;
  1309. //pentru fiecare camp, mai facem un row in tabel
  1310. if ( angular.isDefined ( lucrare.campuri ) ) {
  1311. angular.forEach ( lucrare.campuri , function ( camp ) {
  1312. var valoriIntroduse = {
  1313. child : true ,
  1314. visible : true ,
  1315. valoare_introdusa : camp.valoare_introdusa ,
  1316. valoare_originala : camp.valoare_introdusa ,
  1317. nume_camp : camp.nume_camp
  1318. };
  1319. if ( camp.nume_camp.toLowerCase ().indexOf ( DOZE_RECOMANDATE ) == -1 ) {
  1320. if ( camp.nume_camp.toLowerCase ().indexOf ( FERTILIZATOR ) >= 0 ) {
  1321. var fertilizatorSelectat = _.findWhere ( $rootScope.fertilizari , { id : Number ( camp.valoare_introdusa ) } );
  1322. if ( angular.isDefined ( fertilizatorSelectat ) ) {
  1323. if ( angular.isDefined ( fertilizatorSelectat.continut_sa_procente ) && angular.isDefined ( fertilizatorSelectat.continut_sa_grame ) ) {
  1324. lucrareProcesata.fertilizator = fertilizatorSelectat;
  1325. valoriIntroduse.valoare_introdusa = fertilizatorSelectat.denumire_comerciala + " (" + fertilizatorSelectat.continut_sa_grame + "g - " + fertilizatorSelectat.continut_sa_procente + "%)";
  1326. } else {
  1327. valoriIntroduse.valoare_introdusa = fertilizatorSelectat.denumire_comerciala + " ( lipsesc substantele)";
  1328. }
  1329. } else {
  1330. valoriIntroduse.valoare_introdusa = "Fertilizator LIPSA# " + camp.valoare_introdusa;
  1331. }
  1332. } else if ( camp.nume_camp.toLowerCase ().indexOf ( TRATAMENT ) >= 0 ) {
  1333. var tratamentSelectat = _.findWhere ( $rootScope.tratamente , { id : Number ( camp.valoare_introdusa ) } );
  1334. if ( angular.isDefined ( tratamentSelectat ) ) {
  1335. lucrareProcesata.tratament = tratamentSelectat;
  1336. valoriIntroduse.valoare_introdusa = tratamentSelectat.nume + " (" + tratamentSelectat.cultura.tip + " - " + tratamentSelectat.tip.tip + ")";
  1337. } else {
  1338. valoriIntroduse.valoare_introdusa = "Tratament LIPSA# " + camp.valoare_introdusa;
  1339. }
  1340. } else if ( camp.nume_camp.toLowerCase ().indexOf ( DAUNATORUL ) >= 0 ) {
  1341. valoriIntroduse.valoare_introdusa = camp.valoarea_text_introdusa;
  1342. } else if ( camp.nume_camp.toLowerCase ().indexOf ( DOZA_UTILIZATA ) >= 0 ) {
  1343. doza = Number ( Number ( lucrareProcesata.suprafata ) * Number ( camp.valoare_introdusa ) * 0.001 ).toFixed ( 2 );
  1344. valoriIntroduse.valoare_introdusa = camp.valoare_introdusa + " " + camp.unitate_de_masura + " - Total : " + doza + " kg";
  1345. } else if ( camp.nume_camp.toLowerCase ().indexOf ( COST ) >= 0 ) {
  1346. cost = Number ( camp.valoare_introdusa );
  1347. if ( isNaN ( cost ) ) {
  1348. console.error ( camp.nume_camp + " = " + camp.valoare_introdus );
  1349. }
  1350. valoriIntroduse.valoare_introdusa = camp.valoare_introdusa + " " + camp.unitate_de_masura + " - Total : " + Number ( doza * cost ).toFixed ( 2 ) + " " + camp.unitate_de_masura;
  1351. } else if ( camp.nume_camp.toLowerCase ().indexOf ( KG ) >= 0 ) {
  1352. doza = Number ( Number ( lucrareProcesata.suprafata ) * Number ( camp.valoare_introdusa ) ).toFixed ( 2 );
  1353. valoriIntroduse.valoare_introdusa = camp.valoare_introdusa + " " + camp.unitate_de_masura + " Total : " + doza + " kg";
  1354. } else if ( camp.nume_camp.toLowerCase ().indexOf ( DENSITATE ) >= 0 ) {
  1355. valoriIntroduse.valoare_introdusa = camp.valoare_introdusa + " " + camp.unitate_de_masura;
  1356. } else if ( camp.nume_camp.toLowerCase ().indexOf ( CANTITATE ) >= 0 ) {
  1357. //console.log("Cantitate " + camp.valoare_introdusa);
  1358. doza = Number ( Number ( lucrareProcesata.suprafata ) * Number ( camp.valoare_introdusa ) ).toFixed ( 2 );
  1359. valoriIntroduse.valoare_introdusa = camp.valoare_introdusa + " " + camp.unitate_de_masura + " Total : " + doza + " kg.";
  1360. } else if ( camp.nume_camp.toLowerCase ().indexOf ( KM1 ) >= 0 ) {
  1361. cost = Number ( camp.valoare_introdusa );
  1362. valoriIntroduse.valoare_introdusa = camp.valoare_introdusa + " " + camp.unitate_de_masura;
  1363. } else if ( camp.nume_camp.toLowerCase ().indexOf ( KM2 ) >= 0 ) {
  1364. doza = Number ( camp.valoare_introdusa );
  1365. valoriIntroduse.valoare_introdusa = camp.valoare_introdusa + " " + camp.unitate_de_masura;
  1366. }
  1367. }
  1368. if ( !isNaN ( Number ( doza ) ) ) {
  1369. lucrareProcesata.cantitate_total = doza;
  1370. if ( !isNaN ( Number ( cost ) ) ) {
  1371. lucrareProcesata.cost_total = Number ( Number ( lucrareProcesata.cost_total ) + Number ( doza * cost ) );
  1372. }
  1373. }
  1374. //punem row-ul in tabel
  1375. listaLucrariProcesata.push ( valoriIntroduse );
  1376. //punem copilul in parinte (pentru al putea ascunde)
  1377. lucrareProcesata.children.push ( valoriIntroduse );
  1378. } );
  1379. }
  1380. } );
  1381.  
  1382. return listaLucrariProcesata;
  1383.  
  1384. };
  1385.  
  1386. $rootScope.postProcesareLucrari = function ( idSola , rapoarte , tableHeaders ) {
  1387. var costTotal = 0;
  1388. var listaSubstanteFertilizatori = [];
  1389. var listaSubstanteTratamente = [];
  1390. var dataSemanatului;
  1391. var areSubstanteFertilizatori = false;
  1392. var areSubstanteTratamente = false;
  1393.  
  1394. _.each ( rapoarte , function ( raport ) {
  1395. if ( _.has ( raport , 'children' ) ) {
  1396. raport.cost_total = Number ( Number ( raport.cost_total ) + Number ( raport.cost_exploatare ) );
  1397. costTotal = Number ( costTotal ) + Number ( raport.cost_total );
  1398. var kilogrameSubstanta = 0;
  1399. if ( raport.tip.toLowerCase ().indexOf ( TRATAMENT ) >= 0 ) {
  1400. if ( angular.isDefined ( raport.tratament ) && angular.isDefined ( raport.tratament.substanta_activa ) ) {
  1401. _.each ( raport.children , function ( child ) {
  1402. if ( child.nume_camp.toLowerCase ().indexOf ( DOZA_UTILIZATA ) >= 0 ) {
  1403. kilogrameSubstanta = Number ( Number ( child.valoare_originala ) * 0.001 * Number ( raport.suprafata ) ).toFixed ( 2 );
  1404. //console.log(child.valoare_originala + " g x " + raport.suprafata + " ha = " + kilogrameSubstanta);
  1405. }
  1406. } );
  1407. areSubstanteTratamente = true;
  1408. if ( angular.isDefined ( listaSubstanteTratamente[ raport.tratament.substanta_activa ] ) ) {
  1409. listaSubstanteTratamente[ raport.tratament.substanta_activa ] = listaSubstanteTratamente[ raport.tratament.substanta_activa ] + Number ( kilogrameSubstanta );
  1410. } else {
  1411. listaSubstanteTratamente[ raport.tratament.substanta_activa ] = Number ( kilogrameSubstanta );
  1412. }
  1413. }
  1414. } else if ( raport.tip.toLowerCase ().indexOf ( FERTILIZATOR ) >= 0 ) {
  1415. if ( angular.isDefined ( raport.fertilizator ) && angular.isDefined ( raport.fertilizator.denumire_comerciala ) ) {
  1416. _.each ( raport.children , function ( child ) {
  1417. if ( child.nume_camp.toLowerCase ().indexOf ( CANTITATE ) >= 0 ) {
  1418. kilogrameSubstanta = Number ( Number ( child.valoare_originala ) * Number ( raport.suprafata ) ).toFixed ( 2 );
  1419. //console.log(child.valoare_originala + " kg x " + raport.suprafata + " ha = " + kilogrameSubstanta);
  1420. }
  1421. } );
  1422. areSubstanteFertilizatori = true;
  1423. if ( angular.isDefined ( listaSubstanteFertilizatori[ raport.fertilizator.denumire_comerciala ] ) ) {
  1424. listaSubstanteFertilizatori[ raport.fertilizator.denumire_comerciala ] = listaSubstanteFertilizatori[ raport.fertilizator.denumire_comerciala ] + Number ( kilogrameSubstanta );
  1425. } else {
  1426. listaSubstanteFertilizatori[ raport.fertilizator.denumire_comerciala ] = Number ( kilogrameSubstanta );
  1427. }
  1428. }
  1429. } else if ( raport.tip.toLowerCase ().indexOf ( SEMANAT ) >= 0 ) {
  1430. dataSemanatului = moment ( raport.data_inregistrare ).format ( "LL" );
  1431. }
  1432. }
  1433. } );
  1434.  
  1435. if ( angular.isDefined ( dataSemanatului ) ) {
  1436. tableHeaders.push ( {
  1437. isNotHeader : true ,
  1438. valoare_introdusa : dataSemanatului ,
  1439. nume_camp : "Data semanatului"
  1440. } );
  1441. } else {
  1442. tableHeaders.push ( {
  1443. isNotHeader : true ,
  1444. valoare_introdusa : "nu are" ,
  1445. nume_camp : "Data semanatului"
  1446. } );
  1447. }
  1448.  
  1449. if ( angular.isDefined ( idSola ) ) {
  1450. var cultura = _.findWhere ( $rootScope.culturi , { id : $rootScope.culturi_sole[ idSola ] } );
  1451. if ( angular.isDefined ( cultura ) ) {
  1452. tableHeaders.push ( {
  1453. isNotHeader : true ,
  1454. valoare_introdusa : cultura.tip.tip + "(" + cultura.specia + ")" ,
  1455. nume_camp : "Cultura curentă"
  1456. } );
  1457. } else {
  1458. //console.log("Fara cultura curenta");
  1459. tableHeaders.push ( {
  1460. isNotHeader : true ,
  1461. valoare_introdusa : "nu are" ,
  1462. nume_camp : "Cultura curentă"
  1463. } );
  1464. }
  1465. }
  1466. tableHeaders.push ( {
  1467. isNotHeader : true ,
  1468. valoare_introdusa : costTotal.toFixed ( 2 ) + " RON fără TVA" ,
  1469. nume_camp : "Cost total"
  1470. } );
  1471. if ( areSubstanteTratamente ) {
  1472. tableHeaders.push ( {
  1473. isNotHeader : true ,
  1474. valoare_introdusa : "" ,
  1475. nume_camp : "Substanțe tratamente"
  1476. } );
  1477. }
  1478. for ( var key in listaSubstanteTratamente ) {
  1479. tableHeaders.push ( {
  1480. isNotHeader : true ,
  1481. valoare_introdusa : Number ( listaSubstanteTratamente[ key ] ).toFixed ( 2 ) + " kg" ,
  1482. nume_camp : key
  1483. } );
  1484. }
  1485. if ( areSubstanteFertilizatori ) {
  1486. tableHeaders.push ( {
  1487. isNotHeader : true ,
  1488. valoare_introdusa : "" ,
  1489. nume_camp : "Substanțe fertilizări"
  1490. } );
  1491. }
  1492. for ( var key2 in listaSubstanteFertilizatori ) {
  1493. tableHeaders.push ( {
  1494. isNotHeader : true ,
  1495. valoare_introdusa : Number ( listaSubstanteFertilizatori[ key2 ] ).toFixed ( 2 ) + " kg" ,
  1496. nume_camp : key2
  1497. } );
  1498. }
  1499.  
  1500. if ( idSola ) {
  1501. var solaSelectata = _.findWhere ( $rootScope.listaSole , { id : idSola } );
  1502. if ( solaSelectata ) {
  1503. if ( solaSelectata.data_arendare ) {
  1504. tableHeaders.push ( {
  1505. isNotHeader : true ,
  1506. valoare_introdusa : moment ( solaSelectata.data_arendare ).format ( "MMM Do YY" ) ,
  1507. nume_camp : "Data inceput arendare:" ,
  1508. isDate : true
  1509. } );
  1510. }
  1511. if ( solaSelectata.data_final_arendare ) {
  1512. tableHeaders.push ( {
  1513. isNotHeader : true ,
  1514. valoare_introdusa : moment ( solaSelectata.data_final_arendare ).format ( "MMM Do YY" ) ,
  1515. nume_camp : "Data final arendare:" ,
  1516. isDate : true
  1517. } );
  1518. }
  1519. if ( solaSelectata.proprietar ) {
  1520. tableHeaders.push ( {
  1521. isNotHeader : true ,
  1522. valoare_introdusa : solaSelectata.proprietar ,
  1523. nume_camp : "Contract si proprietari:"
  1524. } );
  1525. }
  1526. }
  1527. }
  1528.  
  1529. };
  1530.  
  1531. // # Maybe some utils.
  1532.  
  1533. // # Return the key of the inserted object value.
  1534. $rootScope.getKeyByValue = function ( thisObject , value ) {
  1535. for ( var prop in this ) {
  1536. if ( thisObject.hasOwnProperty ( prop ) ) {
  1537. if ( thisObject[ prop ] === value )
  1538. return prop;
  1539. }
  1540. }
  1541. };
  1542.  
  1543. // # index.html helpers
  1544.  
  1545. $rootScope.changeFuelCost = function ( fuelCost ) {
  1546. return utilizatorService.changeFuelCost ( fuelCost ).then ( function ( res ) {
  1547. // getFuelCost();
  1548. $rootScope.displayToast ( 'Pretul combustibilului a fost modificat cu succes !' );
  1549. } , function ( err ) {
  1550. console.error ( 'err in changeFuelCost' , err );
  1551. $rootScope.displayToast ( 'Eroare ! Nu am putut modifica costul combustibilului ! Daca eroarea persista, va rugam contactati administratorul.' );
  1552. } );
  1553. };
  1554.  
  1555. init ();
  1556.  
  1557. }
  1558.  
  1559. appStartUp.$inject = [
  1560. '$log' ,
  1561. '$rootScope' ,
  1562. '$window' ,
  1563. '$http' ,
  1564. 'APP_URL' ,
  1565. 'uiGmapGoogleMapApi' ,
  1566. '$mdToast' ,
  1567. 'angularLoad' ,
  1568. 'nomenclatoareService' ,
  1569. '$mdDialog' ,
  1570. '$mdSidenav' ,
  1571. '$state' ,
  1572. 'storage' ,
  1573. '$location' ,
  1574. 'iconsUrls' ,
  1575. '$templateCache' ,
  1576. 'BUTTON' ,
  1577. 'DAUNATORUL' ,
  1578. 'DOZE_RECOMANDATE' ,
  1579. 'DOZA_UTILIZATA' ,
  1580. 'TRATAMENT' ,
  1581. 'CULTURA' ,
  1582. 'FERTILIZATOR' ,
  1583. 'COST' ,
  1584. 'CANTITATE' ,
  1585. 'KG' ,
  1586. 'DENSITATE' ,
  1587. 'SEMANAT' ,
  1588. 'KM1' ,
  1589. 'KM2' ,
  1590. 'utilizatorService' ];
  1591.  
  1592. }).call ( this );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement