report.rb 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Report
  3. def self.enabled?
  4. Setting.get('es_url').present?
  5. end
  6. def self.config
  7. config = {}
  8. config[:metric] = {}
  9. config[:metric][:count] = {
  10. name: 'count',
  11. display: __('Ticket Count'),
  12. default: true,
  13. prio: 10_000,
  14. }
  15. backend = [
  16. {
  17. name: 'created',
  18. display: __('Created'),
  19. selected: true,
  20. dataDownload: true,
  21. adapter: Report::TicketGenericTime,
  22. params: { field: 'created_at' }
  23. },
  24. {
  25. name: 'closed',
  26. display: __('Closed'),
  27. selected: true,
  28. dataDownload: true,
  29. adapter: Report::TicketGenericTime,
  30. params: { field: 'close_at' }
  31. },
  32. {
  33. name: 'backlog',
  34. display: __('Backlog'),
  35. selected: true,
  36. dataDownload: false,
  37. adapter: Report::TicketBacklog
  38. },
  39. {
  40. name: 'first_solution',
  41. display: __('First Solution'),
  42. selected: false,
  43. dataDownload: true,
  44. adapter: Report::TicketFirstSolution
  45. },
  46. {
  47. name: 'reopened',
  48. display: __('Reopened'),
  49. selected: false,
  50. dataDownload: true,
  51. adapter: Report::TicketReopened
  52. },
  53. {
  54. name: 'movedin',
  55. display: __('Moved in'),
  56. selected: false,
  57. dataDownload: true,
  58. adapter: Report::TicketMoved,
  59. params: { type: 'in' }
  60. },
  61. {
  62. name: 'movedout',
  63. display: __('Moved out'),
  64. selected: false,
  65. dataDownload: true,
  66. adapter: Report::TicketMoved,
  67. params: { type: 'out' }
  68. },
  69. {
  70. name: 'merged',
  71. display: __('Merged'),
  72. selected: false,
  73. dataDownload: true,
  74. adapter: Report::TicketMerged,
  75. },
  76. ]
  77. config[:metric][:count][:backend] = backend
  78. config[:metric][:create_channels] = {
  79. name: 'create_channels',
  80. display: __('Creation Channels'),
  81. prio: 9000,
  82. }
  83. backend = [
  84. {
  85. name: 'phone_in',
  86. display: __('Phone (in)'),
  87. selected: true,
  88. dataDownload: true,
  89. adapter: Report::TicketGenericTime,
  90. params: {
  91. field: 'created_at',
  92. selector: {
  93. 'create_article_type_id' => {
  94. 'operator' => 'is',
  95. 'value' => Ticket::Article::Type.lookup(name: 'phone').id,
  96. },
  97. 'create_article_sender_id' => {
  98. 'operator' => 'is',
  99. 'value' => Ticket::Article::Sender.lookup(name: 'Customer').id,
  100. },
  101. },
  102. },
  103. },
  104. {
  105. name: 'phone_out',
  106. display: __('Phone (out)'),
  107. selected: true,
  108. dataDownload: true,
  109. adapter: Report::TicketGenericTime,
  110. params: {
  111. field: 'created_at',
  112. selector: {
  113. 'create_article_type_id' => {
  114. 'operator' => 'is',
  115. 'value' => Ticket::Article::Type.lookup(name: 'phone').id,
  116. },
  117. 'create_article_sender_id' => {
  118. 'operator' => 'is',
  119. 'value' => Ticket::Article::Sender.lookup(name: 'Agent').id,
  120. },
  121. }
  122. },
  123. },
  124. {
  125. name: 'email_in',
  126. display: __('Email (in)'),
  127. selected: true,
  128. dataDownload: true,
  129. adapter: Report::TicketGenericTime,
  130. params: {
  131. field: 'created_at',
  132. selector: {
  133. 'create_article_type_id' => {
  134. 'operator' => 'is',
  135. 'value' => Ticket::Article::Type.lookup(name: 'email').id,
  136. },
  137. 'create_article_sender_id' => {
  138. 'operator' => 'is',
  139. 'value' => Ticket::Article::Sender.lookup(name: 'Customer').id,
  140. },
  141. },
  142. },
  143. },
  144. {
  145. name: 'email_out',
  146. display: __('Email (out)'),
  147. selected: true,
  148. dataDownload: true,
  149. adapter: Report::TicketGenericTime,
  150. params: {
  151. field: 'created_at',
  152. selector: {
  153. 'create_article_type_id' => {
  154. 'operator' => 'is',
  155. 'value' => Ticket::Article::Type.lookup(name: 'email').id,
  156. },
  157. 'create_article_sender_id' => {
  158. 'operator' => 'is',
  159. 'value' => Ticket::Article::Sender.lookup(name: 'Agent').id,
  160. },
  161. },
  162. },
  163. },
  164. {
  165. name: 'web_in',
  166. display: __('Web (in)'),
  167. selected: true,
  168. dataDownload: true,
  169. adapter: Report::TicketGenericTime,
  170. params: {
  171. field: 'created_at',
  172. selector: {
  173. 'create_article_type_id' => {
  174. 'operator' => 'is',
  175. 'value' => Ticket::Article::Type.lookup(name: 'web').id,
  176. },
  177. 'create_article_sender_id' => {
  178. 'operator' => 'is',
  179. 'value' => Ticket::Article::Sender.lookup(name: 'Customer').id,
  180. },
  181. },
  182. },
  183. },
  184. {
  185. name: 'twitter_in',
  186. display: __('Twitter (in)'),
  187. selected: true,
  188. dataDownload: true,
  189. adapter: Report::TicketGenericTime,
  190. params: {
  191. field: 'created_at',
  192. selector: {
  193. 'create_article_type_id' => {
  194. 'operator' => 'is',
  195. 'value' => Ticket::Article::Type.lookup(name: 'twitter status').id,
  196. },
  197. 'create_article_sender_id' => {
  198. 'operator' => 'is',
  199. 'value' => Ticket::Article::Sender.lookup(name: 'Customer').id,
  200. },
  201. },
  202. },
  203. },
  204. {
  205. name: 'twitter_out',
  206. display: __('Twitter (out)'),
  207. selected: true,
  208. dataDownload: true,
  209. adapter: Report::TicketGenericTime,
  210. params: {
  211. field: 'created_at',
  212. selector: {
  213. 'create_article_type_id' => {
  214. 'operator' => 'is',
  215. 'value' => Ticket::Article::Type.lookup(name: 'twitter status').id,
  216. },
  217. 'create_article_sender_id' => {
  218. 'operator' => 'is',
  219. 'value' => Ticket::Article::Sender.lookup(name: 'Agent').id,
  220. },
  221. },
  222. },
  223. },
  224. ]
  225. config[:metric][:create_channels][:backend] = backend
  226. config[:metric][:communication] = {
  227. name: 'communication',
  228. display: __('Communication'),
  229. prio: 7000,
  230. }
  231. backend = [
  232. {
  233. name: 'phone_in',
  234. display: __('Phone (in)'),
  235. selected: true,
  236. dataDownload: false,
  237. adapter: Report::ArticleByTypeSender,
  238. params: {
  239. type: 'phone',
  240. sender: 'Customer',
  241. },
  242. },
  243. {
  244. name: 'phone_out',
  245. display: __('Phone (out)'),
  246. selected: true,
  247. dataDownload: false,
  248. adapter: Report::ArticleByTypeSender,
  249. params: {
  250. type: 'phone',
  251. sender: 'Agent',
  252. },
  253. },
  254. {
  255. name: 'email_in',
  256. display: __('Email (in)'),
  257. selected: true,
  258. dataDownload: false,
  259. adapter: Report::ArticleByTypeSender,
  260. params: {
  261. type: 'email',
  262. sender: 'Customer',
  263. },
  264. },
  265. {
  266. name: 'email_out',
  267. display: __('Email (out)'),
  268. selected: true,
  269. dataDownload: false,
  270. adapter: Report::ArticleByTypeSender,
  271. params: {
  272. type: 'email',
  273. sender: 'Agent',
  274. },
  275. },
  276. {
  277. name: 'web_in',
  278. display: __('Web (in)'),
  279. selected: true,
  280. dataDownload: false,
  281. adapter: Report::ArticleByTypeSender,
  282. params: {
  283. type: 'web',
  284. sender: 'Customer',
  285. },
  286. },
  287. {
  288. name: 'twitter_in',
  289. display: __('Twitter (in)'),
  290. selected: true,
  291. dataDownload: false,
  292. adapter: Report::ArticleByTypeSender,
  293. params: {
  294. type: 'twitter status',
  295. sender: 'Customer',
  296. },
  297. },
  298. {
  299. name: 'twitter_out',
  300. display: __('Twitter (out)'),
  301. selected: true,
  302. dataDownload: false,
  303. adapter: Report::ArticleByTypeSender,
  304. params: {
  305. type: 'twitter status',
  306. sender: 'Agent',
  307. },
  308. },
  309. ]
  310. config[:metric][:communication][:backend] = backend
  311. config[:metric].each do |metric_key, metric_value|
  312. metric_value[:backend].each do |metric_backend|
  313. metric_backend[:name] = "#{metric_key}::#{metric_backend[:name]}"
  314. end
  315. end
  316. config
  317. end
  318. end