From c2afcfcc5ad71e3394443d1ae8f3b58f47dfc227 Mon Sep 17 00:00:00 2001 From: RedHood Date: Sun, 24 Jan 2021 16:25:08 +1000 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=B8=D1=81=D0=BA=20=D0=BF=D0=BE?= =?UTF-8?q?=20=D1=82=D0=BE=D0=B2=D0=B0=D1=80=D0=B0=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mirzaev/skillparts/system/assets/AppAsset.php | 6 +- .../skillparts/system/config/db.php.example | 2 +- .../controllers/AuthenticationController.php | 2 +- .../DeauthenticationController.php | 2 +- .../controllers/IdentificationController.php | 4 +- .../controllers/RegistrationController.php | 2 +- .../system/controllers/SearchController.php | 100 +++++++ mirzaev/skillparts/system/models/Document.php | 2 +- mirzaev/skillparts/system/models/Edge.php | 2 - mirzaev/skillparts/system/models/Product.php | 6 + .../skillparts/system/views/layouts/main.php | 17 +- mirzaev/skillparts/system/views/loading.php | 4 + .../skillparts/system/views/product/index.php | 9 +- .../skillparts/system/views/profile/index.php | 76 +++--- .../skillparts/system/views/search/index.php | 39 +++ .../skillparts/system/views/search/panel.php | 22 ++ mirzaev/skillparts/system/web/css/header.css | 1 + mirzaev/skillparts/system/web/css/loading.css | 15 ++ mirzaev/skillparts/system/web/css/main.css | 16 +- .../system/web/css/pages/product.css | 3 + .../system/web/css/pages/profile.css | 3 + .../system/web/css/pages/search.css | 3 + mirzaev/skillparts/system/web/debug.txt | 247 ++++++++++++++++++ mirzaev/skillparts/system/web/index.php | 4 +- mirzaev/skillparts/system/web/js/account.js | 48 ++-- mirzaev/skillparts/system/web/js/menu.js | 39 ++- .../system/web/js/reinitialization.js | 42 +-- mirzaev/skillparts/system/web/js/search.js | 123 +++++++++ 28 files changed, 715 insertions(+), 124 deletions(-) create mode 100644 mirzaev/skillparts/system/controllers/SearchController.php create mode 100644 mirzaev/skillparts/system/views/loading.php create mode 100644 mirzaev/skillparts/system/views/search/index.php create mode 100644 mirzaev/skillparts/system/views/search/panel.php create mode 100644 mirzaev/skillparts/system/web/css/loading.css create mode 100644 mirzaev/skillparts/system/web/css/pages/product.css create mode 100644 mirzaev/skillparts/system/web/css/pages/profile.css create mode 100644 mirzaev/skillparts/system/web/css/pages/search.css create mode 100644 mirzaev/skillparts/system/web/debug.txt create mode 100644 mirzaev/skillparts/system/web/js/search.js 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);