df1e2d19ca7573b8da9c34c776158cc1161a40d9
[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 _0xf515=['redis','defaults','socket.io-emitter','./dashboardItem.socket','register','status','count','offset','limit','Content-Range','json','apply','reject','update','then','destroy','end','sendStatus','error','name','send','show','model','keys','query','filters','attributes','intersection','fields','length','include','merge','options','DashboardItem','catch','find','params','type','iframe','attrUrl','attrs','value','attrPath','clock','attrHourFormat','HH:mm:ss','attrTimezone','attrFontSize','counter','attrMetric','total','attrVoiceQueues','multibar-chart','pie-chart','attrSerie1','attrSerie2','attrSerie3','web-report','attrReport','reportType','attrRefresh','stringify','create','body','html-pdf','eml-format','rimraf','fast-json-patch','request-promise','mustache','util','path','sox','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../mysqldb'];(function(_0x39d92c,_0x5da592){var _0x47065f=function(_0x246a91){while(--_0x246a91){_0x39d92c['push'](_0x39d92c['shift']());}};_0x47065f(++_0x5da592);}(_0xf515,0x98));var _0x5f51=function(_0x2e5dc0,_0x33a556){_0x2e5dc0=_0x2e5dc0-0x0;var _0x11589b=_0xf515[_0x2e5dc0];return _0x11589b;};'use strict';var pdf=require(_0x5f51('0x0'));var emlformat=require(_0x5f51('0x1'));var rimraf=require(_0x5f51('0x2'));var zipdir=require('zip-dir');var jsonpatch=require(_0x5f51('0x3'));var rp=require(_0x5f51('0x4'));var moment=require('moment');var BPromise=require('bluebird');var Mustache=require(_0x5f51('0x5'));var util=require(_0x5f51('0x6'));var path=require(_0x5f51('0x7'));var sox=require(_0x5f51('0x8'));var csv=require(_0x5f51('0x9'));var ejs=require(_0x5f51('0xa'));var fs=require('fs');var _=require(_0x5f51('0xb'));var squel=require(_0x5f51('0xc'));var crypto=require(_0x5f51('0xd'));var jsforce=require(_0x5f51('0xe'));var deskjs=require(_0x5f51('0xf'));var toCsv=require(_0x5f51('0x9'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0x5f51('0x10'));var authService=require(_0x5f51('0x11'));var qs=require(_0x5f51('0x12'));var as=require(_0x5f51('0x13'));var hardwareService=require(_0x5f51('0x14'));var logger=require(_0x5f51('0x15'))(_0x5f51('0x16'));var utils=require('../../config/utils');var config=require('../../config/environment');var db=require(_0x5f51('0x17'))['db'];config[_0x5f51('0x18')]=_[_0x5f51('0x19')](config[_0x5f51('0x18')],{'host':'localhost','port':0x18eb});var socket=require(_0x5f51('0x1a'))(new Redis(config[_0x5f51('0x18')]));require(_0x5f51('0x1b'))[_0x5f51('0x1c')](socket);function respondWithStatusCode(_0x5c4f71,_0x4335c1){_0x4335c1=_0x4335c1||0xcc;return function(_0x2b56fa){if(_0x2b56fa){return _0x5c4f71['sendStatus'](_0x4335c1);}return _0x5c4f71[_0x5f51('0x1d')](_0x4335c1)['end']();};}function respondWithResult(_0x583173,_0x4f60d4){_0x4f60d4=_0x4f60d4||0xc8;return function(_0x43a116){if(_0x43a116){return _0x583173[_0x5f51('0x1d')](_0x4f60d4)['json'](_0x43a116);}};}function respondWithFilteredResult(_0x31e771,_0x3fc378){return function(_0x1acd72){if(_0x1acd72){var _0x5eab6a=_0x1acd72[_0x5f51('0x1e')],_0x4c7fbb=_0x3fc378['offset'],_0x8a6c78=_0x3fc378[_0x5f51('0x1f')]+_0x3fc378[_0x5f51('0x20')],_0x33155a;if(_0x8a6c78>=_0x5eab6a){_0x8a6c78=_0x5eab6a;_0x33155a=0xc8;}else{_0x33155a=0xce;}_0x31e771['status'](_0x33155a);return _0x31e771['set'](_0x5f51('0x21'),_0x4c7fbb+'-'+_0x8a6c78+'/'+_0x5eab6a)[_0x5f51('0x22')](_0x1acd72);}return null;};}function patchUpdates(_0x3e5ec3){return function(_0x5c4fa3){try{jsonpatch[_0x5f51('0x23')](_0x5c4fa3,_0x3e5ec3,!![]);}catch(_0x69e8bb){return BPromise[_0x5f51('0x24')](_0x69e8bb);}return _0x5c4fa3['save']();};}function saveUpdates(_0x2d8954,_0x13a79d){return function(_0x2bba08){if(_0x2bba08){return _0x2bba08[_0x5f51('0x25')](_0x2d8954)[_0x5f51('0x26')](function(_0x546665){return _0x546665;});}return null;};}function removeEntity(_0x1318d6,_0x91b992){return function(_0x299dba){if(_0x299dba){return _0x299dba[_0x5f51('0x27')]()[_0x5f51('0x26')](function(){_0x1318d6['status'](0xcc)[_0x5f51('0x28')]();});}};}function handleEntityNotFound(_0x419bcd,_0x4ba588){return function(_0x1e7651){if(!_0x1e7651){_0x419bcd[_0x5f51('0x29')](0x194);}return _0x1e7651;};}function handleError(_0x2b1e8b,_0x1b3bbf){_0x1b3bbf=_0x1b3bbf||0x1f4;return function(_0x5d6eab){logger[_0x5f51('0x2a')](_0x5d6eab['stack']);if(_0x5d6eab[_0x5f51('0x2b')]){delete _0x5d6eab[_0x5f51('0x2b')];}_0x2b1e8b[_0x5f51('0x1d')](_0x1b3bbf)[_0x5f51('0x2c')](_0x5d6eab);};}exports[_0x5f51('0x2d')]=function(_0x19a525,_0x5bfeef){var _0x3cc1c1={'raw':![],'where':{'id':_0x19a525['params']['id']}},_0x48d024={};_0x48d024[_0x5f51('0x2e')]=_[_0x5f51('0x2f')](db['DashboardItem']['rawAttributes']);_0x48d024[_0x5f51('0x30')]=_[_0x5f51('0x2f')](_0x19a525[_0x5f51('0x30')]);_0x48d024[_0x5f51('0x31')]=_['intersection'](_0x48d024[_0x5f51('0x2e')],_0x48d024[_0x5f51('0x30')]);_0x3cc1c1[_0x5f51('0x32')]=_[_0x5f51('0x33')](_0x48d024[_0x5f51('0x2e')],qs[_0x5f51('0x34')](_0x19a525[_0x5f51('0x30')][_0x5f51('0x34')]));_0x3cc1c1[_0x5f51('0x32')]=_0x3cc1c1[_0x5f51('0x32')][_0x5f51('0x35')]?_0x3cc1c1[_0x5f51('0x32')]:_0x48d024[_0x5f51('0x2e')];if(_0x19a525[_0x5f51('0x30')]['includeAll']){_0x3cc1c1[_0x5f51('0x36')]=[{'all':!![]}];}_0x3cc1c1=_[_0x5f51('0x37')]({},_0x3cc1c1,_0x19a525[_0x5f51('0x38')]);return db[_0x5f51('0x39')]['find'](_0x3cc1c1)['then'](handleEntityNotFound(_0x5bfeef,null))[_0x5f51('0x26')](respondWithResult(_0x5bfeef,null))[_0x5f51('0x3a')](handleError(_0x5bfeef,null));};exports[_0x5f51('0x27')]=function(_0x5d1c88,_0x3f97dc){return db['DashboardItem'][_0x5f51('0x3b')]({'where':{'id':_0x5d1c88[_0x5f51('0x3c')]['id']}})['then'](handleEntityNotFound(_0x3f97dc,null))[_0x5f51('0x26')](removeEntity(_0x3f97dc,null))['catch'](handleError(_0x3f97dc,null));};function widgetAttributes(_0x1c7b77){try{switch(_0x1c7b77[_0x5f51('0x3d')]){case _0x5f51('0x3e'):return[{'name':_0x5f51('0x3f'),'value':_0x1c7b77[_0x5f51('0x3f')]||(_0x1c7b77[_0x5f51('0x40')]&&_0x1c7b77[_0x5f51('0x40')][0x0]?_0x1c7b77['attrs'][0x0][_0x5f51('0x41')]:undefined)||'https://'}];case'custom':return[{'name':_0x5f51('0x42'),'value':_0x1c7b77[_0x5f51('0x42')]||(_0x1c7b77[_0x5f51('0x40')]&&_0x1c7b77[_0x5f51('0x40')][0x0]?_0x1c7b77[_0x5f51('0x40')][0x0][_0x5f51('0x41')]:undefined)||''}];case _0x5f51('0x43'):return[{'name':'attrHourFormat','value':_0x1c7b77[_0x5f51('0x44')]||(_0x1c7b77[_0x5f51('0x40')]&&_0x1c7b77[_0x5f51('0x40')][0x0]?_0x1c7b77[_0x5f51('0x40')][0x0][_0x5f51('0x41')]:undefined)||_0x5f51('0x45')},{'name':_0x5f51('0x46'),'value':_0x1c7b77[_0x5f51('0x46')]||(_0x1c7b77[_0x5f51('0x40')]&&_0x1c7b77[_0x5f51('0x40')][0x1]?_0x1c7b77[_0x5f51('0x40')][0x1][_0x5f51('0x41')]:undefined)||'0.00'},{'name':'attrFontSize','value':_0x1c7b77[_0x5f51('0x47')]||(_0x1c7b77['attrs']&&_0x1c7b77[_0x5f51('0x40')][0x2]?_0x1c7b77[_0x5f51('0x40')][0x2][_0x5f51('0x41')]:undefined)||0xc}];case _0x5f51('0x48'):return[{'name':_0x5f51('0x49'),'value':_0x1c7b77['attrMetric']||(_0x1c7b77[_0x5f51('0x40')]&&_0x1c7b77[_0x5f51('0x40')][0x0]?_0x1c7b77['attrs'][0x0]['value']:undefined)||_0x5f51('0x4a')},{'name':_0x5f51('0x4b'),'value':_0x1c7b77['attrVoiceQueues']||(_0x1c7b77['attrs']&&_0x1c7b77[_0x5f51('0x40')][0x1]?_0x1c7b77['attrs'][0x1][_0x5f51('0x41')]:undefined)||[]},{'name':_0x5f51('0x47'),'value':_0x1c7b77[_0x5f51('0x47')]||(_0x1c7b77[_0x5f51('0x40')]&&_0x1c7b77[_0x5f51('0x40')][0x2]?_0x1c7b77[_0x5f51('0x40')][0x2][_0x5f51('0x41')]:undefined)||0x14}];case _0x5f51('0x4c'):case _0x5f51('0x4d'):return[{'name':_0x5f51('0x4e'),'value':_0x1c7b77[_0x5f51('0x4e')]||(_0x1c7b77['attrs']&&_0x1c7b77[_0x5f51('0x40')][0x0]?_0x1c7b77['attrs'][0x0]['value']:undefined)||_0x5f51('0x4a')},{'name':_0x5f51('0x4f'),'value':_0x1c7b77[_0x5f51('0x4f')]||(_0x1c7b77['attrs']&&_0x1c7b77[_0x5f51('0x40')][0x1]?_0x1c7b77[_0x5f51('0x40')][0x1][_0x5f51('0x41')]:undefined)||null},{'name':_0x5f51('0x50'),'value':_0x1c7b77[_0x5f51('0x50')]||(_0x1c7b77[_0x5f51('0x40')]&&_0x1c7b77[_0x5f51('0x40')][0x2]?_0x1c7b77[_0x5f51('0x40')][0x2]['value']:undefined)||null},{'name':_0x5f51('0x4b'),'value':_0x1c7b77[_0x5f51('0x4b')]||(_0x1c7b77[_0x5f51('0x40')]&&_0x1c7b77[_0x5f51('0x40')][0x3]?_0x1c7b77[_0x5f51('0x40')][0x3][_0x5f51('0x41')]:undefined)||[]}];case _0x5f51('0x51'):return[{'name':_0x5f51('0x52'),'type':_0x1c7b77[_0x5f51('0x53')]||(_0x1c7b77[_0x5f51('0x40')]&&_0x1c7b77['attrs'][0x0]?_0x1c7b77['attrs'][0x0][_0x5f51('0x3d')]:undefined)||null,'value':_0x1c7b77['attrReport']||(_0x1c7b77['attrs']&&_0x1c7b77[_0x5f51('0x40')][0x0]?_0x1c7b77[_0x5f51('0x40')][0x0][_0x5f51('0x41')]:undefined)||null},{'name':_0x5f51('0x54'),'value':_0x1c7b77[_0x5f51('0x54')]||(_0x1c7b77[_0x5f51('0x40')]&&_0x1c7b77[_0x5f51('0x40')][0x1]?_0x1c7b77['attrs'][0x1][_0x5f51('0x41')]:undefined)||0x0}];default:return[];}}catch(_0x5243e6){logger[_0x5f51('0x2a')]('widgetAttributes:\x20%s',JSON[_0x5f51('0x55')](_0x5243e6));return[];}}exports[_0x5f51('0x56')]=function(_0x2966a3,_0x105ef3){if(_0x2966a3[_0x5f51('0x57')]){_0x2966a3[_0x5f51('0x57')][_0x5f51('0x40')]=widgetAttributes(_0x2966a3[_0x5f51('0x57')]);}return db[_0x5f51('0x39')]['create'](_0x2966a3['body'],{})[_0x5f51('0x26')](respondWithResult(_0x105ef3,0xc9))[_0x5f51('0x3a')](handleError(_0x105ef3,null));};exports[_0x5f51('0x25')]=function(_0x50e16b,_0x1990da){if(_0x50e16b[_0x5f51('0x57')]['id']){delete _0x50e16b[_0x5f51('0x57')]['id'];}_0x50e16b[_0x5f51('0x57')][_0x5f51('0x40')]=widgetAttributes(_0x50e16b[_0x5f51('0x57')]);return db[_0x5f51('0x39')][_0x5f51('0x3b')]({'where':{'id':_0x50e16b[_0x5f51('0x3c')]['id']}})[_0x5f51('0x26')](handleEntityNotFound(_0x1990da,null))['then'](saveUpdates(_0x50e16b[_0x5f51('0x57')],null))['then'](respondWithResult(_0x1990da,null))[_0x5f51('0x3a')](handleError(_0x1990da,null));};