Projekt

Obecné

Profil

Stáhnout (11.3 KB) Statistiky
| Větev: | Revize:
1
angular.module("pvpk",["ngResource","ngSanitize"]),angular.module("pvpk").constant("config",{APP_NAME:"PVPK",APP_VERSION:"1.3.0",API_URL:API_URL,API_TOKEN:API_TOKEN,DEFAULT_POSITION:{lat:49.53,lng:13.3},DEFAULT_ZOOM:10,DEFAULT_ZOOM_MIN:7,DEFAULT_RANGE_DATE_DAY:{from:-30,to:-1},DEFAULT_RANGE_TIME_HOUR:{from:7,to:16}}),angular.module("pvpk").controller("infoController",["$rootScope","$scope","$location","config","Device","Vehicle",function(u,h,r,i,n,e){this.$onInit=function(){u.selectDevice=null,h.showInfoLoading=!1,h.vehicles=[],h.urlExportCsv=null,e.query(null,function(e){h.vehicles=e},function(e){u.graphShow=!1,console.log("Error api all Vehicles"),u.handleErrorResponse(e)}),u.$emit("setRangeFromUrl",null)},u.$on("setRangeFromUrl",function(e,o){var t=r.search();h.range={fromDate:moment(t.fromDate,"YYYY-MM-DD").isValid()?moment(t.fromDate).toDate():moment().add(i.DEFAULT_RANGE_DATE_DAY.from,"d").toDate(),toDate:moment(t.toDate,"YYYY-MM-DD").isValid()?moment(t.toDate).toDate():moment().add(i.DEFAULT_RANGE_DATE_DAY.to,"d").toDate(),fromTime:moment(t.fromTime,"HH:mm").isValid()?moment(t.fromTime,"HH:mm").toDate():moment({hour:i.DEFAULT_RANGE_TIME_HOUR.from}).toDate(),toTime:moment(t.toTime,"HH:mm").isValid()?moment(t.toTime,"HH:mm").toDate():moment({hour:i.DEFAULT_RANGE_TIME_HOUR.to}).toDate(),isTime:0!=t.isTime}}),u.$on("infoLocation",function(e,o){h.showInfoLoading=!0;var t=r.search();t.deviceId=o.id,t.direction=o.direction,r.search(t);var i=h.getRange(),a={period:i.isTime?"time-period":"day-period",id:o.id,direction:o.direction,dateFrom:i.fromDate.format("YYYY-MM-DD"),dateTo:i.toDate.format("YYYY-MM-DD"),timeFrom:i.isTime?i.fromTime.format("HH:mm"):null,timeTo:i.isTime?i.toTime.format("HH:mm"):null};n.get(a,function(e){u.selectDevice=e,h.renderGraph(),h.urlExportCsv=h.generateUrlExportCsv(a),h.showInfoLoading=!1},function(e){u.selectDevice=null,h.showInfoLoading=!1,console.log("Error api get Devices"),u.handleErrorResponse(e)})}),h.generateUrlExportCsv=function(e){var o="/devices/:id/:period/csv?".replace(":id",e.id).replace(":period",e.period);delete e.id,delete e.period;var t=jQuery.param(e);return i.API_URL+o+t},h.changeRange=function(){if(h.range.fromDate>=h.range.toDate||h.range.isTime&&h.range.fromTime>=h.range.toTime)u.selectDevice.traffics=[];else{var e=h.getRange(),o=r.search();o.fromDate=e.fromDate.format("YYYY-MM-DD"),o.toDate=e.toDate.format("YYYY-MM-DD"),o.fromTime=e.isTime?e.fromTime.format("HH:mm"):null,o.toTime=e.isTime?e.toTime.format("HH:mm"):null,o.isTime=e.isTime?null:0,r.search(o),u.selectDevice&&u.$emit("infoLocation",{id:u.selectDevice.id,direction:u.selectDevice.direction})}},h.getRange=function(){return{fromDate:moment(h.range.fromDate).isValid()?moment(h.range.fromDate):moment().add(i.DEFAULT_RANGE_DATE_DAY.from,"d"),toDate:moment(h.range.toDate).isValid()?moment(h.range.toDate):moment().add(i.DEFAULT_RANGE_DATE_DAY.to,"d"),fromTime:moment(h.range.fromTime).isValid()?moment(h.range.fromTime):moment({hour:i.DEFAULT_RANGE_TIME_HOUR.from}),toTime:moment(h.range.toTime).isValid()?moment(h.range.toTime):moment({hour:i.DEFAULT_RANGE_TIME_HOUR.to}),isTime:!!h.range.isTime}},h.renderGraph=function(){for(var e,o=["rgba(158, 158, 158, #alpha)","rgba(213, 0, 0, #alpha)","rgba(0, 123, 255, #alpha)","rgba(170, 0, 255, #alpha)","rgba(0, 200, 83, #alpha)","rgba(255, 214, 0, #alpha)","rgba(255, 109, 0, #alpha)","rgba(174, 234, 0, #alpha)","rgba(98, 0, 234, #alpha)","rgba(255, 171, 0, #alpha)","rgba(100, 221, 23, #alpha)","rgba(0, 184, 212, #alpha)"],t=jQuery.unique(u.selectDevice.traffics.map(function(e){return h.range.isTime?e.timeFrom:moment(e.date,"YYYY-MM-DD").format("D.M.YYYY")})),i=jQuery.unique(u.selectDevice.traffics.map(function(e){return e.typeVehicleId})),a=jQuery.grep(h.vehicles,function(e){return 0<=i.indexOf(e.id)}),r=[],n=[],l=0;e=a[l];l++){for(var c,s={label:e.name,backgroundColor:o[e.id].replace("#alpha","0.3"),borderColor:o[e.id].replace("#alpha","1"),borderWidth:2,data:[]},m={data:[],borderWidth:2,label:e.name,fill:!1,backgroundColor:o[e.id].replace("#alpha","0.3"),borderColor:o[e.id].replace("#alpha","1"),cubicInterpolationMode:"monotone",pointRadius:0},d=0,p=0;c=u.selectDevice.traffics[p];p++)(h.range.isTime&&t[d]!==c.timeFrom||!h.range.isTime&&t[d]!==moment(c.date,"YYYY-MM-DD").format("D.M.YYYY"))&&(d++,s.data.length<d&&(s.data.push(0),m.data.push(null))),c.typeVehicleId===e.id&&(s.data.push(h.range.isTime?c.numberVehicleAverage:c.numberVehicle),m.data.push(c.speedAverage<=0?null:c.speedAverage));r.push(s),n.push(m)}u.$emit("renderGraphNumberVehicles",{data:{labels:t,datasets:r}}),u.$emit("renderGraphAverageSpeed",{data:{labels:t,datasets:n}})},h.infoClose=function(){u.selectDevice=null;var e=r.search();e.deviceId=null,e.direction=null,r.search(e),u.$emit("setDefaultMap",null)}}]),angular.module("pvpk").controller("mainController",["$rootScope","$scope","$location","$window",function(a,r,n,e){this.$onInit=function(){r.showLoadingScreen=!0},e.onload=function(){var e=n.search();e.deviceId&&a.$emit("activeMarker",{id:e.deviceId}),r.$apply(function(){r.showLoadingScreen=!1})},a.$on("$locationChangeSuccess",function(e,o,t){var i=n.search();o!==t&&r.historyUrl?(r.historyUrl.q==r.historyUrl.q&&r.historyUrl.isDirection==i.isDirection||a.$emit("setSearchFromUrl",null),r.historyUrl.fromDate!==i.fromDate||r.historyUrl.toDate!==i.toDate||r.historyUrl.fromTime!==i.fromTime||r.historyUrl.toTime!==i.toTime?(a.$emit("setRangeFromUrl",null),i.deviceId&&a.$emit("infoLocation",{id:i.deviceId,direction:i.direction})):!i.deviceId||r.historyUrl.deviceId===i.deviceId&&r.historyUrl.direction===i.direction?!i.deviceId&&r.historyUrl.deviceId&&(a.selectDevice=null,a.$emit("setDefaultMap",null)):(a.$emit("infoLocation",{id:i.deviceId,direction:i.direction}),a.$emit("activeMarker",{id:i.deviceId}))):i.deviceId&&a.$emit("infoLocation",{id:i.deviceId,direction:i.direction}),r.historyUrl=n.search()}),a.handleErrorResponse=function(e){var o=jQuery("#modalError");switch(e.status){case 400:console.log("API ERROR 400"),r.modalError={title:"Neplatný požadavek",body:"Požadavek nemůže být vyřízen, poněvadž byl syntakticky nesprávně zapsán.",button:"OK"},o.modal("show");break;case 401:r.modalError={title:"Platnost webové aplikace vypršela",body:"Pro obnovení platnosti stačí stisknout tlačítko <strong>Obnovit</strong>.",button:"Obnovit",clickButton:r.reloadApp},o.modal({backdrop:"static",keyboard:!1});break;case 404:console.log("API ERROR 404"),r.modalError={title:"Nenalezen",body:"Záznam nebyl nalezen.",button:"OK"},o.modal("show");break;case 500:console.log("API ERROR 500"),r.modalError={title:"Chyba",body:"Chyba serveru. Zopakujte akci později.",button:"OK"},o.modal("show");break;case-1:console.log("API NOT CONNECTED"),r.modalError={title:"Připojení k internetu",body:"Nejste připojeni k internetu. Zkontrolujte připojení.",button:"OK"},o.modal("show");break;default:console.log("API UNKNOWN ERROR"),r.modalError={title:"Neočekávaná chyba",body:"Nastala neočekávaná chyba.",button:"OK"},o.modal("show")}},r.reloadApp=function(){e.location.reload()}}]),angular.module("pvpk").controller("mapController",["$rootScope","$scope","config","Device",function(t,a,i,e){this.$onInit=function(){a.markers=[],a.map=new google.maps.Map(document.getElementById("map"),{center:i.DEFAULT_POSITION,zoom:i.DEFAULT_ZOOM,minZoom:i.DEFAULT_ZOOM_MIN,zoomControl:!0,mapTypeControl:!1,scaleControl:!1,streetViewControl:!1,rotateControl:!1,fullscreenControl:!1,mapTypeId:google.maps.MapTypeId.ROADMAP}),e.query({showDirection:0},function(e){for(var o,t=0;o=e[t];t++)a.createMarker(o)},function(e){console.log("Error api all Devices"),t.handleErrorResponse(e)})},a.createMarker=function(e){if(e.lat&&e.lng){var o=new google.maps.Marker({map:a.map,position:{lat:e.lat,lng:e.lng},title:e.name,infoWindow:new google.maps.InfoWindow({content:'<h6 class="mb-1">'+e.name+"</h6><address>"+e.street+", "+e.town+"</address>"}),id:e.id});o.addListener("click",function(){a.closeInfoWindows(),o.infoWindow.open(a.map,o),t.$emit("infoLocation",{id:e.id})}),a.markers.push(o)}},t.$on("activeMarker",function(e,o){for(var t,i=0;t=a.markers[i];i++)t.id&&t.id===o.id&&t.infoWindow?(a.map.setCenter(t.getPosition()),a.map.setZoom(12),t.infoWindow.open(a.map,t)):t.infoWindow.close()}),t.$on("setDefaultMap",function(e,o){a.map.setCenter(i.DEFAULT_POSITION),a.map.setZoom(i.DEFAULT_ZOOM),a.closeInfoWindows()}),a.closeInfoWindows=function(){for(var e,o=0;e=a.markers[o];o++)e.infoWindow.close()}}]),angular.module("pvpk").controller("searchController",["$rootScope","$scope","$location","config","Device",function(t,i,a,e,o){this.$onInit=function(){i.config=e,i.locations=[],i.showSearchLoading=!1,t.$emit("setSearchFromUrl",null)},i.searchLocations=function(){var e=a.search();e.q=i.search.q,e.isDirection=i.search.isDirection?1:null,a.search(e),!i.search.q||i.search.q.length<=1?i.locations=[]:(i.showSearchLoading=!0,o.query({address:i.search.q,showDirection:i.search.isDirection?1:0},function(e){i.locations=e,i.showSearchLoading=!1},function(e){i.showSearchLoading=!1,console.log("Error api all Devices"),t.handleErrorResponse(e)}))},t.$on("setSearchFromUrl",function(e,o){var t=a.search();i.search={q:t.q,isDirection:!!t.isDirection&&!!+t.isDirection},i.searchLocations()}),i.selectDevice=function(e,o){t.$emit("activeMarker",{id:e}),t.$emit("infoLocation",{id:e,direction:o})}}]),angular.module("pvpk").component("graphAverageSpeed",{template:'<div><canvas id="graphAverageSpeed" class="graphSize mb-5"></canvas></div>',controller:["$rootScope","$scope",function(e,i){e.$on("renderGraphAverageSpeed",function(e,o){var t=document.getElementById("graphAverageSpeed").getContext("2d");i.graphLine&&i.graphLine.destroy(),i.graphLine=new Chart(t,{type:"line",data:o.data,options:{responsive:!0,pointDot:!1,legend:{position:"bottom"},scales:{xAxes:[{ticks:{autoSkip:!0,maxTicksLimit:15}}],yAxes:[{scaleLabel:{display:!0,labelString:"km/h"},ticks:{beginAtZero:!0,suggestedMax:70}}]},tooltips:{mode:"index",intersect:!1,callbacks:{label:function(e){return e.yLabel+" km/h"}}}}})})}]}),angular.module("pvpk").component("graphNumberVehicles",{template:'<div><canvas id="graphNumberVehicles" class="graphSize mb-5"></canvas></div>',controller:["$rootScope","$scope",function(e,i){e.$on("renderGraphNumberVehicles",function(e,o){var t=document.getElementById("graphNumberVehicles").getContext("2d");i.graphNumberVehicles&&i.graphNumberVehicles.destroy(),i.graphNumberVehicles=new Chart(t,{type:"bar",data:o.data,options:{responsive:!0,onResize:function(e,o){e.options.legend.display=240<o.height,e.update()},legend:{position:"bottom"},scales:{xAxes:[{stacked:!0,ticks:{autoSkip:!0,maxTicksLimit:15}}],yAxes:[{scaleLabel:{display:!0,labelString:"počet vozidel"},stacked:!0}]},tooltips:{mode:"index",intersect:!1}}})})}]}),angular.module("pvpk").factory("Device",["$resource","config",function(e,o){return e(o.API_URL+"/devices/:id",{id:"@id",period:"@period"},{get:{url:o.API_URL+"/devices/:id/:period",method:"GET",headers:{"Content-Type":"application/json",Accept:"application/json",jwt:o.API_TOKEN}},query:{url:o.API_URL+"/devices",method:"GET",isArray:!0,headers:{"Content-Type":"application/json",Accept:"application/json",jwt:o.API_TOKEN}}})}]),angular.module("pvpk").factory("Vehicle",["$resource","config",function(e,o){return e(o.API_URL+"/vehicles",null,{query:{url:o.API_URL+"/vehicles",method:"GET",isArray:!0,headers:{"Content-Type":"application/json",Accept:"application/json",jwt:o.API_TOKEN}}})}]);
2
//# sourceMappingURL=app.min.js.map
(3-3/8)