Skip to content

Commit

Permalink
Robots on content level (#148)
Browse files Browse the repository at this point in the history
* Starting on robots on content level

* Finish up the robot setting on content level
  • Loading branch information
patrickdemooij9 authored Feb 5, 2023
1 parent bbe8607 commit 0e43367
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public object ConvertDatabaseToObject(object value)

public object ConvertEditorToDatabaseValue(object value)
{
if (!(value is JArray array)) return null;
if (!(value is JArray array) || array.Count == 0) return null;
return string.Join(',', array);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace SeoToolkit.Umbraco.MetaFields.Core.Common.SeoFieldEditEditors
{
public class SeoCheckboxlistEditEditor : ISeoFieldEditEditor
{
public string View => "checkboxlist";
public string View => "/App_Plugins/SeoToolkit/MetaFields/Interface/SeoFieldEditors/PropertyEditor/noSelectCheckboxList.html";
public Dictionary<string, object> Config { get; }
public IEditorValueConverter ValueConverter => new CheckboxlistConverter();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,15 @@ public IActionResult Get(int nodeId, string culture)
var userValue = userValues.ContainsKey(key.Alias)
? key.EditEditor.ValueConverter.ConvertObjectToEditorValue(key.EditEditor.ValueConverter.ConvertDatabaseToObject(userValues[key.Alias]))
: null;

var humanReadableValue = value is string[] ? string.Join(", ", value as string[]) : value;
return new SeoSettingsFieldViewModel
{
Alias = key.Alias,
Title = key.Title,
Description = key.Description,
GroupAlias = key.GroupAlias,
Value = value?.ToString(),
Value = humanReadableValue?.ToString(),
UserValue = userValue,
EditView = key.EditEditor.View,
EditConfig = key.EditEditor.Config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ public RobotsField()

Editor = new CheckboxListFieldPropertyEditor(items);

//EditEditor = new SeoCheckboxlistEditEditor(items);
EditEditor = new SeoCheckboxlistEditEditor(items);
}

protected override HtmlString Render(string[] value)
{
if (value is null || value.Length == 0) return HtmlString.Empty;
if (value.Length == 1 && value[0].Equals("none")) return HtmlString.Empty;

return new HtmlString($"<meta name=\"robots\" content=\"{string.Join(',', value)}\">");
}
Expand Down
1 change: 1 addition & 0 deletions src/SeoToolkit.Umbraco.MetaFields/ManifestLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public void Filter(List<PackageManifest> manifests)
"/App_Plugins/SeoToolkit/MetaFields/Interface/Previewers/OpenGraph/openGraphPreviewer.controller.js",
"/App_Plugins/SeoToolkit/MetaFields/Interface/SeoFieldEditors/FieldsEditor/fieldsEditor.controller.js",
"/App_Plugins/SeoToolkit/MetaFields/Interface/SeoFieldEditors/PropertyEditor/propertyEditor.controller.js",
"/App_Plugins/SeoToolkit/MetaFields/Interface/SeoFieldEditors/PropertyEditor/noSelectCheckboxList.controller.js",
"/App_Plugins/SeoToolkit/MetaFields/Interface/Components/ItemGroupPicker/itemGroupPicker.controller.js",
"/App_Plugins/SeoToolkit/MetaFields/Interface/SeoFieldEditors/seoFieldEditor.directive.js",
"/App_Plugins/SeoToolkit/MetaFields/Interface/Previewers/previewer.directive.js"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

vm.isUrl = isUrl;
vm.culture = $routeParams.cculture ? $routeParams.cculture : $routeParams.mculture;
vm.getValue = getValue;

vm.isContentDirty = function () {
var currentEditorItem = editorState.getCurrent();
Expand Down Expand Up @@ -110,6 +111,13 @@
return false;
}

function getValue(field) {
if (Array.isArray(field.value)) {
return "array";
}
return field.value;
}

unsubscribe.push($scope.$on("seoContentSubmitting",
function () {
save();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<div class="controls">
<umb-property-editor class="umb-property-editor" model="field.editModel">
</umb-property-editor>
<small class="property-fallback-info" ng-if="field.value">Fallback value: <strong>{{field.value}}</strong></small>
<small class="property-fallback-info" ng-if="field.value">Fallback value: <strong>{{vm.getValue(field)}}</strong></small>
<small class="property-fallback-info" ng-if="!field.value">No fallback value found!</small>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
(function () {
function noSelectCheckboxListController($scope) {
var vm = this;

const noneValue = 'none';

vm.items = [];

vm.change = change;

function change(model, value) {
var index = $scope.model.value.indexOf(value);
if (model === true) {

if (value === noneValue) {
$scope.model.value = [];
vm.items.forEach(item => {
if (item.value !== noneValue) {
item.checked = false;
}
});
} else {
if ($scope.model.value.includes(noneValue)) {
var noneIndex = $scope.model.value.indexOf(noneValue);
if (noneIndex !== -1) {
$scope.model.value.splice(noneIndex, 1);
}

var item = vm.items.find(item => item.value === noneValue);
if (item) {
item.checked = false;
}
}
}

//if it doesn't exist in the model, then add it
if (index < 0) {
$scope.model.value.push(value);
}
} else {
//if it exists in the model, then remove it
if (index >= 0) {
$scope.model.value.splice(index, 1);
}
}
}

function init() {
if (!Array.isArray($scope.model.value)) {
$scope.model.value = [];
}

$scope.model.config.prevalues.forEach(function (prevalue) {
var newItem = { ...prevalue };
if ($scope.model.value.find(item => item === newItem.value)) {
newItem.checked = true;
}

vm.items.push(newItem);
});

var noneItem = {
value: noneValue,
label: 'None',
checked: $scope.model.value.find(item => item === noneValue) != null
};
vm.items.push(noneItem);
}

init();
}

angular.module("umbraco").controller("SeoToolkit.SeoFieldEditors.NoSelectCheckboxList", noSelectCheckboxListController);
})();
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div ng-controller="SeoToolkit.SeoFieldEditors.NoSelectCheckboxList as vm">
<umb-checkbox value="{{item.value}}"
model="item.checked"
text="{{item.label}}"
ng-repeat="item in vm.items track by item.value"
on-change="vm.change(model, value)">
</umb-checkbox>
</div>

0 comments on commit 0e43367

Please sign in to comment.