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); }
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; }
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; }
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"); } }
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); }
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); }); }
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); }
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 } }
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); }
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); }
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); }
public void Destroy(RemoteFileDescr forFile) { _known.Remove(forFile); }
private void UpdateEnablementAndHref(RemoteFileDescr forFile, bool isOperationRunning) { _known .Where(x => x.Key == forFile) .ForEach(x => UpdateEnablementAndHref(x.Key, x.Value, isOperationRunning)); }
public void OnNotifyOperationEnded(RemoteFileDescr forFile, IView <HTMLElement> _) { _known .Where(x => x.Key == forFile) .ForEach(x => UpdateContent(x.Key, x.Value, false)); }
public void OnNotifyOperationStart(RemoteFileDescr forFile, IView <HTMLElement> _) { UpdateEnablementAndHref(forFile, true); }
public void OnNotifyOperationEnded(RemoteFileDescr forFile, IView <HTMLElement> _) { UpdateEnablementAndHref(forFile, false); }
public void OnNotifyOperationEnded(RemoteFileDescr forFile, IView <HTMLElement> senderOrNull) { Logger.Debug(GetType(), "updating enablement for {0} due to oper ending", forFile); UpdateEnablement(forFile, false, senderOrNull); }
public void OnNotifyOperationEnded(RemoteFileDescr forFile, IView <HTMLElement> _) { Logger.Debug(GetType(), "updating visibility for {0} due to oper ending", forFile); UpdateVisibility(forFile); }
private void UpdateVisibility(RemoteFileDescr forFile, InputTypeButtonActionView widget) { widget.Widget.Style.SetProperty("display", forFile.Status == UploadStatus.Failed && forFile.FileId == null ? "" : "none"); }
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"); } }
private void UpdateVisibility(RemoteFileDescr forFile) { _known .Where(x => x.Key == forFile) .ForEach(x => UpdateVisibility(x.Key, x.Value)); }