Built motion from commit (unavailable).|2.4.21
[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 _0xc295=['localhost','socket.io-emitter','register','status','end','json','offset','limit','set','Content-Range','apply','reject','save','update','destroy','sendStatus','error','stack','name','send','show','params','model','keys','DashboardItem','rawAttributes','query','filters','attributes','intersection','fields','length','includeAll','include','merge','then','catch','iframe','attrUrl','attrs','https://','custom','value','clock','attrHourFormat','HH:mm:ss','attrTimezone','attrFontSize','counter','attrMetric','total','attrVoiceQueues','multibar-chart','pie-chart','attrSerie1','attrSerie2','attrSerie3','web-report','attrReport','attrRefresh','widgetAttributes:\x20%s','stringify','body','find','html-pdf','eml-format','rimraf','fast-json-patch','request-promise','bluebird','mustache','sox','to-csv','ejs','squel','crypto','jsforce','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','api','../../config/utils','../../config/environment','../../mysqldb','redis','defaults'];(function(_0x5ab99f,_0x3d6a94){var _0x35c931=function(_0x2114c0){while(--_0x2114c0){_0x5ab99f['push'](_0x5ab99f['shift']());}};_0x35c931(++_0x3d6a94);}(_0xc295,0xf2));var _0x5c29=function(_0x18cf28,_0x5e09c5){_0x18cf28=_0x18cf28-0x0;var _0xa8f3ed=_0xc295[_0x18cf28];return _0xa8f3ed;};'use strict';var pdf=require(_0x5c29('0x0'));var emlformat=require(_0x5c29('0x1'));var rimraf=require(_0x5c29('0x2'));var zipdir=require('zip-dir');var jsonpatch=require(_0x5c29('0x3'));var rp=require(_0x5c29('0x4'));var moment=require('moment');var BPromise=require(_0x5c29('0x5'));var Mustache=require(_0x5c29('0x6'));var util=require('util');var path=require('path');var sox=require(_0x5c29('0x7'));var csv=require(_0x5c29('0x8'));var ejs=require(_0x5c29('0x9'));var fs=require('fs');var _=require('lodash');var squel=require(_0x5c29('0xa'));var crypto=require(_0x5c29('0xb'));var jsforce=require(_0x5c29('0xc'));var deskjs=require(_0x5c29('0xd'));var toCsv=require(_0x5c29('0x8'));var querystring=require('querystring');var Papa=require(_0x5c29('0xe'));var Redis=require(_0x5c29('0xf'));var authService=require(_0x5c29('0x10'));var qs=require(_0x5c29('0x11'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x5c29('0x12'));var logger=require('../../config/logger')(_0x5c29('0x13'));var utils=require(_0x5c29('0x14'));var config=require(_0x5c29('0x15'));var db=require(_0x5c29('0x16'))['db'];config[_0x5c29('0x17')]=_[_0x5c29('0x18')](config[_0x5c29('0x17')],{'host':_0x5c29('0x19'),'port':0x18eb});var socket=require(_0x5c29('0x1a'))(new Redis(config[_0x5c29('0x17')]));require('./dashboardItem.socket')[_0x5c29('0x1b')](socket);function respondWithStatusCode(_0x362cd1,_0x590155){_0x590155=_0x590155||0xcc;return function(_0xb7ba8e){if(_0xb7ba8e){return _0x362cd1['sendStatus'](_0x590155);}return _0x362cd1[_0x5c29('0x1c')](_0x590155)[_0x5c29('0x1d')]();};}function respondWithResult(_0x58f1a1,_0x36382e){_0x36382e=_0x36382e||0xc8;return function(_0x4e9155){if(_0x4e9155){return _0x58f1a1[_0x5c29('0x1c')](_0x36382e)[_0x5c29('0x1e')](_0x4e9155);}};}function respondWithFilteredResult(_0x2d30ba,_0x1bdb00){return function(_0x1b0413){if(_0x1b0413){var _0x5b8c3e=_0x1b0413['count'],_0xa491b9=_0x1bdb00[_0x5c29('0x1f')],_0x5e2d62=_0x1bdb00[_0x5c29('0x1f')]+_0x1bdb00[_0x5c29('0x20')],_0x3d4733;if(_0x5e2d62>=_0x5b8c3e){_0x5e2d62=_0x5b8c3e;_0x3d4733=0xc8;}else{_0x3d4733=0xce;}_0x2d30ba[_0x5c29('0x1c')](_0x3d4733);return _0x2d30ba[_0x5c29('0x21')](_0x5c29('0x22'),_0xa491b9+'-'+_0x5e2d62+'/'+_0x5b8c3e)['json'](_0x1b0413);}return null;};}function patchUpdates(_0x4c4be0){return function(_0x55be28){try{jsonpatch[_0x5c29('0x23')](_0x55be28,_0x4c4be0,!![]);}catch(_0x175538){return BPromise[_0x5c29('0x24')](_0x175538);}return _0x55be28[_0x5c29('0x25')]();};}function saveUpdates(_0x13e9dc,_0x40efc5){return function(_0x1f7c9d){if(_0x1f7c9d){return _0x1f7c9d[_0x5c29('0x26')](_0x13e9dc)['then'](function(_0x1dc7a2){return _0x1dc7a2;});}return null;};}function removeEntity(_0x3fdd7f,_0x50d379){return function(_0x59b26f){if(_0x59b26f){return _0x59b26f[_0x5c29('0x27')]()['then'](function(){_0x3fdd7f[_0x5c29('0x1c')](0xcc)[_0x5c29('0x1d')]();});}};}function handleEntityNotFound(_0x1c4e53,_0x43703a){return function(_0x189415){if(!_0x189415){_0x1c4e53[_0x5c29('0x28')](0x194);}return _0x189415;};}function handleError(_0x218681,_0xb89d3c){_0xb89d3c=_0xb89d3c||0x1f4;return function(_0x46ce1b){logger[_0x5c29('0x29')](_0x46ce1b[_0x5c29('0x2a')]);if(_0x46ce1b['name']){delete _0x46ce1b[_0x5c29('0x2b')];}_0x218681[_0x5c29('0x1c')](_0xb89d3c)[_0x5c29('0x2c')](_0x46ce1b);};}exports[_0x5c29('0x2d')]=function(_0x5de86f,_0x25a541){var _0x32bf3d={'raw':![],'where':{'id':_0x5de86f[_0x5c29('0x2e')]['id']}},_0x3d8ffe={};_0x3d8ffe[_0x5c29('0x2f')]=_[_0x5c29('0x30')](db[_0x5c29('0x31')][_0x5c29('0x32')]);_0x3d8ffe[_0x5c29('0x33')]=_[_0x5c29('0x30')](_0x5de86f[_0x5c29('0x33')]);_0x3d8ffe[_0x5c29('0x34')]=_['intersection'](_0x3d8ffe[_0x5c29('0x2f')],_0x3d8ffe[_0x5c29('0x33')]);_0x32bf3d[_0x5c29('0x35')]=_[_0x5c29('0x36')](_0x3d8ffe[_0x5c29('0x2f')],qs[_0x5c29('0x37')](_0x5de86f[_0x5c29('0x33')][_0x5c29('0x37')]));_0x32bf3d[_0x5c29('0x35')]=_0x32bf3d['attributes'][_0x5c29('0x38')]?_0x32bf3d['attributes']:_0x3d8ffe[_0x5c29('0x2f')];if(_0x5de86f[_0x5c29('0x33')][_0x5c29('0x39')]){_0x32bf3d[_0x5c29('0x3a')]=[{'all':!![]}];}_0x32bf3d=_[_0x5c29('0x3b')]({},_0x32bf3d,_0x5de86f['options']);return db['DashboardItem']['find'](_0x32bf3d)[_0x5c29('0x3c')](handleEntityNotFound(_0x25a541,null))[_0x5c29('0x3c')](respondWithResult(_0x25a541,null))[_0x5c29('0x3d')](handleError(_0x25a541,null));};exports['destroy']=function(_0xf117eb,_0x59c2f0){return db[_0x5c29('0x31')]['find']({'where':{'id':_0xf117eb[_0x5c29('0x2e')]['id']}})[_0x5c29('0x3c')](handleEntityNotFound(_0x59c2f0,null))[_0x5c29('0x3c')](removeEntity(_0x59c2f0,null))[_0x5c29('0x3d')](handleError(_0x59c2f0,null));};function widgetAttributes(_0x2e1595){try{switch(_0x2e1595['type']){case _0x5c29('0x3e'):return[{'name':_0x5c29('0x3f'),'value':_0x2e1595['attrUrl']||(_0x2e1595['attrs']&&_0x2e1595[_0x5c29('0x40')][0x0]?_0x2e1595[_0x5c29('0x40')][0x0]['value']:undefined)||_0x5c29('0x41')}];case _0x5c29('0x42'):return[{'name':'attrPath','value':_0x2e1595['attrPath']||(_0x2e1595['attrs']&&_0x2e1595[_0x5c29('0x40')][0x0]?_0x2e1595[_0x5c29('0x40')][0x0][_0x5c29('0x43')]:undefined)||''}];case _0x5c29('0x44'):return[{'name':_0x5c29('0x45'),'value':_0x2e1595[_0x5c29('0x45')]||(_0x2e1595[_0x5c29('0x40')]&&_0x2e1595[_0x5c29('0x40')][0x0]?_0x2e1595['attrs'][0x0][_0x5c29('0x43')]:undefined)||_0x5c29('0x46')},{'name':_0x5c29('0x47'),'value':_0x2e1595[_0x5c29('0x47')]||(_0x2e1595[_0x5c29('0x40')]&&_0x2e1595[_0x5c29('0x40')][0x1]?_0x2e1595[_0x5c29('0x40')][0x1][_0x5c29('0x43')]:undefined)||'0.00'},{'name':'attrFontSize','value':_0x2e1595[_0x5c29('0x48')]||(_0x2e1595[_0x5c29('0x40')]&&_0x2e1595[_0x5c29('0x40')][0x2]?_0x2e1595['attrs'][0x2][_0x5c29('0x43')]:undefined)||0xc}];case _0x5c29('0x49'):return[{'name':_0x5c29('0x4a'),'value':_0x2e1595[_0x5c29('0x4a')]||(_0x2e1595[_0x5c29('0x40')]&&_0x2e1595[_0x5c29('0x40')][0x0]?_0x2e1595[_0x5c29('0x40')][0x0][_0x5c29('0x43')]:undefined)||_0x5c29('0x4b')},{'name':_0x5c29('0x4c'),'value':_0x2e1595[_0x5c29('0x4c')]||(_0x2e1595[_0x5c29('0x40')]&&_0x2e1595['attrs'][0x1]?_0x2e1595[_0x5c29('0x40')][0x1][_0x5c29('0x43')]:undefined)||[]},{'name':_0x5c29('0x48'),'value':_0x2e1595['attrFontSize']||(_0x2e1595[_0x5c29('0x40')]&&_0x2e1595[_0x5c29('0x40')][0x2]?_0x2e1595[_0x5c29('0x40')][0x2][_0x5c29('0x43')]:undefined)||0x14}];case _0x5c29('0x4d'):case _0x5c29('0x4e'):return[{'name':_0x5c29('0x4f'),'value':_0x2e1595[_0x5c29('0x4f')]||(_0x2e1595['attrs']&&_0x2e1595[_0x5c29('0x40')][0x0]?_0x2e1595[_0x5c29('0x40')][0x0][_0x5c29('0x43')]:undefined)||'total'},{'name':'attrSerie2','value':_0x2e1595[_0x5c29('0x50')]||(_0x2e1595[_0x5c29('0x40')]&&_0x2e1595[_0x5c29('0x40')][0x1]?_0x2e1595[_0x5c29('0x40')][0x1]['value']:undefined)||null},{'name':_0x5c29('0x51'),'value':_0x2e1595[_0x5c29('0x51')]||(_0x2e1595[_0x5c29('0x40')]&&_0x2e1595[_0x5c29('0x40')][0x2]?_0x2e1595[_0x5c29('0x40')][0x2][_0x5c29('0x43')]:undefined)||null},{'name':'attrVoiceQueues','value':_0x2e1595[_0x5c29('0x4c')]||(_0x2e1595[_0x5c29('0x40')]&&_0x2e1595['attrs'][0x3]?_0x2e1595[_0x5c29('0x40')][0x3][_0x5c29('0x43')]:undefined)||[]}];case _0x5c29('0x52'):return[{'name':_0x5c29('0x53'),'type':_0x2e1595['reportType']||(_0x2e1595[_0x5c29('0x40')]&&_0x2e1595['attrs'][0x0]?_0x2e1595['attrs'][0x0]['type']:undefined)||null,'value':_0x2e1595[_0x5c29('0x53')]||(_0x2e1595[_0x5c29('0x40')]&&_0x2e1595[_0x5c29('0x40')][0x0]?_0x2e1595[_0x5c29('0x40')][0x0][_0x5c29('0x43')]:undefined)||null},{'name':_0x5c29('0x54'),'value':_0x2e1595[_0x5c29('0x54')]||(_0x2e1595[_0x5c29('0x40')]&&_0x2e1595[_0x5c29('0x40')][0x1]?_0x2e1595['attrs'][0x1]['value']:undefined)||0x0}];default:return[];}}catch(_0x221c6d){logger['error'](_0x5c29('0x55'),JSON[_0x5c29('0x56')](_0x221c6d));return[];}}exports['create']=function(_0x95c904,_0x2e0cab){if(_0x95c904['body']){_0x95c904[_0x5c29('0x57')]['attrs']=widgetAttributes(_0x95c904[_0x5c29('0x57')]);}return db['DashboardItem']['create'](_0x95c904['body'],{})[_0x5c29('0x3c')](respondWithResult(_0x2e0cab,0xc9))['catch'](handleError(_0x2e0cab,null));};exports[_0x5c29('0x26')]=function(_0x55eef0,_0x54e803){if(_0x55eef0[_0x5c29('0x57')]['id']){delete _0x55eef0['body']['id'];}_0x55eef0[_0x5c29('0x57')][_0x5c29('0x40')]=widgetAttributes(_0x55eef0[_0x5c29('0x57')]);return db[_0x5c29('0x31')][_0x5c29('0x58')]({'where':{'id':_0x55eef0['params']['id']}})['then'](handleEntityNotFound(_0x54e803,null))['then'](saveUpdates(_0x55eef0['body'],null))['then'](respondWithResult(_0x54e803,null))[_0x5c29('0x3d')](handleError(_0x54e803,null));};