Built motion from commit (unavailable).|2.3.96
[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 _0x3b68=['sox','ejs','lodash','crypto','to-csv','querystring','../../components/auth/service','../../components/parsers/qs','api','../../config/environment','../../mysqldb','redis','defaults','socket.io-emitter','./dashboardItem.socket','register','sendStatus','status','end','json','count','offset','set','Content-Range','apply','reject','save','then','destroy','error','stack','name','model','DashboardItem','rawAttributes','keys','query','filters','intersection','attributes','fields','include','merge','options','find','catch','params','type','iframe','attrUrl','attrs','https://','custom','attrPath','clock','attrHourFormat','attrTimezone','value','0.00','attrFontSize','counter','attrMetric','total','attrVoiceQueues','pie-chart','attrSerie1','attrSerie2','attrSerie3','web-report','attrReport','reportType','attrRefresh','widgetAttributes:\x20%s','stringify','create','body','update','html-pdf','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util'];(function(_0x4f4a34,_0x316a26){var _0x1e91fe=function(_0x4130c5){while(--_0x4130c5){_0x4f4a34['push'](_0x4f4a34['shift']());}};_0x1e91fe(++_0x316a26);}(_0x3b68,0x1a5));var _0x83b6=function(_0x3e2b6f,_0x51441a){_0x3e2b6f=_0x3e2b6f-0x0;var _0x1f8ad4=_0x3b68[_0x3e2b6f];return _0x1f8ad4;};'use strict';var pdf=require(_0x83b6('0x0'));var emlformat=require('eml-format');var rimraf=require(_0x83b6('0x1'));var zipdir=require(_0x83b6('0x2'));var jsonpatch=require(_0x83b6('0x3'));var rp=require(_0x83b6('0x4'));var moment=require(_0x83b6('0x5'));var BPromise=require(_0x83b6('0x6'));var Mustache=require(_0x83b6('0x7'));var util=require(_0x83b6('0x8'));var path=require('path');var sox=require(_0x83b6('0x9'));var csv=require('to-csv');var ejs=require(_0x83b6('0xa'));var fs=require('fs');var _=require(_0x83b6('0xb'));var squel=require('squel');var crypto=require(_0x83b6('0xc'));var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0x83b6('0xd'));var querystring=require(_0x83b6('0xe'));var Papa=require('papaparse');var authService=require(_0x83b6('0xf'));var hardwareService=require('../../config/license/hardware');var Redis=require('ioredis');var qs=require(_0x83b6('0x10'));var logger=require('../../config/logger')(_0x83b6('0x11'));var utils=require('../../config/utils');var config=require(_0x83b6('0x12'));var db=require(_0x83b6('0x13'))['db'];config[_0x83b6('0x14')]=_[_0x83b6('0x15')](config[_0x83b6('0x14')],{'host':'localhost','port':0x18eb});var socket=require(_0x83b6('0x16'))(new Redis(config['redis']));require(_0x83b6('0x17'))[_0x83b6('0x18')](socket);function respondWithStatusCode(_0x3569da,_0x4b83f4){_0x4b83f4=_0x4b83f4||0xcc;return function(_0x1f8f0f){if(_0x1f8f0f){return _0x3569da[_0x83b6('0x19')](_0x4b83f4);}return _0x3569da[_0x83b6('0x1a')](_0x4b83f4)[_0x83b6('0x1b')]();};}function respondWithResult(_0x3ea073,_0x437741){_0x437741=_0x437741||0xc8;return function(_0x36ee91){if(_0x36ee91){return _0x3ea073['status'](_0x437741)[_0x83b6('0x1c')](_0x36ee91);}};}function respondWithFilteredResult(_0x1fd22a,_0x357635){return function(_0xe6f0c3){if(_0xe6f0c3){var _0x239a77=_0xe6f0c3[_0x83b6('0x1d')],_0x415594=_0x357635['offset'],_0x3e3765=_0x357635[_0x83b6('0x1e')]+_0x357635['limit'],_0x287b3f;if(_0x3e3765>=_0x239a77){_0x3e3765=_0x239a77;_0x287b3f=0xc8;}else{_0x287b3f=0xce;}_0x1fd22a['status'](_0x287b3f);return _0x1fd22a[_0x83b6('0x1f')](_0x83b6('0x20'),_0x415594+'-'+_0x3e3765+'/'+_0x239a77)[_0x83b6('0x1c')](_0xe6f0c3);}return null;};}function patchUpdates(_0x87fda9){return function(_0x22596a){try{jsonpatch[_0x83b6('0x21')](_0x22596a,_0x87fda9,!![]);}catch(_0x15d288){return BPromise[_0x83b6('0x22')](_0x15d288);}return _0x22596a[_0x83b6('0x23')]();};}function saveUpdates(_0x5a2095,_0x4ea04b){return function(_0x5e46a6){if(_0x5e46a6){return _0x5e46a6['update'](_0x5a2095)[_0x83b6('0x24')](function(_0x2a0c91){return _0x2a0c91;});}return null;};}function removeEntity(_0x1e2062,_0x40f49f){return function(_0x47956b){if(_0x47956b){return _0x47956b[_0x83b6('0x25')]()[_0x83b6('0x24')](function(){_0x1e2062[_0x83b6('0x1a')](0xcc)[_0x83b6('0x1b')]();});}};}function handleEntityNotFound(_0x442a2d,_0x23509f){return function(_0x67d843){if(!_0x67d843){_0x442a2d['sendStatus'](0x194);}return _0x67d843;};}function handleError(_0x3f4c51,_0x2842e8){_0x2842e8=_0x2842e8||0x1f4;return function(_0x2bc48b){logger[_0x83b6('0x26')](_0x2bc48b[_0x83b6('0x27')]);if(_0x2bc48b[_0x83b6('0x28')]){delete _0x2bc48b[_0x83b6('0x28')];}_0x3f4c51[_0x83b6('0x1a')](_0x2842e8)['send'](_0x2bc48b);};}exports['show']=function(_0x38c6bc,_0x5d8c91){var _0x3ad62f={'raw':![],'where':{'id':_0x38c6bc['params']['id']}},_0x1fea21={};_0x1fea21[_0x83b6('0x29')]=_['keys'](db[_0x83b6('0x2a')][_0x83b6('0x2b')]);_0x1fea21['query']=_[_0x83b6('0x2c')](_0x38c6bc[_0x83b6('0x2d')]);_0x1fea21[_0x83b6('0x2e')]=_[_0x83b6('0x2f')](_0x1fea21['model'],_0x1fea21['query']);_0x3ad62f[_0x83b6('0x30')]=_[_0x83b6('0x2f')](_0x1fea21[_0x83b6('0x29')],qs[_0x83b6('0x31')](_0x38c6bc[_0x83b6('0x2d')]['fields']));_0x3ad62f['attributes']=_0x3ad62f[_0x83b6('0x30')]['length']?_0x3ad62f['attributes']:_0x1fea21[_0x83b6('0x29')];if(_0x38c6bc['query']['includeAll']){_0x3ad62f[_0x83b6('0x32')]=[{'all':!![]}];}_0x3ad62f=_[_0x83b6('0x33')]({},_0x3ad62f,_0x38c6bc[_0x83b6('0x34')]);return db['DashboardItem'][_0x83b6('0x35')](_0x3ad62f)[_0x83b6('0x24')](handleEntityNotFound(_0x5d8c91,null))['then'](respondWithResult(_0x5d8c91,null))[_0x83b6('0x36')](handleError(_0x5d8c91,null));};exports[_0x83b6('0x25')]=function(_0x11e60f,_0x183d59){return db['DashboardItem'][_0x83b6('0x35')]({'where':{'id':_0x11e60f[_0x83b6('0x37')]['id']}})[_0x83b6('0x24')](handleEntityNotFound(_0x183d59,null))[_0x83b6('0x24')](removeEntity(_0x183d59,null))[_0x83b6('0x36')](handleError(_0x183d59,null));};function widgetAttributes(_0x1722f1){try{switch(_0x1722f1[_0x83b6('0x38')]){case _0x83b6('0x39'):return[{'name':_0x83b6('0x3a'),'value':_0x1722f1['attrUrl']||(_0x1722f1['attrs']&&_0x1722f1[_0x83b6('0x3b')][0x0]?_0x1722f1[_0x83b6('0x3b')][0x0]['value']:undefined)||_0x83b6('0x3c')}];case _0x83b6('0x3d'):return[{'name':_0x83b6('0x3e'),'value':_0x1722f1[_0x83b6('0x3e')]||(_0x1722f1[_0x83b6('0x3b')]&&_0x1722f1[_0x83b6('0x3b')][0x0]?_0x1722f1[_0x83b6('0x3b')][0x0]['value']:undefined)||''}];case _0x83b6('0x3f'):return[{'name':_0x83b6('0x40'),'value':_0x1722f1['attrHourFormat']||(_0x1722f1[_0x83b6('0x3b')]&&_0x1722f1[_0x83b6('0x3b')][0x0]?_0x1722f1['attrs'][0x0]['value']:undefined)||'HH:mm:ss'},{'name':'attrTimezone','value':_0x1722f1[_0x83b6('0x41')]||(_0x1722f1[_0x83b6('0x3b')]&&_0x1722f1[_0x83b6('0x3b')][0x1]?_0x1722f1[_0x83b6('0x3b')][0x1][_0x83b6('0x42')]:undefined)||_0x83b6('0x43')},{'name':_0x83b6('0x44'),'value':_0x1722f1['attrFontSize']||(_0x1722f1['attrs']&&_0x1722f1['attrs'][0x2]?_0x1722f1[_0x83b6('0x3b')][0x2][_0x83b6('0x42')]:undefined)||0xc}];case _0x83b6('0x45'):return[{'name':_0x83b6('0x46'),'value':_0x1722f1[_0x83b6('0x46')]||(_0x1722f1[_0x83b6('0x3b')]&&_0x1722f1[_0x83b6('0x3b')][0x0]?_0x1722f1['attrs'][0x0][_0x83b6('0x42')]:undefined)||_0x83b6('0x47')},{'name':_0x83b6('0x48'),'value':_0x1722f1[_0x83b6('0x48')]||(_0x1722f1[_0x83b6('0x3b')]&&_0x1722f1[_0x83b6('0x3b')][0x1]?_0x1722f1[_0x83b6('0x3b')][0x1][_0x83b6('0x42')]:undefined)||[]},{'name':'attrFontSize','value':_0x1722f1[_0x83b6('0x44')]||(_0x1722f1[_0x83b6('0x3b')]&&_0x1722f1[_0x83b6('0x3b')][0x2]?_0x1722f1['attrs'][0x2][_0x83b6('0x42')]:undefined)||0x14}];case'multibar-chart':case _0x83b6('0x49'):return[{'name':'attrSerie1','value':_0x1722f1[_0x83b6('0x4a')]||(_0x1722f1['attrs']&&_0x1722f1['attrs'][0x0]?_0x1722f1[_0x83b6('0x3b')][0x0][_0x83b6('0x42')]:undefined)||_0x83b6('0x47')},{'name':_0x83b6('0x4b'),'value':_0x1722f1[_0x83b6('0x4b')]||(_0x1722f1['attrs']&&_0x1722f1[_0x83b6('0x3b')][0x1]?_0x1722f1['attrs'][0x1][_0x83b6('0x42')]:undefined)||null},{'name':_0x83b6('0x4c'),'value':_0x1722f1[_0x83b6('0x4c')]||(_0x1722f1[_0x83b6('0x3b')]&&_0x1722f1[_0x83b6('0x3b')][0x2]?_0x1722f1[_0x83b6('0x3b')][0x2][_0x83b6('0x42')]:undefined)||null},{'name':_0x83b6('0x48'),'value':_0x1722f1[_0x83b6('0x48')]||(_0x1722f1[_0x83b6('0x3b')]&&_0x1722f1[_0x83b6('0x3b')][0x3]?_0x1722f1[_0x83b6('0x3b')][0x3][_0x83b6('0x42')]:undefined)||[]}];case _0x83b6('0x4d'):return[{'name':_0x83b6('0x4e'),'type':_0x1722f1[_0x83b6('0x4f')]||(_0x1722f1[_0x83b6('0x3b')]&&_0x1722f1[_0x83b6('0x3b')][0x0]?_0x1722f1[_0x83b6('0x3b')][0x0][_0x83b6('0x38')]:undefined)||null,'value':_0x1722f1[_0x83b6('0x4e')]||(_0x1722f1['attrs']&&_0x1722f1[_0x83b6('0x3b')][0x0]?_0x1722f1['attrs'][0x0][_0x83b6('0x42')]:undefined)||null},{'name':'attrRefresh','value':_0x1722f1[_0x83b6('0x50')]||(_0x1722f1['attrs']&&_0x1722f1[_0x83b6('0x3b')][0x1]?_0x1722f1['attrs'][0x1][_0x83b6('0x42')]:undefined)||0x0}];default:return[];}}catch(_0xbaeb7b){logger['error'](_0x83b6('0x51'),JSON[_0x83b6('0x52')](_0xbaeb7b));return[];}}exports[_0x83b6('0x53')]=function(_0x5bdc5c,_0x323420){if(_0x5bdc5c[_0x83b6('0x54')]){_0x5bdc5c['body']['attrs']=widgetAttributes(_0x5bdc5c[_0x83b6('0x54')]);}return db['DashboardItem'][_0x83b6('0x53')](_0x5bdc5c['body'],{})[_0x83b6('0x24')](respondWithResult(_0x323420,0xc9))[_0x83b6('0x36')](handleError(_0x323420,null));};exports[_0x83b6('0x55')]=function(_0x2946aa,_0x5bffb7){if(_0x2946aa[_0x83b6('0x54')]['id']){delete _0x2946aa[_0x83b6('0x54')]['id'];}_0x2946aa[_0x83b6('0x54')][_0x83b6('0x3b')]=widgetAttributes(_0x2946aa[_0x83b6('0x54')]);return db[_0x83b6('0x2a')][_0x83b6('0x35')]({'where':{'id':_0x2946aa[_0x83b6('0x37')]['id']}})[_0x83b6('0x24')](handleEntityNotFound(_0x5bffb7,null))['then'](saveUpdates(_0x2946aa[_0x83b6('0x54')],null))[_0x83b6('0x24')](respondWithResult(_0x5bffb7,null))['catch'](handleError(_0x5bffb7,null));};