Skip to content

Commit 1d2272f

Browse files
patrickdemooij9nathanwoulfe
authored andcommitted
Content app for dictionary items
1 parent e04efe6 commit 1d2272f

File tree

9 files changed

+221
-169
lines changed

9 files changed

+221
-169
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System.Collections.Generic;
2+
using Umbraco.Cms.Core.Models;
3+
using Umbraco.Cms.Core.Models.ContentEditing;
4+
using Umbraco.Cms.Core.Models.Membership;
5+
6+
namespace Umbraco.Cms.Core.ContentApps
7+
{
8+
internal class DictionaryContentAppFactory : IContentAppFactory
9+
{
10+
private const int Weight = -100;
11+
12+
private ContentApp _dictionaryApp;
13+
14+
public ContentApp GetContentAppFor(object source, IEnumerable<IReadOnlyUserGroup> userGroups)
15+
{
16+
switch (source)
17+
{
18+
case IDictionaryItem _:
19+
return _dictionaryApp ??= new ContentApp
20+
{
21+
Alias = "dictionaryContent",
22+
Name = "Content",
23+
Icon = "icon-document",
24+
View = "views/dictionary/views/content/content.html",
25+
Weight = Weight
26+
};
27+
default:
28+
return null;
29+
}
30+
}
31+
}
32+
}

src/Umbraco.Core/DependencyInjection/UmbracoBuilder.Collections.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ internal static void AddAllCoreCollectionBuilders(this IUmbracoBuilder builder)
4444
.Append<ContentTypeDesignContentAppFactory>()
4545
.Append<ContentTypeListViewContentAppFactory>()
4646
.Append<ContentTypePermissionsContentAppFactory>()
47-
.Append<ContentTypeTemplatesContentAppFactory>();
47+
.Append<ContentTypeTemplatesContentAppFactory>()
48+
.Append<DictionaryContentAppFactory>();
4849

4950
// all built-in finders in the correct order,
5051
// devs can then modify this list on application startup

src/Umbraco.Core/Manifest/ManifestContentAppFactory.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Text.RegularExpressions;
@@ -70,6 +70,10 @@ public ContentApp GetContentAppFor(object o,IEnumerable<IReadOnlyUserGroup> user
7070
partA = "contentType";
7171
partB = contentType.Alias;
7272
break;
73+
case IDictionaryItem _:
74+
partA = "dictionary";
75+
partB = "*"; //Not really a different type for dictionary items
76+
break;
7377

7478
default:
7579
return null;

src/Umbraco.Core/Models/ContentEditing/DictionaryDisplay.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Runtime.Serialization;
44

@@ -17,6 +17,7 @@ public DictionaryDisplay()
1717
{
1818
Notifications = new List<BackOfficeNotification>();
1919
Translations = new List<DictionaryTranslationDisplay>();
20+
ContentApps = new List<ContentApp>();
2021
}
2122

2223
/// <inheritdoc />
@@ -37,5 +38,11 @@ public DictionaryDisplay()
3738
/// </summary>
3839
[DataMember(Name = "translations")]
3940
public List<DictionaryTranslationDisplay> Translations { get; private set; }
41+
42+
/// <summary>
43+
/// Apps for the dictionary item
44+
/// </summary>
45+
[DataMember(Name = "apps")]
46+
public List<ContentApp> ContentApps { get; private set; }
4047
}
4148
}

src/Umbraco.Core/Models/Mapping/CommonMapper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Linq;
44
using Umbraco.Cms.Core.ContentApps;
@@ -47,7 +47,7 @@ public ContentTypeBasic GetContentType(IContentBase source, MapperContext contex
4747
return contentTypeBasic;
4848
}
4949

50-
public IEnumerable<ContentApp> GetContentApps(IUmbracoEntity source)
50+
public IEnumerable<ContentApp> GetContentApps(IEntity source)
5151
{
5252
var apps = _contentAppDefinitions.GetContentAppsFor(source).ToArray();
5353

src/Umbraco.Core/Models/Mapping/DictionaryMapDefinition.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Linq;
44
using Umbraco.Cms.Core.Mapping;
@@ -14,10 +14,12 @@ namespace Umbraco.Cms.Core.Models.Mapping
1414
public class DictionaryMapDefinition : IMapDefinition
1515
{
1616
private readonly ILocalizationService _localizationService;
17+
private readonly CommonMapper _commonMapper;
1718

18-
public DictionaryMapDefinition(ILocalizationService localizationService)
19+
public DictionaryMapDefinition(ILocalizationService localizationService, CommonMapper commonMapper)
1920
{
2021
_localizationService = localizationService;
22+
_commonMapper = commonMapper;
2123
}
2224

2325
public void DefineMaps(IUmbracoMapper mapper)
@@ -44,6 +46,7 @@ private void Map(IDictionaryItem source, DictionaryDisplay target, MapperContext
4446
target.Name = source.ItemKey;
4547
target.ParentId = source.ParentId ?? Guid.Empty;
4648
target.Udi = Udi.Create(Constants.UdiEntityType.DictionaryItem, source.Key);
49+
target.ContentApps.AddRange(_commonMapper.GetContentApps(source));
4750

4851
// build up the path to make it possible to set active item in tree
4952
// TODO: check if there is a better way
Lines changed: 103 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/**
22
* @ngdoc controller
33
* @name Umbraco.Editors.Dictionary.EditController
44
* @function
@@ -7,128 +7,131 @@
77
* The controller for editing dictionary items
88
*/
99
function DictionaryEditController($scope, $routeParams, $location, dictionaryResource, navigationService, appState, editorState, contentEditingHelper, formHelper, notificationsService, localizationService) {
10-
11-
var vm = this;
12-
13-
//setup scope vars
14-
vm.nameDirty = false;
15-
vm.header = {};
16-
vm.header.editorfor = "template_insertDictionaryItem";
17-
vm.header.setPageTitle = true;
18-
19-
vm.page = {};
20-
vm.page.loading = false;
21-
vm.page.nameLocked = false;
22-
vm.page.menu = {};
23-
vm.page.menu.currentSection = appState.getSectionState("currentSection");
24-
vm.page.menu.currentNode = null;
25-
vm.description = "";
26-
vm.showBackButton = true;
27-
vm.maxlength = 1000;
28-
29-
vm.save = saveDictionary;
30-
vm.back = back;
31-
vm.change = change;
32-
33-
function loadDictionary() {
34-
35-
vm.page.loading = true;
36-
37-
//we are editing so get the content item from the server
38-
dictionaryResource.getById($routeParams.id)
39-
.then(function (data) {
40-
bindDictionary(data);
41-
vm.page.loading = false;
42-
});
43-
}
4410

45-
function createTranslationProperty(translation) {
46-
return {
47-
alias: translation.isoCode,
48-
label: translation.displayName,
49-
hideLabel : false
50-
}
11+
var vm = this;
12+
13+
//setup scope vars
14+
vm.nameDirty = false;
15+
vm.header = {};
16+
vm.header.editorfor = "template_insertDictionaryItem";
17+
vm.header.setPageTitle = true;
18+
19+
vm.page = {};
20+
vm.page.navigation = {};
21+
vm.page.loading = false;
22+
vm.page.nameLocked = false;
23+
vm.page.menu = {};
24+
vm.page.menu.currentSection = appState.getSectionState("currentSection");
25+
vm.page.menu.currentNode = null;
26+
vm.description = "";
27+
vm.showBackButton = true;
28+
vm.maxlength = 1000;
29+
30+
vm.save = saveDictionary;
31+
vm.back = back;
32+
vm.change = change;
33+
34+
function loadDictionary() {
35+
36+
vm.page.loading = true;
37+
38+
//we are editing so get the content item from the server
39+
dictionaryResource.getById($routeParams.id)
40+
.then(function (data) {
41+
bindDictionary(data);
42+
vm.page.navigation = data.apps;
43+
data.apps[0].active = true;
44+
vm.page.loading = false;
45+
});
46+
}
47+
48+
function createTranslationProperty(translation) {
49+
return {
50+
alias: translation.isoCode,
51+
label: translation.displayName,
52+
hideLabel: false
5153
}
54+
}
5255

53-
function bindDictionary(data) {
54-
localizationService.localize("dictionaryItem_description").then(function (value) {
55-
vm.description = value.replace("%0%", data.name);
56-
});
56+
function bindDictionary(data) {
57+
localizationService.localize("dictionaryItem_description").then(function (value) {
58+
vm.description = value.replace("%0%", data.name);
59+
});
5760

58-
// create data for umb-property displaying
59-
for (var i = 0; i < data.translations.length; i++) {
60-
data.translations[i].property = createTranslationProperty(data.translations[i]);
61-
change(data.translations[i]);
62-
}
61+
// create data for umb-property displaying
62+
for (var i = 0; i < data.translations.length; i++) {
63+
data.translations[i].property = createTranslationProperty(data.translations[i]);
64+
change(data.translations[i]);
65+
}
6366

64-
contentEditingHelper.handleSuccessfulSave({
65-
scope: $scope,
66-
savedContent: data
67-
});
67+
contentEditingHelper.handleSuccessfulSave({
68+
scope: $scope,
69+
savedContent: data
70+
});
6871

69-
// set content
70-
vm.content = data;
72+
// set content
73+
vm.content = data;
7174

72-
//share state
73-
editorState.set(vm.content);
75+
//share state
76+
editorState.set(vm.content);
7477

75-
navigationService.syncTree({ tree: "dictionary", path: data.path, forceReload: true }).then(function (syncArgs) {
76-
vm.page.menu.currentNode = syncArgs.node;
77-
});
78-
}
78+
navigationService.syncTree({ tree: "dictionary", path: data.path, forceReload: true }).then(function (syncArgs) {
79+
vm.page.menu.currentNode = syncArgs.node;
80+
});
81+
}
7982

80-
function onInit() {
81-
loadDictionary();
82-
}
83+
function onInit() {
84+
loadDictionary();
85+
}
86+
87+
function saveDictionary() {
88+
if (formHelper.submitForm({ scope: $scope, statusMessage: "Saving..." })) {
8389

84-
function saveDictionary() {
85-
if (formHelper.submitForm({ scope: $scope, statusMessage: "Saving..." })) {
90+
vm.page.saveButtonState = "busy";
8691

87-
vm.page.saveButtonState = "busy";
92+
dictionaryResource.save(vm.content, vm.nameDirty)
93+
.then(function (data) {
8894

89-
dictionaryResource.save(vm.content, vm.nameDirty)
90-
.then(function (data) {
95+
formHelper.resetForm({ scope: $scope });
9196

92-
formHelper.resetForm({ scope: $scope });
97+
bindDictionary(data);
9398

94-
bindDictionary(data);
99+
vm.page.saveButtonState = "success";
100+
},
101+
function (err) {
95102

96-
vm.page.saveButtonState = "success";
97-
},
98-
function (err) {
103+
formHelper.resetForm({ scope: $scope, hasErrors: true });
99104

100-
formHelper.resetForm({ scope: $scope, hasErrors: true });
105+
contentEditingHelper.handleSaveError({
106+
err: err
107+
});
101108

102-
contentEditingHelper.handleSaveError({
103-
err: err
104-
});
105-
106-
notificationsService.error(err.data.message);
109+
notificationsService.error(err.data.message);
107110

108-
vm.page.saveButtonState = "error";
109-
});
110-
}
111-
}
112-
113-
function back() {
114-
$location.path(vm.page.menu.currentSection + "/dictionary/list");
111+
vm.page.saveButtonState = "error";
112+
});
115113
}
114+
}
116115

117-
function change(translation) {
118-
if (translation.translation) {
119-
var charsCount = translation.translation.length;
120-
translation.nearMaxLimit = charsCount > Math.max(vm.maxlength * .8, vm.maxlength - 50);
121-
}
116+
function back() {
117+
$location.path(vm.page.menu.currentSection + "/dictionary/list");
118+
}
119+
120+
function change(translation) {
121+
if (translation.translation) {
122+
var charsCount = translation.translation.length;
123+
translation.nearMaxLimit = charsCount > Math.max(vm.maxlength * .8, vm.maxlength - 50);
122124
}
125+
}
123126

124-
$scope.$watch("vm.content.name", function (newVal, oldVal) {
125-
//when the value changes, we need to set the name dirty
126-
if (newVal && (newVal !== oldVal) && typeof(oldVal) !== "undefined") {
127-
vm.nameDirty = true;
128-
}
129-
});
127+
$scope.$watch("vm.content.name", function (newVal, oldVal) {
128+
//when the value changes, we need to set the name dirty
129+
if (newVal && (newVal !== oldVal) && typeof (oldVal) !== "undefined") {
130+
vm.nameDirty = true;
131+
}
132+
});
130133

131-
onInit();
134+
onInit();
132135
}
133136

134137
angular.module("umbraco").controller("Umbraco.Editors.Dictionary.EditController", DictionaryEditController);

0 commit comments

Comments
 (0)