Built motion from commit (unavailable).|2.5.10
[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 _0x6d1d=['end','json','count','offset','limit','set','reject','save','update','then','destroy','error','stack','name','send','show','params','model','DashboardItem','rawAttributes','query','keys','filters','intersection','fields','attributes','includeAll','include','merge','options','find','catch','type','iframe','attrUrl','attrs','value','https://','custom','attrPath','clock','attrHourFormat','HH:mm:ss','attrTimezone','attrFontSize','attrMetric','total','attrVoiceQueues','pie-chart','attrSerie1','attrSerie2','attrSerie3','reportType','attrReport','attrRefresh','widgetAttributes:\x20%s','stringify','create','body','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','util','path','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','defaults','redis','localhost','socket.io-emitter','./dashboardItem.socket','register','sendStatus','status'];(function(_0x54f06d,_0x28b7d3){var _0x341896=function(_0x3749fc){while(--_0x3749fc){_0x54f06d['push'](_0x54f06d['shift']());}};_0x341896(++_0x28b7d3);}(_0x6d1d,0x1b7));var _0xd6d1=function(_0x35fa3f,_0x500d59){_0x35fa3f=_0x35fa3f-0x0;var _0x158869=_0x6d1d[_0x35fa3f];return _0x158869;};'use strict';var pdf=require(_0xd6d1('0x0'));var emlformat=require(_0xd6d1('0x1'));var rimraf=require(_0xd6d1('0x2'));var zipdir=require(_0xd6d1('0x3'));var jsonpatch=require(_0xd6d1('0x4'));var rp=require(_0xd6d1('0x5'));var moment=require(_0xd6d1('0x6'));var BPromise=require(_0xd6d1('0x7'));var Mustache=require('mustache');var util=require(_0xd6d1('0x8'));var path=require(_0xd6d1('0x9'));var sox=require('sox');var csv=require(_0xd6d1('0xa'));var ejs=require(_0xd6d1('0xb'));var fs=require('fs');var _=require(_0xd6d1('0xc'));var squel=require(_0xd6d1('0xd'));var crypto=require(_0xd6d1('0xe'));var jsforce=require(_0xd6d1('0xf'));var deskjs=require(_0xd6d1('0x10'));var toCsv=require(_0xd6d1('0xa'));var querystring=require(_0xd6d1('0x11'));var Papa=require(_0xd6d1('0x12'));var Redis=require('ioredis');var authService=require(_0xd6d1('0x13'));var qs=require(_0xd6d1('0x14'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xd6d1('0x15'));var logger=require(_0xd6d1('0x16'))(_0xd6d1('0x17'));var utils=require(_0xd6d1('0x18'));var config=require(_0xd6d1('0x19'));var licenseUtil=require(_0xd6d1('0x1a'));var db=require(_0xd6d1('0x1b'))['db'];config['redis']=_[_0xd6d1('0x1c')](config[_0xd6d1('0x1d')],{'host':_0xd6d1('0x1e'),'port':0x18eb});var socket=require(_0xd6d1('0x1f'))(new Redis(config[_0xd6d1('0x1d')]));require(_0xd6d1('0x20'))[_0xd6d1('0x21')](socket);function respondWithStatusCode(_0xfd50f3,_0x443fda){_0x443fda=_0x443fda||0xcc;return function(_0x1e37a0){if(_0x1e37a0){return _0xfd50f3[_0xd6d1('0x22')](_0x443fda);}return _0xfd50f3[_0xd6d1('0x23')](_0x443fda)[_0xd6d1('0x24')]();};}function respondWithResult(_0x42b6df,_0x5a9c3f){_0x5a9c3f=_0x5a9c3f||0xc8;return function(_0x439f9f){if(_0x439f9f){return _0x42b6df[_0xd6d1('0x23')](_0x5a9c3f)[_0xd6d1('0x25')](_0x439f9f);}};}function respondWithFilteredResult(_0x4ee508,_0x51cefe){return function(_0x57e76c){if(_0x57e76c){var _0x43eb66=_0x57e76c[_0xd6d1('0x26')],_0x1333e4=_0x51cefe[_0xd6d1('0x27')],_0x2d6290=_0x51cefe[_0xd6d1('0x27')]+_0x51cefe[_0xd6d1('0x28')],_0x460984;if(_0x2d6290>=_0x43eb66){_0x2d6290=_0x43eb66;_0x460984=0xc8;}else{_0x460984=0xce;}_0x4ee508['status'](_0x460984);return _0x4ee508[_0xd6d1('0x29')]('Content-Range',_0x1333e4+'-'+_0x2d6290+'/'+_0x43eb66)[_0xd6d1('0x25')](_0x57e76c);}return null;};}function patchUpdates(_0x127106){return function(_0x8b95fa){try{jsonpatch['apply'](_0x8b95fa,_0x127106,!![]);}catch(_0x44173e){return BPromise[_0xd6d1('0x2a')](_0x44173e);}return _0x8b95fa[_0xd6d1('0x2b')]();};}function saveUpdates(_0x551bb8,_0x4e9427){return function(_0x1e4208){if(_0x1e4208){return _0x1e4208[_0xd6d1('0x2c')](_0x551bb8)[_0xd6d1('0x2d')](function(_0x33cab3){return _0x33cab3;});}return null;};}function removeEntity(_0x35f7dd,_0x5e5df8){return function(_0x136876){if(_0x136876){return _0x136876[_0xd6d1('0x2e')]()[_0xd6d1('0x2d')](function(){_0x35f7dd[_0xd6d1('0x23')](0xcc)['end']();});}};}function handleEntityNotFound(_0x1c5725,_0x31c8ee){return function(_0x19fdd0){if(!_0x19fdd0){_0x1c5725['sendStatus'](0x194);}return _0x19fdd0;};}function handleError(_0x14223f,_0x3793f9){_0x3793f9=_0x3793f9||0x1f4;return function(_0x965bb1){logger[_0xd6d1('0x2f')](_0x965bb1[_0xd6d1('0x30')]);if(_0x965bb1[_0xd6d1('0x31')]){delete _0x965bb1['name'];}_0x14223f[_0xd6d1('0x23')](_0x3793f9)[_0xd6d1('0x32')](_0x965bb1);};}exports[_0xd6d1('0x33')]=function(_0x3db72c,_0x1434c0){var _0x12f7de={'raw':![],'where':{'id':_0x3db72c[_0xd6d1('0x34')]['id']}},_0x59900e={};_0x59900e[_0xd6d1('0x35')]=_['keys'](db[_0xd6d1('0x36')][_0xd6d1('0x37')]);_0x59900e[_0xd6d1('0x38')]=_[_0xd6d1('0x39')](_0x3db72c[_0xd6d1('0x38')]);_0x59900e[_0xd6d1('0x3a')]=_[_0xd6d1('0x3b')](_0x59900e['model'],_0x59900e[_0xd6d1('0x38')]);_0x12f7de['attributes']=_[_0xd6d1('0x3b')](_0x59900e[_0xd6d1('0x35')],qs[_0xd6d1('0x3c')](_0x3db72c[_0xd6d1('0x38')][_0xd6d1('0x3c')]));_0x12f7de[_0xd6d1('0x3d')]=_0x12f7de[_0xd6d1('0x3d')]['length']?_0x12f7de['attributes']:_0x59900e[_0xd6d1('0x35')];if(_0x3db72c[_0xd6d1('0x38')][_0xd6d1('0x3e')]){_0x12f7de[_0xd6d1('0x3f')]=[{'all':!![]}];}_0x12f7de=_[_0xd6d1('0x40')]({},_0x12f7de,_0x3db72c[_0xd6d1('0x41')]);return db['DashboardItem'][_0xd6d1('0x42')](_0x12f7de)[_0xd6d1('0x2d')](handleEntityNotFound(_0x1434c0,null))[_0xd6d1('0x2d')](respondWithResult(_0x1434c0,null))[_0xd6d1('0x43')](handleError(_0x1434c0,null));};exports[_0xd6d1('0x2e')]=function(_0x1de9cc,_0xa66c0){return db[_0xd6d1('0x36')][_0xd6d1('0x42')]({'where':{'id':_0x1de9cc[_0xd6d1('0x34')]['id']}})['then'](handleEntityNotFound(_0xa66c0,null))[_0xd6d1('0x2d')](removeEntity(_0xa66c0,null))['catch'](handleError(_0xa66c0,null));};function widgetAttributes(_0x587d61){try{switch(_0x587d61[_0xd6d1('0x44')]){case _0xd6d1('0x45'):return[{'name':_0xd6d1('0x46'),'value':_0x587d61['attrUrl']||(_0x587d61['attrs']&&_0x587d61[_0xd6d1('0x47')][0x0]?_0x587d61[_0xd6d1('0x47')][0x0][_0xd6d1('0x48')]:undefined)||_0xd6d1('0x49')}];case _0xd6d1('0x4a'):return[{'name':_0xd6d1('0x4b'),'value':_0x587d61[_0xd6d1('0x4b')]||(_0x587d61[_0xd6d1('0x47')]&&_0x587d61[_0xd6d1('0x47')][0x0]?_0x587d61['attrs'][0x0][_0xd6d1('0x48')]:undefined)||''}];case _0xd6d1('0x4c'):return[{'name':_0xd6d1('0x4d'),'value':_0x587d61['attrHourFormat']||(_0x587d61[_0xd6d1('0x47')]&&_0x587d61[_0xd6d1('0x47')][0x0]?_0x587d61['attrs'][0x0][_0xd6d1('0x48')]:undefined)||_0xd6d1('0x4e')},{'name':_0xd6d1('0x4f'),'value':_0x587d61['attrTimezone']||(_0x587d61['attrs']&&_0x587d61[_0xd6d1('0x47')][0x1]?_0x587d61[_0xd6d1('0x47')][0x1][_0xd6d1('0x48')]:undefined)||'0.00'},{'name':_0xd6d1('0x50'),'value':_0x587d61[_0xd6d1('0x50')]||(_0x587d61[_0xd6d1('0x47')]&&_0x587d61[_0xd6d1('0x47')][0x2]?_0x587d61[_0xd6d1('0x47')][0x2]['value']:undefined)||0xc}];case'counter':return[{'name':_0xd6d1('0x51'),'value':_0x587d61[_0xd6d1('0x51')]||(_0x587d61[_0xd6d1('0x47')]&&_0x587d61[_0xd6d1('0x47')][0x0]?_0x587d61['attrs'][0x0]['value']:undefined)||_0xd6d1('0x52')},{'name':_0xd6d1('0x53'),'value':_0x587d61['attrVoiceQueues']||(_0x587d61[_0xd6d1('0x47')]&&_0x587d61['attrs'][0x1]?_0x587d61[_0xd6d1('0x47')][0x1][_0xd6d1('0x48')]:undefined)||[]},{'name':_0xd6d1('0x50'),'value':_0x587d61[_0xd6d1('0x50')]||(_0x587d61['attrs']&&_0x587d61[_0xd6d1('0x47')][0x2]?_0x587d61[_0xd6d1('0x47')][0x2][_0xd6d1('0x48')]:undefined)||0x14}];case'multibar-chart':case _0xd6d1('0x54'):return[{'name':_0xd6d1('0x55'),'value':_0x587d61[_0xd6d1('0x55')]||(_0x587d61[_0xd6d1('0x47')]&&_0x587d61['attrs'][0x0]?_0x587d61[_0xd6d1('0x47')][0x0][_0xd6d1('0x48')]:undefined)||_0xd6d1('0x52')},{'name':'attrSerie2','value':_0x587d61[_0xd6d1('0x56')]||(_0x587d61[_0xd6d1('0x47')]&&_0x587d61[_0xd6d1('0x47')][0x1]?_0x587d61[_0xd6d1('0x47')][0x1]['value']:undefined)||null},{'name':_0xd6d1('0x57'),'value':_0x587d61[_0xd6d1('0x57')]||(_0x587d61[_0xd6d1('0x47')]&&_0x587d61[_0xd6d1('0x47')][0x2]?_0x587d61[_0xd6d1('0x47')][0x2]['value']:undefined)||null},{'name':_0xd6d1('0x53'),'value':_0x587d61[_0xd6d1('0x53')]||(_0x587d61['attrs']&&_0x587d61[_0xd6d1('0x47')][0x3]?_0x587d61[_0xd6d1('0x47')][0x3][_0xd6d1('0x48')]:undefined)||[]}];case'web-report':return[{'name':'attrReport','type':_0x587d61[_0xd6d1('0x58')]||(_0x587d61[_0xd6d1('0x47')]&&_0x587d61[_0xd6d1('0x47')][0x0]?_0x587d61[_0xd6d1('0x47')][0x0][_0xd6d1('0x44')]:undefined)||null,'value':_0x587d61[_0xd6d1('0x59')]||(_0x587d61['attrs']&&_0x587d61[_0xd6d1('0x47')][0x0]?_0x587d61['attrs'][0x0][_0xd6d1('0x48')]:undefined)||null},{'name':_0xd6d1('0x5a'),'value':_0x587d61[_0xd6d1('0x5a')]||(_0x587d61[_0xd6d1('0x47')]&&_0x587d61['attrs'][0x1]?_0x587d61[_0xd6d1('0x47')][0x1][_0xd6d1('0x48')]:undefined)||0x0}];default:return[];}}catch(_0x1965e6){logger[_0xd6d1('0x2f')](_0xd6d1('0x5b'),JSON[_0xd6d1('0x5c')](_0x1965e6));return[];}}exports[_0xd6d1('0x5d')]=function(_0x4e599d,_0x3f6022){if(_0x4e599d['body']){_0x4e599d[_0xd6d1('0x5e')][_0xd6d1('0x47')]=widgetAttributes(_0x4e599d[_0xd6d1('0x5e')]);}return db['DashboardItem'][_0xd6d1('0x5d')](_0x4e599d[_0xd6d1('0x5e')],{})[_0xd6d1('0x2d')](respondWithResult(_0x3f6022,0xc9))[_0xd6d1('0x43')](handleError(_0x3f6022,null));};exports[_0xd6d1('0x2c')]=function(_0x1581f2,_0x191788){if(_0x1581f2[_0xd6d1('0x5e')]['id']){delete _0x1581f2[_0xd6d1('0x5e')]['id'];}_0x1581f2[_0xd6d1('0x5e')][_0xd6d1('0x47')]=widgetAttributes(_0x1581f2[_0xd6d1('0x5e')]);return db['DashboardItem'][_0xd6d1('0x42')]({'where':{'id':_0x1581f2[_0xd6d1('0x34')]['id']}})['then'](handleEntityNotFound(_0x191788,null))[_0xd6d1('0x2d')](saveUpdates(_0x1581f2[_0xd6d1('0x5e')],null))['then'](respondWithResult(_0x191788,null))['catch'](handleError(_0x191788,null));};