From 61080912781f12582665f9a7d0dcf28b01dafaeb Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Sun, 29 Dec 2013 19:13:48 +0100 Subject: [PATCH] Template stuff --- frontend/modules/admin/template/add.php | 59 ++++++++++++++++++- frontend/modules/admin/template/list.php | 40 +++++++++++++ frontend/templates/pure/admin/main.tpl | 1 + .../templates/pure/admin/template/add.tpl | 36 +++++++++++ .../templates/pure/admin/template/list.tpl | 56 ++++++++++++++++++ frontend/templates/pure/static/css/cvm.css | 11 ++++ scss/pure/cvm.scss | 26 ++++++++ 7 files changed, 226 insertions(+), 3 deletions(-) create mode 100644 frontend/modules/admin/template/list.php create mode 100644 frontend/templates/pure/admin/template/add.tpl create mode 100644 frontend/templates/pure/admin/template/list.tpl diff --git a/frontend/modules/admin/template/add.php b/frontend/modules/admin/template/add.php index bccb007..008ac74 100644 --- a/frontend/modules/admin/template/add.php +++ b/frontend/modules/admin/template/add.php @@ -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:
"); + foreach($e->exceptions as $exceptionlist) + { + foreach($exceptionlist as $exception) + { + echo("{$exception['key']}[{$exception['index']}] {$exception['error_msg']}
"); + } + }*/ + 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 + )); +} diff --git a/frontend/modules/admin/template/list.php b/frontend/modules/admin/template/list.php new file mode 100644 index 0000000..90ff6ba --- /dev/null +++ b/frontend/modules/admin/template/list.php @@ -0,0 +1,40 @@ + $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 +)); diff --git a/frontend/templates/pure/admin/main.tpl b/frontend/templates/pure/admin/main.tpl index 13184ea..8ce82c0 100644 --- a/frontend/templates/pure/admin/main.tpl +++ b/frontend/templates/pure/admin/main.tpl @@ -4,6 +4,7 @@ diff --git a/frontend/templates/pure/admin/template/add.tpl b/frontend/templates/pure/admin/template/add.tpl new file mode 100644 index 0000000..3026f5b --- /dev/null +++ b/frontend/templates/pure/admin/template/add.tpl @@ -0,0 +1,36 @@ +

Add templates

+ +{%if isempty|templates == true} +

+ 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. +

+ +

+ All templates will be automatically synchronized to slave nodes. +

+{%else} +
+ {%foreach template in templates} +
+
+

{%?template}

+ +
+ +
+ + {%input type="text" group="addtemplate" name="name[]"} +
+ +
+ + +
+
+ {%/foreach} +
+ +
+
+{%/if} diff --git a/frontend/templates/pure/admin/template/list.tpl b/frontend/templates/pure/admin/template/list.tpl new file mode 100644 index 0000000..1982a56 --- /dev/null +++ b/frontend/templates/pure/admin/template/list.tpl @@ -0,0 +1,56 @@ +

Template overview

+ + + + + + + + + + + + + + + {%foreach template in templates} + + + + + + + + {%/foreach} + +
FilenameTemplate nameSupportedUp-to-dateAvailable
+ + {%?template[filename]} + + + + {%?template[name]} + + + {%if template[supported] == true} + + {%else} + + {%/if} + + {%if template[outdated] == true} + + {%else} + + {%/if} + + {%if template[available] == true} + + {%else} + + {%/if} +
diff --git a/frontend/templates/pure/static/css/cvm.css b/frontend/templates/pure/static/css/cvm.css index 808f89f..a947ee2 100644 --- a/frontend/templates/pure/static/css/cvm.css +++ b/frontend/templates/pure/static/css/cvm.css @@ -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 { diff --git a/scss/pure/cvm.scss b/scss/pure/cvm.scss index 4312134..ed97241 100644 --- a/scss/pure/cvm.scss +++ b/scss/pure/cvm.scss @@ -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;