Esempio n. 1
0
        void MapColumns(IEnumerable <ColumnBase> columns)
        {
            if (!_handledIdentity)
            {
                _handledIdentity = true;
                if (_bp.From == null)
                {
                    throw new NotImplementedException("Must have an Entity - did you forget to set the From");
                }
                if (_bp.From.PrimaryKeyColumns == null || _bp.From.PrimaryKeyColumns.Length == 0)
                {
                    throw new NotImplementedException("Entity must have a primary key");
                }

                if (_bp.From.PrimaryKeyColumns.Length == 1)
                {
                    _idColumn = _bp.From.PrimaryKeyColumns[0];
                }
                else
                {
                    _idColumn = new TextColumn("id").BindValue(() =>
                    {
                        var x = new SeperatedBuilder();
                        foreach (var item in _bp.From.PrimaryKeyColumns)
                        {
                            x.Add(DataItem.FixValueTypes(item.Value));
                        }
                        return(x.ToString());
                    });
                    Columns.Add(_bp.From.PrimaryKeyColumns);
                    Columns.Add(_idColumn);
                    IgnoreUpdateOf(_idColumn);
                }
            }
            foreach (var column in columns)
            {
                string name = column.Caption;
                if (column == _idColumn)
                {
                    name = "id";
                }
                name = NameFixer.fixName(name);
                var orgName = name;
                int i       = 1;
                while (_colsPerKey.ContainsKey(name))
                {
                    name = orgName + (i++).ToString();
                }
                var cv = new ColumnInViewModel(name, () => column.Value, v =>
                {
                    Caster.Cast(column, v, new setValueForColumn());
                }, column);
                _colMap.Add(column, cv);
                _colsPerKey.Add(name, cv);
                _columns.Add(cv);
                Columns.Add(column);
            }
        }
Esempio n. 2
0
        internal void CreateTypeScriptInterface(TextWriter tw, string name, string url)
        {
            var singular = NameFixer.MakeSingular(name);


            tw.WriteLine("export interface " + singular + " {");
            init();
            foreach (var item in _columns)
            {
                tw.WriteLine($"    {item.Key}?:{item.getJsonType()};");
            }
            tw.WriteLine("}");
        }
Esempio n. 3
0
        public void CreateTypeScriptInterface(TextWriter tw, string name, string url)
        {
            var singular = NameFixer.MakeSingular(name);


            tw.WriteLine($@"export class {name} extends radweb.DataSettings&lt;{singular}&gt;{{
    constructor(settings?: radweb.IDataSettings&lt;{singular}&gt;) {{
        super(environment.apiUrl + '{url}', settings);
    }}
}}");
            tw.WriteLine("export interface " + singular + " {");
            init();
            foreach (var item in _columns)
            {
                tw.WriteLine($"    {item.Key}?:{item.getJsonType()};");
            }
            tw.WriteLine("}");
        }
Esempio n. 4
0
        public void MapColumn(ColumnBase column, string name = null)
        {
            if (!_handledIdentity)
            {
                _handledIdentity = true;
                if (_bp.From == null)
                {
                    throw new NotImplementedException("Must have an Entity - did you forget to set the From");
                }
                if (_bp.From.PrimaryKeyColumns == null || _bp.From.PrimaryKeyColumns.Length == 0)
                {
                    throw new NotImplementedException("Entity must have a primary key");
                }

                if (_bp.From.PrimaryKeyColumns.Length == 1)
                {
                    _idColumn = _bp.From.PrimaryKeyColumns[0];
                }
                else
                {
                    _idColumn = new TextColumn("id").BindValue(() =>
                    {
                        var x = new SeperatedBuilder();
                        foreach (var item in _bp.From.PrimaryKeyColumns)
                        {
                            x.Add(DataItem.FixValueTypes(item.Value));
                        }
                        return(x.ToString());
                    });
                    Columns.Add(_bp.From.PrimaryKeyColumns);
                    Columns.Add(_idColumn);
                    IgnoreUpdateOf(_idColumn);
                }
            }
            if (name == null)
            {
                if (UseClassMemberName)
                {
                    if (column.Entity != null)
                    {
                        foreach (var item in column.Entity.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
                        {
                            if (item.GetValue(column.Entity) == column)
                            {
                                name = item.Name;
                            }
                        }
                    }
                    else
                    {
                        foreach (var item in this.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
                        {
                            if (item.GetValue(this) == column)
                            {
                                name = item.Name;
                            }
                        }
                    }
                    if (name != null)
                    {
                        if (name.Length > 1)
                        {
                            name = name[0].ToString().ToLower() + name.Substring(1);
                        }
                        if (name.Length == 1)
                        {
                            name = name.ToLower();
                        }
                    }
                    if (column.Entity != null && column.Entity != From)
                    {
                        foreach (var item in this.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
                        {
                            if (item.GetValue(this) == column.Entity)
                            {
                                name = item.Name + "_" + name;
                                name = name[0].ToString().ToLower() + name.Substring(1);
                            }
                        }
                    }
                }
                if (name == null)
                {
                    name = column.Caption;
                    if (NameFixer.HasHebrewInIt(name) && !string.IsNullOrEmpty(column.Name) && UseNameInsteadOfCaptionForHebrew)
                    {
                        name = column.Name;
                    }
                    name = SeparateWordsAndCasing(name);
                }
            }

            if (column == _idColumn)
            {
                name = "id";
            }

            name = NameFixer.fixName(name);
            var orgName = name;
            int i       = 1;

            while (_colsPerKey.ContainsKey(name.ToUpper()))
            {
                name = orgName + (i++).ToString();
            }
            var cv = new ColumnInViewModel(name, () => column.Value, v =>
            {
                Caster.Cast(column, v, new setValueForColumn());
            }, column);

            _colMap.Add(column, cv);
            _colsPerKey.Add(name.ToUpper(), cv);
            _columns.Add(cv);
            Columns.Add(column);
        }