Skip to content
This repository has been archived by the owner on Sep 10, 2021. It is now read-only.

Commit

Permalink
Revise landingpage module configuration form and add install script
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamie Snape committed Dec 5, 2014
1 parent 1e7f746 commit 6ccd95a
Show file tree
Hide file tree
Showing 12 changed files with 223 additions and 190 deletions.
17 changes: 7 additions & 10 deletions modules/landingpage/configs/module.ini
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
; MIDAS Server. Copyright Kitware SAS. Licensed under the Apache License 2.0.

[global]
; version of the module
version = 1.0.0
; full name
fullname = Landing Page
; description
description = Module for adding a custom landing page to the Midas instance
; category
category = Core
; dependencies
dependencies =
fullname = "Landing Page"
description = "Display a custom landing page"
category = "Core"
uuid = "00c52901-4892-41a3-9e24-dd9fa56ad1f8"
version = "1.0.0"
22 changes: 22 additions & 0 deletions modules/landingpage/constant/module.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
/*=========================================================================
MIDAS Server
Copyright (c) Kitware SAS. 26 rue Louis Guérin. 69100 Villeurbanne, FRANCE
All rights reserved.
More information http://www.kitware.com
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0.txt
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=========================================================================*/

define('LANDINGPAGE_TEXT_KEY', 'text');
define('LANDINGPAGE_TEXT_DEFAULT_VALUE', 'Welcome to __Midas Platform__.');
93 changes: 93 additions & 0 deletions modules/landingpage/controllers/AdminController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php
/*=========================================================================
MIDAS Server
Copyright (c) Kitware SAS. 26 rue Louis Guérin. 69100 Villeurbanne, FRANCE
All rights reserved.
More information http://www.kitware.com
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0.txt
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=========================================================================*/

/**
* Admin controller for the landingpage module.
*
* @property Landingpage_TextModel $Landingpage_Text
*/
class Landingpage_AdminController extends Landingpage_AppController
{
/** @var array */
public $_models = array('Setting');

/** @var array */
public $_moduleDaos = array('Text');

/** @var array */
public $_moduleModels = array('Text');

/** Index action */
public function indexAction()
{
$this->requireAdminPrivileges();

$this->view->pageTitle = 'Landing Page Module Configuration';
$form = new Landingpage_Form_Admin();
$textDaos = $this->Landingpage_Text->getAll();

if ($this->getRequest()->isPost()) {
$data = $this->getRequest()->getPost();

if ($form->isValid($data)) {
$values = $form->getValues();

if (count($textDaos) > 0) {
$textDao = $textDaos[0];
} else {
/** @var Landingpage_TextDao $textDao */
$textDao = MidasLoader::newDao('Text', $this->moduleName);
}

$textDao->setText($values[LANDINGPAGE_TEXT_KEY]);
$this->Landingpage_Text->save($textDao);
unset($values[LANDINGPAGE_TEXT_KEY]);

foreach ($values as $key => $value) {
$this->Setting->setConfig($key, $value, $this->moduleName);
}
}

$form->populate($data);
} else {
$elements = $form->getElements();

foreach ($elements as $element) {
$name = $element->getName();

if ($name === LANDINGPAGE_TEXT_KEY) {
if (count($textDaos) > 0) {
$value = $textDaos[0]->getText();
$form->setDefault($name, $value);
}
} elseif ($name !== 'csrf' && $name !== 'submit') {
$value = $this->Setting->getValueByName($name, $this->moduleName);

if (!is_null($value)) {
$form->setDefault($name, $value);
}
}
}
}

$this->view->form = $form;
session_start();
}
}
61 changes: 0 additions & 61 deletions modules/landingpage/controllers/ConfigController.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,19 @@
limitations under the License.
=========================================================================*/

/** Landingpage module config form */
class Landingpage_ConfigForm extends AppForm
{
/** main config form */
public function createForm()
{
$form = new Zend_Form();

$form->setAction("")->setMethod('post');

$name = new Zend_Form_Element_Textarea('text');
$name->setRequired(true)->setAttrib('cols', '120')->setAttrib('rows', '100')->setValue(
'Add some text or _Markdown_ here'
);
require_once BASE_PATH.'/modules/landingpage/constant/module.php';

$submit = new Zend_Form_Element_Submit('submit');
$submit->setLabel('Edit');

$form->addElements(array($name, $submit));
/** Install the landingpage module. */
class Landingpage_InstallScript extends MIDASModuleInstallScript
{
/** @var string */
public $moduleName = 'landingpage';

return $form;
/** Post database install. */
public function postInstall()
{
/** @var SettingModel $settingModel */
$settingModel = MidasLoader::loadModel('Setting');
$settingModel->setConfig(LANDINGPAGE_TEXT_KEY, LANDINGPAGE_TEXT_DEFAULT_VALUE, $this->moduleName);
}
}
48 changes: 48 additions & 0 deletions modules/landingpage/forms/Admin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
/*=========================================================================
MIDAS Server
Copyright (c) Kitware SAS. 26 rue Louis Guérin. 69100 Villeurbanne, FRANCE
All rights reserved.
More information http://www.kitware.com
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0.txt
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=========================================================================*/

/** Admin form for the landingpage module. */
class Landingpage_Form_Admin extends Zend_Form
{
/** Initialize this form. */
public function init()
{
$this->setName('landingpage_admin');
$this->setMethod('POST');

$csrf = new Midas_Form_Element_Hash('csrf');
$csrf->setSalt('kUjBumZdEykrY8JHB88uzZjv');
$csrf->setDecorators(array('ViewHelper'));

$text = new Zend_Form_Element_Textarea(LANDINGPAGE_TEXT_KEY);
$text->setLabel('Landing Page Text');
$text->setRequired(true);
$text->addValidator('NotEmpty', true);
$text->setAttrib('cols', '120');
$text->setAttrib('rows', '100');

$this->addDisplayGroup(array($text), 'global');

$submit = new Zend_Form_Element_Submit('submit');
$submit->setLabel('Save');

$this->addElements(array($csrf, $text, $submit));
}
}
13 changes: 12 additions & 1 deletion modules/landingpage/models/dao/TextDao.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,20 @@
limitations under the License.
=========================================================================*/

/** Landingpage text dao */
/**
* Text DAO for the landingpage module.
*
* @method int getLandingpageId()
* @method void setLandingpageId(int $landingpageId)
* @method string getText()
* @method void setText(string $text)
* @package Modules\Landingpage\DAO
*/
class Landingpage_TextDao extends AppDao
{
/** @var string */
public $_model = 'Text';

/** @var string */
public $_module = 'landingpage';
}
1 change: 0 additions & 1 deletion modules/landingpage/public/css/config/config.index.css

This file was deleted.

39 changes: 0 additions & 39 deletions modules/landingpage/public/js/config/config.index.js

This file was deleted.

6 changes: 0 additions & 6 deletions modules/landingpage/public/scss/config/config.index.scss

This file was deleted.

29 changes: 29 additions & 0 deletions modules/landingpage/views/admin/index.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/*=========================================================================
MIDAS Server
Copyright (c) Kitware SAS. 26 rue Louis Guérin. 69100 Villeurbanne, FRANCE
All rights reserved.
More information http://www.kitware.com
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0.txt
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=========================================================================*/

$this->declareVars('form', 'pageTitle');
$this->headTitle($this->escape($this->pageTitle));
?>

<div class="viewMain">
<h1><?php echo $this->escape($this->pageTitle); ?></h1>
<?php echo $this->form; ?>
<p><a href="<?php echo $this->url(array('controller' => 'admin', 'action' => 'index'), 'default'); ?>#tabs-modules">&laquo; Back to Modules Administration</a></p>
</div>
Loading

0 comments on commit 6ccd95a

Please sign in to comment.