Skip to content
This repository has been archived by the owner on Mar 7, 2019. It is now read-only.

Commit

Permalink
Merge pull request #431 from kgiszewski/feature/letstryagain
Browse files Browse the repository at this point in the history
Feature/letstryagain
  • Loading branch information
kgiszewski authored Sep 20, 2017
2 parents 5e3e37a + 46b0396 commit 3a2190b
Show file tree
Hide file tree
Showing 10 changed files with 339 additions and 313 deletions.
1 change: 1 addition & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,4 +322,5 @@ module.exports = function(grunt) {
grunt.registerTask('nuget', ['copy:nuget', 'template:nuspec', 'template:nuspec_binaries', 'template:nuspec_courier', 'nugetpack']);
grunt.registerTask('umbraco', ['copy:umbraco', 'umbracoPackage']);
grunt.registerTask('package', ['clean:tmp', 'default', 'nuget', 'copy:umbraco', 'umbracoPackage', 'clean:tmp']);
grunt.registerTask('assets', ['clean', 'string-replace', 'less', 'concat', 'assemblyinfo', 'copy:assets', 'copy:html', 'copy:config', 'clean:html', 'clean:js', 'clean:less']);
};
20 changes: 20 additions & 0 deletions app/Umbraco/Umbraco.Archetype/Api/ArchetypeDataTypeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,26 @@ public object GetAll()
return dataTypes.Select(t => new { guid = t.Key, name = t.Name });
}

/// <summary>
/// Gets all details.
/// </summary>
/// <returns>System.Object.</returns>
public object GetAllDetails()
{
var dataTypes = Services.DataTypeService.GetAllDataTypeDefinitions();

var list = new List<object>();

foreach (var dataType in dataTypes)
{
var dataTypeDisplay = Mapper.Map<IDataTypeDefinition, DataTypeDisplay>(dataType);

list.Add(new { selectedEditor = dataTypeDisplay.SelectedEditor, preValues = dataTypeDisplay.PreValues, dataTypeGuid = dataType.Key });
}

return list;
}

/// <summary>
/// Gets the datatype by GUID.
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions app/Umbraco/Umbraco.Archetype/Properties/VersionInfo.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Reflection;

[assembly: AssemblyVersion("1.16.0")]
[assembly: AssemblyFileVersion("1.16.0")]
[assembly: AssemblyVersion("1.17.0")]
[assembly: AssemblyFileVersion("1.17.0")]
45 changes: 18 additions & 27 deletions app/controllers/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ angular.module("umbraco").controller("Imulus.ArchetypeController", function ($sc

// Variables.
var draggedParent;

var isCacheInitialized = false;

//$scope.model.value = "";
$scope.model.hideLabel = $scope.model.config.hideLabel == 1;
Expand All @@ -27,24 +29,15 @@ angular.module("umbraco").controller("Imulus.ArchetypeController", function ($sc
};

init();

//hold references to helper resources
$scope.resources = {
entityResource: entityResource,
archetypePropertyEditorResource: archetypePropertyEditorResource
}

//hold references to helper services
$scope.services = {
archetypeService: archetypeService,
archetypeLabelService: archetypeLabelService,
archetypeCacheService: archetypeCacheService
}


//helper to get $eval the labelTemplate
$scope.fieldsetTitles = [];
$scope.getFieldsetTitle = function (fieldsetConfigModel, fieldsetIndex) {


if(!isCacheInitialized) {
return "";
}

// Ensure the collection of titles is large enough.
ensureEnoughTitles(fieldsetIndex + 1);
var title = $scope.fieldsetTitles[fieldsetIndex];
Expand All @@ -63,18 +56,13 @@ angular.module("umbraco").controller("Imulus.ArchetypeController", function ($sc
title.loading = true;
title.loaded = false;
title.value = null;
archetypeLabelService.getFieldsetTitle($scope, fieldsetConfigModel, fieldsetIndex)
.then(function(value) {

// Finished loading the title.
title.loaded = true;
title.loading = false;
title.value = value;

});

// Still loading a title, so do not return a title.

archetypeLabelService.getFieldsetTitle($scope, fieldsetConfigModel, fieldsetIndex).then(function(value) {
// Finished loading the title.
title.loaded = true;
title.loading = false;
title.value = value;
});
};

/**
Expand Down Expand Up @@ -582,6 +570,10 @@ angular.module("umbraco").controller("Imulus.ArchetypeController", function ($sc
function init() {
$scope.model.value = removeNulls($scope.model.value);
addDefaultProperties($scope.model.value.fieldsets);

archetypeCacheService.initialize().then(function() {
isCacheInitialized = true;
});

$timeout(function () {
$scope.handleMandatoryValidation();
Expand Down Expand Up @@ -998,5 +990,4 @@ angular.module("umbraco").controller("Imulus.ArchetypeController", function ($sc
}
return null;
}

});
5 changes: 1 addition & 4 deletions app/directives/archetypeproperty.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
angular.module("umbraco.directives").directive('archetypeProperty', function ($compile, $http, archetypePropertyEditorResource, umbPropEditorHelper, $timeout, $rootScope, $q, fileManager, editorState, archetypeService, archetypeCacheService) {
angular.module("umbraco.directives").directive('archetypeProperty', function ($compile, $http, archetypePropertyEditorResource, umbPropEditorHelper, $timeout, $rootScope, $q, fileManager, editorState, archetypeService) {

var linker = function (scope, element, attrs, ngModelCtrl) {
var configFieldsetModel = archetypeService.getFieldsetByAlias(scope.archetypeConfig.fieldsets, scope.fieldset.alias);
Expand All @@ -25,9 +25,6 @@ angular.module("umbraco.directives").directive('archetypeProperty', function ($c

config = configObj;

//caching for use by label templates later
archetypeCacheService.addDatatypeToCache(data, dataTypeGuid);

//determine the view to use [...] and load it
archetypePropertyEditorResource.getPropertyEditorMapping(data.selectedEditor).then(function(propertyEditor) {
var pathToView = umbPropEditorHelper.getViewPath(propertyEditor.view);
Expand Down
119 changes: 50 additions & 69 deletions app/helpers/sampleLabelHelpers.js
Original file line number Diff line number Diff line change
@@ -1,70 +1,51 @@
var ArchetypeSampleLabelTemplates = (function() {

//public functions
return {
Entity: function (value, scope, args) {

if(!args.entityType) {
args = {entityType: "Document", propertyName: "name"}
}

if (value) {
//if handed a csv list, take the first only
var id = value.split(",")[0];

if (id) {
var entity = scope.services.archetypeCacheService.getEntityById(scope, id, args.entityType);

if(entity) {
return entity[args.propertyName];
}
}
}

return "";
},
UrlPicker: function(value, scope, args) {

if(!args.propertyName) {
args = {propertyName: "name"}
}

var entity;

switch (value.type) {
case "content":
if(value.typeData.contentId) {
entity = scope.services.archetypeCacheService.getEntityById(scope, value.typeData.contentId, "Document");
}
break;

case "media":
if(value.typeData.mediaId) {
entity = scope.services.archetypeCacheService.getEntityById(scope, value.typeData.mediaId, "Media");
}
break;

case "url":
return value.typeData.url;

default:
break;

}

if(entity) {
return entity[args.propertyName];
}

return "";
},
Rte: function (value, scope, args) {

if(!args.contentLength) {
args = {contentLength: 50}
}

return $(value).text().substring(0, args.contentLength);
}
//create a namespace (optional)
var ArchetypeSampleLabelHelpers = {};

//create a function
//you will add it to your label template field as `{{ArchetypeSampleLabelHelpers.testPromise(someArchetypePropertyAlias)}}`
ArchetypeSampleLabelHelpers.testPromise = function(value) {
//you can inject services
return function ($timeout, archetypeCacheService) {
//best to return a promise
//NOTE: $timeout returns a promise
return $timeout(function () {
return "As Promised: " + value;
}, 1000);
}
}

ArchetypeSampleLabelHelpers.testEntityPromise = function(value, scope, args) {
//hey look, args!
//{{ArchetypeSampleLabelHelpers.testEntityPromise(someArchetypePropertyAlias, {foo: 1})}}
console.log(args);

return function ($q, entityResource) {
var deferred = $q.defer();

entityResource.getById(args.foo, 'document').then(function(entity) {
console.log("Hello from testEntityPromise");
console.log(entity);
deferred.resolve(entity.name);
});

return deferred.promise;
}
}

ArchetypeSampleLabelHelpers.testEntityPromise2 = function(value, scope, args) {
//hey look, args but we're also using the built-in archetypeCacheService
//{{ArchetypeSampleLabelHelpers.testEntityPromise(someArchetypePropertyAlias, {foo: 1234})}}
console.log(args);

return function ($q, archetypeCacheService) {
var deferred = $q.defer();

archetypeCacheService.getEntityById(args.foo, 'document').then(function(entity) {
console.log("Hello from testEntityPromise2");
console.log(entity);
deferred.resolve(entity.name);
});

return deferred.promise;
}
})();
}
5 changes: 5 additions & 0 deletions app/resources/archetypePropertyEditorResource.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ angular.module('umbraco.resources').factory('archetypePropertyEditorResource', f
$http.get("backoffice/ArchetypeApi/ArchetypeDataType/GetAll"), 'Failed to retrieve datatypes from tree service'
);
},
getAllDataTypesForCache: function() {
return umbRequestHelper.resourcePromise(
$http.get("backoffice/ArchetypeApi/ArchetypeDataType/GetAllDetails"), 'Failed to retrieve datatypes from tree service'
);
},
getDataType: function (guid, useDeepDatatypeLookup, contentTypeAlias, propertyTypeAlias, archetypeAlias, nodeId) {
if(useDeepDatatypeLookup) {
return umbRequestHelper.resourcePromise(
Expand Down
Loading

0 comments on commit 3a2190b

Please sign in to comment.