Template stuff
This commit is contained in:
parent
b8ff50956c
commit
6108091278
|
@ -13,6 +13,59 @@
|
|||
|
||||
if(!isset($_APP)) { die("Unauthorized."); }
|
||||
|
||||
$sPageContents = NewTemplater::Render("{$sTheme}/admin/template/add", $locale->strings, array(
|
||||
"templates" => array("ubuntu.tar.gz", "fedora.tar.gz", "debian7.tar.gz", "opensuse.tar.gz")
|
||||
));
|
||||
if($router->uMethod == "post")
|
||||
{
|
||||
$handler = new CPHPFormHandler();
|
||||
|
||||
try
|
||||
{
|
||||
$handler
|
||||
->RequireKey("filename")
|
||||
->RequireKey("name")
|
||||
->RequireKey("description")
|
||||
->RequireNonEmpty("filename")
|
||||
->RequireNonEmpty("name")
|
||||
->ValidateCustom("filename", "The specified template file does not exist.", function($key, $value, $args, $handler){
|
||||
return file_exists("/etc/cvm/templates/{$value}");
|
||||
})
|
||||
->Done();
|
||||
}
|
||||
catch (FormValidationException $e)
|
||||
{
|
||||
/*echo("Errors:<br>");
|
||||
foreach($e->exceptions as $exceptionlist)
|
||||
{
|
||||
foreach($exceptionlist as $exception)
|
||||
{
|
||||
echo("{$exception['key']}[{$exception['index']}] {$exception['error_msg']}<br>");
|
||||
}
|
||||
}*/
|
||||
var_dump($e->GetOffendingKeys());
|
||||
var_dump($e->GetErrors());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$sUnknownTemplates = array();
|
||||
|
||||
$handle = opendir("/etc/cvm/templates");
|
||||
while(($filename = readdir($handle)) !== false)
|
||||
{
|
||||
if($filename != "." && $filename != "..")
|
||||
{
|
||||
try
|
||||
{
|
||||
Template::CreateFromQuery("SELECT * FROM templates WHERE `TemplateName` = :Filename", array("Filename" => $filename), 0);
|
||||
}
|
||||
catch (NotFoundException $e)
|
||||
{
|
||||
$sUnknownTemplates[] = $filename;
|
||||
}
|
||||
}
|
||||
}
|
||||
closedir($handle);
|
||||
|
||||
$sPageContents = NewTemplater::Render("{$sTheme}/admin/template/add", $locale->strings, array(
|
||||
"templates" => $sUnknownTemplates
|
||||
));
|
||||
}
|
||||
|
|
40
frontend/modules/admin/template/list.php
Normal file
40
frontend/modules/admin/template/list.php
Normal file
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
/*
|
||||
* CVM is more free software. It is licensed under the WTFPL, which
|
||||
* allows you to do pretty much anything with it, without having to
|
||||
* ask permission. Commercial use is allowed, and no attribution is
|
||||
* required. We do politely request that you share your modifications
|
||||
* to benefit other developers, but you are under no enforced
|
||||
* obligation to do so :)
|
||||
*
|
||||
* Please read the accompanying LICENSE document for the full WTFPL
|
||||
* licensing text.
|
||||
*/
|
||||
|
||||
if(!isset($_APP)) { die("Unauthorized."); }
|
||||
|
||||
$sTemplates = array();
|
||||
|
||||
try
|
||||
{
|
||||
foreach(Template::CreateFromQuery("SELECT * FROM templates") as $sTemplate)
|
||||
{
|
||||
$sTemplates[] = array(
|
||||
"id" => $sTemplate->sId,
|
||||
"name" => $sTemplate->sName,
|
||||
"filename" => $sTemplate->sTemplateName,
|
||||
"description" => $sTemplate->sDescription,
|
||||
"supported" => $sTemplate->sIsSupported,
|
||||
"outdated" => $sTemplate->sIsOutdated,
|
||||
"available" => $sTemplate->sIsAvailable
|
||||
);
|
||||
}
|
||||
}
|
||||
catch (NotFoundException $e)
|
||||
{
|
||||
/* pass */
|
||||
}
|
||||
|
||||
$sPageContents = NewTemplater::Render("{$sTheme}/admin/template/list", $locale->strings, array(
|
||||
"templates" => $sTemplates
|
||||
));
|
|
@ -4,6 +4,7 @@
|
|||
<ul>
|
||||
<li><a href="/admin/"><i class="fa fa-fw fa-bars"></i> {%!menu-admin-overview}</a></li>
|
||||
<li><a href="/admin/nodes/"><i class="fa fa-fw fa-desktop"></i> {%!menu-admin-nodes}</a></li>
|
||||
<li><a href="/admin/templates/"><i class="fa fa-fw fa-puzzle-piece"></i> {%!menu-admin-templates}</a></li>
|
||||
<li><a href="/admin/users/"><i class="fa fa-fw fa-users"></i> {%!menu-admin-users}</a></li>
|
||||
<li><a href="/admin/vpses/"><i class="fa fa-fw fa-cloud"></i> {%!menu-admin-vpses}</a></li>
|
||||
</ul>
|
||||
|
|
36
frontend/templates/pure/admin/template/add.tpl
Normal file
36
frontend/templates/pure/admin/template/add.tpl
Normal file
|
@ -0,0 +1,36 @@
|
|||
<h2>Add templates</h2>
|
||||
|
||||
{%if isempty|templates == true}
|
||||
<p>
|
||||
To add new templates, add the corresponding tar.gz files to /etc/cvm/templates on the master node, and reload this page.
|
||||
New files will be automatically detected, and you will be able to add them as templates from this page.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
All templates will be automatically synchronized to slave nodes.
|
||||
</p>
|
||||
{%else}
|
||||
<form method="post" action="/admin/templates/add" class="pure-form pure-form-aligned">
|
||||
{%foreach template in templates}
|
||||
<section>
|
||||
<div class="pure-controls">
|
||||
<h3>{%?template}</h3>
|
||||
<input type="hidden" name="filename[]" value="{%?template}">
|
||||
</div>
|
||||
|
||||
<div class="pure-control-group">
|
||||
<label>Template name</label>
|
||||
{%input type="text" group="addtemplate" name="name[]"}
|
||||
</div>
|
||||
|
||||
<div class="pure-control-group">
|
||||
<label>Description</label>
|
||||
<textarea name="description[]"></textarea>
|
||||
</div>
|
||||
</section>
|
||||
{%/foreach}
|
||||
<div class="pure-controls">
|
||||
<button type="submit" name="submit" class="pure-button pure-button-primary">Add templates</button>
|
||||
</div>
|
||||
</form>
|
||||
{%/if}
|
56
frontend/templates/pure/admin/template/list.tpl
Normal file
56
frontend/templates/pure/admin/template/list.tpl
Normal file
|
@ -0,0 +1,56 @@
|
|||
<h2>Template overview</h2>
|
||||
|
||||
<div class="pure-menu pure-menu-open pure-menu-horizontal submenu">
|
||||
<ul>
|
||||
<li><a href="/admin/templates/add/"><i class="fa fa-fw fa-plus-circle"></i> Add template(s)</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<table class="pure-table pure-table-bordered stretch">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Filename</th>
|
||||
<th>Template name</th>
|
||||
<th>Supported</th>
|
||||
<th>Up-to-date</th>
|
||||
<th>Available</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{%foreach template in templates}
|
||||
<tr class="clickable" data-url="/admin/template/{%?template[id]}/">
|
||||
<td>
|
||||
<a href="/admin/template/{%?template[id]}/">
|
||||
{%?template[filename]}
|
||||
</a>
|
||||
</td>
|
||||
<td>
|
||||
<a href="/admin/template/{%?template[id]}/">
|
||||
{%?template[name]}
|
||||
</a>
|
||||
</td>
|
||||
<td class="icon">
|
||||
{%if template[supported] == true}
|
||||
<i class="fa fa-check-circle ok"></i>
|
||||
{%else}
|
||||
<i class="fa fa-times-circle not-ok"></i>
|
||||
{%/if}
|
||||
</td>
|
||||
<td class="icon">
|
||||
{%if template[outdated] == true}
|
||||
<i class="fa fa-times-circle not-ok"></i>
|
||||
{%else}
|
||||
<i class="fa fa-check-circle ok"></i>
|
||||
{%/if}
|
||||
</td>
|
||||
<td class="icon">
|
||||
{%if template[available] == true}
|
||||
<i class="fa fa-check-circle ok"></i>
|
||||
{%else}
|
||||
<i class="fa fa-times-circle not-ok"></i>
|
||||
{%/if}
|
||||
</td>
|
||||
</tr>
|
||||
{%/foreach}
|
||||
</tbody>
|
||||
</table>
|
|
@ -22,8 +22,19 @@
|
|||
text-align: left;
|
||||
vertical-align: bottom;
|
||||
border-bottom: 1px solid #cbcbcb; }
|
||||
.wrapper .pure-table i.fa.ok {
|
||||
color: #208927; }
|
||||
.wrapper .pure-table i.fa.not-ok {
|
||||
color: #C22118; }
|
||||
.wrapper .pure-table td.icon {
|
||||
text-align: center;
|
||||
vertical-align: middle;
|
||||
font-size: 19px; }
|
||||
.wrapper .pure-button.add {
|
||||
#background-color: #7ECB9A; }
|
||||
.wrapper .clickable:hover {
|
||||
background-color: #F1F1F1;
|
||||
cursor: pointer; }
|
||||
.wrapper section {
|
||||
margin-bottom: 16px; }
|
||||
.wrapper .error {
|
||||
|
|
|
@ -48,6 +48,26 @@
|
|||
vertical-align: bottom;
|
||||
border-bottom: 1px solid #cbcbcb;
|
||||
}
|
||||
|
||||
i.fa
|
||||
{
|
||||
&.ok
|
||||
{
|
||||
color: #208927;
|
||||
}
|
||||
|
||||
&.not-ok
|
||||
{
|
||||
color: #C22118;
|
||||
}
|
||||
}
|
||||
|
||||
td.icon
|
||||
{
|
||||
text-align: center;
|
||||
vertical-align: middle;
|
||||
font-size: 19px;
|
||||
}
|
||||
}
|
||||
|
||||
.pure-button
|
||||
|
@ -58,6 +78,12 @@
|
|||
}
|
||||
}
|
||||
|
||||
.clickable:hover
|
||||
{
|
||||
background-color: #F1F1F1;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
section
|
||||
{
|
||||
margin-bottom: 16px;
|
||||
|
|
Loading…
Reference in a new issue