zulip/web/templates/settings/edit_bot_form.hbs

52 lines
2.8 KiB
Handlebars
Raw Normal View History

<div id="bot-edit-form" data-user-id="{{user_id}}" data-email="{{email}}">
<form class="new-style edit_bot_form name-setting">
<div class="input-group name_change_container">
<label for="edit_bot_full_name">{{t "Full name" }}</label>
<input type="text" autocomplete="off" name="full_name" id="edit_bot_full_name" value="{{ full_name }}" />
</div>
<input type="hidden" name="is_full_name" value="true" />
<div class="input-group email_change_container">
<label for="email">{{t "Email" }}</label>
<input type="text" autocomplete="off" name="email" value="{{ email }}" readonly/>
</div>
<div class="input-group user_id_container">
<label for="user_id">{{t "User ID" }}</label>
<input type="text" autocomplete="off" name="user_id" value="{{ user_id }}" readonly/>
</div>
<div class="input-group">
<label class="input-label" for="bot-role-select">{{t 'Role' }}
{{> ../help_link_widget link="/help/roles-and-permissions" }}
</label>
<select name="bot-role-select" id="bot-role-select" class="modal_select bootstrap-focus-style" data-setting-widget-type="number" {{#if disable_role_dropdown}}disabled{{/if}}>
{{> dropdown_options_widget option_values=user_role_values}}
</select>
</div>
<div class="input-group edit_bot_owner_container">
<label for="bot_owner_select">{{t "Owner" }}</label>
{{> dropdown_list_widget
widget_name="edit_bot_owner"
list_placeholder=(t 'Filter users')}}
user settings: Separate code for bot form. When editing a bot, there are only two fields that are similar to humans--full name and email--which are trivial. Before this commit we used a single codepath to build the human form and the bot form. Now we have two simple codepaths. The tricky nature of the code had already led to ugly things for the bot codepath that fortunately weren't user facing, but which were distracting: - For bots we would needlessly set things like is_admin, is_guest in the template data. - For bots we would needlessly try to update custom profile fields. The code that differs between bots and humans is nontrivial, and the code was both hard to read and hard to improve: - Humans don't have bot owners. - Bots don't have custom profile fields. The bot-owner code is nontrivial for performance reasons. In a big realm there are tens of thousands of potential bot owners. We avoid the most egregious performance problems (i.e we don't have multiple copies of the dropdown), but we may still want to refine that (at least adding a spinner). The custom-profile-fields code is nontrivial due to the dynamic nature of custom profile fields, which can bring in specialized widgets like pill fields. Now each form corresponds to a single endpoint: * human -> /json/users * bot -> /json/bots Before we had a lot of conditional logic in the template, the code to build to views, and the code to submit the data. Now everything is much flatter. The human code is still a bit messy (more work coming on that), but the bot code is fairly pristine. All three components of the bot code fit on a page, and there are no conditionals: - admin_bot_form.hbs - open_bot_form - handle_bot_form We may want to grow out the bot code a bit to allow admins to do more things, such as adding services, and this will be easier now. It would also be easier for us now to share widgets with the per-user bot settings. Note that the form for editing human data will continue to be invoked from two panels: - Users - Deactivated users There are some minor differences between users and deactivated users, but the shape of the data is the same for both, so that's still all one codepath. We eliminate `reset_edit_user` here, since it was never used. One nice thing about these forms was that they had very little custom CSS attached to them (at form-level specificity), and it turned out all the custom CSS was for the human-specific form.
2020-05-09 12:13:03 +02:00
</div>
<div id="service_data">
</div>
<div class="input-group edit-avatar-section">
<label>Avatar</label>
{{!-- Shows the current avatar --}}
<img src="{{bot_avatar_url}}" id="current_bot_avatar_image" />
<input type="file" name="bot_avatar_file_input" class="notvisible edit_bot_avatar_file_input" value="{{t 'Upload profile picture' }}" />
<div class="edit_bot_avatar_file"></div>
<div class="edit_bot_avatar_preview_text">
<img class="edit_bot_avatar_preview_image" />
</div>
<button type="button" class="button white rounded edit_bot_avatar_upload_button">{{t "Change avatar" }}</button>
<button type="button" class="button white rounded edit_bot_avatar_clear_button" style="display: none;">{{t "Clear profile picture" }}</button>
<div><label for="edit_bot_avatar_file" generated="true" class="edit_bot_avatar_error text-error"></label></div>
</div>
</form>
<div class="input-group new-style">
<button class="button rounded btn-danger deactivate_bot_button">
{{t 'Deactivate bot' }}
</button>
</div>
user settings: Separate code for bot form. When editing a bot, there are only two fields that are similar to humans--full name and email--which are trivial. Before this commit we used a single codepath to build the human form and the bot form. Now we have two simple codepaths. The tricky nature of the code had already led to ugly things for the bot codepath that fortunately weren't user facing, but which were distracting: - For bots we would needlessly set things like is_admin, is_guest in the template data. - For bots we would needlessly try to update custom profile fields. The code that differs between bots and humans is nontrivial, and the code was both hard to read and hard to improve: - Humans don't have bot owners. - Bots don't have custom profile fields. The bot-owner code is nontrivial for performance reasons. In a big realm there are tens of thousands of potential bot owners. We avoid the most egregious performance problems (i.e we don't have multiple copies of the dropdown), but we may still want to refine that (at least adding a spinner). The custom-profile-fields code is nontrivial due to the dynamic nature of custom profile fields, which can bring in specialized widgets like pill fields. Now each form corresponds to a single endpoint: * human -> /json/users * bot -> /json/bots Before we had a lot of conditional logic in the template, the code to build to views, and the code to submit the data. Now everything is much flatter. The human code is still a bit messy (more work coming on that), but the bot code is fairly pristine. All three components of the bot code fit on a page, and there are no conditionals: - admin_bot_form.hbs - open_bot_form - handle_bot_form We may want to grow out the bot code a bit to allow admins to do more things, such as adding services, and this will be easier now. It would also be easier for us now to share widgets with the per-user bot settings. Note that the form for editing human data will continue to be invoked from two panels: - Users - Deactivated users There are some minor differences between users and deactivated users, but the shape of the data is the same for both, so that's still all one codepath. We eliminate `reset_edit_user` here, since it was never used. One nice thing about these forms was that they had very little custom CSS attached to them (at form-level specificity), and it turned out all the custom CSS was for the human-specific form.
2020-05-09 12:13:03 +02:00
</div>