Exemplo n.º 1
0
        private async Task _onValueChangeHandler(ChangeEventArgs e)
        {
            var value = (string)e.Value;
            //Generate new Rows
            var rows = WvpHelpers.GetCsvData <TItem>(value, _hasHeader, _delimiter, Culture);
            await ValueChanged.InvokeAsync(new ChangeEventArgs { Value = value });

            await RowsChanged.InvokeAsync(new ChangeEventArgs { Value = rows });
        }
        public async Task NotifyChange(List <WvpFileInfo> files)
        {
            _value = null;
            if (files.Count > 0)
            {
                _value = files[0];
            }

            foreach (var file in files)
            {
                if (file == null)
                {
                    file.Status = "File not found";
                    await InvokeAsync(StateHasChanged);

                    return;
                }
                else if (file.Size > MaxFileSize)
                {
                    file.Status = $"That's too big. Max size: {WvpHelpers.GetSizeStringFromSize(MaxFileSize)}";
                    await InvokeAsync(StateHasChanged);

                    return;
                }
                else
                {
                    file.Status = "Loading...";
                }

                await file.WriteTempFileAsync(JSRuntime, _elementRef, UpdateProgressAsync);
            }
            await ValueChanged.InvokeAsync(new ChangeEventArgs { Value = _value });

            await OnInput.InvokeAsync(new ChangeEventArgs { Value = _value });

            await InvokeAsync(StateHasChanged);
        }
Exemplo n.º 3
0
        public async Task NotifyChange(List <WvpFileInfo> files)
        {
            _errorFiles = new List <WvpFileInfo>();

            //Multi File upload
            if (Multiple)
            {
                var eligibleFiles = new List <WvpFileInfo>();
                if (_value != null)
                {
                    eligibleFiles.AddRange(_value);
                }

                foreach (var file in files)
                {
                    if (file == null)
                    {
                        file.Status = "File not found";
                        _errorFiles.Add(file);
                        await InvokeAsync(StateHasChanged);

                        return;
                    }
                    else if (file.Size > MaxFileSize)
                    {
                        file.Status = $"That's too big. Max size: {WvpHelpers.GetSizeStringFromSize(MaxFileSize)}";
                        _errorFiles.Add(file);
                        await InvokeAsync(StateHasChanged);

                        return;
                    }
                    else if (eligibleFiles.Any(x => x.Name == file.Name))
                    {
                        // If file with the same name is uploaded again, exchange
                        file.Status   = "Loading...";
                        eligibleFiles = eligibleFiles.FindAll(x => x.Name != file.Name).ToList();
                    }
                    else
                    {
                        file.Status = "Loading...";
                    }

                    await file.WriteTempFileAsync(JSRuntime, _elementRef, UpdateProgressAsync);

                    eligibleFiles.Add(new WvpFileInfo
                    {
                        ContentType    = file.ContentType,
                        Id             = file.Id,
                        LastModified   = file.LastModified,
                        Name           = file.Name,
                        Url            = file.Url,
                        Size           = file.Size,
                        ServerTempPath = file.ServerTempPath
                    });
                }
                _value = eligibleFiles;
                await ValueChanged.InvokeAsync(new ChangeEventArgs { Value = _value });

                await OnInput.InvokeAsync(new ChangeEventArgs { Value = _value });
            }
            //Single File upload
            else
            {
                if (files.Count > 0)
                {
                    var file = files[0];

                    if (file == null)
                    {
                        file.Status = "File not found";
                        _errorFiles.Add(file);
                        await InvokeAsync(StateHasChanged);

                        return;
                    }
                    else if (file.Size > MaxFileSize)
                    {
                        file.Status = $"That's too big. Max size: {WvpHelpers.GetSizeStringFromSize(MaxFileSize)}";
                        _errorFiles.Add(file);
                        await InvokeAsync(StateHasChanged);

                        return;
                    }
                    else
                    {
                        file.Status = "Loading...";
                    }

                    await file.WriteTempFileAsync(JSRuntime, _elementRef, UpdateProgressAsync);

                    _value = new List <WvpFileInfo>();
                    _value.Add(new WvpFileInfo
                    {
                        ContentType    = file.ContentType,
                        Id             = file.Id,
                        LastModified   = file.LastModified,
                        Name           = file.Name,
                        Url            = file.Url,
                        Size           = file.Size,
                        ServerTempPath = file.ServerTempPath
                    });
                    await ValueChanged.InvokeAsync(new ChangeEventArgs { Value = _value });

                    await OnInput.InvokeAsync(new ChangeEventArgs { Value = _value });
                }
            }
            await InvokeAsync(StateHasChanged);
        }
Exemplo n.º 4
0
        protected override async Task OnParametersSetAsync()
        {
            _cssList = new List <string>();

            if (!String.IsNullOrWhiteSpace(Class))
            {
                _cssList.Add(Class);
            }

            _cssList.Add($"form-control-datacsv");

            var valueHasChanged     = false;
            var rowsHasChanged      = false;
            var delimterHasChanged  = false;
            var hasHeaderHasChanged = false;

            if (JsonConvert.SerializeObject(_originalValue) != JsonConvert.SerializeObject(Value))
            {
                _originalValue  = Value;
                _value          = FieldValueService.InitAsString(Value);
                valueHasChanged = true;
            }

            if (JsonConvert.SerializeObject(_originalRows) != JsonConvert.SerializeObject(Rows))
            {
                _originalRows  = Rows.ToList();
                _rows          = Rows.ToList();
                rowsHasChanged = true;
            }

            if (JsonConvert.SerializeObject(_originalDelimiter) != JsonConvert.SerializeObject(Delimiter))
            {
                _originalDelimiter = Delimiter;
                _delimiter         = Delimiter;
                delimterHasChanged = true;
            }

            if (JsonConvert.SerializeObject(_originalHasHeader) != JsonConvert.SerializeObject(HasHeader))
            {
                _originalHasHeader  = HasHeader ? true : false;
                _hasHeader          = HasHeader ? true : false;
                hasHeaderHasChanged = true;
            }

            if (!String.IsNullOrWhiteSpace(Name))
            {
                AdditionalAttributes["name"] = Name;
            }

            if (!String.IsNullOrWhiteSpace(Placeholder))
            {
                AdditionalAttributes["placeholder"] = Placeholder;
            }

            if (!String.IsNullOrWhiteSpace(Title))
            {
                AdditionalAttributes["title"] = Title;
            }

            //Value has preference
            if (valueHasChanged)
            {
                if (!String.IsNullOrWhiteSpace(_value))
                {
                    _rows = WvpHelpers.GetCsvData <TItem>(_value, _hasHeader, _delimiter, Culture);
                }
                else
                {
                    _rows = new List <TItem>();
                }
            }
            else if (rowsHasChanged || delimterHasChanged || hasHeaderHasChanged)
            {
                if (_rows.Count == 0)
                {
                    _value = "";
                }
                else
                {
                    //Specifics here is that header should not be generated
                    _value = WvpHelpers.WriteCsvData <TItem>(_rows, false, _delimiter, Culture);
                }
            }


            await base.OnParametersSetAsync();
        }