Compare commits
250 Commits
v0.4-alpha
...
v1.2-beta
| Author | SHA1 | Date | |
|---|---|---|---|
| 3c9b7692f1 | |||
| 51223d4ac7 | |||
| 1d5f91964f | |||
| 0accac26ee | |||
| 6527e66ff3 | |||
| 47e71067a1 | |||
| 969cc45e9b | |||
| 9ff5bfc907 | |||
| 7cdcb940bd | |||
| 75e0ac5d6d | |||
| ba6921fdb9 | |||
| 8624617ad4 | |||
| e46e5c279f | |||
| a9dc79e4ff | |||
| 485c6cb6a1 | |||
| 8e7eda9276 | |||
| 96d70bc1a9 | |||
| 264208dcc7 | |||
| 077ab44dc8 | |||
| 7499395807 | |||
| d983b75be3 | |||
| 381875bc14 | |||
| 3944da57b1 | |||
| 0cbbd1c93e | |||
| 1bfab0f8a3 | |||
| 537abea717 | |||
| c8d9b04a57 | |||
| 32d0d199a3 | |||
| 715776771a | |||
| 4785c85b84 | |||
| 712ca3cd76 | |||
| 43a7202194 | |||
| 9a21ab0ef4 | |||
| 46613bbc01 | |||
| 4998acb59a | |||
| bc58078eec | |||
| d1d95aebe7 | |||
| 1c9bce8b66 | |||
| 8d3e3aeb0a | |||
| a58c0154c9 | |||
| 9829ab796a | |||
| 75080b0e2d | |||
| 932f098837 | |||
| 6e50301da5 | |||
| 448bbe26f0 | |||
| 7c3c0e041d | |||
| 3b2559c37d | |||
| 2cc4fd711a | |||
| d5038a52d1 | |||
| d4cf60d5f3 | |||
| 09a3172c80 | |||
| 2bf2e5f91a | |||
| d09831b547 | |||
| db82bd8013 | |||
| 4014583ade | |||
| 9a0e40b489 | |||
| 5c60c109d5 | |||
| 7615657a18 | |||
| bdb3655418 | |||
| 0d766c1ad9 | |||
| e2c7e9b0ef | |||
| 62964dcfae | |||
| a48033874a | |||
| ecb933d13a | |||
| 45ccf6e06d | |||
| b0118f4bdb | |||
| 7fd1b69e81 | |||
| b67e150fe1 | |||
| 5b43053406 | |||
| 1cbc192a9d | |||
| 4fff98640e | |||
| 085ff2cecf | |||
| d72a000d68 | |||
| 2fc8845851 | |||
| d5c6b4a324 | |||
| bd617162f1 | |||
| 06fdfc8226 | |||
| d4d50cae52 | |||
| 688ad534f2 | |||
| ff39bce262 | |||
| 481259f0b7 | |||
| 059d951a21 | |||
| 6dc5841f31 | |||
| 91fc5bbd7f | |||
| 3742147cf7 | |||
| 432a33eef8 | |||
| b7a8f5f581 | |||
| baa909d0c7 | |||
| 6ea44c271d | |||
| 7d4c27646f | |||
| 848d25a156 | |||
| b4fc3e1cd3 | |||
| 0547c4c07e | |||
| 86f2f180bf | |||
| 62a9ff05b9 | |||
| ce05dbb845 | |||
| 8ce8454620 | |||
| d13a5b1b86 | |||
| a6b1abaecc | |||
| 258b0859ab | |||
| cee7d73b01 | |||
| 1e12b82742 | |||
| 3b5cff8d9a | |||
| f214785cfa | |||
| 61d0b67118 | |||
| 7a71afda0e | |||
| 4ad88a04e5 | |||
| 6f281080e8 | |||
| 7b5d9b4dd5 | |||
| 766ae0a8df | |||
| 43e1855b2c | |||
| 00d2b693dd | |||
| bf76b80330 | |||
| 5d12f5f76c | |||
| 8deca35f24 | |||
| e628fa7af0 | |||
| e2341e8bb5 | |||
| 55bb2e49e5 | |||
| cbec133186 | |||
| ff4b5da163 | |||
| ea017fa6cd | |||
| 7a29683008 | |||
| f52bbc2d0a | |||
| fa174ba15a | |||
| a3a275808e | |||
| 23735fdf59 | |||
| 8c005b2ec9 | |||
| bfb1cc6abc | |||
| ea0d641f25 | |||
| 67311836c8 | |||
| 22d596e827 | |||
| b42306e741 | |||
| 1ca8878592 | |||
| 5aeef0383c | |||
| 337cd6d863 | |||
| 3160f8ce8f | |||
| 5eed6da175 | |||
| da4383181c | |||
| 25e8db9443 | |||
| c6a47c0036 | |||
| 9795e26f1a | |||
| e144e475b7 | |||
| 9c7cb43bb9 | |||
| ac20b370fb | |||
| 6cc91e4359 | |||
| c883afc81f | |||
| 3a89c73b6d | |||
| 1eb0aa68d2 | |||
| 533f7d9f8f | |||
| 3ffd03e34c | |||
| 91dcdae780 | |||
| 15a242ab9b | |||
| 05b98beee6 | |||
| f138ee178b | |||
| 6e52df4f88 | |||
| 59aa67b89f | |||
| 7ddc74d75b | |||
| b53e3529b4 | |||
| e2e38646d1 | |||
| d7432d1f95 | |||
| b9a0852c4f | |||
| 9d1850de97 | |||
| 4a319b9ed4 | |||
| 96aed2c256 | |||
| ddd01b4745 | |||
| 3521543f17 | |||
| 6ce31efc27 | |||
| 342789e692 | |||
| e87e84eb5b | |||
| 96b1839c04 | |||
| 73e8712ad8 | |||
| 0830290bf1 | |||
| e374a9f01b | |||
| 980752340e | |||
| 5092a24dca | |||
| 9203718a95 | |||
| 63b47c8f9d | |||
| f3fd6f3676 | |||
| 504a3b5c04 | |||
| 363e614349 | |||
| 35ea62dff1 | |||
| 4879230303 | |||
| 0a65c1a843 | |||
| 30d0d11af0 | |||
| bb6a2d2f96 | |||
| c5eced8a44 | |||
| 512edaeaf9 | |||
| dd453fc66a | |||
| cc92cd23f4 | |||
| ac36b19399 | |||
| 2a444260a4 | |||
| 8e71e5b66e | |||
| d0ffd314e9 | |||
| 9abab522e6 | |||
| 99861275a8 | |||
| fa54294d74 | |||
| 92b2615e46 | |||
| 898790bfa6 | |||
| d37ee132bc | |||
| 561ef8ccd0 | |||
| 45d7db0239 | |||
| e444b728b6 | |||
| 5865b47482 | |||
| 6248837b60 | |||
| 37f2de0a8f | |||
| be15dba68a | |||
| e2620892f5 | |||
| 7879ae695e | |||
| 50ced7459a | |||
| 89af319265 | |||
| 7505de1cf1 | |||
| a09c69edc1 | |||
| 03101a128e | |||
| 67c118066b | |||
| f49159d2d0 | |||
| 840feec967 | |||
| ffc4eaa964 | |||
| eaf766c2a7 | |||
| 419180c443 | |||
| e97c976c7f | |||
| 2d05e64e5a | |||
| 6f4d7f9e9b | |||
| 5a24e9b016 | |||
| 4d4e9d7de0 | |||
| 1dde1ed5f0 | |||
| 88051ef61d | |||
| 10d3dd76ed | |||
| b52f153141 | |||
| 062f28f9ca | |||
| cd2bd8c562 | |||
| ed6068230e | |||
| 24bfef64dd | |||
| 1d5e4eda7e | |||
| 346b8c73d4 | |||
| 43ea29cdf2 | |||
| de03a12e9c | |||
| f05a67d9d2 | |||
| 3ac7ef34ec | |||
| 518f95ce01 | |||
| 7831e476e3 | |||
| bfb883c098 | |||
| bbe3506747 | |||
| 42743b1394 | |||
| 9a712acd6a | |||
| 4c8bbd5d8f | |||
| 9296388abe | |||
| 3c5e2013a0 | |||
| aacbc06992 | |||
| 220a034d2a | |||
| 6317b83720 |
+2
-1
@@ -13,7 +13,7 @@ $RECYCLE.BIN/
|
||||
app/less/*.css
|
||||
dist/
|
||||
node_modules/
|
||||
pkg/tmp/
|
||||
tmp/
|
||||
pkg/*.nupkg
|
||||
pkg/*.zip
|
||||
|
||||
@@ -23,6 +23,7 @@ pkg/*.zip
|
||||
[Bb]in/
|
||||
[Oo]bj/
|
||||
[Pp]ackages/
|
||||
VersionInfo.cs
|
||||
|
||||
*.aps
|
||||
*.bak
|
||||
|
||||
+184
-173
@@ -1,38 +1,182 @@
|
||||
module.exports = function(grunt) {
|
||||
require('load-grunt-tasks')(grunt);
|
||||
var path = require('path')
|
||||
|
||||
grunt.initConfig({
|
||||
pkg: grunt.file.readJSON('package.json'),
|
||||
pkgMeta: grunt.file.readJSON('pkg/meta.json'),
|
||||
dest: 'dist',
|
||||
package_dir: 'pkg',
|
||||
package_temp_dir: '<%= package_dir %>/tmp/',
|
||||
|
||||
pkgMeta: grunt.file.readJSON('config/meta.json'),
|
||||
dest: grunt.option('target') || 'dist',
|
||||
basePath: path.join('<%= dest %>', 'App_Plugins', '<%= pkgMeta.name %>'),
|
||||
|
||||
watch: {
|
||||
options: {
|
||||
spawn: false,
|
||||
atBegin: true
|
||||
},
|
||||
|
||||
less: {
|
||||
files: ['app/less/*.less', 'lib/**/*.less'],
|
||||
tasks: ['less:build'],
|
||||
options: {
|
||||
spawn: false
|
||||
}
|
||||
files: ['app/**/*.less'],
|
||||
tasks: ['less:dist']
|
||||
},
|
||||
|
||||
js: {
|
||||
files: ['app/**/*.js', 'lib/**/*.js'],
|
||||
tasks: ['concat', 'jshint'],
|
||||
options: {
|
||||
spawn: false
|
||||
}
|
||||
files: ['app/**/*.js'],
|
||||
tasks: ['concat:dist']
|
||||
},
|
||||
|
||||
dev: {
|
||||
files: ['app/**'],
|
||||
tasks: ['deploy'],
|
||||
html: {
|
||||
files: ['app/**/*.html'],
|
||||
tasks: ['copy:html']
|
||||
},
|
||||
|
||||
dll: {
|
||||
files: ['app/Umbraco/**/*.dll'],
|
||||
tasks: ['copy:dll']
|
||||
}
|
||||
},
|
||||
|
||||
less: {
|
||||
dist: {
|
||||
options: {
|
||||
spawn: false
|
||||
paths: ["app/less", "lib/less", "vendor"],
|
||||
},
|
||||
files: {
|
||||
'<%= basePath %>/css/archetype.css': 'app/less/archetype.less',
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
concat: {
|
||||
options: {
|
||||
stripBanners: false
|
||||
},
|
||||
dist: {
|
||||
src: [
|
||||
'app/controllers/controller.js',
|
||||
'app/controllers/config.controller.js',
|
||||
'app/directives/archetypeproperty.js',
|
||||
'app/directives/archetypecustomview.js',
|
||||
'app/directives/localize.js',
|
||||
'app/services/localization.js',
|
||||
'app/resources/propertyeditor.js'
|
||||
],
|
||||
dest: '<%= basePath %>/js/archetype.js'
|
||||
}
|
||||
},
|
||||
|
||||
copy: {
|
||||
html: {
|
||||
cwd: 'app/views/',
|
||||
src: ['archetype.html', 'archetype.default.html', 'archetype.config.html'],
|
||||
dest: '<%= basePath %>/views',
|
||||
expand: true
|
||||
},
|
||||
dll: {
|
||||
cwd: 'app/Umbraco/Umbraco.Archetype/bin/Release/',
|
||||
src: 'Archetype.dll',
|
||||
dest: '<%= dest %>/bin/',
|
||||
expand: true
|
||||
},
|
||||
config: {
|
||||
files: [
|
||||
{
|
||||
cwd: 'app/langs/',
|
||||
src: ['**'],
|
||||
dest: '<%= basePath %>/langs',
|
||||
expand: true
|
||||
}
|
||||
]
|
||||
},
|
||||
nuget: {
|
||||
files: [
|
||||
{
|
||||
cwd: '<%= dest %>',
|
||||
src: ['**/*', '!bin', '!bin/*'],
|
||||
dest: 'tmp/nuget/content',
|
||||
expand: true
|
||||
},
|
||||
{
|
||||
cwd: '<%= dest %>/bin',
|
||||
src: ['*.dll'],
|
||||
dest: 'tmp/nuget/lib/net40',
|
||||
expand: true
|
||||
}
|
||||
]
|
||||
},
|
||||
umbraco: {
|
||||
cwd: '<%= dest %>',
|
||||
src: '**/*',
|
||||
dest: 'tmp/umbraco',
|
||||
expand: true
|
||||
}
|
||||
},
|
||||
|
||||
nugetpack: {
|
||||
dist: {
|
||||
src: 'tmp/nuget/package.nuspec',
|
||||
dest: 'pkg'
|
||||
}
|
||||
},
|
||||
|
||||
template: {
|
||||
'nuspec': {
|
||||
'options': {
|
||||
'data': {
|
||||
name: '<%= pkgMeta.name %>',
|
||||
version: '<%= pkgMeta.version %>',
|
||||
url: '<%= pkgMeta.url %>',
|
||||
license: '<%= pkgMeta.license %>',
|
||||
licenseUrl: '<%= pkgMeta.licenseUrl %>',
|
||||
author: '<%= pkgMeta.author %>',
|
||||
authorUrl: '<%= pkgMeta.authorUrl %>',
|
||||
|
||||
files: [{ path: 'tmp/nuget/**', target: 'content/App_Plugins/Archetype'}]
|
||||
}
|
||||
},
|
||||
'files': {
|
||||
'tmp/nuget/package.nuspec': ['config/package.nuspec']
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
umbracoPackage: {
|
||||
options: {
|
||||
name: "<%= pkgMeta.name %>",
|
||||
version: '<%= pkgMeta.version %>',
|
||||
url: '<%= pkgMeta.url %>',
|
||||
license: '<%= pkgMeta.license %>',
|
||||
licenseUrl: '<%= pkgMeta.licenseUrl %>',
|
||||
author: '<%= pkgMeta.author %>',
|
||||
authorUrl: '<%= pkgMeta.authorUrl %>',
|
||||
manifest: 'config/package.xml',
|
||||
readme: 'config/readme.txt',
|
||||
sourceDir: 'tmp/umbraco',
|
||||
outputDir: 'pkg',
|
||||
}
|
||||
},
|
||||
|
||||
clean: {
|
||||
build: '<%= grunt.config("basePath").substring(0, 4) == "dist" ? "dist/**/*" : "null" %>',
|
||||
tmp: ['tmp']
|
||||
},
|
||||
|
||||
assemblyinfo: {
|
||||
options: {
|
||||
files: ['app/Umbraco/Umbraco.Archetype/Archetype.Umbraco.csproj'],
|
||||
filename: 'VersionInfo.cs',
|
||||
info: {
|
||||
version: '<%= (pkgMeta.version.indexOf("-") ? pkgMeta.version.substring(0, pkgMeta.version.indexOf("-")) : pkgMeta.version) %>',
|
||||
fileVersion: '<%= pkgMeta.version %>'
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
touch: {
|
||||
webconfig: {
|
||||
src: ['<%= grunt.option("target") %>\\Web.config']
|
||||
}
|
||||
},
|
||||
|
||||
jshint: {
|
||||
options: {
|
||||
jshintrc: '.jshintrc'
|
||||
@@ -42,164 +186,31 @@ module.exports = function(grunt) {
|
||||
}
|
||||
},
|
||||
|
||||
less: {
|
||||
build: {
|
||||
options: {
|
||||
paths: ["app/less", "lib/less", "vendor"],
|
||||
},
|
||||
files: {
|
||||
'<%= dest %>/css/archetype.css': 'app/less/archetype.less',
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
concat: {
|
||||
options: {
|
||||
stripBanners: false
|
||||
},
|
||||
application: {
|
||||
src: [
|
||||
'app/controllers/controller.js',
|
||||
'app/controllers/config.controller.js',
|
||||
'app/directives/archetypeproperty.js',
|
||||
'app/directives/localize.js',
|
||||
'app/services/localization.js',
|
||||
'app/resources/propertyeditor.js'
|
||||
],
|
||||
dest: '<%= dest %>/js/archetype.js'
|
||||
}
|
||||
},
|
||||
|
||||
nugetpack: {
|
||||
dist: {
|
||||
src: '<%= package_temp_dir %>/nuget/package.nuspec',
|
||||
dest: '<%= package_dir %>'
|
||||
}
|
||||
},
|
||||
|
||||
template: {
|
||||
'nuget_manifest': {
|
||||
'options': {
|
||||
'data': {
|
||||
name: '<%= pkgMeta.name %>',
|
||||
version: '<%= pkgMeta.version %>',
|
||||
url: '<%= pkgMeta.url %>',
|
||||
license: '<%= pkgMeta.license %>',
|
||||
licenseUrl: '<%= pkgMeta.licenseUrl %>',
|
||||
author: '<%= pkgMeta.author %>',
|
||||
authorUrl: '<%= pkgMeta.authorUrl %>',
|
||||
|
||||
files: [{ path: '..\\..\\..\\<%= dest %>\\**', target: 'content\\App_Plugins\\Archetype'}]
|
||||
}
|
||||
},
|
||||
'files': {
|
||||
'<%= package_temp_dir %>/nuget/package.nuspec': ['<%= package_dir %>/nuget/package.nuspec']
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
clean: {
|
||||
build: ['<%= dest %>']
|
||||
},
|
||||
|
||||
copy: {
|
||||
build: {
|
||||
files: [
|
||||
{expand: true, cwd: 'app/', src: ['package.manifest'], dest: '<%= dest %>', flatten: true},
|
||||
{expand: true, cwd: 'app/views/', src: ['archetype.html', 'archetype.config.html'], dest: '<%= dest %>/views', flatten: true},
|
||||
{expand: true, cwd: 'app/config/', src: ['propertyEditors.views.js'], dest: '<%= dest %>/js', flatten: true},
|
||||
{expand: true, cwd: 'app/langs/', src: ['**'], dest: '<%= dest %>/langs', flatten: true},
|
||||
{expand: true, cwd: 'app/Umbraco/Umbraco.Archetype/bin/Debug/', src: ['Archetype.dll'], dest: '<%= dest %>/bin', flatten: true}
|
||||
]
|
||||
},
|
||||
deploy: {
|
||||
files: [
|
||||
{expand: true, cwd: '<%= dest %>/', src: ['**/*', '!bin/*'], dest: '<%= grunt.option("target") %>\\App_Plugins\\Archetype', flatten: false},
|
||||
{expand: true, cwd: '<%= dest %>/', src: ['bin/*'], dest: '<%= grunt.option("target") %>\\bin', flatten: false},
|
||||
]
|
||||
},
|
||||
nuget_prepare: {
|
||||
files: [
|
||||
{expand: true, cwd: '<%= dest %>/', src: ['**/*', '!bin/*'], dest: '<%= package_temp_dir %>/nuget/content/', flatten: false},
|
||||
{expand: true, cwd: '<%= dest %>/', src: ['bin/*'], dest: '<%= package_temp_dir %>/nuget/lib/net40/', flatten: false}
|
||||
]
|
||||
},
|
||||
umbracopackage: {
|
||||
files: [
|
||||
{expand: true, cwd: '<%= dest %>/', src: ['**/*', "!bin/*"], dest: 'pkg/tmp/umbraco/App_Plugins/Archetype', flatten: false},
|
||||
{expand: true, cwd: '<%= dest %>/', src: ['bin/*'], dest: 'pkg/tmp/umbraco', flatten: false}
|
||||
]
|
||||
}
|
||||
},
|
||||
|
||||
touch: {
|
||||
options: {},
|
||||
webconfig: {
|
||||
src: ['<%= grunt.option("target") %>\\Web.config']
|
||||
}
|
||||
},
|
||||
|
||||
umbracoPackage: {
|
||||
options: {
|
||||
name: "<%= pkgMeta.name %>",
|
||||
version: '<%= pkgMeta.version %>',
|
||||
url: '<%= pkgMeta.url %>',
|
||||
license: '<%= pkgMeta.license %>',
|
||||
licenseUrl: '<%= pkgMeta.licenseUrl %>',
|
||||
author: '<%= pkgMeta.author %>',
|
||||
authorUrl: '<%= pkgMeta.authorUrl %>',
|
||||
manifest: 'pkg/umbraco/package.xml',
|
||||
readme: 'pkg/umbraco/readme.txt',
|
||||
sourceDir: 'pkg/tmp/umbraco',
|
||||
outputDir: 'pkg',
|
||||
}
|
||||
},
|
||||
|
||||
clean: {
|
||||
build: ['<%= dest %>'],
|
||||
package_temp: ['pkg/tmp'],
|
||||
package_artifacts: ['pkg/*.zip', 'pkg/*.nupkg'],
|
||||
},
|
||||
|
||||
msbuild: {
|
||||
dev: {
|
||||
src: ['app/Umbraco/Umbraco.Archetype/Archetype.Umbraco.csproj'],
|
||||
options: {
|
||||
projectConfiguration: 'Debug',
|
||||
targets: ['Clean', 'Rebuild'],
|
||||
stdout: true,
|
||||
maxCpuCount: 4,
|
||||
buildParameters: {
|
||||
WarningLevel: 2
|
||||
},
|
||||
verbosity: 'quiet'
|
||||
}
|
||||
options: {
|
||||
stdout: true,
|
||||
verbosity: 'quiet',
|
||||
maxCpuCount: 4,
|
||||
version: 4.0,
|
||||
buildParameters: {
|
||||
WarningLevel: 2,
|
||||
NoWarn: 1607
|
||||
}
|
||||
},
|
||||
dist: {
|
||||
src: ['app/Umbraco/Umbraco.Archetype/Archetype.Umbraco.csproj'],
|
||||
options: {
|
||||
projectConfiguration: 'Release',
|
||||
targets: ['Clean', 'Rebuild'],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
grunt.loadNpmTasks('grunt-contrib-watch');
|
||||
grunt.loadNpmTasks('grunt-contrib-less');
|
||||
grunt.loadNpmTasks('grunt-contrib-clean');
|
||||
grunt.loadNpmTasks('grunt-contrib-concat');
|
||||
grunt.loadNpmTasks('grunt-contrib-copy');
|
||||
grunt.loadNpmTasks('grunt-contrib-uglify');
|
||||
grunt.loadNpmTasks('grunt-contrib-jshint');
|
||||
grunt.loadNpmTasks('grunt-nuget');
|
||||
grunt.loadNpmTasks('grunt-template');
|
||||
grunt.loadNpmTasks('grunt-touch');
|
||||
grunt.loadNpmTasks('grunt-msbuild');
|
||||
grunt.loadTasks('tasks');
|
||||
|
||||
|
||||
grunt.registerTask('package', ['clean:package_artifacts', 'default', 'package:nuget', 'package:umbraco']);
|
||||
grunt.registerTask('package:nuget', ['copy:nuget_prepare', 'template:nuget_manifest', 'nugetpack', 'clean:package_temp']);
|
||||
grunt.registerTask('package:umbraco', ['copy:umbracopackage', 'umbracoPackage', 'clean:package_temp']);
|
||||
grunt.registerTask('touchwebconfigifenabled', function() { if (grunt.option("touch")) grunt.task.run("touch:webconfig") });
|
||||
grunt.registerTask('deploy', ['default', 'copy:deploy', 'touchwebconfigifenabled']);
|
||||
grunt.registerTask('css:build', ['less']);
|
||||
grunt.registerTask('js:build', ['concat']);
|
||||
grunt.registerTask('default', ['clean', 'css:build', 'js:build', 'copy:build', 'msbuild:dev']);
|
||||
};
|
||||
grunt.registerTask('default', ['clean', 'less', 'concat', 'assemblyinfo', 'msbuild:dist', 'copy:dll', 'copy:config', 'copy:html']);
|
||||
|
||||
grunt.registerTask('nuget', ['clean:tmp', 'default', 'copy:nuget', 'template:nuspec', 'nugetpack', 'clean:tmp']);
|
||||
grunt.registerTask('umbraco', ['clean:tmp', 'default', 'copy:umbraco', 'umbracoPackage', 'clean:tmp']);
|
||||
grunt.registerTask('package', ['clean:tmp', 'default', 'copy:nuget', 'template:nuspec', 'nugetpack', 'copy:umbraco', 'umbracoPackage', 'clean:tmp']);
|
||||
};
|
||||
@@ -1,5 +1,8 @@
|
||||
Archetype
|
||||
=========
|
||||

|
||||
|
||||

|
||||
|
||||
## Installation
|
||||
Install the selected <a href='https://github.com/imulus/Archetype/releases'>release</a> through the Umbraco package installer or via <a href='http://www.nuget.org/packages/Archetype/'>NuGet</a>.
|
||||
@@ -8,6 +11,8 @@ Install the selected <a href='https://github.com/imulus/Archetype/releases'>rele
|
||||
## Official Docs ##
|
||||
http://imulus.github.io/Archetype
|
||||
|
||||
Follow us on Twitter https://twitter.com/ArchetypeKit
|
||||
|
||||
## Contribute ##
|
||||
|
||||
Want to contribute to Archetype? You'll want to use Grunt (our task runner) to help you integrate with a local copy of Umbraco.
|
||||
@@ -21,10 +26,14 @@ Want to contribute to Archetype? You'll want to use Grunt (our task runner) to
|
||||
### Build ###
|
||||
grunt
|
||||
|
||||
Builds the project to `/dist/`. These files can be dropped into an Umbraco 7 site, or you can build directly to a site using:
|
||||
|
||||
grunt --target="D:\inetpub\mysite"
|
||||
|
||||
You can also watch for changes using:
|
||||
|
||||
grunt watch
|
||||
grunt watch --target="D:\inetpub\mysite"
|
||||
|
||||
### Deploy ###
|
||||
grunt deploy --target=C:\\path\\to\\umbraco\\site
|
||||
grunt watch:dev --target=C:\\path\to\\umbraco\\site
|
||||
|
||||
Add `--touch` to either command to automatically touch the web.config on a deploy
|
||||
|
||||
|
||||
@@ -31,29 +31,204 @@
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="AutoMapper">
|
||||
<HintPath>..\packages\AutoMapper.3.0.0\lib\net40\AutoMapper.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="AutoMapper.Net4">
|
||||
<HintPath>..\packages\AutoMapper.3.0.0\lib\net40\AutoMapper.Net4.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="businesslogic, Version=1.0.5242.22740, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\businesslogic.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ClientDependency.Core">
|
||||
<HintPath>..\packages\ClientDependency.1.7.1.2\lib\ClientDependency.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ClientDependency.Core.Mvc">
|
||||
<HintPath>..\packages\ClientDependency-Mvc.1.7.0.4\lib\ClientDependency.Core.Mvc.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="cms, Version=1.0.5242.22741, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\cms.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="controls, Version=1.0.5242.22742, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\controls.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="CookComputing.XmlRpcV2">
|
||||
<HintPath>..\packages\xmlrpcnet.2.5.0\lib\net20\CookComputing.XmlRpcV2.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Examine, Version=0.1.55.2941, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\Examine.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="HtmlAgilityPack">
|
||||
<HintPath>..\packages\HtmlAgilityPack.1.4.6\lib\Net45\HtmlAgilityPack.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ICSharpCode.SharpZipLib">
|
||||
<HintPath>..\packages\SharpZipLib.0.86.0\lib\20\ICSharpCode.SharpZipLib.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ImageProcessor, Version=1.9.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\ImageProcessor.1.9.0.0\lib\ImageProcessor.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ImageProcessor.Web, Version=3.2.3.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\ImageProcessor.Web.3.2.3.0\lib\net45\ImageProcessor.Web.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="interfaces, Version=1.0.5242.22737, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\interfaces.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="log4net, Version=1.2.11.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\log4net.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Lucene.Net">
|
||||
<HintPath>..\packages\Lucene.Net.2.9.4.1\lib\net40\Lucene.Net.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.ApplicationBlocks.Data, Version=1.0.1559.20655, Culture=neutral">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\Microsoft.ApplicationBlocks.Data.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\Microsoft.Web.Helpers.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<Private>True</Private>
|
||||
<HintPath>..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Web.Mvc.FixedDisplayModes">
|
||||
<HintPath>..\packages\Microsoft.AspNet.Mvc.FixedDisplayModes.1.0.1\lib\net40\Microsoft.Web.Mvc.FixedDisplayModes.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MiniProfiler">
|
||||
<HintPath>..\packages\MiniProfiler.2.1.0\lib\net40\MiniProfiler.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Moq">
|
||||
<HintPath>..\packages\Moq.4.2.1312.1622\lib\net40\Moq.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MySql.Data">
|
||||
<HintPath>..\packages\MySql.Data.6.6.5\lib\net40\MySql.Data.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\Newtonsoft.Json.6.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="nunit.framework">
|
||||
<HintPath>..\packages\NUnit.2.6.3\lib\nunit.framework.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="SQLCE4Umbraco, Version=1.0.5242.22741, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\SQLCE4Umbraco.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL">
|
||||
<Private>True</Private>
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\System.Data.SqlServerCe.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Data.SqlServerCe.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL">
|
||||
<Private>True</Private>
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\System.Data.SqlServerCe.Entity.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Net.Http.Formatting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.AspNet.WebApi.Client.4.0.30506.0\lib\net40\System.Net.Http.Formatting.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Net.Http.WebRequest" />
|
||||
<Reference Include="System.Web.Helpers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<Private>True</Private>
|
||||
<HintPath>..\packages\Microsoft.AspNet.WebPages.2.0.30506.0\lib\net40\System.Web.Helpers.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.AspNet.WebApi.Core.4.0.30506.0\lib\net40\System.Web.Http.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.Http.WebHost, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.AspNet.WebApi.WebHost.4.0.30506.0\lib\net40\System.Web.Http.WebHost.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<Private>True</Private>
|
||||
<HintPath>..\packages\Microsoft.AspNet.Mvc.4.0.30506.0\lib\net40\System.Web.Mvc.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\Microsoft.AspNet.Razor.2.0.30506.0\lib\net40\System.Web.Razor.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.WebPages, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<Private>True</Private>
|
||||
<HintPath>..\packages\Microsoft.AspNet.WebPages.2.0.30506.0\lib\net40\System.Web.WebPages.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.WebPages.Deployment, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<Private>True</Private>
|
||||
<HintPath>..\packages\Microsoft.AspNet.WebPages.2.0.30506.0\lib\net40\System.Web.WebPages.Deployment.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<Private>True</Private>
|
||||
<HintPath>..\packages\Microsoft.AspNet.WebPages.2.0.30506.0\lib\net40\System.Web.WebPages.Razor.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="Umbraco.Core">
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.0.1\lib\Umbraco.Core.dll</HintPath>
|
||||
<Reference Include="TidyNet, Version=1.0.0.0, Culture=neutral">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\TidyNet.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="umbraco, Version=1.0.5242.22743, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\umbraco.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Umbraco.Core, Version=1.0.5242.22738, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\Umbraco.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="umbraco.DataLayer, Version=1.0.5242.22740, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\umbraco.DataLayer.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="umbraco.editorControls, Version=1.0.5242.22746, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\umbraco.editorControls.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="umbraco.MacroEngines, Version=1.0.5242.22747, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\umbraco.MacroEngines.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="umbraco.providers, Version=1.0.5242.22742, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\umbraco.providers.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Umbraco.Web.UI, Version=1.0.5242.22748, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\Umbraco.Web.UI.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="umbraco.XmlSerializers, Version=1.0.5242.22743, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\umbraco.XmlSerializers.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="UmbracoExamine, Version=0.6.0.22741, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\UmbracoExamine.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="UrlRewritingNet.UrlRewriter, Version=2.0.60829.1, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\UrlRewritingNet.UrlRewriter.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Models\FieldsetTests.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="PropertyValueConverter\PropertyValueConverterTests.cs" />
|
||||
<Compile Include="Serialization\ArchetypeJsonConverterComplexModelTest.cs" />
|
||||
<Compile Include="Serialization\ArchetypeJsonConverterTest.cs" />
|
||||
<Compile Include="Serialization\JsonTestStrings.cs" />
|
||||
<Compile Include="Serialization\JsonTestModels.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="app.config" />
|
||||
<None Include="Data\sample-1.json" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
@@ -63,6 +238,7 @@
|
||||
<Name>Archetype.Umbraco</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
|
||||
@@ -4,7 +4,7 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Archetype.Umbraco.PropertyConverters;
|
||||
using Archetype.PropertyConverters;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Archetype.Tests.Models
|
||||
@@ -26,7 +26,7 @@ namespace Archetype.Tests.Models
|
||||
public void Can_Get_Fieldset_Property_By_Alias()
|
||||
{
|
||||
var converter = new ArchetypeValueConverter();
|
||||
var result = (Archetype.Umbraco.Models.Archetype)converter.ConvertDataToSource(null, _sampleJson, false);
|
||||
var result = (Archetype.Models.ArchetypeModel)converter.ConvertDataToSource(null, _sampleJson, false);
|
||||
|
||||
var fieldset = result.Fieldsets.First();
|
||||
var propertyValue = fieldset.GetValue("boxHeadline");
|
||||
@@ -38,7 +38,7 @@ namespace Archetype.Tests.Models
|
||||
public void Can_Convert_Property_Value_Types()
|
||||
{
|
||||
var converter = new ArchetypeValueConverter();
|
||||
var result = (Archetype.Umbraco.Models.Archetype)converter.ConvertDataToSource(null, _sampleJson, false);
|
||||
var result = (Archetype.Models.ArchetypeModel)converter.ConvertDataToSource(null, _sampleJson, false);
|
||||
|
||||
var fieldset = result.Fieldsets.First();
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace Archetype.Tests.Models
|
||||
public void Returns_String_When_No_Type_Specified()
|
||||
{
|
||||
var converter = new ArchetypeValueConverter();
|
||||
var result = (Archetype.Umbraco.Models.Archetype)converter.ConvertDataToSource(null, _sampleJson, false);
|
||||
var result = (Archetype.Models.ArchetypeModel)converter.ConvertDataToSource(null, _sampleJson, false);
|
||||
|
||||
var fieldset = result.Fieldsets.First();
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Archetype.Umbraco.PropertyConverters;
|
||||
using Archetype.PropertyConverters;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
@@ -24,39 +24,37 @@ namespace Archetype.Tests.PropertyValueConverter
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Returns_Null_When_Data_Is_Null()
|
||||
[TestCase(null)]
|
||||
[TestCase("")]
|
||||
public void Returns_Empty_Archetype_When_Data_Is_Null_Or_Empty(object data)
|
||||
{
|
||||
var converter = new ArchetypeValueConverter();
|
||||
var result = converter.ConvertDataToSource(null, null, false);
|
||||
|
||||
Assert.IsNull(result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Returns_Empty_String_When_Data_Is_Empty_String()
|
||||
{
|
||||
var data = "";
|
||||
var converter = new ArchetypeValueConverter();
|
||||
var result = converter.ConvertDataToSource(null, data, false);
|
||||
|
||||
Assert.AreEqual("", result);
|
||||
Assert.AreEqual(result.GetType(), typeof (Archetype.Models.ArchetypeModel));
|
||||
|
||||
var fieldsets = (Archetype.Models.ArchetypeModel) result;
|
||||
Assert.IsTrue(fieldsets.Count() == 0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Returns_Original_String_When_Data_Is_Invalid_Json()
|
||||
public void Returns_Empty_Archetype_When_Data_Is_Invalid_Json()
|
||||
{
|
||||
var data = "{ invalid";
|
||||
var converter = new ArchetypeValueConverter();
|
||||
var result = converter.ConvertDataToSource(null, data, false);
|
||||
|
||||
Assert.AreEqual(data, result);
|
||||
Assert.AreEqual(result.GetType(), typeof (Archetype.Models.ArchetypeModel));
|
||||
|
||||
var fieldsets = (Archetype.Models.ArchetypeModel) result;
|
||||
Assert.IsTrue(fieldsets.Count() == 0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Can_Serialize_From_Json_Model()
|
||||
{
|
||||
var converter = new ArchetypeValueConverter();
|
||||
var result = (Archetype.Umbraco.Models.Archetype)converter.ConvertDataToSource(null, _sampleJson, false);
|
||||
var result = (Archetype.Models.ArchetypeModel)converter.ConvertDataToSource(null, _sampleJson, false);
|
||||
|
||||
Assert.That(result != null);
|
||||
Assert.That(result.Fieldsets.Count() == 2);
|
||||
|
||||
@@ -0,0 +1,216 @@
|
||||
using System.Linq;
|
||||
using Archetype.PropertyConverters;
|
||||
using Newtonsoft.Json;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Archetype.Tests.Serialization
|
||||
{
|
||||
[TestFixture]
|
||||
public class ArchetypeJsonConverterComplexModelTest
|
||||
{
|
||||
private TextList _textList;
|
||||
private Captions _captions;
|
||||
private PageDetails _pageDetails;
|
||||
|
||||
private SlideShow _slides;
|
||||
private Seo _seo;
|
||||
private TextPageList _textPages;
|
||||
private PageList _pages;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
InitComplexModels();
|
||||
InitComplexTreeModel();
|
||||
}
|
||||
|
||||
#region complex nested model tests
|
||||
|
||||
[Test]
|
||||
public void PageDetailsModel_Serializes_To_Archetype_Property()
|
||||
{
|
||||
var result = JsonConvert.SerializeObject(_pageDetails, Formatting.Indented);
|
||||
Assert.AreEqual(JsonTestStrings._PAGE_DETAILS_JSON, result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConvertComplexModelToArchetype()
|
||||
{
|
||||
var converter = new ArchetypeValueConverter();
|
||||
var json = JsonConvert.SerializeObject(_pageDetails, Formatting.Indented);
|
||||
var archetype = (Archetype.Models.ArchetypeModel)converter.ConvertDataToSource(null, json, false);
|
||||
|
||||
Assert.NotNull(archetype);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeserializeComplexModelFromArchetype()
|
||||
{
|
||||
var result = JsonConvert.DeserializeObject<PageDetails>(JsonTestStrings._PAGE_DETAILS_JSON);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.IsInstanceOf<PageDetails>(result);
|
||||
|
||||
Assert.AreEqual("2439,2440,2441,2442,2443,2444,2445,2446,2447,2448,2449,2450,2451,2452,2453", result.Pages);
|
||||
Assert.AreEqual("First Page", result.Captions.TextStringArray.ElementAt(0).TextString);
|
||||
Assert.AreEqual("Second Page", result.Captions.TextStringArray.ElementAt(1).TextString);
|
||||
Assert.AreEqual("Third Page", result.Captions.TextStringArray.ElementAt(2).TextString);
|
||||
Assert.AreEqual("Fourth Page", result.Captions.TextStringArray.ElementAt(3).TextString);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SerializeThenDeserializeComplexModelFromArchetype()
|
||||
{
|
||||
var json = JsonConvert.SerializeObject(_pageDetails);
|
||||
var result = JsonConvert.DeserializeObject<PageDetails>(json);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.IsInstanceOf<PageDetails>(result);
|
||||
|
||||
Assert.AreEqual(_pageDetails.Pages, result.Pages);
|
||||
Assert.AreEqual(_pageDetails.Captions.TextStringArray.ElementAt(0).TextString, result.Captions.TextStringArray.ElementAt(0).TextString);
|
||||
Assert.AreEqual(_pageDetails.Captions.TextStringArray.ElementAt(1).TextString, result.Captions.TextStringArray.ElementAt(1).TextString);
|
||||
Assert.AreEqual(_pageDetails.Captions.TextStringArray.ElementAt(2).TextString, result.Captions.TextStringArray.ElementAt(2).TextString);
|
||||
Assert.AreEqual(_pageDetails.Captions.TextStringArray.ElementAt(3).TextString, result.Captions.TextStringArray.ElementAt(3).TextString);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region complex nested tree model tests
|
||||
|
||||
[Test]
|
||||
public void ConvertComplexNestedModelToArchetype()
|
||||
{
|
||||
var converter = new ArchetypeValueConverter();
|
||||
var json = JsonConvert.SerializeObject(_pages, Formatting.Indented);
|
||||
var archetype = (Archetype.Models.ArchetypeModel)converter.ConvertDataToSource(null, json, false);
|
||||
|
||||
Assert.NotNull(archetype);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PagesModel_Serializes_To_Archetype_Property()
|
||||
{
|
||||
var result = JsonConvert.SerializeObject(_pages, Formatting.Indented);
|
||||
Assert.AreEqual(JsonTestStrings._PAGES_JSON, result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeserializeComplexTreeModelFromArchetype()
|
||||
{
|
||||
var result = JsonConvert.DeserializeObject<PageList>(JsonTestStrings._PAGES_JSON);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.IsInstanceOf<PageList>(result);
|
||||
|
||||
Assert.AreEqual("1,2,3,4,5,6,7,8", result.Pages.ElementAt(0).Media.Slides);
|
||||
Assert.AreEqual("1,2,3,4,5,6,7,8", result.Pages.ElementAt(1).Media.Slides);
|
||||
Assert.AreEqual("1,2,3,4,5,6,7,8", result.Pages.ElementAt(2).Media.Slides);
|
||||
|
||||
Assert.AreEqual("Test Meta Title", result.Pages.ElementAt(0).Seo.MetaTitle);
|
||||
Assert.AreEqual("Test Meta Description", result.Pages.ElementAt(0).Seo.MetaDescription);
|
||||
Assert.AreEqual("Test Meta Title", result.Pages.ElementAt(1).Seo.MetaTitle);
|
||||
Assert.AreEqual("Test Meta Description", result.Pages.ElementAt(1).Seo.MetaDescription);
|
||||
Assert.AreEqual("Test Meta Title", result.Pages.ElementAt(2).Seo.MetaTitle);
|
||||
Assert.AreEqual("Test Meta Description", result.Pages.ElementAt(2).Seo.MetaDescription);
|
||||
|
||||
Assert.AreEqual("Home Page Body", result.Pages.ElementAt(0).BodyText);
|
||||
Assert.AreEqual("Home Page", result.Pages.ElementAt(0).PageTitle);
|
||||
Assert.AreEqual("About us Page Body", result.Pages.ElementAt(1).BodyText);
|
||||
Assert.AreEqual("About us Page", result.Pages.ElementAt(1).PageTitle);
|
||||
Assert.AreEqual("Contact us Page Body", result.Pages.ElementAt(2).BodyText);
|
||||
Assert.AreEqual("Contact us Page", result.Pages.ElementAt(2).PageTitle);
|
||||
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SerializeThenDeserializeComplexTreeModelFromArchetype()
|
||||
{
|
||||
var json = JsonConvert.SerializeObject(_pages);
|
||||
var result = JsonConvert.DeserializeObject<PageList>(json);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.IsInstanceOf<PageList>(result);
|
||||
|
||||
Assert.AreEqual(_pages.Pages.ElementAt(0).Media.Slides, result.Pages.ElementAt(0).Media.Slides);
|
||||
Assert.AreEqual(_pages.Pages.ElementAt(1).Media.Slides, result.Pages.ElementAt(1).Media.Slides);
|
||||
Assert.AreEqual(_pages.Pages.ElementAt(2).Media.Slides, result.Pages.ElementAt(2).Media.Slides);
|
||||
|
||||
Assert.AreEqual(_pages.Pages.ElementAt(0).Seo.MetaTitle, result.Pages.ElementAt(0).Seo.MetaTitle);
|
||||
Assert.AreEqual(_pages.Pages.ElementAt(0).Seo.MetaDescription, result.Pages.ElementAt(0).Seo.MetaDescription);
|
||||
Assert.AreEqual(_pages.Pages.ElementAt(1).Seo.MetaTitle, result.Pages.ElementAt(1).Seo.MetaTitle);
|
||||
Assert.AreEqual(_pages.Pages.ElementAt(1).Seo.MetaDescription, result.Pages.ElementAt(1).Seo.MetaDescription);
|
||||
Assert.AreEqual(_pages.Pages.ElementAt(2).Seo.MetaTitle, result.Pages.ElementAt(2).Seo.MetaTitle);
|
||||
Assert.AreEqual(_pages.Pages.ElementAt(2).Seo.MetaDescription, result.Pages.ElementAt(2).Seo.MetaDescription);
|
||||
|
||||
Assert.AreEqual(_pages.Pages.ElementAt(0).BodyText, result.Pages.ElementAt(0).BodyText);
|
||||
Assert.AreEqual(_pages.Pages.ElementAt(0).PageTitle, result.Pages.ElementAt(0).PageTitle);
|
||||
Assert.AreEqual(_pages.Pages.ElementAt(1).BodyText, result.Pages.ElementAt(1).BodyText);
|
||||
Assert.AreEqual(_pages.Pages.ElementAt(1).PageTitle, result.Pages.ElementAt(1).PageTitle);
|
||||
Assert.AreEqual(_pages.Pages.ElementAt(2).BodyText, result.Pages.ElementAt(2).BodyText);
|
||||
Assert.AreEqual(_pages.Pages.ElementAt(2).PageTitle, result.Pages.ElementAt(2).PageTitle);
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region utility methods
|
||||
|
||||
private void InitComplexModels()
|
||||
{
|
||||
_textList = new TextList
|
||||
{
|
||||
new TextItem{TextString = "First Page"},
|
||||
new TextItem{TextString = "Second Page"},
|
||||
new TextItem{TextString = "Third Page"},
|
||||
new TextItem{TextString = "Fourth Page"}
|
||||
};
|
||||
|
||||
_captions = new Captions {TextStringArray = _textList};
|
||||
|
||||
_pageDetails = new PageDetails
|
||||
{
|
||||
Captions = _captions,
|
||||
Pages = "2439,2440,2441,2442,2443,2444,2445,2446,2447,2448,2449,2450,2451,2452,2453"
|
||||
};
|
||||
}
|
||||
|
||||
private void InitComplexTreeModel()
|
||||
{
|
||||
_slides = new SlideShow{Slides = "1,2,3,4,5,6,7,8"};
|
||||
_seo = new Seo{MetaDescription = "Test Meta Description", MetaTitle = "Test Meta Title"};
|
||||
_textPages = new TextPageList
|
||||
{
|
||||
new TextPage()
|
||||
{
|
||||
PageTitle = "Home Page",
|
||||
BodyText = "Home Page Body",
|
||||
Media = _slides,
|
||||
Seo = _seo
|
||||
},
|
||||
new TextPage()
|
||||
{
|
||||
PageTitle = "About us Page",
|
||||
BodyText = "About us Page Body",
|
||||
Media = _slides,
|
||||
Seo = _seo
|
||||
},
|
||||
new TextPage()
|
||||
{
|
||||
PageTitle = "Contact us Page",
|
||||
BodyText = "Contact us Page Body",
|
||||
Media = _slides,
|
||||
Seo = _seo
|
||||
}
|
||||
};
|
||||
|
||||
_pages = new PageList
|
||||
{
|
||||
Pages = _textPages
|
||||
};
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,367 @@
|
||||
using System;
|
||||
using Archetype.PropertyConverters;
|
||||
using Newtonsoft.Json;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Archetype.Tests.Serialization
|
||||
{
|
||||
[TestFixture]
|
||||
public class ArchetypeJsonConverterTest
|
||||
{
|
||||
private ContactDetails _contactDetails;
|
||||
private CompanyDetails _companyDetails;
|
||||
private AnnualStatement _annualStatement;
|
||||
private MergerDetails _mergerDetails;
|
||||
private UrlPicker _webSite;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_webSite = new UrlPicker
|
||||
{
|
||||
Url = "http://test.com",
|
||||
Title = "The Test Company",
|
||||
OpenInNewWindow = true
|
||||
};
|
||||
|
||||
_mergerDetails = new MergerDetails
|
||||
{
|
||||
MergerDate = new DateTime(2014,6,7,8,9,10),
|
||||
MergerValue = 12345676890.12m
|
||||
};
|
||||
|
||||
_contactDetails = new ContactDetails
|
||||
{
|
||||
Address = "Test Address",
|
||||
Email = "test@test.com",
|
||||
Fax = "000",
|
||||
Mobile = "000",
|
||||
Name = "Test",
|
||||
Telephone = "111",
|
||||
WebSite = _webSite
|
||||
};
|
||||
|
||||
_companyDetails = new CompanyDetails
|
||||
{
|
||||
Region = "Test Region",
|
||||
ContactDetails = _contactDetails
|
||||
};
|
||||
|
||||
_annualStatement = new AnnualStatement
|
||||
{
|
||||
FiscalYearStart = new DateTime(2013, 9, 1),
|
||||
FiscalYearEnd = new DateTime(2014, 8, 31),
|
||||
TotalShares = 345678,
|
||||
Sales = 123456700.89,
|
||||
Profit = 1123456.78m
|
||||
};
|
||||
}
|
||||
|
||||
#region serialization tests
|
||||
|
||||
[Test]
|
||||
public void MergerDetailsModel_Serializes_To_Archetype_Property()
|
||||
{
|
||||
var result = JsonConvert.SerializeObject(_mergerDetails, Formatting.Indented);
|
||||
Assert.AreEqual(JsonTestStrings._MERGER_DETAILS_JSON, result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ContactDetailsModel_Serializes_To_Archetype_Property()
|
||||
{
|
||||
var result = JsonConvert.SerializeObject(_contactDetails, Formatting.Indented);
|
||||
Assert.AreEqual(JsonTestStrings._CONTACT_DETAILS_JSON, result);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CompanyDetailsModel_Fieldset_Serializes_As_Expected()
|
||||
{
|
||||
var result = JsonConvert.SerializeObject(_companyDetails, Formatting.Indented);
|
||||
|
||||
Assert.AreEqual(JsonTestStrings._COMPANY_DETAILS_JSON, result);
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AnnualStatementModel_Fieldset_Serializes_As_Expected()
|
||||
{
|
||||
var result = JsonConvert.SerializeObject(_annualStatement, Formatting.Indented);
|
||||
|
||||
Assert.AreEqual(JsonTestStrings._ANNUAL_STATEMENT_JSON, result);
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NullValues_Serialize_To_Empty_String()
|
||||
{
|
||||
var result = JsonConvert.SerializeObject(new ContactDetails());
|
||||
|
||||
Assert.AreEqual(JsonTestStrings._NULL_VALUES_JSON, result);
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConvertModelToArchetype()
|
||||
{
|
||||
var model = new ContactDetails
|
||||
{
|
||||
Address = "addr",
|
||||
Email = "email"
|
||||
};
|
||||
|
||||
var converter = new ArchetypeValueConverter();
|
||||
var json = JsonConvert.SerializeObject(model);
|
||||
var archetype = (Archetype.Models.ArchetypeModel)converter.ConvertDataToSource(null, json, false);
|
||||
|
||||
Assert.NotNull(archetype);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConvertNumericAndDateModelToArchetype()
|
||||
{
|
||||
var converter = new ArchetypeValueConverter();
|
||||
var json = JsonConvert.SerializeObject(_annualStatement);
|
||||
var archetype = (Archetype.Models.ArchetypeModel)converter.ConvertDataToSource(null, json, false);
|
||||
|
||||
Assert.NotNull(archetype);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConvertCompoundModelToArchetype()
|
||||
{
|
||||
var item1 = new ContactDetails
|
||||
{
|
||||
Address = "addr",
|
||||
Email = "email"
|
||||
};
|
||||
|
||||
var item2 = new ContactDetails
|
||||
{
|
||||
Address = "addr1",
|
||||
Name = "email2"
|
||||
};
|
||||
|
||||
var model = new AllContactDetails
|
||||
{
|
||||
UserDetails = item1,
|
||||
AdminDetails = item2
|
||||
};
|
||||
|
||||
var converter = new ArchetypeValueConverter();
|
||||
var json = JsonConvert.SerializeObject(model, Formatting.Indented);
|
||||
var archetype = (Archetype.Models.ArchetypeModel)converter.ConvertDataToSource(null, json, false);
|
||||
|
||||
Assert.NotNull(archetype);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConvertEnumerableModelToArchetype()
|
||||
{
|
||||
var item1 = new ContactDetails
|
||||
{
|
||||
Address = "addr",
|
||||
Email = "email"
|
||||
};
|
||||
|
||||
var item2 = new ContactDetails
|
||||
{
|
||||
Address = "addr1",
|
||||
Name = "email2"
|
||||
};
|
||||
|
||||
var model = new ContactDetailsList
|
||||
{
|
||||
item1,
|
||||
item2
|
||||
};
|
||||
|
||||
var converter = new ArchetypeValueConverter();
|
||||
var json = JsonConvert.SerializeObject(model, Formatting.Indented);
|
||||
var archetype = (Archetype.Models.ArchetypeModel)converter.ConvertDataToSource(null, json, false);
|
||||
|
||||
Assert.NotNull(archetype);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConvertNestedModelToArchetype()
|
||||
{
|
||||
var model = new CompanyDetails
|
||||
{
|
||||
Region = "Test Region",
|
||||
ContactDetails = new ContactDetails
|
||||
{
|
||||
Address = "addr1",
|
||||
Name = "email2"
|
||||
}
|
||||
};
|
||||
|
||||
var converter = new ArchetypeValueConverter();
|
||||
var json = JsonConvert.SerializeObject(model, Formatting.Indented);
|
||||
var archetype = (Archetype.Models.ArchetypeModel)converter.ConvertDataToSource(null, json, false);
|
||||
|
||||
Assert.NotNull(archetype);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region deserialization tests
|
||||
|
||||
[Test]
|
||||
public void DeserializeModelFromArchetype()
|
||||
{
|
||||
var result = JsonConvert.DeserializeObject<ContactDetails>(JsonTestStrings._CONTACT_DETAILS_JSON);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.IsInstanceOf<ContactDetails>(result);
|
||||
|
||||
Assert.AreEqual("Test Address", result.Address);
|
||||
Assert.AreEqual("test@test.com", result.Email);
|
||||
Assert.AreEqual("000", result.Fax);
|
||||
Assert.AreEqual("000", result.Mobile);
|
||||
Assert.AreEqual("Test", result.Name);
|
||||
Assert.AreEqual("111", result.Telephone);
|
||||
Assert.AreEqual(_webSite.Content, result.WebSite.Content);
|
||||
Assert.AreEqual(_webSite.Media, result.WebSite.Media);
|
||||
Assert.AreEqual(_webSite.OpenInNewWindow, result.WebSite.OpenInNewWindow);
|
||||
Assert.AreEqual(_webSite.Title, result.WebSite.Title);
|
||||
Assert.AreEqual(_webSite.Url, result.WebSite.Url);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeserializeNumericAndDateModelFromArchetype()
|
||||
{
|
||||
var result = JsonConvert.DeserializeObject<AnnualStatement>(JsonTestStrings._ANNUAL_STATEMENT_JSON);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.IsInstanceOf<AnnualStatement>(result);
|
||||
|
||||
Assert.AreEqual(new DateTime(2013, 9, 1), result.FiscalYearStart);
|
||||
Assert.AreEqual(new DateTime(2014, 8, 31), result.FiscalYearEnd);
|
||||
Assert.IsNull(result.DividendPaymentDate);
|
||||
Assert.AreEqual(345678, result.TotalShares);
|
||||
Assert.AreEqual(123456700.89, result.Sales);
|
||||
Assert.AreEqual(1123456.78m, result.Profit);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeserializeNumericAndDateModel_NullableDate_HasValue_FromArchetype()
|
||||
{
|
||||
var annualStatement = new AnnualStatement
|
||||
{
|
||||
FiscalYearStart = new DateTime(2013, 9, 1),
|
||||
FiscalYearEnd = new DateTime(2014, 8, 31),
|
||||
DividendPaymentDate = new DateTime(2014,9,15,10,15,30),
|
||||
TotalShares = 345678,
|
||||
Sales = 123456700.89,
|
||||
Profit = 1123456.78m
|
||||
};
|
||||
|
||||
var json = JsonConvert.SerializeObject(annualStatement);
|
||||
var result = JsonConvert.DeserializeObject<AnnualStatement>(json);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.IsInstanceOf<AnnualStatement>(result);
|
||||
|
||||
Assert.AreEqual(annualStatement.FiscalYearStart, result.FiscalYearStart);
|
||||
Assert.AreEqual(annualStatement.FiscalYearEnd, result.FiscalYearEnd);
|
||||
Assert.AreEqual(annualStatement.DividendPaymentDate, result.DividendPaymentDate);
|
||||
Assert.AreEqual(annualStatement.TotalShares, result.TotalShares);
|
||||
Assert.AreEqual(annualStatement.Sales, result.Sales);
|
||||
Assert.AreEqual(annualStatement.Profit, result.Profit);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeserializeCompoundModelFromArchetype()
|
||||
{
|
||||
var item1 = new ContactDetails
|
||||
{
|
||||
Address = "addr",
|
||||
Email = "email"
|
||||
};
|
||||
|
||||
var item2 = new ContactDetails
|
||||
{
|
||||
Address = "addr1",
|
||||
Name = "email2"
|
||||
};
|
||||
|
||||
var model = new AllContactDetails
|
||||
{
|
||||
UserDetails = item1,
|
||||
AdminDetails = item2
|
||||
};
|
||||
|
||||
var json = JsonConvert.SerializeObject(model, Formatting.Indented);
|
||||
var result = JsonConvert.DeserializeObject<AllContactDetails>(json);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.IsInstanceOf<AllContactDetails>(result);
|
||||
|
||||
Assert.AreEqual(item1.Address, result.UserDetails.Address);
|
||||
Assert.AreEqual(item1.Email, result.UserDetails.Email);
|
||||
Assert.AreEqual(item2.Address, result.AdminDetails.Address);
|
||||
Assert.AreEqual(item2.Name, result.AdminDetails.Name);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeserializeEnumerableModelFromArchetype()
|
||||
{
|
||||
var item1 = new ContactDetails
|
||||
{
|
||||
Address = "addr",
|
||||
Email = "email"
|
||||
};
|
||||
|
||||
var item2 = new ContactDetails
|
||||
{
|
||||
Address = "addr1",
|
||||
Name = "email2"
|
||||
};
|
||||
|
||||
var model = new ContactDetailsList
|
||||
{
|
||||
item1,
|
||||
item2
|
||||
};
|
||||
|
||||
var json = JsonConvert.SerializeObject(model, Formatting.Indented);
|
||||
var result = JsonConvert.DeserializeObject<ContactDetailsList>(json);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.IsInstanceOf<ContactDetailsList>(result);
|
||||
Assert.AreEqual(result.Count, 2);
|
||||
|
||||
Assert.AreEqual(item1.Address, result[0].Address);
|
||||
Assert.AreEqual(item1.Email, result[0].Email);
|
||||
Assert.AreEqual(item2.Address, result[1].Address);
|
||||
Assert.AreEqual(item2.Name, result[1].Name);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeserializeNestedModelFromArchetype()
|
||||
{
|
||||
var model = new CompanyDetails
|
||||
{
|
||||
Region = "Test Region",
|
||||
ContactDetails = new ContactDetails
|
||||
{
|
||||
Address = "addr1",
|
||||
Name = "email2"
|
||||
}
|
||||
};
|
||||
|
||||
var json = JsonConvert.SerializeObject(model, Formatting.Indented);
|
||||
var result = JsonConvert.DeserializeObject<CompanyDetails>(json);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.IsInstanceOf<CompanyDetails>(result);
|
||||
|
||||
Assert.AreEqual(model.Region, result.Region);
|
||||
Assert.AreEqual(model.ContactDetails.Address, result.ContactDetails.Address);
|
||||
Assert.AreEqual(model.ContactDetails.Name, result.ContactDetails.Name);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Archetype.Serialization;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Archetype.Tests.Serialization
|
||||
{
|
||||
#region json test Models
|
||||
|
||||
[AsArchetype("urlPicker")]
|
||||
[JsonConverter(typeof(ArchetypeJsonConverter))]
|
||||
public class UrlPicker
|
||||
{
|
||||
[JsonProperty("title")]
|
||||
public string Title { get; set; }
|
||||
[JsonProperty("url")]
|
||||
public string Url { get; set; }
|
||||
[JsonProperty("content")]
|
||||
public int? Content { get; set; }
|
||||
[JsonProperty("media")]
|
||||
public int? Media { get; set; }
|
||||
[JsonProperty("openInNewWindow")]
|
||||
public bool OpenInNewWindow { get; set; }
|
||||
}
|
||||
|
||||
[AsArchetype("contactDetails")]
|
||||
[JsonConverter(typeof(ArchetypeJsonConverter))]
|
||||
public class ContactDetails
|
||||
{
|
||||
[JsonProperty("name")]
|
||||
public string Name { get; set; }
|
||||
[JsonProperty("address")]
|
||||
public string Address { get; set; }
|
||||
[JsonProperty("telephone")]
|
||||
public string Telephone { get; set; }
|
||||
[JsonProperty("mobile")]
|
||||
public string Mobile { get; set; }
|
||||
[JsonProperty("fax")]
|
||||
public string Fax { get; set; }
|
||||
[JsonProperty("email")]
|
||||
public string Email { get; set; }
|
||||
[JsonProperty("webSite")]
|
||||
public UrlPicker WebSite { get; set; }
|
||||
}
|
||||
|
||||
[AsArchetype("companyDetails")]
|
||||
[JsonConverter(typeof(ArchetypeJsonConverter))]
|
||||
public class CompanyDetails
|
||||
{
|
||||
[JsonProperty("region")]
|
||||
public string Region { get; set; }
|
||||
[JsonProperty("contactDetails")]
|
||||
public ContactDetails ContactDetails { get; set; }
|
||||
}
|
||||
|
||||
[AsArchetype("allContactDetails")]
|
||||
[JsonConverter(typeof(ArchetypeJsonConverter))]
|
||||
public class AllContactDetails
|
||||
{
|
||||
public ContactDetails UserDetails { get; set; }
|
||||
public ContactDetails AdminDetails { get; set; }
|
||||
|
||||
}
|
||||
|
||||
[AsArchetype("contactDetailsList")]
|
||||
[JsonConverter(typeof(ArchetypeJsonConverter))]
|
||||
public class ContactDetailsList : List<ContactDetails>
|
||||
{
|
||||
}
|
||||
|
||||
[AsArchetype("annualStatement")]
|
||||
[JsonConverter(typeof(ArchetypeJsonConverter))]
|
||||
public class AnnualStatement
|
||||
{
|
||||
public DateTime FiscalYearStart { get; set; }
|
||||
public DateTime FiscalYearEnd { get; set; }
|
||||
public DateTime? DividendPaymentDate { get; set; }
|
||||
public Int32 TotalShares { get; set; }
|
||||
public Double Sales { get; set; }
|
||||
public Decimal Profit { get; set; }
|
||||
}
|
||||
|
||||
[AsArchetype("mergerDetails")]
|
||||
[JsonConverter(typeof(ArchetypeJsonConverter))]
|
||||
public class MergerDetails
|
||||
{
|
||||
public DateTime MergerDate { get; set; }
|
||||
[JsonIgnore]
|
||||
public decimal MergerValue { get; set; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region complex nested model
|
||||
|
||||
[AsArchetype("pages")]
|
||||
[JsonConverter(typeof(ArchetypeJsonConverter))]
|
||||
public class PageDetails
|
||||
{
|
||||
[JsonProperty("pages")]
|
||||
public string Pages { get; set; }
|
||||
[AsFieldset]
|
||||
[JsonProperty("captions")]
|
||||
public Captions Captions { get; set; }
|
||||
}
|
||||
|
||||
[AsArchetype("captions")]
|
||||
[JsonConverter(typeof(ArchetypeJsonConverter))]
|
||||
public class Captions
|
||||
{
|
||||
[JsonProperty("captions")]
|
||||
public TextList TextStringArray { get; set; }
|
||||
}
|
||||
|
||||
[AsArchetype("textstringArray")]
|
||||
[JsonConverter(typeof(ArchetypeJsonConverter))]
|
||||
public class TextList : List<TextItem>
|
||||
{
|
||||
}
|
||||
|
||||
[AsArchetype("textstringArray")]
|
||||
[JsonConverter(typeof(ArchetypeJsonConverter))]
|
||||
public class TextItem
|
||||
{
|
||||
[JsonProperty("textstring")]
|
||||
public string TextString { get; set; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region complex nested tree model
|
||||
|
||||
public abstract class PageBase
|
||||
{
|
||||
public string PageTitle { get; set; }
|
||||
public string BodyText { get; set; }
|
||||
}
|
||||
|
||||
[AsArchetype("slideShow")]
|
||||
[JsonConverter(typeof(ArchetypeJsonConverter))]
|
||||
public class SlideShow
|
||||
{
|
||||
public string Slides { get; set; }
|
||||
}
|
||||
|
||||
[AsArchetype("seo")]
|
||||
[JsonConverter(typeof(ArchetypeJsonConverter))]
|
||||
public class Seo
|
||||
{
|
||||
public string MetaTitle { get; set; }
|
||||
public string MetaDescription { get; set; }
|
||||
}
|
||||
|
||||
[AsArchetype("TextPage")]
|
||||
[JsonConverter(typeof(ArchetypeJsonConverter))]
|
||||
public class TextPage : PageBase
|
||||
{
|
||||
[AsFieldset]
|
||||
public SlideShow Media { get; set; }
|
||||
|
||||
[AsFieldset]
|
||||
public Seo Seo { get; set; }
|
||||
}
|
||||
|
||||
[AsArchetype("TextPageList")]
|
||||
[JsonConverter(typeof(ArchetypeJsonConverter))]
|
||||
public class TextPageList : List<TextPage>
|
||||
{
|
||||
}
|
||||
|
||||
[AsArchetype("Pages")]
|
||||
[JsonConverter(typeof(ArchetypeJsonConverter))]
|
||||
public class PageList
|
||||
{
|
||||
public TextPageList Pages { get; set; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,435 @@
|
||||
namespace Archetype.Tests.Serialization
|
||||
{
|
||||
public class JsonTestStrings
|
||||
{
|
||||
public const string _MERGER_DETAILS_JSON =
|
||||
@"{
|
||||
""fieldsets"": [
|
||||
{
|
||||
""alias"": ""mergerDetails"",
|
||||
""properties"": [
|
||||
{
|
||||
""alias"": ""MergerDate"",
|
||||
""value"": ""07/06/2014 08:09:10""
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}";
|
||||
|
||||
public const string _ANNUAL_STATEMENT_JSON =
|
||||
@"{
|
||||
""fieldsets"": [
|
||||
{
|
||||
""alias"": ""annualStatement"",
|
||||
""properties"": [
|
||||
{
|
||||
""alias"": ""FiscalYearStart"",
|
||||
""value"": ""01/09/2013 00:00:00""
|
||||
},
|
||||
{
|
||||
""alias"": ""FiscalYearEnd"",
|
||||
""value"": ""31/08/2014 00:00:00""
|
||||
},
|
||||
{
|
||||
""alias"": ""DividendPaymentDate"",
|
||||
""value"": """"
|
||||
},
|
||||
{
|
||||
""alias"": ""TotalShares"",
|
||||
""value"": ""345678""
|
||||
},
|
||||
{
|
||||
""alias"": ""Sales"",
|
||||
""value"": ""123456700.89""
|
||||
},
|
||||
{
|
||||
""alias"": ""Profit"",
|
||||
""value"": ""1123456.78""
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}";
|
||||
|
||||
public const string _CONTACT_DETAILS_JSON =
|
||||
@"{
|
||||
""fieldsets"": [
|
||||
{
|
||||
""alias"": ""contactDetails"",
|
||||
""properties"": [
|
||||
{
|
||||
""alias"": ""name"",
|
||||
""value"": ""Test""
|
||||
},
|
||||
{
|
||||
""alias"": ""address"",
|
||||
""value"": ""Test Address""
|
||||
},
|
||||
{
|
||||
""alias"": ""telephone"",
|
||||
""value"": ""111""
|
||||
},
|
||||
{
|
||||
""alias"": ""mobile"",
|
||||
""value"": ""000""
|
||||
},
|
||||
{
|
||||
""alias"": ""fax"",
|
||||
""value"": ""000""
|
||||
},
|
||||
{
|
||||
""alias"": ""email"",
|
||||
""value"": ""test@test.com""
|
||||
},
|
||||
{
|
||||
""alias"": ""webSite"",
|
||||
""value"": {
|
||||
""fieldsets"": [
|
||||
{
|
||||
""alias"": ""urlPicker"",
|
||||
""properties"": [
|
||||
{
|
||||
""alias"": ""title"",
|
||||
""value"": ""The Test Company""
|
||||
},
|
||||
{
|
||||
""alias"": ""url"",
|
||||
""value"": ""http://test.com""
|
||||
},
|
||||
{
|
||||
""alias"": ""content"",
|
||||
""value"": """"
|
||||
},
|
||||
{
|
||||
""alias"": ""media"",
|
||||
""value"": """"
|
||||
},
|
||||
{
|
||||
""alias"": ""openInNewWindow"",
|
||||
""value"": ""1""
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}";
|
||||
|
||||
public const string _COMPANY_DETAILS_JSON =
|
||||
@"{
|
||||
""fieldsets"": [
|
||||
{
|
||||
""alias"": ""companyDetails"",
|
||||
""properties"": [
|
||||
{
|
||||
""alias"": ""region"",
|
||||
""value"": ""Test Region""
|
||||
},
|
||||
{
|
||||
""alias"": ""contactDetails"",
|
||||
""value"": {
|
||||
""fieldsets"": [
|
||||
{
|
||||
""alias"": ""contactDetails"",
|
||||
""properties"": [
|
||||
{
|
||||
""alias"": ""name"",
|
||||
""value"": ""Test""
|
||||
},
|
||||
{
|
||||
""alias"": ""address"",
|
||||
""value"": ""Test Address""
|
||||
},
|
||||
{
|
||||
""alias"": ""telephone"",
|
||||
""value"": ""111""
|
||||
},
|
||||
{
|
||||
""alias"": ""mobile"",
|
||||
""value"": ""000""
|
||||
},
|
||||
{
|
||||
""alias"": ""fax"",
|
||||
""value"": ""000""
|
||||
},
|
||||
{
|
||||
""alias"": ""email"",
|
||||
""value"": ""test@test.com""
|
||||
},
|
||||
{
|
||||
""alias"": ""webSite"",
|
||||
""value"": {
|
||||
""fieldsets"": [
|
||||
{
|
||||
""alias"": ""urlPicker"",
|
||||
""properties"": [
|
||||
{
|
||||
""alias"": ""title"",
|
||||
""value"": ""The Test Company""
|
||||
},
|
||||
{
|
||||
""alias"": ""url"",
|
||||
""value"": ""http://test.com""
|
||||
},
|
||||
{
|
||||
""alias"": ""content"",
|
||||
""value"": """"
|
||||
},
|
||||
{
|
||||
""alias"": ""media"",
|
||||
""value"": """"
|
||||
},
|
||||
{
|
||||
""alias"": ""openInNewWindow"",
|
||||
""value"": ""1""
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}";
|
||||
|
||||
public const string _PAGE_DETAILS_JSON =
|
||||
@"{
|
||||
""fieldsets"": [
|
||||
{
|
||||
""alias"": ""pages"",
|
||||
""properties"": [
|
||||
{
|
||||
""alias"": ""pages"",
|
||||
""value"": ""2439,2440,2441,2442,2443,2444,2445,2446,2447,2448,2449,2450,2451,2452,2453""
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
""alias"": ""captions"",
|
||||
""properties"": [
|
||||
{
|
||||
""alias"": ""captions"",
|
||||
""value"": {
|
||||
""fieldsets"": [
|
||||
{
|
||||
""alias"": ""textstringArray"",
|
||||
""properties"": [
|
||||
{
|
||||
""alias"": ""textstring"",
|
||||
""value"": ""First Page""
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
""alias"": ""textstringArray"",
|
||||
""properties"": [
|
||||
{
|
||||
""alias"": ""textstring"",
|
||||
""value"": ""Second Page""
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
""alias"": ""textstringArray"",
|
||||
""properties"": [
|
||||
{
|
||||
""alias"": ""textstring"",
|
||||
""value"": ""Third Page""
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
""alias"": ""textstringArray"",
|
||||
""properties"": [
|
||||
{
|
||||
""alias"": ""textstring"",
|
||||
""value"": ""Fourth Page""
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}";
|
||||
|
||||
public const string _PAGES_JSON =
|
||||
@"{
|
||||
""fieldsets"": [
|
||||
{
|
||||
""alias"": ""Pages"",
|
||||
""properties"": [
|
||||
{
|
||||
""alias"": ""Pages"",
|
||||
""value"": {
|
||||
""fieldsets"": [
|
||||
{
|
||||
""alias"": ""TextPage"",
|
||||
""properties"": [
|
||||
{
|
||||
""alias"": ""Media"",
|
||||
""value"": {
|
||||
""fieldsets"": [
|
||||
{
|
||||
""alias"": ""slideShow"",
|
||||
""properties"": [
|
||||
{
|
||||
""alias"": ""Slides"",
|
||||
""value"": ""1,2,3,4,5,6,7,8""
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
""alias"": ""Seo"",
|
||||
""value"": {
|
||||
""fieldsets"": [
|
||||
{
|
||||
""alias"": ""seo"",
|
||||
""properties"": [
|
||||
{
|
||||
""alias"": ""MetaTitle"",
|
||||
""value"": ""Test Meta Title""
|
||||
},
|
||||
{
|
||||
""alias"": ""MetaDescription"",
|
||||
""value"": ""Test Meta Description""
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
""alias"": ""PageTitle"",
|
||||
""value"": ""Home Page""
|
||||
},
|
||||
{
|
||||
""alias"": ""BodyText"",
|
||||
""value"": ""Home Page Body""
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
""alias"": ""TextPage"",
|
||||
""properties"": [
|
||||
{
|
||||
""alias"": ""Media"",
|
||||
""value"": {
|
||||
""fieldsets"": [
|
||||
{
|
||||
""alias"": ""slideShow"",
|
||||
""properties"": [
|
||||
{
|
||||
""alias"": ""Slides"",
|
||||
""value"": ""1,2,3,4,5,6,7,8""
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
""alias"": ""Seo"",
|
||||
""value"": {
|
||||
""fieldsets"": [
|
||||
{
|
||||
""alias"": ""seo"",
|
||||
""properties"": [
|
||||
{
|
||||
""alias"": ""MetaTitle"",
|
||||
""value"": ""Test Meta Title""
|
||||
},
|
||||
{
|
||||
""alias"": ""MetaDescription"",
|
||||
""value"": ""Test Meta Description""
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
""alias"": ""PageTitle"",
|
||||
""value"": ""About us Page""
|
||||
},
|
||||
{
|
||||
""alias"": ""BodyText"",
|
||||
""value"": ""About us Page Body""
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
""alias"": ""TextPage"",
|
||||
""properties"": [
|
||||
{
|
||||
""alias"": ""Media"",
|
||||
""value"": {
|
||||
""fieldsets"": [
|
||||
{
|
||||
""alias"": ""slideShow"",
|
||||
""properties"": [
|
||||
{
|
||||
""alias"": ""Slides"",
|
||||
""value"": ""1,2,3,4,5,6,7,8""
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
""alias"": ""Seo"",
|
||||
""value"": {
|
||||
""fieldsets"": [
|
||||
{
|
||||
""alias"": ""seo"",
|
||||
""properties"": [
|
||||
{
|
||||
""alias"": ""MetaTitle"",
|
||||
""value"": ""Test Meta Title""
|
||||
},
|
||||
{
|
||||
""alias"": ""MetaDescription"",
|
||||
""value"": ""Test Meta Description""
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
""alias"": ""PageTitle"",
|
||||
""value"": ""Contact us Page""
|
||||
},
|
||||
{
|
||||
""alias"": ""BodyText"",
|
||||
""value"": ""Contact us Page Body""
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}";
|
||||
|
||||
public const string _NULL_VALUES_JSON = @"{""fieldsets"":[{""alias"":""contactDetails"",""properties"":[{""alias"":""name"",""value"":""""},{""alias"":""address"",""value"":""""},{""alias"":""telephone"",""value"":""""},{""alias"":""mobile"",""value"":""""},{""alias"":""fax"",""value"":""""},{""alias"":""email"",""value"":""""},{""alias"":""webSite"",""value"":""""}]}]}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31bf3856ad364e35" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
</configuration>
|
||||
@@ -1,5 +1,28 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="AutoMapper" version="3.0.0" targetFramework="net45" />
|
||||
<package id="ClientDependency" version="1.7.1.2" targetFramework="net45" />
|
||||
<package id="ClientDependency-Mvc" version="1.7.0.4" targetFramework="net45" />
|
||||
<package id="HtmlAgilityPack" version="1.4.6" targetFramework="net45" />
|
||||
<package id="ImageProcessor" version="1.9.0.0" targetFramework="net45" />
|
||||
<package id="ImageProcessor.Web" version="3.2.3.0" targetFramework="net45" />
|
||||
<package id="Lucene.Net" version="2.9.4.1" targetFramework="net45" />
|
||||
<package id="Microsoft.AspNet.Mvc" version="4.0.30506.0" targetFramework="net45" />
|
||||
<package id="Microsoft.AspNet.Mvc.FixedDisplayModes" version="1.0.1" targetFramework="net45" />
|
||||
<package id="Microsoft.AspNet.Razor" version="2.0.30506.0" targetFramework="net45" />
|
||||
<package id="Microsoft.AspNet.WebApi" version="4.0.30506.0" targetFramework="net45" />
|
||||
<package id="Microsoft.AspNet.WebApi.Client" version="4.0.30506.0" targetFramework="net45" />
|
||||
<package id="Microsoft.AspNet.WebApi.Core" version="4.0.30506.0" targetFramework="net45" />
|
||||
<package id="Microsoft.AspNet.WebApi.WebHost" version="4.0.30506.0" targetFramework="net45" />
|
||||
<package id="Microsoft.AspNet.WebPages" version="2.0.30506.0" targetFramework="net45" />
|
||||
<package id="Microsoft.Net.Http" version="2.0.20710.0" targetFramework="net45" />
|
||||
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" />
|
||||
<package id="MiniProfiler" version="2.1.0" targetFramework="net45" />
|
||||
<package id="Moq" version="4.2.1312.1622" targetFramework="net45" />
|
||||
<package id="MySql.Data" version="6.6.5" targetFramework="net45" />
|
||||
<package id="Newtonsoft.Json" version="6.0.2" targetFramework="net45" />
|
||||
<package id="NUnit" version="2.6.3" targetFramework="net45" />
|
||||
<package id="SharpZipLib" version="0.86.0" targetFramework="net45" />
|
||||
<package id="UmbracoCms.Core" version="7.1.2" targetFramework="net45" />
|
||||
<package id="xmlrpcnet" version="2.5.0" targetFramework="net45" />
|
||||
</packages>
|
||||
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Logging;
|
||||
|
||||
namespace DatabaseSizer
|
||||
{
|
||||
public class Application : ApplicationEventHandler
|
||||
{
|
||||
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
|
||||
{
|
||||
base.ApplicationStarted(umbracoApplication, applicationContext);
|
||||
|
||||
ExpandPrevalueValueColumnSize();
|
||||
}
|
||||
|
||||
protected void ExpandPrevalueValueColumnSize()
|
||||
{
|
||||
try
|
||||
{
|
||||
var dbContext = ApplicationContext.Current.DatabaseContext;
|
||||
var colCount =
|
||||
dbContext.Database.ExecuteScalar<int>(
|
||||
"SELECT COUNT(1) FROM INFORMATION_SCHEMA.COLUMNS WHERE DATA_TYPE = 'nvarchar' AND COLUMN_NAME = 'value' AND CHARACTER_MAXIMUM_LENGTH = 2500 AND TABLE_NAME = 'cmsDataTypePreValues'");
|
||||
|
||||
// Check column
|
||||
if (colCount != 0)
|
||||
{
|
||||
using (var trans = dbContext.Database.GetTransaction())
|
||||
{
|
||||
// Change column
|
||||
dbContext.Database.Execute("ALTER TABLE [cmsDataTypePreValues] ALTER COLUMN [value] ntext NULL;");
|
||||
|
||||
trans.Complete();
|
||||
}
|
||||
|
||||
LogHelper.Debug(typeof(Application), "Successfully expanded Prevalue table Value column");
|
||||
}
|
||||
else
|
||||
{
|
||||
LogHelper.Debug(typeof(Application), "Prevalue table Value column is already expanded");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.Error(typeof(Application), "Error expanding Prevalue table Value column", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,213 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{0114C963-C514-49C1-B7AB-DCB1825F498C}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>DatabaseSizer</RootNamespace>
|
||||
<AssemblyName>DatabaseSizer</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="AutoMapper">
|
||||
<HintPath>..\packages\AutoMapper.3.0.0\lib\net40\AutoMapper.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="AutoMapper.Net4">
|
||||
<HintPath>..\packages\AutoMapper.3.0.0\lib\net40\AutoMapper.Net4.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="businesslogic">
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\businesslogic.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ClientDependency.Core">
|
||||
<HintPath>..\packages\ClientDependency.1.7.1.2\lib\ClientDependency.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ClientDependency.Core.Mvc">
|
||||
<HintPath>..\packages\ClientDependency-Mvc.1.7.0.4\lib\ClientDependency.Core.Mvc.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="cms">
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\cms.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="controls">
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\controls.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="CookComputing.XmlRpcV2">
|
||||
<HintPath>..\packages\xmlrpcnet.2.5.0\lib\net20\CookComputing.XmlRpcV2.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Examine">
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\Examine.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="HtmlAgilityPack">
|
||||
<HintPath>..\packages\HtmlAgilityPack.1.4.6\lib\Net45\HtmlAgilityPack.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ICSharpCode.SharpZipLib">
|
||||
<HintPath>..\packages\SharpZipLib.0.86.0\lib\20\ICSharpCode.SharpZipLib.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ImageProcessor">
|
||||
<HintPath>..\packages\ImageProcessor.1.9.0.0\lib\ImageProcessor.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ImageProcessor.Web">
|
||||
<HintPath>..\packages\ImageProcessor.Web.3.2.3.0\lib\net45\ImageProcessor.Web.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="interfaces">
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\interfaces.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="log4net">
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\log4net.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Lucene.Net">
|
||||
<HintPath>..\packages\Lucene.Net.2.9.4.1\lib\net40\Lucene.Net.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.ApplicationBlocks.Data">
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\Microsoft.ApplicationBlocks.Data.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Web.Helpers">
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\Microsoft.Web.Helpers.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<Private>True</Private>
|
||||
<HintPath>..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Web.Mvc.FixedDisplayModes">
|
||||
<HintPath>..\packages\Microsoft.AspNet.Mvc.FixedDisplayModes.1.0.0\lib\net40\Microsoft.Web.Mvc.FixedDisplayModes.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MiniProfiler">
|
||||
<HintPath>..\packages\MiniProfiler.2.1.0\lib\net40\MiniProfiler.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="MySql.Data">
|
||||
<HintPath>..\packages\MySql.Data.6.6.5\lib\net40\MySql.Data.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json">
|
||||
<HintPath>..\packages\Newtonsoft.Json.6.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="SQLCE4Umbraco">
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\SQLCE4Umbraco.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL">
|
||||
<Private>True</Private>
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\System.Data.SqlServerCe.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Data.SqlServerCe.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL">
|
||||
<Private>True</Private>
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\System.Data.SqlServerCe.Entity.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Net.Http.Formatting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.AspNet.WebApi.Client.4.0.30506.0\lib\net40\System.Net.Http.Formatting.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web" />
|
||||
<Reference Include="System.Web.Helpers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<Private>True</Private>
|
||||
<HintPath>..\packages\Microsoft.AspNet.WebPages.2.0.20710.0\lib\net40\System.Web.Helpers.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.AspNet.WebApi.Core.4.0.20710.0\lib\net40\System.Web.Http.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.Http.WebHost, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.AspNet.WebApi.WebHost.4.0.20710.0\lib\net40\System.Web.Http.WebHost.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<Private>True</Private>
|
||||
<HintPath>..\packages\Microsoft.AspNet.Mvc.4.0.20710.0\lib\net40\System.Web.Mvc.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<Private>True</Private>
|
||||
<HintPath>..\packages\Microsoft.AspNet.Razor.2.0.20710.0\lib\net40\System.Web.Razor.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.WebPages, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<Private>True</Private>
|
||||
<HintPath>..\packages\Microsoft.AspNet.WebPages.2.0.20710.0\lib\net40\System.Web.WebPages.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.WebPages.Deployment, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<Private>True</Private>
|
||||
<HintPath>..\packages\Microsoft.AspNet.WebPages.2.0.20710.0\lib\net40\System.Web.WebPages.Deployment.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<Private>True</Private>
|
||||
<HintPath>..\packages\Microsoft.AspNet.WebPages.2.0.20710.0\lib\net40\System.Web.WebPages.Razor.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="TidyNet">
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\TidyNet.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="umbraco">
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\umbraco.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Umbraco.Core">
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\Umbraco.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="umbraco.DataLayer">
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\umbraco.DataLayer.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="umbraco.editorControls">
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\umbraco.editorControls.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="umbraco.MacroEngines">
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\umbraco.MacroEngines.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="umbraco.providers">
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\umbraco.providers.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Umbraco.Web.UI">
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\Umbraco.Web.UI.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="umbraco.XmlSerializers">
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\umbraco.XmlSerializers.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="UmbracoExamine">
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\UmbracoExamine.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="UrlRewritingNet.UrlRewriter">
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\UrlRewritingNet.UrlRewriter.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Application.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="app.config" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
|
||||
</Target>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("DatabaseSizer.cs")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("DatabaseSizer.cs")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2014")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("28dc35d2-3dfb-40b4-9093-bc47c91127ea")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31bf3856ad364e35" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
</configuration>
|
||||
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="AutoMapper" version="3.0.0" targetFramework="net45" />
|
||||
<package id="ClientDependency" version="1.7.1.2" targetFramework="net45" />
|
||||
<package id="ClientDependency-Mvc" version="1.7.0.4" targetFramework="net45" />
|
||||
<package id="HtmlAgilityPack" version="1.4.6" targetFramework="net45" />
|
||||
<package id="ImageProcessor" version="1.9.0.0" targetFramework="net45" />
|
||||
<package id="ImageProcessor.Web" version="3.2.3.0" targetFramework="net45" />
|
||||
<package id="Lucene.Net" version="2.9.4.1" targetFramework="net45" />
|
||||
<package id="Microsoft.AspNet.Mvc" version="4.0.20710.0" targetFramework="net45" />
|
||||
<package id="Microsoft.AspNet.Mvc.FixedDisplayModes" version="1.0.0" targetFramework="net45" />
|
||||
<package id="Microsoft.AspNet.Razor" version="2.0.20710.0" targetFramework="net45" />
|
||||
<package id="Microsoft.AspNet.WebApi" version="4.0.30506.0" targetFramework="net45" />
|
||||
<package id="Microsoft.AspNet.WebApi.Client" version="4.0.30506.0" targetFramework="net45" />
|
||||
<package id="Microsoft.AspNet.WebApi.Core" version="4.0.20710.0" targetFramework="net45" />
|
||||
<package id="Microsoft.AspNet.WebApi.WebHost" version="4.0.20710.0" targetFramework="net45" />
|
||||
<package id="Microsoft.AspNet.WebPages" version="2.0.20710.0" targetFramework="net45" />
|
||||
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" />
|
||||
<package id="MiniProfiler" version="2.1.0" targetFramework="net45" />
|
||||
<package id="MySql.Data" version="6.6.5" targetFramework="net45" />
|
||||
<package id="Newtonsoft.Json" version="6.0.2" targetFramework="net45" />
|
||||
<package id="SharpZipLib" version="0.86.0" targetFramework="net45" />
|
||||
<package id="UmbracoCms.Core" version="7.1.2" targetFramework="net45" />
|
||||
<package id="xmlrpcnet" version="2.5.0" targetFramework="net45" />
|
||||
</packages>
|
||||
@@ -12,6 +12,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{D84AA4
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Archetype.Tests", "Archetype.Tests\Archetype.Tests.csproj", "{21F3E6CF-B76F-4059-9474-1AF1CE63CD6B}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DatabaseSizer", "DatabaseSizer\DatabaseSizer.csproj", "{0114C963-C514-49C1-B7AB-DCB1825F498C}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -26,6 +28,10 @@ Global
|
||||
{21F3E6CF-B76F-4059-9474-1AF1CE63CD6B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{21F3E6CF-B76F-4059-9474-1AF1CE63CD6B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{21F3E6CF-B76F-4059-9474-1AF1CE63CD6B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{0114C963-C514-49C1-B7AB-DCB1825F498C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{0114C963-C514-49C1-B7AB-DCB1825F498C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{0114C963-C514-49C1-B7AB-DCB1825F498C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{0114C963-C514-49C1-B7AB-DCB1825F498C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Web.Http;
|
||||
using AutoMapper;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Web.Models.ContentEditing;
|
||||
using Umbraco.Web.Mvc;
|
||||
using Umbraco.Web.Editors;
|
||||
|
||||
namespace Archetype.Api
|
||||
{
|
||||
[PluginController("ArchetypeApi")]
|
||||
public class ArchetypeDataTypeController : UmbracoAuthorizedJsonController
|
||||
{
|
||||
|
||||
public IEnumerable<object> GetAllPropertyEditors()
|
||||
{
|
||||
return
|
||||
global::Umbraco.Core.PropertyEditors.PropertyEditorResolver.Current.PropertyEditors
|
||||
.Select(x => new {defaultPreValues = x.DefaultPreValues, alias = x.Alias, view = x.ValueEditor.View});
|
||||
}
|
||||
|
||||
public object GetAll()
|
||||
{
|
||||
var dataTypes = Services.DataTypeService.GetAllDataTypeDefinitions();
|
||||
return dataTypes.Select(t => new { guid = t.Key, name = t.Name });
|
||||
}
|
||||
|
||||
public object GetByGuid(Guid guid)
|
||||
{
|
||||
var dataType = Services.DataTypeService.GetDataTypeDefinitionById(guid);
|
||||
if (dataType == null)
|
||||
{
|
||||
throw new HttpResponseException(HttpStatusCode.NotFound);
|
||||
}
|
||||
var dataTypeDisplay = Mapper.Map<IDataTypeDefinition, DataTypeDisplay>(dataType);
|
||||
return new { selectedEditor = dataTypeDisplay.SelectedEditor, preValues = dataTypeDisplay.PreValues };
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
@@ -7,7 +7,7 @@
|
||||
<ProjectGuid>{7D185D41-4228-4978-ACB8-83F9A48AD94F}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Archetype.Umbraco</RootNamespace>
|
||||
<RootNamespace>Archetype</RootNamespace>
|
||||
<AssemblyName>Archetype</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
@@ -34,114 +34,136 @@
|
||||
<ItemGroup>
|
||||
<Reference Include="AutoMapper">
|
||||
<HintPath>..\packages\AutoMapper.3.0.0\lib\net40\AutoMapper.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="AutoMapper.Net4">
|
||||
<HintPath>..\packages\AutoMapper.3.0.0\lib\net40\AutoMapper.Net4.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="businesslogic">
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.0.1\lib\businesslogic.dll</HintPath>
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\businesslogic.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ClientDependency.Core">
|
||||
<HintPath>..\packages\ClientDependency.1.7.0.4\lib\ClientDependency.Core.dll</HintPath>
|
||||
<HintPath>..\packages\ClientDependency.1.7.1.2\lib\ClientDependency.Core.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="ClientDependency.Core.Mvc">
|
||||
<HintPath>..\packages\ClientDependency-Mvc.1.7.0.4\lib\ClientDependency.Core.Mvc.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="cms">
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.0.1\lib\cms.dll</HintPath>
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\cms.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="controls">
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.0.1\lib\controls.dll</HintPath>
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\controls.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="CookComputing.XmlRpcV2">
|
||||
<HintPath>..\packages\xmlrpcnet.2.5.0\lib\net20\CookComputing.XmlRpcV2.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="Examine">
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.0.1\lib\Examine.dll</HintPath>
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\Examine.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="HtmlAgilityPack">
|
||||
<HintPath>..\packages\HtmlAgilityPack.1.4.6\lib\Net45\HtmlAgilityPack.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="ICSharpCode.SharpZipLib">
|
||||
<HintPath>..\packages\SharpZipLib.0.86.0\lib\20\ICSharpCode.SharpZipLib.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="ImageProcessor">
|
||||
<HintPath>..\packages\ImageProcessor.1.9.0.0\lib\ImageProcessor.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ImageProcessor.Web">
|
||||
<HintPath>..\packages\ImageProcessor.Web.3.2.3.0\lib\net45\ImageProcessor.Web.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="interfaces">
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.0.1\lib\interfaces.dll</HintPath>
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\interfaces.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="log4net">
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.0.1\lib\log4net.dll</HintPath>
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\log4net.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Lucene.Net">
|
||||
<HintPath>..\packages\Lucene.Net.2.9.4.1\lib\net40\Lucene.Net.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.ApplicationBlocks.Data">
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.0.1\lib\Microsoft.ApplicationBlocks.Data.dll</HintPath>
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\Microsoft.ApplicationBlocks.Data.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Web.Helpers">
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.0.1\lib\Microsoft.Web.Helpers.dll</HintPath>
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\Microsoft.Web.Helpers.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<Private>True</Private>
|
||||
<Private>False</Private>
|
||||
<HintPath>..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Web.Mvc.FixedDisplayModes">
|
||||
<HintPath>..\packages\Microsoft.AspNet.Mvc.FixedDisplayModes.1.0.1\lib\net40\Microsoft.Web.Mvc.FixedDisplayModes.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="MiniProfiler">
|
||||
<HintPath>..\packages\MiniProfiler.2.1.0\lib\net40\MiniProfiler.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="MySql.Data">
|
||||
<HintPath>..\packages\MySql.Data.6.6.5\lib\net40\MySql.Data.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json">
|
||||
<HintPath>..\packages\Newtonsoft.Json.4.5.11\lib\net40\Newtonsoft.Json.dll</HintPath>
|
||||
<HintPath>..\packages\Newtonsoft.Json.6.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="SQLCE4Umbraco">
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.0.1\lib\SQLCE4Umbraco.dll</HintPath>
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\SQLCE4Umbraco.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL">
|
||||
<Private>True</Private>
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.0.1\lib\System.Data.SqlServerCe.dll</HintPath>
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\System.Data.SqlServerCe.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Data.SqlServerCe.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91, processorArchitecture=MSIL">
|
||||
<Private>True</Private>
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.0.1\lib\System.Data.SqlServerCe.Entity.dll</HintPath>
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\System.Data.SqlServerCe.Entity.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Net.Http.Formatting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.AspNet.WebApi.Client.4.0.30506.0\lib\net40\System.Net.Http.Formatting.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Net.Http.WebRequest" />
|
||||
<Reference Include="System.Web" />
|
||||
<Reference Include="System.Web.Helpers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<Private>True</Private>
|
||||
<Private>False</Private>
|
||||
<HintPath>..\packages\Microsoft.AspNet.WebPages.2.0.30506.0\lib\net40\System.Web.Helpers.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.AspNet.WebApi.Core.4.0.30506.0\lib\net40\System.Web.Http.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.Http.WebHost, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.AspNet.WebApi.WebHost.4.0.30506.0\lib\net40\System.Web.Http.WebHost.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<Private>True</Private>
|
||||
<Private>False</Private>
|
||||
<HintPath>..\packages\Microsoft.AspNet.Mvc.4.0.30506.0\lib\net40\System.Web.Mvc.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<Private>True</Private>
|
||||
<Private>False</Private>
|
||||
<HintPath>..\packages\Microsoft.AspNet.Razor.2.0.30506.0\lib\net40\System.Web.Razor.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.WebPages, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<Private>True</Private>
|
||||
<Private>False</Private>
|
||||
<HintPath>..\packages\Microsoft.AspNet.WebPages.2.0.30506.0\lib\net40\System.Web.WebPages.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.WebPages.Deployment, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<Private>True</Private>
|
||||
<Private>False</Private>
|
||||
<HintPath>..\packages\Microsoft.AspNet.WebPages.2.0.30506.0\lib\net40\System.Web.WebPages.Deployment.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<Private>True</Private>
|
||||
<Private>False</Private>
|
||||
<HintPath>..\packages\Microsoft.AspNet.WebPages.2.0.30506.0\lib\net40\System.Web.WebPages.Razor.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
@@ -150,51 +172,62 @@
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="TidyNet">
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.0.1\lib\TidyNet.dll</HintPath>
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\TidyNet.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="umbraco">
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.0.1\lib\umbraco.dll</HintPath>
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\umbraco.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Umbraco.Core">
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.0.1\lib\Umbraco.Core.dll</HintPath>
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\Umbraco.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="umbraco.DataLayer">
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.0.1\lib\umbraco.DataLayer.dll</HintPath>
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\umbraco.DataLayer.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="umbraco.editorControls">
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.0.1\lib\umbraco.editorControls.dll</HintPath>
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\umbraco.editorControls.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="umbraco.MacroEngines">
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.0.1\lib\umbraco.MacroEngines.dll</HintPath>
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\umbraco.MacroEngines.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="umbraco.providers">
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.0.1\lib\umbraco.providers.dll</HintPath>
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\umbraco.providers.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Umbraco.Web.UI">
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.0.1\lib\Umbraco.Web.UI.dll</HintPath>
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\Umbraco.Web.UI.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="umbraco.XmlSerializers">
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.0.1\lib\umbraco.XmlSerializers.dll</HintPath>
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\umbraco.XmlSerializers.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="UmbracoExamine">
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.0.1\lib\UmbracoExamine.dll</HintPath>
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\UmbracoExamine.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="UrlRewritingNet.UrlRewriter">
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.0.1\lib\UrlRewritingNet.UrlRewriter.dll</HintPath>
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.1.2\lib\UrlRewritingNet.UrlRewriter.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Api\ArchetypeDataTypeController.cs" />
|
||||
<Compile Include="Constants.cs" />
|
||||
<Compile Include="Events\ExpireCache.cs" />
|
||||
<Compile Include="Extensions\ArchetypeHelper.cs" />
|
||||
<Compile Include="Extensions\Extensions.cs" />
|
||||
<Compile Include="Models\Archetype.cs" />
|
||||
<Compile Include="Models\ArchetypeModel.cs" />
|
||||
<Compile Include="Models\ArchetypePreValue.cs" />
|
||||
<Compile Include="Models\ArchetypePreValueFieldset.cs" />
|
||||
<Compile Include="Models\ArchetypePreValueProperty.cs" />
|
||||
<Compile Include="Models\Fieldset.cs" />
|
||||
<Compile Include="Models\Property.cs" />
|
||||
<Compile Include="Models\ArchetypeFieldsetModel.cs" />
|
||||
<Compile Include="Models\ArchetypePropertyModel.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Properties\VersionInfo.cs" />
|
||||
<Compile Include="PropertyConverters\ArchetypeValueConverter.cs" />
|
||||
<Compile Include="Serialization\AsArchetypeAttribute.cs" />
|
||||
<Compile Include="Serialization\ArchetypeJsonConverter.cs" />
|
||||
<Compile Include="Serialization\AsFieldsetAttribute.cs" />
|
||||
<Compile Include="Serialization\SerializationExtensions.cs" />
|
||||
<Compile Include="PropertyEditors\ArchetypePropertyEditor.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="app.config" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
namespace Archetype
|
||||
{
|
||||
public static class Constants
|
||||
{
|
||||
public const string PropertyEditorAlias = "Imulus.Archetype";
|
||||
|
||||
public const string PreValueAlias = "archetypeConfig";
|
||||
|
||||
public const string CacheKey_DataTypeByGuid = "";
|
||||
|
||||
public const string CacheKey_PreValueFromDataTypeId = "Archetype_GetArchetypePreValueFromDataTypeId_";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Web;
|
||||
|
||||
namespace Archetype.Events
|
||||
{
|
||||
public class ExpireCache : ApplicationEventHandler
|
||||
{
|
||||
|
||||
protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
|
||||
{
|
||||
base.ApplicationStarting(umbracoApplication, applicationContext);
|
||||
|
||||
DataTypeService.Saved += ExpirePreValueCache;
|
||||
}
|
||||
|
||||
void ExpirePreValueCache(IDataTypeService sender, global::Umbraco.Core.Events.SaveEventArgs<IDataTypeDefinition> e)
|
||||
{
|
||||
foreach (var dataType in e.SavedEntities)
|
||||
{
|
||||
ApplicationContext.Current.ApplicationCache.RuntimeCache.ClearCacheItem(Constants.CacheKey_PreValueFromDataTypeId + dataType.Id);
|
||||
ApplicationContext.Current.ApplicationCache.RuntimeCache.ClearCacheItem(Constants.CacheKey_DataTypeByGuid + dataType.Key);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Archetype.Models;
|
||||
using Newtonsoft.Json;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
|
||||
namespace Archetype.Extensions
|
||||
{
|
||||
public class ArchetypeHelper
|
||||
{
|
||||
|
||||
protected JsonSerializerSettings _jsonSettings;
|
||||
protected ApplicationContext _app;
|
||||
|
||||
internal ArchetypeHelper()
|
||||
{
|
||||
var dcr = new Newtonsoft.Json.Serialization.DefaultContractResolver();
|
||||
dcr.DefaultMembersSearchFlags |= System.Reflection.BindingFlags.NonPublic;
|
||||
|
||||
_jsonSettings = new JsonSerializerSettings { ContractResolver = dcr };
|
||||
_app = ApplicationContext.Current;
|
||||
}
|
||||
|
||||
internal Models.ArchetypeModel DeserializeJsonToArchetype(string sourceJson, PreValueCollection dataTypePreValues)
|
||||
{
|
||||
try
|
||||
{
|
||||
var archetype = JsonConvert.DeserializeObject<Models.ArchetypeModel>(sourceJson, _jsonSettings);
|
||||
|
||||
try
|
||||
{
|
||||
// Get list of configured properties and their types and map them to the deserialized archetype model
|
||||
var preValue = GetArchetypePreValueFromPreValuesCollection(dataTypePreValues);
|
||||
RetrieveAdditionalProperties(ref archetype, preValue);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
}
|
||||
|
||||
return archetype;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return new Models.ArchetypeModel();
|
||||
}
|
||||
}
|
||||
|
||||
internal Models.ArchetypeModel DeserializeJsonToArchetype(string sourceJson, int dataTypeId, PublishedContentType hostContentType = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var archetype = JsonConvert.DeserializeObject<Models.ArchetypeModel>(sourceJson, _jsonSettings);
|
||||
|
||||
try
|
||||
{
|
||||
// Get list of configured properties and their types and map them to the deserialized archetype model
|
||||
var preValue = GetArchetypePreValueFromDataTypeId(dataTypeId);
|
||||
RetrieveAdditionalProperties(ref archetype, preValue, hostContentType);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
}
|
||||
|
||||
return archetype;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return new Models.ArchetypeModel();
|
||||
}
|
||||
}
|
||||
|
||||
private ArchetypePreValue GetArchetypePreValueFromDataTypeId(int dataTypeId)
|
||||
{
|
||||
return _app.ApplicationCache.RuntimeCache.GetCacheItem(
|
||||
Constants.CacheKey_PreValueFromDataTypeId + dataTypeId,
|
||||
() =>
|
||||
{
|
||||
var preValues = _app.Services.DataTypeService.GetPreValuesCollectionByDataTypeId(dataTypeId);
|
||||
|
||||
var configJson = preValues.IsDictionaryBased
|
||||
? preValues.PreValuesAsDictionary[Constants.PreValueAlias].Value
|
||||
: preValues.PreValuesAsArray.First().Value;
|
||||
|
||||
var config = JsonConvert.DeserializeObject<ArchetypePreValue>(configJson, _jsonSettings);
|
||||
RetrieveAdditionalProperties(ref config);
|
||||
|
||||
return config;
|
||||
|
||||
}) as ArchetypePreValue;
|
||||
}
|
||||
|
||||
private ArchetypePreValue GetArchetypePreValueFromPreValuesCollection(PreValueCollection dataTypePreValues)
|
||||
{
|
||||
var preValueAsString = dataTypePreValues.PreValuesAsDictionary.First().Value.Value;
|
||||
var preValue = JsonConvert.DeserializeObject<ArchetypePreValue>(preValueAsString, _jsonSettings);
|
||||
return preValue;
|
||||
}
|
||||
|
||||
|
||||
private IDataTypeDefinition GetDataTypeByGuid(Guid guid)
|
||||
{
|
||||
return (IDataTypeDefinition) ApplicationContext.Current.ApplicationCache.RuntimeCache.GetCacheItem(
|
||||
Constants.CacheKey_DataTypeByGuid + guid,
|
||||
() => _app.Services.DataTypeService.GetDataTypeDefinitionById(guid));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves additional metadata that isn't available on the stored model of an Archetype
|
||||
/// </summary>
|
||||
/// <param name="archetype">The Archetype to add the additional metadata to</param>
|
||||
/// <param name="preValue">The configuration of the Archetype</param>
|
||||
private void RetrieveAdditionalProperties(ref Models.ArchetypeModel archetype, ArchetypePreValue preValue, PublishedContentType hostContentType = null)
|
||||
{
|
||||
foreach (var fieldset in preValue.Fieldsets)
|
||||
{
|
||||
var fieldsetAlias = fieldset.Alias;
|
||||
foreach (var fieldsetInst in archetype.Fieldsets.Where(x => x.Alias == fieldsetAlias))
|
||||
{
|
||||
foreach (var property in fieldset.Properties)
|
||||
{
|
||||
var propertyAlias = property.Alias;
|
||||
foreach ( var propertyInst in fieldsetInst.Properties.Where(x => x.Alias == propertyAlias))
|
||||
{
|
||||
propertyInst.DataTypeGuid = property.DataTypeGuid.ToString();
|
||||
propertyInst.DataTypeId = GetDataTypeByGuid(property.DataTypeGuid).Id;
|
||||
propertyInst.PropertyEditorAlias = property.PropertyEditorAlias;
|
||||
propertyInst.HostContentType = hostContentType;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves additional metadata that isn't available on the stored model of an ArchetypePreValue
|
||||
/// </summary>
|
||||
/// <param name="archetype">The Archetype to add the additional metadata to</param>
|
||||
/// <param name="preValue">The configuration of the Archetype</param>
|
||||
private void RetrieveAdditionalProperties(ref Models.ArchetypePreValue preValue)
|
||||
{
|
||||
foreach (var fieldset in preValue.Fieldsets)
|
||||
{
|
||||
foreach (var property in fieldset.Properties)
|
||||
{
|
||||
property.PropertyEditorAlias = GetDataTypeByGuid(property.DataTypeGuid).PropertyEditorAlias;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,16 @@
|
||||
using Umbraco.Core;
|
||||
using Archetype.Umbraco.Models;
|
||||
using System;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Mvc.Html;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Collections.Generic;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Web;
|
||||
using Archetype.Models;
|
||||
|
||||
namespace Archetype.Umbraco.Extensions
|
||||
namespace Archetype.Extensions
|
||||
{
|
||||
public static class Extensions
|
||||
{
|
||||
@@ -13,9 +22,63 @@ namespace Archetype.Umbraco.Extensions
|
||||
|| input.StartsWith("[") && input.EndsWith("]");
|
||||
}
|
||||
|
||||
public static bool IsArchetype(this Property prop)
|
||||
public static bool IsArchetype(this ArchetypePropertyModel prop)
|
||||
{
|
||||
return prop.PropertyEditorAlias.InvariantEquals("Imulus.Archetype");
|
||||
return prop.PropertyEditorAlias.InvariantEquals(Constants.PropertyEditorAlias);
|
||||
}
|
||||
|
||||
public static IHtmlString RenderArchetypePartials(this HtmlHelper htmlHelper, ArchetypeModel archetypeModel)
|
||||
{
|
||||
return RenderPartials(htmlHelper, archetypeModel, null, null);
|
||||
}
|
||||
|
||||
public static IHtmlString RenderArchetypePartials(this HtmlHelper htmlHelper, ArchetypeModel archetypeModel, string partialPath)
|
||||
{
|
||||
return RenderPartials(htmlHelper, archetypeModel, partialPath, null);
|
||||
}
|
||||
|
||||
public static IHtmlString RenderArchetypePartials(this HtmlHelper htmlHelper, ArchetypeModel archetypeModel, ViewDataDictionary viewDataDictionary)
|
||||
{
|
||||
return RenderPartials(htmlHelper, archetypeModel, null, viewDataDictionary);
|
||||
}
|
||||
|
||||
public static IHtmlString RenderArchetypePartials(this HtmlHelper htmlHelper, ArchetypeModel archetypeModel, string partialPath, ViewDataDictionary viewDataDictionary)
|
||||
{
|
||||
return RenderPartials(htmlHelper, archetypeModel, partialPath, viewDataDictionary);
|
||||
}
|
||||
|
||||
private static IHtmlString RenderPartials(HtmlHelper htmlHelper, ArchetypeModel archetypeModel, string partialPath, ViewDataDictionary viewDataDictionary)
|
||||
{
|
||||
var context = HttpContext.Current;
|
||||
|
||||
if (archetypeModel == null || context == null)
|
||||
{
|
||||
return new HtmlString("");
|
||||
}
|
||||
|
||||
var sb = new StringBuilder();
|
||||
|
||||
var pathToPartials = "~/Views/Partials/Archetype/";
|
||||
if (!string.IsNullOrEmpty(partialPath))
|
||||
{
|
||||
pathToPartials = partialPath;
|
||||
}
|
||||
|
||||
foreach (var fieldsetModel in archetypeModel)
|
||||
{
|
||||
var partial = pathToPartials + fieldsetModel.Alias + ".cshtml";
|
||||
|
||||
if (System.IO.File.Exists(context.Server.MapPath(partial)))
|
||||
{
|
||||
sb.AppendLine(htmlHelper.Partial(partial, fieldsetModel, viewDataDictionary).ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
LogHelper.Info<ArchetypeModel>(string.Format("The partial for {0} could not be found. Please create a partial with that name or rename your alias.", context.Server.MapPath(partial)));
|
||||
}
|
||||
}
|
||||
|
||||
return new HtmlString(sb.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Archetype.Umbraco.Models
|
||||
{
|
||||
public class Archetype
|
||||
{
|
||||
public IEnumerable<Fieldset> Fieldsets { get; set; }
|
||||
|
||||
public Archetype()
|
||||
{
|
||||
Fieldsets = new List<Fieldset>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using Umbraco.Core;
|
||||
|
||||
namespace Archetype.Models
|
||||
{
|
||||
public class ArchetypeFieldsetModel
|
||||
{
|
||||
[JsonProperty("alias")]
|
||||
public string Alias { get; set; }
|
||||
|
||||
[JsonProperty("properties")]
|
||||
public IEnumerable<ArchetypePropertyModel> Properties;
|
||||
|
||||
public ArchetypeFieldsetModel()
|
||||
{
|
||||
Properties = new List<ArchetypePropertyModel>();
|
||||
}
|
||||
|
||||
#region Helper Methods
|
||||
|
||||
public string GetValue(string propertyAlias)
|
||||
{
|
||||
return GetValue<string>(propertyAlias);
|
||||
}
|
||||
|
||||
public T GetValue<T>(string propertyAlias)
|
||||
{
|
||||
var property = GetProperty(propertyAlias);
|
||||
|
||||
if (property == null || property.Value == null || string.IsNullOrEmpty(property.Value.ToString()))
|
||||
return default(T);
|
||||
|
||||
return property.GetValue<T>();
|
||||
}
|
||||
|
||||
public bool HasProperty(string propertyAlias)
|
||||
{
|
||||
return GetProperty(propertyAlias) != null;
|
||||
}
|
||||
|
||||
public bool HasValue(string propertyAlias)
|
||||
{
|
||||
var property = GetProperty(propertyAlias);
|
||||
if (property == null || property.Value == null)
|
||||
return false;
|
||||
|
||||
return !string.IsNullOrEmpty(property.Value.ToString());
|
||||
}
|
||||
|
||||
private ArchetypePropertyModel GetProperty(string propertyAlias)
|
||||
{
|
||||
return Properties.FirstOrDefault(p => p.Alias.InvariantEquals(propertyAlias));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Archetype.Models
|
||||
{
|
||||
[JsonObject]
|
||||
public class ArchetypeModel : IEnumerable<ArchetypeFieldsetModel>
|
||||
{
|
||||
[JsonProperty("fieldsets")]
|
||||
internal IEnumerable<ArchetypeFieldsetModel> Fieldsets { get; set; }
|
||||
|
||||
public ArchetypeModel()
|
||||
{
|
||||
Fieldsets = new List<ArchetypeFieldsetModel>();
|
||||
}
|
||||
|
||||
public IEnumerator<ArchetypeFieldsetModel> GetEnumerator()
|
||||
{
|
||||
return this.Fieldsets.GetEnumerator();
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return this.GetEnumerator();
|
||||
}
|
||||
|
||||
internal string SerializeForPersistence()
|
||||
{
|
||||
var json = JObject.Parse(JsonConvert.SerializeObject(this));
|
||||
var propertiesToRemove = new String[] { "propertyEditorAlias", "dataTypeId", "dataTypeGuid", "hostContentType" };
|
||||
|
||||
json.Descendants().OfType<JProperty>()
|
||||
.Where(p => propertiesToRemove.Contains(p.Name))
|
||||
.ToList()
|
||||
.ForEach(x => x.Remove());
|
||||
|
||||
return json.ToString(Formatting.None);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,50 @@
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Archetype.Umbraco.Models
|
||||
namespace Archetype.Models
|
||||
{
|
||||
internal class ArchetypePreValue
|
||||
{
|
||||
internal IEnumerable<ArchetypePreValueFieldset> Fieldsets { get; set; }
|
||||
}
|
||||
public class ArchetypePreValue
|
||||
{
|
||||
[JsonProperty("showAdvancedOptions")]
|
||||
public bool ShowAdvancedOptions { get; set; }
|
||||
|
||||
[JsonProperty("startWithAddButton")]
|
||||
public bool StartWithAddButton { get; set; }
|
||||
|
||||
[JsonProperty("hideFieldsetToolbar")]
|
||||
public bool HideFieldsetToolbar { get; set; }
|
||||
|
||||
[JsonProperty("enableMultipleFieldsets")]
|
||||
public bool EnableMultipleFieldsets { get; set; }
|
||||
|
||||
[JsonProperty("enableCollapsing")]
|
||||
public bool EnableCollapsing { get; set; }
|
||||
|
||||
[JsonProperty("hideFieldsetControls")]
|
||||
public bool HideFieldsetControls { get; set; }
|
||||
|
||||
[JsonProperty("hidePropertyLabel")]
|
||||
public bool HidePropertyLabel { get; set; }
|
||||
|
||||
[JsonProperty("maxFieldsets", NullValueHandling = NullValueHandling.Ignore)]
|
||||
public int MaxFieldsets { get; set; }
|
||||
|
||||
[JsonProperty("fieldsets")]
|
||||
public IEnumerable<ArchetypePreValueFieldset> Fieldsets { get; set; }
|
||||
|
||||
[JsonProperty("hidePropertyLabels")]
|
||||
public bool HidePropertyLabels { get; set; }
|
||||
|
||||
[JsonProperty("customCssClass")]
|
||||
public string CustomCssClass { get; set; }
|
||||
|
||||
[JsonProperty("customCssPath")]
|
||||
public string CustomCssPath { get; set; }
|
||||
|
||||
[JsonProperty("customJsPath")]
|
||||
public string CustomJsPath { get; set; }
|
||||
|
||||
[JsonProperty("developerMode")]
|
||||
public bool DeveloperMode { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,29 @@
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Archetype.Umbraco.Models
|
||||
namespace Archetype.Models
|
||||
{
|
||||
internal class ArchetypePreValueFieldset
|
||||
{
|
||||
internal string Alias { get; set; }
|
||||
internal IEnumerable<ArchetypePreValueProperty> Properties { get; set; }
|
||||
}
|
||||
}
|
||||
public class ArchetypePreValueFieldset
|
||||
{
|
||||
[JsonProperty("alias")]
|
||||
public string Alias { get; set; }
|
||||
|
||||
[JsonProperty("remove")]
|
||||
public bool Remove { get; set; }
|
||||
|
||||
[JsonProperty("collapse")]
|
||||
public bool Collapse { get; set; }
|
||||
|
||||
[JsonProperty("labelTemplate")]
|
||||
public string LabelTemplate { get; set; }
|
||||
|
||||
[JsonProperty("icon")]
|
||||
public string Icon { get; set; }
|
||||
|
||||
[JsonProperty("label")]
|
||||
public string Label { get; set; }
|
||||
|
||||
[JsonProperty("properties")]
|
||||
public IEnumerable<ArchetypePreValueProperty> Properties { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,38 @@
|
||||
namespace Archetype.Umbraco.Models
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Archetype.Models
|
||||
{
|
||||
internal class ArchetypePreValueProperty
|
||||
{
|
||||
internal string Alias { get; set; }
|
||||
internal int DataTypeId { get; set; }
|
||||
internal string PropertyEditorAlias { get; set; }
|
||||
}
|
||||
public class ArchetypePreValueProperty
|
||||
{
|
||||
[JsonProperty("alias")]
|
||||
public string Alias { get; set; }
|
||||
|
||||
[JsonProperty("remove")]
|
||||
public bool Remove { get; set; }
|
||||
|
||||
[JsonProperty("collapse")]
|
||||
public bool Collapse { get; set; }
|
||||
|
||||
[JsonProperty("label")]
|
||||
public string Label { get; set; }
|
||||
|
||||
[JsonProperty("helpText")]
|
||||
public string HelpText { get; set; }
|
||||
|
||||
[JsonProperty("dataTypeGuid")]
|
||||
public Guid DataTypeGuid { get; set; }
|
||||
|
||||
[JsonProperty("propertyEditorAlias")]
|
||||
public string PropertyEditorAlias { get; set; }
|
||||
|
||||
[JsonProperty("value")]
|
||||
public string Value { get; set; }
|
||||
|
||||
[JsonProperty("required")]
|
||||
public bool Required { get; set; }
|
||||
|
||||
[JsonProperty("regEx")]
|
||||
public string RegEx { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Web;
|
||||
|
||||
namespace Archetype.Models
|
||||
{
|
||||
public class ArchetypePropertyModel {
|
||||
[JsonProperty("alias")]
|
||||
public string Alias { get; internal set; }
|
||||
|
||||
[JsonProperty("value")]
|
||||
public object Value { get; internal set; }
|
||||
|
||||
[JsonProperty("propertyEditorAlias")]
|
||||
public string PropertyEditorAlias { get; internal set; }
|
||||
|
||||
[JsonProperty("dataTypeId")]
|
||||
public int DataTypeId { get; internal set; }
|
||||
|
||||
[JsonProperty("dataTypeGuid")]
|
||||
internal string DataTypeGuid { get; set; }
|
||||
|
||||
[JsonProperty("hostContentType")]
|
||||
internal PublishedContentType HostContentType { get; set; }
|
||||
|
||||
public T GetValue<T>()
|
||||
{
|
||||
|
||||
// Try Umbraco's PropertyValueConverters
|
||||
var converters = UmbracoContext.Current != null ? PropertyValueConvertersResolver.Current.Converters : Enumerable.Empty<IPropertyValueConverter>();
|
||||
if (converters.Any())
|
||||
{
|
||||
var convertedAttempt = TryConvertWithPropertyValueConverters<T>(Value, converters);
|
||||
if (convertedAttempt.Success)
|
||||
return convertedAttempt.Result;
|
||||
}
|
||||
|
||||
// If the value is of type T, just return it
|
||||
if (Value is T)
|
||||
return (T)Value;
|
||||
|
||||
// No PropertyValueConverters matched, so try a regular type conversion
|
||||
var convertAttempt2 = Value.TryConvertTo<T>();
|
||||
if (convertAttempt2.Success)
|
||||
return convertAttempt2.Result;
|
||||
|
||||
return default(T);
|
||||
}
|
||||
|
||||
private Attempt<T> TryConvertWithPropertyValueConverters<T>(object value, IEnumerable<IPropertyValueConverter> converters)
|
||||
{
|
||||
var properyType = CreateDummyPropertyType(DataTypeId, PropertyEditorAlias);
|
||||
|
||||
// In umbraco, there are default value converters that try to convert the
|
||||
// value if all else fails. The problem is, they are also in the list of
|
||||
// converters, and the means for filtering these out is internal, so
|
||||
// we currently have to try ALL converters to see if they can convert
|
||||
// rather than just finding the most appropreate. If the ability to filter
|
||||
// out default value converters becomes public, the following logic could
|
||||
// and probably should be changed.
|
||||
foreach (var converter in converters.Where(x => x.IsConverter(properyType)))
|
||||
{
|
||||
// Convert the type using a found value converter
|
||||
var value2 = converter.ConvertDataToSource(properyType, value, false);
|
||||
|
||||
// If the value is of type T, just return it
|
||||
if (value2 is T)
|
||||
return Attempt<T>.Succeed((T)value2);
|
||||
|
||||
// Value is not final value type, so try a regular type conversion aswell
|
||||
var convertAttempt = value2.TryConvertTo<T>();
|
||||
if (convertAttempt.Success)
|
||||
return Attempt<T>.Succeed(convertAttempt.Result);
|
||||
}
|
||||
|
||||
return Attempt<T>.Fail();
|
||||
}
|
||||
|
||||
private PublishedPropertyType CreateDummyPropertyType(int dataTypeId, string propertyEditorAlias)
|
||||
{
|
||||
return new PublishedPropertyType(this.HostContentType,
|
||||
new PropertyType(new DataTypeDefinition(-1, propertyEditorAlias)
|
||||
{
|
||||
Id = dataTypeId
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Umbraco.Core;
|
||||
|
||||
namespace Archetype.Umbraco.Models
|
||||
{
|
||||
public class Fieldset
|
||||
{
|
||||
public string Alias { get; set; }
|
||||
|
||||
public IEnumerable<Property> Properties;
|
||||
|
||||
public Fieldset()
|
||||
{
|
||||
Properties = new List<Property>();
|
||||
}
|
||||
|
||||
#region Helper Methods
|
||||
|
||||
public string GetValue(string propertyAlias)
|
||||
{
|
||||
return GetValue<string>(propertyAlias);
|
||||
}
|
||||
|
||||
public T GetValue<T>(string propertyAlias)
|
||||
{
|
||||
var property = GetProperty(propertyAlias);
|
||||
|
||||
if (property == null || string.IsNullOrEmpty(property.Value.ToString()))
|
||||
return default(T);
|
||||
|
||||
return property.GetValue<T>();
|
||||
}
|
||||
|
||||
private Property GetProperty(string propertyAlias)
|
||||
{
|
||||
return Properties.FirstOrDefault(p => p.Alias.InvariantEquals(propertyAlias));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
using System.Linq;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
|
||||
namespace Archetype.Umbraco.Models
|
||||
{
|
||||
public class Property
|
||||
{
|
||||
public string Alias { get; internal set; }
|
||||
public object Value { get; internal set; }
|
||||
public string PropertyEditorAlias { get; internal set; }
|
||||
|
||||
internal int DataTypeId { get; set; }
|
||||
|
||||
public T GetValue<T>()
|
||||
{
|
||||
// If the value is of type T, just return it
|
||||
if (Value is T)
|
||||
return (T)Value;
|
||||
|
||||
// Umbraco has the concept of a IPropertyEditorValueConverter which it
|
||||
// also queries for property resolvers. However I'm not sure what these
|
||||
// are for, nor can I find any implementations in core, so am currently
|
||||
// just ignoring these when looking up converters.
|
||||
// NB: IPropertyEditorValueConverter not to be confused with
|
||||
// IPropertyValueConverter which are the ones most people are creating
|
||||
var properyType = CreateDummyPropertyType(DataTypeId, PropertyEditorAlias);
|
||||
var converters = PropertyValueConvertersResolver.Current.Converters.ToArray();
|
||||
|
||||
// In umbraco, there are default value converters that try to convert the
|
||||
// value if all else fails. The problem is, they are also in the list of
|
||||
// converters, and the means for filtering these out is internal, so
|
||||
// we currently have to try ALL converters to see if they can convert
|
||||
// rather than just finding the most appropreate. If the ability to filter
|
||||
// out default value converters becomes public, the following logic could
|
||||
// and probably should be changed.
|
||||
foreach (var converter in converters.Where(x => x.IsConverter(properyType)))
|
||||
{
|
||||
// Convert the type using a found value converter
|
||||
var value2 = converter.ConvertDataToSource(properyType, Value, false);
|
||||
|
||||
// If the value is of type T, just return it
|
||||
if (value2 is T)
|
||||
return (T)value2;
|
||||
|
||||
// Value is not final value type, so try a regular type conversion aswell
|
||||
var convertAttempt = value2.TryConvertTo<T>();
|
||||
if (convertAttempt.Success)
|
||||
return convertAttempt.Result;
|
||||
}
|
||||
|
||||
// Value is not final value type, so try a regular type conversion
|
||||
var convertAttempt2 = Value.TryConvertTo<T>();
|
||||
if (convertAttempt2.Success)
|
||||
return convertAttempt2.Result;
|
||||
|
||||
return default(T);
|
||||
}
|
||||
|
||||
private PublishedPropertyType CreateDummyPropertyType(int dataTypeId, string propertyEditorAlias)
|
||||
{
|
||||
return new PublishedPropertyType(null,
|
||||
new PropertyType(new DataTypeDefinition(-1, propertyEditorAlias)
|
||||
{
|
||||
Id = dataTypeId
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,36 +2,17 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("Archetype")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyDescription("Archetype's supporting code library for Umbraco")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyCompany("Imulus")]
|
||||
[assembly: AssemblyProduct("Archetype")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2014")]
|
||||
[assembly: AssemblyCopyright("Copyright \xa9 Imulus 2014")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
[assembly: Guid("E37E94F9-C7BA-4B54-B7E1-64419B3DBA0B")]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("e37e94f9-c7ba-4b54-b7e1-64419b3dba0b")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("0.1.0.0")]
|
||||
[assembly: AssemblyFileVersion("0.1.0.0")]
|
||||
[assembly: AssemblyInformationalVersion("0.1.0-alpha")]
|
||||
[assembly: InternalsVisibleTo("Archetype.Courier")]
|
||||
[assembly: InternalsVisibleTo("Archetype.Tests")]
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
using System.Reflection;
|
||||
|
||||
[assembly: AssemblyVersion("1.2")]
|
||||
[assembly: AssemblyFileVersion("1.2-beta")]
|
||||
@@ -1,110 +1,49 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Archetype.Umbraco.Models;
|
||||
using Archetype.Umbraco.Extensions;
|
||||
using Umbraco.Core.Services;
|
||||
using Archetype.Extensions;
|
||||
using Archetype.Models;
|
||||
using Newtonsoft.Json;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Core.Services;
|
||||
|
||||
namespace Archetype.Umbraco.PropertyConverters
|
||||
{
|
||||
/* based on the Tim Geyssens sample at: https://github.com/TimGeyssens/MatrixPropEditor/blob/master/SamplePropertyValueConverter/SamplePropertyValueConverter/MatrixValueConverter.cs */
|
||||
[PropertyValueType(typeof(Archetype.Umbraco.Models.Archetype))]
|
||||
[PropertyValueCache(PropertyCacheValue.All, PropertyCacheLevel.Content)]
|
||||
public class ArchetypeValueConverter : PropertyValueConverterBase
|
||||
{
|
||||
protected JsonSerializerSettings _jsonSettings;
|
||||
|
||||
public ArchetypeValueConverter()
|
||||
{
|
||||
var dcr = new Newtonsoft.Json.Serialization.DefaultContractResolver();
|
||||
dcr.DefaultMembersSearchFlags |= System.Reflection.BindingFlags.NonPublic;
|
||||
|
||||
_jsonSettings = new JsonSerializerSettings { ContractResolver = dcr };
|
||||
}
|
||||
|
||||
public ServiceContext Services
|
||||
{
|
||||
get { return ApplicationContext.Current.Services; }
|
||||
}
|
||||
|
||||
public override bool IsConverter(PublishedPropertyType propertyType)
|
||||
{
|
||||
return propertyType.PropertyEditorAlias.Equals("Imulus.Archetype");
|
||||
}
|
||||
|
||||
public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview)
|
||||
{
|
||||
if (source == null) return null;
|
||||
|
||||
var sourceString = source.ToString();
|
||||
|
||||
if (sourceString.DetectIsJson())
|
||||
{
|
||||
try
|
||||
{
|
||||
// Deserialize value to archetype model
|
||||
var archetype = JsonConvert.DeserializeObject<Models.Archetype>(sourceString, _jsonSettings);
|
||||
|
||||
// Get list of configured properties and their types
|
||||
// and map them to the deserialized archetype model
|
||||
var preValue = GetArchetypePreValueFromDataTypeId(propertyType.DataTypeId);
|
||||
foreach (var fieldset in preValue.Fieldsets)
|
||||
{
|
||||
var fieldsetAlias = fieldset.Alias;
|
||||
foreach (var fieldsetInst in archetype.Fieldsets.Where(x => x.Alias == fieldsetAlias))
|
||||
{
|
||||
foreach (var property in fieldset.Properties)
|
||||
{
|
||||
var propertyAlias = property.Alias;
|
||||
foreach (var propertyInst in fieldsetInst.Properties.Where(x => x.Alias == propertyAlias))
|
||||
{
|
||||
propertyInst.DataTypeId = property.DataTypeId;
|
||||
propertyInst.PropertyEditorAlias = property.PropertyEditorAlias;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return archetype;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return sourceString;
|
||||
}
|
||||
|
||||
internal ArchetypePreValue GetArchetypePreValueFromDataTypeId(int dataTypeId)
|
||||
{
|
||||
var preValues = Services.DataTypeService.GetPreValuesCollectionByDataTypeId(dataTypeId);
|
||||
|
||||
var configJson = preValues.IsDictionaryBased
|
||||
? preValues.PreValuesAsDictionary["archetypeConfig"].Value
|
||||
: preValues.PreValuesAsArray.First().Value;
|
||||
|
||||
var config = JsonConvert.DeserializeObject<Models.ArchetypePreValue>(configJson, _jsonSettings);
|
||||
|
||||
foreach (var fieldset in config.Fieldsets)
|
||||
{
|
||||
foreach (var property in fieldset.Properties)
|
||||
{
|
||||
// Lookup the properties property editor alias
|
||||
// (See if we've already looked it up first though to save a database hit)
|
||||
var propertyWithSameDataType = config.Fieldsets.SelectMany(x => x.Properties)
|
||||
.FirstOrDefault(x => x.DataTypeId == property.DataTypeId && !string.IsNullOrWhiteSpace(x.PropertyEditorAlias));
|
||||
|
||||
property.PropertyEditorAlias = propertyWithSameDataType != null
|
||||
? propertyWithSameDataType.PropertyEditorAlias
|
||||
: Services.DataTypeService.GetDataTypeDefinitionById(property.DataTypeId).PropertyEditorAlias;
|
||||
}
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
}
|
||||
}
|
||||
namespace Archetype.PropertyConverters
|
||||
{
|
||||
[PropertyValueType(typeof(Models.ArchetypeModel))]
|
||||
[PropertyValueCache(PropertyCacheValue.All, PropertyCacheLevel.Content)]
|
||||
public class ArchetypeValueConverter : PropertyValueConverterBase
|
||||
{
|
||||
|
||||
public ServiceContext Services
|
||||
{
|
||||
get { return ApplicationContext.Current.Services; }
|
||||
}
|
||||
|
||||
public override bool IsConverter(PublishedPropertyType propertyType)
|
||||
{
|
||||
return propertyType.PropertyEditorAlias.Equals(Constants.PropertyEditorAlias);
|
||||
}
|
||||
|
||||
public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview)
|
||||
{
|
||||
var defaultValue = new Models.ArchetypeModel();
|
||||
|
||||
if (source == null)
|
||||
return defaultValue;
|
||||
|
||||
var sourceString = source.ToString();
|
||||
|
||||
if (!sourceString.DetectIsJson())
|
||||
return defaultValue;
|
||||
|
||||
var archetype = new ArchetypeHelper().DeserializeJsonToArchetype(source.ToString(),
|
||||
(propertyType != null ? propertyType.DataTypeId : -1),
|
||||
(propertyType != null ? propertyType.ContentType : null));
|
||||
|
||||
return archetype;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Archetype.Extensions;
|
||||
using ClientDependency.Core;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.Editors;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Web.PropertyEditors;
|
||||
using Umbraco.Core.Logging;
|
||||
|
||||
namespace Archetype.PropertyEditors
|
||||
{
|
||||
[PropertyEditorAsset(ClientDependencyType.Javascript, "/App_Plugins/Archetype/js/archetype.js")]
|
||||
[PropertyEditor("Imulus.Archetype", "Archetype", "/App_Plugins/Archetype/views/archetype.html", ValueType = "JSON")]
|
||||
public class ArchetypePropertyEditor : PropertyEditor
|
||||
{
|
||||
#region Pre Value Editor
|
||||
|
||||
protected override PreValueEditor CreatePreValueEditor()
|
||||
{
|
||||
return new ArchetypePreValueEditor();
|
||||
}
|
||||
|
||||
internal class ArchetypePreValueEditor : PreValueEditor
|
||||
{
|
||||
[PreValueField("archetypeConfig", "Config", "/App_Plugins/Archetype/views/archetype.config.html",
|
||||
Description = "(Required) Describe your Archetype.")]
|
||||
public string Config { get; set; }
|
||||
|
||||
[PreValueField("hideLabel", "Hide Label", "boolean",
|
||||
Description = "Hide the Umbraco property title and description, making the Archetype span the entire page width")]
|
||||
public bool HideLabel { get; set; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Value Editor
|
||||
|
||||
protected override PropertyValueEditor CreateValueEditor()
|
||||
{
|
||||
return new ArchetypePropertyValueEditor(base.CreateValueEditor());
|
||||
}
|
||||
|
||||
internal class ArchetypePropertyValueEditor : PropertyValueEditorWrapper
|
||||
{
|
||||
protected JsonSerializerSettings _jsonSettings;
|
||||
|
||||
public ArchetypePropertyValueEditor(PropertyValueEditor wrapped)
|
||||
: base(wrapped) { }
|
||||
|
||||
public override string ConvertDbToString(Property property, PropertyType propertyType, IDataTypeService dataTypeService)
|
||||
{
|
||||
if (property.Value == null || property.Value.ToString() == "")
|
||||
return string.Empty;
|
||||
|
||||
var archetype = new ArchetypeHelper().DeserializeJsonToArchetype(property.Value.ToString(), propertyType.DataTypeDefinitionId);
|
||||
|
||||
foreach (var fieldset in archetype.Fieldsets)
|
||||
{
|
||||
foreach (var propDef in fieldset.Properties)
|
||||
{
|
||||
try
|
||||
{
|
||||
var dtd = dataTypeService.GetDataTypeDefinitionById(Guid.Parse(propDef.DataTypeGuid));
|
||||
var propType = new PropertyType(dtd) { Alias = propDef.Alias };
|
||||
var prop = new Property(propType, propDef.Value);
|
||||
var propEditor = PropertyEditorResolver.Current.GetByAlias(dtd.PropertyEditorAlias);
|
||||
propDef.Value = propEditor.ValueEditor.ConvertDbToString(prop, propType, dataTypeService);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.Error<ArchetypeHelper>(ex.Message, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return archetype.SerializeForPersistence();
|
||||
}
|
||||
|
||||
public override object ConvertDbToEditor(Property property, PropertyType propertyType, IDataTypeService dataTypeService)
|
||||
{
|
||||
if (property.Value == null || property.Value.ToString() == "")
|
||||
return string.Empty;
|
||||
|
||||
var archetype = new ArchetypeHelper().DeserializeJsonToArchetype(property.Value.ToString(), propertyType.DataTypeDefinitionId);
|
||||
|
||||
foreach (var fieldset in archetype.Fieldsets)
|
||||
{
|
||||
foreach (var propDef in fieldset.Properties)
|
||||
{
|
||||
try
|
||||
{
|
||||
var dtd = dataTypeService.GetDataTypeDefinitionById(Guid.Parse(propDef.DataTypeGuid));
|
||||
var propType = new PropertyType(dtd) { Alias = propDef.Alias };
|
||||
var prop = new Property(propType, propDef.Value);
|
||||
var propEditor = PropertyEditorResolver.Current.GetByAlias(dtd.PropertyEditorAlias);
|
||||
propDef.Value = propEditor.ValueEditor.ConvertDbToEditor(prop, propType, dataTypeService);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.Error<ArchetypeHelper>(ex.Message, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return archetype;
|
||||
}
|
||||
public override object ConvertEditorToDb(ContentPropertyData editorValue, object currentValue)
|
||||
{
|
||||
if (editorValue.Value == null || editorValue.Value.ToString() == "")
|
||||
return string.Empty;
|
||||
|
||||
var archetype = new ArchetypeHelper().DeserializeJsonToArchetype(editorValue.Value.ToString(), editorValue.PreValues);
|
||||
|
||||
foreach (var fieldset in archetype.Fieldsets)
|
||||
{
|
||||
foreach (var propDef in fieldset.Properties)
|
||||
{
|
||||
try
|
||||
{
|
||||
var dtd = ApplicationContext.Current.Services.DataTypeService.GetDataTypeDefinitionById(Guid.Parse(propDef.DataTypeGuid));
|
||||
var preValues = ApplicationContext.Current.Services.DataTypeService.GetPreValuesCollectionByDataTypeId(dtd.Id);
|
||||
var propData = new ContentPropertyData(propDef.Value, preValues, new Dictionary<string, object>());
|
||||
var propEditor = PropertyEditorResolver.Current.GetByAlias(dtd.PropertyEditorAlias);
|
||||
propDef.Value = propEditor.ValueEditor.ConvertEditorToDb(propData, propDef.Value);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.Error<ArchetypeHelper>(ex.Message, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return archetype.SerializeForPersistence();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,354 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Dynamic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Archetype.Serialization
|
||||
{
|
||||
public class ArchetypeJsonConverter : JsonConverter
|
||||
{
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||
{
|
||||
var models = GenerateModels(value);
|
||||
|
||||
if (models.Count < 1)
|
||||
return;
|
||||
|
||||
if (models.Count == 1 && models[0] == null)
|
||||
return;
|
||||
|
||||
var jObj = new JObject
|
||||
{
|
||||
{
|
||||
"fieldsets",
|
||||
new JArray( new JRaw(SerializeModels(models)))
|
||||
}
|
||||
};
|
||||
|
||||
writer.WriteRaw(ApplyFormatting(jObj.ToString(), writer.Formatting));
|
||||
}
|
||||
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||
{
|
||||
var jToken = JToken.ReadFrom(reader);
|
||||
|
||||
if (jToken == null)
|
||||
return null;
|
||||
|
||||
var obj = Activator.CreateInstance(objectType);
|
||||
|
||||
if (null != obj as IEnumerable<object>
|
||||
&& jToken["fieldsets"] != null && jToken["fieldsets"].Any())
|
||||
{
|
||||
return DeserializeEnumerableObject(obj, jToken);
|
||||
}
|
||||
|
||||
return null == jToken as JArray
|
||||
? DeserializeObject(obj, jToken)
|
||||
: PopulateProperties(obj, jToken);
|
||||
}
|
||||
|
||||
public override bool CanConvert(Type objectType)
|
||||
{
|
||||
return IsValueArchetypeDatatype(objectType);
|
||||
}
|
||||
|
||||
#region private methods
|
||||
|
||||
private string ApplyFormatting(string json, Formatting formatting)
|
||||
{
|
||||
return JToken.Parse(json).ToString(formatting);
|
||||
}
|
||||
|
||||
private IList GenerateModels(object value)
|
||||
{
|
||||
var models = value as IList;
|
||||
|
||||
if (null != models)
|
||||
return models;
|
||||
|
||||
var properties = GetSerialiazableProperties(value).ToList();
|
||||
|
||||
if (!PropertyLayoutHasFieldsets(properties))
|
||||
return new List<object>() { value };
|
||||
|
||||
var dynamicModel = new ExpandoObject() as IDictionary<string, object>;
|
||||
|
||||
foreach (var pInfo in properties.Where(pInfo => !HasAsFieldsetAttribute(pInfo)))
|
||||
{
|
||||
dynamicModel.Add(GetJsonPropertyName(pInfo), pInfo.GetValue(value));
|
||||
}
|
||||
|
||||
var fieldsetModels = properties.Where(HasAsFieldsetAttribute)
|
||||
.Select(pInfo => pInfo.GetValue(value));
|
||||
|
||||
models = new List<object>
|
||||
{
|
||||
dynamicModel,
|
||||
};
|
||||
|
||||
models = ((IEnumerable<object>)models).Concat(fieldsetModels).ToList();
|
||||
|
||||
return models;
|
||||
}
|
||||
|
||||
private object DeserializeEnumerableObject(object obj, JToken jToken)
|
||||
{
|
||||
var model = obj as IEnumerable<object>;
|
||||
|
||||
var itemType = model.GetType().BaseType.GetGenericArguments().First();
|
||||
foreach (var fs in jToken["fieldsets"].Where(fs => fs["alias"].ToString().Equals(GetFieldsetName(itemType))))
|
||||
{
|
||||
var item = JsonConvert.DeserializeObject(
|
||||
fs["properties"].ToString(), itemType, GetArchetypeDatatypeConverter());
|
||||
|
||||
obj.GetType().GetMethod("Add").Invoke(obj, new[] { item });
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
private object DeserializeObject(object obj, JToken jToken)
|
||||
{
|
||||
var properties = GetSerialiazableProperties(obj).ToList();
|
||||
var asFieldset = properties.Where(HasAsFieldsetAttribute).ToList();
|
||||
|
||||
foreach (var propInfo in asFieldset)
|
||||
{
|
||||
var propAlias = GetJsonPropertyName(propInfo);
|
||||
var fsJToken = GetFieldsetProperties(propInfo.PropertyType, jToken);
|
||||
var propJToken =
|
||||
fsJToken.Single(p => p.SelectToken("alias").ToString().Equals(propAlias));
|
||||
|
||||
if (propJToken == null)
|
||||
continue;
|
||||
|
||||
var propValue = IsValueArchetypeDatatype(propInfo.PropertyType)
|
||||
? JsonConvert.DeserializeObject(fsJToken.ToString(), propInfo.PropertyType,
|
||||
GetArchetypeDatatypeConverter())
|
||||
: GetDeserializedPropertyValue(fsJToken, propInfo.PropertyType); ;
|
||||
|
||||
propInfo.SetValue(obj, propValue);
|
||||
}
|
||||
|
||||
return PopulateProperties(obj, GetFieldsetProperties(obj.GetType(), jToken));
|
||||
}
|
||||
|
||||
private JToken GetFieldsetProperties(Type objType, JToken jToken)
|
||||
{
|
||||
var objAlias = GetFieldsetName(objType);
|
||||
return
|
||||
jToken["fieldsets"].Single(p => p.SelectToken("alias").ToString().Equals(objAlias)).SelectToken("properties");
|
||||
}
|
||||
|
||||
private object PopulateProperties(object obj, JToken jToken)
|
||||
{
|
||||
var properties = GetSerialiazableProperties(obj);
|
||||
|
||||
foreach (var propertyInfo in properties)
|
||||
{
|
||||
var propAlias = GetJsonPropertyName(propertyInfo);
|
||||
|
||||
var propJToken = jToken.SingleOrDefault(p => p.SelectToken("alias").ToString().Equals(propAlias));
|
||||
|
||||
if (propJToken == null)
|
||||
continue;
|
||||
|
||||
var propValue = GetPropertyValue(propertyInfo, propJToken);
|
||||
|
||||
propertyInfo.SetValue(obj, propValue);
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
private object GetPropertyValue(PropertyInfo propertyInfo, JToken propJToken)
|
||||
{
|
||||
return IsValueArchetypeDatatype(propertyInfo.PropertyType)
|
||||
? JsonConvert.DeserializeObject(propJToken["value"].ToString(), propertyInfo.PropertyType,
|
||||
GetArchetypeDatatypeConverter())
|
||||
: GetDeserializedPropertyValue(propJToken["value"], propertyInfo.PropertyType);
|
||||
}
|
||||
|
||||
private bool PropertyLayoutHasFieldsets(IEnumerable<PropertyInfo> properties)
|
||||
{
|
||||
return properties.Any(HasAsFieldsetAttribute);
|
||||
}
|
||||
|
||||
private static bool HasAsFieldsetAttribute(PropertyInfo pInfo)
|
||||
{
|
||||
return pInfo
|
||||
.GetCustomAttributes(typeof(AsFieldsetAttribute), true).Length > 0;
|
||||
}
|
||||
|
||||
private IEnumerable SerializeModels(IEnumerable models)
|
||||
{
|
||||
var fieldsetJson = (from object model in models where null != model select SerializeModel(model)).ToList();
|
||||
|
||||
return String.Join(",", fieldsetJson);
|
||||
}
|
||||
|
||||
private string SerializeModel(object value)
|
||||
{
|
||||
if (value == null)
|
||||
return null;
|
||||
|
||||
var jObj = IsExpandoObject(value)
|
||||
? GetJObjectFromExpandoObject(value as IDictionary<string, object>)
|
||||
: GetJObject(value);
|
||||
|
||||
var fieldsetJson = new StringBuilder();
|
||||
var fieldsetWriter = new StringWriter(fieldsetJson);
|
||||
|
||||
using (var jsonWriter = new JsonTextWriter(fieldsetWriter))
|
||||
{
|
||||
jObj.WriteTo(jsonWriter);
|
||||
}
|
||||
|
||||
return fieldsetJson.ToString();
|
||||
}
|
||||
|
||||
private bool IsExpandoObject(object value)
|
||||
{
|
||||
return value.GetType().Name.Equals(typeof (ExpandoObject).Name);
|
||||
}
|
||||
|
||||
private JObject GetJObjectFromExpandoObject(IEnumerable<KeyValuePair<string, object>> obj)
|
||||
{
|
||||
var property = obj.ElementAt(0);
|
||||
var alias = property.Key;
|
||||
var value = property.Value;
|
||||
|
||||
var jObj = new JObject
|
||||
{
|
||||
{
|
||||
"alias",
|
||||
new JValue(alias)
|
||||
}
|
||||
};
|
||||
|
||||
var fsProperties = new List<JObject>
|
||||
{
|
||||
new JObject {new JProperty("alias", alias), new JProperty("value", value)}
|
||||
};
|
||||
jObj.Add("properties", new JRaw(JsonConvert.SerializeObject(fsProperties)));
|
||||
|
||||
return jObj;
|
||||
}
|
||||
|
||||
private JObject GetJObject(object obj)
|
||||
{
|
||||
var jObj = new JObject
|
||||
{
|
||||
{
|
||||
"alias",
|
||||
new JValue(GetFieldsetName(obj.GetType()))
|
||||
}
|
||||
};
|
||||
|
||||
var properties = GetSerialiazableProperties(obj);
|
||||
|
||||
var fsProperties = new List<JObject>();
|
||||
|
||||
foreach (var propertyInfo in properties)
|
||||
{
|
||||
var fsProperty = new JObject();
|
||||
var jProperty = new JProperty("alias", GetJsonPropertyName(propertyInfo));
|
||||
fsProperty.Add(jProperty);
|
||||
|
||||
var propValue = propertyInfo.GetValue(obj, null);
|
||||
|
||||
fsProperty.Add(
|
||||
new JProperty("value",
|
||||
IsValueArchetypeDatatype(propValue)
|
||||
? new JRaw(JsonConvert.SerializeObject(propValue,
|
||||
GetArchetypeDatatypeConverter()))
|
||||
: new JValue(GetSerializedPropertyValue(propValue))));
|
||||
|
||||
fsProperties.Add(fsProperty);
|
||||
}
|
||||
|
||||
jObj.Add("properties", new JRaw(JsonConvert.SerializeObject(fsProperties)));
|
||||
|
||||
return jObj;
|
||||
}
|
||||
|
||||
private IEnumerable<PropertyInfo> GetSerialiazableProperties(object obj)
|
||||
{
|
||||
return obj.GetType()
|
||||
.GetProperties(BindingFlags.Instance | BindingFlags.Public)
|
||||
.Where(prop => !Attribute.IsDefined(prop, typeof(JsonIgnoreAttribute)));
|
||||
}
|
||||
|
||||
private string GetJsonPropertyName(PropertyInfo property)
|
||||
{
|
||||
var attributes = property.GetCustomAttributes(true);
|
||||
var jsonPropAttribute = (JsonPropertyAttribute)attributes.FirstOrDefault(attr => attr is JsonPropertyAttribute);
|
||||
|
||||
return jsonPropAttribute != null ? jsonPropAttribute.PropertyName : property.Name;
|
||||
}
|
||||
|
||||
private string GetFieldsetName(Type type)
|
||||
{
|
||||
var attributes = type.GetCustomAttributes(true);
|
||||
var archetypeDatatypeAttribute = (AsArchetypeAttribute)attributes.FirstOrDefault(attr => attr is AsArchetypeAttribute);
|
||||
|
||||
return archetypeDatatypeAttribute != null ? archetypeDatatypeAttribute.FieldsetName : type.Name;
|
||||
}
|
||||
|
||||
private bool IsValueArchetypeDatatype(object value)
|
||||
{
|
||||
return value != null &&
|
||||
IsValueArchetypeDatatype(value.GetType());
|
||||
}
|
||||
|
||||
private bool IsValueArchetypeDatatype(Type type)
|
||||
{
|
||||
return type.GetCustomAttributes(typeof(AsArchetypeAttribute), true).Length > 0;
|
||||
}
|
||||
|
||||
private JsonConverter GetArchetypeDatatypeConverter()
|
||||
{
|
||||
return (JsonConverter)Activator.CreateInstance(GetType());
|
||||
}
|
||||
|
||||
private string GetSerializedPropertyValue(object propValue)
|
||||
{
|
||||
if (propValue == null)
|
||||
return String.Empty;
|
||||
|
||||
if (propValue is bool)
|
||||
return (bool)propValue ? GetSerializedPropertyValue(1) : GetSerializedPropertyValue(0);
|
||||
|
||||
return String.Format("{0}", propValue);
|
||||
}
|
||||
|
||||
private object GetDeserializedPropertyValue(JToken jToken, Type type)
|
||||
{
|
||||
if (String.IsNullOrEmpty(jToken.ToString()))
|
||||
return GetDefault(type);
|
||||
|
||||
var localType = Nullable.GetUnderlyingType(type) ?? type;
|
||||
|
||||
if (localType == typeof(bool))
|
||||
return jToken.ToString() == "1";
|
||||
|
||||
return localType == typeof(DateTime)
|
||||
? Convert.ToDateTime(jToken.ToString())
|
||||
: jToken.ToObject(localType);
|
||||
}
|
||||
|
||||
private object GetDefault(Type type)
|
||||
{
|
||||
return type.IsValueType ? Activator.CreateInstance(type) : null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
|
||||
namespace Archetype.Serialization
|
||||
{
|
||||
public class AsArchetypeAttribute : Attribute
|
||||
{
|
||||
public string FieldsetName { get; set; }
|
||||
|
||||
public AsArchetypeAttribute(string fieldsetname)
|
||||
{
|
||||
FieldsetName = fieldsetname;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
using System;
|
||||
|
||||
namespace Archetype.Serialization
|
||||
{
|
||||
public class AsFieldsetAttribute : Attribute
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Web;
|
||||
|
||||
namespace Archetype.Serialization
|
||||
{
|
||||
public static class SerializationExtensions
|
||||
{
|
||||
//temporary
|
||||
public static string GetPropertyDataValue(this IPublishedContent contentPage, string propertyAlias)
|
||||
{
|
||||
if (contentPage == null || !contentPage.HasProperty(propertyAlias))
|
||||
return null;
|
||||
|
||||
return (string)contentPage.Properties.Single(p => p.PropertyTypeAlias == propertyAlias).DataValue;
|
||||
}
|
||||
|
||||
public static T GetModelFromArchetype<T>(this IPublishedContent content,
|
||||
string cmsFieldAlias, bool returnInstanceIfNull = false)
|
||||
where T : class, new()
|
||||
{
|
||||
var archetypeJson = content.GetPropertyDataValue(cmsFieldAlias);
|
||||
return JsonConvert.DeserializeObject<T>(archetypeJson) ??
|
||||
(returnInstanceIfNull ? Activator.CreateInstance<T>() : default(T));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
</configuration>
|
||||
@@ -1,9 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="AutoMapper" version="3.0.0" targetFramework="net45" />
|
||||
<package id="ClientDependency" version="1.7.0.4" targetFramework="net45" />
|
||||
<package id="ClientDependency" version="1.7.1.2" targetFramework="net45" />
|
||||
<package id="ClientDependency-Mvc" version="1.7.0.4" targetFramework="net45" />
|
||||
<package id="HtmlAgilityPack" version="1.4.6" targetFramework="net45" />
|
||||
<package id="ImageProcessor" version="1.9.0.0" targetFramework="net45" />
|
||||
<package id="ImageProcessor.Web" version="3.2.3.0" targetFramework="net45" />
|
||||
<package id="Lucene.Net" version="2.9.4.1" targetFramework="net45" />
|
||||
<package id="Microsoft.AspNet.Mvc" version="4.0.30506.0" targetFramework="net45" />
|
||||
<package id="Microsoft.AspNet.Mvc.FixedDisplayModes" version="1.0.1" targetFramework="net45" />
|
||||
@@ -17,8 +19,8 @@
|
||||
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" />
|
||||
<package id="MiniProfiler" version="2.1.0" targetFramework="net45" />
|
||||
<package id="MySql.Data" version="6.6.5" targetFramework="net45" />
|
||||
<package id="Newtonsoft.Json" version="4.5.11" targetFramework="net45" />
|
||||
<package id="Newtonsoft.Json" version="6.0.2" targetFramework="net45" />
|
||||
<package id="SharpZipLib" version="0.86.0" targetFramework="net45" />
|
||||
<package id="UmbracoCms.Core" version="7.0.1" targetFramework="net45" />
|
||||
<package id="UmbracoCms.Core" version="7.1.2" targetFramework="net45" />
|
||||
<package id="xmlrpcnet" version="2.5.0" targetFramework="net45" />
|
||||
</packages>
|
||||
@@ -1,148 +0,0 @@
|
||||
[
|
||||
{
|
||||
"propertyEditorAlias": "Umbraco.CheckBoxList",
|
||||
"view": "checkboxlist"
|
||||
},
|
||||
{
|
||||
"propertyEditorAlias": "Umbraco.ColorPickerAlias",
|
||||
"view": "colorpicker"
|
||||
},
|
||||
{
|
||||
"propertyEditorAlias": "Umbraco.ContentPickerAlias",
|
||||
"view": "contentpicker"
|
||||
},
|
||||
{
|
||||
"propertyEditorAlias": "Umbraco.Date",
|
||||
"view": "datepicker",
|
||||
"defaultPreValues": [{ "format": "yyyy-MM-dd", "pickTime": false }]
|
||||
},
|
||||
{
|
||||
"propertyEditorAlias": "Umbraco.DateTime",
|
||||
"view": "datepicker",
|
||||
"format": "yyyy-MM-dd hh:mm:ss"
|
||||
},
|
||||
{
|
||||
"propertyEditorAlias": "Umbraco.DropDown",
|
||||
"view": "dropdown"
|
||||
},
|
||||
{
|
||||
"propertyEditorAlias": "Umbraco.DropDownMultiple",
|
||||
"view": "dropdown"
|
||||
},
|
||||
{
|
||||
"propertyEditorAlias": "Umbraco.DropDownMultiplePublishKeys",
|
||||
"view": "dropdown"
|
||||
},
|
||||
{
|
||||
"propertyEditorAlias": "Umbraco.DropdownlistPublishingKeys",
|
||||
"view": "dropdown"
|
||||
},
|
||||
{
|
||||
"propertyEditorAlias": "Umbraco.EmailAddress",
|
||||
"view": "email"
|
||||
},
|
||||
{
|
||||
"propertyEditorAlias": "Umbraco.UploadField",
|
||||
"view": "fileupload"
|
||||
},
|
||||
{
|
||||
"propertyEditorAlias": "Umbraco.FolderBrowser",
|
||||
"view": "folderbrowser"
|
||||
},
|
||||
{
|
||||
"propertyEditorAlias": "Umbraco.Integer",
|
||||
"view": "integer"
|
||||
},
|
||||
{
|
||||
"propertyEditorAlias": "Umbraco.NoEdit",
|
||||
"view": "readonlyvalue"
|
||||
},
|
||||
{
|
||||
"propertyEditorAlias": "Umbraco.ListView",
|
||||
"view": "listview"
|
||||
},
|
||||
{
|
||||
"propertyEditorAlias": "Umbraco.MacroContainer",
|
||||
"view": "macrocontainer"
|
||||
},
|
||||
{
|
||||
"propertyEditorAlias": "Umbraco.MarkdownEditor",
|
||||
"view": "markdowneditor"
|
||||
},
|
||||
{
|
||||
"propertyEditorAlias": "Umbraco.MediaPicker",
|
||||
"view": "mediapicker",
|
||||
"defaultPreValues": [{ "multiPicker": "0" }]
|
||||
},
|
||||
{
|
||||
"propertyEditorAlias": "Umbraco.MemberGroupPicker",
|
||||
"view": "membergrouppicker"
|
||||
},
|
||||
{
|
||||
"propertyEditorAlias": "Umbraco.MemberPicker",
|
||||
"view": "memberpicker"
|
||||
},
|
||||
{
|
||||
"propertyEditorAlias": "Umbraco.MultiNodeTreePicker",
|
||||
"view": "contentpicker",
|
||||
"defaultPreValues": [{ "multiPicker": "1" }]
|
||||
},
|
||||
{
|
||||
"propertyEditorAlias": "Umbraco.MultipleMediaPicker",
|
||||
"view": "mediapicker"
|
||||
},
|
||||
{
|
||||
"propertyEditorAlias": "Umbraco.MultipleTextstring",
|
||||
"view": "multipletextbox"
|
||||
},
|
||||
{
|
||||
"propertyEditorAlias": "Umbraco.RadioButtonList",
|
||||
"view": "radiobuttons"
|
||||
},
|
||||
{
|
||||
"propertyEditorAlias": "Umbraco.RelatedLinks",
|
||||
"view": "relatedlinks"
|
||||
},
|
||||
{
|
||||
"propertyEditorAlias": "Umbraco.TinyMCEv3",
|
||||
"view": "rte"
|
||||
},
|
||||
{
|
||||
"propertyEditorAlias": "Umbraco.Slider",
|
||||
"view": "slider"
|
||||
},
|
||||
{
|
||||
"propertyEditorAlias": "Umbraco.Tags",
|
||||
"view": "tags",
|
||||
"defaultPreValues": [{ "group": "default" }]
|
||||
},
|
||||
{
|
||||
"propertyEditorAlias": "Umbraco.TextboxMultiple",
|
||||
"view": "textarea"
|
||||
},
|
||||
{
|
||||
"propertyEditorAlias": "Umbraco.Textbox",
|
||||
"view": "textbox"
|
||||
},
|
||||
{
|
||||
"propertyEditorAlias": "Umbraco.TrueFalse",
|
||||
"view": "boolean"
|
||||
},
|
||||
{
|
||||
"propertyEditorAlias": "Umbraco.UserPicker",
|
||||
"view": "entitypicker",
|
||||
"defaultPreValues": [{ "entityType": "User" }]
|
||||
},
|
||||
{
|
||||
"propertyEditorAlias": "Umbraco.NoEdit",
|
||||
"view": "readonlyvalue"
|
||||
},
|
||||
{
|
||||
"propertyEditorAlias": "Umbraco.Textbox",
|
||||
"view": "textbox"
|
||||
},
|
||||
{
|
||||
"propertyEditorAlias": "Imulus.Archetype",
|
||||
"view": "/App_Plugins/Archetype/views/archetype.html"
|
||||
}
|
||||
]
|
||||
@@ -1,19 +1,19 @@
|
||||
angular.module("umbraco").controller("Imulus.ArchetypeConfigController", function ($scope, $http, assetsService, dialogService, archetypePropertyEditorResource) {
|
||||
|
||||
//$scope.model.value = "";
|
||||
//console.log($scope.model.value);
|
||||
|
||||
//$scope.model.value = "";
|
||||
//console.log($scope.model.value);
|
||||
|
||||
//define empty items
|
||||
var newPropertyModel = '{"alias": "", "remove": false, "collapse": false, "label": "", "helpText": "", "dataTypeId": "-88", "value": ""}';
|
||||
var newPropertyModel = '{"alias": "", "remove": false, "collapse": false, "label": "", "helpText": "", "dataTypeGuid": "0cc0eba1-9960-42c9-bf9b-60e150b429ae", "value": ""}';
|
||||
var newFieldsetModel = '{"alias": "", "remove": false, "collapse": false, "labelTemplate": "", "icon": "", "label": "", "properties": [' + newPropertyModel + ']}';
|
||||
var defaultFieldsetConfigModel = JSON.parse('{"showAdvancedOptions": false, "hideFieldsetToolbar": false, "enableMultipleFieldsets": false, "hideFieldsetControls": false, "hidePropertyLabel": false, "maxFieldsets": null, "fieldsets": [' + newFieldsetModel + ']}');
|
||||
var defaultFieldsetConfigModel = JSON.parse('{"showAdvancedOptions": false, "startWithAddButton": false, "hideFieldsetToolbar": false, "enableMultipleFieldsets": false, "hideFieldsetControls": false, "hidePropertyLabel": false, "maxFieldsets": null, "enableCollapsing": true, "fieldsets": [' + newFieldsetModel + ']}');
|
||||
|
||||
//ini the model
|
||||
$scope.model.value = $scope.model.value || defaultFieldsetConfigModel;
|
||||
|
||||
|
||||
//ini the render model
|
||||
initConfigRenderModel();
|
||||
|
||||
|
||||
//get the available datatypes
|
||||
archetypePropertyEditorResource.getAllDataTypes().then(function(data) {
|
||||
$scope.availableDataTypes = data;
|
||||
@@ -40,16 +40,16 @@ angular.module("umbraco").controller("Imulus.ArchetypeConfigController", functio
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//function that determines how to manage expanding/collapsing fieldsets
|
||||
$scope.focusFieldset = function(fieldset){
|
||||
var iniState;
|
||||
|
||||
|
||||
if(fieldset)
|
||||
{
|
||||
iniState = fieldset.collapse;
|
||||
}
|
||||
|
||||
|
||||
_.each($scope.archetypeConfigRenderModel.fieldsets, function(fieldset){
|
||||
if($scope.archetypeConfigRenderModel.fieldsets.length == 1 && fieldset.remove == false)
|
||||
{
|
||||
@@ -66,7 +66,7 @@ angular.module("umbraco").controller("Imulus.ArchetypeConfigController", functio
|
||||
fieldset.collapse = false;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
if(iniState)
|
||||
{
|
||||
fieldset.collapse = !iniState;
|
||||
@@ -79,7 +79,7 @@ angular.module("umbraco").controller("Imulus.ArchetypeConfigController", functio
|
||||
//function that determines how to manage expanding/collapsing properties
|
||||
$scope.focusProperty = function(properties, property){
|
||||
var iniState;
|
||||
|
||||
|
||||
if(property)
|
||||
{
|
||||
iniState = property.collapse;
|
||||
@@ -95,7 +95,7 @@ angular.module("umbraco").controller("Imulus.ArchetypeConfigController", functio
|
||||
property.collapse = false;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
if(iniState)
|
||||
{
|
||||
property.collapse = !iniState;
|
||||
@@ -106,27 +106,45 @@ angular.module("umbraco").controller("Imulus.ArchetypeConfigController", functio
|
||||
_.each($scope.archetypeConfigRenderModel.fieldsets, function(fieldset){
|
||||
$scope.focusProperty(fieldset.properties);
|
||||
});
|
||||
|
||||
|
||||
//setup JSON.stringify helpers
|
||||
$scope.archetypeConfigRenderModel.toString = stringify;
|
||||
|
||||
|
||||
//encapsulate stringify (should be built into browsers, not sure of IE support)
|
||||
function stringify() {
|
||||
return JSON.stringify(this);
|
||||
}
|
||||
|
||||
|
||||
//watch for changes
|
||||
$scope.$watch('archetypeConfigRenderModel', function (v) {
|
||||
//console.log(v);
|
||||
if (typeof v === 'string') {
|
||||
if (typeof v === 'string') {
|
||||
$scope.archetypeConfigRenderModel = JSON.parse(v);
|
||||
$scope.archetypeConfigRenderModel.toString = stringify;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
$scope.autoPopulateAlias = function(s) {
|
||||
var modelType = s.hasOwnProperty('fieldset') ? 'fieldset' : 'property';
|
||||
var modelProperty = s[modelType];
|
||||
|
||||
if (!modelProperty.aliasIsDirty) {
|
||||
modelProperty.alias = modelProperty.label.toUmbracoAlias();
|
||||
}
|
||||
}
|
||||
|
||||
$scope.markAliasDirty = function(s) {
|
||||
var modelType = s.hasOwnProperty('fieldset') ? 'fieldset' : 'property';
|
||||
var modelProperty = s[modelType];
|
||||
|
||||
if (!modelProperty.aliasIsDirty) {
|
||||
modelProperty.aliasIsDirty = true;;
|
||||
}
|
||||
}
|
||||
|
||||
//helper that returns if an item can be removed
|
||||
$scope.canRemoveFieldset = function ()
|
||||
{
|
||||
{
|
||||
return countVisibleFieldset() > 1;
|
||||
}
|
||||
|
||||
@@ -135,10 +153,10 @@ angular.module("umbraco").controller("Imulus.ArchetypeConfigController", functio
|
||||
{
|
||||
return countVisibleFieldset() > 1;
|
||||
}
|
||||
|
||||
|
||||
//helper that returns if an item can be removed
|
||||
$scope.canRemoveProperty = function (fieldset)
|
||||
{
|
||||
{
|
||||
return countVisibleProperty(fieldset) > 1;
|
||||
}
|
||||
|
||||
@@ -148,17 +166,17 @@ angular.module("umbraco").controller("Imulus.ArchetypeConfigController", functio
|
||||
return countVisibleProperty(fieldset) > 1;
|
||||
}
|
||||
|
||||
$scope.getDataTypeNameById = function (id) {
|
||||
$scope.getDataTypeNameByGuid = function (guid) {
|
||||
if ($scope.availableDataTypes == null) // Might not be initialized yet?
|
||||
return "";
|
||||
|
||||
|
||||
var dataType = _.find($scope.availableDataTypes, function(d) {
|
||||
return d.id == id;
|
||||
return d.guid == guid;
|
||||
});
|
||||
|
||||
return dataType == null ? "" : dataType.name;
|
||||
}
|
||||
|
||||
|
||||
//helper to count what is visible
|
||||
function countVisibleFieldset()
|
||||
{
|
||||
@@ -172,7 +190,7 @@ angular.module("umbraco").controller("Imulus.ArchetypeConfigController", functio
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
//determines how many properties are visible
|
||||
function countVisibleProperty(fieldset)
|
||||
{
|
||||
@@ -186,13 +204,13 @@ angular.module("umbraco").controller("Imulus.ArchetypeConfigController", functio
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
//handles a fieldset add
|
||||
$scope.addFieldsetRow = function ($index, $event) {
|
||||
$scope.archetypeConfigRenderModel.fieldsets.splice($index + 1, 0, JSON.parse(newFieldsetModel));
|
||||
$scope.focusFieldset();
|
||||
}
|
||||
|
||||
|
||||
//rather than splice the archetypeConfigRenderModel, we're hiding this and cleaning onFormSubmitting
|
||||
$scope.removeFieldsetRow = function ($index) {
|
||||
if ($scope.canRemoveFieldset()) {
|
||||
@@ -201,12 +219,12 @@ angular.module("umbraco").controller("Imulus.ArchetypeConfigController", functio
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//handles a property add
|
||||
$scope.addPropertyRow = function (fieldset, $index) {
|
||||
fieldset.properties.splice($index + 1, 0, JSON.parse(newPropertyModel));
|
||||
}
|
||||
|
||||
|
||||
//rather than splice the archetypeConfigRenderModel, we're hiding this and cleaning onFormSubmitting
|
||||
$scope.removePropertyRow = function (fieldset, $index) {
|
||||
if ($scope.canRemoveProperty(fieldset)) {
|
||||
@@ -215,7 +233,7 @@ angular.module("umbraco").controller("Imulus.ArchetypeConfigController", functio
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//helper to ini the render model
|
||||
function initConfigRenderModel()
|
||||
{
|
||||
@@ -224,6 +242,8 @@ angular.module("umbraco").controller("Imulus.ArchetypeConfigController", functio
|
||||
_.each($scope.archetypeConfigRenderModel.fieldsets, function(fieldset){
|
||||
|
||||
fieldset.remove = false;
|
||||
if (fieldset.alias.length > 0)
|
||||
fieldset.aliasIsDirty = true;
|
||||
|
||||
if(fieldset.label)
|
||||
{
|
||||
@@ -232,41 +252,43 @@ angular.module("umbraco").controller("Imulus.ArchetypeConfigController", functio
|
||||
|
||||
_.each(fieldset.properties, function(fieldset){
|
||||
fieldset.remove = false;
|
||||
if (fieldset.alias.length > 0)
|
||||
fieldset.aliasIsDirty = true;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
//sync things up on save
|
||||
$scope.$on("formSubmitting", function (ev, args) {
|
||||
syncModelToRenderModel();
|
||||
});
|
||||
|
||||
|
||||
//helper to sync the model to the renderModel
|
||||
function syncModelToRenderModel()
|
||||
{
|
||||
$scope.model.value = $scope.archetypeConfigRenderModel;
|
||||
var fieldsets = [];
|
||||
|
||||
|
||||
_.each($scope.archetypeConfigRenderModel.fieldsets, function(fieldset){
|
||||
//check fieldsets
|
||||
if (!fieldset.remove) {
|
||||
fieldsets.push(fieldset);
|
||||
|
||||
|
||||
var properties = [];
|
||||
|
||||
_.each(fieldset.properties, function(property){
|
||||
if (!property.remove) {
|
||||
properties.push(property);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
fieldset.properties = properties;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
$scope.model.value.fieldsets = fieldsets;
|
||||
}
|
||||
|
||||
|
||||
//archetype css
|
||||
assetsService.loadCss("/App_Plugins/Archetype/css/archetype.css");
|
||||
});
|
||||
|
||||
+111
-119
@@ -1,23 +1,23 @@
|
||||
angular.module("umbraco").controller("Imulus.ArchetypeController", function ($scope, $http, assetsService, angularHelper, notificationsService) {
|
||||
|
||||
angular.module("umbraco").controller("Imulus.ArchetypeController", function ($scope, $http, assetsService, angularHelper, notificationsService, $timeout) {
|
||||
|
||||
//$scope.model.value = "";
|
||||
$scope.model.hideLabel = $scope.model.config.hideLabel == 1;
|
||||
|
||||
//get a reference to the current form
|
||||
var form = angularHelper.getCurrentForm($scope);
|
||||
$scope.form = $scope.form || angularHelper.getCurrentForm($scope);
|
||||
|
||||
//set the config equal to our prevalue config
|
||||
$scope.model.config = $scope.model.config.archetypeConfig;
|
||||
|
||||
//ini the model
|
||||
$scope.model.value = $scope.model.value || { fieldsets: [getEmptyRenderFieldset($scope.model.config.fieldsets[0])] };
|
||||
|
||||
//ini the render model
|
||||
$scope.archetypeRenderModel = {};
|
||||
initArchetypeRenderModel();
|
||||
|
||||
//ini the model
|
||||
$scope.model.value = $scope.model.value || getDefaultModel($scope.model.config);
|
||||
init();
|
||||
|
||||
//helper to get $eval the labelTemplate
|
||||
$scope.getFieldsetTitle = function(fieldsetConfigModel, fieldsetIndex) {
|
||||
var fieldset = $scope.archetypeRenderModel.fieldsets[fieldsetIndex];
|
||||
if(!fieldsetConfigModel)
|
||||
return "";
|
||||
var fieldset = $scope.model.value.fieldsets[fieldsetIndex];
|
||||
var fieldsetConfig = $scope.getConfigFieldsetByAlias(fieldset.alias);
|
||||
var template = fieldsetConfigModel.labelTemplate;
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
cursor: "move",
|
||||
handle: ".handle",
|
||||
update: function (ev, ui) {
|
||||
|
||||
$scope.setDirty();
|
||||
},
|
||||
stop: function (ev, ui) {
|
||||
|
||||
@@ -60,23 +60,25 @@
|
||||
|
||||
if (typeof $index != 'undefined')
|
||||
{
|
||||
$scope.archetypeRenderModel.fieldsets.splice($index + 1, 0, newFieldset);
|
||||
$scope.model.value.fieldsets.splice($index + 1, 0, newFieldset);
|
||||
}
|
||||
else
|
||||
{
|
||||
$scope.archetypeRenderModel.fieldsets.push(newFieldset);
|
||||
$scope.model.value.fieldsets.push(newFieldset);
|
||||
}
|
||||
}
|
||||
newFieldset.collapse = true;
|
||||
$scope.setDirty();
|
||||
|
||||
newFieldset.collapse = $scope.model.config.enableCollapsing ? true : false;
|
||||
$scope.focusFieldset(newFieldset);
|
||||
}
|
||||
}
|
||||
|
||||
//rather than splice the archetypeRenderModel, we're hiding this and cleaning onFormSubmitting
|
||||
$scope.removeRow = function ($index) {
|
||||
if ($scope.canRemove()) {
|
||||
if (confirm('Are you sure you want to remove this?')) {
|
||||
$scope.archetypeRenderModel.fieldsets[$index].remove = true;
|
||||
$scope.setDirty();
|
||||
$scope.model.value.fieldsets.splice($index, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -94,8 +96,10 @@
|
||||
|
||||
//helper that returns if an item can be removed
|
||||
$scope.canRemove = function ()
|
||||
{
|
||||
return countVisible() > 1;
|
||||
{
|
||||
return countVisible() > 1
|
||||
|| ($scope.model.config.maxFieldsets == 1 && $scope.model.config.fieldsets.length > 1)
|
||||
|| $scope.model.config.startWithAddButton;
|
||||
}
|
||||
|
||||
//helper that returns if an item can be sorted
|
||||
@@ -104,16 +108,26 @@
|
||||
return countVisible() > 1;
|
||||
}
|
||||
|
||||
//helper, ini the render model from the server (model.value)
|
||||
function initArchetypeRenderModel() {
|
||||
$scope.archetypeRenderModel = $scope.model.value;
|
||||
//helpers for determining if the add button should be shown
|
||||
$scope.showAddButton = function () {
|
||||
return $scope.model.config.startWithAddButton
|
||||
&& countVisible() === 0;
|
||||
///&& $scope.model.config.fieldsets.length == 1;
|
||||
}
|
||||
|
||||
_.each($scope.archetypeRenderModel.fieldsets, function (fieldset)
|
||||
//helper, ini the render model from the server (model.value)
|
||||
function init() {
|
||||
$scope.model.value = removeNulls($scope.model.value);
|
||||
addDefaultProperties($scope.model.value.fieldsets);
|
||||
}
|
||||
|
||||
function addDefaultProperties(fieldsets)
|
||||
{
|
||||
_.each(fieldsets, function (fieldset)
|
||||
{
|
||||
fieldset.remove = false;
|
||||
fieldset.collapse = false;
|
||||
fieldset.isValid = true;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
//helper to get the correct fieldset from config
|
||||
@@ -130,38 +144,52 @@
|
||||
});
|
||||
return (typeof property !== 'undefined') ? property.value : '';
|
||||
};
|
||||
|
||||
|
||||
$scope.isCollapsed = function(fieldset)
|
||||
{
|
||||
if(typeof fieldset.collapse === "undefined")
|
||||
{
|
||||
fieldset.collapse = true;
|
||||
}
|
||||
return fieldset.collapse;
|
||||
}
|
||||
|
||||
//helper for expanding/collapsing fieldsets
|
||||
$scope.focusFieldset = function(fieldset){
|
||||
|
||||
fixDisableSelection();
|
||||
|
||||
if (!$scope.model.config.enableCollapsing) {
|
||||
return;
|
||||
}
|
||||
|
||||
var iniState;
|
||||
|
||||
|
||||
if(fieldset)
|
||||
{
|
||||
iniState = fieldset.collapse;
|
||||
}
|
||||
|
||||
_.each($scope.archetypeRenderModel.fieldsets, function(fieldset){
|
||||
if($scope.archetypeRenderModel.fieldsets.length == 1 && fieldset.remove == false)
|
||||
{
|
||||
fieldset.collapse = false;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
_.each($scope.model.value.fieldsets, function(fieldset){
|
||||
fieldset.collapse = true;
|
||||
});
|
||||
|
||||
if(iniState)
|
||||
|
||||
if(!fieldset && $scope.model.value.fieldsets.length == 1)
|
||||
{
|
||||
$scope.model.value.fieldsets[0].collapse = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if(iniState && fieldset)
|
||||
{
|
||||
fieldset.collapse = !iniState;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//ini the fieldset expand/collapse
|
||||
$scope.focusFieldset();
|
||||
|
||||
//developerMode helpers
|
||||
$scope.archetypeRenderModel.toString = stringify;
|
||||
$scope.model.value.toString = stringify;
|
||||
|
||||
//encapsulate stringify (should be built into browsers, not sure of IE support)
|
||||
function stringify() {
|
||||
@@ -169,12 +197,12 @@
|
||||
}
|
||||
|
||||
//watch for changes
|
||||
$scope.$watch('archetypeRenderModel', function (v) {
|
||||
$scope.$watch('model.value', function (v) {
|
||||
if ($scope.model.config.developerMode) {
|
||||
console.log(v);
|
||||
if (typeof v === 'string') {
|
||||
$scope.archetypeRenderModel = JSON.parse(v);
|
||||
$scope.archetypeRenderModel.toString = stringify;
|
||||
$scope.model.value = JSON.parse(v);
|
||||
$scope.model.value.toString = stringify;
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -182,78 +210,52 @@
|
||||
//helper to count what is visible
|
||||
function countVisible()
|
||||
{
|
||||
var count = 0;
|
||||
|
||||
_.each($scope.archetypeRenderModel.fieldsets, function(fieldset){
|
||||
if (fieldset.remove == false) {
|
||||
count++;
|
||||
}
|
||||
});
|
||||
|
||||
return count;
|
||||
return $scope.model.value.fieldsets.length;
|
||||
}
|
||||
|
||||
//helper to sync the model to the renderModel
|
||||
function syncModelToRenderModel()
|
||||
{
|
||||
$scope.model.value = { fieldsets: [] };
|
||||
// helper to get initial model if none was provided
|
||||
function getDefaultModel(config) {
|
||||
if (config.startWithAddButton)
|
||||
return { fieldsets: [] };
|
||||
|
||||
_.each($scope.archetypeRenderModel.fieldsets, function(fieldset){
|
||||
var cleanedFieldset = cleanFieldset(fieldset);
|
||||
|
||||
if(cleanFieldset){
|
||||
$scope.model.value.fieldsets.push(cleanedFieldset);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//helper to remove properties only used during editing that we don't want in the saved data
|
||||
//also removes properties that are no longer in the config
|
||||
function cleanFieldset(fieldset)
|
||||
{
|
||||
if (typeof fieldset != 'function' && !fieldset.remove){
|
||||
|
||||
var fieldsetConfig = $scope.getConfigFieldsetByAlias(fieldset.alias);
|
||||
|
||||
//clone and clean
|
||||
var tempFieldset = JSON.parse(JSON.stringify(fieldset));
|
||||
delete tempFieldset.remove;
|
||||
delete tempFieldset.isValid;
|
||||
delete tempFieldset.collapse;
|
||||
|
||||
_.each(tempFieldset.properties, function(property, index){
|
||||
var propertyConfig = _.find(fieldsetConfig.properties, function(p){
|
||||
return property.alias == p.alias;
|
||||
});
|
||||
|
||||
//just prune the property
|
||||
if(propertyConfig){
|
||||
delete property.isValid;
|
||||
}
|
||||
else
|
||||
{
|
||||
//need to remove the whole property
|
||||
tempFieldset.properties.splice(index, 1);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return tempFieldset;
|
||||
}
|
||||
return { fieldsets: [getEmptyRenderFieldset(config.fieldsets[0])] };
|
||||
}
|
||||
|
||||
//helper to add an empty fieldset to the render model
|
||||
function getEmptyRenderFieldset (fieldsetModel)
|
||||
{
|
||||
return JSON.parse('{"alias": "' + fieldsetModel.alias + '", "remove": false, "isValid": true, "properties": []}');
|
||||
function getEmptyRenderFieldset (fieldsetModel) {
|
||||
return {alias: fieldsetModel.alias, collapse: false, isValid: true, properties: []};
|
||||
}
|
||||
|
||||
//helper to ensure no nulls make it into the model
|
||||
function removeNulls(model){
|
||||
if(model.fieldsets){
|
||||
_.each(model.fieldsets, function(fieldset, index){
|
||||
if(!fieldset){
|
||||
model.fieldsets.splice(index, 1);
|
||||
removeNulls(model);
|
||||
}
|
||||
});
|
||||
|
||||
return model;
|
||||
}
|
||||
}
|
||||
|
||||
// Hack for U4-4281 / #61
|
||||
function fixDisableSelection() {
|
||||
$timeout(function() {
|
||||
$('.archetypeEditor .controls')
|
||||
.bind('mousedown.ui-disableSelection selectstart.ui-disableSelection', function(e) {
|
||||
e.stopImmediatePropagation();
|
||||
});
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
//helper to lookup validity when given a fieldsetIndex and property alias
|
||||
$scope.getPropertyValidity = function(fieldsetIndex, alias)
|
||||
{
|
||||
if($scope.archetypeRenderModel.fieldsets[fieldsetIndex])
|
||||
if($scope.model.value.fieldsets[fieldsetIndex])
|
||||
{
|
||||
var property = _.find($scope.archetypeRenderModel.fieldsets[fieldsetIndex].properties, function(property){
|
||||
var property = _.find($scope.model.value.fieldsets[fieldsetIndex].properties, function(property){
|
||||
return property.alias == alias;
|
||||
});
|
||||
}
|
||||
@@ -261,27 +263,17 @@
|
||||
return (typeof property == 'undefined') ? true : property.isValid;
|
||||
}
|
||||
|
||||
//sync things up on save
|
||||
$scope.$on("formSubmitting", function (ev, args) {
|
||||
|
||||
//test for form; may have to do this differently for nested archetypes
|
||||
if(!form)
|
||||
return;
|
||||
|
||||
if(form.$invalid)
|
||||
{
|
||||
notificationsService.warning("Cannot Save Document", "The document could not be saved because of missing required fields.")
|
||||
// helper to force the current form into the dirty state
|
||||
$scope.setDirty = function () {
|
||||
if($scope.form) {
|
||||
$scope.form.$setDirty();
|
||||
}
|
||||
else
|
||||
{
|
||||
syncModelToRenderModel();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//custom js
|
||||
if ($scope.model.config.customJsPath) {
|
||||
assetsService.loadJs($scope.model.config.customJsPath);
|
||||
}
|
||||
}
|
||||
|
||||
//archetype css
|
||||
assetsService.loadCss("/App_Plugins/Archetype/css/archetype.css");
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
angular.module("umbraco.directives").directive('archetypeCustomView', function ($compile, $http) {
|
||||
var linker = function (scope, element, attrs) {
|
||||
|
||||
var config = scope.archetype.config.archetypeConfig;
|
||||
|
||||
var view = "/App_plugins/Archetype/views/archetype.default.html";
|
||||
if(config.customViewPath) {
|
||||
view = config.customViewPath;
|
||||
}
|
||||
|
||||
$http.get(view).then(function(data) {
|
||||
|
||||
scope.model = {};
|
||||
scope.model.value = scope.archetype.value;
|
||||
scope.model.config = scope.archetype.config;
|
||||
|
||||
element.html(data.data).show();
|
||||
|
||||
$compile(element.contents())(scope);
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
restrict: "A",
|
||||
replace: true,
|
||||
link: linker,
|
||||
scope: {
|
||||
archetype: "="
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -1,5 +1,5 @@
|
||||
angular.module("umbraco.directives").directive('archetypeProperty', function ($compile, $http, archetypePropertyEditorResource, umbPropEditorHelper) {
|
||||
|
||||
angular.module("umbraco.directives").directive('archetypeProperty', function ($compile, $http, archetypePropertyEditorResource, umbPropEditorHelper, $timeout, $rootScope, $q) {
|
||||
|
||||
function getFieldsetByAlias(fieldsets, alias)
|
||||
{
|
||||
return _.find(fieldsets, function(fieldset){
|
||||
@@ -51,16 +51,21 @@ angular.module("umbraco.directives").directive('archetypeProperty', function ($c
|
||||
var configFieldsetModel = getFieldsetByAlias(scope.archetypeConfig.fieldsets, scope.fieldset.alias);
|
||||
var view = "";
|
||||
var label = configFieldsetModel.properties[scope.propertyConfigIndex].label;
|
||||
var dataTypeId = configFieldsetModel.properties[scope.propertyConfigIndex].dataTypeId;
|
||||
var dataTypeGuid = configFieldsetModel.properties[scope.propertyConfigIndex].dataTypeGuid;
|
||||
var config = null;
|
||||
var alias = configFieldsetModel.properties[scope.propertyConfigIndex].alias;
|
||||
var defaultValue = configFieldsetModel.properties[scope.propertyConfigIndex].value;
|
||||
var umbracoPropertyAlias = scope.umbracoPropertyAlias;
|
||||
// initialize container for invalid fieldset property identifiers (store on ngModelCtrl to separate Archetype validations, e.g. when there two Archetype properties on the same document)
|
||||
if(ngModelCtrl.invalidProperties == null) {
|
||||
ngModelCtrl.invalidProperties = [];
|
||||
}
|
||||
|
||||
//try to convert the defaultValue to a JS object
|
||||
defaultValue = jsonOrString(defaultValue, scope.archetypeConfig.developerMode, "defaultValue");
|
||||
|
||||
//grab info for the selected datatype, prepare for view
|
||||
archetypePropertyEditorResource.getDataType(dataTypeId).then(function (data) {
|
||||
archetypePropertyEditorResource.getDataType(dataTypeGuid).then(function (data) {
|
||||
//transform preValues array into object expected by propertyeditor views
|
||||
var configObj = {};
|
||||
_.each(data.preValues, function(p) {
|
||||
@@ -74,44 +79,83 @@ angular.module("umbraco.directives").directive('archetypeProperty', function ($c
|
||||
|
||||
//load in the DefaultPreValues for the PropertyEditor, if any
|
||||
var defaultConfigObj = {};
|
||||
if (propertyEditor.hasOwnProperty('defaultPreValues')) {
|
||||
_.each(propertyEditor.defaultPreValues, function(p) {
|
||||
_.extend(defaultConfigObj, p)
|
||||
});
|
||||
if (propertyEditor.hasOwnProperty('defaultPreValues') && propertyEditor.defaultPreValues != null) {
|
||||
_.extend(defaultConfigObj, propertyEditor.defaultPreValues);
|
||||
}
|
||||
|
||||
var mergedConfig = _.extend(defaultConfigObj, config);
|
||||
|
||||
loadView(pathToView, mergedConfig, defaultValue, alias, scope, element, ngModelCtrl);
|
||||
loadView(pathToView, mergedConfig, defaultValue, alias, umbracoPropertyAlias, scope, element, ngModelCtrl, validateProperty);
|
||||
});
|
||||
});
|
||||
|
||||
ngModelCtrl.$parsers.push(validate);
|
||||
ngModelCtrl.$formatters.push(validate);
|
||||
scope.$on("formSubmitting", function (ev, args) {
|
||||
// "hard" validate to highlight any erroneous entries
|
||||
_.each(scope.fieldset.properties, function (property) {
|
||||
validateProperty(scope.fieldset, property, true);
|
||||
});
|
||||
});
|
||||
|
||||
function validate(renderModel){
|
||||
scope.$on("formSubmitted", function (ev, args) {
|
||||
// reset the nested fieldset validation state after submit
|
||||
ngModelCtrl.invalidProperties = [];
|
||||
});
|
||||
|
||||
// need to pass the property fieldset here to clear any invalid state of the fieldset when validating a single fieldset property
|
||||
// - it's the Umbraco way to hide the invalid state when altering an invalid property, even if the new value isn't valid either
|
||||
function validateProperty(fieldset, property, markAsInvalid) {
|
||||
var valid = true;
|
||||
|
||||
_.each(renderModel, function(fieldset){
|
||||
fieldset.isValid = true;
|
||||
_.each(fieldset.properties, function(property){
|
||||
property.isValid = true;
|
||||
|
||||
var propertyConfig = getPropertyByAlias(configFieldsetModel, property.alias);
|
||||
|
||||
if(propertyConfig && propertyConfig.required && property.value == ""){
|
||||
fieldset.isValid = false;
|
||||
property.isValid = false;
|
||||
fieldset.isValid = true;
|
||||
property.isValid = true;
|
||||
var propertyConfig = getPropertyByAlias(configFieldsetModel, property.alias);
|
||||
if (propertyConfig) {
|
||||
// use property.value !== property.value to check for NaN values on numeric inputs
|
||||
if (propertyConfig.required && (property.value == null || property.value === "" || property.value !== property.value)) {
|
||||
valid = false;
|
||||
}
|
||||
// issue 116: RegEx validate property value
|
||||
// Only validate the property value if anything has been entered - RegEx is considered a supplement to "required".
|
||||
if (valid == true && propertyConfig.regEx && property.value) {
|
||||
var regEx = new RegExp(propertyConfig.regEx);
|
||||
if (regEx.test(property.value) == false) {
|
||||
valid = false;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
// only mark the property as invalid when doing a "hard" validation
|
||||
if (valid == false && markAsInvalid == true) {
|
||||
property.isValid = false;
|
||||
}
|
||||
}
|
||||
|
||||
ngModelCtrl.$setValidity('validation', valid);
|
||||
return renderModel;
|
||||
// handle nested fieldset validation by storing the identifier of all invalid fieldset properties
|
||||
var fieldsetIdentifier = scope.umbracoPropertyAlias + "_" + scope.fieldsetIndex;
|
||||
var propertyIdentifier = fieldsetIdentifier + "_" + property.alias;
|
||||
var propertyIdentifierIndex = ngModelCtrl.invalidProperties.indexOf(propertyIdentifier);
|
||||
if (valid == false) {
|
||||
if (propertyIdentifierIndex == -1) {
|
||||
ngModelCtrl.invalidProperties.push(propertyIdentifier);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (propertyIdentifierIndex != -1) {
|
||||
ngModelCtrl.invalidProperties.splice(propertyIdentifierIndex, 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (markAsInvalid) {
|
||||
// mark the entire fieldset as invalid if there are any invalid properties in the fieldset, otherwise mark it as valid
|
||||
fieldset.isValid =
|
||||
_.find(ngModelCtrl.invalidProperties, function (item) {
|
||||
return item.indexOf(fieldsetIdentifier) == 0
|
||||
}) == null;
|
||||
}
|
||||
|
||||
// set invalid state if one or more fieldsets contain invalid properties
|
||||
ngModelCtrl.$setValidity('validation', ngModelCtrl.invalidProperties.length == 0);
|
||||
}
|
||||
}
|
||||
|
||||
function loadView(view, config, defaultValue, alias, scope, element, ngModelCtrl) {
|
||||
function loadView(view, config, defaultValue, alias, umbracoPropertyAlias, scope, element, ngModelCtrl, validateProperty) {
|
||||
if (view)
|
||||
{
|
||||
$http.get(view).success(function (data) {
|
||||
@@ -122,6 +166,7 @@ angular.module("umbraco.directives").directive('archetypeProperty', function ($c
|
||||
}
|
||||
|
||||
//define the initial model and config
|
||||
scope.form = scope.umbracoForm;
|
||||
scope.model = {};
|
||||
scope.model.config = {};
|
||||
|
||||
@@ -139,18 +184,25 @@ angular.module("umbraco.directives").directive('archetypeProperty', function ($c
|
||||
scope.model.config = config;
|
||||
|
||||
//some items need an alias
|
||||
scope.model.alias = "archetype-property-" + scope.fieldsetIndex + "-" + scope.propertyConfigIndex;
|
||||
scope.model.alias = "archetype-property-" + umbracoPropertyAlias + "-" + scope.fieldsetIndex + "-" + scope.propertyConfigIndex;
|
||||
|
||||
//watch for changes since there is no two-way binding with the local model.value
|
||||
scope.$watch('model.value', function (newValue, oldValue) {
|
||||
scope.archetypeRenderModel.fieldsets[scope.fieldsetIndex].properties[renderModelPropertyIndex].value = newValue;
|
||||
|
||||
//trigger the validation pipeline
|
||||
ngModelCtrl.$setViewValue(ngModelCtrl.$viewValue);
|
||||
// call validation method for the property when the value changes
|
||||
// use "soft" validation to mimic the default umbraco validation style (show error highlights on submit, not while entering data)
|
||||
validateProperty(scope.archetypeRenderModel.fieldsets[scope.fieldsetIndex], scope.archetypeRenderModel.fieldsets[scope.fieldsetIndex].properties[renderModelPropertyIndex], false);
|
||||
});
|
||||
|
||||
element.html(data).show();
|
||||
$compile(element.contents())(scope);
|
||||
|
||||
$timeout(function() {
|
||||
var def = $q.defer();
|
||||
def.resolve(true);
|
||||
$rootScope.$apply();
|
||||
}, 500);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -159,7 +211,7 @@ angular.module("umbraco.directives").directive('archetypeProperty', function ($c
|
||||
return {
|
||||
require: "^ngModel",
|
||||
restrict: "E",
|
||||
rep1ace: true,
|
||||
replace: true,
|
||||
link: linker,
|
||||
scope: {
|
||||
property: '=',
|
||||
@@ -167,7 +219,9 @@ angular.module("umbraco.directives").directive('archetypeProperty', function ($c
|
||||
archetypeConfig: '=',
|
||||
fieldset: '=',
|
||||
fieldsetIndex: '=',
|
||||
archetypeRenderModel: '='
|
||||
archetypeRenderModel: '=',
|
||||
umbracoPropertyAlias: '=',
|
||||
umbracoForm: '='
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -1,15 +0,0 @@
|
||||
angular.module('umbraco.filters').filter("archetypeLocale", function(){
|
||||
return function(key, locales){
|
||||
|
||||
if(!locales)
|
||||
return key;
|
||||
|
||||
if(!locales.defaultLocale)
|
||||
return key;
|
||||
|
||||
if(!locales.locale)
|
||||
return key;
|
||||
|
||||
return locales.locale[key] || locales.defaultLocale[key] || key;
|
||||
}
|
||||
})
|
||||
+31
-30
@@ -1,34 +1,35 @@
|
||||
{
|
||||
"label": "Label",
|
||||
"alias": "Alias",
|
||||
"hideFieldsetControls": "Hide Fieldset Controls?",
|
||||
"hideFieldsetControlsDescription": "Hides the fieldset add/remove/sort controls.",
|
||||
"toggleAdvanced": "Toggle Advanced Options",
|
||||
"toggleAdvancedDescription": "Show advanced options.",
|
||||
"hidePropertyLabels": "Hide Property Labels?",
|
||||
"hidePropertyLabelsDescription": "Hides the property labels.",
|
||||
"maxFieldsets": "Max Fieldsets",
|
||||
"maxFieldsetsDescription": "How many Fieldsets are allowed? Entering '1' will disable the controls. Default is unlimited.",
|
||||
"enableMultipleFieldsets": "Enable Multiple Fieldsets?",
|
||||
"enableMultipleFieldsetsDescription": "Allows multiple types of fieldsets within this archetype.",
|
||||
"hideFieldsetToolbar": "Hide Fieldset Toolbar?",
|
||||
"hideFieldsetToolbarDescription": "Hides the fieldset toolbar that appears when more than one fieldset model appears.",
|
||||
"customWrapperClass": "Custom Wrapper Class",
|
||||
"customWrapperClassDescription": "(Optional) Enter a custom CSS class that will be applied to the wrapper div.",
|
||||
"cssFile": "CSS File",
|
||||
"cssFileDescription": "(Optional) Enter a path for a custom CSS file to be included on the page.",
|
||||
"jsFile": "JS File",
|
||||
"jsFileDescription": "(Optional) Enter a path for a custom JS file to be included on the page.",
|
||||
"toggleDeveloperMode": "Toggle Developer Mode",
|
||||
"toggleDeveloperModeDescription": "Turn on for developer options.",
|
||||
"configModel": "Config Model",
|
||||
"configModelDescription": "Be careful editing the text below, it controls the schema for this archetype.",
|
||||
"helpText": "Help Text",
|
||||
"defaultValue": "Default Value",
|
||||
"dataType": "DataType",
|
||||
"required": "Required",
|
||||
"properties": "Properties",
|
||||
"labelTemplate": "Label Template",
|
||||
"select": "Select",
|
||||
"icon": "Icon"
|
||||
"hideFieldsetControls": "Skjul fieldsets?",
|
||||
"hideFieldsetControlsDescription": "Skjuler kontrollerne tilføj/fjern/sortér.",
|
||||
"toggleAdvanced": "Slå avancerede muligheder til/fra",
|
||||
"toggleAdvancedDescription": "Vis avancerede muligheder.",
|
||||
"hidePropertyLabels": "Skjul labels på egenskaber?",
|
||||
"hidePropertyLabelsDescription": "Skjuler labels på egenskaber.",
|
||||
"maxFieldsets": "Maks antal fieldsets",
|
||||
"maxFieldsetsDescription": "Hvor mange fieldsets er tilladt? Hvis der skrives '1' vil deaktivere kontrollerne. Som standard er det ubegrænset.",
|
||||
"enableMultipleFieldsets": "Aktivér flere Fieldsets?",
|
||||
"enableMultipleFieldsetsDescription": "Tillader flere typer af fieldsets i denne archetype.",
|
||||
"hideFieldsetToolbar": "Skjul Fieldset værktøjslinie?",
|
||||
"hideFieldsetToolbarDescription": "Skjuler den fieldset værktøjslinie der fremkommer når der findes mere end ét fieldset.",
|
||||
"customWrapperClass": "Egen Wrapper Class",
|
||||
"customWrapperClassDescription": "(Mulighed) Angiv din egen CSS class som tilføjes på wrapper div'en.",
|
||||
"cssFile": "CSS fil",
|
||||
"cssFileDescription": "(Mulighed) Tilføj en sti til din egen CSS fil der skal inkluderes på siden.",
|
||||
"jsFile": "JavaScript fil",
|
||||
"jsFileDescription": "(Mulighed) Tilføj en sti til din egen JavaScript fil der skal inkluderes på siden.",
|
||||
"toggleDeveloperMode": "Slå udvikler muligheder til/fra.",
|
||||
"toggleDeveloperModeDescription": "Aktivér på udvikler muligheder.",
|
||||
"configModel": "Konfigurationsmodel",
|
||||
"configModelDescription": "Vær forsigt med at redigere teksten for neden, den kontrollerer skemaet for denne archetype.",
|
||||
"helpText": "Hjælpe tekst",
|
||||
"defaultValue": "Standard værdi",
|
||||
"dataType": "Datatype",
|
||||
"required": "Påkrævet",
|
||||
"regEx": "RegEx validering",
|
||||
"properties": "Egenskaber",
|
||||
"labelTemplate": "Label skabelon",
|
||||
"select": "Vælg",
|
||||
"icon": "Ikon"
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
"defaultValue": "Default Value",
|
||||
"dataType": "DataType",
|
||||
"required": "Required",
|
||||
"regEx": "RegEx Validation",
|
||||
"properties": "Properties",
|
||||
"labelTemplate": "Label Template",
|
||||
"select": "Select",
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
"defaultValue": "Default Value",
|
||||
"dataType": "DataType",
|
||||
"required": "Required",
|
||||
"regEx": "RegEx Validation",
|
||||
"properties": "Properties",
|
||||
"labelTemplate": "Label Template",
|
||||
"select": "Select",
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
"defaultValue": "Default Value",
|
||||
"dataType": "DataType",
|
||||
"required": "Required",
|
||||
"regEx": "RegEx Validation",
|
||||
"properties": "Properties",
|
||||
"labelTemplate": "Label Template",
|
||||
"select": "Select",
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
"defaultValue": "Default Value",
|
||||
"dataType": "DataType",
|
||||
"required": "Required",
|
||||
"regEx": "RegEx Validation",
|
||||
"properties": "Properties",
|
||||
"labelTemplate": "Label Template",
|
||||
"select": "Select",
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
"defaultValue": "Default Value",
|
||||
"dataType": "DataType",
|
||||
"required": "Required",
|
||||
"regEx": "RegEx Validation",
|
||||
"properties": "Properties",
|
||||
"labelTemplate": "Label Template",
|
||||
"select": "Select",
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
"defaultValue": "Default Value",
|
||||
"dataType": "DataType",
|
||||
"required": "Required",
|
||||
"regEx": "RegEx Validation",
|
||||
"properties": "Properties",
|
||||
"labelTemplate": "Label Template",
|
||||
"select": "Select",
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
"defaultValue": "Default Value",
|
||||
"dataType": "DataType",
|
||||
"required": "Required",
|
||||
"regEx": "RegEx Validation",
|
||||
"properties": "Properties",
|
||||
"labelTemplate": "Label Template",
|
||||
"select": "Select",
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
"defaultValue": "Default Value",
|
||||
"dataType": "DataType",
|
||||
"required": "Required",
|
||||
"regEx": "RegEx Validation",
|
||||
"properties": "Properties",
|
||||
"labelTemplate": "Label Template",
|
||||
"select": "Select",
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
"defaultValue": "Default Value",
|
||||
"dataType": "DataType",
|
||||
"required": "Required",
|
||||
"regEx": "RegEx Validation",
|
||||
"properties": "Properties",
|
||||
"labelTemplate": "Label Template",
|
||||
"select": "Select",
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
"defaultValue": "Default Value",
|
||||
"dataType": "DataType",
|
||||
"required": "Required",
|
||||
"regEx": "RegEx Validation",
|
||||
"properties": "Properties",
|
||||
"labelTemplate": "Label Template",
|
||||
"select": "Select",
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
"defaultValue": "Default Value",
|
||||
"dataType": "DataType",
|
||||
"required": "Required",
|
||||
"regEx": "RegEx Validation",
|
||||
"properties": "Properties",
|
||||
"labelTemplate": "Label Template",
|
||||
"select": "Select",
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
"defaultValue": "Default Value",
|
||||
"dataType": "DataType",
|
||||
"required": "Required",
|
||||
"regEx": "RegEx Validation",
|
||||
"properties": "Properties",
|
||||
"labelTemplate": "Label Template",
|
||||
"select": "Select",
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
"defaultValue": "Default Value",
|
||||
"dataType": "DataType",
|
||||
"required": "Required",
|
||||
"regEx": "RegEx Validation",
|
||||
"properties": "Properties",
|
||||
"labelTemplate": "Label Template",
|
||||
"select": "Select",
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
"defaultValue": "Default Value",
|
||||
"dataType": "DataType",
|
||||
"required": "Required",
|
||||
"regEx": "RegEx Validation",
|
||||
"properties": "Properties",
|
||||
"labelTemplate": "Label Template",
|
||||
"select": "Select",
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
"defaultValue": "Default Value",
|
||||
"dataType": "DataType",
|
||||
"required": "Required",
|
||||
"regEx": "RegEx Validation",
|
||||
"properties": "Properties",
|
||||
"labelTemplate": "Label Template",
|
||||
"select": "Select",
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
"defaultValue": "Default Value",
|
||||
"dataType": "DataType",
|
||||
"required": "Required",
|
||||
"regEx": "RegEx Validation",
|
||||
"properties": "Properties",
|
||||
"labelTemplate": "Label Template",
|
||||
"select": "Select",
|
||||
|
||||
+69
-14
@@ -1,5 +1,9 @@
|
||||
.archetypeEditor {
|
||||
width: 98%;
|
||||
|
||||
.dropdown-menu {
|
||||
top: auto;
|
||||
}
|
||||
}
|
||||
|
||||
.archetypeEditor fieldset{
|
||||
@@ -13,25 +17,51 @@
|
||||
}
|
||||
|
||||
.archetypeEditor .archetypeFieldsetLabel {
|
||||
padding: 8px 25px 8px 3px;
|
||||
float: left;
|
||||
width: 98%;
|
||||
position: relative;
|
||||
width: 100%%;
|
||||
|
||||
.label-sub {
|
||||
padding: 8px 0;
|
||||
display: inline-block;
|
||||
&.module-label {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.dropdown-menu {
|
||||
padding: 0;
|
||||
border-radius: 0;
|
||||
box-shadow: none;
|
||||
margin-top: -10px;
|
||||
margin-left: -200px;
|
||||
}
|
||||
|
||||
span {
|
||||
font-weight: bold;
|
||||
|
||||
&.menu-label { font-weight: normal; }
|
||||
}
|
||||
|
||||
&:hover {
|
||||
label:hover {
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
&.enableCollapsing:hover {
|
||||
cursor: pointer;
|
||||
|
||||
label span {
|
||||
text-decoration: underline;
|
||||
label {
|
||||
span {
|
||||
text-decoration: underline;
|
||||
}
|
||||
&:hover {
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.caret {
|
||||
float:left;
|
||||
margin: 8px 1px 0 7px;
|
||||
margin: 8px 1px 0 15px;
|
||||
|
||||
&.caret-right {
|
||||
border-bottom: 4px solid transparent;
|
||||
border-top: 4px solid transparent;
|
||||
@@ -42,8 +72,6 @@
|
||||
}
|
||||
|
||||
label{
|
||||
float: left;
|
||||
width: 80%;
|
||||
margin-bottom: 0;
|
||||
margin-left: 5px;
|
||||
padding: 0;
|
||||
@@ -56,7 +84,6 @@
|
||||
.archetypeEditor .archetypeCollapser{
|
||||
clear: both;
|
||||
height: 100%;
|
||||
margin-top: 10px;
|
||||
padding-top: 12px;
|
||||
background-color: #fff;
|
||||
border-top: 1px solid silver;
|
||||
@@ -72,9 +99,11 @@
|
||||
margin-left: 0;
|
||||
}
|
||||
|
||||
.archetypeEditor, .archetypeConfig{
|
||||
.archetypeEditorControls{
|
||||
.archetypeEditor,
|
||||
.archetypeConfig {
|
||||
.archetypeEditorControls {
|
||||
float: right;
|
||||
|
||||
i {
|
||||
cursor: pointer;
|
||||
&.handle {
|
||||
@@ -84,6 +113,17 @@
|
||||
}
|
||||
}
|
||||
|
||||
.archetypeEditor .archetypeEditorControls {
|
||||
float: none;
|
||||
position: absolute;
|
||||
right: 15px;
|
||||
top: 0;
|
||||
}
|
||||
|
||||
.archetypeConfig .archetypeEditorControls {
|
||||
float: right;
|
||||
}
|
||||
|
||||
.archetypeEditor form {
|
||||
margin-left:20px;
|
||||
|
||||
@@ -250,6 +290,13 @@
|
||||
border: 1px solid #b94a48;
|
||||
}
|
||||
|
||||
.archetypeEditor .archetypeProperty {
|
||||
label {
|
||||
span {
|
||||
color: #343434;
|
||||
}
|
||||
}
|
||||
}
|
||||
.archetypeEditor .archetypePropertyError{
|
||||
margin-bottom: 5px;
|
||||
padding-top: 3px;
|
||||
@@ -264,6 +311,14 @@
|
||||
}
|
||||
}
|
||||
|
||||
.archetypeEditor .archetypeAddButton:hover {
|
||||
text-decoration: none;
|
||||
|
||||
.archetypeAddButtonText {
|
||||
text-decoration: underline;
|
||||
}
|
||||
}
|
||||
|
||||
.ui-sortable-placeholder {
|
||||
visibility: visible !important;
|
||||
background-color: #d0e7f1 !important;
|
||||
@@ -281,4 +336,4 @@
|
||||
span {
|
||||
color: #343434;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
{
|
||||
propertyEditors: [
|
||||
{
|
||||
alias: "Imulus.Archetype",
|
||||
name: "Archetype",
|
||||
editor: {
|
||||
view: "~/App_Plugins/Archetype/views/archetype.html",
|
||||
valueType: "JSON"
|
||||
},
|
||||
prevalues: {
|
||||
fields: [
|
||||
{
|
||||
label: "Config",
|
||||
description: "(Required) Describe your Archetype.",
|
||||
key: "archetypeConfig",
|
||||
view: "/App_Plugins/Archetype/views/archetype.config.html",
|
||||
validation: [
|
||||
{
|
||||
type: "Required"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
javascript: [
|
||||
'~/App_Plugins/Archetype/js/archetype.js'
|
||||
]
|
||||
}
|
||||
@@ -3,24 +3,20 @@ angular.module('umbraco.resources').factory('archetypePropertyEditorResource', f
|
||||
getAllDataTypes: function() {
|
||||
// Hack - grab DataTypes from Tree API, as `dataTypeService.getAll()` isn't implemented yet
|
||||
return umbRequestHelper.resourcePromise(
|
||||
$http.get("/umbraco/backoffice/UmbracoTrees/DataTypeTree/GetNodes?id=-1&application=developer&tree=&isDialog=false"), 'Failed to retrieve datatypes from tree service'
|
||||
).then(function (data) {
|
||||
return data.map(function(d) {
|
||||
return { "id": d.id, "name": d.name }
|
||||
});
|
||||
});
|
||||
$http.get("/umbraco/backoffice/ArchetypeApi/ArchetypeDataType/GetAll"), 'Failed to retrieve datatypes from tree service'
|
||||
);
|
||||
},
|
||||
getDataType: function(id) {
|
||||
getDataType: function(guid) {
|
||||
return umbRequestHelper.resourcePromise(
|
||||
$http.get("/umbraco/backoffice/UmbracoApi/DataType/GetById?id=" + id), 'Failed to retrieve datatype'
|
||||
$http.get("/umbraco/backoffice/ArchetypeApi/ArchetypeDataType/GetByGuid?guid=" + guid), 'Failed to retrieve datatype'
|
||||
);
|
||||
},
|
||||
getPropertyEditorMapping: function(alias) {
|
||||
return umbRequestHelper.resourcePromise(
|
||||
$http.get("/App_plugins/Archetype/js/propertyEditors.views.js"), 'Failed to retrieve datatype mappings'
|
||||
$http.get("/umbraco/backoffice/ArchetypeApi/ArchetypeDataType/GetAllPropertyEditors"), 'Failed to retrieve datatype mappings'
|
||||
).then(function (data) {
|
||||
var result = _.find(data, function(d) {
|
||||
return d.propertyEditorAlias === alias;
|
||||
return d.alias === alias;
|
||||
});
|
||||
|
||||
if (result != null)
|
||||
|
||||
@@ -11,11 +11,11 @@
|
||||
<div class="archetypeFieldsetCollapser" ng-hide="fieldset.collapse && fieldset.label">
|
||||
<div class="archetypeFieldsetOption">
|
||||
<label for="archetypeFieldLabel_{{$index}}"><archetype-localize key="label">Label</archetype-localize></label>
|
||||
<input type="text" id="archetypeFieldLabel_{{$index}}" ng-model="fieldset.label" />
|
||||
<input type="text" id="archetypeFieldLabel_{{$index}}" ng-model="fieldset.label" on-keyup="autoPopulateAlias(this)" />
|
||||
</div>
|
||||
<div class="archetypeFieldsetOption">
|
||||
<label for="archetypeFieldAlias_{{$index}}"><archetype-localize key="alias">Alias</archetype-localize></label>
|
||||
<input type="text" id="archetypeFieldAlias_{{$index}}" ng-model="fieldset.alias" required/>
|
||||
<input type="text" id="archetypeFieldAlias_{{$index}}" ng-model="fieldset.alias" on-keyup="markAliasDirty(this)" required/>
|
||||
</div>
|
||||
<div class="archetypeFieldsetOption">
|
||||
<label for="archetypeFieldLabelTemplate_{{$index}}"><archetype-localize key="labelTemplate">Label Template</archetype-localize></label>
|
||||
@@ -27,7 +27,7 @@
|
||||
</div>
|
||||
<div class="archetypeFieldsetOption">
|
||||
<label><archetype-localize key="properties">Properties</archetype-localize></label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="archetypePropertiesWrapper">
|
||||
<ul ui-sortable="sortableOptions" ng-model="fieldset.properties">
|
||||
<li ng-repeat="property in fieldset.properties" ng-hide="property.remove">
|
||||
@@ -37,16 +37,16 @@
|
||||
<i class="icon icon-navigation handle" ng-show="canSortProperty(fieldset)"></i>
|
||||
</div>
|
||||
<div class="archetypePropertyTitle" ng-click="focusProperty(fieldset.properties, property)">
|
||||
{{property.label}} ({{property.alias}}) - <span>{{getDataTypeNameById(property.dataTypeId)}}</span>
|
||||
{{property.label}} ({{property.alias}}) - <span>{{getDataTypeNameByGuid(property.dataTypeGuid)}}</span>
|
||||
</div>
|
||||
<div class="archetypePropertyCollapser" ng-hide="property.collapse && property.label">
|
||||
<div>
|
||||
<label for="archetypePropertyLabel_{{$parent.$index}}_{{$index}}"><archetype-localize key="label">Label</archetype-localize></label>
|
||||
<input type="text" id="archetypePropertyLabel_{{$parent.$index}}_{{$index}}" ng-model="property.label" />
|
||||
<input type="text" id="archetypePropertyLabel_{{$parent.$index}}_{{$index}}" ng-model="property.label" on-keyup="autoPopulateAlias(this)"/>
|
||||
</div>
|
||||
<div>
|
||||
<label for="archetypePropertyAlias_{{$parent.$index}}_{{$index}}"><archetype-localize key="alias">Alias</archetype-localize></label>
|
||||
<input type="text" id="archetypePropertyAlias_{{$parent.$index}}_{{$index}}" ng-model="property.alias" required/>
|
||||
<input type="text" id="archetypePropertyAlias_{{$parent.$index}}_{{$index}}" ng-model="property.alias" on-keyup="markAliasDirty(this)" required/>
|
||||
</div>
|
||||
<div>
|
||||
<label for="archetypePropertyHelpText_{{$parent.$index}}_{{$index}}"><archetype-localize key="helpText">Help Text</archetype-localize></label>
|
||||
@@ -54,7 +54,7 @@
|
||||
</div>
|
||||
<div>
|
||||
<label for="archetypePropertyDataType_{{$parent.$index}}_{{$index}}"><archetype-localize key="dataType">Datatype</archetype-localize></label>
|
||||
<select id="archetypePropertyDataType_{{$parent.$index}}_{{$index}}" ng-model="property.dataTypeId" ng-options="datatype.id as datatype.name for datatype in availableDataTypes"></select>
|
||||
<select id="archetypePropertyDataType_{{$parent.$index}}_{{$index}}" ng-model="property.dataTypeGuid" ng-options="datatype.guid as datatype.name for datatype in availableDataTypes | orderBy:'name'"></select>
|
||||
</div>
|
||||
<div>
|
||||
<label for="archetypePropertyDefaultValue_{{$parent.$index}}_{{$index}}"><archetype-localize key="defaultValue">Default Value</archetype-localize></label>
|
||||
@@ -64,6 +64,10 @@
|
||||
<label for="archetypePropertyRequired_{{$parent.$index}}_{{$index}}"><archetype-localize key="required">Required</archetype-localize></label>
|
||||
<input type="checkbox" id="archetypePropertyRequired_{{$parent.$index}}_{{$index}}" ng-model="property.required" />
|
||||
</div>
|
||||
<div>
|
||||
<label for="archetypePropertyRegEx_{{$parent.$index}}_{{$index}}"><archetype-localize key="regEx">RegEx Validation</archetype-localize></label>
|
||||
<input type="text" id="archetypePropertyRegExValue_{{$parent.$index}}_{{$index}}" ng-model="property.regEx" />
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
@@ -81,6 +85,10 @@
|
||||
</div>
|
||||
|
||||
<div class="archetypeAdvancedOptions" ng-show="archetypeConfigRenderModel.showAdvancedOptions">
|
||||
<div>
|
||||
<label for="archetypeAdvancedOptionsStartWithAddButton"><archetype-localize key="startWithAddButton">Start With Add Button?</archetype-localize><small><archetype-localize key="startWithAddButtonDescription">Empty property shows an add button instead of providing a default fieldset.</archetype-localize></small></label>
|
||||
<input type="checkbox" id="archetypeAdvancedOptionsStartWithAddButton" ng-model="archetypeConfigRenderModel.startWithAddButton"/>
|
||||
</div>
|
||||
<div>
|
||||
<label for="archetypeAdvancedOptionsHideControls"><archetype-localize key="hideFieldsetControls">Hide Fieldset Controls?</archetype-localize><small><archetype-localize key="hideFieldsetControlsDescription">Hides the fieldset add/remove/sort controls.</archetype-localize></small></label>
|
||||
<input type="checkbox" id="archetypeAdvancedOptionsHideControls" ng-model="archetypeConfigRenderModel.hideFieldsetControls"/>
|
||||
@@ -96,7 +104,11 @@
|
||||
<div>
|
||||
<label for="archetypeAdvancedOptionsMultipleFieldsets"><archetype-localize key="enableMultipleFieldsets">Enable Multiple Fieldsets?</archetype-localize><small><archetype-localize key="enableMultipleFieldsetsDescription">Allows multiple types of fieldsets within this archetype.</archetype-localize></small></label>
|
||||
<input type="checkbox" id="archetypeAdvancedOptionsMultipleFieldsets" ng-model="archetypeConfigRenderModel.enableMultipleFieldsets"/>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<label for="archetypeAdvancedOptionsCollapsing"><archetype-localize key="enableCollapsing">Enable Collapsing?</archetype-localize><small><archetype-localize key="enableCollapsingDescription">Allows multiple types of fieldsets within this archetype.</archetype-localize></small></label>
|
||||
<input type="checkbox" id="archetypeAdvancedOptionsCollapsing" ng-model="archetypeConfigRenderModel.enableCollapsing"/>
|
||||
</div>
|
||||
<div>
|
||||
<label for="archetypeAdvancedOptionsFieldsetToolbar"><archetype-localize key="hideFieldsetToolbar">Hide Fieldset Toolbar?</archetype-localize><small><archetype-localize key="hideFieldsetToolbarDescription">Hides the fieldset toolbar that appears when more than one fieldset model appears.</archetype-localize></small></label>
|
||||
<input type="checkbox" id="archetypeAdvancedOptionsFieldsetToolbar" ng-model="archetypeConfigRenderModel.hideFieldsetToolbar"/>
|
||||
@@ -113,6 +125,10 @@
|
||||
<label for="archetypeAdvancedOptionsCustomJs"><archetype-localize key="jsFile">JS File</archetype-localize><small><archetype-localize key="jsFileDescription">(Optional) Enter a path for a custom JS file to be included on the page.</archetype-localize></small></label>
|
||||
<input type="text" id="archetypeAdvancedOptionsCustomJs" ng-model="archetypeConfigRenderModel.customJsPath"/>
|
||||
</div>
|
||||
<div>
|
||||
<label for="archetypeAdvancedOptionsCustomView"><archetype-localize key="viewFile">View File</archetype-localize><small><archetype-localize key="viewFileDescription">(Optional) Enter a path for a custom view file to be used to render this Archetype.</archetype-localize></small></label>
|
||||
<input type="text" id="archetypeAdvancedOptionsCustomView" ng-model="archetypeConfigRenderModel.customViewPath"/>
|
||||
</div>
|
||||
<div>
|
||||
<label for="archetypeAdvancedOptionsDeveloperMode"><archetype-localize key="toggleDeveloperMode">Toggle Developer Mode</archetype-localize><small><archetype-localize key="toggleDeveloperModeDescription">Toggle Developer Mode</archetype-localize></small></label>
|
||||
<input type="checkbox" id="archetypeAdvancedOptionsDeveloperMode" ng-model="archetypeConfigRenderModel.developerMode"/>
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
<div class="archetypeEditor ng-class:model.config.customCssClass" ng-controller="Imulus.ArchetypeController">
|
||||
<textarea class="archetypeDeveloperModel" ng-show="model.config.developerMode" ng-model="model.value"></textarea>
|
||||
<ul ui-sortable="sortableOptions" ng-model="model.value.fieldsets" ng-show="!showAddButton()">
|
||||
<li ng-repeat="fieldset in model.value.fieldsets">
|
||||
<fieldset ng-class="[fieldset.alias, (!fieldset.isValid ? 'archetypeFieldsetError' : '')]" ng-init="fieldsetConfigModel = getConfigFieldsetByAlias(fieldset.alias)">
|
||||
<div class="archetypeFieldsetLabel" ng-class="{enableCollapsing: model.config.enableCollapsing}">
|
||||
<div ng-click="focusFieldset(fieldset)" class="label-sub module-label">
|
||||
<span class="caret" ng-hide="fieldset.collapse || !model.config.enableCollapsing"></span>
|
||||
<span class="caret caret-right" ng-show="fieldset.collapse && model.config.enableCollapsing"></span>
|
||||
<label>
|
||||
<i class="fieldsetIcon icon ng-class:fieldsetConfigModel.icon"></i>
|
||||
<span ng-bind="getFieldsetTitle(fieldsetConfigModel, $index)"></span>
|
||||
</label>
|
||||
</div>
|
||||
<div class="archetypeEditorControls label-sub" ng-hide="model.config.hideFieldsetControls">
|
||||
<i class="icon icon-add dropdown-toggle" ng-show="canAdd()" data-toggle="{{ model.config.fieldsets.length > 1 ? 'dropdown' : ''}}" ng-click="model.config.fieldsets.length == 1 ? addRow(fieldset.alias, $index) : return"></i>
|
||||
<ul class="dropdown-menu umb-actions">
|
||||
<li ng-repeat="fieldsetModel in model.config.fieldsets" ng-click="addRow(fieldsetModel.alias, $parent.$index)">
|
||||
<a>
|
||||
<i class="fieldsetIcon icon ng-class:fieldsetModel.icon"></i>
|
||||
<span class="menu-label">{{fieldsetModel.label}}</span>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
<i class="icon icon-remove" ng-click="removeRow($index)" ng-show="canRemove()"></i>
|
||||
<i class="icon icon-navigation handle" ng-show="canSort()"></i>
|
||||
</div>
|
||||
</div>
|
||||
<div class="archetypeCollapser animate-hide" ng-hide="isCollapsed(fieldset)">
|
||||
<form class="form-inline">
|
||||
<div ng-class="[property.alias, (getPropertyValidity($parent.$index, property.alias) === false ? 'archetypePropertyError' : '')]" class="archetypeProperty control-group" ng-repeat="property in fieldsetConfigModel.properties">
|
||||
<label ng-hide="archetypeConfig.hidePropertyLabels == '1'" class="control-label" for="archetype-property-{{model.alias}}-{{$parent.$index}}-{{$index}}">
|
||||
<span>{{property.label}}</span>
|
||||
<div class="archetypeFieldsetHelpText" ng-show="property.helpText">
|
||||
<small>{{property.helpText}}</small>
|
||||
</div>
|
||||
</label>
|
||||
|
||||
<div class="controls">
|
||||
<archetype-property class="archetypeEditor" property="property" fieldset-index="$parent.$index" fieldset="fieldset" archetype-config="model.config" property-config-index="$index" archetype-render-model="model.value" umbraco-property-alias="model.alias" umbraco-form = "form"></archetype-property>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</fieldset>
|
||||
</li>
|
||||
</ul>
|
||||
<div ng-show="showAddButton()">
|
||||
<a data-toggle="{{ model.config.fieldsets.length > 1 ? 'dropdown' : ''}}" ng-click="model.config.fieldsets.length == 1 ? addRow(model.config.fieldsets[0].alias, 0) : return" prevent-default>
|
||||
<i class="icon icon-add dropdown-toggle"></i>
|
||||
<localize key="general_add" class="archetypeAddButtonText">Add</localize>
|
||||
</a>
|
||||
<ul class="dropdown-menu umb-actions">
|
||||
<li ng-repeat="fieldsetModel in model.config.fieldsets" ng-click="addRow(fieldsetModel.alias, 0)">
|
||||
<a>
|
||||
<i class="fieldsetIcon icon ng-class:fieldsetModel.icon"></i>
|
||||
<span class="menu-label">{{fieldsetModel.label}}</span>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1,49 +1 @@
|
||||
<div class="archetypeEditor ng-class:model.config.customCssClass" ng-controller="Imulus.ArchetypeController">
|
||||
<textarea class="archetypeDeveloperModel" ng-show="model.config.developerMode" ng-model="archetypeRenderModel"></textarea>
|
||||
<div class="archetypeFieldsetToolbar" ng-show="model.config.fieldsets.length > 1 && model.config.hideFieldsetToolbar != '1'">
|
||||
<ul>
|
||||
<li ng-repeat="fieldsetModel in model.config.fieldsets" ng-click="addRow(fieldsetModel.alias)">
|
||||
<i class="fieldsetIcon icon ng-class:fieldsetModel.icon"></i>
|
||||
<span>{{fieldsetModel.label}}</span>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<ul ui-sortable="sortableOptions" ng-model="archetypeRenderModel.fieldsets">
|
||||
<li ng-repeat="fieldset in archetypeRenderModel.fieldsets" ng-hide="fieldset.remove">
|
||||
<fieldset ng-class="{archetypeFieldsetError: !fieldset.isValid}" ng-init="fieldsetConfigModel = getConfigFieldsetByAlias(fieldset.alias)">
|
||||
<div class="archetypeFieldsetLabel">
|
||||
<span class="caret" ng-hide="fieldset.collapse"></span>
|
||||
<span class="caret caret-right" ng-show="fieldset.collapse"></span>
|
||||
|
||||
<label ng-click="focusFieldset(fieldset)">
|
||||
<i class="fieldsetIcon icon ng-class:fieldsetConfigModel.icon"></i>
|
||||
<span ng-bind="getFieldsetTitle(fieldsetConfigModel, $index)"></span>
|
||||
</label>
|
||||
|
||||
<div class="archetypeEditorControls" ng-hide="model.config.hideFieldsetControls || model.config.maxFieldsets == '1'">
|
||||
<i class="icon icon-add" ng-click="addRow(fieldset.alias, $index)" ng-show="canAdd()"></i>
|
||||
<i class="icon icon-delete" ng-click="removeRow($index)" ng-show="canRemove()"></i>
|
||||
<i class="icon icon-navigation handle" ng-show="canSort()"></i>
|
||||
</div>
|
||||
</div>
|
||||
<div class="archetypeCollapser animate-hide" ng-hide="fieldset.collapse">
|
||||
<form class="form-inline">
|
||||
<div ng-class="{archetypePropertyError: getPropertyValidity($parent.$index, property.alias) === false}" class="archetypeProperty control-group" ng-repeat="property in fieldsetConfigModel.properties">
|
||||
<label ng-hide="archetypeConfig.hidePropertyLabels == '1'" class="control-label" for="archetype-property-{{$parent.$index}}-{{$index}}">
|
||||
<span>{{property.label}}</span>
|
||||
<div class="archetypeFieldsetHelpText" ng-show="property.helpText">
|
||||
<em>{{property.helpText}}</em>
|
||||
</div>
|
||||
</label>
|
||||
|
||||
<div class="controls">
|
||||
<archetype-property class="archetypeEditor ng-class:property.alias" property="property" fieldset-index="$parent.$index" fieldset="fieldset" archetype-config="model.config" property-config-index="$index" archetype-render-model="archetypeRenderModel"></archetype-property>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</fieldset>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div archetype-custom-view archetype="model"></div>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "Archetype",
|
||||
"version": "0.4.0-alpha",
|
||||
"version": "1.2-beta",
|
||||
"url": "http://github.com/imulus/archetype/",
|
||||
"author": "Imulus",
|
||||
"authorUrl": "http://imulus.com/",
|
||||
@@ -12,9 +12,4 @@
|
||||
<iconUrl>http://github.com/imulus/archetype/raw/master/assets/logo.png</iconUrl>
|
||||
<licenseUrl><%= licenseUrl %></licenseUrl>
|
||||
</metadata>
|
||||
<files>
|
||||
<% files.forEach(function(file) { %>
|
||||
<file src="<%- file.path %>" target="<%= file.target %>" />
|
||||
<% }); %>
|
||||
</files>
|
||||
</package>
|
||||
+8
-3
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "archetype",
|
||||
"version": "0.0.0",
|
||||
"devDependencies": {
|
||||
"dependencies": {
|
||||
"grunt": "~0.4.2",
|
||||
"bower": "~1.2.8",
|
||||
"grunt-contrib-copy": "~0.5.0",
|
||||
@@ -18,12 +18,17 @@
|
||||
"rimraf": "~2.2.5",
|
||||
"grunt-nuget": "~0.1.1",
|
||||
"grunt-template": "~0.2.2",
|
||||
"grunt-touch": "~0.1.0",
|
||||
"fs-extra": "~0.8.1",
|
||||
"grunt-msbuild": "~0.1.9"
|
||||
"grunt-msbuild": "~0.1.9",
|
||||
"grunt-dotnet-assembly-info": "~1.0.9",
|
||||
"load-grunt-tasks": "~0.4.0",
|
||||
"grunt-umbraco-package": "0.0.5"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/imulus/Archetype.git"
|
||||
},
|
||||
"devDependencies": {
|
||||
"grunt-msbuild": "^0.1.12"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
module.exports = function(grunt) {
|
||||
grunt.registerTask('umbracoPackage', 'Create Umbraco Package', function() {
|
||||
grunt.config.requires('umbracoPackage.options.name');
|
||||
grunt.config.requires('umbracoPackage.options.version');
|
||||
grunt.config.requires('umbracoPackage.options.license');
|
||||
grunt.config.requires('umbracoPackage.options.licenseUrl');
|
||||
grunt.config.requires('umbracoPackage.options.url');
|
||||
grunt.config.requires('umbracoPackage.options.author');
|
||||
grunt.config.requires('umbracoPackage.options.authorUrl');
|
||||
grunt.config.requires('umbracoPackage.options.manifest');
|
||||
grunt.config.requires('umbracoPackage.options.readme');
|
||||
grunt.config.requires('umbracoPackage.options.outputDir');
|
||||
grunt.config.requires('umbracoPackage.options.sourceDir');
|
||||
|
||||
var Guid = require('guid');
|
||||
var path = require('path');
|
||||
var rimraf = require('rimraf');
|
||||
var AdmZip = require('adm-zip');
|
||||
var fs = require('fs-extra');
|
||||
|
||||
var options = this.options({
|
||||
minimumUmbracoVersion: '',
|
||||
files: [],
|
||||
cwd: '/'
|
||||
});
|
||||
|
||||
var packageFileName = options.name + "_" + options.version + ".zip"
|
||||
|
||||
// Gather files
|
||||
var filesToPackage = [];
|
||||
getFilesRecursive(options.sourceDir);
|
||||
filesToPackage = filesToPackage.map(function(f) {
|
||||
return { guid: Guid.create(), dir: f.dir.replace(options.sourceDir, ''), name: f.name, ext: f.name.split('.').pop() };
|
||||
});
|
||||
|
||||
// Create temp folder for package zip source
|
||||
var guidFolder = Guid.create().toString();
|
||||
var newDirName = path.join(options.sourceDir, "..\\" + guidFolder);
|
||||
fs.mkdirSync(newDirName);
|
||||
newDirName = path.join(newDirName, guidFolder);
|
||||
fs.mkdirSync(newDirName);
|
||||
|
||||
// Copy flatten structure, with files renamed as <guid>.<ext>
|
||||
filesToPackage.forEach(function(f) {
|
||||
var newFileName = f.name == "package.xml" ? f.name : f.guid.toString() + '.' + f.ext;
|
||||
fs.copySync(path.join(options.sourceDir, f.dir, f.name), path.join(newDirName, newFileName));
|
||||
});
|
||||
|
||||
// Load / transform XML Manifest
|
||||
options.files = filesToPackage;
|
||||
options.readmeContents = grunt.file.read(options.readme);
|
||||
var manifest = grunt.file.read(options.manifest);
|
||||
manifest = grunt.template.process(manifest, {data: options});
|
||||
grunt.file.write(path.join(options.sourceDir, "..\\", guidFolder, guidFolder, "package.xml"), manifest); // TODO: Probably shouldn't use sourceDir - what if under source control
|
||||
|
||||
// Zip
|
||||
var zip = new AdmZip();
|
||||
zip.addLocalFolder(path.join(options.sourceDir, "..\\", guidFolder));
|
||||
zip.writeZip(path.join(options.outputDir, packageFileName))
|
||||
|
||||
function getFilesRecursive(dir) {
|
||||
var files = fs.readdirSync(dir);
|
||||
for (var i in files) {
|
||||
if (!files.hasOwnProperty(i)) continue;
|
||||
|
||||
var name = dir+'/'+files[i];
|
||||
if (fs.statSync(name).isDirectory()) {
|
||||
getFilesRecursive(name);
|
||||
} else {
|
||||
filesToPackage.push({ dir: dir, name: files[i]});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user