Skip to content

Commit

Permalink
Merge pull request #29 from lukaskavouras/master
Browse files Browse the repository at this point in the history
New admin functionality for changing pages dynamically
  • Loading branch information
zagganas authored Apr 16, 2021
2 parents 13f6810 + b366988 commit fb7b1bf
Show file tree
Hide file tree
Showing 16 changed files with 483 additions and 29 deletions.
91 changes: 90 additions & 1 deletion controllers/AdministrationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
namespace app\controllers;

use Yii;
use yii\helpers\Url;
use yii\filters\AccessControl;
use yii\web\Controller;
use yii\web\Response;
Expand All @@ -33,6 +34,7 @@
use app\models\ImageRequest;
use app\models\User;
use yii\data\Pagination;
use app\models\Page;
use app\models\Notification;
use app\models\UploadDatasetDefaults;
use app\models\SystemConfiguration;
Expand Down Expand Up @@ -155,6 +157,7 @@ public function actionSystemConfiguration()
{

$configuration=SystemConfiguration::find()->one();
$pages=Page::getPagesDropdown();
$no_configuration=false;
if (empty($configuration))
{
Expand All @@ -177,9 +180,95 @@ public function actionSystemConfiguration()
}


return $this->render('system_configuration', ['configuration'=>$configuration]);
return $this->render('system_configuration', ['configuration'=>$configuration, 'pages'=>$pages]);

}


public function actionManagePages()
{
$pages=Page::find()->all();

return $this->render('manage-pages',['pages'=>$pages]);

}

public function actionAddPage()
{
$model=new Page;
$form_params =
[
'action' => URL::to(['administration/add-page']),
'options' =>
[
'class' => 'add_page_form',
'id'=> "add_page_form"
],
'method' => 'POST'
];

if ($model->load(Yii::$app->request->post()) && $model->validate())
{
$model->save();
$this->redirect(['administration/manage-pages']);
}

return $this->render('add-page',['model'=>$model,'form_params'=>$form_params]);

}
public function actionEditPage($id)
{
$page=Page::find()->where(['id'=>$id])->one();

if (empty($page))
{
return $this->render('error_page_exist');
}

$form_params =
[
'action' => URL::to(['administration/edit-page', 'id'=>$id]),
'options' =>
[
'class' => 'edit_page_form',
'id'=> "edit_page_form"
],
'method' => 'POST'
];

if ($page->load(Yii::$app->request->post()) && $page->validate())
{
$page->save();
$this->redirect(['administration/manage-pages']);
}

return $this->render('edit-page',['page'=>$page,'form_params'=>$form_params]);
}
public function actionDeletePage($id)
{
$page=Page::find()->where(['id'=>$id])->one();

if (empty($page))
{
return $this->render('error_page_exist');
}

$page->delete();
$this->redirect(['administration/manage-pages']);


}
public function actionViewPage($id)
{
$page=Page::find()->where(['id'=>$id])->one();

if (empty($page))
{
return $this->render('error_page_exist');
}

return $this->render('view-page',['page'=>$page]);
}



Expand Down
8 changes: 7 additions & 1 deletion controllers/SiteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
use app\models\SoftwareRemove;
use app\models\ImageRequest;
use yii\helpers\Url;
use app\models\Page;
use app\models\SystemConfiguration;
use webvimark\modules\UserManagement\models\User as Userw;
use app\models\RunHistory;
use app\models\SoftwareInput;
Expand Down Expand Up @@ -99,7 +101,11 @@ public function actions()
*/
public function actionIndex()
{
return $this->render('index');
$config=SystemConfiguration::find()->one();
$id=$config->home_page;
$page=Page::find()->where(['id'=>$id])->one();

return $this->render('index',['page'=>$page]);
}

/**
Expand Down
9 changes: 1 addition & 8 deletions controllers/SoftwareController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1744,12 +1744,6 @@ public function actionDownloadRocrate($jobid)

public function actionRoCrateHistory()
{
// $query=RunHistory::find()->where(['username'=>$user])->orderBy(['start'=>SORT_DESC]);
// $count = $query->count();
// $pagination = new Pagination(['totalCount' => $count]);
// $results = $query->offset($pagination->offset)
// ->limit($pagination->limit)
// ->all();
$username=User::getCurrentUser()['username'];
$query=RoCrate::find()->orderBy(['date'=>SORT_DESC]);
$count = $query->count();
Expand Down Expand Up @@ -1777,8 +1771,7 @@ public function actionRoCrateHistory()
'date'=>$ro_crate->date, 'experiment_description'=>$ro_crate->experiment_description, 'public'=>$ro_crate->public, 'link'=>['software/download-rocrate', 'jobid'=>$ro_crate->jobid]];
}
}
// print_r($results_public);
// exit(0);

return $this->render('ro_crate_history', ['results_user'=>$results_user, 'results_public'=>$results_public, 'pagination'=>$pagination]);
}

Expand Down
4 changes: 4 additions & 0 deletions database_schema/migration_2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

ALTER TABLE system_configuration add column home_page integer, add column help_page integer;
INSERT INTO system_configuration (admin_email,home_page,help_page) values (null,null,null);
CREATE TABLE pages (id serial primary key, title text, content text);
58 changes: 58 additions & 0 deletions models/Page.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace app\models;

use Yii;

/**
* This is the model class for table "pages".
*
* @property int $id
* @property string $title
* @property string $body
*/
class Page extends \yii\db\ActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'pages';
}

/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['title', 'content'], 'string'],
];
}

/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'title' => 'Title',
'content' => 'Content',
];
}

public static function getPagesDropdown()
{
$pages=self::find()->all();

$result=[];
foreach ($pages as $page)
{
$result[$page->id]=$page->title;
}

return $result;
}
}
19 changes: 19 additions & 0 deletions models/SystemConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public function rules()
return [
[['admin_email'], 'string'],
[['admin_email'], 'email'],
[['home_page', 'privacy_page','help_page'], 'integer'],
];
}

Expand All @@ -60,6 +61,24 @@ public function attributeLabels()
return [
'id' => 'ID',
'admin_email' => 'Admin Email',
'home_page' => 'Home page',
'help_page' => 'Help page',
];
}


/**
* {@inheritdoc}
*/


public function updateDB()
{
Yii::$app->db->createCommand()->update('system_configuration',[
'admin_email'=>$this->admin_email,
'help_page'=>$this->help_page,
'home_page'=>$this->home_page,
], "TRUE")->execute();
}

}
39 changes: 39 additions & 0 deletions views/administration/add-page.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

use yii\helpers\Html;
use webvimark\modules\UserManagement\models\User;
use yii\widgets\ActiveForm;

$this->title='Add new page';
$this->registerJsFile('@web/js/administration/add-edit-page.js', ['depends' => [\yii\web\JqueryAsset::className()]] );
$back_icon='<i class="fas fa-arrow-left"></i>';
/*
* Users are able to view the name, version, start date, end date, mountpoint
* and running status of their previous software executions.
*/
?>
<div class='title row'>
<div class="col-md-11">
<h1><?= Html::encode($this->title) ?></h1>
</div>
<div class="col-md-1 float-right">
<?= Html::a("$back_icon Back", ['/administration/manage-pages'], ['class'=>'btn btn-default']) ?>
</div>
</div>

<?php $form = ActiveForm::begin($form_params); ?>

<?= $form->field($model, 'title') ?>

<?= $form->field($model, 'content')->textarea(['rows'=>30,'id'=>'content-area']) ?>


<div class="row">
<div class="col-md-1"><?= Html::submitButton('<i class="fas fa-check"></i> Submit', ['class' => 'btn btn-primary']) ?></div>
<div class="col-md-1"><?= Html::a('<i class="fas fa-times"></i> Cancel', ['/project/index'], ['class'=>'btn btn-default']) ?></div>
<div class="col-md-1"><?= Html::a('<i class="fas fa-eye"></i> Preview', "javascript:void(0);", ['class'=>'btn btn-secondary preview-btn']) ?></div>

</div>

<?php ActiveForm::end(); ?>

37 changes: 37 additions & 0 deletions views/administration/edit-page.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

use yii\helpers\Html;
use webvimark\modules\UserManagement\models\User;
use yii\widgets\ActiveForm;

$this->title="Edit page \"$page->title\"";
$this->registerJsFile('@web/js/administration/add-edit-page.js', ['depends' => [\yii\web\JqueryAsset::className()]] );
$back_icon='<i class="fas fa-arrow-left"></i>';
/*
* Users are able to view the name, version, start date, end date, mountpoint
* and running status of their previous software executions.
*/
?>
<div class='title row'>
<div class="col-md-11">
<h1><?= Html::encode($this->title) ?></h1>
</div>
<div class="col-md-1 float-right">
<?= Html::a("$back_icon Back", ['/administration/manage-pages'], ['class'=>'btn btn-default']) ?>
</div>
</div>

<?php $form = ActiveForm::begin($form_params); ?>

<?= $form->field($page, 'content')->textarea(['rows'=>30,'id'=>'content-area']) ?>


<div class="row">
<div class="col-md-1"><?= Html::submitButton('<i class="fas fa-check"></i> Submit', ['class' => 'btn btn-primary']) ?></div>
<div class="col-md-1"><?= Html::a('<i class="fas fa-times"></i> Cancel', ['/administration/index'], ['class'=>'btn btn-default']) ?></div>
<div class="col-md-1"><?= Html::a('<i class="fas fa-eye"></i> Preview', "javascript:void(0);", ['class'=>'btn btn-secondary preview-btn']) ?></div>

</div>

<?php ActiveForm::end(); ?>

28 changes: 28 additions & 0 deletions views/administration/error_page_exist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use yii\helpers\Html;
use app\components\Headers;

echo Html::CssFile('@web/css/project/vm-details.css');

$this->title="Authorization error";

$back_icon='<i class="fas fa-arrow-left"></i>';

Headers::begin() ?>
<?php echo Headers::widget(
['title'=>"Page does not exist.",
'buttons'=>
[
['fontawesome_class'=>$back_icon,'name'=> 'Back', 'action'=> ['/administration/manage-pages'], 'type'=>'a', 'options'=>['class'=>'btn btn-default'] ],

]
])
?>
<?Headers::end()?>



<div class="row">
<div class="col-md-12"><h3>This page does not exist.</h3></div>
</div>
Loading

0 comments on commit fb7b1bf

Please sign in to comment.