Built motion from commit (unavailable).|2.0.72
[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 _0xf950=['DashboardItem','query','intersection','model','attributes','fields','includeAll','include','merge','find','catch','type','iframe','attrUrl','attrs','value','https://','custom','attrPath','clock','attrHourFormat','HH:mm:ss','attrTimezone','attrFontSize','counter','total','attrVoiceQueues','multibar-chart','pie-chart','attrSerie1','attrSerie2','attrSerie3','web-report','attrReport','attrRefresh','widgetAttributes:\x20%s','create','body','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','to-csv','ejs','lodash','squel','jsforce','querystring','../../components/parsers/qs','../../config/logger','api','../../config/environment','../../mysqldb','socket.io-emitter','localhost','./dashboardItem.socket','sendStatus','status','json','offset','limit','set','Content-Range','reject','save','update','then','destroy','end','error','stack','params','keys'];(function(_0x1c68c4,_0x22a605){var _0x212655=function(_0x26784e){while(--_0x26784e){_0x1c68c4['push'](_0x1c68c4['shift']());}};_0x212655(++_0x22a605);}(_0xf950,0x1ee));var _0x0f95=function(_0x17650f,_0x3770ab){_0x17650f=_0x17650f-0x0;var _0x437f97=_0xf950[_0x17650f];return _0x437f97;};'use strict';var jsonpatch=require(_0x0f95('0x0'));var rp=require(_0x0f95('0x1'));var moment=require(_0x0f95('0x2'));var BPromise=require(_0x0f95('0x3'));var Mustache=require(_0x0f95('0x4'));var util=require(_0x0f95('0x5'));var path=require(_0x0f95('0x6'));var sox=require('sox');var csv=require(_0x0f95('0x7'));var ejs=require(_0x0f95('0x8'));var fs=require('fs');var _=require(_0x0f95('0x9'));var squel=require(_0x0f95('0xa'));var crypto=require('crypto');var jsforce=require(_0x0f95('0xb'));var deskjs=require('desk.js');var toCsv=require(_0x0f95('0x7'));var querystring=require(_0x0f95('0xc'));var Papa=require('papaparse');var qs=require(_0x0f95('0xd'));var logger=require(_0x0f95('0xe'))(_0x0f95('0xf'));var utils=require('../../config/utils');var config=require(_0x0f95('0x10'));var db=require(_0x0f95('0x11'))['db'];var socket=require(_0x0f95('0x12'))({'host':_0x0f95('0x13'),'port':0x18eb});require(_0x0f95('0x14'))['register'](socket);function respondWithStatusCode(_0x51b973,_0x445435){_0x445435=_0x445435||0xcc;return function(_0x55afbb){if(_0x55afbb){return _0x51b973[_0x0f95('0x15')](_0x445435);}return _0x51b973[_0x0f95('0x16')](_0x445435)['end']();};}function respondWithResult(_0x1a6563,_0x41b334){_0x41b334=_0x41b334||0xc8;return function(_0x3570d7){if(_0x3570d7){return _0x1a6563[_0x0f95('0x16')](_0x41b334)[_0x0f95('0x17')](_0x3570d7);}};}function respondWithFilteredResult(_0x5de5d4,_0x344ba4){return function(_0x52bd7e){if(_0x52bd7e){var _0x58f62e=_0x52bd7e['count'],_0x447d86=_0x344ba4[_0x0f95('0x18')],_0x607567=_0x344ba4[_0x0f95('0x18')]+_0x344ba4[_0x0f95('0x19')],_0x2310f9;if(_0x607567>=_0x58f62e){_0x607567=_0x58f62e;_0x2310f9=0xc8;}else{_0x2310f9=0xce;}_0x5de5d4[_0x0f95('0x16')](_0x2310f9);return _0x5de5d4[_0x0f95('0x1a')](_0x0f95('0x1b'),_0x447d86+'-'+_0x607567+'/'+_0x58f62e)[_0x0f95('0x17')](_0x52bd7e);}return null;};}function patchUpdates(_0x1457fa){return function(_0x44fd6f){try{jsonpatch['apply'](_0x44fd6f,_0x1457fa,!![]);}catch(_0x3664ee){return BPromise[_0x0f95('0x1c')](_0x3664ee);}return _0x44fd6f[_0x0f95('0x1d')]();};}function saveUpdates(_0x32cb34,_0x5923f){return function(_0x2a8bc7){if(_0x2a8bc7){return _0x2a8bc7[_0x0f95('0x1e')](_0x32cb34)[_0x0f95('0x1f')](function(_0x2d5e34){return _0x2d5e34;});}return null;};}function removeEntity(_0x507b14,_0x385507){return function(_0x4d1243){if(_0x4d1243){return _0x4d1243[_0x0f95('0x20')]()[_0x0f95('0x1f')](function(){_0x507b14['status'](0xcc)[_0x0f95('0x21')]();});}};}function handleEntityNotFound(_0xd0883f,_0x1e4f11){return function(_0x481941){if(!_0x481941){_0xd0883f[_0x0f95('0x15')](0x194);}return _0x481941;};}function handleError(_0x2914e7,_0xec17bc){_0xec17bc=_0xec17bc||0x1f4;return function(_0xe2fb5b){logger[_0x0f95('0x22')](_0xe2fb5b[_0x0f95('0x23')]);if(_0xe2fb5b['name']){delete _0xe2fb5b['name'];}_0x2914e7[_0x0f95('0x16')](_0xec17bc)['send'](_0xe2fb5b);};}exports['show']=function(_0x278cf9,_0x118df6){var _0x5ded84={'raw':![],'where':{'id':_0x278cf9[_0x0f95('0x24')]['id']}},_0x4ed404={};_0x4ed404['model']=_[_0x0f95('0x25')](db[_0x0f95('0x26')]['rawAttributes']);_0x4ed404[_0x0f95('0x27')]=_[_0x0f95('0x25')](_0x278cf9['query']);_0x4ed404['filters']=_[_0x0f95('0x28')](_0x4ed404[_0x0f95('0x29')],_0x4ed404[_0x0f95('0x27')]);_0x5ded84[_0x0f95('0x2a')]=_[_0x0f95('0x28')](_0x4ed404[_0x0f95('0x29')],qs[_0x0f95('0x2b')](_0x278cf9['query'][_0x0f95('0x2b')]));_0x5ded84[_0x0f95('0x2a')]=_0x5ded84['attributes']['length']?_0x5ded84[_0x0f95('0x2a')]:_0x4ed404[_0x0f95('0x29')];if(_0x278cf9['query'][_0x0f95('0x2c')]){_0x5ded84[_0x0f95('0x2d')]=[{'all':!![]}];}_0x5ded84=_[_0x0f95('0x2e')]({},_0x5ded84,_0x278cf9['options']);return db[_0x0f95('0x26')][_0x0f95('0x2f')](_0x5ded84)[_0x0f95('0x1f')](handleEntityNotFound(_0x118df6,null))['then'](respondWithResult(_0x118df6,null))[_0x0f95('0x30')](handleError(_0x118df6,null));};exports[_0x0f95('0x20')]=function(_0x44338e,_0x5b71a5){return db[_0x0f95('0x26')][_0x0f95('0x2f')]({'where':{'id':_0x44338e[_0x0f95('0x24')]['id']}})[_0x0f95('0x1f')](handleEntityNotFound(_0x5b71a5,null))[_0x0f95('0x1f')](removeEntity(_0x5b71a5,null))[_0x0f95('0x30')](handleError(_0x5b71a5,null));};function widgetAttributes(_0x16a2db){try{switch(_0x16a2db[_0x0f95('0x31')]){case _0x0f95('0x32'):return[{'name':'attrUrl','value':_0x16a2db[_0x0f95('0x33')]||(_0x16a2db[_0x0f95('0x34')]&&_0x16a2db[_0x0f95('0x34')][0x0]?_0x16a2db[_0x0f95('0x34')][0x0][_0x0f95('0x35')]:undefined)||_0x0f95('0x36')}];case _0x0f95('0x37'):return[{'name':_0x0f95('0x38'),'value':_0x16a2db[_0x0f95('0x38')]||(_0x16a2db[_0x0f95('0x34')]&&_0x16a2db[_0x0f95('0x34')][0x0]?_0x16a2db[_0x0f95('0x34')][0x0][_0x0f95('0x35')]:undefined)||''}];case _0x0f95('0x39'):return[{'name':_0x0f95('0x3a'),'value':_0x16a2db[_0x0f95('0x3a')]||(_0x16a2db[_0x0f95('0x34')]&&_0x16a2db['attrs'][0x0]?_0x16a2db[_0x0f95('0x34')][0x0][_0x0f95('0x35')]:undefined)||_0x0f95('0x3b')},{'name':_0x0f95('0x3c'),'value':_0x16a2db[_0x0f95('0x3c')]||(_0x16a2db[_0x0f95('0x34')]&&_0x16a2db[_0x0f95('0x34')][0x1]?_0x16a2db[_0x0f95('0x34')][0x1]['value']:undefined)||'0.00'},{'name':_0x0f95('0x3d'),'value':_0x16a2db[_0x0f95('0x3d')]||(_0x16a2db['attrs']&&_0x16a2db[_0x0f95('0x34')][0x2]?_0x16a2db[_0x0f95('0x34')][0x2][_0x0f95('0x35')]:undefined)||0xc}];case _0x0f95('0x3e'):return[{'name':'attrMetric','value':_0x16a2db['attrMetric']||(_0x16a2db['attrs']&&_0x16a2db[_0x0f95('0x34')][0x0]?_0x16a2db[_0x0f95('0x34')][0x0][_0x0f95('0x35')]:undefined)||_0x0f95('0x3f')},{'name':_0x0f95('0x40'),'value':_0x16a2db[_0x0f95('0x40')]||(_0x16a2db['attrs']&&_0x16a2db[_0x0f95('0x34')][0x1]?_0x16a2db['attrs'][0x1][_0x0f95('0x35')]:undefined)||[]},{'name':_0x0f95('0x3d'),'value':_0x16a2db[_0x0f95('0x3d')]||(_0x16a2db['attrs']&&_0x16a2db[_0x0f95('0x34')][0x2]?_0x16a2db[_0x0f95('0x34')][0x2]['value']:undefined)||0x14}];case _0x0f95('0x41'):case _0x0f95('0x42'):return[{'name':_0x0f95('0x43'),'value':_0x16a2db[_0x0f95('0x43')]||(_0x16a2db['attrs']&&_0x16a2db['attrs'][0x0]?_0x16a2db[_0x0f95('0x34')][0x0][_0x0f95('0x35')]:undefined)||_0x0f95('0x3f')},{'name':_0x0f95('0x44'),'value':_0x16a2db['attrSerie2']||(_0x16a2db[_0x0f95('0x34')]&&_0x16a2db[_0x0f95('0x34')][0x1]?_0x16a2db[_0x0f95('0x34')][0x1][_0x0f95('0x35')]:undefined)||null},{'name':'attrSerie3','value':_0x16a2db[_0x0f95('0x45')]||(_0x16a2db[_0x0f95('0x34')]&&_0x16a2db[_0x0f95('0x34')][0x2]?_0x16a2db[_0x0f95('0x34')][0x2][_0x0f95('0x35')]:undefined)||null},{'name':_0x0f95('0x40'),'value':_0x16a2db[_0x0f95('0x40')]||(_0x16a2db[_0x0f95('0x34')]&&_0x16a2db[_0x0f95('0x34')][0x3]?_0x16a2db[_0x0f95('0x34')][0x3]['value']:undefined)||[]}];case _0x0f95('0x46'):return[{'name':_0x0f95('0x47'),'value':_0x16a2db['attrReport']||(_0x16a2db[_0x0f95('0x34')]&&_0x16a2db[_0x0f95('0x34')][0x0]?_0x16a2db[_0x0f95('0x34')][0x0][_0x0f95('0x35')]:undefined)||null},{'name':'attrRefresh','value':_0x16a2db[_0x0f95('0x48')]||(_0x16a2db['attrs']&&_0x16a2db[_0x0f95('0x34')][0x1]?_0x16a2db[_0x0f95('0x34')][0x1]['value']:undefined)||0x0}];default:return[];}}catch(_0x378192){logger['error'](_0x0f95('0x49'),JSON['stringify'](_0x378192));return[];}}exports[_0x0f95('0x4a')]=function(_0x50fd05,_0x49461c){if(_0x50fd05[_0x0f95('0x4b')]){_0x50fd05[_0x0f95('0x4b')][_0x0f95('0x34')]=widgetAttributes(_0x50fd05[_0x0f95('0x4b')]);}return db[_0x0f95('0x26')]['create'](_0x50fd05[_0x0f95('0x4b')],{})[_0x0f95('0x1f')](respondWithResult(_0x49461c,0xc9))[_0x0f95('0x30')](handleError(_0x49461c,null));};exports[_0x0f95('0x1e')]=function(_0x50b7b4,_0x80878a){if(_0x50b7b4[_0x0f95('0x4b')]['id']){delete _0x50b7b4[_0x0f95('0x4b')]['id'];}_0x50b7b4[_0x0f95('0x4b')][_0x0f95('0x34')]=widgetAttributes(_0x50b7b4[_0x0f95('0x4b')]);return db[_0x0f95('0x26')][_0x0f95('0x2f')]({'where':{'id':_0x50b7b4[_0x0f95('0x24')]['id']}})[_0x0f95('0x1f')](handleEntityNotFound(_0x80878a,null))[_0x0f95('0x1f')](saveUpdates(_0x50b7b4[_0x0f95('0x4b')],null))[_0x0f95('0x1f')](respondWithResult(_0x80878a,null))[_0x0f95('0x30')](handleError(_0x80878a,null));};