Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.
C# aspnet-corecsharpdockerdotnetecommerceecommerce-platformmongodbmulti-storemulti-vendornosqlonline-shopshoppingcart
Add Voice Navigation components
KrzysztofPajakbd4d7d3600ff
diff --git a/src/Web/Grand.Web/Components/VoiceNavigation.cs b/src/Web/Grand.Web/Components/VoiceNavigation.csnew file mode 100644index 000000000..393f5de6b--- /dev/null+++ b/src/Web/Grand.Web/Components/VoiceNavigation.cs@@ -0,0 +1,25 @@+using Grand.Domain.Stores;+using Grand.Web.Common.Components;+using Microsoft.AspNetCore.Mvc;++namespace Grand.Web.Components+{+ public class VoiceNavigationViewComponent : BaseViewComponent+ {+ private readonly StoreInformationSettings _storeInformationSettings;++ public VoiceNavigationViewComponent(+ StoreInformationSettings storeInformationSettings)+ {+ _storeInformationSettings = storeInformationSettings;+ }++ public IViewComponentResult Invoke()+ {+ if (!_storeInformationSettings.VoiceNavigation)+ return Content("");++ return View();+ }+ }+}diff --git a/src/Web/Grand.Web/Views/Shared/Components/VoiceNavigation/Default.cshtml b/src/Web/Grand.Web/Views/Shared/Components/VoiceNavigation/Default.cshtmlnew file mode 100644index 000000000..ddd4fc033--- /dev/null+++ b/src/Web/Grand.Web/Views/Shared/Components/VoiceNavigation/Default.cshtml@@ -0,0 +1,148 @@+@inject IWorkContext workContext+@{+ var lang = workContext.WorkingLanguage.LanguageCulture;+}+<template>+ <button id="voicePageButton"+ @@touchstart="voicenavigator.recording = true"+ @@touchcancel="voicenavigator.recording = false; $root.$emit('bv::hide::tooltip')"+ @@touchend="voicenavigator.recording = false; $root.$emit('bv::hide::tooltip')"+ @@mousedown="voicenavigator.recording = true"+ @@mouseup="voicenavigator.recording = false"+ @@mouseleave="voicenavigator.recording = false"+ ref="voicePageButton" type="button" v-bind:class="[{ focus: voicenavigator.recording }, 'btn btn-link voice-page-button']">+ <template v-if="voicenavigator.recording">+ <b-icon icon="mic" variant="info"></b-icon>+ </template>+ <template v-else>+ <b-icon icon="mic-mute" variant="danger"></b-icon>+ </template>+ </button>+ <b-alert :show="voicenavigator.recording"+ class="position-fixed fixed-top m-0 rounded-0"+ style="z-index: 2000;"+ :variant="voicenavigator.variant">+ <div class="recording-window">+ <div class="recording-aniamtion">+ <template v-if="voicenavigator.variant !== 'success'">+ <b-icon icon="mic" variant="info"></b-icon>+ </template>+ <template v-else>+ <b-icon icon="check" variant="success"></b-icon>+ </template>+ </div>+ <input type="text" placeholder="@Loc["voicenavigator.voice.placeholder"]" v-model="voicenavigator.transcript" class="form-control" readonly />+ </div>+ <small class="form-text text-muted w-100">@Loc["voicenavigator.voice.annotation"]</small>+ </b-alert>+</template>+<script asp-location="Footer" asp-order="300">+ var voicenavigator = new Vue({+ data: () => ({+ recording: false,+ recognition: null,+ lang: '@lang',+ commands: [+ {+ "name": "cart",+ "url": "/cart",+ "triggers": @Html.Raw(Json.Serialize(Loc["voicenavigator.commands.cart"].Value.Split(',')))+ },+ {+ "name": "blog",+ "url": "/blog",+ "triggers": @Html.Raw(Json.Serialize(Loc["voicenavigator.commands.blog"].Value.Split(',')))+ },+ {+ "name": "homepage",+ "url": "/",+ "triggers": @Html.Raw(Json.Serialize(Loc["voicenavigator.commands.homepage"].Value.Split(',')))+ },+ {+ "name": "wishlist",+ "url": "/wishlist",+ "triggers": @Html.Raw(Json.Serialize(Loc["voicenavigator.commands.wishlist"].Value.Split(',')))+ },+ {+ "name": "login",+ "url": "/login",+ "triggers": @Html.Raw(Json.Serialize(Loc["voicenavigator.commands.login"].Value.Split(',')))+ },+ {+ "name": "register",+ "url": "/register",+ "triggers": @Html.Raw(Json.Serialize(Loc["voicenavigator.commands.register"].Value.Split(',')))+ },+ {+ "name": "contactus",+ "url": "/contactus",+ "triggers": @Html.Raw(Json.Serialize(Loc["voicenavigator.commands.contactus"].Value.Split(',')))+ }+ ],+ transcript: "",+ variant: "info",+ micMessage: "@Loc["voicenavigator.voice.holdtospeak"]"+ }),+ methods: {+ startRecording() {+ this.recognition.start();+ },+ stopRecording() {+ this.recognition.stop();+ },+ },+ watch: {+ recording: function () {+ const speech = window.SpeechRecognition || window.webkitSpeechRecognition;+ if (speech) {+ if (this.recording) {+ this.recognition = new speech();+ this.recognition.continuous = true;+ this.recognition.lang = voicenavigator.lang;+ this.recognition.interimResults = false;+ this.recognition.maxAlternatives = 1;++ this.startRecording();++ this.micMessage = '@Loc["voicenavigator.voice.placeholder"]';++ this.recognition.addEventListener("result", resultOfSpeechRecognition);++ function resultOfSpeechRecognition(event) {+ if (voicenavigator.recording) {+ const current = event.resultIndex;+ const transcript = event.results[current][0].transcript;+ const concatTranscript = transcript.toLowerCase();++ var transcriptArray = concatTranscript.split(' ');++ voicenavigator.transcript = transcript;++ for (const [key, element] of Object.entries(voicenavigator.commands)) {+ const found = element.triggers.some(r => transcriptArray.includes(r));++ if (found) {+ voicenavigator.variant = "success"+ setTimeout(function () {+ window.location.replace(element.url);+ }, 300);+ break+ } else {+ voicenavigator.variant = "info"+ }+ }+ }+ }+ } else {+ this.stopRecording();+ this.transcript = "";+ this.variant = "info"+ this.micMessage = '@Loc["voicenavigator.voice.holdtospeak"]';+ }+ } else {+ this.micMessage = '@Loc["voicenavigator.voice.notsupported"]';+ }+ }+ }+ });+</script>\ No newline at end of filediff --git a/src/Web/Grand.Web/Views/Shared/_Layout.cshtml b/src/Web/Grand.Web/Views/Shared/_Layout.cshtmlindex 851eed253..6f480d135 100644--- a/src/Web/Grand.Web/Views/Shared/_Layout.cshtml+++ b/src/Web/Grand.Web/Views/Shared/_Layout.cshtml@@ -45,7 +45,7 @@}@RenderBody()@await Component.InvokeAsync("Widget", new { widgetZone = "content_after" })- <partial name="VoiceNavigator/VoiceNavigator" />+ <vc:voice-navigation></vc:voice-navigation></b-container>@await Component.InvokeAsync("Footer")<partial name="_Cookie" />