Built motion from commit (unavailable).|2.5.3
[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 _0x1946=['attrFontSize','counter','attrMetric','attrVoiceQueues','multibar-chart','pie-chart','attrSerie1','total','attrSerie2','attrSerie3','web-report','attrReport','reportType','attrRefresh','stringify','create','body','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','util','to-csv','ejs','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../mysqldb','redis','defaults','./dashboardItem.socket','register','sendStatus','status','json','count','limit','Content-Range','apply','reject','save','update','then','destroy','error','stack','name','show','params','model','keys','DashboardItem','query','attributes','fields','includeAll','include','merge','catch','find','type','iframe','attrUrl','attrs','value','https://','custom','attrPath','clock','attrHourFormat','HH:mm:ss','attrTimezone'];(function(_0x56a2e8,_0x3b3583){var _0x15daac=function(_0x37c49a){while(--_0x37c49a){_0x56a2e8['push'](_0x56a2e8['shift']());}};_0x15daac(++_0x3b3583);}(_0x1946,0xb9));var _0x6194=function(_0x129ae7,_0x1107be){_0x129ae7=_0x129ae7-0x0;var _0x116159=_0x1946[_0x129ae7];return _0x116159;};'use strict';var pdf=require(_0x6194('0x0'));var emlformat=require(_0x6194('0x1'));var rimraf=require(_0x6194('0x2'));var zipdir=require(_0x6194('0x3'));var jsonpatch=require(_0x6194('0x4'));var rp=require(_0x6194('0x5'));var moment=require(_0x6194('0x6'));var BPromise=require('bluebird');var Mustache=require(_0x6194('0x7'));var util=require(_0x6194('0x8'));var path=require('path');var sox=require('sox');var csv=require(_0x6194('0x9'));var ejs=require(_0x6194('0xa'));var fs=require('fs');var _=require('lodash');var squel=require('squel');var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0x6194('0xb'));var toCsv=require(_0x6194('0x9'));var querystring=require(_0x6194('0xc'));var Papa=require(_0x6194('0xd'));var Redis=require(_0x6194('0xe'));var authService=require(_0x6194('0xf'));var qs=require(_0x6194('0x10'));var as=require(_0x6194('0x11'));var hardwareService=require(_0x6194('0x12'));var logger=require(_0x6194('0x13'))(_0x6194('0x14'));var utils=require('../../config/utils');var config=require(_0x6194('0x15'));var db=require(_0x6194('0x16'))['db'];config[_0x6194('0x17')]=_[_0x6194('0x18')](config[_0x6194('0x17')],{'host':'localhost','port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config['redis']));require(_0x6194('0x19'))[_0x6194('0x1a')](socket);function respondWithStatusCode(_0x2f1f2e,_0x11033e){_0x11033e=_0x11033e||0xcc;return function(_0x53be37){if(_0x53be37){return _0x2f1f2e[_0x6194('0x1b')](_0x11033e);}return _0x2f1f2e['status'](_0x11033e)['end']();};}function respondWithResult(_0x37c806,_0x268369){_0x268369=_0x268369||0xc8;return function(_0x17fcbc){if(_0x17fcbc){return _0x37c806[_0x6194('0x1c')](_0x268369)[_0x6194('0x1d')](_0x17fcbc);}};}function respondWithFilteredResult(_0x5c9934,_0x4da5ae){return function(_0x25d641){if(_0x25d641){var _0x2c3006=_0x25d641[_0x6194('0x1e')],_0x52ab3c=_0x4da5ae['offset'],_0x380832=_0x4da5ae['offset']+_0x4da5ae[_0x6194('0x1f')],_0xe69b33;if(_0x380832>=_0x2c3006){_0x380832=_0x2c3006;_0xe69b33=0xc8;}else{_0xe69b33=0xce;}_0x5c9934['status'](_0xe69b33);return _0x5c9934['set'](_0x6194('0x20'),_0x52ab3c+'-'+_0x380832+'/'+_0x2c3006)[_0x6194('0x1d')](_0x25d641);}return null;};}function patchUpdates(_0x557b6f){return function(_0x22a436){try{jsonpatch[_0x6194('0x21')](_0x22a436,_0x557b6f,!![]);}catch(_0x8195f5){return BPromise[_0x6194('0x22')](_0x8195f5);}return _0x22a436[_0x6194('0x23')]();};}function saveUpdates(_0xd2863a,_0x3b9e9d){return function(_0x413beb){if(_0x413beb){return _0x413beb[_0x6194('0x24')](_0xd2863a)[_0x6194('0x25')](function(_0xe8cb8b){return _0xe8cb8b;});}return null;};}function removeEntity(_0x20e628,_0x5d769a){return function(_0x2a86f1){if(_0x2a86f1){return _0x2a86f1[_0x6194('0x26')]()['then'](function(){_0x20e628[_0x6194('0x1c')](0xcc)['end']();});}};}function handleEntityNotFound(_0x32301f,_0x2793b0){return function(_0x3ee0cb){if(!_0x3ee0cb){_0x32301f[_0x6194('0x1b')](0x194);}return _0x3ee0cb;};}function handleError(_0x8b9c02,_0x476ad7){_0x476ad7=_0x476ad7||0x1f4;return function(_0x44d031){logger[_0x6194('0x27')](_0x44d031[_0x6194('0x28')]);if(_0x44d031[_0x6194('0x29')]){delete _0x44d031['name'];}_0x8b9c02[_0x6194('0x1c')](_0x476ad7)['send'](_0x44d031);};}exports[_0x6194('0x2a')]=function(_0x223c24,_0x4ae3da){var _0x176b8e={'raw':![],'where':{'id':_0x223c24[_0x6194('0x2b')]['id']}},_0x246ff8={};_0x246ff8[_0x6194('0x2c')]=_[_0x6194('0x2d')](db[_0x6194('0x2e')]['rawAttributes']);_0x246ff8[_0x6194('0x2f')]=_[_0x6194('0x2d')](_0x223c24[_0x6194('0x2f')]);_0x246ff8['filters']=_['intersection'](_0x246ff8['model'],_0x246ff8[_0x6194('0x2f')]);_0x176b8e[_0x6194('0x30')]=_['intersection'](_0x246ff8[_0x6194('0x2c')],qs[_0x6194('0x31')](_0x223c24['query']['fields']));_0x176b8e['attributes']=_0x176b8e[_0x6194('0x30')]['length']?_0x176b8e[_0x6194('0x30')]:_0x246ff8[_0x6194('0x2c')];if(_0x223c24['query'][_0x6194('0x32')]){_0x176b8e[_0x6194('0x33')]=[{'all':!![]}];}_0x176b8e=_[_0x6194('0x34')]({},_0x176b8e,_0x223c24['options']);return db['DashboardItem']['find'](_0x176b8e)['then'](handleEntityNotFound(_0x4ae3da,null))[_0x6194('0x25')](respondWithResult(_0x4ae3da,null))[_0x6194('0x35')](handleError(_0x4ae3da,null));};exports[_0x6194('0x26')]=function(_0x585504,_0x31dc11){return db[_0x6194('0x2e')][_0x6194('0x36')]({'where':{'id':_0x585504[_0x6194('0x2b')]['id']}})[_0x6194('0x25')](handleEntityNotFound(_0x31dc11,null))[_0x6194('0x25')](removeEntity(_0x31dc11,null))[_0x6194('0x35')](handleError(_0x31dc11,null));};function widgetAttributes(_0x5dc31c){try{switch(_0x5dc31c[_0x6194('0x37')]){case _0x6194('0x38'):return[{'name':_0x6194('0x39'),'value':_0x5dc31c[_0x6194('0x39')]||(_0x5dc31c[_0x6194('0x3a')]&&_0x5dc31c[_0x6194('0x3a')][0x0]?_0x5dc31c[_0x6194('0x3a')][0x0][_0x6194('0x3b')]:undefined)||_0x6194('0x3c')}];case _0x6194('0x3d'):return[{'name':_0x6194('0x3e'),'value':_0x5dc31c['attrPath']||(_0x5dc31c[_0x6194('0x3a')]&&_0x5dc31c[_0x6194('0x3a')][0x0]?_0x5dc31c['attrs'][0x0]['value']:undefined)||''}];case _0x6194('0x3f'):return[{'name':'attrHourFormat','value':_0x5dc31c[_0x6194('0x40')]||(_0x5dc31c[_0x6194('0x3a')]&&_0x5dc31c[_0x6194('0x3a')][0x0]?_0x5dc31c[_0x6194('0x3a')][0x0][_0x6194('0x3b')]:undefined)||_0x6194('0x41')},{'name':'attrTimezone','value':_0x5dc31c[_0x6194('0x42')]||(_0x5dc31c[_0x6194('0x3a')]&&_0x5dc31c[_0x6194('0x3a')][0x1]?_0x5dc31c['attrs'][0x1][_0x6194('0x3b')]:undefined)||'0.00'},{'name':_0x6194('0x43'),'value':_0x5dc31c[_0x6194('0x43')]||(_0x5dc31c[_0x6194('0x3a')]&&_0x5dc31c['attrs'][0x2]?_0x5dc31c['attrs'][0x2][_0x6194('0x3b')]:undefined)||0xc}];case _0x6194('0x44'):return[{'name':_0x6194('0x45'),'value':_0x5dc31c[_0x6194('0x45')]||(_0x5dc31c[_0x6194('0x3a')]&&_0x5dc31c[_0x6194('0x3a')][0x0]?_0x5dc31c[_0x6194('0x3a')][0x0][_0x6194('0x3b')]:undefined)||'total'},{'name':_0x6194('0x46'),'value':_0x5dc31c['attrVoiceQueues']||(_0x5dc31c[_0x6194('0x3a')]&&_0x5dc31c['attrs'][0x1]?_0x5dc31c[_0x6194('0x3a')][0x1][_0x6194('0x3b')]:undefined)||[]},{'name':_0x6194('0x43'),'value':_0x5dc31c['attrFontSize']||(_0x5dc31c[_0x6194('0x3a')]&&_0x5dc31c[_0x6194('0x3a')][0x2]?_0x5dc31c[_0x6194('0x3a')][0x2][_0x6194('0x3b')]:undefined)||0x14}];case _0x6194('0x47'):case _0x6194('0x48'):return[{'name':_0x6194('0x49'),'value':_0x5dc31c['attrSerie1']||(_0x5dc31c[_0x6194('0x3a')]&&_0x5dc31c['attrs'][0x0]?_0x5dc31c[_0x6194('0x3a')][0x0]['value']:undefined)||_0x6194('0x4a')},{'name':_0x6194('0x4b'),'value':_0x5dc31c[_0x6194('0x4b')]||(_0x5dc31c[_0x6194('0x3a')]&&_0x5dc31c[_0x6194('0x3a')][0x1]?_0x5dc31c[_0x6194('0x3a')][0x1][_0x6194('0x3b')]:undefined)||null},{'name':'attrSerie3','value':_0x5dc31c[_0x6194('0x4c')]||(_0x5dc31c[_0x6194('0x3a')]&&_0x5dc31c['attrs'][0x2]?_0x5dc31c['attrs'][0x2][_0x6194('0x3b')]:undefined)||null},{'name':_0x6194('0x46'),'value':_0x5dc31c[_0x6194('0x46')]||(_0x5dc31c['attrs']&&_0x5dc31c[_0x6194('0x3a')][0x3]?_0x5dc31c[_0x6194('0x3a')][0x3]['value']:undefined)||[]}];case _0x6194('0x4d'):return[{'name':_0x6194('0x4e'),'type':_0x5dc31c[_0x6194('0x4f')]||(_0x5dc31c[_0x6194('0x3a')]&&_0x5dc31c[_0x6194('0x3a')][0x0]?_0x5dc31c[_0x6194('0x3a')][0x0]['type']:undefined)||null,'value':_0x5dc31c[_0x6194('0x4e')]||(_0x5dc31c[_0x6194('0x3a')]&&_0x5dc31c[_0x6194('0x3a')][0x0]?_0x5dc31c['attrs'][0x0][_0x6194('0x3b')]:undefined)||null},{'name':_0x6194('0x50'),'value':_0x5dc31c[_0x6194('0x50')]||(_0x5dc31c[_0x6194('0x3a')]&&_0x5dc31c[_0x6194('0x3a')][0x1]?_0x5dc31c[_0x6194('0x3a')][0x1][_0x6194('0x3b')]:undefined)||0x0}];default:return[];}}catch(_0x388e5e){logger[_0x6194('0x27')]('widgetAttributes:\x20%s',JSON[_0x6194('0x51')](_0x388e5e));return[];}}exports[_0x6194('0x52')]=function(_0x432cbb,_0x5c83d8){if(_0x432cbb[_0x6194('0x53')]){_0x432cbb['body'][_0x6194('0x3a')]=widgetAttributes(_0x432cbb[_0x6194('0x53')]);}return db[_0x6194('0x2e')][_0x6194('0x52')](_0x432cbb[_0x6194('0x53')],{})[_0x6194('0x25')](respondWithResult(_0x5c83d8,0xc9))[_0x6194('0x35')](handleError(_0x5c83d8,null));};exports[_0x6194('0x24')]=function(_0x3eda41,_0x3d84b7){if(_0x3eda41[_0x6194('0x53')]['id']){delete _0x3eda41[_0x6194('0x53')]['id'];}_0x3eda41[_0x6194('0x53')][_0x6194('0x3a')]=widgetAttributes(_0x3eda41[_0x6194('0x53')]);return db[_0x6194('0x2e')][_0x6194('0x36')]({'where':{'id':_0x3eda41[_0x6194('0x2b')]['id']}})[_0x6194('0x25')](handleEntityNotFound(_0x3d84b7,null))['then'](saveUpdates(_0x3eda41[_0x6194('0x53')],null))[_0x6194('0x25')](respondWithResult(_0x3d84b7,null))[_0x6194('0x35')](handleError(_0x3d84b7,null));};