1
0

Added CRUD for Logs

This commit is contained in:
2014-06-06 19:31:05 +02:00
parent 53211ea359
commit 4b9310d69c
21 changed files with 811 additions and 479 deletions

View File

@@ -19,7 +19,7 @@ class UserIdentity extends CUserIdentity
{
$connection = Yii::app()->db;
$command=$connection->createCommand("SELECT SValue FROM othervalues WHERE Name = 'AdminPassword'");
$command=$connection->createCommand("SELECT SValue FROM {{othervalues}} WHERE Name = 'AdminPassword'");
$pw = $command->queryScalar();
$users=array(

View File

@@ -68,8 +68,8 @@ return ArrayX::merge(
'programs/' => 'programs/index',
'programs/view/<id>' => 'programs/view',
'log' => ['msmain/log', 'defaultParams' => ['logid' => '-1']],
'log/<logid:[0-9]+>' => ['msmain/log', 'defaultParams' => ['logid' => '-1']],
'log/' => ['log/index', 'defaultParams' => ['logid' => '-1']],
'log/<logid:[0-9]+>' => ['log/index', 'defaultParams' => ['logid' => '-1']],
'downloads/details.php' => 'programs/index', // Compatibility
'downloads/downloads.php' => 'programs/index', // Compatibility

View File

@@ -0,0 +1,195 @@
<?php
class LogController extends MsController
{
public $layout='//layouts/column2';
public $menu=array();
/**
* @return array action filters
*/
public function filters()
{
return array(
'accessControl', // perform access control for CRUD operations
'postOnly + delete', // we only allow deletion via POST request
);
}
/**
* Specifies the access control rules.
* This method is used by the 'accessControl' filter.
* @return array access control rules
*/
public function accessRules()
{
return array(
array('allow',
'actions'=>array('index', 'ajaxMarkdownPreview'),
'users'=>array('*'),
),
array('allow',
'actions'=>array('create','update','admin','delete','view'),
'users'=>array('admin'),
),
array('deny',
'users'=>array('*'),
),
);
}
/**
* Lists all models.
*/
public function actionIndex($logid)
{
$this->layout='//layouts/main';
$criteria = new CDbCriteria;
$criteria->order = "date DESC";
$all = Log::model()->findAll($criteria);
/* @var $all Log[] */
$this->render('index',
[
'logs' => $all,
'logid' => $logid,
]);
}
public function actionAjaxMarkdownPreview() {
if(Yii::app()->request->isAjaxRequest){
$this->renderPartial('_ajaxMarkdownPreview',
[
'content' => $_POST['content'],
],
false, true);
} else {
throw new CHttpException(400,'Invalid request. This is a Ajax only action.');
}
}
/**
* Displays a particular model.
* @param integer $id the ID of the model to be displayed
*/
public function actionView($id)
{
$this->render('view',array(
'model'=>$this->loadModel($id),
));
}
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model=new Log;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Log']))
{
$model->attributes=$_POST['Log'];
if($model->save())
$this->redirect(array('view','id'=>$model->ID));
}
$this->render('create',array(
'model'=>$model,
));
}
/**
* Updates a particular model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id the ID of the model to be updated
*/
public function actionUpdate($id)
{
$model=$this->loadModel($id);
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['Log']))
{
$model->attributes=$_POST['Log'];
if($model->save())
$this->redirect(array('view','id'=>$model->ID));
}
$this->render('update',array(
'model'=>$model,
));
}
/**
* Deletes a particular model.
* If deletion is successful, the browser will be redirected to the 'admin' page.
* @param integer $id the ID of the model to be deleted
* @throws CHttpException
*/
public function actionDelete($id)
{
if (Yii::app()->request->isPostRequest) {
// we only allow deletion via POST request
$this->loadModel($id)->delete();
// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
if (!isset($_GET['ajax'])) {
$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
}
} else {
throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');
}
}
/**
* Manages all models.
*/
public function actionAdmin()
{
$model=new Log('search');
$model->unsetAttributes(); // clear any default values
if(isset($_GET['Log']))
$model->attributes=$_GET['Log'];
$this->render('admin',array(
'model'=>$model,
));
}
/**
* Returns the data model based on the primary key given in the GET variable.
* If the data model is not found, an HTTP exception will be raised.
* @param integer $id the ID of the model to be loaded
* @return Log the loaded model
* @throws CHttpException
*/
public function loadModel($id)
{
$model=Log::model()->findByPk($id);
if($model===null)
throw new CHttpException(404,'The requested page does not exist.');
return $model;
}
/**
* Performs the AJAX validation.
* @param Log $model the model to be validated
*/
protected function performAjaxValidation($model)
{
if(isset($_POST['ajax']) && $_POST['ajax']==='log-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
}
}

View File

@@ -2,6 +2,38 @@
class MSMainController extends MSController
{
/**
* @return array action filters
*/
public function filters()
{
return array(
'accessControl',
);
}
/**
* Specifies the access control rules.
* This method is used by the 'accessControl' filter.
* @return array access control rules
*/
public function accessRules()
{
return array(
array('allow',
'actions'=>array('index', 'about', 'debugerror', 'error', 'login', 'logout'),
'users'=>array('*'),
),
array('allow',
'actions'=>array('admin'),
'users'=>array('admin'),
),
array('deny',
'users'=>array('*'),
),
);
}
public function actionIndex()
{
$criteria = new CDbCriteria;
@@ -77,7 +109,7 @@ class MSMainController extends MSController
public function actionLogin()
{
$model=new LoginForm;
$model = new LoginForm();
// if it is ajax validation request
if(isset($_POST['ajax']) && $_POST['ajax']==='login-form')
@@ -98,6 +130,11 @@ class MSMainController extends MSController
$this->render('login', array('model'=>$model));
}
public function actionAdmin()
{
$this->render('admin', array());
}
public function actionLogout()
{
Yii::app()->user->logout();
@@ -105,16 +142,6 @@ class MSMainController extends MSController
}
public function actionLog($logid) {
$criteria = new CDbCriteria;
$criteria->order = "date DESC";
$all = Log::model()->findAll($criteria);
/* @var $all Log[] */
$this->render('log',
[
'logs' => $all,
'logid' => $logid,
]);
}
}

View File

@@ -47,10 +47,10 @@
['label' => 'Programs', 'url' => '/programs/', 'active' => ($this->selectedNav === 'prog')],
['label' => '', 'items' => ProgramHelper::GetProgDropDownList(), 'htmlOptions' => ['class' => 'dropdown-append']],
['label' => 'About', 'url' => '/about', 'active' => ($this->selectedNav === 'about')],
['label' => '[[Log "'.Yii::app()->user->name.'" out]]', 'url' => '/logout', 'visible' => !Yii::app()->user->isGuest]
['label' => '[[Log "'.Yii::app()->user->name.'" out]]', 'url' => '/logout', 'visible' => !Yii::app()->user->isGuest, 'htmlOptions' => ['class' => 'cstm-main-navbar-highlight']]
],
],
MsHtml::navbarSearchForm('search', '',
MsHtml::navbarSearchForm('/search', '',
[
'class' => 'pull-right',
'placeholder' => 'Search',
@@ -89,10 +89,6 @@
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/vendor/jquery-1.9.1.min.js"><\/script>')</script>
<script src="<?php echo (YII_DEBUG ? 'bootstrap.js' : 'bootstrap.min.js') ?>"></script>
<script src="/js/plugins.js"></script>
<script src="/js/main.js"></script>
<script src="/javascript/scripts.js"></script>
</body>
</html>

View File

@@ -0,0 +1,7 @@
<?php
$this->beginWidget('CMarkdown');
echo $content;
$this->endWidget();

View File

@@ -0,0 +1,52 @@
<?php
/* @var $this LogController */
/* @var $model Log */
/* @var $form TbActiveForm */
?>
<div class="form">
<?php $form=$this->beginWidget('bootstrap.widgets.TbActiveForm', array(
'id'=>'log-form',
// Please note: When you enable ajax validation, make sure the corresponding
// controller action is handling ajax validation correctly.
// There is a call to performAjaxValidation() commented in generated controller code.
// See class documentation of CActiveForm for details on this.
'enableAjaxValidation'=>false,
)); ?>
<p class="help-block">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model); ?>
<?php echo $form->textFieldControlGroup($model,'date',array('span'=>5, 'value'=>date('Y-m-d'))); ?>
<?php echo $form->textAreaControlGroup($model,'title',array('rows'=>6,'span'=>8)); ?>
<?php echo $form->textAreaControlGroup($model,'content',array('rows'=>6,'span'=>8)); ?>
<?php echo MsHtml::ajaxButton ("Preview", CController::createUrl('log/ajaxMarkdownPreview'),
[
'type'=>'POST',
'data' => ['content'=> 'js: $("#Log_content").val()'],
'update' => '#markdownAjaxContent',
'error'=>'function(msg){alert("An error has happened");}',
]); ?>
<br>
<br>
<div class="well markdownOwner" id="markdownAjaxContent">
<?php $this->renderPartial('_ajaxMarkdownPreview', ['content' => $model->content, ], false, true); ?>
</div>
<div class="form-actions">
<?php echo MsHtml::submitButton($model->isNewRecord ? 'Create' : 'Save',array(
'color'=>MsHtml::BUTTON_COLOR_PRIMARY,
'size'=>MsHtml::BUTTON_SIZE_LARGE,
)); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->

View File

@@ -0,0 +1,28 @@
<?php
/* @var $this LogController */
/* @var $model Log */
/* @var $form CActiveForm */
?>
<div class="wide form">
<?php $form=$this->beginWidget('bootstrap.widgets.TbActiveForm', array(
'action'=>Yii::app()->createUrl($this->route),
'method'=>'get',
)); ?>
<?php echo $form->textFieldControlGroup($model,'ID',array('span'=>5)); ?>
<?php echo $form->textFieldControlGroup($model,'date',array('span'=>5)); ?>
<?php echo $form->textAreaControlGroup($model,'title',array('rows'=>6,'span'=>8)); ?>
<?php echo $form->textAreaControlGroup($model,'content',array('rows'=>6,'span'=>8)); ?>
<div class="form-actions">
<?php echo MsHtml::submitButton('Search', array('color' => MsHtml::BUTTON_COLOR_PRIMARY,));?>
</div>
<?php $this->endWidget(); ?>
</div><!-- search-form -->

View File

@@ -0,0 +1,25 @@
<?php
/* @var $this LogController */
/* @var $data Log */
?>
<div class="view">
<b><?php echo CHtml::encode($data->getAttributeLabel('ID')); ?>:</b>
<?php echo CHtml::link(CHtml::encode($data->ID),array('view','id'=>$data->ID)); ?>
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('date')); ?>:</b>
<?php echo CHtml::encode($data->date); ?>
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('title')); ?>:</b>
<?php echo CHtml::encode($data->title); ?>
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('content')); ?>:</b>
<?php echo CHtml::encode($data->content); ?>
<br />
</div>

View File

@@ -0,0 +1,58 @@
<?php
/* @var $this LogController */
/* @var $model Log */
$this->breadcrumbs=array(
'Logs'=>array('index'),
'Manage',
);
$this->menu=array(
array('label'=>'List Log', 'url'=>array('index')),
array('label'=>'Create Log', 'url'=>array('create')),
);
Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
$('.search-form').toggle();
return false;
});
$('.search-form form').submit(function(){
$('#log-grid').yiiGridView('update', {
data: $(this).serialize()
});
return false;
});
");
?>
<h1>Manage Logs</h1>
<p>
You may optionally enter a comparison operator (<b>&lt;</b>, <b>&lt;=</b>, <b>&gt;</b>, <b>&gt;=</b>, <b>
&lt;&gt;</b>
or <b>=</b>) at the beginning of each of your search values to specify how the comparison should be done.
</p>
<?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button btn')); ?>
<div class="search-form" style="display:none">
<?php $this->renderPartial('_search',array(
'model'=>$model,
)); ?>
</div><!-- search-form -->
<?php $this->widget('bootstrap.widgets.TbGridView',array(
'id'=>'log-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'ID',
'date',
'title',
'content',
array(
'class'=>'bootstrap.widgets.TbButtonColumn',
),
),
)); ?>

View File

@@ -0,0 +1,20 @@
<?php
/* @var $this LogController */
/* @var $model Log */
?>
<?php
$this->breadcrumbs=array(
'Logs'=>array('index'),
'Create',
);
$this->menu=array(
array('label'=>'List Log', 'url'=>array('index')),
array('label'=>'Manage Log', 'url'=>array('admin')),
);
?>
<h1>Create Log</h1>
<?php $this->renderPartial('_form', array('model'=>$model)); ?>

View File

@@ -0,0 +1,40 @@
<?php
/* @var $this MsMainController */
/* @var $logs Log[] */
/* @var $logid integer */
$this->pageTitle=Yii::app()->name;
$this->breadcrumbs=
[
'Log'
];
$this->selectedNav = '';
?>
<div class="container">
<?php echo MsHtml::pageHeader("Site-log", "Changelog and Blog for mikescher.de"); ?>
<div class="accordion" id="lca">
<?php
$i = 0;
foreach($logs as $logelem) { //TODO-MS Translate all log things to eng
$i++;
$this->widget('ExpandedLogHeader',
[
'date' => new DateTime($logelem->date),
'caption' => $logelem->title,
'content' => $logelem->content,
'collapseID' => $i,
'collapseOwner' => '#lca',
'collapseOpen' => ($logelem->ID == $logid),
]);
}
?>
</div>
</div>

View File

@@ -0,0 +1,23 @@
<?php
/* @var $this LogController */
/* @var $model Log */
?>
<?php
$this->breadcrumbs=array(
'Logs'=>array('index'),
$model->title=>array('view','id'=>$model->ID),
'Update',
);
$this->menu=array(
array('label'=>'List Log', 'url'=>array('index')),
array('label'=>'Create Log', 'url'=>array('create')),
array('label'=>'View Log', 'url'=>array('view', 'id'=>$model->ID)),
array('label'=>'Manage Log', 'url'=>array('admin')),
);
?>
<h1>Update Log <?php echo $model->ID; ?></h1>
<?php $this->renderPartial('_form', array('model'=>$model)); ?>

View File

@@ -0,0 +1,34 @@
<?php
/* @var $this LogController */
/* @var $model Log */
?>
<?php
$this->breadcrumbs=array(
'Logs'=>array('index'),
$model->title,
);
$this->menu=array(
array('label'=>'List Log', 'url'=>array('index')),
array('label'=>'Create Log', 'url'=>array('create')),
array('label'=>'Update Log', 'url'=>array('update', 'id'=>$model->ID)),
array('label'=>'Delete Log', 'url'=>'#', 'linkOptions'=>array('submit'=>array('delete','id'=>$model->ID),'confirm'=>'Are you sure you want to delete this item?')),
array('label'=>'Manage Log', 'url'=>array('admin')),
);
?>
<h1>View Log #<?php echo $model->ID; ?></h1>
<?php $this->widget('zii.widgets.CDetailView',array(
'htmlOptions' => array(
'class' => 'table table-striped table-condensed table-hover',
),
'data'=>$model,
'attributes'=>array(
'ID',
'date',
'title',
'content',
),
)); ?>

View File

@@ -1,5 +1,5 @@
<?php
/* @var $this SiteController */
/* @var $this MsMainController */
/* @var $error array */
$this->pageTitle=Yii::app()->name . ' - Error';

View File

@@ -1,5 +1,5 @@
<?php
/* @var $this SiteController */
/* @var $this MsMainController */
/* @var $error array */
$this->pageTitle=Yii::app()->name . ' - Error';

View File

@@ -1,40 +0,0 @@
<?php
/* @var $this MsMainController */
/* @var $logs Log[] */
/* @var $logid integer */
$this->pageTitle=Yii::app()->name;
$this->breadcrumbs=
[
'Log'
];
$this->selectedNav = '';
?>
<div class="container">
<?php echo MsHtml::pageHeader("Site-log", "Changelog and Blog for mikescher.de"); ?>
<div class="accordion" id="lca">
<?php
$i = 0;
foreach($logs as $logelem) {
$i++;
$this->widget('ExpandedLogHeader',
[
'date' => new DateTime($logelem->date),
'caption' => $logelem->title,
'content' => $logelem->content,
'collapseID' => $i,
'collapseOwner' => '#lca',
'collapseOpen' => ($logelem->ID == $logid),
]);
}
?>
</div>
</div>

View File

@@ -1,5 +1,5 @@
<?php
/* @var $this SiteController */
/* @var $this MsMainController */
/* @var $model LoginForm */
/* @var $form CActiveForm */