function _toConsumableArray(t){return _arrayWithoutHoles(t)||_iterableToArray(t)||_unsupportedIterableToArray(t)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(t,a){var e;if(t)return"string"==typeof t?_arrayLikeToArray(t,a):"Map"===(e="Object"===(e={}.toString.call(t).slice(8,-1))&&t.constructor?t.constructor.name:e)||"Set"===e?Array.from(t):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?_arrayLikeToArray(t,a):void 0}function _iterableToArray(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}function _arrayWithoutHoles(t){if(Array.isArray(t))return _arrayLikeToArray(t)}function _arrayLikeToArray(t,a){(null==a||a>t.length)&&(a=t.length);for(var e=0,n=Array(a);e<a;e++)n[e]=t[e];return n}(()=>{function t(e,t,n,o,a,r,i,d,c,s,l,u,m,g){var f,p;function h(t,a){t&&a&&(e.data.datapoints.length=0,(a=e.data.datapoints).push.apply(a,_toConsumableArray(t))),e.data.graphDataPoints=t;a=v(_.filter(t,"__active"));e.channel=a?"/measurements/".concat(a):""}function y(t){e.data.graphAlarmsEventsConfigs=t;t=v(_.filter(t,"__active"));e.alarmsChannel=t?"/alarms/".concat(t):"",e.eventsChannel=t?"/events/".concat(t):""}function v(t){return _(t).map(function(t){return t.__target.id}).uniq().value().join(",")}function A(){var a,t=o.getContext();t.context&&(f="".concat(t.context,"_").concat(t.id)),e.disableLocalStorage||(a=_.throttle(function(t,a){t===a||e.dontSave||e.disableLocalStorage||(t=_.pick(e.data,["dateFrom","dateTo","interval","aggregation","realtime","alarmsEventsConfigs"]),r.setSavedFilters(t,f))},500,{leading:!1,trailing:!0}),r.getSavedFilters(f).then(function(t){_.assign(e.data,t),e.$watch("data.realtime",a),e.$watch("data.dateFrom",a),e.$watch("data.dateTo",a),e.$watch("data.interval",a),e.$watch("data.aggregation",a),e.$watch("data.alarmsEventsConfigs",a,!0)}))}function b(){var t,a=b._hasDashboard,e=a;if(_.isUndefined(a))try{2===(t=n.get("dashboardSvc")).VERSION&&(e=t)}catch(t){e=!1}return b._hasDashboard=e}function S(t){var a=b();a&&a[t]({name:"Data points graph",title:l.getString("Data points"),_width:24,_height:5,config:{datapoints:e.data.graphDataPoints,alarmsEventsConfigs:e.data.graphAlarmsEventsConfigs,dateTo:e.data.dateTo,dateFrom:e.data.dateFrom,aggregation:e.data.aggregation,realtime:e.data.realtime}}).then(T)}function T(){d.success(s("Widget created."))}function D(){S("addWidgetToSelectedDashboardInContext")}function w(){S("addWidgetToSelectedReport")}function F(t){e.chartBox=t}function C(){e.$watch("data.datapoints",function(){e.dontSave||r.saveLocal(e.data.datapoints,f)},!0)}function x(t,a){i.addAction({text:t,action:function(){var t={dateFrom:moment(e.data.dateFrom).format(c.dateFullFormat),dateTo:moment(e.data.dateTo).format(c.dateFullFormat)};m.downloadReportForDatapoints(a,e.data.graphDataPoints,t).catch(function(t){t&&t.message&&d.warning(t.message)})}})}e.onRealtimeAlarmFn=function(t){e.onAlarm=t},e.onRealtimeEventFn=function(t){e.onEvent=t},!o.getContext().context&&t.path().match(/datapoint/)&&a.changeTitle({title:s("Data explorer")}),A(),t={text:s(f?"Send as widget to dashboard":"Send as widget to report"),action:f?D:w},b()&&!e.noActions&&i.addAction(t),_.get(e,"data.datapoints.length")||r.listLocal(f).then(function(t){t&&t.length&&h(t,!0)}).then(C),e.noActions||(x(s("Download as CSV"),u.format.csv),x(s("Download as Excel"),u.format.xlsx)),$(window).resize(function(){e.$broadcast("dashboardResize"),e.$apply()}),e.onBoxChanged=F,e.onUpdateDates=function(t,a){e.data.dateFrom=t;t=moment().diff(moment(a),"seconds")<5;e.data.realtime&&!t&&(e.data.realtime=!1),e.data.dateTo=a},e.onUpdateDisplayedDates=function(t,a){e.data.displayedDateFrom=t,e.data.displayedDateTo=a},e.savedFilter={config:{},datapoints:[]},e.data=e.data||_.cloneDeep(e.savedFilter),(p=e.data.interval)&&"custom"!==p&&(t=_.find(g.intervals,function(t){return t.id===p})||{}).qty&&(e.data.dateFrom=moment().subtract(t.qty,t.unit).toDate(),e.data.dateTo=moment().toDate()),e.$watch("data.datapoints",function(){return h(e.data.datapoints)},!0),e.$watch("data.alarmsEventsConfigs",y,!0)}t.$inject=["$scope","$location","$injector","c8yUiUtil","c8yTitle","c8yDataPointSvc","c8yActions","c8yAlert","c8yBase","gettext","gettextCatalog","c8yMeasurements","MeasurementsReportSvc","INTERVAL_CONSTANTS"],angular.module("c8y.cockpit.dataPointExplorer").controller("c8yDataPointExplorerCtrl",t)})();