protected override async Task OnAfterRenderAsync(bool firstRender)
        {
            if (firstRender)
            {
                mediaQueryJs = await Js.InvokeAsync<IJSObjectReference>(
                    "import",
                    "./_content/BlazorPro.BlazorSize/blazorSizeMediaModule.js"
                    );

                DotNetInstance = DotNetObjectReference.Create(this);
                var result = mediaQueryJs.InvokeVoidAsync("addMediaQueryList", DotNetInstance);
                await result;
                // Because MediaQueries are added by the child component before IJSObjectReference completes.
                // We must cache the MediaQueries and load them after the JS module is imported.
                // On additional renders the module is already available and child components can self initialize.
                await InitializeCachedMediaQueries();
            }
            await base.OnAfterRenderAsync(firstRender);

            async Task InitializeCachedMediaQueries()
            {
                foreach (var item in mediaQueries)
                {
                    foreach (var mq in item.MediaQueries)
                    {
                        await Initialize(mq);
                    }
                }
            }
        }
Ejemplo n.º 2
0
 protected override async Task OnAfterRenderAsync(bool firstRender)
 {
     if (firstRender)
     {
         await Js.InvokeAsync <object>("matBlazor.matFileUpload.init", Ref, InputRef, jsHelper.Reference);
     }
 }
        public async Task Initialize(MediaQuery mediaQuery)
        {
            var cache = GetMediaQueryFromCache(byMedia: mediaQuery.Media);

            if (cache.Value == null)
            {
                // If we don't flag the cache as loading, duplicate requests will be sent async.
                // Duplicate requests = poor performance, esp with web sockets.
                if (!cache.Loading)
                {
                    cache.Loading = true;
                    var task = Js.InvokeAsync <MediaQueryArgs>($"{ns}.addMediaQueryToList", DotNetInstance, cache.MediaRequested);
                    cache.Value   = await task;
                    cache.Loading = task.IsCompleted;
                    // When loading is complete dispatch an update to all subscribers.
                    foreach (var item in cache.MediaQueries)
                    {
                        item.MediaQueryChanged(cache.Value);
                    }
                }
                else
                {
                    var task = Js.InvokeAsync <MediaQueryArgs>($"{ns}.getMediaQueryArgs", cache.MediaRequested);
                    cache.Value = await task;

                    mediaQuery.MediaQueryChanged(cache.Value);
                }
            }
        }
Ejemplo n.º 4
0
 public BaseMatRipple()
 {
     ClassMapper
     .Add("mdc-ripple-surface")
     .If("mdc-ripple-surface--primary", () => Color == MatRippleColor.Primary)
     .If("mdc-ripple-surface--accent", () => Color == MatRippleColor.Secondary);
     CallAfterRender(async() => { await Js.InvokeAsync <object>("matBlazor.matRipple.init", Ref); });
 }
Ejemplo n.º 5
0
        protected async Task OnClickHandler()
        {
            var stream = await ScoreReportService.ExportScoreReportToStreamAsync();

            var reader = new StreamReader(stream);
            var text   = reader.ReadToEnd();
            await Js.InvokeAsync <string>("FileSaveAs", Guid.NewGuid(), text);
        }
Ejemplo n.º 6
0
        public async Task SignedIn()
        {
            SetSubject(await Js.InvokeAsync <string>(
                           "interop.authentication.signedIn",
                           JsonConvert.SerializeObject(_config)
                           ));

            ClearSignedInHistory();
        }
Ejemplo n.º 7
0
 public BaseMatHidden()
 {
     CallAfterRender(async() =>
     {
         dotNetObjectRef = dotNetObjectRef ?? CreateDotNetObjectRef(this);
         await Js.InvokeAsync <object>("matBlazor.matHidden.init", Id, dotNetObjectRef);
         await UpdateVisible();
     });
 }
Ejemplo n.º 8
0
 public BaseMatTooltip()
 {
     ClassMapper.Add("mat-tooltip");
     CallAfterRender(async() =>
     {
         await Js.InvokeAsync <object>("matBlazor.matTooltip.init", Ref, TargetForwardRef?.Current, TargetId,
                                       CreateJSOptions());
     });
 }
Ejemplo n.º 9
0
        protected async override Task OnFirstAfterRenderAsync()
        {
            await base.OnFirstAfterRenderAsync();

            await Js.InvokeAsync <object>("matBlazor.matList.init", this.Ref, new MatListJsOptions()
            {
                SingleSelection = SingleSelection
            });
        }
Ejemplo n.º 10
0
        protected async Task OnScrollAsync()
        {
            var scrollAtTop = await Js.InvokeAsync <bool>("scrollAtTop", _scroll);

            if (scrollAtTop)
            {
                await LoadMore();
            }
        }
Ejemplo n.º 11
0
        protected async override Task OnFirstAfterRenderAsync()
        {
            await base.OnFirstAfterRenderAsync();

            await Js.InvokeAsync <object>("blazorFiddle.create", Ref, new
            {
                Text     = this.Code,
                Template = this.Template,
            });
        }
Ejemplo n.º 12
0
        public async Task Delete(int id)
        {
            var user = UserInfos.FirstOrDefault(p => p.UserID.Equals(id));
            // 调用js的方法
            var confirmed = await Js.InvokeAsync <bool>("confirm", $"确定要删除用户 {user.UserName}?");

            if (confirmed)
            {
                await OnDeleted.InvokeAsync(id);
            }
        }
Ejemplo n.º 13
0
        public BaseMatSlider()
        {
            jsHelper = new JsHelper(this);

            ClassMapper
            .Add("mdc-slider")
            .If("mdc-slider--discrete", () => Discrete);
            CallAfterRender(async() =>
            {
                dotNetObjectRef = dotNetObjectRef ?? CreateDotNetObjectRef(jsHelper);
                await Js.InvokeAsync <object>("matBlazor.matSlider.init", Ref, dotNetObjectRef);
            });
        }
Ejemplo n.º 14
0
        private async Task OnChangeMainCheckbox(MouseEventArgs e)
        {
            bool selected = await Js.InvokeAsync <bool>("Bui.datatable.checkSelectAll", Guid.ToString());

            if (selected)
            {
                SelectAll();
            }
            else
            {
                UnselectAll();
            }
        }
Ejemplo n.º 15
0
        private async Task DeleteExpenseAsync(Expense expense)
        {
            if (await Js.InvokeAsync <bool>("confirm",
                                            "Are you sure you want to delete this expense? " +
                                            "This action cannot be undone."))
            {
                await ExpenseService.DeleteExpense(expense.Id);

                ToastService.ShowSuccess($"The '{ expense.Name }' expense has been sucessfully deleted.", "Expense Deleted");

                Expenses.Remove(expense);
            }
        }
Ejemplo n.º 16
0
        public async void OnSendClickAsync()
        {
            _messageText = _messageText.TrimEnd();
            if (string.IsNullOrWhiteSpace(_messageText) || string.IsNullOrEmpty(_messageText))
            {
                return;
            }

            if (_edit != null)
            {
                var model = new EditMessageModel()
                {
                    ContentType = ContentType.Text,
                    Id          = _edit.Id,
                    Content     = _messageText
                };

                var response = await Api.EditMessage(model);

                if (!response.IsSuccessStatusCode)
                {
                    Toaster.Add("Error occured while trying edit message", MatToastType.Danger);
                }

                _edit        = null;
                _messageText = string.Empty;
            }
            else
            {
                var message = new MessageModel()
                {
                    Content     = _messageText,
                    ContentType = ContentType.Text,
                    ReplyTo     = _replyTo?.Id
                };

                var result = await Api.SendMessage(message, ChatId);

                if (!result.IsSuccessStatusCode)
                {
                    Toaster.Add("Error occured while trying send message", MatToastType.Danger);
                }

                _replyTo     = null;
                _messageText = string.Empty;
            }

            StateHasChanged();

            await Js.InvokeAsync <string>("resize", _textarea);
        }
Ejemplo n.º 17
0
        public virtual async Task <T> GetResultAsync <T>(string url, string json = "", HttpMethod method = null)
        {
            http = HttpClientFactory.CreateClient("api");

            var token = await Js.InvokeAsync <string>("localStorage.getItem", "token");

            http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

            string response;

            if (method is null || method == HttpMethod.Get)
            {
                response = await http.GetStringAsync(url);
            }
Ejemplo n.º 18
0
        public BaseMatVirtualScroll()
        {
            ClassMapper.Add("mat-virtual-scroll");

            CallAfterRender(async() =>
            {
                if (!Disabled)
                {
                    JsHelperReference =
                        new MatDotNetObjectReference <MatVirtualScrollJsHelper>(new MatVirtualScrollJsHelper(this));
                    var scrollView = await Js.InvokeAsync <MatVirtualScrollView>("matBlazor.matVirtualScroll.init", Ref,
                                                                                 JsHelperReference.Reference);
                    this.SetScrollView(scrollView);
                }
            });
        }
Ejemplo n.º 19
0
 protected override async Task OnAfterRenderAsync(bool firstRender)
 {
     if (_messages.Count != 0 && !_loading)
     {
         if (_isNewMessagesBarVisible && _firstLoad)
         {
             _firstLoad = false;
             await Js.InvokeAsync <bool>("scrollToView", NewMessagesDivider, new { behaviour = "auto" });
         }
         else if (_loadedMore)
         {
             _loadedMore = false;
             //await Js.InvokeAsync<bool>("scrollToView", _messageElements.First(), new { behaviour = "auto" });
         }
     }
 }
Ejemplo n.º 20
0
        protected async override Task OnFirstAfterRenderAsync()
        {
            await base.OnFirstAfterRenderAsync();
            try
            {
                await Js.InvokeAsync<object>("blazorFiddle.create", Ref, new
                {
                    Text = this.Code,
                    Template = this.Template,
                });
            }
            catch (Exception e)
            {
//                Console.WriteLine(e);
//                throw;
            }
        }
Ejemplo n.º 21
0
        protected async Task <T> JsInvokeAsync <T>(string code, params object[] args)
        {
            if (ComponentContext.IsConnected)
            {
                try
                {
                    return(await Js.InvokeAsync <T>(code, args));
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    throw;
                }
            }

            return(default(T));
        }
Ejemplo n.º 22
0
        private async Task SetConfig(ConfigModel configModel)
        {
            if (editor is null)
            {
                return;
            }

            if (isDirty)
            {
                var result = await Js.InvokeAsync <bool>("confirm", "This config has not been saved yet. Are you sure you want to load another one?");

                if (!result)
                {
                    return;
                }
            }

            string?content = default;

            try
            {
                var sourceConfig = await configModel.Load();

                content = sourceConfig?.Content ?? string.Empty;
                var model = await editor.GetModel();

                await Js.InvokeVoidAsync("blazorMonaco.editor.setModelLanguage", editor.Id, model.Id, sourceConfig?.Language ?? string.Empty);
            }
            catch (Exception e)
            {
                Logger.LogError(e, $"Exception while loading content.");
            }

            content ??= string.Empty;
            await editor.SetValue(content);

            currentConfig = configModel;
            isDirty       = false;

            await editor.UpdateOptions(new()
            {
                ReadOnly = currentConfig.IsReadOnly,
            });
        }
Ejemplo n.º 23
0
        async Task Delete(int diaryId)
        {
            var diary = AllDiaries.First(x => x.DiaryID == diaryId);

            if (await Js.InvokeAsync <bool>("confirm", $"Do you want to delete {diary.Title}'s ({diary.DiaryID}) Record?"))
            {
                var result = await Client.DeleteAsync($"api/v1.0/diary/{diaryId}");

                if (result.IsSuccessStatusCode)
                {
                    ToastService.ShowToast("Deleted Successfully", ToastLevel.Success);
                }
                else
                {
                    ToastService.ShowToast("Failed to Delete", ToastLevel.Error);
                }
            }
            await OnInitializedAsync();
        }
Ejemplo n.º 24
0
        async Task Delete(int todoId)
        {
            var todo = todos.First(x => x.TodoID == todoId);

            if (await Js.InvokeAsync <bool>("confirm", $"Do you want to delete {todo.Title}'s ({todo.TodoID}) Record?"))
            {
                var result = await Client.DeleteAsync($"api/v1.0/Todo/{todoId}");

                if (result.IsSuccessStatusCode)
                {
                    ToastService.ShowToast("Deleted Successfully", ToastLevel.Success);
                    Nav.NavigateTo("diary");
                }
                else
                {
                    ToastService.ShowToast("Failed to delete", ToastLevel.Error);
                }
                await OnInitializedAsync();
            }
        }
Ejemplo n.º 25
0
        public async Task Initialize(MediaQuery mediaQuery)
        {
            bool byMediaProperties(MediaQueryCache q) => q.MediaRequested == mediaQuery.Media;

            var cache = mediaQueries.Find(byMediaProperties);

            if (cache.Value == null)
            {
                if (!cache.Loading)
                {
                    cache.Loading = true;
                    var task = Js.InvokeAsync <MediaQueryArgs>($"{ns}.addMediaQueryToList", DotNetInstance, cache.MediaRequested);
                    cache.Value   = await task;
                    cache.Loading = task.IsCompleted;
                    foreach (var item in cache.MediaQueries)
                    {
                        item.MediaQueryChanged(cache.Value);
                    }
                }
            }
        }
Ejemplo n.º 26
0
        protected async Task ExportErrors()
        {
            string    FileName = $"export_{DateTime.Now.ToShortDateString()}.xlsx";
            var       memory   = new MemoryStream();
            IWorkbook workbook;

            workbook = new XSSFWorkbook();
            ISheet excelSheet = workbook.CreateSheet($"Errors_{DateTime.Now.ToShortDateString()}");
            IRow   row        = excelSheet.CreateRow(0);
            int    counter    = 1;

            row.CreateCell(0).SetCellValue("#");
            row.CreateCell(1).SetCellValue("Insert");
            row.CreateCell(2).SetCellValue("User");
            row.CreateCell(3).SetCellValue("Level");
            row.CreateCell(4).SetCellValue("Error");
            row.CreateCell(5).SetCellValue("Stack Trace");

            foreach (var item in Model.Where(r => r.InsertDate >= StartDate && r.InsertDate < EndDate))
            {
                row = excelSheet.CreateRow(counter);
                row.CreateCell(0).SetCellValue(item.Id);
                row.CreateCell(1).SetCellValue(item.InsertDate.ToString("dd.MM.yy hh:mm:ss"));
                row.CreateCell(2).SetCellValue(item.UserData);
                row.CreateCell(3).SetCellValue(item.ErrorLevel.ToString());
                row.CreateCell(4).SetCellValue(item.ErrorMsg);
                row.CreateCell(5).SetCellValue(item.ErrorContext);
                counter++;
            }
            workbook.Write(memory);
            var fileData = memory.ToArray();

            await Js.InvokeAsync <object>(
                "saveAsFile",
                FileName,
                fileData);
        }
Ejemplo n.º 27
0
        protected async override Task OnFirstAfterRenderAsync()
        {
            await base.OnFirstAfterRenderAsync();

            await Js.InvokeAsync <object>("matBlazor.matCheckbox.init", Ref, FormFieldRef);
        }
Ejemplo n.º 28
0
        public async Task Download(PodcastInfo info)
        {
            var url = await PodcastDownloader.GetZipDownloadUrl(info.Id);

            await Js.InvokeAsync <object>("open", url, "_blank");
        }
Ejemplo n.º 29
0
        protected async override Task OnFirstAfterRenderAsync()
        {
            await base.OnFirstAfterRenderAsync();

            await Js.InvokeAsync <object>("matBlazor.matAppBar.init", Ref);
        }
Ejemplo n.º 30
0
 public async Task OpenAsync(ElementRef anchorElement)
 {
     await Js.InvokeAsync <object>("matBlazor.matMenu.open", Ref, anchorElement);
 }