Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align template picking more towards the other pickers #11247

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/Umbraco.Web.BackOffice/Controllers/EntityController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,15 @@ private ActionResult<EntityBasic> GetResultForKey(Guid key, UmbracoEntityTypes e

case UmbracoEntityTypes.Macro:

case UmbracoEntityTypes.Template:
var template = _fileService.GetTemplate(key);
if (template is null)
{
return NotFound();
}

return _umbracoMapper.Map<ITemplate, EntityBasic>(template);

default:
throw new NotSupportedException("The " + typeof(EntityController) + " does not currently support data for the type " + entityType);
}
Expand Down Expand Up @@ -1038,6 +1047,15 @@ private ActionResult<EntityBasic> GetResultForId(int id, UmbracoEntityTypes enti

case UmbracoEntityTypes.Macro:

case UmbracoEntityTypes.Template:
var template = _fileService.GetTemplate(id);
if (template is null)
{
return NotFound();
}

return _umbracoMapper.Map<ITemplate, EntityBasic>(template);

default:
throw new NotSupportedException("The " + typeof(EntityController) + " does not currently support data for the type " + entityType);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,169 +1,174 @@
(function () {
'use strict';

function GridSelector($location, overlayService, editorService) {

function link(scope, el, attr, ctrl) {

var eventBindings = [];
scope.dialogModel = {};
scope.showDialog = false;
scope.itemLabel = "";

// set default item name
if (!scope.itemName) {
scope.itemLabel = "item";
} else {
scope.itemLabel = scope.itemName;
}

scope.removeItem = function (selectedItem) {
var selectedItemIndex = scope.selectedItems.indexOf(selectedItem);
scope.selectedItems.splice(selectedItemIndex, 1);
};

scope.removeDefaultItem = function () {

// it will be the last item so we can clear the array
scope.selectedItems = [];

// remove as default item
scope.defaultItem = null;

};

scope.openItemPicker = function ($event) {
var dialogModel = {
view: "itempicker",
title: "Choose " + scope.itemLabel,
availableItems: scope.availableItems,
selectedItems: scope.selectedItems,
position: "target",
event: $event,
submit: function (model) {
scope.selectedItems.push(model.selectedItem);
// if no default item - set item as default
if (scope.defaultItem === null) {
scope.setAsDefaultItem(model.selectedItem);
}
overlayService.close();
},
close: function() {
overlayService.close();
}
};
overlayService.open(dialogModel);
};

scope.openTemplate = function (selectedItem) {
const editor = {
id: selectedItem.id,
submit: function () {
editorService.close();
},
close: function () {
editorService.close();
}
};
editorService.templateEditor(editor);
'use strict';

function GridSelector($location, overlayService, editorService) {

function link(scope, el, attr, ctrl) {

var eventBindings = [];
scope.dialogModel = {};
scope.showDialog = false;
scope.itemLabel = "";

// set default item name
if (!scope.itemName) {
scope.itemLabel = "item";
} else {
scope.itemLabel = scope.itemName;
}

scope.removeItem = function (selectedItem) {
var selectedItemIndex = scope.selectedItems.indexOf(selectedItem);
scope.selectedItems.splice(selectedItemIndex, 1);
};

scope.removeDefaultItem = function () {

// it will be the last item so we can clear the array
scope.selectedItems = [];

// remove as default item
scope.defaultItem = null;

};

scope.openItemPicker = function ($event) {
if (scope.itemPicker) {
scope.itemPicker();
} else {
var dialogModel = {
view: "itempicker",
title: "Choose " + scope.itemLabel,
availableItems: scope.availableItems,
selectedItems: scope.selectedItems,
position: "target",
event: $event,
submit: function (model) {
scope.selectedItems.push(model.selectedItem);
// if no default item - set item as default
if (scope.defaultItem === null) {
scope.setAsDefaultItem(model.selectedItem);
}
overlayService.close();
},
close: function () {
overlayService.close();
}
};
overlayService.open(dialogModel);
}
};

scope.openTemplate = function (selectedItem) {
const editor = {
id: selectedItem.id,
submit: function () {
editorService.close();
},
close: function () {
editorService.close();
}
};
editorService.templateEditor(editor);
}

scope.setAsDefaultItem = function (selectedItem) {

// clear default item
scope.defaultItem = {};
scope.setAsDefaultItem = function (selectedItem) {

// set as default item
scope.defaultItem = selectedItem;
};
// clear default item
scope.defaultItem = {};

function updatePlaceholders() {
// set as default item
scope.defaultItem = selectedItem;
};

// update default item
if (scope.defaultItem !== null && scope.defaultItem.placeholder) {
function updatePlaceholders() {

scope.defaultItem.name = scope.name;
// update default item
if (scope.defaultItem !== null && scope.defaultItem.placeholder) {

if (scope.alias !== null && scope.alias !== undefined) {
scope.defaultItem.alias = scope.alias;
}
scope.defaultItem.name = scope.name;

}
if (scope.alias !== null && scope.alias !== undefined) {
scope.defaultItem.alias = scope.alias;
}

// update selected items
Utilities.forEach(scope.selectedItems, selectedItem => {
if (selectedItem.placeholder) {
}

selectedItem.name = scope.name;
// update selected items
Utilities.forEach(scope.selectedItems, selectedItem => {
if (selectedItem.placeholder) {

if (scope.alias !== null && scope.alias !== undefined) {
selectedItem.alias = scope.alias;
}
}
});
selectedItem.name = scope.name;

// update availableItems
Utilities.forEach(scope.availableItems, availableItem => {
if (availableItem.placeholder) {
if (scope.alias !== null && scope.alias !== undefined) {
selectedItem.alias = scope.alias;
}
}
});

availableItem.name = scope.name;
// update availableItems
Utilities.forEach(scope.availableItems, availableItem => {
if (availableItem.placeholder) {

if (scope.alias !== null && scope.alias !== undefined) {
availableItem.alias = scope.alias;
}
}
});
availableItem.name = scope.name;

if (scope.alias !== null && scope.alias !== undefined) {
availableItem.alias = scope.alias;
}
}
});

function activate() {

// add watchers for updating placeholde name and alias
if (scope.updatePlaceholder) {
eventBindings.push(scope.$watch('name', function (newValue, oldValue) {
updatePlaceholders();
}));
}

eventBindings.push(scope.$watch('alias', function (newValue, oldValue) {
updatePlaceholders();
}));
}
function activate() {

}
// add watchers for updating placeholde name and alias
if (scope.updatePlaceholder) {
eventBindings.push(scope.$watch('name', function (newValue, oldValue) {
updatePlaceholders();
}));

activate();
eventBindings.push(scope.$watch('alias', function (newValue, oldValue) {
updatePlaceholders();
}));
}

// clean up
scope.$on('$destroy', function () {
}

// clear watchers
for (var e in eventBindings) {
eventBindings[e]();
}
activate();

});
// clean up
scope.$on('$destroy', function () {

// clear watchers
for (var e in eventBindings) {
eventBindings[e]();
}

var directive = {
restrict: 'E',
replace: true,
templateUrl: 'views/components/umb-grid-selector.html',
scope: {
name: "=",
alias: "=",
selectedItems: '=',
availableItems: "=",
defaultItem: "=",
itemName: "@",
updatePlaceholder: "="
},
link: link
};
});

return directive;
}

angular.module('umbraco.directives').directive('umbGridSelector', GridSelector);
var directive = {
restrict: 'E',
replace: true,
templateUrl: 'views/components/umb-grid-selector.html',
scope: {
name: "=",
alias: "=",
selectedItems: '=',
availableItems: "=",
defaultItem: "=",
itemName: "@",
updatePlaceholder: "=",
itemPicker: "="
},
link: link
};

return directive;
}

angular.module('umbraco.directives').directive('umbGridSelector', GridSelector);

})();
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,14 @@ When building a custom infinite editor view you can use the same components as a
editor.view = "views/common/infiniteeditors/itempicker/itempicker.html";
if (!editor.size) editor.size = "small";
open(editor);
}

function templatePicker(editor) {
editor.view = "views/common/infiniteeditors/treepicker/treepicker.html";
if (!editor.size) editor.size = "small";
editor.section = "settings";
editor.treeAlias = "templates";
open(editor);
}

/**
Expand Down Expand Up @@ -1133,6 +1141,7 @@ When building a custom infinite editor view you can use the same components as a
templateSections: templateSections,
userPicker: userPicker,
itemPicker: itemPicker,
templatePicker: templatePicker,
macroPicker: macroPicker,
memberGroupPicker: memberGroupPicker,
memberPicker: memberPicker,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ angular.module("umbraco").controller("Umbraco.Editors.TreePickerController",
$scope.model.title = value;
});
}
}
else if (vm.treeAlias === "templates") {
vm.entityType = "Template";
}

// TODO: Seems odd this logic is here, i don't think it needs to be and should just exist on the property editor using this
Expand Down
Loading