public SyncView(Action <HTMLElement> stylePopupHolder = null) { _toggleState = new InputTypeButtonActionView(""); _showLogs = new AnchorBasedActionView(""); _showLogs.Widget.Style.Padding = "5px"; _logsPopup = new FramelessPopupProvider(_showLogs.Widget) { PopupRawContent = _logItems }; _container.Style.Display = Display.Flex; _container.Style.AlignItems = AlignItems.Center; _container.AppendChild(_toggleState.Widget); _container.AppendChild(_logsPopup.Widget); _logItems.Style.Padding = "20px"; _logItems.Style.MinHeight = "75px"; _logItems.Style.MaxHeight = "75px"; _logItems.Style.OverflowX = Overflow.Auto; _logItems.Style.OverflowY = Overflow.Scroll; _logItems.Style.WhiteSpace = WhiteSpace.Pre; stylePopupHolder?.Invoke(_logsPopup.PopupHolderElement); _toggleState.StaysPressed = true; _showLogs.Triggered += () => _logsPopup.ShowPopup(); }
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 = 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); }
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); }
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"); } }