Exemple #1
0
        private async Task ExportDataGrid()
        {
            Logger.Debug(GetType(), "Export trigger start");
            await DataGridSettings.ConvertJsonToXlsxOperation(_model.ExportDataToJson());

            await Task.Delay(1000); //eyecandy: so that spinner is visible

            Logger.Debug(GetType(), "Export trigger finished");
        }
Exemple #2
0
        public static void InitializeToolkit(
            ILoggerImplementation customLogger = null,
            Func <DatagridContent, Task <FileModel> > spreadsheetBuilder = null,
            bool?clickingOutsideOfDialogDismissesIt = null)
        {
            ExecOnUiThread.SetImplementation(
                async x => {
                x();
                await Task.Run(() => {});     //NOP
            },
                async x => {
                await x();
            });

            if (customLogger != null)
            {
                Logger.ConfigureImplementation(customLogger);
            }
            else if (DocumentUtil.HasQueryParameter("debug") && DocumentUtil.GetQueryParameter("debug") == "lite")
            {
                var toIgnoreByType = new [] {
                    typeof(Philadelphia.Web.GeneralAttrChangedObserver),
                    typeof(Philadelphia.Web.GeneralChildListChangedObserver),
                    typeof(Philadelphia.Web.SpecificChildListChangedObserver),
                    typeof(Philadelphia.Web.TooltipManager),
                    typeof(Philadelphia.Web.MouseObserver),
                    typeof(Philadelphia.Web.FormCanvasExtensions),
                    typeof(Philadelphia.Web.SpecificResizeObserver)
                };

                var toIgnoreByBaseName = new [] {
                    typeof(Philadelphia.Web.DataGridColumn <string, Unit>).FullNameWithoutGenerics()
                };

                Logger.ConfigureImplementation(new ForwardMatchingToConsoleLogLoggerImplementation(
                                                   x => !toIgnoreByType.Contains(x) && !toIgnoreByBaseName.Contains(x.FullNameWithoutGenerics())));
            }
            else if (DocumentUtil.HasQueryParameter("debug"))
            {
                Logger.ConfigureImplementation(new ForwardEverythingToConsoleLogLoggerImplementation());
            }
            else
            {
                Logger.ConfigureImplementation(new ForwardErrorsToConsoleLogLoggerImplementation());
            }

            DocumentUtil.Initialize(); //initialize tooltips, esc handler etc

            var env = EnvironmentTypeUtil.GetInstanceFromWindow(Window.Instance);

            Document.Body.SetAttribute(Magics.AttrDataEnvironment, env.AsDataEnvironmentAttributeValue());

            Func <DatagridContent, Task <FileModel> > noExportImpl =
                _ => {
                throw new Exception("spreadsheet builder not provided via DataGridSettings.Init()");
            };

            DataGridSettings.Init(spreadsheetBuilder ?? noExportImpl);

            Document.OnDragEnter += ev => {
                Document.Body.SetAttribute(Magics.AttrDataDraggingFile, "x");
                ev.PreventDefault();
            };
            //detect real end of dragging (leaving outside of browser)
            //https://stackoverflow.com/questions/3144881/how-do-i-detect-a-html5-drag-event-entering-and-leaving-the-window-like-gmail-d#14248483
            Document.OnDragLeave += ev => {
                var clientX = (int)ev.GetFieldValue("clientX");
                var clientY = (int)ev.GetFieldValue("clientY");

                if (clientX <= 0 || clientY <= 0)
                {
                    Document.Body.RemoveAttribute(Magics.AttrDataDraggingFile);
                }

                Logger.Debug(typeof(Toolkit), "Document dragleave {0}", ev.Target);
            };

            switch (env)
            {
            case EnvironmentType.Desktop:
                BaseFormCanvasTitleStrategy           = x => new RegularDomElementTitleFormCanvasStrategy(x);
                BaseFormCanvasExitButtonBuilderOrNull = DefaultExitButtonBuilder;
                ClickingOutsideOfDialogDismissesIt    = clickingOutsideOfDialogDismissesIt ?? false;
                break;

            case EnvironmentType.IndustrialAndroidWebApp:
                BaseFormCanvasTitleStrategy           = x => new BodyBasedPropagatesToAppBatTitleFormCanvasStrategy(x);
                BaseFormCanvasExitButtonBuilderOrNull = null;
                ClickingOutsideOfDialogDismissesIt    = clickingOutsideOfDialogDismissesIt ?? true;

                IawAppApi.SetOnBackPressed(() => {
                    Logger.Debug(typeof(Toolkit), "backbutton pressed");
                    var consumed = DocumentUtil.TryCloseTopMostForm();
                    Logger.Debug(typeof(Toolkit), "backbutton consumed?={0}", consumed);
                    return(consumed);
                });
                break;

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