Ejemplo n.º 1
0
        internal List <Field> GetNavigationFields()
        {
            // was: FirstOrDefault
            var hierarchy = RelationshipsAsChild.SingleOrDefault(r => r.Hierarchy);

            var result = new List <Field>();

            foreach (var field in KeyFields.OrderBy(f => f.SortPriority))
            {
                // exclude field if hierarchichal parent has field of same name
                // this is used to ignore/exclude a multi-field primary key on an entity that
                // is a hierarchical child of the repeated parent key.
                // example: WRC project: customer is hierarchical parent of consumption.
                //          key on consumption = customer + consumptionSet.
                //          url must NOT be: customer/:customerId/consumption/:customerId/:consumptionSetId
                //          as that would repeat the :customerId param, which is not allowed.
                //  because it is hierarchical, just need the parent's :customerId

                if (hierarchy == null || !hierarchy.ParentEntity.KeyFields.Any(f => f.Name == field.Name))
                {
                    result.Add(field);
                }
            }

            if (hierarchy != null)
            {
                var parentResult = hierarchy.ParentEntity.GetNavigationFields();
                result.InsertRange(0, parentResult);
            }

            return(result);
        }
Ejemplo n.º 2
0
        internal Relationship GetParentSearchRelationship(Field field)
        {
            // field must be in a relationship of this entity, where the field is (part of) the key of the related entity
            var relationship = RelationshipsAsChild.Single(r => r.RelationshipFields.Any(f => f.ChildFieldId == field.FieldId && f.ParentField.KeyField));

            //if (relationship.RelationshipFields.Count() != 1) throw new Exception("Can't have a search field that is part of a multi-field key");
            return(relationship);
        }
Ejemplo n.º 3
0
        internal List <Field> GetNonHierarchicalKeyFields()
        {
            var parentRel = RelationshipsAsChild.SingleOrDefault(o => o.Hierarchy);

            // exclude parent entity fields
            // example: in African POT, where the Team entity has a composite key of projectid + userid
            //          and the team is a hierarchical child on the project: the url should be '/projects/{projectid}/team/{userid}
            //          without excluding, the url was: '/projects/{projectid}/team/{projectid}/{userid}
            //          i.e. duplicating projectid
            if (parentRel == null || parentRel.IsOneToOne)
            {
                return(KeyFields);
            }
            return(KeyFields.Where(o => !o.RelationshipFieldsAsChild.Any(rf => rf.ParentField.EntityId == parentRel.ParentEntityId)).ToList());
        }
Ejemplo n.º 4
0
        internal List <SearchResultColumn> GetSearchResultsFields(Entity currentEntity)
        {
            var result = new List <SearchResultColumn>();

            foreach (var field in Fields.Where(f => f.ShowInSearchResults).OrderBy(f => f.FieldOrder))
            {
                if (RelationshipsAsChild.Any(r => r.RelationshipFields.Any(f => f.ChildFieldId == field.FieldId)))
                {
                    var rel = RelationshipsAsChild.Single(r => r.RelationshipFields.Any(f => f.ChildFieldId == field.FieldId));
                    if (rel.ParentEntity == currentEntity)
                    {
                        continue;
                    }

                    result.Add(new SearchResultColumn {
                        Header = rel.ParentEntity.FriendlyName, Value = $"{{{{ { field.Entity.Name.ToCamelCase()}.{ rel.ParentName.ToCamelCase() }.{ rel.ParentField.Name.ToCamelCase() } }}}}"
                    });
                }
                else
                {
                    var column = new SearchResultColumn {
                        Header = field.Label
                    };
                    if (field.FieldType == FieldType.Enum)
                    {
                        column.Value = $"{{{{ vm.appSettings.find(vm.appSettings.{ field.Lookup.Name.ToCamelCase() }, {field.Entity.Name.ToCamelCase()}.{ field.Name.ToCamelCase() }).label }}}}";
                    }
                    else if (field.FieldType == FieldType.Bit)
                    {
                        column.Value = $"{{{{ { field.Entity.Name.ToCamelCase()}.{ field.Name.ToCamelCase() } ? \"Yes\" : \"No\" }}}}";
                    }
                    else if (field.FieldType == FieldType.Date)
                    {
                        column.Value = $"{{{{ { field.Entity.Name.ToCamelCase()}.{ field.Name.ToCamelCase() } | toLocaleDateString }}}}";
                    }
                    else
                    {
                        column.Value = $"{{{{ { field.Entity.Name.ToCamelCase()}.{ field.Name.ToCamelCase() } }}}}";
                    }
                    result.Add(column);
                }
            }

            return(result);
        }
Ejemplo n.º 5
0
        internal List <Field> GetNavigationFields()
        {
            var result = new List <Field>();

            foreach (var field in KeyFields.OrderBy(f => f.SortPriority))
            {
                result.Add(field);
            }

            // todo: if more than one relationship, will this FirstOrDefault randomly choose the wrong one?
            var relationship = RelationshipsAsChild.FirstOrDefault(r => r.Hierarchy);

            if (relationship != null)
            {
                var parentResult = relationship.ParentEntity.GetNavigationFields();
                result.InsertRange(0, parentResult);
            }

            return(result);
        }
Ejemplo n.º 6
0
        internal List <SearchResultColumn> GetSearchResultsFields(Entity currentEntity)
        {
            var result = new List <SearchResultColumn>();

            foreach (var field in Fields.Where(f => f.ShowInSearchResults).OrderBy(f => f.FieldOrder))
            {
                if (RelationshipsAsChild.Any(r => r.RelationshipFields.Any(f => f.ChildFieldId == field.FieldId)))
                {
                    var rel = RelationshipsAsChild.Single(r => r.RelationshipFields.Any(f => f.ChildFieldId == field.FieldId));
                    if (rel.ParentEntity == currentEntity)
                    {
                        continue;
                    }

                    var value = string.Empty;
                    if (rel.ParentEntity.PrimaryField.FieldType == FieldType.Enum)
                    {
                        if (field.IsNullable)
                        {
                            throw new Exception("unhandled: what now!?");
                        }
                        value = $"{{{{ {rel.ParentEntity.PrimaryField.Lookup.PluralName.ToCamelCase()}[{ field.Entity.Name.ToCamelCase()}.{ rel.ParentName.ToCamelCase() }.{ rel.ParentField.Name.ToCamelCase() }].label }}}}";
                    }
                    else
                    {
                        value = $"{{{{ { field.Entity.Name.ToCamelCase()}.{ rel.ParentName.ToCamelCase() + (field.IsNullable ? "?" : "") }.{ rel.ParentField.Name.ToCamelCase() } }}}}";
                    }

                    result.Add(new SearchResultColumn
                    {
                        Header            = rel.ParentEntity.FriendlyName,
                        Value             = value,
                        IsOnAnotherEntity = true
                    });
                }
                else
                {
                    var column = new SearchResultColumn {
                        Header = field.Label, IsOnAnotherEntity = false
                    };
                    // these should use local formats?
                    if (field.FieldType == FieldType.Enum)
                    {
                        column.Value = $"{{{{ {field.Lookup.PluralName.ToCamelCase()}[{field.Entity.Name.ToCamelCase()}.{ field.Name.ToCamelCase() }].label }}}}";
                    }
                    else if (field.FieldType == FieldType.Bit)
                    {
                        column.Value = $"{{{{ { field.Entity.Name.ToCamelCase()}.{ field.Name.ToCamelCase() } | booleanPipe }}}}";
                    }
                    else if (field.FieldType == FieldType.Money)
                    {
                        column.Value = $"{{{{ { field.Entity.Name.ToCamelCase()}.{ field.Name.ToCamelCase() } | currency }}}}";
                    }
                    else if (field.FieldType == FieldType.Date)
                    {
                        column.Value = $"{{{{ { field.Entity.Name.ToCamelCase()}.{ field.Name.ToCamelCase() } | momentPipe: 'DD MMM YYYY' }}}}";
                    }
                    else if (field.FieldType == FieldType.DateTime || field.FieldType == FieldType.SmallDateTime)
                    {
                        column.Value = $"{{{{ { field.Entity.Name.ToCamelCase()}.{ field.Name.ToCamelCase() } | momentPipe: 'DD MMM YYYY HH:mm' }}}}";
                    }
                    else
                    {
                        column.Value = $"{{{{ { field.Entity.Name.ToCamelCase()}.{ field.Name.ToCamelCase() } }}}}";
                    }
                    result.Add(column);
                }
            }

            return(result);
        }