From b3669880cc159b50c6dcdfb4b8b40a4cde06df70 Mon Sep 17 00:00:00 2001 From: lukaskavouras Date: Fri, 16 Apr 2021 16:55:22 +0300 Subject: [PATCH] New admin functionality for changing pages dynamically --- controllers/AdministrationController.php | 91 ++++++++++++++- controllers/SiteController.php | 8 +- controllers/SoftwareController.php | 9 +- database_schema/migration_2.sql | 4 + models/Page.php | 58 ++++++++++ models/SystemConfiguration.php | 19 ++++ views/administration/add-page.php | 39 +++++++ views/administration/edit-page.php | 37 +++++++ views/administration/error_page_exist.php | 28 +++++ views/administration/manage-pages.php | 104 ++++++++++++++++++ views/administration/preview-page.php | 25 +++++ views/administration/system_configuration.php | 29 ++++- views/administration/view-page.php | 25 +++++ views/site/index.php | 17 +-- web/js/administration/add-edit-page.js | 9 ++ web/js/administration/manage-pages.js | 10 ++ 16 files changed, 483 insertions(+), 29 deletions(-) create mode 100644 database_schema/migration_2.sql create mode 100644 models/Page.php create mode 100644 views/administration/add-page.php create mode 100644 views/administration/edit-page.php create mode 100644 views/administration/error_page_exist.php create mode 100644 views/administration/manage-pages.php create mode 100644 views/administration/preview-page.php create mode 100644 views/administration/view-page.php create mode 100644 web/js/administration/add-edit-page.js create mode 100644 web/js/administration/manage-pages.js diff --git a/controllers/AdministrationController.php b/controllers/AdministrationController.php index 9f5c683..a2bc935 100644 --- a/controllers/AdministrationController.php +++ b/controllers/AdministrationController.php @@ -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; @@ -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; @@ -155,6 +157,7 @@ public function actionSystemConfiguration() { $configuration=SystemConfiguration::find()->one(); + $pages=Page::getPagesDropdown(); $no_configuration=false; if (empty($configuration)) { @@ -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]); + } diff --git a/controllers/SiteController.php b/controllers/SiteController.php index e280197..0c822b7 100644 --- a/controllers/SiteController.php +++ b/controllers/SiteController.php @@ -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; @@ -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]); } /** diff --git a/controllers/SoftwareController.php b/controllers/SoftwareController.php index 14d8bcf..0ed872b 100644 --- a/controllers/SoftwareController.php +++ b/controllers/SoftwareController.php @@ -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(); @@ -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]); } diff --git a/database_schema/migration_2.sql b/database_schema/migration_2.sql new file mode 100644 index 0000000..3eab5a6 --- /dev/null +++ b/database_schema/migration_2.sql @@ -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); \ No newline at end of file diff --git a/models/Page.php b/models/Page.php new file mode 100644 index 0000000..51c3225 --- /dev/null +++ b/models/Page.php @@ -0,0 +1,58 @@ + '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; + } +} diff --git a/models/SystemConfiguration.php b/models/SystemConfiguration.php index f281e12..ae0923f 100644 --- a/models/SystemConfiguration.php +++ b/models/SystemConfiguration.php @@ -49,6 +49,7 @@ public function rules() return [ [['admin_email'], 'string'], [['admin_email'], 'email'], + [['home_page', 'privacy_page','help_page'], 'integer'], ]; } @@ -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(); + } + } diff --git a/views/administration/add-page.php b/views/administration/add-page.php new file mode 100644 index 0000000..27d94da --- /dev/null +++ b/views/administration/add-page.php @@ -0,0 +1,39 @@ +title='Add new page'; +$this->registerJsFile('@web/js/administration/add-edit-page.js', ['depends' => [\yii\web\JqueryAsset::className()]] ); +$back_icon=''; +/* + * Users are able to view the name, version, start date, end date, mountpoint + * and running status of their previous software executions. + */ +?> +
+
+

title) ?>

+
+
+ 'btn btn-default']) ?> +
+
+ + + +field($model, 'title') ?> + +field($model, 'content')->textarea(['rows'=>30,'id'=>'content-area']) ?> + + +
+
Submit', ['class' => 'btn btn-primary']) ?>
+
Cancel', ['/project/index'], ['class'=>'btn btn-default']) ?>
+
Preview', "javascript:void(0);", ['class'=>'btn btn-secondary preview-btn']) ?>
+ +
+ + + diff --git a/views/administration/edit-page.php b/views/administration/edit-page.php new file mode 100644 index 0000000..3ed6628 --- /dev/null +++ b/views/administration/edit-page.php @@ -0,0 +1,37 @@ +title="Edit page \"$page->title\""; +$this->registerJsFile('@web/js/administration/add-edit-page.js', ['depends' => [\yii\web\JqueryAsset::className()]] ); +$back_icon=''; +/* + * Users are able to view the name, version, start date, end date, mountpoint + * and running status of their previous software executions. + */ +?> +
+
+

title) ?>

+
+
+ 'btn btn-default']) ?> +
+
+ + + +field($page, 'content')->textarea(['rows'=>30,'id'=>'content-area']) ?> + + +
+
Submit', ['class' => 'btn btn-primary']) ?>
+
Cancel', ['/administration/index'], ['class'=>'btn btn-default']) ?>
+
Preview', "javascript:void(0);", ['class'=>'btn btn-secondary preview-btn']) ?>
+ +
+ + + diff --git a/views/administration/error_page_exist.php b/views/administration/error_page_exist.php new file mode 100644 index 0000000..3a8cdb2 --- /dev/null +++ b/views/administration/error_page_exist.php @@ -0,0 +1,28 @@ +title="Authorization error"; + +$back_icon=''; + +Headers::begin() ?> +"Page does not exist.", + 'buttons'=> + [ + ['fontawesome_class'=>$back_icon,'name'=> 'Back', 'action'=> ['/administration/manage-pages'], 'type'=>'a', 'options'=>['class'=>'btn btn-default'] ], + + ] +]) +?> + + + + +
+

This page does not exist.

+
diff --git a/views/administration/manage-pages.php b/views/administration/manage-pages.php new file mode 100644 index 0000000..7b2f7c1 --- /dev/null +++ b/views/administration/manage-pages.php @@ -0,0 +1,104 @@ +title="Manage pages"; + +echo Html::cssFile('@web/css/project/project_details.css'); +$this->registerJsFile('@web/js/administration/manage-pages.js', ['depends' => [\yii\web\JqueryAsset::className()]] ); + + +$back_icon=''; +$add_icon=''; +$view_icon=''; +$delete_icon=''; +$edit_icon='' +/* + * Users are able to view the name, version, start date, end date, mountpoint + * and running status of their previous software executions. + */ +?> +
+
+

title) ?>

+
+
+ 'btn btn-default']) ?> +
+
+ +
 
+'btn btn-primary']) ?> +
 
+ +

No pages available yet.

+ +
+ + + + + + + + + + + + + +
Title
title?> + $page->id],['class'=>'btn btn-primary', 'title'=>'Preview'])?> + $page->id],['class'=>'btn btn-warning','title'=>'Edit'])?> + 'btn btn-danger delete-button','title'=>'Delete'])?> + id,['class'=>'hidden_page_id'])?> +
+
+ + + \ No newline at end of file diff --git a/views/administration/preview-page.php b/views/administration/preview-page.php new file mode 100644 index 0000000..b2f3a9b --- /dev/null +++ b/views/administration/preview-page.php @@ -0,0 +1,25 @@ +title="View page \"$page->title\""; + +$back_icon=''; + +Headers::begin() ?> +"$page->title", + 'buttons'=> + [ + ['fontawesome_class'=>$back_icon,'name'=> 'Back', 'action'=> ['/administration/manage-pages'], 'type'=>'a', 'options'=>['class'=>'btn btn-default'] ], + + ] +]) +?> + + + +content?> diff --git a/views/administration/system_configuration.php b/views/administration/system_configuration.php index dc3c734..73fb62d 100644 --- a/views/administration/system_configuration.php +++ b/views/administration/system_configuration.php @@ -26,8 +26,11 @@ use yii\bootstrap\NavBar; use yii\bootstrap\Nav; use yii\helpers\Url; + use yii\widgets\ActiveForm; -use app\components\Headers; +use app\components\Headers; +use app\components\MagicSearchBox; +use webvimark\modules\UserManagement\models\User as Userw; @@ -38,7 +41,8 @@ $back_button=' '; $submit_button=''; - +echo Html::CssFile('@web/css/site/configure.css'); +$this->registerJsFile('@web/js/site/configure.js', ['depends' => [\yii\web\JqueryAsset::className()]] ); Headers::begin() ?>   -

Administration Email

-
- field($configuration, 'admin_email')->textInput()->label('')?> + +
+

Administration Email

+
+ field($configuration, 'admin_email')->textInput()->label('')?> +
+
+ field($configuration,'home_page')->dropDownList($pages,['prompt'=>'Please select a page', 'disabled'=>(empty($pages))? true : false ])?> + field($configuration,'help_page')->dropDownList($pages,['prompt'=>'Please select a page', 'disabled'=>(empty($pages))? true : false ])?> + 'btn btn-secondary']) ?> +
+
 
 
@@ -68,3 +81,9 @@ ?> + + + + + + \ No newline at end of file diff --git a/views/administration/view-page.php b/views/administration/view-page.php new file mode 100644 index 0000000..b2f3a9b --- /dev/null +++ b/views/administration/view-page.php @@ -0,0 +1,25 @@ +title="View page \"$page->title\""; + +$back_icon=''; + +Headers::begin() ?> +"$page->title", + 'buttons'=> + [ + ['fontawesome_class'=>$back_icon,'name'=> 'Back', 'action'=> ['/administration/manage-pages'], 'type'=>'a', 'options'=>['class'=>'btn btn-default'] ], + + ] +]) +?> + + + +content?> diff --git a/views/site/index.php b/views/site/index.php index 494c155..2a92309 100644 --- a/views/site/index.php +++ b/views/site/index.php @@ -32,22 +32,11 @@ /* @var $this yii\web\View */ $this->title = 'SCHeMa scheduler'; -?> -
-
- - -
-
-

Scheduling scientific containers on a cluster of heterogeneous machines

-

"btn btn-lg btn-success"])?>

-
- -
+ +echo $page->content; +?> -
-
diff --git a/web/js/administration/add-edit-page.js b/web/js/administration/add-edit-page.js new file mode 100644 index 0000000..c1432c9 --- /dev/null +++ b/web/js/administration/add-edit-page.js @@ -0,0 +1,9 @@ +$(document).ready(function(){ + + $(".preview-btn").click(function(){ + var content=$("#content-area").val(); + + var newWindow = window.open("", "MsgWindow", "width=1200,height=800"); + newWindow.document.write('
' + content + '
'); + }); +}) \ No newline at end of file diff --git a/web/js/administration/manage-pages.js b/web/js/administration/manage-pages.js new file mode 100644 index 0000000..0a17949 --- /dev/null +++ b/web/js/administration/manage-pages.js @@ -0,0 +1,10 @@ +$(document).ready(function(){ + $(".delete-button").click(function(){ + var hidden=$(this).parent().children('.hidden_page_id'); + var id=hidden.val(); + + var modal=$('#delete-modal-' + id); + + modal.modal(); + }); +}) \ No newline at end of file