Skip to content

Commit

Permalink
Added combo2 for Acctount, DbService, Service
Browse files Browse the repository at this point in the history
 Db Deep coding
  • Loading branch information
SilverFire committed Apr 23, 2015
1 parent bbcab8d commit 94dd965
Show file tree
Hide file tree
Showing 5 changed files with 151 additions and 12 deletions.
43 changes: 43 additions & 0 deletions assets/combo2/Account.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace hipanel\modules\hosting\assets\combo2;

use hipanel\widgets\Combo2Config;
use yii\helpers\ArrayHelper;

/**
* Class Account
*/
class Account extends Combo2Config
{
/** @inheritdoc */
public $type = 'account';

/** @inheritdoc */
public $_primaryFilter = 'login_like';

/** @inheritdoc */
public $url = '/hosting/account/search';

public $_return = ['id', 'client', 'client_id', 'device', 'device_id'];

public $_rename = ['text' => 'login'];

public $_filter = [
'client' => 'client',
'server' => 'server'
];

/** @inheritdoc */
function getConfig ($config = []) {
$config = ArrayHelper::merge([
'clearWhen' => ['client', 'server'],
'affects' => [
'client' => 'client',
'server' => 'device'
]
], $config);

return parent::getConfig($config);
}
}
15 changes: 15 additions & 0 deletions assets/combo2/DbService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace hipanel\modules\hosting\assets\combo2;

/**
* Class DbService
*/
class DbService extends Service {
/** @inheritdoc */
public $type = 'dbService';

/** @inheritdoc */
public $softType = 'db';

}
58 changes: 58 additions & 0 deletions assets/combo2/Service.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace hipanel\modules\hosting\assets\combo2;
use hipanel\widgets\Combo2Config;
use yii\helpers\ArrayHelper;


/**
* Class Service
*/
class Service extends Combo2Config
{
/** @inheritdoc */
public $type = 'service';

/** @inheritdoc */
public $_primaryFilter = 'name_like';

/** @inheritdoc */
public $url = '/hosting/service/search';

/** @inheritdoc */
public $_return = ['id', 'client', 'client_id', 'device', 'device_id', 'seller', 'seller_id'];

/** @inheritdoc */
public $_rename = ['text' => 'name'];

/** @inheritdoc */
public $_filter = [
'client' => 'client',
'server' => 'server'
];

public $softType;

/** @inheritdoc */
function getConfig ($config = []) {
$config = ArrayHelper::merge([
'affects' => [
'seller' => 'seller',
'client' => 'client',
'server' => 'device'
],
'activeWhen' => [
'server'
]
], $config);

return parent::getConfig($config);
}

/** @inheritdoc */
public function getFilter () {
return ArrayHelper::merge(parent::getFilter(), [
'soft_type' => ['format' => $this->softType]
]);
}
}
9 changes: 7 additions & 2 deletions controllers/AccountController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

namespace hipanel\modules\hosting\controllers;

use hipanel\modules\hosting\models\Account;
use Yii;
use yii\base\Response;
use yii\web\NotFoundHttpException;

class AccountController extends \hipanel\base\CrudController
{
public function actionCreateFtp () {
Expand Down Expand Up @@ -34,7 +39,7 @@ public function actionSetPassword ($id) {
if ($model->load(Yii::$app->request->post()) && $model->validate() && $model->save()) {
Yii::$app->getSession()->addFlash('success', [
'title' => $model->login,
'text' => \Yii::t('app', 'Password changing task has been successfully added to queue'),
'text' => Yii::t('app', 'Password changing task has been successfully added to queue'),
]);

return $this->redirect(['view', 'id' => $model->id]);
Expand All @@ -46,7 +51,7 @@ public function actionSetPassword ($id) {

/**
* @param $id
* @return string|yii\web\Response
* @return string|Response
* @throws NotFoundHttpException
*/
public function actionSetAllowedIps ($id) {
Expand Down
38 changes: 28 additions & 10 deletions controllers/DBController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,25 @@ public function behaviors () {
}

public function actionCreate () {
$model = new Db(['scenario' => 'create']);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
$model = $this->newModel(['scenario' => 'create']);

return $this->perform([
'success' => [
'result' => [
'POST html' => ['redirect', function ($m) { return $m->id; }, 'addFlash' => true],
'POST pjax' => [
'action',
['view', function ($m) { return $m->id; }],
'setUrl' => function ($m) { return ['view', 'id' => $m->id]; },
'addFlash' => true
]
]
],
'result' => [
'GET html' => ['render', ['create', ['model' => $model]]]
],
]);

return $this->render('create', ['model' => $model]);
}

public function actionDelete () {
Expand Down Expand Up @@ -61,7 +74,7 @@ public function actionDelete () {
public function actionSetPassword () {
return $this->perform([
'result' => [ ///
'POST pjax' => ['action', ['view', function ($model) { return ['id' => $model->id]; }], 'addFlash' => true]
'POST pjax' => ['action', ['view', function ($model) { return ['id' => $model->id]; }], 'addFlash' => true]
],
]);
}
Expand All @@ -75,10 +88,15 @@ public function actionTruncate () {
'message' => Yii::t('app', 'Error while truncating DB'),
],
'result' => [
'pjax' => [
'action',
['view', function ($model) { return ['id' => $model->id]; }],
]
'pjax' => ['action', ['view', function ($model) { return ['id' => $model->id]; }]],
'html' => ['render', ['create', function ($model) { return ['id' => $model->id]; }]],
'html2' => ['render', ['create', ['id']]],
'POST html' => ['redirect', ['create']],
'POST html1' => ['redirect', function ($model) { return ['view', 'id' => $model->id]; }],
'POST html2' => ['redirect', ['view', ['id']]],
'POST html3' => ['return'],
'POST html4' => ['renderJson'],
'POST html5' => ['custom',],
],
'addFlash' => true
]);
Expand Down

0 comments on commit 94dd965

Please sign in to comment.