Commit 37ea8297 by Junaid Rahman pv

bug fixing

parent 5975a46b
......@@ -70,6 +70,16 @@ class DistrictController extends Controller
$states = ArrayHelper::map(State::find()->all(), 'id', 'name');
if ($model->load(Yii::$app->request->post()) && $model->save()) {
Yii::$app->getSession()->setFlash('districtCreate', [
'type' => 'success',
'duration' => 5000,
'icon' => 'fa fa-map',
'message' => ' New District added',
'showSeparator' => true,
'title' => ' District',
'positonY' => 'top',
'positonX' => 'right'
]);
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', [
......
......@@ -66,6 +66,16 @@ class StateController extends Controller
$model = new State();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
Yii::$app->getSession()->setFlash('stateCreate', [
'type' => 'success',
'duration' => 5000,
'icon' => 'fa fa-map',
'message' => ' New State added',
'showSeparator' => true,
'title' => ' State',
'positonY' => 'top',
'positonX' => 'right'
]);
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', [
......
......@@ -72,11 +72,11 @@ class CategoryController extends Controller
Yii::$app->getSession()->setFlash('success', [
'type' => 'success',
'duration' => 5000,
'icon' => 'fa fa-envira',
'message' => 'New Theme Category Created! ',
'icon' => 'fa fa-sitemap',
'message' => 'New Category '.$model->name.' is Created! ',
'title' => 'Category',
'positonY' => 'top',
'positonX' => 'right'
'positonX' => 'center'
]);
return $this->redirect(['files', 'id' => $model->id]);
}
......@@ -99,7 +99,16 @@ class CategoryController extends Controller
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save() && $model->validate()) {
return $this->redirect(['view', 'id' => $model->id]);
Yii::$app->getSession()->setFlash('success', [
'type' => 'success',
'duration' => 5000,
'icon' => 'fa fa-sitemap',
'message' => 'Category '. $model->name .' Updated! ',
'title' => 'Category',
'positonY' => 'top',
'positonX' => 'right'
]);
return $this->redirect(['files', 'id' => $model->id]);
}
return $this->render('update', [
......@@ -139,7 +148,6 @@ class CategoryController extends Controller
if (Model::loadMultiple($models, Yii::$app->request->post())) {
$deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($models, 'id', 'id')));
if (Model::validateMultiple($models)) {
$transaction = \Yii::$app->db->beginTransaction();
......@@ -159,15 +167,6 @@ class CategoryController extends Controller
if ($flag) {
$transaction->commit();
Yii::$app->getSession()->setFlash('success', [
'type' => 'success',
'duration' => 5000,
'icon' => 'fa fa-file',
'message' => 'New File is added to Category Files list! ',
'title' => 'Category Files',
'positonY' => 'top',
'positonX' => 'right'
]);
}
} catch (Exception $e) {
$transaction->rollBack();
......
......@@ -73,7 +73,16 @@ class ThemeController extends Controller
$model = new Theme();
$model->status = $model::STATUS_ACTIVE;
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
Yii::$app->getSession()->setFlash('success', [
'type' => 'success',
'duration' => 5000,
'icon' => 'fa fa-envira',
'message' => 'New Theme '.$model->name.' is Created! ',
'title' => ' Theme',
'positonY' => 'top',
'positonX' => 'center'
]);
return $this->redirect(['files', 'id' => $model->id]);
}
return $this->render('create', [
'model' => $model,
......@@ -94,6 +103,15 @@ class ThemeController extends Controller
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
Yii::$app->getSession()->setFlash('success', [
'type' => 'success',
'duration' => 5000,
'icon' => 'fa fa-envira',
'message' => 'Theme '. $model->name .' Updated! ',
'title' => 'Theme',
'positonY' => 'top',
'positonX' => 'right'
]);
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('update', [
......
......@@ -4,7 +4,6 @@ namespace backend\modules\theme\controllers;
use common\models\ThemeFiles;
use yii;
use common\models\Theme;
use yii\web\NotFoundHttpException;
use yii\web\UploadedFile;
......@@ -14,6 +13,7 @@ class ThemeFileController extends \yii\web\Controller
{
return $this->render('index');
}
public function actionUpload()
{
$model = new ThemeFiles();
......@@ -24,37 +24,91 @@ class ThemeFileController extends \yii\web\Controller
// the following data will return an array
$theme_file = UploadedFile::getInstance($model, 'file');
$model->file = $theme_file;
$ext = $model->file->extension;
$allowed = array('js', 'css', 'html');
if (in_array($ext, $allowed)) {
// the path to save file,
$folderPath = yii::getAlias('@storage/private/theme-assets/') .$model->theme_code;
if ( ! is_dir($folderPath)) {
$folderPath = yii::getAlias('@storage/private/theme-assets/') . $model->theme_code;
if (!is_dir($folderPath)) {
mkdir($folderPath);
}
$path = $folderPath.'/'.$model->file_code;
$path = $folderPath . '/' . $model->file_code;
if ($model->save(false)) {
$theme_file->saveAs($path);
$model->file->saveAs($path);
Yii::$app->getSession()->setFlash($model->file_code, [
'type' => 'warning',
'duration' => 4000,
'icon' => 'fa fa-file',
'message' => ''.$model->file_code.' Uploading...',
'showSeparator' => true,
'title' => ' File Upload',
'showProgressbar' => true,
'positonY' => 'top',
'positonX' => 'right'
]);
Yii::$app->getSession()->setFlash('success', [
'type' => 'success',
'duration' => 5000,
'icon' => 'fa fa-file',
'message' => ' File successfully Uploaded',
'showSeparator' => true,
'title' => ' File Upload',
'delay' => 4000,
'positonY' => 'top',
'positonX' => 'right'
]);
} else {
echo 'Error';
exit();
}
} else {
Yii::$app->getSession()->setFlash('alert', [
'type' => 'danger',
'duration' => 5000,
'icon' => 'fa fa-envira',
'message' => 'File type miss match! ',
'showSeparator' => true,
'title' => 'Error',
'showProgressbar' => true,
'positonY' => 'top',
'positonX' => 'right'
]);
}
}
return $this->redirect(['theme/index']);
return $this->redirect(['theme/files', 'id' => $model->theme_id]);
}
public function actionEditor($id)
{
public
function actionEditor(
$id
) {
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post())) {
$file = yii::getAlias('@storage/private/theme-assets/') .$model->theme_code . '/' .$model->file_code;
$file = yii::getAlias('@storage/private/theme-assets/') . $model->theme_code . '/' . $model->file_code;
file_put_contents($file, $model->fileContent);
Yii::$app->getSession()->setFlash('success', [
'type' => 'success',
'duration' => 5000,
'icon' => 'fa fa-file',
'message' => ' File Saved',
'showSeparator' => true,
'title' => ' Code Editor',
'positonY' => 'top',
'positonX' => 'right'
]);
}
return $this->render('editor',[
return $this->render('editor', [
'model' => $model,
]);
}
protected function findModel($id)
{
protected
function findModel(
$id
) {
if (($model = ThemeFiles::findOne($id)) !== null) {
return $model;
} else {
......
......@@ -45,19 +45,14 @@ $this->params['breadcrumbs'][] = $this->title;
[
'class' => 'yii\grid\ActionColumn',
'template' => '{update} {delete}',
'template' => '{update} {files} {delete}',
'buttons' => [
'download' => function ($url) {
return Html::a(
'<span class="glyphicon glyphicon-arrow-download"></span>',
$url,
[
'title' => 'Download',
'data-pjax' => '0',
'files' => function ($url) {
return Html::a('<span class="fa fa-file"></span>', $url, [
'title' => Yii::t('yii', 'Files'),
]);
}
]
);
},
],
],
],
]); ?>
......
......@@ -75,8 +75,7 @@ use wbraganca\dynamicform\DynamicFormWidget;
</div>
<div class="col-sm-4">
<?= $form->field($model, "[{$i}]type")->dropDownList($model::getfiles(),
['prompt' => '']) ?>
<?= $form->field($model, "[{$i}]type")->dropDownList($model::getfiles()) ?>
</div>
</div>
......
......@@ -65,7 +65,11 @@ use yii\bootstrap\Modal;
<div id='modalContent'<?= $value['id'] ?> style="text-align: center">
<?= $this->render('upload', ['model' => $modelFiles[0],]) ?>
<?= $this->render('upload',
[
'model' => $modelFiles[0],
'ThemeId' => $model->id,
]) ?>
</div>
......
......@@ -7,6 +7,7 @@
*/
/* @var $model common\models\ThemeFiles */
/* @var $ThemeId id of theme */
use yii\widgets\ActiveForm;
use yii\bootstrap\Html;
......@@ -26,18 +27,20 @@ use yii\bootstrap\Html;
<?= $form->field($model, 'file')->fileInput(['class' => 'btn btn-default']) ?>
</div>
<div class="col-md-11">
<?= $form->field($model, 'file_code')->hiddenInput(['value' => $model->file_code])->label(false) ?>
</div>
<div class="col-md-11">
<?= $form->field($model, 'theme_code')->hiddenInput(['value' => $model->theme_code])->label(false) ?>
</div>
<div class="col-md-11">
<?= $form->field($model, 'theme_id')->hiddenInput(['value' => $ThemeId])->label(false) ?>
</div>
</div>
......
......@@ -57,7 +57,7 @@ use yii\bootstrap\ActiveForm;
<div class="row">
<div class="col-md-6">
<?= $form->field($model, 'status')->dropDownList($model::statuses(), ['prompt' => '']) ?>
<?= $form->field($model, 'status')->dropDownList($model::statuses()) ?>
</div>
</div>
......
......@@ -19,7 +19,7 @@ $this->params['breadcrumbs'][] = $this->title;
<p>
<?= Html::a(Yii::t('backend', 'Create {modelClass}', [
'modelClass' => 'Theme',
]), ['create'], ['class' => 'btn btn-success']) ?>
]), ['create'], ['class' => 'btn btn-success']) ?>
</p>
<?= GridView::widget([
......@@ -44,11 +44,18 @@ $this->params['breadcrumbs'][] = $this->title;
// 'created_at',
// 'updated_at',
['class' => 'yii\grid\ActionColumn'
[
'class' => 'yii\grid\ActionColumn',
'template' => '{update} {files} {delete}',
'buttons' => [
'files' => function ($url) {
return Html::a('<span class="fa fa-file"></span>', $url, [
'title' => Yii::t('yii', 'Files'),
]);
}
]
],
// ['class' => 'yii\grid\ActionColumn',
// 'template' => '{update}{delete}'],
],
]); ?>
......
......@@ -342,12 +342,13 @@ $bundle = BackendAsset::register($this);
<?php foreach (Yii::$app->session->getAllFlashes() as $message):; ?>
<?= Growl::widget([
'type' => (!empty($message['type'])) ? $message['type'] : 'danger',
'title' => (!empty($message['title'])) ? Html::encode($message['title']) : 'Title Not Set!',
'title' => (!empty($message['title'])) ? Html::encode($message['title']) : 'Libromi Web!',
'icon' => (!empty($message['icon'])) ? $message['icon'] : 'fa fa-info',
'body' => (!empty($message['message'])) ? Html::encode($message['message']) : 'Message Not Set!',
'body' => (!empty($message['message'])) ? Html::encode($message['message']) : 'Welcome to Libromi Web!',
'showSeparator' => true,
'delay' => 1, //This delay is how long before the message shows
'delay' => (!empty($message['delay'])) ? Html::encode($message['delay']) : 1, //This delay is how long before the message shows
'pluginOptions' => [
'showProgressbar' => (!empty($message['showProgressbar'])) ? Html::encode($message['showProgressbar']) : false,
'delay' => (!empty($message['duration'])) ? $message['duration'] : 3000, //This delay is how long the message shows for
'placement' => [
'from' => (!empty($message['positonY'])) ? $message['positonY'] : 'top',
......
......@@ -40,13 +40,13 @@ class m160830_105840_category extends Migration
$this->createIndex('idx_category_files_code', '{{%category_files}}', 'code');
$this->createIndex('idx_category_files_name', '{{%category_files}}', 'name');
$this->addForeignKey('fk_category', '{{%category_files}}', 'category_id', '{{%category}}', 'id', 'RESTRICT',
'RESTRICT');
$this->addForeignKey('fk_category_files_category', '{{%category_files}}', 'category_id', '{{%category}}', 'id', 'cascade',
'cascade');
}
public function safeDown()
{
$this->dropForeignKey('fk_category', '{{%category_files}}');
$this->dropForeignKey('fk_category_files_category', '{{%category_files}}');
$this->dropIndex('idx_category_files_name', '{{%category_files}}');
$this->dropIndex('idx_category_files_code', '{{%category_files}}');
......
......@@ -137,4 +137,5 @@ class Category extends \yii\db\ActiveRecord
];
}
}
......@@ -93,4 +93,5 @@ class CategoryFiles extends \yii\db\ActiveRecord
self::TYPE_HTML_BLOCK => Yii::t('common', 'HTML BLOCK'),
];
}
}
......@@ -27,6 +27,10 @@ class ThemeFiles extends \yii\db\ActiveRecord
*/
public $file;
/*
* @var theme_id using to render file page
*/
public $theme_id;
/*
* @var file upload
*/
public $fileContent;
......@@ -56,10 +60,10 @@ class ThemeFiles extends \yii\db\ActiveRecord
return [
[['theme_code', 'file_code','file'], 'required'],
[['theme_code', 'file_code','fileContent'], 'string'],
[['created_at', 'updated_at'], 'integer'],
[['created_at', 'updated_at','theme_id'], 'integer'],
[['file_code'], 'exist', 'skipOnError' => true, 'targetClass' => CategoryFiles::className(), 'targetAttribute' => ['file_code' => 'id']],
[['theme_code'], 'exist', 'skipOnError' => true, 'targetClass' => Theme::className(), 'targetAttribute' => ['theme_code' => 'id']],
[['file'],'file'],
[['file'],'file','skipOnEmpty' => false, 'extensions' => 'js,css,html'],
];
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment