zcatalyst-cli 1.13.2 → 1.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. package/docs/client-utils.toml +6 -1
  2. package/docs/commands/ds/import.toml +5 -0
  3. package/docs/fn-utils/lib/python.toml +4 -0
  4. package/docs/init/dependencies/python/ensure-python.toml +12 -0
  5. package/docs/init/dependencies/python/pip-install.toml +4 -0
  6. package/docs/serve/index.toml +5 -0
  7. package/lib/authentication/login.js +2 -1
  8. package/lib/cli_table/index.js +26 -2
  9. package/lib/cli_table/src/cell.js +359 -267
  10. package/lib/cli_table/src/layout-manager.js +231 -209
  11. package/lib/cli_table/src/table.js +76 -60
  12. package/lib/cli_table/src/utils.js +259 -224
  13. package/lib/client-utils.js +18 -4
  14. package/lib/command_needs/rc.js +57 -8
  15. package/lib/commands/config/delete.js +23 -0
  16. package/lib/commands/config/get.js +23 -0
  17. package/lib/commands/config/list.js +23 -0
  18. package/lib/commands/config/set.js +29 -0
  19. package/lib/commands/console/cache.js +31 -1
  20. package/lib/commands/console/queue.js +31 -1
  21. package/lib/commands/console/zcql.js +27 -1
  22. package/lib/commands/ds/export.js +2 -2
  23. package/lib/commands/ds/import.js +25 -5
  24. package/lib/commands/ds/status.js +2 -2
  25. package/lib/commands/iac/export.js +1 -1
  26. package/lib/commands/iac/import.js +1 -1
  27. package/lib/commands/iac/pack.js +16 -5
  28. package/lib/commands/iac/status.js +1 -1
  29. package/lib/commands/index.js +4 -0
  30. package/lib/commands/project/list.js +1 -1
  31. package/lib/commands/project/use.js +1 -1
  32. package/lib/deploy/features/client.js +2 -2
  33. package/lib/deploy/features/functions/index.js +13 -3
  34. package/lib/deploy/features/functions/languages/index.js +19 -2
  35. package/lib/endpoints/index.js +12 -5
  36. package/lib/endpoints/lib/env.js +5 -2
  37. package/lib/endpoints/lib/functions.js +30 -0
  38. package/lib/endpoints/lib/org.js +35 -0
  39. package/lib/endpoints/lib/project.js +7 -3
  40. package/lib/express_middlewares/unknownReqProxy.js +4 -1
  41. package/lib/fn-utils/index.js +2 -0
  42. package/lib/fn-utils/lib/common.js +68 -7
  43. package/lib/fn-utils/lib/integ.js +15 -11
  44. package/lib/fn-utils/lib/java.js +7 -3
  45. package/lib/fn-utils/lib/python.js +121 -0
  46. package/lib/fn-watcher.js +10 -2
  47. package/lib/index.js +2 -1
  48. package/lib/init/dependencies/python/ensure-python.js +151 -0
  49. package/lib/init/dependencies/python/pip-install.js +175 -0
  50. package/lib/init/features/functions/index.js +50 -29
  51. package/lib/init/features/functions/languages/index.js +3 -1
  52. package/lib/init/features/functions/languages/python.js +115 -0
  53. package/lib/init/features/index.js +2 -2
  54. package/lib/init/features/project.js +26 -6
  55. package/lib/init/util/project.js +2 -2
  56. package/lib/internal/api.js +2 -0
  57. package/lib/internal/command.js +1 -1
  58. package/lib/internal/rc.js +2 -0
  59. package/lib/port-resolver.js +4 -3
  60. package/lib/prompt/types/file-path.js +1 -1
  61. package/lib/pull/features/functions/index.js +35 -2
  62. package/lib/pull/features/functions/languages.js +8 -1
  63. package/lib/readLineUtils.js +37 -1
  64. package/lib/readline/features/cache.js +175 -1
  65. package/lib/readline/features/index.js +7 -1
  66. package/lib/readline/features/queue.js +209 -1
  67. package/lib/readline/features/zcql.js +237 -1
  68. package/lib/readline/index.js +30 -1
  69. package/lib/serve/index.js +48 -7
  70. package/lib/serve/server/index.js +118 -44
  71. package/lib/serve/server/lib/java/lib/catalyst-cli-java-runtime-1.0.0.jar +0 -0
  72. package/lib/serve/server/lib/java/lib/catalyst-function-sdk-1.0.0.jar +0 -0
  73. package/lib/serve/server/lib/java/lib/catalyst-java-runtime-1.0.0.jar +0 -0
  74. package/lib/serve/server/lib/master.js +18 -5
  75. package/lib/serve/server/lib/node.mjs +41 -0
  76. package/lib/serve/server/lib/web_client/index.js +7 -3
  77. package/lib/serve/server/lib/web_client/server.js +31 -15
  78. package/lib/shell/dependencies/http-functions.js +57 -21
  79. package/lib/shell/dependencies/invoker/bio/java/JavabioInvoker.java +1 -2
  80. package/lib/shell/dependencies/invoker/bio/node.mjs +127 -0
  81. package/lib/shell/dependencies/invoker/cron/java/JavacronInvoker.java +1 -1
  82. package/lib/shell/dependencies/invoker/cron/node.mjs +87 -0
  83. package/lib/shell/dependencies/invoker/event/java/JavaeventInvoker.java +3 -3
  84. package/lib/shell/dependencies/invoker/event/node.mjs +84 -0
  85. package/lib/shell/dependencies/invoker/integ/java/JavaintegInvoker.java +1 -1
  86. package/lib/shell/dependencies/invoker/integ/node.mjs +88 -0
  87. package/lib/shell/dependencies/local-function.js +74 -22
  88. package/lib/shell/index.js +11 -2
  89. package/lib/shell/prepare/index.js +21 -0
  90. package/lib/shell/prepare/languages/index.js +8 -2
  91. package/lib/shell/prepare/languages/java.js +39 -2
  92. package/lib/shell/prepare/languages/node.js +21 -2
  93. package/lib/shell/prepare/languages/python.js +65 -0
  94. package/lib/throbber/index.js +3 -1
  95. package/lib/userConfig.js +48 -0
  96. package/lib/util_modules/constants/index.js +3 -1
  97. package/lib/util_modules/constants/lib/apig-rules.js +8 -0
  98. package/lib/util_modules/constants/lib/cliq-handlers.js +17 -1
  99. package/lib/util_modules/constants/lib/dc-type.js +8 -0
  100. package/lib/util_modules/constants/lib/default.js +2 -2
  101. package/lib/util_modules/constants/lib/env-path.js +12 -0
  102. package/lib/util_modules/constants/lib/file-names.js +4 -1
  103. package/lib/util_modules/constants/lib/folder-names.js +3 -1
  104. package/lib/util_modules/constants/lib/placeholders.js +6 -1
  105. package/lib/util_modules/constants/lib/runtime.js +2 -1
  106. package/lib/util_modules/constants/lib/scopes.js +1 -0
  107. package/lib/util_modules/constants/lib/template.js +9 -0
  108. package/lib/util_modules/constants/lib/urls.js +2 -6
  109. package/lib/util_modules/context-help.js +2 -0
  110. package/lib/util_modules/fs/lib/async.js +35 -11
  111. package/lib/util_modules/project.js +20 -1
  112. package/package.json +2 -1
  113. package/templates/init/functions/java/aio/catalyst-config.json +3 -2
  114. package/templates/init/functions/java/bio/catalyst-config.json +3 -2
  115. package/templates/init/functions/java/cron/catalyst-config.json +3 -2
  116. package/templates/init/functions/java/event/catalyst-config.json +3 -2
  117. package/templates/init/functions/java/integ/cliq/catalyst-config.json +1 -0
  118. package/templates/init/functions/node/aio/catalyst-config.json +3 -2
  119. package/templates/init/functions/node/bio/catalyst-config.json +3 -2
  120. package/templates/init/functions/node/cron/catalyst-config.json +3 -2
  121. package/templates/init/functions/node/event/catalyst-config.json +3 -2
  122. package/templates/init/functions/node/integ/cliq/catalyst-config.json +1 -0
  123. package/templates/init/functions/node/integ/cliq/handlers/bot-handler.js +2 -2
  124. package/templates/init/functions/node/integ/cliq/handlers/command-handler.js +1 -2
  125. package/templates/init/functions/node/integ/cliq/handlers/function-handler.js +1 -1
  126. package/templates/init/functions/node/integ/cliq/handlers/installation-handler.js +1 -1
  127. package/templates/init/functions/node/integ/cliq/handlers/installation-validator.js +1 -1
  128. package/templates/init/functions/node/integ/cliq/handlers/message-action-handler.js +1 -1
  129. package/templates/init/functions/node/integ/cliq/handlers/widget-handler.js +1 -1
  130. package/templates/init/functions/node/integ/cliq/sample.js +4 -4
  131. package/templates/init/functions/python/aio/catalyst-config.json +11 -0
  132. package/templates/init/functions/python/aio/requirements.txt +1 -0
  133. package/templates/init/functions/python/aio/sample.py +26 -0
  134. package/templates/init/functions/python/bio/catalyst-config.json +11 -0
  135. package/templates/init/functions/python/bio/requirements.txt +1 -0
  136. package/templates/init/functions/python/bio/sample.py +6 -0
  137. package/templates/init/functions/python/cron/catalyst-config.json +11 -0
  138. package/templates/init/functions/python/cron/requirements.txt +1 -0
  139. package/templates/init/functions/python/cron/sample.py +18 -0
  140. package/templates/init/functions/python/event/catalyst-config.json +11 -0
  141. package/templates/init/functions/python/event/requirements.txt +1 -0
  142. package/templates/init/functions/python/event/sample.py +21 -0
  143. package/templates/init/functions/python/integ/cliq/catalyst-config.json +11 -0
  144. package/templates/init/functions/python/integ/cliq/handlers/bot_handler.py +174 -0
  145. package/templates/init/functions/python/integ/cliq/handlers/command_handler.py +102 -0
  146. package/templates/init/functions/python/integ/cliq/handlers/function_handler.py +409 -0
  147. package/templates/init/functions/python/integ/cliq/handlers/installation_handler.py +12 -0
  148. package/templates/init/functions/python/integ/cliq/handlers/installation_validator.py +16 -0
  149. package/templates/init/functions/python/integ/cliq/handlers/message_action_handler.py +18 -0
  150. package/templates/init/functions/python/integ/cliq/handlers/widget_handler.py +269 -0
  151. package/templates/init/functions/python/integ/cliq/requirements.txt +1 -0
  152. package/templates/init/functions/python/integ/cliq/sample.py +21 -0
  153. package/lib/serve/server/lib/node.js +0 -62
  154. package/lib/shell/dependencies/invoker/bio/node.js +0 -80
  155. package/lib/shell/dependencies/invoker/cron/node.js +0 -54
  156. package/lib/shell/dependencies/invoker/event/node.js +0 -56
  157. package/lib/shell/dependencies/invoker/integ/node.js +0 -79
  158. package/templates/.DS_Store +0 -0
  159. package/templates/init/.DS_Store +0 -0
  160. package/templates/init/client/.DS_Store +0 -0
  161. package/templates/init/client/react/.DS_Store +0 -0
  162. package/templates/init/functions/node/integ/cliq/.DS_Store +0 -0
@@ -0,0 +1,174 @@
1
+ import json
2
+ from zcatalyst_cliq.bot_handler import (
3
+ welcome_handler,
4
+ message_handler,
5
+ context_handler,
6
+ mention_handler,
7
+ menu_action_handler,
8
+ webhook_handler,
9
+ participation_handler,
10
+ BotWelcomeHandlerRequest,
11
+ BotMessageHandlerRequest,
12
+ BotContextHandlerRequest,
13
+ BotMentionHandlerRequest,
14
+ BotMenuActionHandlerRequest,
15
+ BotParticipationHandlerRequest,
16
+ BotWebHookHandlerRequest,
17
+ HandlerResponse
18
+ )
19
+ from zcatalyst.catalyst_app import CatalystApp
20
+ import logging
21
+
22
+ @welcome_handler
23
+ def welcome_handler_fn(req: BotWelcomeHandlerRequest, res: HandlerResponse, *args):
24
+ res.text = f'hello {req.user.first_name}'
25
+ return res
26
+
27
+
28
+ @message_handler
29
+ def msg_handler(req: BotMessageHandlerRequest, res: HandlerResponse, *args):
30
+ try:
31
+ msg = req.message
32
+ text = ''
33
+ if not msg:
34
+ text = 'Please enable \'Message\' in bot settings'
35
+ elif msg == 'hi' or msg == 'hello':
36
+ text = f'Hi {req.user.first_name} :smile: . How are you doing ??'
37
+
38
+ suggestions = res.new_suggestion_list()
39
+
40
+ suggestions.add_suggestions(
41
+ suggestions.new_suggestion('Good'),
42
+ suggestions.new_suggestion('Not Bad'),
43
+ suggestions.new_suggestion('meh'),
44
+ suggestions.new_suggestion('Worst'),
45
+ )
46
+ res.suggestions = suggestions
47
+ elif msg == 'Good' or msg == 'Not Bad':
48
+ text = 'That\'s glad to hear :smile:'
49
+ elif msg == 'meh' or msg == 'Worst':
50
+ text = "Oops! Don't you worry. Your day is definitely going to get better. :grinning:"
51
+ elif msg == 'details':
52
+ text = 'welcome to details collection center :wink:'
53
+ context = res.new_context()
54
+ context.id = 'personal_details'
55
+ context.timeout = 300
56
+
57
+ param1 = context.new_param()
58
+ param1.name = 'name'
59
+ param1.question = 'Please enter your name: '
60
+
61
+ param2 = context.new_param()
62
+ param2.name = 'dept'
63
+ param2.question = 'Please enter your department: '
64
+ param2.add_suggestion('CSE')
65
+ param2.add_suggestion('IT')
66
+ param2.add_suggestion('MECH')
67
+
68
+ param3 = context.new_param()
69
+ param3.name = 'cache'
70
+ param3.question = "Do you wish to put this detail in Catalyst Cache ?"
71
+ param3.add_suggestion('YES')
72
+ param3.add_suggestion('NO')
73
+
74
+ context.add_params(param1, param2, param3)
75
+ res.context = context
76
+ else:
77
+ text = "Oops! Sorry, I'm not programmed yet to do this :sad:"
78
+ res.set_text(text)
79
+ return res
80
+ except Exception as e:
81
+ logging.error(e)
82
+ return
83
+
84
+ @context_handler
85
+ def ctx_handler(req: BotContextHandlerRequest, res: HandlerResponse, *args):
86
+ app: CatalystApp = args[0]
87
+ if req.context_id == 'personal_details':
88
+ answer = req.answers
89
+ name = answer.name.text
90
+ dept = answer.dept.text
91
+
92
+ text = f'Nice! I have collected your info: \n*Name*: {name} \n*Department*: {dept}'
93
+
94
+ if answer.cache.text == 'YES':
95
+ try:
96
+ default_segment = app.cache().segment()
97
+ default_segment.put('Name', name)
98
+ default_segment.put('Department', dept)
99
+ text += '\nThis data is now available in Catalyst Cache\'s default segment.'
100
+ except Exception as e:
101
+ logging.error(e)
102
+ res.set_text(text)
103
+ return res
104
+
105
+
106
+ @mention_handler
107
+ def mention_handler(req: BotMentionHandlerRequest, res: HandlerResponse, *args):
108
+ text = f"Hey *{req.user.first_name}*, thanks for mentioning me here. I'm from Catalyst city"
109
+ res.set_text(text);
110
+ return res
111
+
112
+
113
+ @menu_action_handler
114
+ def action(req: BotMenuActionHandlerRequest, res: HandlerResponse, *args):
115
+ text = '';
116
+ if req.action_name == 'Say Hi':
117
+ text = 'Hi'
118
+ elif req.action_name == 'Look Angry':
119
+ text = ':angry:'
120
+ else:
121
+ text = 'Menu action triggered :fist:'
122
+
123
+ res.set_text(text)
124
+ return res
125
+
126
+
127
+ @participation_handler
128
+ def participation(req: BotParticipationHandlerRequest, res: HandlerResponse, *args):
129
+ text = '';
130
+ if req.operation == 'added':
131
+ text = 'Hi. Thanks for adding me to the channel :smile:'
132
+ elif req.operation == 'removed':
133
+ text = 'Bye-Bye :bye-bye:'
134
+ else:
135
+ text = 'I\'m too a participant of this chat :wink:'
136
+
137
+ res.set_text(text)
138
+ return res
139
+
140
+ @webhook_handler
141
+ def webhook_fn(req: BotWebHookHandlerRequest, res: HandlerResponse, *args):
142
+ req_body: dict = json.loads(req.body)
143
+ post_json_msg = req_body.get('message')
144
+
145
+ res.bot = res.new_bot_details('PostPerson', 'https://www.zoho.com/sites/default/files/catalyst/functions-images/icon-robot.jpg')
146
+
147
+ card = res.new_card()
148
+ card.title = 'New Mail'
149
+ card.thumbnail = 'https://www.zoho.com/sites/default/files/catalyst/functions-images/mail.svg'
150
+ res.card = card
151
+
152
+ button = res.new_button()
153
+ button.label = 'open mail'
154
+ button.type = '+'
155
+ button.hint = 'Click to open the mail in a new tab'
156
+
157
+ action = button.new_action_object()
158
+ action.type = 'open.url'
159
+
160
+ action_data = action.new_action_data_obj()
161
+ action_data.web = 'https://mail.zoho.com/zm/#mail/folder/inbox/p/${reqBody.messageId}'
162
+
163
+ action.data = action_data
164
+ button.action= action
165
+
166
+ res.add_button(button)
167
+
168
+ gif_slide = res.new_slide()
169
+ gif_slide.type = 'images'
170
+ gif_slide.title = ''
171
+ gif_slide.data = ['https://media.giphy.com/media/efyEShk2FJ9X2Kpd7V/giphy.gif']
172
+ res.add_slides(gif_slide)
173
+
174
+ return res
@@ -0,0 +1,102 @@
1
+ from typing import List
2
+ import zcatalyst_cliq.command_handler as command
3
+ from zcatalyst_cliq.command_handler import (
4
+ execution_handler,
5
+ suggestion_handler,
6
+ CommandHandlerRequest,
7
+ CommandSuggestion,
8
+ HandlerResponse
9
+ )
10
+
11
+ @execution_handler
12
+ def executor(req: CommandHandlerRequest, res: HandlerResponse, *args):
13
+ text = ''
14
+ cmd = req.name
15
+ if cmd == 'catalyst':
16
+ suggestions = req.selections
17
+ if not suggestions:
18
+ text = 'Please select a suggestion from the command'
19
+ else:
20
+ prefix = 'Take a look at our ';
21
+ if suggestions[0].title == 'API doc':
22
+ text = prefix + '[API Documentation](https://www.zoho.com/catalyst/help/api/introduction/overview.html)'
23
+ elif suggestions[0].title == 'CLI doc':
24
+ text = prefix + '[CLI Documentation](https://www.zoho.com/catalyst/help/cli-command-reference.html)'
25
+ else:
26
+ text = prefix + '[help documentation](https://www.zoho.com/catalyst/help/)'
27
+ elif cmd == 'raisereq':
28
+ return get_form()
29
+ else:
30
+ text = 'Command executed successfully!'
31
+ res.text = text
32
+ return res
33
+
34
+
35
+ @suggestion_handler
36
+ def suggester(req: CommandHandlerRequest, res: List[CommandSuggestion], *args):
37
+ if req.name == 'catalyst':
38
+ suggestion1 = command.new_command_suggestion()
39
+ suggestion1.title = 'API doc'
40
+ suggestion1.description = 'Catalyst API documentation'
41
+ suggestion1.imageurl = 'https://www.zohowebstatic.com/sites/default/files/styles/product-home-page/public/catalyst-icon.png'
42
+
43
+ suggestion2 = command.new_command_suggestion()
44
+ suggestion2.title = 'CLI doc'
45
+ suggestion2.description = 'Catalyst CLI documentation'
46
+ suggestion2.imageurl = 'https://www.zohowebstatic.com/sites/default/files/styles/product-home-page/public/catalyst-icon.png'
47
+
48
+ suggestion3 = command.new_command_suggestion()
49
+ suggestion3.title = 'Help docs'
50
+ suggestion3.description = 'Catalyst help documentation'
51
+ suggestion3.imageurl = 'https://www.zohowebstatic.com/sites/default/files/styles/product-home-page/public/catalyst-icon.png'
52
+
53
+ res.extend([suggestion1,suggestion2,suggestion3])
54
+ return res
55
+
56
+
57
+ def get_form():
58
+ form = command.new_handler_response().new_form()
59
+ form.title = 'Asset Request'
60
+ form.hint = 'Raise your asset request'
61
+ form.name = 'ID'
62
+ form.button_label = 'Raise Request'
63
+ form.version = 1
64
+
65
+ actions = form.new_form_actions_obj()
66
+ actions.submit = actions.new_form_action('PyFnForm'); # ENTER YOUR FORM FUNCTION NAME HERE
67
+
68
+ form.actions = actions
69
+
70
+ user_name = form.new_form_input()
71
+ user_name.type = 'text'
72
+ user_name.name = 'username'
73
+ user_name.label = 'Name'
74
+ user_name.hint = 'Please enter your name'
75
+ user_name.placeholder = 'John Reese'
76
+ user_name.mandatory = True
77
+ user_name.value = 'Harold Finch'
78
+ form.add_inputs(user_name)
79
+
80
+ email = form.new_form_input()
81
+ email.type = 'text'
82
+ email.format = 'email'
83
+ email.name = 'email'
84
+ email.label = 'Email'
85
+ email.hint = 'Enter your email address'
86
+ email.placeholder = "johnreese@poi.com"
87
+ email.mandatory = True
88
+ email.value = "haroldfinch@samaritan.com"
89
+
90
+ asset_type = form.new_form_input()
91
+ asset_type.type = 'select'
92
+ asset_type.trigger_on_change = True
93
+ asset_type.name = 'asset_type'
94
+ asset_type.label = "Asset Type"
95
+ asset_type.hint = "Choose your request asset type"
96
+ asset_type.placeholder = "Mobile"
97
+ asset_type.mandatory = True
98
+ asset_type.add_options(asset_type.new_form_value('Laptop', 'laptop'))
99
+ asset_type.add_options(asset_type.new_form_value('Mobile', 'mobile'))
100
+
101
+ form.add_inputs(email, asset_type)
102
+ return form
@@ -0,0 +1,409 @@
1
+ from datetime import datetime
2
+ from zcatalyst_cliq import function_handler
3
+ from zcatalyst_cliq.function_handler import (
4
+ button_function_handler,
5
+ form_submit_handler,
6
+ form_change_handler,
7
+ form_dynamic_field_handler,
8
+ widget_button_handler,
9
+ ButtonFunctionRequest,
10
+ FormFunctionRequest,
11
+ WidgetFunctionRequest,
12
+ HandlerResponse,
13
+ FormChangeResponse,
14
+ FormDynamicFieldResponse,
15
+ WidgetResponse
16
+ )
17
+
18
+
19
+ @button_function_handler
20
+ def button_fn_handler(req: ButtonFunctionRequest, res: HandlerResponse, *args):
21
+ res.text = 'Button function executed'
22
+ return res
23
+
24
+
25
+
26
+ @form_submit_handler
27
+ def form_submit(req: FormFunctionRequest, res: HandlerResponse, *args):
28
+ values = req.form.values
29
+ type = None
30
+ if hasattr(values,'type'):
31
+ type = values.type
32
+ if type:
33
+ if type == 'formTab':
34
+ widget_response = function_handler.new_widget_response()
35
+ widget_response.type = 'applet'
36
+
37
+ title_section = widget_response.new_widget_section()
38
+ title_section.id = '100'
39
+
40
+ edited_by = title_section.new_widget_element()
41
+ edited_by.type = 'title'
42
+ edited_by.text = 'Edited by ' + values.text + ' :wink:'
43
+
44
+ time = title_section.new_widget_element()
45
+ time.type = 'subtext'
46
+ time.text = 'Target:buttons\nTime : ' + str(datetime.now())
47
+
48
+ title_section.add_elements(edited_by, time)
49
+ widget_response.add_sections(title_section, get_button_section())
50
+ return widget_response
51
+ elif type == 'formsection':
52
+ section = function_handler.new_widget_response().new_widget_section()
53
+ section.id = '102'
54
+ section.type = 'section'
55
+
56
+ edited_by = section.new_widget_element()
57
+ edited_by.type = 'title'
58
+ edited_by.text = 'Edited by ' + values.text + ' :wink:'
59
+
60
+ section.add_elements(edited_by)
61
+
62
+ return section
63
+ else:
64
+ msg = function_handler.new_handler_response().new_message()
65
+ msg.text = 'Applet Button executed successfully'
66
+ msg.type = 'banner'
67
+ msg.status = 'success'
68
+ return msg
69
+
70
+ text = f"Hi {values.username}, thanks for raising your request. Your request will be processed based on the device availability."
71
+ res.set_text(text)
72
+
73
+ card = res.new_card()
74
+ card.title = 'Asset Request'
75
+ res.card = card
76
+
77
+ slide = res.new_slide()
78
+ slide.type = 'label'
79
+ slide.title = ''
80
+
81
+ data_list = []
82
+ obj1 = {
83
+ 'Asset type': values.asset_type.label
84
+ }
85
+ data_list.append(obj1)
86
+ if values.asset_type.value == 'mobile':
87
+ obj2= {
88
+ 'Preferred OS': values.mobile_os.label
89
+ }
90
+ data_list.append(obj2)
91
+ obj3 = {
92
+ 'Preferred Devices': values.mobile_list.label
93
+ }
94
+ data_list.append(obj3)
95
+ else:
96
+ obj2 = {
97
+ 'Device Preferred': values.os_type.label
98
+ }
99
+ data_list.append(obj2)
100
+ slide.data = data_list
101
+ res.add_slides(slide)
102
+ return res
103
+
104
+
105
+ @form_change_handler
106
+ def change_form(req: FormFunctionRequest, res: FormChangeResponse, *args):
107
+ target = req.target.name
108
+ values = req.form.values
109
+ field_value = values.asset_type.value
110
+
111
+ if target == 'asset_type':
112
+ if field_value == 'laptop':
113
+ select_box_action = res.new_form_modification_action()
114
+ select_box_action.type = 'add_after'
115
+ select_box_action.name = 'asset_type'
116
+
117
+ os = select_box_action.new_form_input()
118
+ os.trigger_on_change = True
119
+ os.type = 'select'
120
+ os.name = 'os_type'
121
+ os.label = 'Laptop Type'
122
+ os.hint = 'Choose your preferred OS type'
123
+ os.placeholder = 'Ubuntu'
124
+ os.mandatory = True
125
+
126
+ mac = os.new_form_value()
127
+ mac.label = 'Mac OS X'
128
+ mac.value = 'mac'
129
+
130
+ windows = os.new_form_value()
131
+ windows.label = 'Windows'
132
+ windows.value = 'windows'
133
+
134
+ ubuntu = os.new_form_value()
135
+ ubuntu.label = 'Ubuntu'
136
+ ubuntu.value = 'ubuntu'
137
+
138
+ os.add_options(mac, windows, ubuntu)
139
+ select_box_action.input = os
140
+
141
+ remove_mobile_OSAction = res.new_form_modification_action()
142
+ remove_mobile_OSAction.type = 'remove'
143
+ remove_mobile_OSAction.name = 'mobile_os'
144
+
145
+ remove_mobile_list_action = res.new_form_modification_action()
146
+ remove_mobile_list_action.type = 'remove'
147
+ remove_mobile_list_action.name = 'mobile_list'
148
+
149
+ res.add_actions(select_box_action, remove_mobile_OSAction, remove_mobile_list_action)
150
+
151
+ elif field_value == 'mobile':
152
+ select_box_action = res.new_form_modification_action()
153
+ select_box_action.type = 'add_after'
154
+ select_box_action.name = 'asset_type'
155
+
156
+ os = select_box_action.new_form_input()
157
+ os.trigger_on_change = True
158
+ os.type = 'select'
159
+ os.name = 'mobile_os'
160
+ os.label = 'Mobile OS'
161
+ os.hint = 'Choose your preferred mobile OS'
162
+ os.placeholder = 'Android'
163
+ os.mandatory = True
164
+
165
+ android = os.new_form_value()
166
+ android.label = 'Android'
167
+ android.value = 'android'
168
+
169
+ ios = os.new_form_value()
170
+ ios.label = 'iOS'
171
+ ios.value = 'ios'
172
+
173
+ os.add_options(android, ios)
174
+ select_box_action.input = os
175
+
176
+ remove_os_type_action = res.new_form_modification_action()
177
+ remove_os_type_action.type = 'remove'
178
+ remove_os_type_action.name = 'os_type'
179
+
180
+ res.add_actions(select_box_action, remove_os_type_action)
181
+
182
+ elif target == 'mobile_os':
183
+ if field_value:
184
+ mobile_list_action = res.new_form_modification_action()
185
+ mobile_list_action.type = 'add_after'
186
+ mobile_list_action.name = 'mobile_os'
187
+
188
+ list_input = mobile_list_action.new_form_input()
189
+ list_input.type = 'dynamic_select'
190
+ list_input.name = 'mobile_list'
191
+ list_input.label = 'Mobile Device'
192
+ list_input.placeholder = 'Choose your preferred mobile device'
193
+ list_input.mandatory = True
194
+ mobile_list_action.input = list_input
195
+
196
+ res.add_actions(mobile_list_action)
197
+ else:
198
+ remove_mobile_list_action = res.new_form_modification_action()
199
+ remove_mobile_list_action.type = 'remove';
200
+ remove_mobile_list_action.name = 'mobile_list'
201
+
202
+ res.add_actions(remove_mobile_list_action)
203
+
204
+ return res
205
+
206
+
207
+ @form_dynamic_field_handler
208
+ def handle_dynamic_field(req: FormFunctionRequest, res: FormDynamicFieldResponse, *args):
209
+ target = req.target
210
+ values = req.form.values
211
+
212
+ if target.name == 'mobile_list' and values.mobile_os:
213
+ device = values.mobile_os.value
214
+ if device == 'android':
215
+ mobile_list = ['One Plus 6T', 'One Plus 6', 'Google Pixel 3', 'Google Pixel 4']
216
+ for mobile in mobile_list:
217
+ res.add_options(res.new_form_value(mobile,mobile.lower().replace(' ','_')))
218
+ elif device == 'ios':
219
+ mobile_list = ['IPhone XR', 'IPhone XS', 'IPhone X', 'IPhone 13']
220
+ for mobile in mobile_list:
221
+ res.add_options(res.new_form_value(mobile,mobile.lower().replace(' ','_')))
222
+ return res
223
+
224
+
225
+ @widget_button_handler
226
+ def widget_button(req: WidgetFunctionRequest, res: WidgetResponse, *args):
227
+
228
+ id = req.target.id
229
+ if id == 'tab':
230
+ res.type = 'applet'
231
+
232
+ title_section = res.new_widget_section()
233
+ title_section.id = '100'
234
+
235
+ time = title_section.new_widget_element()
236
+ time.type = 'subtext'
237
+ time.text = 'Target:buttons\nTime : ' + str(datetime.now())
238
+
239
+ title_section.add_elements(time)
240
+ res.add_sections(title_section, get_button_section())
241
+
242
+ return res
243
+
244
+ elif id == 'section':
245
+ section = res.new_widget_section()
246
+ section.id = '102'
247
+ section.type = 'section'
248
+ element = section.new_widget_element()
249
+ element.type = 'title'
250
+ element.text = 'Edited :wink: '
251
+
252
+ section.add_elements(element)
253
+ return section
254
+
255
+ elif id == 'formTab' or id == 'formsection':
256
+ form = function_handler.new_handler_response().new_form()
257
+ form.title = 'Zylker Annual Marathon'
258
+ form.name = 'a'
259
+ form.hint = 'Register yourself for the Zylker Annual Marathon'
260
+ form.button_label = 'Submit'
261
+
262
+ input1 = form.new_form_input()
263
+ input1.type = 'text'
264
+ input1.name = 'text'
265
+ input1.label = 'Name'
266
+ input1.placeholder = 'Scott Fischer'
267
+ input1.min_length = '0'
268
+ input1.max_length = '25'
269
+ input1.mandatory = True
270
+
271
+ input2 = form.new_form_input()
272
+ input2.type = 'hidden'
273
+ input2.name = 'type'
274
+ input2.value = id
275
+
276
+ form.add_inputs(input1, input2)
277
+ form.action = form.new_form_action('PyFnForm'); # ** ENTER YOUR FORM FUNCTION NAME HERE **
278
+ return form
279
+
280
+ elif id == 'breadcrumbs':
281
+ page = str(int(req.target.label.split("Page : ")[1].rstrip()) + 1)
282
+
283
+
284
+ section = res.new_widget_section()
285
+ section.id = '12345'
286
+
287
+ elem = section.new_widget_element()
288
+ elem.type = 'subtext';
289
+ elem.text = 'Page : ' + page
290
+ section.add_elements(elem)
291
+ res.add_sections(section)
292
+
293
+ first_nav = {
294
+ 'label': 'Page : ' + page,
295
+ 'type': 'invoke.function',
296
+ 'name': 'PyFnWidgetButton',
297
+ 'id': 'breadcrumbs'
298
+ }
299
+
300
+ link_button = {
301
+ 'label': 'Link',
302
+ 'type': 'open.url',
303
+ 'url': 'https://www.zoho.com'
304
+ }
305
+
306
+ banner_button = {
307
+ 'label': 'Banner',
308
+ 'type': 'invoke.function',
309
+ 'name': 'PyFnWidgetButton',
310
+ 'id': 'banner'
311
+ }
312
+
313
+ res.header = {
314
+ 'title' : 'Header ' + page,
315
+ 'navigation' : 'continue',
316
+ 'buttons' : [first_nav, link_button, banner_button]
317
+ }
318
+
319
+ res.footer = {
320
+ 'text' : 'Footer text',
321
+ 'buttons' : [link_button, banner_button]
322
+ }
323
+
324
+ res.type = 'applet'
325
+ return res
326
+ else:
327
+ msg = function_handler.new_handler_response().new_message()
328
+ msg.text = 'Applet Button executed successfully'
329
+ msg.type = 'banner'
330
+ msg.status = 'success'
331
+ return msg
332
+
333
+
334
+
335
+ def get_button_section():
336
+ widget_response = function_handler.new_widget_response()
337
+
338
+ button_section = widget_response.new_widget_section()
339
+
340
+ title = button_section.new_widget_element()
341
+ title.type = 'title'
342
+ title.text = 'Buttons'
343
+
344
+ button_element1 = button_section.new_widget_element()
345
+ button_element1.type = 'buttons'
346
+
347
+ button1 = button_element1.new_widget_button()
348
+ button1.label = 'link'
349
+ button1.type = 'open.url'
350
+ button1.url = 'https://www.zoho.com'
351
+
352
+ button2 = button_element1.new_widget_button()
353
+ button2.label = 'Banner'
354
+ button2.type = 'invoke.function'
355
+ button2.name = 'PyFnWidgetButton'
356
+ button2.id = 'banner'
357
+
358
+ button3 = button_element1.new_widget_button()
359
+ button3.label = 'Open Channel'
360
+ button3.type = 'system.api'
361
+ button3.set_api('joinchannel/{{id}}', 'CT_1407724818712687474_72317143'); # ** ENTER YOUR CHANNEL ID HERE **
362
+
363
+ button4 = button_element1.new_widget_button()
364
+ button4.label = 'Preview'
365
+ button4.type = 'preview.url'
366
+ button4.url = 'https://www.zoho.com/catalyst/features.html'
367
+
368
+ button_element1.add_widget_buttons(button1,button2,button3)
369
+
370
+ #Buttons - Row2
371
+ button_element2 = button_section.new_widget_element()
372
+ button_element2.type = 'buttons'
373
+
374
+ button5 = button_element2.new_widget_button()
375
+ button5.label = 'Edit Section'
376
+ button5.type = 'invoke.function'
377
+ button5.name = 'PyFnWidgetButton'
378
+ button5.id = 'section'
379
+
380
+ button6 = button_element2.new_widget_button()
381
+ button6.label = 'Form Edit Section'
382
+ button6.type = 'invoke.function'
383
+ button6.name = 'PyFnWidgetButton'
384
+ button6.id = 'formsection'
385
+
386
+ button7 = button_element2.new_widget_button()
387
+ button7.label = 'Banner'
388
+ button7.type = 'invoke.function'
389
+ button7.name = 'PyFnWidgetButton'
390
+ button7.id = 'banner'
391
+
392
+ button8 = button_element2.new_widget_button()
393
+ button8.label = 'Edit Whole Tab'
394
+ button8.type = 'invoke.function'
395
+ button8.name = 'PyFnWidgetButton'
396
+ button8.id = 'tab'
397
+
398
+ button9 = button_element2.new_widget_button()
399
+ button9.label = 'Form Edit Tab'
400
+ button9.type = 'invoke.function'
401
+ button9.name = 'PyFnWidgetButton'
402
+ button9.id = 'formTab'
403
+
404
+ button_element2.add_widget_buttons(button5, button6, button7, button8, button9)
405
+
406
+ button_section.add_elements(title, button_element1, button_element2);
407
+ button_section.id = '101'
408
+
409
+ return button_section
@@ -0,0 +1,12 @@
1
+ from zcatalyst_cliq.installation_handler import (
2
+ handle_installation,
3
+ InstallationRequest,
4
+ InstallationResponse
5
+ )
6
+
7
+
8
+ @handle_installation
9
+ def installation_handler(req: InstallationRequest, res: InstallationResponse, *args):
10
+ '''Logic for installation post handling'''
11
+ res.status = 200
12
+ return res