protected override IMetaNode VisitSchema(ContentRepository.Schema.Metadata.Schema schema)
        {
            // do not call the base functionality

            #region Write filestart
            _writer.WriteLine(@"/**
 *
 * @module Enums
 *
 * @preferred
 *
 * @description Module for enums types defined in SenseNet helps you to use enums with dot notation.
 *
 * This module is autogenerated from Sense/Net metadata (/Odata/$metadata)
 *
 * ```
 * const car = new ContentTypes.Car({
 *  Id: 1,
 *  Name: 'MyCar',
 *  DisplayName: 'My Car',
 *  Style: Style.Cabrio
 * });
 * ```
 */
");
            #endregion

            foreach (var enumeration in Context.Enumerations)
            {
                Visit(enumeration);
            }

            return(schema);
        }
Exemple #2
0
        protected override IMetaNode VisitSchema(ContentRepository.Schema.Metadata.Schema schema)
        {
            _writer.WriteLine(@"/**
 * The Content Repository contains many different types of *Content*. *Content* vary in structure and even in function.
 *
 * Different types of content contain different fields, are displayed with different views, and may also implement different business logic. The fields, views and business logic of a content is defined by its type - the Content Type.
 *
 * Content Types are defined in a type hierarchy: a Content Type may be inherited from another Content Type - thus automatically inheriting its fields.
 *
 * This module represents the above mentioned type hierarchy by Typescript classes with the Content Types' Fields as properties. With Typescript classes we can derive types from another
 * inheriting its properties just like Content Types in the Content Repository. This module provides us to create an objects with a type so that we can validate on its properties by their
 * types or check the required ones.
 *
 */

import { ActionModel } from './ActionModel'
import * as ComplexTypes from './ComplexTypes'
import * as Enums from './Enums'

export type ContentReferenceField<T> = ComplexTypes.DeferredObject | T | number
export type ContentListReferenceField<T> = ComplexTypes.DeferredObject | T[] | number[]

export type BinaryField = ComplexTypes.MediaResourceObject
");

            // Do not call base because only classes will be read.
            Visit(schema.Classes);
            return(schema);
        }
Exemple #3
0
        protected override IMetaNode VisitSchema(ContentRepository.Schema.Metadata.Schema schema)
        {
            _writer.WriteLine(@"/**
 * 
 * @module ContentTypes
 * @preferred
 * 
 * 
 * @description The Content Repository contains many different types of ```Content```. ```Content``` vary in structure and even in function. Different types of content contain different fields,
 * are displayed with different views, and may also implement different business logic. The fields, views and business logic of a content is defined by its type - the Content Type.
 *
 * Content Types are defined in a type hierarchy: a Content Type may be inherited from another Content Type - thus automatically inheriting its fields.
 *
 * This module represents the above mentioned type hierarchy by Typescript classes with the Content Types' Fields as properties. With Typescript classes we can derive types from another
 * inheriting its properties just like Content Types in the Content Repository. This module provides us to create an objects with a type so that we can validate on its properties by their
 * types or check the required ones.
 * 
 *//** */
import { Content, IContentOptions } from './Content';
import { Enums, FieldSettings, ComplexTypes } from './SN';
import { BaseRepository } from './Repository';

");

            // Do not call base because only classes will be read.
            _indentCount++;
            Visit(schema.Classes);
            _indentCount--;

            return(schema);
        }
        protected override IMetaNode VisitSchema(ContentRepository.Schema.Metadata.Schema schema)
        {
            #region Write filestart
            _writer.WriteLine(@"/**
 * @module Schemas
 * @preferred
 * @description Module for ContentType schemas.
 *
 * A Content Type Definition in Sense/Net is an xml-format configuration file for defining Content Types. The xml configuration (CTD) holds information about the types name and description
 * properties that control how content of this type look and behave (icon, preview generation, indexing), set of fields, etc. This information about the type and its Fields helps us for example
 * building forms. Based on the Field definitions we can render a Field with its DisplayName as a label or validate the Field on save by its validation related configs.
 *
 * This module provides us description of this Content schemas in Typesript.
 *
 * The ```Schema``` class represents an object that holds the basic information about the Content Type (name, icon, ect.) and an array of its ```FieldSettings``` and their full configuration.
 */ /** */

import { FieldSettings, Content, ContentTypes } from './SN';

    /**
     * Class that represents a Schema.
     *
     * It represents an object that holds the basic information about the Content Type (name, icon, ect.) and an array of its ```FieldSettings``` and their full configuration.
     */
    export class Schema<TContentType extends Content> {
        ContentType: {new(...args): TContentType}
        Icon: string;
        DisplayName: string;
        Description: string;
        AllowIndexing: boolean;
        AllowIncrementalNaming: boolean;
        AllowedChildTypes: string[];
        FieldSettings: FieldSettings.FieldSetting[];

        constructor(schema: Partial<Schema<TContentType>>){
            Object.assign(this, schema);
        }
    }

    export const SchemaStore: Schema<Content>[] = [
");
            #endregion

            // Do not call base because only classes will be read.
            _indentCount++;
            Visit(schema.Classes);
            _indentCount--;

            _writer.WriteLine(@"]");
            return(schema);
        }
        protected override IMetaNode VisitSchema(ContentRepository.Schema.Metadata.Schema schema)
        {
            #region Write filestart
            _writer.WriteLine(@"/**
 * @module Schemas
 * @preferred
 * @description Module for ContentType schemas.
 *
 * A Content Type Definition in Sense/Net is an xml-format configuration file for defining Content Types. The xml configuration (CTD) holds information about the types name and description
 * properties that control how content of this type look and behave (icon, preview generation, indexing), set of fields, etc. This information about the type and its Fields helps us for example
 * building forms. Based on the Field definitions we can render a Field with its DisplayName as a label or validate the Field on save by its validation related configs.
 *
 * This module provides us description of this Content schemas in Typesript.
 *
 * The ```Schema``` class represents an object that holds the basic information about the Content Type (name, icon, ect.) and an array of its ```FieldSettings``` and their full configuration.
 */

import * as FieldSettings from './FieldSettings'

/**
 * Class that represents a Schema.
 *
 * It represents an object that holds the basic information about the Content Type (name, icon, ect.) and an array of its ```FieldSettings``` and their full configuration.
 */
export class Schema {
     public ContentTypeName!: string
     public ParentTypeName?: string
     public Icon!: string
     public DisplayName!: string
     public Description!: string
     public AllowIndexing!: boolean
     public AllowIncrementalNaming!: boolean
     public AllowedChildTypes!: string[]
     public FieldSettings!: FieldSettings.FieldSetting[]
}

export const SchemaStore: Schema[] = [
");
            #endregion

            // Do not call base because only classes will be read.
            _indentCount++;
            Visit(schema.Classes);
            _indentCount--;

            _writer.WriteLine(@"];");
            _writer.WriteLine();
            return(schema);
        }
        /// <inheritdoc />
        protected override void WriteMetadata(System.IO.TextWriter writer, Metadata.Edmx edmx)
        {
            var requestedModule = HttpContext.Current.Request["module"]?.ToLowerInvariant();

            if (string.IsNullOrEmpty(requestedModule))
            {
                requestedModule = "classes";
            }

            var schema0 = new ContentRepository.Schema.Metadata.Schema(new[] { "Application", "ApplicationCacheFile", "FieldSettingContent", "JournalNode" });
            var context = new TypescriptGenerationContext();
            var schema1 = new TypescriptTypeCollectorVisitor(context).Visit(schema0);

            switch (requestedModule)
            {
            case "enums":
                new TypescriptEnumsVisitor(context, writer).Visit(schema1);
                break;

            case "complextypes":
                new TypescriptComplexTypesVisitor(context, writer).Visit(schema1);
                break;

            case "contenttypes":
                new TypescriptClassesVisitor(context, writer).Visit(schema1);
                break;

            case "resources":
                ResourceWriter.WriteResourceClasses(writer);
                break;

            case "schemas":
                new TypescriptCtdVisitor(context, writer).Visit(schema1);
                break;

            case "fieldsettings":
                new TypescriptFieldSettingsVisitor(context, writer).Visit(schema1);
                break;

            default:
                throw new InvalidOperationException("Unknown module name: " + requestedModule
                                                    + ". Valid names: enums, complextypes, contenttypes, resources, schemas, fieldsettings.");
            }
        }
Exemple #7
0
        protected override IMetaNode VisitSchema(ContentRepository.Schema.Metadata.Schema schema)
        {
            _writer.WriteLine(@"//file: ContentTypes.ts
import { " + TypescriptGenerationContext.EnumTypesModuleName + @" } from './" + TypescriptGenerationContext.EnumTypesModuleName + @"';
import { FieldSettings } from './FieldSettings';
import { " + TypescriptGenerationContext.ComplexTypesModuleName + @" } from './" + TypescriptGenerationContext.ComplexTypesModuleName + @"';
import { Content, IContentOptions } from './Content';

/**
 * The Content Repository contains many different types of ```Content```. ```Content``` vary in structure and even in function. Different types of content contain different fields,
 * are displayed with different views, and may also implement different business logic. The fields, views and business logic of a content is defined by its type - the Content Type.
 *
 * Content Types are defined in a type hierarchy: a Content Type may be inherited from another Content Type - thus automatically inheriting its fields.
 *
 * This module represents the above mentioned type hierarchy by Typescript classes with the Content Types' Fields as properties. With Typescript classes we can derive types from another
 * inheriting its properties just like Content Types in the Content Repository. This module provides us to create an objects with a type so that we can validate on its properties by their
 * types or check the required ones.
 */

export module ContentTypes {");

            // Do not call base because only classes will be read.
            _indentCount++;
            Visit(schema.Classes);
            _indentCount--;

            _writer.WriteLine(@"}

/**
 * Creates a Content object by the given type and options Object that hold the field values.
 * @param type {string} The Content will be a copy of the given type.
 * @param options {SenseNet.IContentOptions} Optional list of fields and values.
 * @returns {SenseNet.Content}
 * ```ts
 * var content = SenseNet.Content.Create('Folder', { DisplayName: 'My folder' }); // content is an instance of the Folder with the DisplayName 'My folder'
 * ```
 */
export function CreateContent<T>(type: string, options: IContentOptions = {}): Content {
    let content = new ContentTypes[type](options);
    return content;
}");
            return(schema);
        }
        protected override IMetaNode VisitSchema(ContentRepository.Schema.Metadata.Schema schema)
        {
            // do not call the base functionality

            #region Write filestart
            _writer.WriteLine(@"//file: " + TypescriptGenerationContext.EnumTypesModuleName + @".ts
/**
 * Module for enums types defined in SenseNet helps you to use enums with dot notation. 
 * 
 * This module is autogenerated from Sense/Net metadata (/Odata/$metadata)
 * 
 * ```
 * let car = new ContentTypes.Car({
 *  Id: 1,
 *  Name: 'MyCar',
 *  DisplayName: 'My Car',
 *  Style: Enum.Style.Cabrio
 * });
 * ```
 */

export module " + TypescriptGenerationContext.EnumTypesModuleName + @" {");
            #endregion

            _indentCount++;
            foreach (var enumeration in Context.Enumerations)
            {
                Visit(enumeration);
            }
            _indentCount--;

            #region Write fileend
            _writer.WriteLine(@"}
");
            #endregion

            return(schema);
        }
        protected virtual void WriteMetadata(TextWriter writer, string requestedModule)
        {
            var context = new TypescriptGenerationContext();
            var schema0 = new ContentRepository.Schema.Metadata.Schema(new[]
                                                                       { "Application", "ApplicationCacheFile", "FieldSettingContent", "JournalNode" });
            var schema1 = new TypescriptTypeCollectorVisitor(context).Visit(schema0);

            switch (requestedModule)
            {
            case "enums":
                new TypescriptEnumsVisitor(context, writer).Visit(schema1);
                break;

            case "complextypes":
                new TypescriptComplexTypesVisitor(context, writer).Visit(schema1);
                break;

            case "contenttypes":
                new TypescriptClassesVisitor(context, writer).Visit(schema1);
                break;

            case "resources":
                ResourceWriter.WriteResourceClasses(writer);
                break;

            case "schemas":
                new TypescriptCtdVisitor(context, writer).Visit(schema1);
                break;

            case "fieldsettings":
                new TypescriptFieldSettingsVisitor(context, writer).Visit(schema1);
                break;

            default:
                throw new InvalidOperationException(
                          $"Unknown module name: {requestedModule}. Valid names: {string.Join(", ", ModuleNames)}");
            }
        }
        protected override IMetaNode VisitSchema(ContentRepository.Schema.Metadata.Schema schema)
        {
            // do not call the base functionality

            #region Write filestart
            _writer.WriteLine(@"/**
 * @module ComplexTypes
 * @preferred
 * 
* @description Module containing complex data types like HyperLink or ChoiceOption.
*
* This module is autogenerated from Sense/Net ContentRepository.
*
* ```
* let link = new Fields.HyperlinkData({
*   Href: 'http://sensenet.com',
*   Text: 'Link to sensenet.com',
*   Title: 'Go to sensenet.com',
*   Target: '_blank'
* });
*
* let webContent = new ContentTypes.WebContentDemo({
*   Id: 1,
*   Name: 'MyContent',
*   DisplayName: 'My Content',
*   Type: 'WebContentDemo',
*   Details: link
* });
*
* ```
*/ /** */
");
            #endregion

            _indentCount++;
            foreach (var complexType in Context.ComplexTypes)
            {
                Visit(complexType);
            }
            _indentCount--;

            #region Write fileend
            _writer.WriteLine(@"export class ChoiceOption {
    Value: string;
    Text?: string;
    Enabled?: boolean;
    Selected?: boolean;

    constructor(value: string, text?: string, enabled?: boolean, selected?: boolean) {
        this.Value = value;
        this.Text = text;
        this.Enabled = enabled;
        this.Selected = selected;
    }
}

export class DeferredUriObject {
    uri: string;
}

export class DeferredObject extends Object {
    __deferred: DeferredUriObject;
}

export class MediaObject {
    edit_media: string;
    media_src: string;
    content_type: string;
    media_etag: string;
}

export class MediaResourceObject extends Object {
    __mediaresource: MediaObject;
}");
            #endregion

            return(schema);
        }
Exemple #11
0
        protected override IMetaNode VisitSchema(ContentRepository.Schema.Metadata.Schema schema)
        {
            #region Write filestart
            _writer.WriteLine(@"//file: " + TypescriptGenerationContext.SchemaModuleName + @".ts
import { " + TypescriptGenerationContext.FieldSettingsModuleName + @" } from './" + TypescriptGenerationContext.FieldSettingsModuleName + @"';
/**
 * Module for ContentType schemas.
 *
 * A Content Type Definition in Sense/Net is an xml-format configuration file for defining Content Types. The xml configuration (CTD) holds information about the types name and description
 * properties that control how content of this type look and behave (icon, preview generation, indexing), set of fields, etc. This information about the type and its Fields helps us for example
 * building forms. Based on the Field definitions we can render a Field with its DisplayName as a label or validate the Field on save by its validation related configs.
 *
 * This module provides us description of this Content schemas in Typesript.
 *
 * The ```Schema``` class represents an object that holds the basic information about the Content Type (name, icon, ect.) and an array of its ```FieldSettings``` and their full configuration.
 */

export module " + TypescriptGenerationContext.SchemaModuleName + @" {
    /**
     * Class that represents a Schema.
     *
     * It represents an object that holds the basic information about the Content Type (name, icon, ect.) and an array of its ```FieldSettings``` and their full configuration.
     */
    export class Schema {
        Icon: string;
        DisplayName: string;
        Description: string;
        AllowIndexing: boolean;
        AllowIncrementalNaming: boolean;
        AllowedChildTypes: string[];
        FieldSettings: FieldSettings.FieldSetting[];
        /**
         * @constructs Schema
         * @param options {Object} An object implementing ISchemaOptions interface;
         */
        constructor(options: ISchemaOptions) {
            this.Icon = options.Icon;
            this.DisplayName = options.DisplayName;
            this.Description = options.Description;
            this.FieldSettings = options.FieldSettings;
            this.AllowIndexing = options.AllowIndexing;
            this.AllowIncrementalNaming = options.AllowIncrementalNaming;
            this.AllowedChildTypes = options.AllowedChildTypes;
        }
    }

    /**
    * Interface for classes that represent a Schema.
    *
    * @interface ISchemaOptions
    */
    export interface ISchemaOptions {
        Icon?: string;
        DisplayName?: string;
        Description?: string;
        AllowIndexing?: boolean;
        AllowIncrementalNaming?: boolean;
        AllowedChildTypes?: string[];
        FieldSettings?: FieldSettings.FieldSetting[];
    }
");
            #endregion

            // Do not call base because only classes will be read.
            _indentCount++;
            Visit(schema.Classes);
            _indentCount--;

            #region Write fileend
            _writer.WriteLine(@"}
");
            #endregion
            return(schema);
        }
Exemple #12
0
        protected override IMetaNode VisitSchema(ContentRepository.Schema.Metadata.Schema schema)
        {
            #region Write filestart
            _writer.WriteLine(@"/**
 * @module FieldSettings
 * @preferred
 * 
 * @description Module for FieldSettings.
 *
 * FieldSetting object is the implementation of the configuration element in a Sense/Net Content Type Definition.
 * The FieldSetting of a Field contains properties that define the behavior of the Field - for example a Field can be configured as read only or compulsory to fill.
 * FieldSettings helps us to autogenerate type and schema TS files from Sense/Net CTDs and use these files to reach all the configuration options of the Content Types fields on
 * client-side e.g. for validation.
 *
 * This module also contains some FieldSetting related enums to use them as types in properties e.g. visibitily or datetime mode options.
 */ /** */

import { ComplexTypes } from './SN';

    /**
     * Enum for Field visibility values.
     */
    export enum FieldVisibility { Show, Hide, Advanced }
    /**
     * Enum for Field output method values.
     */
    export enum OutputMethod { Default, Raw, Text, Html }
    /**
     * Enum for Choice Field control values.
     */
    export enum DisplayChoice { DropDown, RadioButtons, CheckBoxes }
    /**
     * Enum for DateTime Field mode values.
     */
    export enum DateTimeMode { None, Date, DateAndTime }
    /**
     * Enum for DateTime Field precision values.
     */
    export enum DateTimePrecision { Millisecond, Second, Minute, Hour, Day }
    /**
     * Enum for LongText field editor values.
     */
    export enum TextType { LongText, RichText, AdvancedRichText }
    /**
     * Enum for HyperLink field href values.
     */
    export enum UrlFormat { Hyperlink, Picture }

    export class FieldSetting {
        Name: string = 'Content';
        DisplayName?: string;
        Description?: string;
        Icon?: string;
        ReadOnly?: boolean;
        Compulsory?: boolean;
        DefaultValue?: string;
        OutputMethod?: OutputMethod;
        VisibleBrowse?: FieldVisibility;
        VisibleNew?: FieldVisibility;
        VisibleEdit?: FieldVisibility;
        FieldIndex?: number;
        DefaultOrder?: number;
        ControlHint?: string;

        constructor(options: IFieldSettingOptions) {
            this.Name = options.name;
            this.DisplayName = options.displayName;
            this.Icon = options.icon;
            this.ReadOnly = options.readOnly;
            this.Compulsory = options.compulsory;
            this.DefaultValue = options.defaultValue;
            this.OutputMethod = options.outputMethod;
            this.VisibleBrowse = options.visibleBrowse;
            this.VisibleEdit = options.visibleEdit;
            this.VisibleNew = options.visibleNew;
            this.FieldIndex = options.fieldIndex;
            this.DefaultOrder = options.defaultOrder;
            this.ControlHint = options.controlHint;

        }
    }

    export interface IFieldSettingOptions {
        name?: string;
        displayName?: string;
        description?: string;
        icon?: string;
        readOnly?: boolean;
        compulsory?: boolean;
        defaultValue?: string;
        outputMethod?: OutputMethod;
        visibleBrowse?: FieldVisibility;
        visibleNew?: FieldVisibility;
        visibleEdit?: FieldVisibility;
        fieldIndex?: number;
        defaultOrder?: number;
        controlHint?: string;
    }
");
            #endregion

            // Do not call base because only classes will be read.
            _indentCount++;
            Visit(schema.Classes);
            _indentCount--;

            return(schema);
        }
        protected override IMetaNode VisitSchema(ContentRepository.Schema.Metadata.Schema schema)
        {
            #region Write filestart
            _writer.WriteLine(@"/**
 * @module FieldSettings
 * @preferred
 *
 * @description Module for FieldSettings.
 *
 * FieldSetting object is the implementation of the configuration element in a Sense/Net Content Type Definition.
 * The FieldSetting of a Field contains properties that define the behavior of the Field - for example a Field can be configured as read only or compulsory to fill.
 * FieldSettings helps us to autogenerate type and schema TS files from Sense/Net CTDs and use these files to reach all the configuration options of the Content Types fields on
 * client-side e.g. for validation.
 *
 * This module also contains some FieldSetting related enums to use them as types in properties e.g. visibitily or datetime mode options.
 */

import * as ComplexTypes from ""./ComplexTypes"";

/**
 * Enum for Field visibility values.
 */
export enum FieldVisibility { Show, Hide, Advanced }
/**
 * Enum for Field output method values.
 */
export enum OutputMethod { Default, Raw, Text, Html }
/**
 * Enum for Choice Field control values.
 */
export enum DisplayChoice { DropDown, RadioButtons, CheckBoxes }
/**
 * Enum for DateTime Field mode values.
 */
export enum DateTimeMode { None, Date, DateAndTime }
/**
 * Enum for DateTime Field precision values.
 */
export enum DateTimePrecision { Millisecond, Second, Minute, Hour, Day }
/**
 * Enum for LongText field editor values.
 */
export enum TextType { LongText, RichText, AdvancedRichText }
/**
 * Enum for HyperLink field href values.
 */
export enum UrlFormat { Hyperlink, Picture }

export function isFieldSettingOfType<T extends FieldSetting>(setting: FieldSetting, type: { new(): T }): setting is T {
    return setting.Type === type.name;
}

export class FieldSetting {
    public Name!: string;
    public Type!: string;
    public DisplayName?: string;
    public Description?: string;
    public FieldClassName?: string;
    public Icon?: string;
    public ReadOnly?: boolean;
    public Compulsory?: boolean;
    public DefaultValue?: string;
    public OutputMethod?: OutputMethod;
    public Visible?: boolean;
    public VisibleBrowse?: FieldVisibility;
    public VisibleNew?: FieldVisibility;
    public VisibleEdit?: FieldVisibility;
    public FieldIndex?: number;
    public DefaultOrder?: number;
    public ControlHint?: string;
}
");
            #endregion

            // Do not call base because only classes will be read.
            Visit(schema.Classes);

            return(schema);
        }
        protected override IMetaNode VisitSchema(ContentRepository.Schema.Metadata.Schema schema)
        {
            // do not call the base functionality

            #region Write filestart
            _writer.WriteLine(@"/**
 * @module ComplexTypes
 * @preferred
 *
 * @description Module containing complex data types like HyperLink or ChoiceOption.
 *
 * This module is autogenerated from Sense/Net ContentRepository.
 *
 * ```
 * let link = new Fields.HyperlinkData({
 *   Href: 'http://sensenet.com',
 *   Text: 'Link to sensenet.com',
 *   Title: 'Go to sensenet.com',
 *   Target: '_blank'
 * });
 *
 * let webContent = new ContentTypes.WebContentDemo({
 *   Id: 1,
 *   Name: 'MyContent',
 *   DisplayName: 'My Content',
 *   Type: 'WebContentDemo',
 *   Details: link
 * });
 *
 * ```
 */ /** */

// tslint:disable:naming-convention
");
            #endregion

            _indentCount++;
            foreach (var complexType in Context.ComplexTypes)
            {
                Visit(complexType);
            }
            _indentCount--;

            #region Write fileend
            _writer.WriteLine(@"export class ChoiceOption {
    public Value!: string;
    public Text?: string;
    public Enabled?: boolean;
    public Selected?: boolean;
}

export class DeferredUriObject {
    public uri!: string;
}

export class DeferredObject extends Object {
    public __deferred!: DeferredUriObject;
}

export class MediaObject {
    public edit_media!: string;
    public media_src!: string;
    public content_type!: string;
    public media_etag!: string;
}

export class MediaResourceObject extends Object {
   public __mediaresource!: MediaObject;
}");
            #endregion

            return(schema);
        }