mirror of
https://github.com/ComputerScienceHouse/proxstar.git
synced 2025-03-09 15:40:09 +00:00
remove settings button in dropdown, add ability to edit templates
This commit is contained in:
parent
019dae3502
commit
df8e1cf62c
5 changed files with 112 additions and 7 deletions
|
@ -511,6 +511,20 @@ def template_disk(template_id):
|
||||||
return get_template_disk(db, template_id)
|
return get_template_disk(db, template_id)
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/template/<string:template_id>/edit', methods=['POST'])
|
||||||
|
@auth.oidc_auth
|
||||||
|
def template_edit(template_id):
|
||||||
|
if 'rtp' in session['userinfo']['groups']:
|
||||||
|
name = request.form['name']
|
||||||
|
username = request.form['username']
|
||||||
|
password = request.form['password']
|
||||||
|
disk = request.form['disk']
|
||||||
|
set_template_info(db, template_id, name, username, password, disk)
|
||||||
|
return '', 200
|
||||||
|
else:
|
||||||
|
return '', 403
|
||||||
|
|
||||||
|
|
||||||
@app.route("/logout")
|
@app.route("/logout")
|
||||||
@auth.oidc_logout
|
@auth.oidc_logout
|
||||||
def logout():
|
def logout():
|
||||||
|
|
|
@ -201,3 +201,14 @@ def delete_allowed_user(db, user):
|
||||||
Allowed_Users.id == user).one()
|
Allowed_Users.id == user).one()
|
||||||
db.delete(allowed_user)
|
db.delete(allowed_user)
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
|
|
||||||
|
def set_template_info(db, template_id, name, username, password, disk):
|
||||||
|
if db.query(exists().where(Template.id == template_id,)).scalar():
|
||||||
|
template = db.query(Template).filter(Template.id == template_id,).one()
|
||||||
|
template.name = name
|
||||||
|
template.username = username
|
||||||
|
if password:
|
||||||
|
template.password = password
|
||||||
|
template.disk = disk
|
||||||
|
db.commit()
|
||||||
|
|
|
@ -903,3 +903,87 @@ $(".resize-disk").click(function(){
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$(".edit-template").click(function(){
|
||||||
|
const template_id = $(this).data('template_id');
|
||||||
|
const template_name = $(this).data('template_name');
|
||||||
|
const template_username = $(this).data('template_username');
|
||||||
|
const template_disk = $(this).data('template_disk');
|
||||||
|
var options = document.createElement('div');
|
||||||
|
name_text = document.createElement('p');
|
||||||
|
name_text.innerHTML = 'Name';
|
||||||
|
options.append(name_text);
|
||||||
|
var name = document.createElement('input');
|
||||||
|
name.defaultValue = template_name;
|
||||||
|
options.append(name);
|
||||||
|
username_text = document.createElement('p');
|
||||||
|
username_text.innerHTML = 'Username';
|
||||||
|
options.append(username_text);
|
||||||
|
var username = document.createElement('input');
|
||||||
|
username.defaultValue = template_username;
|
||||||
|
options.append(username);
|
||||||
|
password_text = document.createElement('p');
|
||||||
|
password_text.innerHTML = 'Password';
|
||||||
|
options.append(password_text);
|
||||||
|
var password = document.createElement('input');
|
||||||
|
password.type = 'password';
|
||||||
|
options.append(password);
|
||||||
|
disk_text = document.createElement('p');
|
||||||
|
disk_text.innerHTML = 'Disk Size (GB)';
|
||||||
|
options.append(disk_text);
|
||||||
|
var disk = document.createElement('input');
|
||||||
|
disk.type = 'number';
|
||||||
|
disk.defaultValue = template_disk;
|
||||||
|
options.append(disk);
|
||||||
|
swal({
|
||||||
|
title: `Template ${template_id}:`,
|
||||||
|
content: options,
|
||||||
|
buttons: {
|
||||||
|
cancel: {
|
||||||
|
text: "Cancel",
|
||||||
|
visible: true,
|
||||||
|
closeModal: true,
|
||||||
|
className: "",
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
text: "Submit",
|
||||||
|
closeModal: false,
|
||||||
|
className: "swal-button",
|
||||||
|
}
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.then((willChange) => {
|
||||||
|
if (willChange) {
|
||||||
|
var data = new FormData();
|
||||||
|
data.append('name', $(name).val());
|
||||||
|
data.append('username', $(username).val());
|
||||||
|
data.append('password', $(password).val());
|
||||||
|
data.append('disk', $(disk).val());
|
||||||
|
fetch(`/template/${template_id}/edit`, {
|
||||||
|
credentials: 'same-origin',
|
||||||
|
method: 'post',
|
||||||
|
body: data
|
||||||
|
}).then((response) => {
|
||||||
|
return swal(`Template info changed!`, {
|
||||||
|
icon: "success",
|
||||||
|
buttons: {
|
||||||
|
ok: {
|
||||||
|
text: "OK",
|
||||||
|
closeModal: true,
|
||||||
|
className: "",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}).then(() => {
|
||||||
|
location.reload();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}).catch(err => {
|
||||||
|
if (err) {
|
||||||
|
swal("Uh oh...", `Unable to change the template info. Please try again later.`, "error");
|
||||||
|
} else {
|
||||||
|
swal.stopLoading();
|
||||||
|
swal.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
@ -60,13 +60,6 @@
|
||||||
<span class="caret"></span>
|
<span class="caret"></span>
|
||||||
</a>
|
</a>
|
||||||
<ul class="dropdown-menu" role="menu">
|
<ul class="dropdown-menu" role="menu">
|
||||||
<li>
|
|
||||||
<a href="/settings">
|
|
||||||
<span class="glyphicon glyphicon-cog"></span>
|
|
||||||
Settings
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
<li class="divider"></li>
|
|
||||||
<li>
|
<li>
|
||||||
<a href="https://profiles.csh.rit.edu/user/{{ user['username'] }}">
|
<a href="https://profiles.csh.rit.edu/user/{{ user['username'] }}">
|
||||||
<span class="glyphicon glyphicon-user"></span>
|
<span class="glyphicon glyphicon-user"></span>
|
||||||
|
|
|
@ -27,6 +27,9 @@
|
||||||
<td>{{ template['username'] }}</td>
|
<td>{{ template['username'] }}</td>
|
||||||
<td>{{ template['disk'] }}</td>
|
<td>{{ template['disk'] }}</td>
|
||||||
<td>
|
<td>
|
||||||
|
<button class="btn btn-sm btn-info edit-template" data-template_id="{{ template['id'] }}" data-template_name="{{ template['name'] }}" data-template_username="{{ template['username'] }}" data-template_disk="{{ template['disk'] }}">
|
||||||
|
<span class="glyphicon glyphicon-pencil"></span>
|
||||||
|
</button>
|
||||||
<button class="btn btn-sm btn-danger delete-template" data-template_id="{{ template['id'] }}">
|
<button class="btn btn-sm btn-danger delete-template" data-template_id="{{ template['id'] }}">
|
||||||
<span class="glyphicon glyphicon-remove"></span>
|
<span class="glyphicon glyphicon-remove"></span>
|
||||||
</button>
|
</button>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue