diff --git a/mirzaev/skillparts/system/assets/AppAsset.php b/mirzaev/skillparts/system/assets/AppAsset.php index 9aaaae4..724d5a8 100644 --- a/mirzaev/skillparts/system/assets/AppAsset.php +++ b/mirzaev/skillparts/system/assets/AppAsset.php @@ -9,6 +9,7 @@ namespace app\assets; use yii\web\AssetBundle; +use yii\web\View; /** * Main application asset bundle. @@ -31,15 +32,18 @@ class AppAsset extends AssetBundle ]; public $js = [ 'https://kit.fontawesome.com/d7e922c226.js', - 'https://code.jquery.com/jquery-3.5.1.min.js', 'js/bootstrap/popper.min.js', 'js/bootstrap/bootstrap.min.js', 'https://cdn.jsdelivr.net/bxslider/4.1.1/jquery.bxslider.min.js', 'https://unpkg.com/cookielib/src/cookie.min.js', 'js/menu.js', 'js/account.js', + 'js/search.js', 'js/reinitialization.js' ]; + public $jsOptions = [ + // 'position' => View::POS_HEAD + ]; public $depends = [ 'yii\web\YiiAsset', // 'yii\bootstrap\BootstrapAsset' diff --git a/mirzaev/skillparts/system/config/db.php.example b/mirzaev/skillparts/system/config/db.php.example index c18864e..5216d07 100644 --- a/mirzaev/skillparts/system/config/db.php.example +++ b/mirzaev/skillparts/system/config/db.php.example @@ -3,7 +3,7 @@ use ArangoDBClient\ConnectionOptions; return [ - 'class' => '\explosivebit\arangodb\Connection', + 'class' => '\mirzaev\yii2\arangodb\Connection', 'connectionOptions' => [ ConnectionOptions::OPTION_DATABASE => '', ConnectionOptions::OPTION_ENDPOINT => 'tcp://127.0.0.1:8529', diff --git a/mirzaev/skillparts/system/controllers/AuthenticationController.php b/mirzaev/skillparts/system/controllers/AuthenticationController.php index c01fd83..e0987ac 100644 --- a/mirzaev/skillparts/system/controllers/AuthenticationController.php +++ b/mirzaev/skillparts/system/controllers/AuthenticationController.php @@ -45,7 +45,7 @@ class AuthenticationController extends Controller // Запись ответа $return = [ - 'nav' => (new AccountForm())->deauthenticationGenHtml(), + 'menu' => (new AccountForm())->deauthenticationGenHtml(), '_csrf' => Yii::$app->request->getCsrfToken() ]; diff --git a/mirzaev/skillparts/system/controllers/DeauthenticationController.php b/mirzaev/skillparts/system/controllers/DeauthenticationController.php index 8629794..bf51d08 100644 --- a/mirzaev/skillparts/system/controllers/DeauthenticationController.php +++ b/mirzaev/skillparts/system/controllers/DeauthenticationController.php @@ -44,7 +44,7 @@ class DeauthenticationController extends Controller // Ответа return [ - 'nav' => $model->authenticationGenHtml($this->renderPartial('/account', compact('model'))), + 'menu' => $model->authenticationGenHtml($this->renderPartial('/account', compact('model'))), 'main' => $this->renderPartial('/index'), 'redirect' => '/', '_csrf' => Yii::$app->request->getCsrfToken() diff --git a/mirzaev/skillparts/system/controllers/IdentificationController.php b/mirzaev/skillparts/system/controllers/IdentificationController.php index f5cf1bc..4deb421 100644 --- a/mirzaev/skillparts/system/controllers/IdentificationController.php +++ b/mirzaev/skillparts/system/controllers/IdentificationController.php @@ -24,7 +24,7 @@ class IdentificationController extends Controller // Запись ответа $return = [ - 'nav' => $model->authenticationGenHtml($this->renderPartial('/account', compact('model'))), + 'menu' => $model->authenticationGenHtml($this->renderPartial('/account', compact('model'))), '_csrf' => Yii::$app->request->getCsrfToken() ]; } else { @@ -35,7 +35,7 @@ class IdentificationController extends Controller // Запись ответа $return = [ - 'nav' => (new AccountForm())->deauthenticationGenHtml(), + 'menu' => (new AccountForm())->deauthenticationGenHtml(), '_csrf' => Yii::$app->request->getCsrfToken() ]; } diff --git a/mirzaev/skillparts/system/controllers/RegistrationController.php b/mirzaev/skillparts/system/controllers/RegistrationController.php index 4548ac2..63dbaf2 100644 --- a/mirzaev/skillparts/system/controllers/RegistrationController.php +++ b/mirzaev/skillparts/system/controllers/RegistrationController.php @@ -49,7 +49,7 @@ class RegistrationController extends Controller // Запись ответа $return = [ - 'nav' => (new AccountForm())->deauthenticationGenHtml(), + 'menu' => (new AccountForm())->deauthenticationGenHtml(), '_csrf' => Yii::$app->request->getCsrfToken() ]; diff --git a/mirzaev/skillparts/system/controllers/SearchController.php b/mirzaev/skillparts/system/controllers/SearchController.php new file mode 100644 index 0000000..8894b13 --- /dev/null +++ b/mirzaev/skillparts/system/controllers/SearchController.php @@ -0,0 +1,100 @@ +request->post('request') ?? Yii::$app->request->get('q'); + + if (Yii::$app->request->post('type') === 'product' || Yii::$app->request->get('type') === 'product') { + // Поиск по продуктам + + // Инициализация сессии + $session = Yii::$app->session; + $session->open(); + + // Инициализация ответа + $response = null; + + // Период пропуска запросов (в секундах) + $period = 1; + + // Запись времени последнего запроса и вычисление об истечении таймера + $timer = ($session['last_request'] ?? $session['last_request'] = time() + $period) - time(); + + if ($timer > 0) { + // Ожидание перед повторным запросом при условии что старых запросов нет + + Yii::$app->response->statusCode = 202; + + $return = [ + 'timer' => $timer, + 'search_line_window' => $this->renderPartial('/loading'), + '_csrf' => Yii::$app->request->getCsrfToken() + ]; + } else { + // Повторный запрос по истечению ожидания + + // Очистка времени последнего запроса + unset($session['last_request']); + + // + // Здесь запись истории запросов (в базе данных) + // + + if ($response = Product::search($request)) { + // Данные найдены + + // Запись ответа + $return = [ + 'search_line_window' => $this->renderPartial('/search/panel', compact('response')), + '_csrf' => Yii::$app->request->getCsrfToken() + ]; + + if ((int) Yii::$app->request->post('advanced')) { + // Полноценный поиск + + // Запись ответа + $return['main'] = $this->renderPartial('/search/index', compact('response')); + $return['search_line_window_hide'] = 1; + $return['redirect'] = '/search?type=product&q=' . $request; + } + } else { + // Данные не найдены + + Yii::$app->response->statusCode = 404; + } + } + + if (Yii::$app->request->isAjax) { + // AJAX-POST-запрос + + Yii::$app->response->format = Response::FORMAT_JSON; + + return $return ?? [ + 'search_line_window' => $this->renderPartial('/search/panel'), + '_csrf' => Yii::$app->request->getCsrfToken() + ]; + } else { + // GET-запрос + + return $this->render('/search/index', compact('response', 'timer')); + } + } + + if (Yii::$app->user->isGuest) { + return $this->render('/search/index', ['error_auth' => true]); + } else { + return $this->render('/search/index'); + } + } +} diff --git a/mirzaev/skillparts/system/models/Document.php b/mirzaev/skillparts/system/models/Document.php index 2158e16..6e379d1 100644 --- a/mirzaev/skillparts/system/models/Document.php +++ b/mirzaev/skillparts/system/models/Document.php @@ -3,7 +3,7 @@ namespace app\models; use Yii; -use explosivebit\arangodb\ActiveRecord; +use mirzaev\yii2\arangodb\ActiveRecord; abstract class Document extends ActiveRecord { diff --git a/mirzaev/skillparts/system/models/Edge.php b/mirzaev/skillparts/system/models/Edge.php index 7f4ffd5..b18950d 100644 --- a/mirzaev/skillparts/system/models/Edge.php +++ b/mirzaev/skillparts/system/models/Edge.php @@ -2,8 +2,6 @@ namespace app\models; -use explosivebit\arangodb\ActiveRecord; - abstract class Edge extends Document { public function attributes() diff --git a/mirzaev/skillparts/system/models/Product.php b/mirzaev/skillparts/system/models/Product.php index fc0ba04..0f8c06e 100644 --- a/mirzaev/skillparts/system/models/Product.php +++ b/mirzaev/skillparts/system/models/Product.php @@ -3,6 +3,7 @@ namespace app\models; use moonland\phpexcel\Excel; +use mirzaev\yii2\arangodb\Query; class Product extends Document { @@ -139,6 +140,11 @@ class Product extends Document return false; } + public static function search(string $text): array + { + return (new Query)->limit(10)->search('product_search', ['id' => '_key', 'catn' => 'catn'], ['catn' => $text], 1); + } + private static function writeEdgeBetweenGroup(string $from, string $to): bool { // Инициализация diff --git a/mirzaev/skillparts/system/views/layouts/main.php b/mirzaev/skillparts/system/views/layouts/main.php index c95eea4..8e557d3 100644 --- a/mirzaev/skillparts/system/views/layouts/main.php +++ b/mirzaev/skillparts/system/views/layouts/main.php @@ -39,7 +39,7 @@ AppAsset::register($this);
- +
@@ -47,11 +47,11 @@ AppAsset::register($this);