Skip to content

Commit

Permalink
Update to Umbraco v8 preview
Browse files Browse the repository at this point in the history
  • Loading branch information
rasmusjp committed May 30, 2018
1 parent 7b139d4 commit 2ae5acb
Show file tree
Hide file tree
Showing 19 changed files with 392 additions and 1,043 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Multi Url Picker for Umbraco 7
# Multi Url Picker for Umbraco 8

[![NuGet release](https://img.shields.io/nuget/v/RJP.UmbracoMultiUrlPicker.svg)](https://www.nuget.org/packages/RJP.UmbracoMultiUrlPicker)
[![Our Umbraco project page](https://img.shields.io/badge/our-umbraco-orange.svg)](https://our.umbraco.org/projects/backoffice-extensions/multi-url-picker)
Expand Down
3 changes: 2 additions & 1 deletion build/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
2.1.0
3.0.0
alpha
44 changes: 40 additions & 4 deletions src/RJP.MultiUrlPicker.Web.UI/MultiUrlPicker.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<div ng-controller="RJP.MultiUrlPickerController as ctrl" class="umb-editor umb-contentpicker">
<div ng-controller="RJP.MultiUrlPickerController as ctrl" class="umb-property-editor umb-contentpicker">
<p ng-if="(ctrl.renderModel|filter:{trashed:true}).length == 1"><localize key="contentPicker_pickedTrashedItem"></localize></p>
<p ng-if="(ctrl.renderModel|filter:{trashed:true}).length > 1"><localize key="contentPicker_pickedTrashedItems"></localize></p>

<ng-form name="multiUrlPickerForm">
<div ui-sortable="ctrl.sortableOptions" ng-model="ctrl.renderModel">
<div ng-repeat="link in ctrl.renderModel">
Expand All @@ -14,7 +17,6 @@
</umb-node-preview>
</div>
</div>

<a ng-show="!model.config.maxNumberOfItems || ctrl.renderModel.length < model.config.maxNumberOfItems"
class="umb-node-preview-add"
href
Expand All @@ -23,15 +25,49 @@
<localize key="general_add">Add</localize>
</a>

<div class="umb-contentpicker__min-max-help" ng-if="model.config.minNumberOfItems || model.config.maxNumberOfItems">

<!-- Both min and max items -->
<span ng-if="model.config.minNumberOfItems && model.config.maxNumberOfItems && model.config.minNumberOfItems !== model.config.maxNumberOfItems">
<span ng-if="ctrl.renderModel.length < model.config.maxNumberOfItems">Add between {{model.config.minNumberOfItems}} and {{model.config.maxNumberOfItems}} items</span>
<span ng-if="ctrl.renderModel.length > model.config.maxNumberOfItems">
<localize key="validation_maxCount">You can only have</localize> {{model.config.maxNumberOfItems}} <localize key="validation_itemsSelected"> items selected</localize>
</span>
</span>

<!-- Equal min and max -->
<span ng-if="model.config.minNumberOfItems && model.config.maxNumber && model.config.minNumberOfItems === model.config.maxNumberOfItems">
<span ng-if="ctrl.renderModel.length < model.config.maxNumberOfItems">Add {{model.config.minNumberOfItems - renderModel.length}} item(s)</span>
<span ng-if="ctrl.renderModel.length > model.config.maxNumberOfItems">
<localize key="validation_maxCount">You can only have</localize> {{model.config.maxNumberOfItems}} <localize key="validation_itemsSelected"> items selected</localize>
</span>
</span>

<!-- Only max -->
<span ng-if="!model.config.minNumberOfItems && model.config.maxNumberOfItems">
<span ng-if="ctrl.renderModel.length < model.config.maxNumberOfItems">Add up to {{model.config.maxNumberOfItems}} items</span>
<span ng-if="ctrl.renderModel.length > model.config.maxNumberOfItems">
<localize key="validation_maxCount">You can only have</localize> {{model.config.maxNumberOfItems}} <localize key="validation_itemsSelected">items selected</localize>
</span>
</span>

<!-- Only min -->
<span ng-if="model.config.minNumberOfItems && !model.config.maxNumberOfItems && ctrl.renderModel.length < model.config.minNumberOfItems">
Add at least {{model.config.minNumberOfItems}} item(s)
</span>

</div>


<input type="hidden" name="minCount" ng-model="ctrl.renderModel" />
<input type="hidden" name="maxCount" ng-model="ctrl.renderModel" />

<div class="help-inline" val-msg-for="minCount" val-toggle-msg="minCount">
You need to add at least {{model.config.minNumberOfItems}} items
<localize key="validation_minCount">You need to add at least</localize> {{model.config.minNumberOfItems}} <localize key="validation_items">items</localize>
</div>

<div class="help-inline" val-msg-for="maxCount" val-toggle-msg="maxCount">
You can only have {{model.config.maxNumberOfItems}} items selected
<localize key="validation_maxCount">You can only have</localize> {{model.config.maxNumberOfItems}} <localize key="validation_itemsSelected">items selected</localize>
</div>
</ng-form>

Expand Down
5 changes: 3 additions & 2 deletions src/RJP.MultiUrlPicker.Web.UI/MultiUrlPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
'use strict'

var MultiUrlPickerController = function ($scope, angularHelper, entityResource, iconHelper) {

this.renderModel = []

if ($scope.preview) {
Expand Down Expand Up @@ -126,7 +127,7 @@
// Inject the querystring field
var $markup = $(response.data)
var $urlField = $markup.find('[label="@defaultdialogs_urlLinkPicker"]')
$urlField.after('<umb-control-group label="Query String" ng-if="model.querystring"><input type="text" placeholder="Query String" class="umb-editor umb-textstring" ng-model="model.target.querystring"/></umb-control-group>')
$urlField.after('<umb-control-group label="Query String" ng-if="model.querystring"><input type="text" placeholder="Query String" class="umb-property-editor umb-textstring" ng-model="model.target.querystring"/></umb-control-group>')
response.data = $markup[0]
}
return response
Expand All @@ -136,5 +137,5 @@
}

angular.module('umbraco').controller('RJP.MultiUrlPickerController', MultiUrlPickerController)
angular.module("umbraco.services").config(['$httpProvider', mupHttpProvider]);
angular.module('umbraco.services').config(['$httpProvider', mupHttpProvider])
})()
23 changes: 0 additions & 23 deletions src/RJP.MultiUrlPicker/Information.cs

This file was deleted.

227 changes: 6 additions & 221 deletions src/RJP.MultiUrlPicker/Models/Link.cs
Original file line number Diff line number Diff line change
@@ -1,228 +1,13 @@
namespace RJP.MultiUrlPicker.Models
namespace RJP.MultiUrlPicker.Models
{
using System;

using Newtonsoft.Json.Linq;

using Umbraco.Core.Models;
using Umbraco.Core;

using Umbraco.Web;
using Umbraco.Web.Extensions;
using Umbraco.Core.Models.PublishedContent;

public class Link
{
private readonly JToken _linkItem;
private bool _publishedContentInitialized = false;
private string _name;
private string _url;
private string _target;
private bool? _deleted;
private LinkType? _linkType;
private IPublishedContent _content;
private Udi _udi;
private int? _id;

public Link(JToken linkItem)
{
_linkItem = linkItem;
}

private IPublishedContent PublishedContent
{
get
{
InitPublishedContent();
return _content;
}
}

[Obsolete("Use Udi instead")]
public int? Id
{
get
{
if (_id == null)
{
_id = _linkItem.Value<int?>("id");
if (!_id.HasValue)
{
InitPublishedContent();
}
}
return _id;
}

}

public Udi Udi
{
get
{
if (_udi == null)
{
if (!Udi.TryParse(_linkItem.Value<string>("udi"), out _udi))
{
InitPublishedContent();
}
}
return _udi;
}
}

public string Name
{
get
{
if (string.IsNullOrEmpty(_name))
{
_name = _linkItem.Value<string>("name");
}
return _name;
}
}

internal bool Deleted
{
get
{
if (_deleted == null)
{
if (Id.HasValue || Udi != null)
{
_deleted = PublishedContent == null;
}
else
{
_deleted = false;
}
}
return (bool)_deleted;
}
}

public string Url
{
get
{
if (string.IsNullOrEmpty(_url))
{
_url = PublishedContent?.Url ?? _linkItem.Value<string>("url");

var qs = _linkItem.Value<string>("querystring");
if (!string.IsNullOrWhiteSpace(qs))
{
_url += qs;
}
}
return _url;
}
}

public string Target
{
get
{
if (string.IsNullOrEmpty(_target))
{
_target = _linkItem.Value<string>("target");
}
return _target == string.Empty ? null : _target;
}
}

public LinkType Type
{
get
{
if (_linkType == null)
{
if (Udi != null)
{
if (Udi.EntityType == Constants.UdiEntityType.Media)
{
_linkType = LinkType.Media;
}
else
{
_linkType = LinkType.Content;
}
}
else
{
_linkType = LinkType.External;
}
}
return _linkType.Value;
}
}


private void InitPublishedContent()
{
if (!_publishedContentInitialized)
{
_publishedContentInitialized = true;

if (UmbracoContext.Current == null)
{
return;
}

if (Udi.TryParse(_linkItem.Value<string>("udi"), out _udi))
{
_content = _udi.ToPublishedContent();
_id = _content?.Id;
}
else
{
var helper = new UmbracoHelper(UmbracoContext.Current);

// there were no Udi so let's try the legacy way
_id = _linkItem.Value<int?>("id");

if (_id.HasValue)
{
bool isMedia = _linkItem.Value<bool>("isMedia");

if (_linkItem.Value<bool>("isMedia"))
{
_content = helper.TypedMedia(_id.Value);
}
else
{
_content = helper.TypedContent(_id.Value);
}
SetUdi();
}
}
}
}

private void SetUdi()
{
if (_content != null && _udi == null)
{
Guid? key = _content.GetKey();
if (key == Guid.Empty)
{
// if the key is Guid.Empty the model might be created by the ModelsBuilder,
// if so it, by default, derives from PublishedContentModel.
// By calling UnWrap() we get the original content, which probably implements
// IPublishedContentWithKey, so we can get the key
key = (_content as PublishedContentWrapped)?.Unwrap().GetKey();
}

if (key.HasValue && key != Guid.Empty)
{
string udiType = _content.ItemType == PublishedItemType.Media ?
Constants.UdiEntityType.Media :
Constants.UdiEntityType.Document;

_udi = Udi.Create(udiType, key.Value);
}
}
}
public string Name { get; set; }
public string Target { get; set; }
public LinkType Type { get; set; }
public Udi Udi { get; set; }
public string Url { get; set; }
}
}
Loading

0 comments on commit 2ae5acb

Please sign in to comment.