Ejemplo n.º 1
0
        public override bool Initialise()
        {
            EditorRedirect.Instance.Register(typeof(List<User>), new ListEditorRedirect(new List<string> { "UserName", "Email", "Created", "Modified", "Roles" }));

            // Set up Url Management
            UrlRequestInterceptor.Register();

            // Set up base UI
            LyniconUi.Instance.FuncPanelButtons.Add(new FuncPanelButton
            {
                Id = "fpbMainLogout",
                Caption = "Log Out",
                DisplayPermission = new ContentPermission("E"),
                Url = "/Lynicon/Login/Logout?returnUrl=$$CurrentUrl$$",
                Section = "Global"
            });
            LyniconUi.Instance.FuncPanelButtons.Add(new FuncPanelButton
            {
                Id = "fpbMainLogin",
                Caption = "Log In",
                DisplayPermission = new ContentPermission { RolesPermitted = roles => !roles.Contains("E") },
                Url = "/Lynicon/Login",
                Section = "Global"
            });
            LyniconUi.Instance.FuncPanelButtons.Add(new FuncPanelButton
            {
                Id = "fpbListItems",
                Caption = "List",
                DisplayPermission = new ContentPermission("E"),
                Url = "/Lynicon/Items",
                Section = "Global"
            });
            LyniconUi.Instance.FuncPanelButtons.Add(new FuncPanelButton
            {
                Id = "fpbFilterItems",
                Caption = "Filtering",
                DisplayPermission = new ContentPermission("E"),
                Url = "/Lynicon/Items/List",
                Section = "Global"
            });
            LyniconUi.Instance.FuncPanelButtons.Add(new FuncPanelButton
            {
                Id = "fpbAdmin",
                Caption = "Admin",
                DisplayPermission = new ContentPermission("A"),
                Url = "/Lynicon/Admin",
                Section = "Global"
            });
            LyniconUi.Instance.FuncPanelButtons.Add(new FuncPanelButton
            {
                Id = "fpbUsers",
                Caption = "Users",
                DisplayPermission = new ContentPermission("A"),
                Url = "/Lynicon/Users?$orderby=Email&$top=15",
                Section = "Global"
            });

            LyniconUi.Instance.FuncPanelButtons.Add(new FuncPanelButton
            {
                Id = "save",
                Caption = "SAVE",
                DisplayPermission = new ContentPermission("E"),
                Section = "Record",
                BackgroundColor = "#cbdfdf"
            });
            LyniconUi.Instance.FuncPanelButtons.Add(new FuncPanelButton
            {
                Id = "fpbMainDelete",
                Caption = "Delete",
                DisplayPermission = new ContentPermission("A"),
                ClientClickScript = @"var $itemIdx = $('#lynicon_itemIndex');
                    var data = ($itemIdx.length > 0 ? { idx: $itemIdx.val() } : {});
                    if (!confirm('Are you sure you want to delete this item?'))
                        return;
                    $.post(""$$BaseUrl$$?$mode=delete$$OriginalQuery$$"",
                    data, function (res) {
                        window.location = window.location.href;
                    });",
                Section = "Record",
                BackgroundColor = "#8c8c8c"
            });

            var modifiedWhenFilter = new DateFieldFilter("Modified When", typeof(IBasicAuditable).GetProperty("Updated"));
            LyniconUi.Instance.Filters.Add(modifiedWhenFilter);
            var modifiedByFilter = new ForeignKeyFilter("Modified By", typeof(User), "UserName", typeof(IBasicAuditable).GetProperty("UserUpdated"));
            LyniconUi.Instance.Filters.Add(modifiedByFilter);
            var createdWhenFilter = new DateFieldFilter("Created When", typeof(IBasicAuditable).GetProperty("Created"));
            LyniconUi.Instance.Filters.Add(createdWhenFilter);
            var createdByFilter = new ForeignKeyFilter("Created By", typeof(User), "UserName", typeof(IBasicAuditable).GetProperty("UserCreated"));
            LyniconUi.Instance.Filters.Add(createdByFilter);

            return true;
        }
Ejemplo n.º 2
0
        public override bool Initialise()
        {
            log.Info("Starting Core Module");

            // Set up Url Management
            UrlRequestInterceptor.Register();

            // Set up base UI
            LyniconUi.Instance.FuncPanelButtons.Add(new FuncPanelButton
            {
                Id                = "fpbMainLogout",
                Caption           = "Log Out",
                DisplayPermission = new ContentPermission("E"),
                Url               = "/Lynicon/Login/Logout?returnUrl=$$CurrentUrl$$",
                Section           = "Global"
            });
            LyniconUi.Instance.FuncPanelButtons.Add(new FuncPanelButton
            {
                Id                = "fpbMainLogin",
                Caption           = "Log In",
                DisplayPermission = new ContentPermission {
                    TestPermitted = (roles, data) => !roles.Contains("E")
                },
                Url     = "/Lynicon/Login?returnUrl=$$CurrentUrl$$",
                Section = "Global"
            });
            LyniconUi.Instance.FuncPanelButtons.Add(new FuncPanelButton
            {
                Id                = "fpbListItems",
                Caption           = "List",
                DisplayPermission = new ContentPermission("E"),
                Url               = "/Lynicon/Items",
                Section           = "Global"
            });
            LyniconUi.Instance.FuncPanelButtons.Add(new FuncPanelButton
            {
                Id                = "fpbFilterItems",
                Caption           = "Filtering",
                DisplayPermission = new ContentPermission("E"),
                Url               = "/Lynicon/Items/List",
                Section           = "Global"
            });
            LyniconUi.Instance.FuncPanelButtons.Add(new FuncPanelButton
            {
                Id                = "fpbAdmin",
                Caption           = "Admin",
                DisplayPermission = new ContentPermission("A"),
                Url               = "/Lynicon/Admin",
                Section           = "Global"
            });
            LyniconUi.Instance.FuncPanelButtons.Add(new FuncPanelButton
            {
                Id                = "fpbUsers",
                Caption           = "Users",
                DisplayPermission = new ContentPermission("A"),
                Url               = "/Lynicon/Users?$orderby=Email&$top=15",
                Section           = "Global"
            });

            LyniconUi.Instance.FuncPanelButtons.Add(new FuncPanelButton
            {
                Id              = "save",
                Caption         = "SAVE",
                DisplayPolicy   = "CanEditData",
                Section         = "Record",
                BackgroundColor = "#cbdfdf"
            });
            LyniconUi.Instance.FuncPanelButtons.Add(new FuncPanelButton
            {
                Id                = "fpbMainDelete",
                Caption           = "Delete",
                DisplayPolicy     = "CanDeleteData",
                ClientClickScript = @"var $itemIdx = $('#lynicon_itemIndex');
                    var data = ($itemIdx.length > 0 ? { idx: $itemIdx.val() } : {});
                    if (!confirm('Are you sure you want to delete this item?'))
                        return;
                    $.post(""$$BaseUrl$$?$mode=delete$$OriginalQuery$$"",
                    data, function (res) {
                        window.location = window.location.href;
                    });",
                Section           = "Record",
                BackgroundColor   = "#8c8c8c"
            });

            var modifiedWhenFilter = new DateFieldFilter("Modified When", typeof(IBasicAuditable).GetProperty("Updated"));

            LyniconUi.Instance.Filters.Add(modifiedWhenFilter);
            var modifiedByFilter = new ForeignKeyFilter("Modified By", typeof(User), "UserName", typeof(IBasicAuditable).GetProperty("UserUpdated"));

            LyniconUi.Instance.Filters.Add(modifiedByFilter);
            var createdWhenFilter = new DateFieldFilter("Created When", typeof(IBasicAuditable).GetProperty("Created"));

            LyniconUi.Instance.Filters.Add(createdWhenFilter);
            var createdByFilter = new ForeignKeyFilter("Created By", typeof(User), "UserName", typeof(IBasicAuditable).GetProperty("UserCreated"));

            LyniconUi.Instance.Filters.Add(createdByFilter);

            log.Info("Core Module Initialised");

            return(true);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Copies all values entered by the user to a DavaValueInstance collection
        /// </summary>
        /// <param name="members">Collection where values will be copied to</param>
        public Filter GetFilter(MemberInfo member)
        {
            //validate arguments
            if (member == null)
            {
                throw new ArgumentNullException(nameof(member));
            }

            //filters
            Filter filter = null;

            DataType dtype      = member.DeclaringType;
            Type     returnType = MemberExpression.GetReturnType(member);

            //is this a single value member? (not a foreign key?)
            if (dtype.IsMapped(member.Name))
            {
                DataMember dmember = dtype[member.Name];

                #region Range filter

                //if it's a datetime or a numeric field, create range filter
                if (returnType.Equals(typeof(DateTime)) || returnType.IsNumeric())
                {
                    //realted fields
                    FormField fieldMin = null, fieldMax = null;

                    //search corresponding field for this DataValueInstance
                    foreach (FormField f in Fields)
                    {
                        if (f.Name == member.Name + "_0")
                        {
                            fieldMin = f;
                        }
                        if (f.Name == member.Name + "_1")
                        {
                            fieldMax = f;
                        }
                    }

                    //if no controls where found, return no filter
                    if (fieldMin == null && fieldMax == null)
                    {
                        return(null);
                    }

                    //if no value was set, return no filter
                    if (!RequiredValidator.HasValue(fieldMin.Value) && !RequiredValidator.HasValue(fieldMax.Value))
                    {
                        return(null);
                    }

                    //if both values are set, create range filter
                    if (RequiredValidator.HasValue(fieldMin.Value) && RequiredValidator.HasValue(fieldMax.Value))
                    {
                        filter = new RangeFilter(dmember, (IComparable)fieldMin.Value, (IComparable)fieldMax.Value);
                    }

                    //only min value is defined
                    else if (RequiredValidator.HasValue(fieldMin.Value))
                    {
                        filter = new ValueCompareFilter(dmember, (IComparable)fieldMin.Value, CompareOperator.GreaterThanEqual);
                    }

                    //only max value is defined
                    else if (RequiredValidator.HasValue(fieldMax.Value))
                    {
                        filter = new ValueCompareFilter(dmember, (IComparable)fieldMax.Value, CompareOperator.LessThanEqual);
                    }
                }

                #endregion

                #region Single value filter

                //create single value filter
                else
                {
                    //realted fields
                    FormField field = Fields.Where(f => f.Name == member.Name).SingleOrDefault();

                    //if field not found, return no filter
                    if (field == null)
                    {
                        return(null);
                    }

                    //if no value was set, return no filter
                    if (!RequiredValidator.HasValue(field.Value))
                    {
                        return(null);
                    }

                    //if its a string, make a LIKE filter
                    else if (field.ValueType.Equals(typeof(string)))
                    {
                        filter = new LikeFilter(dmember, "%" + field.Value + "%");
                    }

                    //otherwise create a compare filter
                    else
                    {
                        filter = new ValueCompareFilter(dmember, (IComparable)field.Value, CompareOperator.Equal);
                    }
                }

                #endregion
            }
            //this is a foreign key
            else if (DataType.IsMapped(returnType) && dtype.IsForeignKey(member))
            {
                //realted fields
                FormField field = Fields.Where(f => f.Name == member.Name).SingleOrDefault();

                //if field not found, return no filter
                if (field == null)
                {
                    return(null);
                }

                //if no value was set, return no filter
                if (!RequiredValidator.HasValue(field.Value))
                {
                    return(null);
                }

                filter = new ForeignKeyFilter(dtype, member, field.Value);
            }

            return(filter);
        }