import keywords=require("./keywords")
interface IFacet {
facetName(): string
value(): any
}
export interface PropertyDescription {
enumOptions?: any[]
regExp?: string
description?: string
displayName?: string
id?: string
default?: string
required?: boolean
multiline?: boolean;
scalar?: boolean
boolean?: boolean
nil?: boolean
array?: boolean
object?: boolean
map?: boolean
children?: PropertyDescription[];
componentType?: PropertyDescription;
}
export class PropertyGroup {
priority: number;
caption: string
properties: PropertyDescription[] = [];
}
export interface IPropertyGroupProvider {
consumeProperty(p: PropertyDescription): boolean;
getResult(): PropertyGroup[]
}
abstract class AbstractProvider implements IPropertyGroupProvider {
_result: PropertyGroup = new PropertyGroup();
abstract consume(p: PropertyDescription): boolean;
consumeProperty(p: PropertyDescription): boolean {
var r = this.consume(p);
if (r) {
this._result.properties.push(p);
}
return r;
}
getResult() {
this.updateGroup();
return [this._result];
}
updateGroup() {
}
}
class RequiredProvider extends AbstractProvider {
constructor() {
super();
this._result.caption = "General";
}
consume(p: PropertyDescription): boolean {
return p.required&&p.scalar&&!p.multiline;
}
}
class ObjectProvider implements IPropertyGroupProvider{
_result: PropertyGroup[] = [];
consumeProperty(p: PropertyDescription): boolean {
if (p.object&&!p.map) {
var g = new PropertyGroup();
g.properties=p.children;
g.caption = p.displayName;
this._result.push(g);
return true;
}
return false;
}
getResult() {
return this._result;
}
}
export function nicerName(n: string) {
var result: string[] = [];
var needUpperCase = true;
var p = "";
for (var i = 0; i < n.length; i++) {
var c = n.charAt(i);
if (p.toUpperCase() != p) {
if (c.toLowerCase() != c) {
result.push(' ');
}
}
if (needUpperCase) {
c = c.toUpperCase();
needUpperCase = false;
}
result.push(c);
p = c;
}
return result.join("");
}
class OtherScalar extends AbstractProvider {
constructor() {
super()
this._result.caption = "Advanced"
}
consume(p: PropertyDescription): boolean {
return (p.scalar&&!p.multiline);
}
}
class CatchAll implements IPropertyGroupProvider {
_result: PropertyGroup[] = [];
consumeProperty(p: PropertyDescription): boolean {
var g = new PropertyGroup();
g.properties.push(p);
g.caption = p.displayName;
this._result.push(g);
return true;
}
getResult() {
return this._result;
}
}
export function createProviders(): IPropertyGroupProvider[] {
return [new RequiredProvider(), new OtherScalar(), new ObjectProvider(),new CatchAll()]
}
var iterateProviders = function (providers: IPropertyGroupProvider[], props: PropertyDescription[], consumed: {}) {
providers.forEach(x=> {
props.forEach(y=> {
if (!consumed.hasOwnProperty(y.id)) {
var r = x.consumeProperty(y);
if (r) {
consumed[y.id] = true;
}
}
})
})
};
declare class Map
" + tc.description + "
"; g.properties = [tc]; } } } } } declare var $: any function deepCopy(obj: any) { var newObj = $.extend(true, {}, obj); return newObj; } export function collapseInnerProps(g: PropertyDescription) { if (g.children&&g.children.length == 1) { if (g.children[0].map|| g.children[0].array) { var tc = deepCopy(g.children[0]); if (tc.map) { tc.displayName = g.displayName; tc.id=g.id+"=>"+tc.id; tc.description = g.description + "" + tc.description + "
"; return tc; } } } return g; } function tryMerge(g: PropertyGroup[]): PropertyGroup[] { g=g.filter(x=>x.properties.length>0) var map = new Map