Built motion from commit 0900f080.|2.5.45
[motion2.git] / server / api / dashboardItem / dashboardItem.controller.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0xcb04=['then','destroy','sendStatus','stack','name','send','model','rawAttributes','query','intersection','attributes','fields','length','includeAll','include','DashboardItem','find','params','catch','type','iframe','attrUrl','attrs','custom','attrPath','value','clock','attrHourFormat','attrTimezone','attrFontSize','counter','attrMetric','total','attrVoiceQueues','attrChannel','voice','attrEmailAccounts','attrFaxAccounts','attrSmsAccounts','attrOpenchannelAccounts','attrChatWebsites','attrSerie1','attrSerie2','attrSerie3','attrWhatsappAccounts','web-report','attrReport','reportType','attrRefresh','error','widgetAttributes:\x20%s','stringify','create','body','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','redis','localhost','socket.io-emitter','./dashboardItem.socket','register','status','end','json','offset','undefined','limit','set','apply','reject','save','update'];(function(_0x17d9e3,_0x1f969c){var _0x14192d=function(_0x159745){while(--_0x159745){_0x17d9e3['push'](_0x17d9e3['shift']());}};_0x14192d(++_0x1f969c);}(_0xcb04,0x9a));var _0x4cb0=function(_0x14add3,_0x13ce8d){_0x14add3=_0x14add3-0x0;var _0x4a174f=_0xcb04[_0x14add3];return _0x4a174f;};'use strict';var emlformat=require(_0x4cb0('0x0'));var rimraf=require(_0x4cb0('0x1'));var zipdir=require(_0x4cb0('0x2'));var jsonpatch=require(_0x4cb0('0x3'));var rp=require(_0x4cb0('0x4'));var moment=require(_0x4cb0('0x5'));var BPromise=require(_0x4cb0('0x6'));var Mustache=require(_0x4cb0('0x7'));var util=require(_0x4cb0('0x8'));var path=require(_0x4cb0('0x9'));var sox=require('sox');var csv=require(_0x4cb0('0xa'));var ejs=require(_0x4cb0('0xb'));var fs=require('fs');var fs_extra=require(_0x4cb0('0xc'));var _=require(_0x4cb0('0xd'));var squel=require(_0x4cb0('0xe'));var crypto=require(_0x4cb0('0xf'));var jsforce=require(_0x4cb0('0x10'));var deskjs=require(_0x4cb0('0x11'));var toCsv=require(_0x4cb0('0xa'));var querystring=require(_0x4cb0('0x12'));var Papa=require(_0x4cb0('0x13'));var Redis=require(_0x4cb0('0x14'));var authService=require(_0x4cb0('0x15'));var qs=require(_0x4cb0('0x16'));var as=require(_0x4cb0('0x17'));var hardwareService=require(_0x4cb0('0x18'));var logger=require(_0x4cb0('0x19'))(_0x4cb0('0x1a'));var utils=require('../../config/utils');var config=require(_0x4cb0('0x1b'));var licenseUtil=require(_0x4cb0('0x1c'));var db=require(_0x4cb0('0x1d'))['db'];config[_0x4cb0('0x1e')]=_['defaults'](config[_0x4cb0('0x1e')],{'host':_0x4cb0('0x1f'),'port':0x18eb});var socket=require(_0x4cb0('0x20'))(new Redis(config[_0x4cb0('0x1e')]));require(_0x4cb0('0x21'))[_0x4cb0('0x22')](socket);function respondWithStatusCode(_0x2738aa,_0x3014ae){_0x3014ae=_0x3014ae||0xcc;return function(_0x246605){if(_0x246605){return _0x2738aa['sendStatus'](_0x3014ae);}return _0x2738aa[_0x4cb0('0x23')](_0x3014ae)[_0x4cb0('0x24')]();};}function respondWithResult(_0x1317e9,_0x3bbe1a){_0x3bbe1a=_0x3bbe1a||0xc8;return function(_0x53838b){if(_0x53838b){return _0x1317e9['status'](_0x3bbe1a)[_0x4cb0('0x25')](_0x53838b);}};}function respondWithFilteredResult(_0x33f7ef,_0x1e4659){return function(_0x91d3b){if(_0x91d3b){var _0x248e22=typeof _0x1e4659[_0x4cb0('0x26')]===_0x4cb0('0x27')&&typeof _0x1e4659['limit']==='undefined';var _0x30ba5a=_0x91d3b['count'];var _0x4ca756=_0x248e22?0x0:_0x1e4659[_0x4cb0('0x26')];var _0x3b2f0c=_0x248e22?_0x91d3b['count']:_0x1e4659[_0x4cb0('0x26')]+_0x1e4659[_0x4cb0('0x28')];var _0x2def01;if(_0x3b2f0c>=_0x30ba5a){_0x3b2f0c=_0x30ba5a;_0x2def01=0xc8;}else{_0x2def01=0xce;}_0x33f7ef['status'](_0x2def01);return _0x33f7ef[_0x4cb0('0x29')]('Content-Range',_0x4ca756+'-'+_0x3b2f0c+'/'+_0x30ba5a)[_0x4cb0('0x25')](_0x91d3b);}return null;};}function patchUpdates(_0x3196e0){return function(_0x267c74){try{jsonpatch[_0x4cb0('0x2a')](_0x267c74,_0x3196e0,!![]);}catch(_0x4f12e6){return BPromise[_0x4cb0('0x2b')](_0x4f12e6);}return _0x267c74[_0x4cb0('0x2c')]();};}function saveUpdates(_0x53fdd3,_0x485c9f){return function(_0x3456ef){if(_0x3456ef){return _0x3456ef[_0x4cb0('0x2d')](_0x53fdd3)[_0x4cb0('0x2e')](function(_0x188623){return _0x188623;});}return null;};}function removeEntity(_0x325745,_0x3710eb){return function(_0x1688c5){if(_0x1688c5){return _0x1688c5[_0x4cb0('0x2f')]()[_0x4cb0('0x2e')](function(){_0x325745[_0x4cb0('0x23')](0xcc)[_0x4cb0('0x24')]();});}};}function handleEntityNotFound(_0xde2bd9,_0x50f9eb){return function(_0x2f3b9f){if(!_0x2f3b9f){_0xde2bd9[_0x4cb0('0x30')](0x194);}return _0x2f3b9f;};}function handleError(_0x4417df,_0x347dfd){_0x347dfd=_0x347dfd||0x1f4;return function(_0x25a25d){logger['error'](_0x25a25d[_0x4cb0('0x31')]);if(_0x25a25d['name']){delete _0x25a25d[_0x4cb0('0x32')];}_0x4417df[_0x4cb0('0x23')](_0x347dfd)[_0x4cb0('0x33')](_0x25a25d);};}exports['show']=function(_0x2182bc,_0xf1bdc1){var _0x1abab2={'raw':![],'where':{'id':_0x2182bc['params']['id']}},_0xe3ae3a={};_0xe3ae3a[_0x4cb0('0x34')]=_['keys'](db['DashboardItem'][_0x4cb0('0x35')]);_0xe3ae3a[_0x4cb0('0x36')]=_['keys'](_0x2182bc[_0x4cb0('0x36')]);_0xe3ae3a['filters']=_[_0x4cb0('0x37')](_0xe3ae3a[_0x4cb0('0x34')],_0xe3ae3a[_0x4cb0('0x36')]);_0x1abab2[_0x4cb0('0x38')]=_['intersection'](_0xe3ae3a[_0x4cb0('0x34')],qs[_0x4cb0('0x39')](_0x2182bc[_0x4cb0('0x36')][_0x4cb0('0x39')]));_0x1abab2[_0x4cb0('0x38')]=_0x1abab2[_0x4cb0('0x38')][_0x4cb0('0x3a')]?_0x1abab2['attributes']:_0xe3ae3a[_0x4cb0('0x34')];if(_0x2182bc[_0x4cb0('0x36')][_0x4cb0('0x3b')]){_0x1abab2[_0x4cb0('0x3c')]=[{'all':!![]}];}_0x1abab2=_['merge']({},_0x1abab2,_0x2182bc['options']);return db[_0x4cb0('0x3d')]['find'](_0x1abab2)[_0x4cb0('0x2e')](handleEntityNotFound(_0xf1bdc1,null))[_0x4cb0('0x2e')](respondWithResult(_0xf1bdc1,null))['catch'](handleError(_0xf1bdc1,null));};exports[_0x4cb0('0x2f')]=function(_0x58bd51,_0x444d7e){return db[_0x4cb0('0x3d')][_0x4cb0('0x3e')]({'where':{'id':_0x58bd51[_0x4cb0('0x3f')]['id']}})['then'](handleEntityNotFound(_0x444d7e,null))[_0x4cb0('0x2e')](removeEntity(_0x444d7e,null))[_0x4cb0('0x40')](handleError(_0x444d7e,null));};function widgetAttributes(_0x139efc){try{switch(_0x139efc[_0x4cb0('0x41')]){case _0x4cb0('0x42'):return[{'name':_0x4cb0('0x43'),'value':_0x139efc[_0x4cb0('0x43')]||(_0x139efc[_0x4cb0('0x44')]&&_0x139efc[_0x4cb0('0x44')][0x0]?_0x139efc[_0x4cb0('0x44')][0x0]['value']:undefined)||'https://'}];case _0x4cb0('0x45'):return[{'name':'attrPath','value':_0x139efc[_0x4cb0('0x46')]||(_0x139efc[_0x4cb0('0x44')]&&_0x139efc[_0x4cb0('0x44')][0x0]?_0x139efc['attrs'][0x0][_0x4cb0('0x47')]:undefined)||''}];case _0x4cb0('0x48'):return[{'name':_0x4cb0('0x49'),'value':_0x139efc['attrHourFormat']||(_0x139efc[_0x4cb0('0x44')]&&_0x139efc[_0x4cb0('0x44')][0x0]?_0x139efc[_0x4cb0('0x44')][0x0][_0x4cb0('0x47')]:undefined)||'HH:mm:ss'},{'name':_0x4cb0('0x4a'),'value':_0x139efc[_0x4cb0('0x4a')]||(_0x139efc[_0x4cb0('0x44')]&&_0x139efc[_0x4cb0('0x44')][0x1]?_0x139efc[_0x4cb0('0x44')][0x1]['value']:undefined)||'0.00'},{'name':_0x4cb0('0x4b'),'value':_0x139efc[_0x4cb0('0x4b')]||(_0x139efc[_0x4cb0('0x44')]&&_0x139efc['attrs'][0x2]?_0x139efc['attrs'][0x2][_0x4cb0('0x47')]:undefined)||0xc}];case _0x4cb0('0x4c'):return[{'name':_0x4cb0('0x4d'),'value':_0x139efc[_0x4cb0('0x4d')]||(_0x139efc['attrs']&&_0x139efc[_0x4cb0('0x44')][0x0]?_0x139efc[_0x4cb0('0x44')][0x0][_0x4cb0('0x47')]:undefined)||_0x4cb0('0x4e')},{'name':_0x4cb0('0x4f'),'value':_0x139efc[_0x4cb0('0x4f')]||(_0x139efc[_0x4cb0('0x44')]&&_0x139efc['attrs'][0x1]?_0x139efc['attrs'][0x1][_0x4cb0('0x47')]:undefined)||[]},{'name':_0x4cb0('0x4b'),'value':_0x139efc[_0x4cb0('0x4b')]||(_0x139efc['attrs']&&_0x139efc[_0x4cb0('0x44')][0x2]?_0x139efc['attrs'][0x2]['value']:undefined)||0x14},{'name':'attrChannel','value':_0x139efc[_0x4cb0('0x50')]||(_0x139efc[_0x4cb0('0x44')]&&_0x139efc[_0x4cb0('0x44')][0x3]?_0x139efc[_0x4cb0('0x44')][0x3][_0x4cb0('0x47')]:undefined)||_0x4cb0('0x51')},{'name':'attrEmailAccounts','value':_0x139efc[_0x4cb0('0x52')]||(_0x139efc[_0x4cb0('0x44')]&&_0x139efc[_0x4cb0('0x44')][0x4]?_0x139efc['attrs'][0x4][_0x4cb0('0x47')]:undefined)||''},{'name':'attrFaxAccounts','value':_0x139efc[_0x4cb0('0x53')]||(_0x139efc[_0x4cb0('0x44')]&&_0x139efc['attrs'][0x5]?_0x139efc[_0x4cb0('0x44')][0x5][_0x4cb0('0x47')]:undefined)||''},{'name':_0x4cb0('0x54'),'value':_0x139efc[_0x4cb0('0x54')]||(_0x139efc[_0x4cb0('0x44')]&&_0x139efc[_0x4cb0('0x44')][0x6]?_0x139efc['attrs'][0x6][_0x4cb0('0x47')]:undefined)||''},{'name':_0x4cb0('0x55'),'value':_0x139efc['attrOpenchannelAccounts']||(_0x139efc[_0x4cb0('0x44')]&&_0x139efc[_0x4cb0('0x44')][0x7]?_0x139efc[_0x4cb0('0x44')][0x7][_0x4cb0('0x47')]:undefined)||''},{'name':'attrWhatsappAccounts','value':_0x139efc['attrWhatsappAccounts']||(_0x139efc[_0x4cb0('0x44')]&&_0x139efc['attrs'][0x8]?_0x139efc[_0x4cb0('0x44')][0x8][_0x4cb0('0x47')]:undefined)||''},{'name':_0x4cb0('0x56'),'value':_0x139efc['attrChatWebsites']||(_0x139efc[_0x4cb0('0x44')]&&_0x139efc[_0x4cb0('0x44')][0x9]?_0x139efc[_0x4cb0('0x44')][0x9][_0x4cb0('0x47')]:undefined)||''}];case'multibar-chart':case'pie-chart':return[{'name':_0x4cb0('0x57'),'value':_0x139efc[_0x4cb0('0x57')]||(_0x139efc[_0x4cb0('0x44')]&&_0x139efc[_0x4cb0('0x44')][0x0]?_0x139efc[_0x4cb0('0x44')][0x0][_0x4cb0('0x47')]:undefined)||_0x4cb0('0x4e')},{'name':_0x4cb0('0x58'),'value':_0x139efc[_0x4cb0('0x58')]||(_0x139efc[_0x4cb0('0x44')]&&_0x139efc[_0x4cb0('0x44')][0x1]?_0x139efc[_0x4cb0('0x44')][0x1]['value']:undefined)||null},{'name':'attrSerie3','value':_0x139efc[_0x4cb0('0x59')]||(_0x139efc[_0x4cb0('0x44')]&&_0x139efc[_0x4cb0('0x44')][0x2]?_0x139efc[_0x4cb0('0x44')][0x2]['value']:undefined)||null},{'name':'attrVoiceQueues','value':_0x139efc[_0x4cb0('0x4f')]||(_0x139efc['attrs']&&_0x139efc['attrs'][0x3]?_0x139efc[_0x4cb0('0x44')][0x3][_0x4cb0('0x47')]:undefined)||[]},{'name':_0x4cb0('0x50'),'value':_0x139efc[_0x4cb0('0x50')]||(_0x139efc[_0x4cb0('0x44')]&&_0x139efc['attrs'][0x4]?_0x139efc[_0x4cb0('0x44')][0x4]['value']:undefined)||_0x4cb0('0x51')},{'name':_0x4cb0('0x52'),'value':_0x139efc[_0x4cb0('0x52')]||(_0x139efc[_0x4cb0('0x44')]&&_0x139efc[_0x4cb0('0x44')][0x5]?_0x139efc[_0x4cb0('0x44')][0x5][_0x4cb0('0x47')]:undefined)||''},{'name':_0x4cb0('0x53'),'value':_0x139efc['attrFaxAccounts']||(_0x139efc[_0x4cb0('0x44')]&&_0x139efc[_0x4cb0('0x44')][0x6]?_0x139efc[_0x4cb0('0x44')][0x6][_0x4cb0('0x47')]:undefined)||''},{'name':_0x4cb0('0x54'),'value':_0x139efc['attrSmsAccounts']||(_0x139efc[_0x4cb0('0x44')]&&_0x139efc['attrs'][0x7]?_0x139efc[_0x4cb0('0x44')][0x7][_0x4cb0('0x47')]:undefined)||''},{'name':'attrOpenchannelAccounts','value':_0x139efc[_0x4cb0('0x55')]||(_0x139efc[_0x4cb0('0x44')]&&_0x139efc['attrs'][0x8]?_0x139efc[_0x4cb0('0x44')][0x8][_0x4cb0('0x47')]:undefined)||''},{'name':_0x4cb0('0x5a'),'value':_0x139efc[_0x4cb0('0x5a')]||(_0x139efc[_0x4cb0('0x44')]&&_0x139efc[_0x4cb0('0x44')][0x9]?_0x139efc[_0x4cb0('0x44')][0x9]['value']:undefined)||''},{'name':'attrChatWebsites','value':_0x139efc[_0x4cb0('0x56')]||(_0x139efc['attrs']&&_0x139efc[_0x4cb0('0x44')][0xa]?_0x139efc[_0x4cb0('0x44')][0xa]['value']:undefined)||''}];case _0x4cb0('0x5b'):return[{'name':_0x4cb0('0x5c'),'type':_0x139efc[_0x4cb0('0x5d')]||(_0x139efc[_0x4cb0('0x44')]&&_0x139efc[_0x4cb0('0x44')][0x0]?_0x139efc[_0x4cb0('0x44')][0x0][_0x4cb0('0x41')]:undefined)||null,'value':_0x139efc[_0x4cb0('0x5c')]||(_0x139efc[_0x4cb0('0x44')]&&_0x139efc[_0x4cb0('0x44')][0x0]?_0x139efc[_0x4cb0('0x44')][0x0][_0x4cb0('0x47')]:undefined)||null},{'name':_0x4cb0('0x5e'),'value':_0x139efc['attrRefresh']||(_0x139efc[_0x4cb0('0x44')]&&_0x139efc['attrs'][0x1]?_0x139efc['attrs'][0x1]['value']:undefined)||0x0}];default:return[];}}catch(_0x597abc){logger[_0x4cb0('0x5f')](_0x4cb0('0x60'),JSON[_0x4cb0('0x61')](_0x597abc));return[];}}exports[_0x4cb0('0x62')]=function(_0x490b6f,_0xda9228){if(_0x490b6f[_0x4cb0('0x63')]){_0x490b6f['body'][_0x4cb0('0x44')]=widgetAttributes(_0x490b6f[_0x4cb0('0x63')]);}return db['DashboardItem'][_0x4cb0('0x62')](_0x490b6f[_0x4cb0('0x63')],{})[_0x4cb0('0x2e')](respondWithResult(_0xda9228,0xc9))['catch'](handleError(_0xda9228,null));};exports[_0x4cb0('0x2d')]=function(_0x46178c,_0x53f01c){if(_0x46178c[_0x4cb0('0x63')]['id']){delete _0x46178c[_0x4cb0('0x63')]['id'];}_0x46178c[_0x4cb0('0x63')][_0x4cb0('0x44')]=widgetAttributes(_0x46178c[_0x4cb0('0x63')]);return db[_0x4cb0('0x3d')][_0x4cb0('0x3e')]({'where':{'id':_0x46178c[_0x4cb0('0x3f')]['id']}})[_0x4cb0('0x2e')](handleEntityNotFound(_0x53f01c,null))['then'](saveUpdates(_0x46178c['body'],null))[_0x4cb0('0x2e')](respondWithResult(_0x53f01c,null))[_0x4cb0('0x40')](handleError(_0x53f01c,null));};