Comparing version 0.8.1 to 0.9.0
@@ -0,1 +1,6 @@ | ||
# 0.9.0 | ||
* Add `readOnly` support - pulls across from ModelSafe (introduced in ModelSafe 0.6.0) | ||
* The `values` of a property is automatically populated with defaults if it's a ModelSafe ENUM attribute | ||
# 0.8.1 | ||
@@ -2,0 +7,0 @@ |
@@ -38,2 +38,4 @@ import { Model, ModelConstructor, AttributeType, AssociationType } from 'modelsafe'; | ||
data?: any; | ||
/** Whether the property is read-only. */ | ||
readOnly?: boolean; | ||
/** The possible values for the property (mainly for enums or associations). */ | ||
@@ -40,0 +42,0 @@ values?: PropertyValueDefinition[] | Promise<PropertyValueDefinition>; |
@@ -29,35 +29,41 @@ "use strict"; | ||
var options = modelsafe_1.getModelOptions(model); | ||
var attrs = modelsafe_1.getAttributes(model); | ||
var assocs = modelsafe_1.getAssociations(model); | ||
var singular = inflection_1.singularize(_.camelCase(options.name)); | ||
var plural = inflection_1.pluralize(_.camelCase(options.name)); | ||
var props = modelsafe_1.getProperties(model); | ||
var attrs = []; | ||
var assocs = []; | ||
var visible = []; | ||
for (var _i = 0, _a = Object.keys(props); _i < _a.length; _i++) { | ||
var mappedAttrs = []; | ||
var mappedAssocs = []; | ||
for (var _i = 0, _a = Object.keys(attrs); _i < _a.length; _i++) { | ||
var key = _a[_i]; | ||
var prop = props[key]; | ||
var attr = attrs[key]; | ||
var propOptions = metadata_1.getPropertyOptions(model, key); | ||
var path = prop.toString(); | ||
if (propOptions.visible) { | ||
visible.push(path); | ||
visible.push(key); | ||
} | ||
if (prop instanceof modelsafe_1.Attribute) { | ||
// FIXME: We cast as any to get the private assoc type. | ||
var type = prop.type; | ||
attrs.push(__assign({ path: path, | ||
type: type }, propOptions)); | ||
var attrOptions = __assign({ path: key, type: attr.type, readOnly: attr.readOnly }, propOptions); | ||
// Check if the internal attribute type is ENUM, if so pre-populate values with relevant enum variants. | ||
if (attr.type.type === modelsafe_1.InternalAttributeType.ENUM) { | ||
attrOptions.values = attr.type.options.values.map(function (v) { | ||
return { | ||
label: v, | ||
value: v | ||
}; | ||
}); | ||
} | ||
if (prop instanceof modelsafe_1.Association) { | ||
// FIXME: We cast as any to get the private assoc type. | ||
var type = prop.type; | ||
assocs.push(__assign({ path: path, | ||
type: type }, propOptions)); | ||
mappedAttrs.push(attrOptions); | ||
} | ||
for (var _b = 0, _c = Object.keys(assocs); _b < _c.length; _b++) { | ||
var key = _c[_b]; | ||
var assoc = assocs[key]; | ||
var propOptions = metadata_1.getPropertyOptions(model, key); | ||
if (propOptions.visible) { | ||
visible.push(key); | ||
} | ||
var assocOptions = __assign({ path: key, type: assoc.type, readOnly: assoc.readOnly }, propOptions); | ||
mappedAssocs.push(assocOptions); | ||
} | ||
return __assign({ model: model, | ||
singular: singular, | ||
plural: plural, | ||
attrs: attrs, | ||
assocs: assocs, | ||
visible: visible, actions: [], contextualActions: [] }, overrides); | ||
plural: plural, attrs: mappedAttrs, assocs: mappedAssocs, visible: visible, actions: [], contextualActions: [] }, overrides); | ||
}; | ||
@@ -64,0 +70,0 @@ /** |
{ | ||
"name": "cruddle", | ||
"version": "0.8.1", | ||
"version": "0.9.0", | ||
"main": "dist/index.js", | ||
@@ -35,3 +35,3 @@ "bugs": "https://github.com/creativecuriositystudio/cruddle/issues", | ||
"@angular/core": "^4.0.0", | ||
"modelsafe": ">= 0.5.2" | ||
"modelsafe": ">= 0.6.0" | ||
}, | ||
@@ -54,3 +54,3 @@ "devDependencies": { | ||
"mocha": "^3.2.0", | ||
"modelsafe": ">= 0.5.2", | ||
"modelsafe": ">= 0.6.0", | ||
"reflect-metadata": "^0.1.8", | ||
@@ -57,0 +57,0 @@ "rxjs": "^5.0.0", |
@@ -48,2 +48,5 @@ import { Property, Model, ModelConstructor, | ||
/** Whether the property is read-only. */ | ||
readOnly?: boolean; | ||
/** The possible values for the property (mainly for enums or associations). */ | ||
@@ -50,0 +53,0 @@ values?: PropertyValueDefinition[] | Promise<PropertyValueDefinition>; |
import * as _ from 'lodash'; | ||
import { pluralize, singularize } from 'inflection'; | ||
import { getProperties, getModelOptions, Model, ModelConstructor, ModelProperties, | ||
Property, Attribute, Association } from 'modelsafe'; | ||
import { getProperties, getModelOptions, Model, ModelConstructor, ModelProperties, EnumAttributeTypeOptions, | ||
Property, Attribute, Association, InternalAttributeType, getAttributes, getAssociations } from 'modelsafe'; | ||
@@ -23,41 +23,56 @@ import { BaseDefinition, DeleteDefinition, FormDefinition, | ||
let options = getModelOptions(model); | ||
let attrs = getAttributes(model); | ||
let assocs = getAssociations(model); | ||
let singular = singularize(_.camelCase(options.name)); | ||
let plural = pluralize(_.camelCase(options.name)); | ||
let props = getProperties(model); | ||
let attrs = []; | ||
let assocs = []; | ||
let visible = []; | ||
let mappedAttrs = []; | ||
let mappedAssocs = []; | ||
for (let key of Object.keys(props)) { | ||
let prop = props[key] as Property<any>; | ||
for (let key of Object.keys(attrs)) { | ||
let attr = attrs[key]; | ||
let propOptions = getPropertyOptions(model, key); | ||
let path = prop.toString(); | ||
if (propOptions.visible) { | ||
visible.push(path); | ||
visible.push(key); | ||
} | ||
if (prop instanceof Attribute) { | ||
// FIXME: We cast as any to get the private assoc type. | ||
let type = (prop as any).type; | ||
let attrOptions = { | ||
path: key, | ||
type: attr.type, | ||
readOnly: attr.readOnly, | ||
attrs.push({ | ||
path, | ||
type, | ||
... propOptions | ||
}; | ||
... propOptions | ||
// Check if the internal attribute type is ENUM, if so pre-populate values with relevant enum variants. | ||
if (attr.type.type === InternalAttributeType.ENUM) { | ||
attrOptions.values = (<EnumAttributeTypeOptions> attr.type.options).values.map((v: any) => { | ||
return { | ||
label: v, | ||
value: v | ||
}; | ||
}); | ||
} | ||
if (prop instanceof Association) { | ||
// FIXME: We cast as any to get the private assoc type. | ||
let type = (prop as any).type; | ||
mappedAttrs.push(attrOptions); | ||
} | ||
assocs.push({ | ||
path, | ||
type, | ||
for (let key of Object.keys(assocs)) { | ||
let assoc = assocs[key]; | ||
let propOptions = getPropertyOptions(model, key); | ||
... propOptions | ||
}); | ||
if (propOptions.visible) { | ||
visible.push(key); | ||
} | ||
let assocOptions = { | ||
path: key, | ||
type: assoc.type, | ||
readOnly: assoc.readOnly, | ||
... propOptions | ||
}; | ||
mappedAssocs.push(assocOptions); | ||
} | ||
@@ -69,4 +84,4 @@ | ||
plural, | ||
attrs, | ||
assocs, | ||
attrs: mappedAttrs, | ||
assocs: mappedAssocs, | ||
visible, | ||
@@ -73,0 +88,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
417553
3553