Built motion from commit 753c950e.|2.5.42
[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 _0x40f3=['keys','rawAttributes','query','filters','intersection','model','fields','length','attributes','includeAll','merge','options','DashboardItem','find','catch','destroy','attrUrl','attrs','value','attrPath','clock','HH:mm:ss','attrTimezone','0.00','attrFontSize','attrMetric','total','attrVoiceQueues','attrChannel','voice','attrEmailAccounts','attrFaxAccounts','attrWhatsappAccounts','attrSerie1','attrSerie3','attrSmsAccounts','attrOpenchannelAccounts','attrChatWebsites','web-report','attrReport','reportType','type','attrRefresh','widgetAttributes:\x20%s','body','create','update','rimraf','zip-dir','request-promise','moment','util','path','to-csv','lodash','squel','crypto','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','defaults','redis','localhost','./dashboardItem.socket','register','sendStatus','status','json','offset','limit','undefined','count','set','Content-Range','apply','reject','save','then','end','error','name','send','show','params'];(function(_0x1f1c40,_0x3122d8){var _0x50ae90=function(_0x50b309){while(--_0x50b309){_0x1f1c40['push'](_0x1f1c40['shift']());}};_0x50ae90(++_0x3122d8);}(_0x40f3,0x8b));var _0x340f=function(_0x648163,_0x241576){_0x648163=_0x648163-0x0;var _0x199d4d=_0x40f3[_0x648163];return _0x199d4d;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x340f('0x0'));var zipdir=require(_0x340f('0x1'));var jsonpatch=require('fast-json-patch');var rp=require(_0x340f('0x2'));var moment=require(_0x340f('0x3'));var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0x340f('0x4'));var path=require(_0x340f('0x5'));var sox=require('sox');var csv=require(_0x340f('0x6'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x340f('0x7'));var squel=require(_0x340f('0x8'));var crypto=require(_0x340f('0x9'));var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0x340f('0x6'));var querystring=require(_0x340f('0xa'));var Papa=require(_0x340f('0xb'));var Redis=require(_0x340f('0xc'));var authService=require(_0x340f('0xd'));var qs=require(_0x340f('0xe'));var as=require(_0x340f('0xf'));var hardwareService=require(_0x340f('0x10'));var logger=require(_0x340f('0x11'))(_0x340f('0x12'));var utils=require(_0x340f('0x13'));var config=require('../../config/environment');var licenseUtil=require(_0x340f('0x14'));var db=require('../../mysqldb')['db'];config['redis']=_[_0x340f('0x15')](config[_0x340f('0x16')],{'host':_0x340f('0x17'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x340f('0x16')]));require(_0x340f('0x18'))[_0x340f('0x19')](socket);function respondWithStatusCode(_0x20beeb,_0x58e42f){_0x58e42f=_0x58e42f||0xcc;return function(_0x2fb52a){if(_0x2fb52a){return _0x20beeb[_0x340f('0x1a')](_0x58e42f);}return _0x20beeb[_0x340f('0x1b')](_0x58e42f)['end']();};}function respondWithResult(_0x14d631,_0x230101){_0x230101=_0x230101||0xc8;return function(_0x490ae6){if(_0x490ae6){return _0x14d631[_0x340f('0x1b')](_0x230101)[_0x340f('0x1c')](_0x490ae6);}};}function respondWithFilteredResult(_0x5c36ea,_0x2faf3c){return function(_0x55714f){if(_0x55714f){var _0x4fa470=typeof _0x2faf3c[_0x340f('0x1d')]==='undefined'&&typeof _0x2faf3c[_0x340f('0x1e')]===_0x340f('0x1f');var _0x3dede2=_0x55714f[_0x340f('0x20')];var _0x550762=_0x4fa470?0x0:_0x2faf3c['offset'];var _0x205fe2=_0x4fa470?_0x55714f[_0x340f('0x20')]:_0x2faf3c[_0x340f('0x1d')]+_0x2faf3c[_0x340f('0x1e')];var _0xe85ff2;if(_0x205fe2>=_0x3dede2){_0x205fe2=_0x3dede2;_0xe85ff2=0xc8;}else{_0xe85ff2=0xce;}_0x5c36ea[_0x340f('0x1b')](_0xe85ff2);return _0x5c36ea[_0x340f('0x21')](_0x340f('0x22'),_0x550762+'-'+_0x205fe2+'/'+_0x3dede2)[_0x340f('0x1c')](_0x55714f);}return null;};}function patchUpdates(_0x36a845){return function(_0x553287){try{jsonpatch[_0x340f('0x23')](_0x553287,_0x36a845,!![]);}catch(_0x3f0c03){return BPromise[_0x340f('0x24')](_0x3f0c03);}return _0x553287[_0x340f('0x25')]();};}function saveUpdates(_0x4acba5,_0x1d9d42){return function(_0x59db07){if(_0x59db07){return _0x59db07['update'](_0x4acba5)[_0x340f('0x26')](function(_0x3aee9c){return _0x3aee9c;});}return null;};}function removeEntity(_0x5c0034,_0x805a20){return function(_0xc809c1){if(_0xc809c1){return _0xc809c1['destroy']()[_0x340f('0x26')](function(){_0x5c0034[_0x340f('0x1b')](0xcc)[_0x340f('0x27')]();});}};}function handleEntityNotFound(_0x1524c4,_0x4cb37e){return function(_0x1607ee){if(!_0x1607ee){_0x1524c4[_0x340f('0x1a')](0x194);}return _0x1607ee;};}function handleError(_0x7f6d6b,_0x481685){_0x481685=_0x481685||0x1f4;return function(_0x5f2e3f){logger[_0x340f('0x28')](_0x5f2e3f['stack']);if(_0x5f2e3f[_0x340f('0x29')]){delete _0x5f2e3f[_0x340f('0x29')];}_0x7f6d6b['status'](_0x481685)[_0x340f('0x2a')](_0x5f2e3f);};}exports[_0x340f('0x2b')]=function(_0x14725d,_0x29e1e4){var _0x6c1492={'raw':![],'where':{'id':_0x14725d[_0x340f('0x2c')]['id']}},_0x314397={};_0x314397['model']=_[_0x340f('0x2d')](db['DashboardItem'][_0x340f('0x2e')]);_0x314397[_0x340f('0x2f')]=_['keys'](_0x14725d[_0x340f('0x2f')]);_0x314397[_0x340f('0x30')]=_[_0x340f('0x31')](_0x314397[_0x340f('0x32')],_0x314397[_0x340f('0x2f')]);_0x6c1492['attributes']=_[_0x340f('0x31')](_0x314397['model'],qs[_0x340f('0x33')](_0x14725d[_0x340f('0x2f')][_0x340f('0x33')]));_0x6c1492['attributes']=_0x6c1492['attributes'][_0x340f('0x34')]?_0x6c1492[_0x340f('0x35')]:_0x314397[_0x340f('0x32')];if(_0x14725d[_0x340f('0x2f')][_0x340f('0x36')]){_0x6c1492['include']=[{'all':!![]}];}_0x6c1492=_[_0x340f('0x37')]({},_0x6c1492,_0x14725d[_0x340f('0x38')]);return db[_0x340f('0x39')][_0x340f('0x3a')](_0x6c1492)[_0x340f('0x26')](handleEntityNotFound(_0x29e1e4,null))[_0x340f('0x26')](respondWithResult(_0x29e1e4,null))[_0x340f('0x3b')](handleError(_0x29e1e4,null));};exports[_0x340f('0x3c')]=function(_0x39ecdd,_0x457eb4){return db['DashboardItem'][_0x340f('0x3a')]({'where':{'id':_0x39ecdd[_0x340f('0x2c')]['id']}})[_0x340f('0x26')](handleEntityNotFound(_0x457eb4,null))[_0x340f('0x26')](removeEntity(_0x457eb4,null))[_0x340f('0x3b')](handleError(_0x457eb4,null));};function widgetAttributes(_0x61ee89){try{switch(_0x61ee89['type']){case'iframe':return[{'name':'attrUrl','value':_0x61ee89[_0x340f('0x3d')]||(_0x61ee89[_0x340f('0x3e')]&&_0x61ee89[_0x340f('0x3e')][0x0]?_0x61ee89[_0x340f('0x3e')][0x0][_0x340f('0x3f')]:undefined)||'https://'}];case'custom':return[{'name':_0x340f('0x40'),'value':_0x61ee89[_0x340f('0x40')]||(_0x61ee89[_0x340f('0x3e')]&&_0x61ee89[_0x340f('0x3e')][0x0]?_0x61ee89[_0x340f('0x3e')][0x0][_0x340f('0x3f')]:undefined)||''}];case _0x340f('0x41'):return[{'name':'attrHourFormat','value':_0x61ee89['attrHourFormat']||(_0x61ee89[_0x340f('0x3e')]&&_0x61ee89[_0x340f('0x3e')][0x0]?_0x61ee89['attrs'][0x0][_0x340f('0x3f')]:undefined)||_0x340f('0x42')},{'name':_0x340f('0x43'),'value':_0x61ee89[_0x340f('0x43')]||(_0x61ee89['attrs']&&_0x61ee89[_0x340f('0x3e')][0x1]?_0x61ee89[_0x340f('0x3e')][0x1][_0x340f('0x3f')]:undefined)||_0x340f('0x44')},{'name':_0x340f('0x45'),'value':_0x61ee89[_0x340f('0x45')]||(_0x61ee89[_0x340f('0x3e')]&&_0x61ee89[_0x340f('0x3e')][0x2]?_0x61ee89[_0x340f('0x3e')][0x2][_0x340f('0x3f')]:undefined)||0xc}];case'counter':return[{'name':'attrMetric','value':_0x61ee89[_0x340f('0x46')]||(_0x61ee89[_0x340f('0x3e')]&&_0x61ee89[_0x340f('0x3e')][0x0]?_0x61ee89[_0x340f('0x3e')][0x0][_0x340f('0x3f')]:undefined)||_0x340f('0x47')},{'name':'attrVoiceQueues','value':_0x61ee89[_0x340f('0x48')]||(_0x61ee89[_0x340f('0x3e')]&&_0x61ee89['attrs'][0x1]?_0x61ee89[_0x340f('0x3e')][0x1][_0x340f('0x3f')]:undefined)||[]},{'name':_0x340f('0x45'),'value':_0x61ee89[_0x340f('0x45')]||(_0x61ee89[_0x340f('0x3e')]&&_0x61ee89[_0x340f('0x3e')][0x2]?_0x61ee89[_0x340f('0x3e')][0x2]['value']:undefined)||0x14},{'name':'attrChannel','value':_0x61ee89[_0x340f('0x49')]||(_0x61ee89[_0x340f('0x3e')]&&_0x61ee89[_0x340f('0x3e')][0x3]?_0x61ee89[_0x340f('0x3e')][0x3][_0x340f('0x3f')]:undefined)||_0x340f('0x4a')},{'name':'attrEmailAccounts','value':_0x61ee89[_0x340f('0x4b')]||(_0x61ee89[_0x340f('0x3e')]&&_0x61ee89[_0x340f('0x3e')][0x4]?_0x61ee89['attrs'][0x4][_0x340f('0x3f')]:undefined)||''},{'name':_0x340f('0x4c'),'value':_0x61ee89[_0x340f('0x4c')]||(_0x61ee89['attrs']&&_0x61ee89[_0x340f('0x3e')][0x5]?_0x61ee89[_0x340f('0x3e')][0x5][_0x340f('0x3f')]:undefined)||''},{'name':'attrSmsAccounts','value':_0x61ee89['attrSmsAccounts']||(_0x61ee89[_0x340f('0x3e')]&&_0x61ee89[_0x340f('0x3e')][0x6]?_0x61ee89[_0x340f('0x3e')][0x6][_0x340f('0x3f')]:undefined)||''},{'name':'attrOpenchannelAccounts','value':_0x61ee89['attrOpenchannelAccounts']||(_0x61ee89[_0x340f('0x3e')]&&_0x61ee89[_0x340f('0x3e')][0x7]?_0x61ee89[_0x340f('0x3e')][0x7][_0x340f('0x3f')]:undefined)||''},{'name':_0x340f('0x4d'),'value':_0x61ee89[_0x340f('0x4d')]||(_0x61ee89[_0x340f('0x3e')]&&_0x61ee89[_0x340f('0x3e')][0x8]?_0x61ee89[_0x340f('0x3e')][0x8]['value']:undefined)||''},{'name':'attrChatWebsites','value':_0x61ee89['attrChatWebsites']||(_0x61ee89[_0x340f('0x3e')]&&_0x61ee89['attrs'][0x9]?_0x61ee89[_0x340f('0x3e')][0x9][_0x340f('0x3f')]:undefined)||''}];case'multibar-chart':case'pie-chart':return[{'name':'attrSerie1','value':_0x61ee89[_0x340f('0x4e')]||(_0x61ee89[_0x340f('0x3e')]&&_0x61ee89[_0x340f('0x3e')][0x0]?_0x61ee89[_0x340f('0x3e')][0x0]['value']:undefined)||'total'},{'name':'attrSerie2','value':_0x61ee89['attrSerie2']||(_0x61ee89[_0x340f('0x3e')]&&_0x61ee89[_0x340f('0x3e')][0x1]?_0x61ee89[_0x340f('0x3e')][0x1][_0x340f('0x3f')]:undefined)||null},{'name':_0x340f('0x4f'),'value':_0x61ee89[_0x340f('0x4f')]||(_0x61ee89[_0x340f('0x3e')]&&_0x61ee89[_0x340f('0x3e')][0x2]?_0x61ee89[_0x340f('0x3e')][0x2][_0x340f('0x3f')]:undefined)||null},{'name':_0x340f('0x48'),'value':_0x61ee89[_0x340f('0x48')]||(_0x61ee89[_0x340f('0x3e')]&&_0x61ee89[_0x340f('0x3e')][0x3]?_0x61ee89['attrs'][0x3][_0x340f('0x3f')]:undefined)||[]},{'name':_0x340f('0x49'),'value':_0x61ee89[_0x340f('0x49')]||(_0x61ee89[_0x340f('0x3e')]&&_0x61ee89[_0x340f('0x3e')][0x4]?_0x61ee89[_0x340f('0x3e')][0x4][_0x340f('0x3f')]:undefined)||_0x340f('0x4a')},{'name':_0x340f('0x4b'),'value':_0x61ee89[_0x340f('0x4b')]||(_0x61ee89['attrs']&&_0x61ee89[_0x340f('0x3e')][0x5]?_0x61ee89[_0x340f('0x3e')][0x5][_0x340f('0x3f')]:undefined)||''},{'name':_0x340f('0x4c'),'value':_0x61ee89[_0x340f('0x4c')]||(_0x61ee89['attrs']&&_0x61ee89[_0x340f('0x3e')][0x6]?_0x61ee89[_0x340f('0x3e')][0x6][_0x340f('0x3f')]:undefined)||''},{'name':_0x340f('0x50'),'value':_0x61ee89[_0x340f('0x50')]||(_0x61ee89[_0x340f('0x3e')]&&_0x61ee89[_0x340f('0x3e')][0x7]?_0x61ee89[_0x340f('0x3e')][0x7][_0x340f('0x3f')]:undefined)||''},{'name':_0x340f('0x51'),'value':_0x61ee89[_0x340f('0x51')]||(_0x61ee89['attrs']&&_0x61ee89[_0x340f('0x3e')][0x8]?_0x61ee89[_0x340f('0x3e')][0x8][_0x340f('0x3f')]:undefined)||''},{'name':_0x340f('0x4d'),'value':_0x61ee89[_0x340f('0x4d')]||(_0x61ee89[_0x340f('0x3e')]&&_0x61ee89[_0x340f('0x3e')][0x9]?_0x61ee89[_0x340f('0x3e')][0x9]['value']:undefined)||''},{'name':_0x340f('0x52'),'value':_0x61ee89[_0x340f('0x52')]||(_0x61ee89[_0x340f('0x3e')]&&_0x61ee89['attrs'][0xa]?_0x61ee89['attrs'][0xa][_0x340f('0x3f')]:undefined)||''}];case _0x340f('0x53'):return[{'name':_0x340f('0x54'),'type':_0x61ee89[_0x340f('0x55')]||(_0x61ee89[_0x340f('0x3e')]&&_0x61ee89['attrs'][0x0]?_0x61ee89[_0x340f('0x3e')][0x0][_0x340f('0x56')]:undefined)||null,'value':_0x61ee89[_0x340f('0x54')]||(_0x61ee89[_0x340f('0x3e')]&&_0x61ee89[_0x340f('0x3e')][0x0]?_0x61ee89[_0x340f('0x3e')][0x0][_0x340f('0x3f')]:undefined)||null},{'name':_0x340f('0x57'),'value':_0x61ee89[_0x340f('0x57')]||(_0x61ee89[_0x340f('0x3e')]&&_0x61ee89[_0x340f('0x3e')][0x1]?_0x61ee89['attrs'][0x1][_0x340f('0x3f')]:undefined)||0x0}];default:return[];}}catch(_0x1697ab){logger['error'](_0x340f('0x58'),JSON['stringify'](_0x1697ab));return[];}}exports['create']=function(_0xad0d8f,_0x27433e){if(_0xad0d8f[_0x340f('0x59')]){_0xad0d8f['body']['attrs']=widgetAttributes(_0xad0d8f[_0x340f('0x59')]);}return db[_0x340f('0x39')][_0x340f('0x5a')](_0xad0d8f[_0x340f('0x59')],{})[_0x340f('0x26')](respondWithResult(_0x27433e,0xc9))[_0x340f('0x3b')](handleError(_0x27433e,null));};exports[_0x340f('0x5b')]=function(_0xabc355,_0x2562c6){if(_0xabc355['body']['id']){delete _0xabc355['body']['id'];}_0xabc355[_0x340f('0x59')][_0x340f('0x3e')]=widgetAttributes(_0xabc355[_0x340f('0x59')]);return db[_0x340f('0x39')][_0x340f('0x3a')]({'where':{'id':_0xabc355[_0x340f('0x2c')]['id']}})[_0x340f('0x26')](handleEntityNotFound(_0x2562c6,null))['then'](saveUpdates(_0xabc355['body'],null))[_0x340f('0x26')](respondWithResult(_0x2562c6,null))[_0x340f('0x3b')](handleError(_0x2562c6,null));};