public void TryFormatForView_FormatsAccordingToType()
        {
            TestViewModel    viewmodel = new TestViewModel();
            Mock <IHtmlView> viewMock  = new Mock <IHtmlView>();
            VueDataBinding   binding   = new VueDataBinding(viewmodel, viewMock.Object);
            string           formattedValue;

            // int
            Assert.IsTrue(binding.TryFormatForView(
                              new VueBindingDescription("MyIntProperty", VueBindingMode.OneWayToView), 888, out formattedValue));
            Assert.AreEqual("888", formattedValue);

            // string
            Assert.IsTrue(binding.TryFormatForView(
                              new VueBindingDescription("MyStringProperty", VueBindingMode.OneWayToView), "abc", out formattedValue));
            Assert.AreEqual("'abc'", formattedValue);

            // list<string>
            Assert.IsTrue(binding.TryFormatForView(
                              new VueBindingDescription("MyStringListProperty", VueBindingMode.OneWayToView), new List <string> {
                "a", "b"
            }, out formattedValue));
            Assert.AreEqual("['a','b']", formattedValue);

            // bool
            Assert.IsTrue(binding.TryFormatForView(
                              new VueBindingDescription("MyBoolProperty", VueBindingMode.OneWayToView), false, out formattedValue));
            Assert.AreEqual("false", formattedValue);
        }
        /// <inheritdoc/>
        public override void ShowInView(IHtmlView htmlView, KeyValueList <string, string> variables, Navigation redirectedFrom)
        {
            base.ShowInView(htmlView, variables, redirectedFrom);
            _viewModel = new OpenSafeViewModel(
                Ioc.GetOrCreate <INavigationService>(),
                Ioc.GetOrCreate <ILanguageService>(),
                Ioc.GetOrCreate <ISvgIconService>(),
                Ioc.GetOrCreate <IThemeService>(),
                Ioc.GetOrCreate <IBaseUrlService>(),
                Ioc.GetOrCreate <IFeedbackService>(),
                Ioc.GetOrCreate <ICryptoRandomService>(),
                Ioc.GetOrCreate <ISettingsService>(),
                Ioc.GetOrCreate <IRepositoryStorageService>(),
                RedirectedFrom);

            VueBindingShortcut[] shortcuts = new[]
            {
                new VueBindingShortcut(VueBindingShortcut.KeyEscape, nameof(OpenSafeViewModel.GoBackCommand)),
                new VueBindingShortcut(VueBindingShortcut.KeyEnter, nameof(OpenSafeViewModel.OkCommand)),
            };
            VueBindings = new VueDataBinding(_viewModel, View, shortcuts);
            _viewModel.VueDataBindingScript = VueBindings.BuildVueScript();
            VueBindings.StartListening();

            string html = _viewService.GenerateHtml(_viewModel);

            View.LoadHtml(html);
        }
        /// <inheritdoc/>
        public override void ShowInView(IHtmlView htmlView, KeyValueList <string, string> variables, Navigation redirectedFrom)
        {
            base.ShowInView(htmlView, variables, redirectedFrom);
            IStoryBoardService storyBoardService             = Ioc.GetOrCreate <IStoryBoardService>();
            SerializeableCloudStorageCredentials credentials = storyBoardService.ActiveStory.LoadFromSession <SerializeableCloudStorageCredentials>(SynchronizationStorySessionKey.CloudStorageCredentials);

            _viewModel = new CloudStorageAccountViewModel(
                Ioc.GetOrCreate <INavigationService>(),
                Ioc.GetOrCreate <ILanguageService>(),
                Ioc.GetOrCreate <ISvgIconService>(),
                Ioc.GetOrCreate <IThemeService>(),
                Ioc.GetOrCreate <IBaseUrlService>(),
                storyBoardService,
                Ioc.GetOrCreate <IFeedbackService>(),
                Ioc.GetOrCreate <ICloudStorageClientFactory>(),
                credentials);

            VueBindingShortcut[] shortcuts = new[]
            {
                new VueBindingShortcut(VueBindingShortcut.KeyEscape, nameof(CloudStorageAccountViewModel.CancelCommand)),
                new VueBindingShortcut(VueBindingShortcut.KeyEnter, nameof(CloudStorageAccountViewModel.OkCommand)),
            };
            VueBindings = new VueDataBinding(_viewModel, View, shortcuts);
            _viewModel.VueDataBindingScript = VueBindings.BuildVueScript();
            VueBindings.StartListening();

            string html = _viewService.GenerateHtml(_viewModel);

            View.LoadHtml(html);
        }
Ejemplo n.º 4
0
        /// <inheritdoc/>
        public override void ShowInView(IHtmlView htmlView, KeyValueList <string, string> variables, Navigation redirectedFrom)
        {
            base.ShowInView(htmlView, variables, redirectedFrom);
            _viewModel = new SettingsViewModel(
                Ioc.GetOrCreate <INavigationService>(),
                Ioc.GetOrCreate <ILanguageService>(),
                Ioc.GetOrCreate <ISvgIconService>(),
                Ioc.GetOrCreate <IThemeService>(),
                Ioc.GetOrCreate <IBaseUrlService>(),
                Ioc.GetOrCreate <ISettingsService>(),
                Ioc.GetOrCreate <IStoryBoardService>(),
                Ioc.GetOrCreate <IFeedbackService>(),
                Ioc.GetOrCreate <ICloudStorageClientFactory>(),
                Ioc.GetOrCreate <IFilePickerService>());

            VueBindingShortcut[] shortcuts = new[]
            {
                new VueBindingShortcut(VueBindingShortcut.KeyEscape, nameof(SettingsViewModel.GoBackCommand)),
            };
            VueBindings = new VueDataBinding(_viewModel, View, shortcuts);
            _viewModel.VueDataBindingScript = VueBindings.BuildVueScript();
            VueBindings.StartListening();

            string html = _viewService.GenerateHtml(_viewModel);

            View.LoadHtml(html);
        }
        public void VueScriptContainsMarkedCommands()
        {
            TestViewModel    viewmodel = new TestViewModel();
            Mock <IHtmlView> view      = new Mock <IHtmlView>();

            VueDataBinding binding = new VueDataBinding(viewmodel, view.Object);
            string         script  = binding.BuildVueScript();

            // Contains declaration
            Assert.IsTrue(script.Contains("MyCommand: function() { vueCommandExecute('MyCommand'); },"));
            Assert.IsFalse(script.Contains("MyUnboundCommand"));
        }
        public void VueScriptContainsMarkedProperties()
        {
            TestViewModel    viewmodel = new TestViewModel();
            Mock <IHtmlView> view      = new Mock <IHtmlView>();

            VueDataBinding binding = new VueDataBinding(viewmodel, view.Object);
            string         script  = binding.BuildVueScript();

            // Contains declaration and watch
            Assert.IsTrue(script.Contains("MyProperty: 'Horse',"));
            Assert.IsTrue(script.Contains("MyProperty: function(newVal) { vuePropertyChanged('MyProperty', newVal); },"));
            Assert.IsFalse(script.Contains("MyUnboundProperty"));
        }
        public void ViewmodelChangeUpdatesView()
        {
            TestViewModel    viewmodel = new TestViewModel();
            Mock <IHtmlView> viewMock  = new Mock <IHtmlView>();

            VueDataBinding binding = new VueDataBinding(viewmodel, viewMock.Object);

            binding.StartListening();

            // Simulate Viewmodel change
            viewmodel.MyProperty = "Cat";
            viewmodel.OnPropertyChanged(nameof(viewmodel.MyProperty));

            viewMock.Verify(m => m.ExecuteJavaScript(It.Is <string>(p => p == "var newValue = 'Cat'; if (vm.MyProperty != newValue) vm.MyProperty = newValue;")), Times.Once);
        }
        public void ViewChangeDoesNotTriggerCircularUpdateInView()
        {
            TestViewModel    viewmodel = new TestViewModel();
            Mock <IHtmlView> viewMock  = new Mock <IHtmlView>();

            VueDataBinding binding = new VueDataBinding(viewmodel, viewMock.Object);

            binding.StartListening();

            // Simulate view change
            string js = string.Format("vuePropertyChanged?name=MyProperty&value=Dog");

            viewMock.Raise(m => m.Navigating += null, new object[] { null, js });

            viewMock.Verify(m => m.ExecuteJavaScript(It.IsAny <string>()), Times.Never);
            viewMock.Verify(m => m.ExecuteJavaScriptReturnString(It.IsAny <string>()), Times.Never);
        }
        public void ViewChangeUpdatesViewmodel()
        {
            TestViewModel    viewmodel = new TestViewModel();
            Mock <IHtmlView> viewMock  = new Mock <IHtmlView>();

            VueDataBinding binding = new VueDataBinding(viewmodel, viewMock.Object);

            binding.StartListening();

            // Simulate view change
            string js = string.Format("vuePropertyChanged?name=MyProperty&value=Dog");

            viewMock.Raise(m => m.Navigating += null, new object[] { null, js });
            js = string.Format("vuePropertyChanged?name=MyIntProperty&value=888");
            viewMock.Raise(m => m.Navigating += null, new object[] { null, js });

            Assert.AreEqual("Dog", viewmodel.MyProperty);
            Assert.AreEqual(888, viewmodel.MyIntProperty);
        }
        /// <inheritdoc/>
        public override void ShowInView(IHtmlView htmlView, KeyValueList <string, string> variables, Navigation redirectedFrom)
        {
            base.ShowInView(htmlView, variables, redirectedFrom);
            _viewModel = new CloudStorageOauthWaitingViewModel(
                Ioc.GetOrCreate <INavigationService>(),
                Ioc.GetOrCreate <ILanguageService>(),
                Ioc.GetOrCreate <ISvgIconService>(),
                Ioc.GetOrCreate <IThemeService>(),
                Ioc.GetOrCreate <IBaseUrlService>(),
                Ioc.GetOrCreate <IStoryBoardService>(),
                Ioc.GetOrCreate <IFeedbackService>());

            VueBindings = new VueDataBinding(_viewModel, View);
            _viewModel.VueDataBindingScript = VueBindings.BuildVueScript();
            VueBindings.StartListening();

            string html = _viewService.GenerateHtml(_viewModel);

            View.LoadHtml(html);
        }
Ejemplo n.º 11
0
        /// <inheritdoc/>
        public override void ShowInView(IHtmlView htmlView, KeyValueList <string, string> variables, Navigation redirectedFrom)
        {
            base.ShowInView(htmlView, variables, redirectedFrom);
            IRepositoryStorageService repositoryService = Ioc.GetOrCreate <IRepositoryStorageService>();

            _scrollToNote = variables?.GetValueOrDefault(ControllerParameters.NoteId);

            RepositoryStorageLoadResult loadResult = repositoryService.LoadRepositoryOrDefault(out _);

            if (loadResult != RepositoryStorageLoadResult.InvalidRepository)
            {
                _viewModel = new NoteRepositoryViewModel(
                    Ioc.GetOrCreate <INavigationService>(),
                    Ioc.GetOrCreate <ILanguageService>(),
                    Ioc.GetOrCreate <ISvgIconService>(),
                    Ioc.GetOrCreate <IThemeService>(),
                    Ioc.GetOrCreate <IBaseUrlService>(),
                    Ioc.GetOrCreate <IStoryBoardService>(),
                    Ioc.GetOrCreate <IFeedbackService>(),
                    Ioc.GetOrCreate <ISettingsService>(),
                    Ioc.GetOrCreate <IEnvironmentService>(),
                    Ioc.GetOrCreate <ICryptoRandomService>(),
                    repositoryService);

                VueBindingShortcut[] shortcuts = new[]
                {
                    new VueBindingShortcut("s", nameof(_viewModel.SynchronizeCommand))
                    {
                        Ctrl = true
                    },
                    new VueBindingShortcut("n", nameof(_viewModel.NewNoteCommand))
                    {
                        Ctrl = true
                    },
                    new VueBindingShortcut("l", nameof(_viewModel.NewChecklistCommand))
                    {
                        Ctrl = true
                    },
                    new VueBindingShortcut("r", nameof(_viewModel.ShowRecycleBinCommand))
                    {
                        Ctrl = true
                    },
                    new VueBindingShortcut("i", nameof(_viewModel.ShowInfoCommand))
                    {
                        Ctrl = true
                    },
                    new VueBindingShortcut(VueBindingShortcut.KeyHome, "ScrollToTop")
                    {
                        Ctrl = true
                    },
                    new VueBindingShortcut(VueBindingShortcut.KeyEnd, "ScrollToBottom")
                    {
                        Ctrl = true
                    },
                };
                VueBindings = new VueDataBinding(_viewModel, View, shortcuts);
                VueBindings.DeclareAdditionalVueMethod("ScrollToTop", "scrollToTop();");
                VueBindings.DeclareAdditionalVueMethod("ScrollToBottom", "scrollToBottom();");
                _viewModel.VueDataBindingScript        = VueBindings.BuildVueScript();
                VueBindings.UnhandledViewBindingEvent += UnhandledViewBindingEventHandler;
                VueBindings.ViewLoadedEvent           += ViewLoadedEventHandler;
                VueBindings.StartListening();

                _viewModel.PropertyChanged += ViewmodelPropertyChangedEventHandler;

                string html = _viewService.GenerateHtml(_viewModel);
                View.LoadHtml(html);
            }
            else
            {
                // Show error message and stop loading the application
                _stopViewModel = new StopViewModel(
                    Ioc.GetOrCreate <INavigationService>(),
                    Ioc.GetOrCreate <ILanguageService>(),
                    Ioc.GetOrCreate <ISvgIconService>(),
                    Ioc.GetOrCreate <IThemeService>(),
                    Ioc.GetOrCreate <IBaseUrlService>());
                string html = _viewStop.GenerateHtml(_stopViewModel);
                View.LoadHtml(html);
            }
        }
Ejemplo n.º 12
0
        /// <inheritdoc/>
        public override void ShowInView(IHtmlView htmlView, KeyValueList <string, string> variables, Navigation redirectedFrom)
        {
            base.ShowInView(htmlView, variables, redirectedFrom);
            ISettingsService settingsService = Ioc.GetOrCreate <ISettingsService>();

            _repositoryService.LoadRepositoryOrDefault(out NoteRepositoryModel noteRepository);

            variables.TryGetValue(ControllerParameters.SearchFilter, out _startingSearchFilter);

            // Get the note from the repository
            Guid      noteId = new Guid(variables[ControllerParameters.NoteId]);
            NoteModel note   = noteRepository.Notes.FindById(noteId);

            ICryptor cryptor = new Cryptor(NoteModel.CryptorPackageName, Ioc.GetOrCreate <ICryptoRandomService>());

            _viewModel = new NoteViewModel(
                Ioc.GetOrCreate <INavigationService>(),
                Ioc.GetOrCreate <ILanguageService>(),
                Ioc.GetOrCreate <ISvgIconService>(),
                Ioc.GetOrCreate <IThemeService>(),
                Ioc.GetOrCreate <IBaseUrlService>(),
                null,
                _repositoryService,
                Ioc.GetOrCreate <IFeedbackService>(),
                settingsService,
                cryptor,
                noteRepository.Safes,
                noteRepository.CollectActiveTags(),
                note);
            SetHtmlViewBackgroundColor(htmlView);

            VueBindingShortcut[] shortcuts = new[]
            {
                new VueBindingShortcut("f", "ToggleSearchDialogCommand")
                {
                    Ctrl = true
                },
                new VueBindingShortcut(VueBindingShortcut.KeyEscape, "CloseSearchDialogCommand"),
                new VueBindingShortcut(VueBindingShortcut.KeyHome, "ScrollToTop")
                {
                    Ctrl = true
                },
                new VueBindingShortcut(VueBindingShortcut.KeyEnd, "ScrollToBottom")
                {
                    Ctrl = true
                },
            };
            VueBindings = new VueDataBinding(_viewModel, View, shortcuts);
            VueBindings.DeclareAdditionalVueData("PrettyTimeAgoVisible", "true");
            VueBindings.DeclareAdditionalVueData("Header1Active", "false");
            VueBindings.DeclareAdditionalVueData("Header2Active", "false");
            VueBindings.DeclareAdditionalVueData("Header3Active", "false");
            VueBindings.DeclareAdditionalVueData("BoldActive", "false");
            VueBindings.DeclareAdditionalVueData("ItalicActive", "false");
            VueBindings.DeclareAdditionalVueData("ListOrderedActive", "false");
            VueBindings.DeclareAdditionalVueData("ListBulletActive", "false");
            VueBindings.DeclareAdditionalVueData("CodeActive", "false");
            VueBindings.DeclareAdditionalVueData("QuoteActive", "false");
            VueBindings.DeclareAdditionalVueData("UnderlineActive", "false");
            VueBindings.DeclareAdditionalVueData("StrikeActive", "false");
            VueBindings.DeclareAdditionalVueMethod("ToggleSearchDialogCommand", "toggleSearchDialog();");
            VueBindings.DeclareAdditionalVueMethod("CloseSearchDialogCommand", "showSearchDialog(false);");
            VueBindings.DeclareAdditionalVueMethod("ScrollToTop", "scrollToTop();");
            VueBindings.DeclareAdditionalVueMethod("ScrollToBottom", "scrollToBottom();");
            VueBindings.UnhandledViewBindingEvent += UnhandledViewBindingEventHandler;
            VueBindings.ViewLoadedEvent           += ViewLoadedEventHandler;
            _viewModel.VueDataBindingScript        = VueBindings.BuildVueScript();
            VueBindings.StartListening();

            string html = _viewService.GenerateHtml(_viewModel);

            View.LoadHtml(html);
        }