diff --git a/src/IDF/Forge.php b/src/IDF/Forge.php index fc4d430..832323d 100644 --- a/src/IDF/Forge.php +++ b/src/IDF/Forge.php @@ -70,4 +70,20 @@ class IDF_Forge } return $tags; } + + public function setCustomForgePageEnabled($enabled) { + $this->conf->setVal('custom_forge_page_enabled', $enabled); + } + + public function isCustomForgePageEnabled($default = false) { + return $this->conf->getVal('custom_forge_page_enabled', $default); + } + + public function getCustomForgePageContent($default = '') { + return $this->conf->getVal('custom_forge_page_content', $default); + } + + public function setCustomForgePageContent($content) { + $this->conf->setVal('custom_forge_page_content', $content); + } } \ No newline at end of file diff --git a/src/IDF/Form/Admin/ForgeConf.php b/src/IDF/Form/Admin/ForgeConf.php new file mode 100644 index 0000000..669ac67 --- /dev/null +++ b/src/IDF/Form/Admin/ForgeConf.php @@ -0,0 +1,47 @@ +fields['enabled'] = new Pluf_Form_Field_Boolean( + array('required' => false, + 'label' => __('Custom forge page enabled'), + 'widget' => 'Pluf_Form_Widget_CheckboxInput', + )); + $this->fields['content'] = new Pluf_Form_Field_Varchar( + array('required' => true, + 'label' => __('Content'), + 'widget' => 'Pluf_Form_Widget_TextareaInput', + 'widget_attrs' => array( + 'cols' => 68, + 'rows' => 26, + ), + )); + } +} diff --git a/src/IDF/Middleware.php b/src/IDF/Middleware.php index 5e44abe..c59217b 100644 --- a/src/IDF/Middleware.php +++ b/src/IDF/Middleware.php @@ -85,6 +85,7 @@ class IDF_Middleware 'issuetext' => 'IDF_Template_IssueComment', 'timeline' => 'IDF_Template_TimelineFragment', 'markdown' => 'IDF_Template_Markdown', + 'markdown_forge' => 'IDF_Template_MarkdownForge', 'showuser' => 'IDF_Template_ShowUser', 'ashowuser' => 'IDF_Template_AssignShowUser', 'appversion' => 'IDF_Template_AppVersion', @@ -102,6 +103,7 @@ class IDF_Middleware function IDF_Middleware_ContextPreProcessor($request) { + $forge = IDF_Forge::instance(); $c = array(); $c['request'] = $request; $c['isAdmin'] = ($request->user->administrator or $request->user->staff); @@ -115,6 +117,7 @@ function IDF_Middleware_ContextPreProcessor($request) } $c['usherConfigured'] = Pluf::f("mtn_usher_conf", null) !== null; $c['allProjects'] = IDF_Views::getProjects($request->user); + $c['customForgePageEnabled'] = $forge->isCustomForgePageEnabled(); return $c; } diff --git a/src/IDF/Template/MarkdownForge.php b/src/IDF/Template/MarkdownForge.php new file mode 100644 index 0000000..58516b8 --- /dev/null +++ b/src/IDF/Template/MarkdownForge.php @@ -0,0 +1,34 @@ +go(Pluf_Text_MarkDown_parse($text)); + } +} + diff --git a/src/IDF/Views.php b/src/IDF/Views.php index 3eaa01c..ecc526f 100644 --- a/src/IDF/Views.php +++ b/src/IDF/Views.php @@ -36,20 +36,41 @@ class IDF_Views */ public function index($request, $match) { - // TODO: add a switch here later on to determine whether the project list - // or a custom start page should be displayed - $match = array('', 'all', 'name'); - return $this->listProjects($request, $match); + $forge = IDF_Forge::instance(); + if (!$forge->isCustomForgePageEnabled()) { + $url = Pluf_HTTP_URL_urlForView('IDF_Views::listProjects'); + return new Pluf_HTTP_Response_Redirect($url); + } + + return Pluf_Shortcuts_RenderToResponse('idf/index.html', + array('page_title' => __('Welcome'), + 'content' => $forge->getCustomForgePageContent(), + ), + $request); } /** - * List all the projects managed by InDefero. + * List all projects unfiltered * - * Only the public projects are listed or the private with correct - * rights. + * @param unknown_type $request + * @param unknown_type $match + * @return Pluf_HTTP_Response */ public function listProjects($request, $match) { + $match = array('', 'all', 'name'); + return $this->listProjectsByLabel($request, $match); + } + + /** + * List projects, optionally filtered by label + * + * @param unknown_type $request + * @param unknown_type $match + * @return Pluf_HTTP_Response + */ + public function listProjectsByLabel($request, $match) + { list(, $tagId, $order) = $match; $tag = false; diff --git a/src/IDF/Views/Admin.php b/src/IDF/Views/Admin.php index 8176fd5..7e78698 100644 --- a/src/IDF/Views/Admin.php +++ b/src/IDF/Views/Admin.php @@ -32,20 +32,40 @@ Pluf::loadFunction('Pluf_Shortcuts_GetFormForModel'); class IDF_Views_Admin { /** - * Home page of the administration. - * - * It should provide an overview of the forge status. + * Start page of the administration. */ - public $home_precond = array('Pluf_Precondition::staffRequired'); - public function home($request, $match) + public $forge_precond = array('Pluf_Precondition::staffRequired'); + public function forge($request, $match) { $title = __('Forge Management'); - return Pluf_Shortcuts_RenderToResponse('idf/gadmin/home.html', + $forge = IDF_Forge::instance(); + if ($request->method == 'POST') { + $form = new IDF_Form_Admin_ForgeConf($request->POST); + if ($form->isValid()) { + $forge->setCustomForgePageEnabled($form->cleaned_data['enabled']); + $forge->setCustomForgePageContent($form->cleaned_data['content']); + $request->user->setMessage(__('The forge configuration has been saved.')); + $url = Pluf_HTTP_URL_urlForView('IDF_Views_Admin::forge'); + return new Pluf_HTTP_Response_Redirect($url); + } + } else { + $params = array(); + $params['enabled'] = $forge->isCustomForgePageEnabled(); + if (($content = $forge->getCustomForgePageContent(false)) !== false) { + $params['content'] = $content; + } + if (count($params) == 0) { + $params = null; //Nothing in the db, so new form. + } + $form = new IDF_Form_Admin_ForgeConf($params); + } + return Pluf_Shortcuts_RenderToResponse('idf/gadmin/forge/index.html', array( - 'page_title' => $title, - ), + 'page_title' => $title, + 'form' => $form, + ), $request); - } + } /** * Projects overview. diff --git a/src/IDF/conf/urls.php b/src/IDF/conf/urls.php index 5995e5b..eac28ae 100644 --- a/src/IDF/conf/urls.php +++ b/src/IDF/conf/urls.php @@ -29,11 +29,16 @@ $ctl[] = array('regex' => '#^/$#', 'model' => 'IDF_Views', 'method' => 'index'); -$ctl[] = array('regex' => '#^/label/(\w+)/(\w+)/$#', +$ctl[] = array('regex' => '#^/projects/$#', 'base' => $base, 'model' => 'IDF_Views', 'method' => 'listProjects'); +$ctl[] = array('regex' => '#^/projects/label/(\w+)/(\w+)/$#', + 'base' => $base, + 'model' => 'IDF_Views', + 'method' => 'listProjectsByLabel'); + $ctl[] = array('regex' => '#^/login/$#', 'base' => $base, 'model' => 'IDF_Views', @@ -473,6 +478,11 @@ $ctl[] = array('regex' => '#^/api/$#', // ---------- FORGE ADMIN -------------------------------- +$ctl[] = array('regex' => '#^/admin/forge/$#', + 'base' => $base, + 'model' => 'IDF_Views_Admin', + 'method' => 'forge'); + $ctl[] = array('regex' => '#^/admin/projects/$#', 'base' => $base, 'model' => 'IDF_Views_Admin', diff --git a/src/IDF/templates/idf/gadmin/base.html b/src/IDF/templates/idf/gadmin/base.html index 20249ee..6a6ab92 100644 --- a/src/IDF/templates/idf/gadmin/base.html +++ b/src/IDF/templates/idf/gadmin/base.html @@ -39,6 +39,7 @@ {include 'idf/main-menu.html'}