report.rb 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. # Copyright (C) 2012-2023 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. config[:metric][:count][:backend] = backend
  71. config[:metric][:create_channels] = {
  72. name: 'create_channels',
  73. display: __('Creation Channels'),
  74. prio: 9000,
  75. }
  76. backend = [
  77. {
  78. name: 'phone_in',
  79. display: __('Phone (in)'),
  80. selected: true,
  81. dataDownload: true,
  82. adapter: Report::TicketGenericTime,
  83. params: {
  84. field: 'created_at',
  85. selector: {
  86. 'create_article_type_id' => {
  87. 'operator' => 'is',
  88. 'value' => Ticket::Article::Type.lookup(name: 'phone').id,
  89. },
  90. 'create_article_sender_id' => {
  91. 'operator' => 'is',
  92. 'value' => Ticket::Article::Sender.lookup(name: 'Customer').id,
  93. },
  94. },
  95. },
  96. },
  97. {
  98. name: 'phone_out',
  99. display: __('Phone (out)'),
  100. selected: true,
  101. dataDownload: true,
  102. adapter: Report::TicketGenericTime,
  103. params: {
  104. field: 'created_at',
  105. selector: {
  106. 'create_article_type_id' => {
  107. 'operator' => 'is',
  108. 'value' => Ticket::Article::Type.lookup(name: 'phone').id,
  109. },
  110. 'create_article_sender_id' => {
  111. 'operator' => 'is',
  112. 'value' => Ticket::Article::Sender.lookup(name: 'Agent').id,
  113. },
  114. }
  115. },
  116. },
  117. {
  118. name: 'email_in',
  119. display: __('Email (in)'),
  120. selected: true,
  121. dataDownload: true,
  122. adapter: Report::TicketGenericTime,
  123. params: {
  124. field: 'created_at',
  125. selector: {
  126. 'create_article_type_id' => {
  127. 'operator' => 'is',
  128. 'value' => Ticket::Article::Type.lookup(name: 'email').id,
  129. },
  130. 'create_article_sender_id' => {
  131. 'operator' => 'is',
  132. 'value' => Ticket::Article::Sender.lookup(name: 'Customer').id,
  133. },
  134. },
  135. },
  136. },
  137. {
  138. name: 'email_out',
  139. display: __('Email (out)'),
  140. selected: true,
  141. dataDownload: true,
  142. adapter: Report::TicketGenericTime,
  143. params: {
  144. field: 'created_at',
  145. selector: {
  146. 'create_article_type_id' => {
  147. 'operator' => 'is',
  148. 'value' => Ticket::Article::Type.lookup(name: 'email').id,
  149. },
  150. 'create_article_sender_id' => {
  151. 'operator' => 'is',
  152. 'value' => Ticket::Article::Sender.lookup(name: 'Agent').id,
  153. },
  154. },
  155. },
  156. },
  157. {
  158. name: 'web_in',
  159. display: __('Web (in)'),
  160. selected: true,
  161. dataDownload: true,
  162. adapter: Report::TicketGenericTime,
  163. params: {
  164. field: 'created_at',
  165. selector: {
  166. 'create_article_type_id' => {
  167. 'operator' => 'is',
  168. 'value' => Ticket::Article::Type.lookup(name: 'web').id,
  169. },
  170. 'create_article_sender_id' => {
  171. 'operator' => 'is',
  172. 'value' => Ticket::Article::Sender.lookup(name: 'Customer').id,
  173. },
  174. },
  175. },
  176. },
  177. {
  178. name: 'twitter_in',
  179. display: __('Twitter (in)'),
  180. selected: true,
  181. dataDownload: true,
  182. adapter: Report::TicketGenericTime,
  183. params: {
  184. field: 'created_at',
  185. selector: {
  186. 'create_article_type_id' => {
  187. 'operator' => 'is',
  188. 'value' => Ticket::Article::Type.lookup(name: 'twitter status').id,
  189. },
  190. 'create_article_sender_id' => {
  191. 'operator' => 'is',
  192. 'value' => Ticket::Article::Sender.lookup(name: 'Customer').id,
  193. },
  194. },
  195. },
  196. },
  197. {
  198. name: 'twitter_out',
  199. display: __('Twitter (out)'),
  200. selected: true,
  201. dataDownload: true,
  202. adapter: Report::TicketGenericTime,
  203. params: {
  204. field: 'created_at',
  205. selector: {
  206. 'create_article_type_id' => {
  207. 'operator' => 'is',
  208. 'value' => Ticket::Article::Type.lookup(name: 'twitter status').id,
  209. },
  210. 'create_article_sender_id' => {
  211. 'operator' => 'is',
  212. 'value' => Ticket::Article::Sender.lookup(name: 'Agent').id,
  213. },
  214. },
  215. },
  216. },
  217. ]
  218. config[:metric][:create_channels][:backend] = backend
  219. config[:metric][:communication] = {
  220. name: 'communication',
  221. display: __('Communication'),
  222. prio: 7000,
  223. }
  224. backend = [
  225. {
  226. name: 'phone_in',
  227. display: __('Phone (in)'),
  228. selected: true,
  229. dataDownload: false,
  230. adapter: Report::ArticleByTypeSender,
  231. params: {
  232. type: 'phone',
  233. sender: 'Customer',
  234. },
  235. },
  236. {
  237. name: 'phone_out',
  238. display: __('Phone (out)'),
  239. selected: true,
  240. dataDownload: false,
  241. adapter: Report::ArticleByTypeSender,
  242. params: {
  243. type: 'phone',
  244. sender: 'Agent',
  245. },
  246. },
  247. {
  248. name: 'email_in',
  249. display: __('Email (in)'),
  250. selected: true,
  251. dataDownload: false,
  252. adapter: Report::ArticleByTypeSender,
  253. params: {
  254. type: 'email',
  255. sender: 'Customer',
  256. },
  257. },
  258. {
  259. name: 'email_out',
  260. display: __('Email (out)'),
  261. selected: true,
  262. dataDownload: false,
  263. adapter: Report::ArticleByTypeSender,
  264. params: {
  265. type: 'email',
  266. sender: 'Agent',
  267. },
  268. },
  269. {
  270. name: 'web_in',
  271. display: __('Web (in)'),
  272. selected: true,
  273. dataDownload: false,
  274. adapter: Report::ArticleByTypeSender,
  275. params: {
  276. type: 'web',
  277. sender: 'Customer',
  278. },
  279. },
  280. {
  281. name: 'twitter_in',
  282. display: __('Twitter (in)'),
  283. selected: true,
  284. dataDownload: false,
  285. adapter: Report::ArticleByTypeSender,
  286. params: {
  287. type: 'twitter status',
  288. sender: 'Customer',
  289. },
  290. },
  291. {
  292. name: 'twitter_out',
  293. display: __('Twitter (out)'),
  294. selected: true,
  295. dataDownload: false,
  296. adapter: Report::ArticleByTypeSender,
  297. params: {
  298. type: 'twitter status',
  299. sender: 'Agent',
  300. },
  301. },
  302. ]
  303. config[:metric][:communication][:backend] = backend
  304. config[:metric].each do |metric_key, metric_value|
  305. metric_value[:backend].each do |metric_backend|
  306. metric_backend[:name] = "#{metric_key}::#{metric_backend[:name]}"
  307. end
  308. end
  309. config
  310. end
  311. end