order page phase 1

This commit is contained in:
deflax 2018-02-21 18:01:35 +02:00
parent a094ccc081
commit b0b82fc7e7
7 changed files with 153 additions and 49 deletions

View file

@ -232,7 +232,10 @@ class Order(db.Model):
pid = db.Column(db.Integer, primary_key=True) pid = db.Column(db.Integer, primary_key=True)
user_id = db.Column(db.ForeignKey('users.pid')) #FK user_id = db.Column(db.ForeignKey('users.pid')) #FK
recipe_id = db.Column(db.ForeignKey('recipes.pid')) #FK recipe_id = db.Column(db.ForeignKey('recipes.pid')) #FK
parameters = db.Column(db.String) parameter1 = db.Column(db.String)
parameter2 = db.Column(db.String)
parameter3 = db.Column(db.String)
parameter4 = db.Column(db.String)
class Recipe(db.Model): class Recipe(db.Model):
__tablename__ = 'recipes' __tablename__ = 'recipes'

View file

@ -6,9 +6,17 @@ from wtforms.fields.html5 import EmailField, DecimalRangeField
from .. import db from .. import db
class OrderForm(FlaskForm): class OrderForm(FlaskForm):
alias = StringField('Machine Alias:', [validators.Regexp(message='ex.: myservice1.com, myservice2.local', regex='^[a-zA-Z0-9][a-zA-Z0-9-_]{0,61}[a-zA-Z0-9]{0,1}\.([a-zA-Z]{1,6}|[a-zA-Z0-9-]{1,30}\.[a-zA-Z]{2,3})$'), validators.Length(6,64)]) region_choices = [(1, 'Plovdiv, Bulgaria')]
region = SelectField('Region:', choices=region_choices, coerce=int)
vmtype_choices = [(1, 'RootVPS')]
vmtype = SelectField('Type:', choices=vmtype_choices, coerce=int)
cpu = DecimalRangeField('Processor Cores', default=2) cpu = DecimalRangeField('Processor Cores', default=2)
memory = DecimalRangeField('Memory', default=512) memory = DecimalRangeField('Memory', default=512)
storage = DecimalRangeField('Storage', default=10) storage = DecimalRangeField('Storage', default=10)
submit = SubmitField('Create')
alias = StringField('Machine Alias:', [validators.Regexp(message='ex.: myservice1.com, myservice2.local', regex='^[a-zA-Z0-9][a-zA-Z0-9-_]{0,61}[a-zA-Z0-9]{0,1}\.([a-zA-Z]{1,6}|[a-zA-Z0-9-]{1,30}\.[a-zA-Z]{2,3})$'), validators.Length(6,64)])
submit = SubmitField('DEPLOY')

View file

@ -6,7 +6,7 @@ from . import panel
from .forms import OrderForm from .forms import OrderForm
from .. import db from .. import db
from ..email import send_email from ..email import send_email
from ..models import User, Permission, Server, Deployment, Service, Region, Address, Domain, contact_proxmaster from ..models import User, Permission, Recipe, Order, Server, Deployment, Service, Region, Address, Domain, contact_proxmaster
import base64 import base64
@ -17,13 +17,23 @@ def after_request(response):
current_app.logger.warning('Slow query: %s\nParameters: %s\nDuration: %fs\nContext: %s\n' % (query.statement, query.parameters, query.duration, query.context)) current_app.logger.warning('Slow query: %s\nParameters: %s\nDuration: %fs\nContext: %s\n' % (query.statement, query.parameters, query.duration, query.context))
return response return response
@panel.route("/ordervm", methods=['GET', 'POST']) @panel.route("/deploy", methods=['GET', 'POST'])
@login_required @login_required
def order(): def deploy():
if current_user.name is None:
return redirect(url_for('settings.profile'))
form = OrderForm() form = OrderForm()
if form.validate_on_submit(): if form.validate_on_submit():
pass recipe = Recipe.query.filter_by(category='deploy').first()
return redirect('main.dashboard') new_order = Order(user_id=int(current_user.pid), recipe_id=int(recipe.pid), parameter1=str(form.alias.data), parameter2=str(form.cpu.data), parameter3=str(form.memory.data), parameter4=str(form.storage.data))
db.session.add(new_order)
db.session.commit()
send_email(current_app.config['MAIL_USERNAME'], 'New order from {}'.format(current_user.email),
'panel/email/adm_neworder', user=current_user)
return redirect(request.args.get('next') or url_for('panel.dashboard'))
return render_template('panel/deploy.html', form=form)
#DASHBOARD #DASHBOARD
@panel.route("/dashboard", methods=['GET', 'POST']) @panel.route("/dashboard", methods=['GET', 'POST'])

View file

@ -0,0 +1,115 @@
{% extends "base.html" %}
{% block title %}Deploy New Instance{% endblock %}
{% block scripts %}
{{ super() }}
<script>
function cpuUpdate(value) {
$('#selected-cpu').html('<h3>' + value + ' cores</h3>');
}
function memoryUpdate(value) {
$('#selected-memory').html('<h3>' + value + ' MB</h3>');
}
function storageUpdate(value) {
$('#selected-storage').html('<h3>' + value + ' GB</h3>');
}
</script>
{% endblock %}
{% block page_content %}
<center><h2>Deploy new Server</h2></center>
<div class="row">
<form method="POST" action="{{ url_for('panel.deploy') }}">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">1. Location</div>
<div class="panel-body">
<p>
{{ form.region.label }}<br /> {{ form.region }}<br />
{% for error in form.region.errors %}
{{ error }}<br />
{% endfor %}
</p>
</div>
</div>
</div>
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">2. Type</div>
<div class="panel-body">
<p>
{{ form.vmtype.label }}<br /> {{ form.vmtype }}<br />
{% for error in form.vmtype.errors %}
{{ error }}<br />
{% endfor %}
</p>
</div>
</div>
</div>
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">3. Size</div>
<div class="panel-body">
<div class="col-md-4">
<p>
{{ form.cpu.label }}
{{ form.cpu(min=2, max=16, step=2, oninput="cpuUpdate(value)") }}
<center><output for="cpu" id="selected-cpu"><h3>{{ form.cpu.data }} cores</h3></output></center>
{% for error in form.cpu.errors %}
{{ error }}<br />
{% endfor %}
</p>
</div>
<div class="col-md-4">
<p>
{{ form.memory.label }}<br /> {{ form.memory(min=512, max=16384, step=512, oninput="memoryUpdate(value)") }}
<center><output for="memory" id="selected-memory"><h3>{{ form.memory.data }} MB</h3></output></center>
{% for error in form.memory.errors %}
{{ error }}<br />
{% endfor %}
</p>
</div>
<div class="col-md-4">
<p>
{{ form.storage.label }}<br /> {{ form.storage(min=10, max=100, step=10, oninput="storageUpdate(value)") }}
<center><output for="storage" id="selected-storage"><h3>{{ form.storage.data }} GB</h3></output></center>
{% for error in form.storage.errors %}
{{ error }}<br />
{% endfor %}
</p>
</div>
</div>
</div>
</div>
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">4. Server Hostname</div>
<div class="panel-body">
<p>
{{ form.alias.label }}<br /> {{ form.alias }}<br />
{% for error in form.alias.errors %}
{{ error }}<br />
{% endfor %}
</p>
</div>
</div>
</div>
<center>
<p>
{{ form.csrf_token() }}
{{ form.submit }}
</p>
</center>
</div>
{% endblock %}

View file

@ -0,0 +1,5 @@
<p>{{ user.email }} have ordered a new deployment<br />
<br />
</p>
<p>Regards,<br />
Proxadmin</p>

View file

@ -0,0 +1,4 @@
User {{ user.email }} have ordered a new deployment.
Regards,
Proxadmin

View file

@ -1,41 +0,0 @@
{% extends "base.html" %}
{% block title %}Request new Server{% endblock %}
{% block page_content %}
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">Request new Server</div>
<div class="panel-body">
<form method="POST" action="{{ url_for('panel.ordervm') }}">
<p>
{{ form.cpu.label }}<br /> {{ form.cpu(min=2, max=16, step=2) }}<br />
{% for error in form.cpu.errors %}
{{ error }}<br />
{% endfor %}
</p>
<p>
{{ form.memory.label }}<br /> {{ form.memory(min=512, max=16384, step=512) }}<br />
{% for error in form.memory.errors %}
{{ error }}<br />
{% endfor %}
</p>
<p>
{{ form.storage.label }}<br /> {{ form.storage(min=10, max=100, step=10) }}<br />
{% for error in form.storage.errors %}
{{ error }}<br />
{% endfor %}
</p>
<p>
{{ form.csrf_token() }}
{{ form.submit }}
</p>
</div>
</div>
</div>
{% endblock %}