From 025c9abc9047ac3ebd4d99f721952ed755577cb5 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Tue, 4 Apr 2017 18:54:17 +0300 Subject: [PATCH] Working on speech rec --- app/Ninja/Intents/BaseIntent.php | 11 +++++++ app/Ninja/Intents/WebApp/NavigateToIntent.php | 29 +++++++++++++++++++ .../partials/speech_recognition.blade.php | 5 ++-- 3 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 app/Ninja/Intents/WebApp/NavigateToIntent.php diff --git a/app/Ninja/Intents/BaseIntent.php b/app/Ninja/Intents/BaseIntent.php index 0c08c694847e..0e6e136ced64 100644 --- a/app/Ninja/Intents/BaseIntent.php +++ b/app/Ninja/Intents/BaseIntent.php @@ -73,6 +73,17 @@ class BaseIntent return new $className($state, $data); } + protected function getField($field) + { + foreach ($this->data->entities as $entity) { + if ($entity->type === $field) { + return $entity->entity; + } + } + + return false; + } + public function process() { throw new Exception(trans('texts.intent_not_supported')); diff --git a/app/Ninja/Intents/WebApp/NavigateToIntent.php b/app/Ninja/Intents/WebApp/NavigateToIntent.php new file mode 100644 index 000000000000..ddb123830ec0 --- /dev/null +++ b/app/Ninja/Intents/WebApp/NavigateToIntent.php @@ -0,0 +1,29 @@ +getField('Location'); + $location = str_replace(' ', '_', $location); + + $map = [ + 'report' => 'reports', + ]; + + if (isset($map[$location])) { + $location = $map[$location]; + } + + if (in_array($location, array_merge(Account::$basicSettings, Account::$advancedSettings))) { + $location = '/settings/' . $location; + } + + return redirect($location); + } +} diff --git a/resources/views/partials/speech_recognition.blade.php b/resources/views/partials/speech_recognition.blade.php index 3c7b3dc585d2..903a9be74415 100644 --- a/resources/views/partials/speech_recognition.blade.php +++ b/resources/views/partials/speech_recognition.blade.php @@ -134,7 +134,6 @@ recognition.onend = function() { recognizing = false; $('.fa-microphone').show(); - $('#search').val(''); if (ignore_onend) { return; } @@ -174,8 +173,8 @@ function onMicrophoneClick() { //$('#search').val('create new invoice for edgar a po number of 1234'); - $('#search').val('create a task for edgar'); - //$('#search').val('show me all vendors'); + //$('#search').val('create a task for edgar'); + $('#search').val('go to localization'); $('#search-form').submit(); return;