Unverified Commit 9c0f00f6 authored by 老广's avatar 老广 Committed by GitHub

[Update] 修改命令执行 (#2148)

* [Update] 修改命令执行

* Update forms.py
parent 6a239833
......@@ -11,6 +11,10 @@
<script src="{% static 'js/plugins/xterm/xterm.js' %}"></script>
<link rel="stylesheet" href="{% static 'js/plugins/xterm/xterm.css' %}" />
<script src="{% static 'js/plugins/xterm/addons/fit/fit.js' %}"></script>
<script src="{% static 'js/plugins/codemirror/codemirror.js' %}"></script>
<script src="{% static 'js/plugins/codemirror/mode/shell/shell.js' %}"></script>
<link href="{% static 'css/plugins/codemirror/codemirror.css' %}" rel="stylesheet">
<link href="{% static 'css/plugins/codemirror/ambiance.css' %}" rel="stylesheet">
<link href="{% static 'css/plugins/select2/select2.min.css' %}" rel="stylesheet">
<script src="{% static 'js/plugins/select2/select2.full.min.js' %}"></script>
<style type="text/css">
......@@ -51,24 +55,22 @@
<div id="term" style="height: 100%;width: 100%"></div>
</div>
<div class="row">
<div class="col-lg-10">
<div class="input-group" style="height: 100%; width: 100%">
<textarea class="form-control" id="command-text"></textarea>
</div>
</div>
<div class="col-lg-2">
<select class="select2 form-control" id="system-users-select">
{% for s in system_users %}
<select class="select2 form-control" id="system-users-select">
{% for s in system_users %}
{% if s.protocol == 'ssh' and s.login_mode == 'auto' %}
<option value="{{ s.id }}">{{ s }}</option>
{% endif %}
{% endfor %}
</select>
</div>
<div class="col-lg-10">
<div class="input-group" style="height: 100%">
<input type="text" id="command-text" class="form-control">
<span class="input-group-btn">
<button type="button" class="btn btn-primary btn-execute">{% trans 'Go' %}</button>
</span>
{% endfor %}
</select>
<button type="button" class="btn btn-primary btn-execute" style="margin-top: 30px; width: 100%">{% trans 'Go' %}</button>
</div>
</div>
</div>
</form>
</div>
</div>
......@@ -186,7 +188,7 @@ function execute() {
}
var url = '{% url "api-ops:command-execution-list" %}';
var run_as = systemUserId;
var command = $("#command-text").val();
var command = editor.getValue();
var hosts = getSelectedAssetsNode().map(function (node) {
return node.id;
});
......@@ -242,6 +244,7 @@ function execute() {
return false;
}
var editor;
$(document).ready(function(){
systemUserId = $('#system-users-select').val();
$(".select2").select2().on('select2:select', function(evt) {
......@@ -249,6 +252,19 @@ $(document).ready(function(){
systemUserId = data.id;
initTree();
});
editor = CodeMirror.fromTextArea(document.getElementById("command-text"), {
lineNumbers: true,
lineWrapping: true,
mode: "shell"
});
editor.setSize(600, 100);
var charWidth = editor.defaultCharWidth(), basePadding = 4;
editor.on("renderLine", function(cm, line, elt) {
var off = CodeMirror.countColumn(line.text, null, cm.getOption("tabSize")) * charWidth;
elt.style.textIndent = "-" + off + "px";
elt.style.paddingLeft = (basePadding + off) + "px";
});
editor.refresh();
initTree();
initResultTerminal();
}).on('click', '.btn-execute', function () {
......
......@@ -54,9 +54,15 @@
<div class="col-sm-9">
<div class="input-daterange input-group" id="datepicker">
<span class="input-group-addon"><i class="fa fa-calendar"></i></span>
<input type="text" class="input-sm form-control" id="date_start" name="date_start" value="{{ form.date_start.value|date:'Y-m-d H:i' }}">
<span class="input-group-addon">to</span>
<input type="text" class="input-sm form-control" id="date_expired" name="date_expired" value="{{ form.date_expired.value|date:'Y-m-d H:i' }}">
{% if form.errors %}
<input type="text" class="input-sm form-control" id="date_start" name="date_start" value="{{ form.date_start.value }}">
<span class="input-group-addon">to</span>
<input type="text" class="input-sm form-control" id="date_expired" name="date_expired" value="{{ form.date_expired.value }}">
{% else %}
<input type="text" class="input-sm form-control" id="date_start" name="date_start" value="{{ form.date_start.value|date:'Y-m-d H:i' }}">
<span class="input-group-addon">to</span>
<input type="text" class="input-sm form-control" id="date_expired" name="date_expired" value="{{ form.date_expired.value|date:'Y-m-d H:i' }}">
{% endif %}
</div>
<span class="help-block ">{{ form.date_expired.errors }}</span>
<span class="help-block ">{{ form.date_start.errors }}</span>
......
......@@ -131,6 +131,10 @@ class UserCreateUpdateForm(OrgModelForm):
class UserProfileForm(forms.ModelForm):
username = forms.CharField(disabled=True)
name = forms.CharField(disabled=True)
email = forms.CharField(disabled=True)
class Meta:
model = User
fields = [
......
......@@ -260,8 +260,6 @@ class User(AbstractUser):
self.role = 'Admin'
self.is_active = True
super().save(*args, **kwargs)
if current_org and current_org.is_real():
self.orgs.add(current_org.id)
@property
def private_token(self):
......
......@@ -30,7 +30,11 @@
<div class="col-sm-9">
<div class="input-group date">
<span class="input-group-addon"><i class="fa fa-calendar"></i></span>
<input id="{{ form.date_expired.id_for_label }}" name="{{ form.date_expired.html_name }}" type="text" class="form-control" value="{{ form.date_expired.value|date:'Y-m-d H:i' }}">
{% if form.errors %}
<input id="{{ form.date_expired.id_for_label }}" name="{{ form.date_expired.html_name }}" type="text" class="form-control" value="{{ form.date_expired.value }}">
{% else %}
<input id="{{ form.date_expired.id_for_label }}" name="{{ form.date_expired.html_name }}" type="text" class="form-control" value="{{ form.date_expired.value|date:'Y-m-d H:i' }}">
{% endif %}
</div>
<span class="help-block ">{{ form.date_expired.errors }}</span>
</div>
......
......@@ -87,6 +87,8 @@ class UserCreateView(AdminUserRequiredMixin, SuccessMessageMixin, CreateView):
user = form.save(commit=False)
user.created_by = self.request.user.username or 'System'
user.save()
if current_org and current_org.is_real():
user.orgs.add(current_org.id)
post_user_create.send(self.__class__, user=user)
return super().form_valid(form)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment