示例#1
0
            public IView <HTMLElement> Create(RemoteFileDescr forFile, Action forceAddOrRemoveToView)
            {
                var widget = InputTypeButtonActionView.CreateFontAwesomeIconedAction(
                    IconFontType.FontAwesomeSolid, FontAwesomeSolid.IconExchangeAlt);

                widget.Widget.Title = I18n.Translate("Replace");
                widget.Triggered   += () => {
                    //HACK due to lack of: on input[file] activated but user declined to select anything
                    _parent._hackOnUploadStarted =
                        () => {
                        widget.State = ActionViewState.CreateOperationRunning();
                        _activatedFor.Add(forFile);
                    };

                    _parent.OnReplace(widget, forFile, forceAddOrRemoveToView);

                    _parent._hackOnUploadEnded = result => {
                        _activatedFor.Remove(forFile);
                        widget.Widget.TextContent = FontAwesomeSolid.IconExchangeAlt;
                        widget.State = result.Success ?
                                       ActionViewState.CreateIdleOrSuccess()
                            :
                                       ActionViewState.CreateOperationFailed(new Exception(result.ErrorMessage));

                        UpdateEnablement(forFile, widget, false); //make action enabled (needed due to hack above)
                    };
                };
                UpdateEnablement(forFile, widget, false);
                _known.Add(forFile, widget);
                return(widget);
            }
示例#2
0
            private void UpdateEnablement(
                RemoteFileDescr forFile, InputTypeButtonActionView widget, bool isOperationStarted)
            {
                var val =
                    _parent.Mutable &&
                    _parent.Enabled &&
                    forFile.FileId != null &&
                    !isOperationStarted;

                widget.Enabled             = val;
                widget.Widget.Style.Cursor = val ? Cursor.Pointer : Cursor.Default;
            }
示例#3
0
            private void UpdateEnablement(
                RemoteFileDescr forFile, InputTypeButtonActionView widget, bool isOperationStarted)
            {
                var val =
                    _parent.Mutable &&
                    _parent.Enabled &&
                    forFile.FileId != null &&
                    !isOperationStarted &&
                    !_activatedFor.Contains(forFile);

                Logger.Debug(GetType(), "UpdateEnablement for {0} value {1}", forFile, val);
                widget.Enabled = val;
            }
示例#4
0
            private void SetupOnClick(
                RemoteFileDescr forFile, AnchorBasedActionView widget, bool isInitial)
            {
                if (!_parent.Downloadable)
                {
                    widget.Href = "#";

                    return;
                }

                var effectiveMethod =
                    _parent.ImageOpenMethod == OpenImagesMethod.Lightbox && forFile.FullDimensions == null ?
                    OpenImagesMethod.DownloadAsAttachment : _parent.ImageOpenMethod;

                switch (effectiveMethod)
                {
                case OpenImagesMethod.DownloadAsAttachment:
                    if (isInitial)
                    {
                        widget.Triggered += () =>
                                            _parent.RunDownloadOperation(forFile, DownloadMethod.Attachment);
                    }

                    break;

                case OpenImagesMethod.InlineInNewTab:
                    widget.OnClickPreventsDefault = false;
                    widget.Target = "_blank";
                    widget.Href   = _parent.BuildHref(forFile, DownloadMethod.Inline);
                    break;

                case OpenImagesMethod.Lightbox:
                    if (isInitial)
                    {
                        widget.ShouldTriggerOnTarget = x => {
                            var res = x.IsElementOrItsDescendant(widget.Widget);
                            Logger.Debug(GetType(), "click was meaningful?=" + res);
                            return(res);
                        };

                        widget.Triggered += () => {
                            Logger.Debug(GetType(), "invoking lightBoxManager from onclick");
                            new LightBoxManager(x => _parent.BuildHref(forFile, DownloadMethod.Inline))
                            .Start(widget, forFile);
                        };
                    }
                    break;

                default: throw new Exception("unsupported OpenImagesMethod");
                }
            }
示例#5
0
            public IView <HTMLElement> Create(RemoteFileDescr forFile, Action forceAddOrRemoveToView)
            {
                var widget = InputTypeButtonActionView.CreateFontAwesomeIconedAction(
                    IconFontType.FontAwesomeSolid, FontAwesomeSolid.IconTimes);

                widget.Widget.Title = I18n.Translate("Hide");
                widget.Triggered   += () => _parent.OnRemoveTransient(forFile);

                UpdateVisibility(forFile, widget);

                _known.Add(forFile, widget);

                return(widget);
            }
示例#6
0
 private void UpdateEnablement(
     RemoteFileDescr forFile, bool isOperationStarted, IView <HTMLElement> senderOrNull)
 {
     _known
     .Where(x => x.Key == forFile)
     .ForEach(x => {
         if (x.Value != senderOrNull)
         {
             //reset former errors if any
             x.Value.State = ActionViewState.CreateIdleOrSuccess();
         }
         UpdateEnablement(x.Key, x.Value, isOperationStarted);
     });
 }
示例#7
0
            public IView <HTMLElement> Create(RemoteFileDescr forFile, Action forceAddOrRemoveToView)
            {
                var widget = new AnchorBasedActionView(
                    forFile.GetNotTooLongFileName(
                        _parent.FileNameMaxVisibleLength, _parent.FileNameShortening),
                    forFile.FileName);

                UpdateEnablementAndHref(forFile, widget, false);

                var effectiveMethod =
                    _parent.ImageOpenMethod == OpenImagesMethod.Lightbox && forFile.FullDimensions == null ?
                    OpenImagesMethod.DownloadAsAttachment : _parent.ImageOpenMethod;

                switch (effectiveMethod)
                {
                case OpenImagesMethod.DownloadAsAttachment:
                    widget.Triggered += () => {
                        if (!_parent.Downloadable)
                        {
                            return;
                        }
                        _parent.RunDownloadOperation(forFile, DownloadMethod.Attachment);
                    };
                    break;

                case OpenImagesMethod.InlineInNewTab:
                    widget.OnClickPreventsDefault = false;
                    widget.Target = "_blank";
                    widget.Href   = _parent.BuildHref(forFile, DownloadMethod.Inline);
                    break;

                case OpenImagesMethod.Lightbox:
                    widget.ShouldTriggerOnTarget = x => x.IsElementOrItsDescendant(widget.Widget);
                    widget.Triggered            += () => {
                        Logger.Debug(GetType(), "invoking lightBoxManager from view");
                        new LightBoxManager(x => _parent.BuildHref(forFile, DownloadMethod.Inline))
                        .Start(widget, forFile);
                    };

                    break;

                default: throw new Exception("unsupported OpenImagesMethod");
                }

                _known.Add(forFile, widget);

                return(widget);
            }
示例#8
0
            private void UpdateEnablementAndHref(
                RemoteFileDescr forFile, AnchorBasedActionView widget, bool isOperationRunning)
            {
                var value = forFile.FileId != null &&
                            _parent.Downloadable &&
                            forFile.Status == UploadStatus.Succeeded &&
                            !isOperationRunning;

                Logger.Debug(GetType(), "updating enablement+href for {0} to={1}", forFile, value);
                widget.Enabled = value;

                if (_parent.ImageOpenMethod == OpenImagesMethod.InlineInNewTab)
                {
                    widget.Target = "_blank";
                    widget.Href   = !_parent.Downloadable ? "#" : _parent.BuildHref(forFile, DownloadMethod.Inline);
                    //note: FileId may be null
                }
            }
示例#9
0
            public IView <HTMLElement> Create(RemoteFileDescr forFile, Action forceAddOrRemoveToView)
            {
                var widget = new AnchorBasedActionView();

                //save current status
                widget.Widget.SetAttribute(Magics.AttrDataStatus, forFile.Status.ToString());

                widget.Widget.Style.Display        = Display.Flex;
                widget.Widget.Style.Width          = $"{_parent._cellSize.width}px";
                widget.Widget.Style.Height         = $"{_parent._cellSize.height}px";
                widget.Widget.Style.AlignItems     = AlignItems.Center;
                widget.Widget.Style.JustifyContent = JustifyContent.Center;

                UpdateContentImpl(forFile, null, widget, false);
                SetupOnClick(forFile, widget, true);
                _known.Add(forFile, widget);

                return(widget);
            }
示例#10
0
            public IView <HTMLElement> Create(RemoteFileDescr forFile, Action forceAddOrRemoveToView)
            {
                var widget = InputTypeButtonActionView.CreateFontAwesomeIconedAction(
                    IconFontType.FontAwesomeSolid, FontAwesomeSolid.IconTrashAlt);

                widget.Widget.Title = I18n.Translate("Remove");
                widget.Triggered   += async() => {
                    widget.State = ActionViewState.CreateOperationRunning();
                    var result = await _parent.OnRemove(widget, forFile, forceAddOrRemoveToView);

                    widget.Widget.TextContent = FontAwesomeSolid.IconTrashAlt;
                    widget.State = result.Success ?
                                   ActionViewState.CreateIdleOrSuccess()
                        :
                                   ActionViewState.CreateOperationFailed(new Exception(result.ErrorMessage));
                };

                UpdateEnablement(forFile, widget, false);

                _known.Add(forFile, widget);
                return(widget);
            }
示例#11
0
            private void UpdateContent(
                RemoteFileDescr forFile, AnchorBasedActionView widget, bool isOperationRunning)
            {
                var          oldStatusRaw = widget.Widget.GetAttribute(Magics.AttrDataStatus);
                UploadStatus?oldStatus    = null;

                if (!string.IsNullOrWhiteSpace(oldStatusRaw))
                {
                    oldStatus = EnumExtensions.GetEnumByLabel <UploadStatus>(oldStatusRaw);
                    var changed = oldStatus.Value != forFile.Status;

                    Logger.Debug(GetType(),
                                 "UpdateContentIfNeeded old={0} new={1} changed?={2}",
                                 oldStatus.Value, forFile.Status, changed);

                    if (changed)
                    {
                        widget.Widget.SetAttribute(Magics.AttrDataStatus, forFile.Status.ToString());
                        widget.Widget.RemoveAllChildren();
                    }
                }

                UpdateContentImpl(forFile, oldStatus, widget, isOperationRunning);
            }
示例#12
0
 public void Destroy(RemoteFileDescr forFile)
 {
     _known.Remove(forFile);
 }
示例#13
0
 private void UpdateEnablementAndHref(RemoteFileDescr forFile, bool isOperationRunning)
 {
     _known
     .Where(x => x.Key == forFile)
     .ForEach(x => UpdateEnablementAndHref(x.Key, x.Value, isOperationRunning));
 }
示例#14
0
 public void OnNotifyOperationEnded(RemoteFileDescr forFile, IView <HTMLElement> _)
 {
     _known
     .Where(x => x.Key == forFile)
     .ForEach(x => UpdateContent(x.Key, x.Value, false));
 }
示例#15
0
 public void OnNotifyOperationStart(RemoteFileDescr forFile, IView <HTMLElement> _)
 {
     UpdateEnablementAndHref(forFile, true);
 }
示例#16
0
 public void OnNotifyOperationEnded(RemoteFileDescr forFile, IView <HTMLElement> _)
 {
     UpdateEnablementAndHref(forFile, false);
 }
示例#17
0
 public void OnNotifyOperationEnded(RemoteFileDescr forFile, IView <HTMLElement> senderOrNull)
 {
     Logger.Debug(GetType(), "updating enablement for {0} due to oper ending", forFile);
     UpdateEnablement(forFile, false, senderOrNull);
 }
示例#18
0
 public void OnNotifyOperationEnded(RemoteFileDescr forFile, IView <HTMLElement> _)
 {
     Logger.Debug(GetType(), "updating visibility for {0} due to oper ending", forFile);
     UpdateVisibility(forFile);
 }
示例#19
0
 private void UpdateVisibility(RemoteFileDescr forFile, InputTypeButtonActionView widget)
 {
     widget.Widget.Style.SetProperty("display",
                                     forFile.Status == UploadStatus.Failed && forFile.FileId == null ? "" : "none");
 }
示例#20
0
            private void UpdateContentImpl(
                RemoteFileDescr forFile, UploadStatus?formerStatus, AnchorBasedActionView widget,
                bool isOperationRunning)
            {
                var enabledVal =
                    _parent.Downloadable &&
                    forFile.Status != UploadStatus.Running &&
                    forFile.FileId != null &&
                    !isOperationRunning;

                Logger.Debug(GetType(),
                             "UpdateContentImpl file={0} formerStatus={1} isOperationRunning={2} enabled={3}",
                             forFile, formerStatus, isOperationRunning, enabledVal);

                widget.Enabled = enabledVal;

                if (formerStatus.HasValue && formerStatus.Value == forFile.Status)
                {
                    //no need to recreate details
                    return;
                }

                switch (forFile.Status)
                {
                case UploadStatus.Running: {
                    widget.State = ActionViewState.CreateOperationRunning();

                    var throbber = new HTMLDivElement {
                        TextContent = FontAwesomeSolid.IconSpinner
                    };
                    throbber.AddClasses(IconFontType.FontAwesomeSolid.ToCssClassName());

                    throbber.Style.FontSize = $"{_parent._cellSize.width/3}px";
                    throbber.Style.SetProperty("animation", "throbberSpin 1.0s linear infinite");

                    widget.Widget.AppendChild(throbber);
                    break;
                }

                case UploadStatus.Failed:
                case UploadStatus.Succeeded:
                    if (formerStatus.HasValue && formerStatus.Value == UploadStatus.Running)
                    {
                        //file just uploaded (succ or fail)
                        SetupOnClick(forFile, widget, false);
                    }

                    if (forFile.UploadErrorMessage != null)
                    {
                        widget.Widget.SetAttribute(
                            Magics.AttrDataErrorsTooltip, forFile.UploadErrorMessage);
                    }

                    if (forFile.ThumbDimensions != null)
                    {
                        var dim = _parent.CalculateDimensionsFittingIntoCell(
                            forFile.ThumbDimensions.Value);
                        var img = new HTMLImageElement {
                            Width  = dim.width,
                            Height = dim.height,
                            Src    = forFile.ThumbnailDataUrl
                        };
                        widget.Widget.AppendChild(img);
                    }
                    else
                    {
                        var icn = new HTMLDivElement {
                            TextContent = FontAwesomeSolid.IconFileAlt
                        };
                        icn.AddClasses(IconFontType.FontAwesomeSolid.ToCssClassName());
                        icn.Style.FontSize = $"{_parent._cellSize.width/3}px";

                        widget.Widget.AppendChild(icn);
                    }
                    break;

                default: throw new Exception("unsupported UploadStatus");
                }
            }
示例#21
0
 private void UpdateVisibility(RemoteFileDescr forFile)
 {
     _known
     .Where(x => x.Key == forFile)
     .ForEach(x => UpdateVisibility(x.Key, x.Value));
 }