object_manager_attribute.rb 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. FactoryBot.define do
  2. factory :object_manager_attribute, class: 'ObjectManager::Attribute' do
  3. transient do
  4. object_name { 'Ticket' }
  5. additional_data_options { nil }
  6. end
  7. object_lookup_id { ObjectLookup.by_name(object_name) }
  8. sequence(:name) { |n| "internal_name#{n}" }
  9. sequence(:display) { |n| "Display Name #{n}" }
  10. data_option_new { {} }
  11. editable { true }
  12. active { true }
  13. add_attribute(:to_create) { true }
  14. to_migrate { true }
  15. to_delete { false }
  16. to_config { false }
  17. position { 15 }
  18. updated_by_id { 1 }
  19. created_by_id { 1 }
  20. screens do
  21. {
  22. 'create_top' => {
  23. '-all-' => {
  24. 'null' => false
  25. }
  26. },
  27. 'edit' => {}
  28. }
  29. end
  30. callback(:after_stub, :before_create) do |object, context|
  31. next if context.additional_data_options.blank?
  32. object.data_option ||= {}
  33. object.data_option.merge! context.additional_data_options
  34. end
  35. end
  36. factory :object_manager_attribute_text, parent: :object_manager_attribute do
  37. data_type { 'input' }
  38. data_option do
  39. {
  40. 'type' => 'text',
  41. 'maxlength' => 200,
  42. 'null' => true,
  43. 'translate' => false,
  44. 'default' => '',
  45. 'options' => {},
  46. 'relation' => '',
  47. }
  48. end
  49. end
  50. factory :object_manager_attribute_integer, parent: :object_manager_attribute do
  51. data_type { 'integer' }
  52. data_option do
  53. {
  54. 'default' => 0,
  55. 'min' => 0,
  56. 'max' => 9999,
  57. }
  58. end
  59. end
  60. factory :object_manager_attribute_boolean, parent: :object_manager_attribute do
  61. data_type { 'boolean' }
  62. data_option do
  63. {
  64. default: false,
  65. options: {
  66. true => 'yes',
  67. false => 'no',
  68. }
  69. }
  70. end
  71. end
  72. factory :object_manager_attribute_date, parent: :object_manager_attribute do
  73. name { 'date_attribute' }
  74. data_type { 'date' }
  75. data_option do
  76. {
  77. 'diff' => 24,
  78. 'null' => true,
  79. }
  80. end
  81. end
  82. factory :object_manager_attribute_datetime, parent: :object_manager_attribute do
  83. name { 'datetime_attribute' }
  84. data_type { 'datetime' }
  85. data_option do
  86. {
  87. 'future' => true,
  88. 'past' => true,
  89. 'diff' => 24,
  90. 'null' => true,
  91. }
  92. end
  93. end
  94. factory :object_manager_attribute_select, parent: :object_manager_attribute do
  95. data_type { 'select' }
  96. data_option do
  97. {
  98. 'default' => '',
  99. 'options' => {
  100. 'key_1' => 'value_1',
  101. 'key_2' => 'value_2',
  102. 'key_3' => 'value_3',
  103. },
  104. 'relation' => '',
  105. 'nulloption' => true,
  106. 'multiple' => false,
  107. 'null' => true,
  108. 'translate' => true,
  109. 'maxlength' => 255
  110. }
  111. end
  112. end
  113. factory :object_manager_attribute_tree_select, parent: :object_manager_attribute do
  114. data_type { 'tree_select' }
  115. data_option do
  116. {
  117. 'options' => [
  118. {
  119. 'name' => 'Incident',
  120. 'value' => 'Incident',
  121. 'children' => [
  122. {
  123. 'name' => 'Hardware',
  124. 'value' => 'Incident::Hardware',
  125. 'children' => [
  126. {
  127. 'name' => 'Monitor',
  128. 'value' => 'Incident::Hardware::Monitor'
  129. },
  130. {
  131. 'name' => 'Mouse',
  132. 'value' => 'Incident::Hardware::Mouse'
  133. },
  134. {
  135. 'name' => 'Keyboard',
  136. 'value' => 'Incident::Hardware::Keyboard'
  137. }
  138. ]
  139. },
  140. {
  141. 'name' => 'Softwareproblem',
  142. 'value' => 'Incident::Softwareproblem',
  143. 'children' => [
  144. {
  145. 'name' => 'CRM',
  146. 'value' => 'Incident::Softwareproblem::CRM'
  147. },
  148. {
  149. 'name' => 'EDI',
  150. 'value' => 'Incident::Softwareproblem::EDI'
  151. },
  152. {
  153. 'name' => 'SAP',
  154. 'value' => 'Incident::Softwareproblem::SAP',
  155. 'children' => [
  156. {
  157. 'name' => 'Authentication',
  158. 'value' => 'Incident::Softwareproblem::SAP::Authentication'
  159. },
  160. {
  161. 'name' => 'Not reachable',
  162. 'value' => 'Incident::Softwareproblem::SAP::Not reachable'
  163. }
  164. ]
  165. },
  166. {
  167. 'name' => 'MS Office',
  168. 'value' => 'Incident::Softwareproblem::MS Office',
  169. 'children' => [
  170. {
  171. 'name' => 'Excel',
  172. 'value' => 'Incident::Softwareproblem::MS Office::Excel'
  173. },
  174. {
  175. 'name' => 'PowerPoint',
  176. 'value' => 'Incident::Softwareproblem::MS Office::PowerPoint'
  177. },
  178. {
  179. 'name' => 'Word',
  180. 'value' => 'Incident::Softwareproblem::MS Office::Word'
  181. },
  182. {
  183. 'name' => 'Outlook',
  184. 'value' => 'Incident::Softwareproblem::MS Office::Outlook'
  185. }
  186. ]
  187. }
  188. ]
  189. }
  190. ]
  191. },
  192. {
  193. 'name' => 'Service request',
  194. 'value' => 'Service request',
  195. 'children' => [
  196. {
  197. 'name' => 'New software requirement',
  198. 'value' => 'Service request::New software requirement'
  199. },
  200. {
  201. 'name' => 'New hardware',
  202. 'value' => 'Service request::New hardware'
  203. },
  204. {
  205. 'name' => 'Consulting',
  206. 'value' => 'Service request::Consulting'
  207. }
  208. ]
  209. },
  210. {
  211. 'name' => 'Change request',
  212. 'value' => 'Change request'
  213. }
  214. ],
  215. 'default' => '',
  216. 'null' => true,
  217. 'relation' => '',
  218. 'maxlength' => 255,
  219. 'nulloption' => true,
  220. }
  221. end
  222. end
  223. factory :required_screen, class: Hash do
  224. create_middle do
  225. {
  226. 'ticket.customer' => {
  227. shown: true,
  228. required: true,
  229. item_class: 'column'
  230. },
  231. 'ticket.agent' => {
  232. shown: true,
  233. required: true,
  234. item_class: 'column'
  235. },
  236. 'admin.organization' => {
  237. shown: true,
  238. required: true,
  239. },
  240. 'admin.group' => {
  241. shown: true,
  242. required: true,
  243. item_class: 'column'
  244. },
  245. }
  246. end
  247. edit do
  248. {
  249. 'ticket.customer' => {
  250. shown: true,
  251. required: true
  252. },
  253. 'ticket.agent' => {
  254. shown: true,
  255. required: true
  256. },
  257. 'admin.organization' => {
  258. shown: true,
  259. required: true,
  260. },
  261. 'admin.group' => {
  262. shown: true,
  263. required: true,
  264. item_class: 'column'
  265. },
  266. }
  267. end
  268. end
  269. end