Skip to content

Commit

Permalink
Nice formatting for document URL in EditAchievements
Browse files Browse the repository at this point in the history
- just like in EditDocuments
  • Loading branch information
roman-yagodin committed Jun 7, 2020
1 parent 2e10928 commit e70ebea
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,4 @@
<data name="FileName.Invalid" xml:space="preserve">
<value>Name of the selected file doesn't match validation expression &quot;{regex}&quot; for the selected document type.</value>
</data>
<data name="FileNotFound.Text" xml:space="preserve">
<value>File not found!</value>
</data>
<data name="PageNotFound.Text" xml:space="preserve">
<value>Page not found!</value>
</data>
<data name="Page.Text" xml:space="preserve">
<value>Page: </value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,4 @@
<data name="FileName.Invalid" xml:space="preserve">
<value>Имя выбранного файла не соответствует проверочному выражению &quot;{regex}&quot; для выбранного типа документа.</value>
</data>
<data name="FileNotFound.Text" xml:space="preserve">
<value>Файл не найден!</value>
</data>
<data name="PageNotFound.Text" xml:space="preserve">
<value>Страница не найдена!</value>
</data>
<data name="Page.Text" xml:space="preserve">
<value>Страница: </value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,13 @@
<data name="NotSelected.Text" xml:space="preserve">
<value>&lt; Not Selected &gt;</value>
</data>
<data name="FileNotFound.Text" xml:space="preserve">
<value>File not found!</value>
</data>
<data name="PageNotFound.Text" xml:space="preserve">
<value>Page not found!</value>
</data>
<data name="Page.Text" xml:space="preserve">
<value>Page: </value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,13 @@
<data name="NotSelected.Text" xml:space="preserve">
<value>&lt; Не выбрано &gt;</value>
</data>
<data name="FileNotFound.Text" xml:space="preserve">
<value>Файл не найден!</value>
</data>
<data name="PageNotFound.Text" xml:space="preserve">
<value>Страница не найдена!</value>
</data>
<data name="Page.Text" xml:space="preserve">
<value>Страница: </value>
</data>
</root>
2 changes: 1 addition & 1 deletion R7.University.Controls/EditAchievements.ascx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<asp:BoundField DataField="Title_String" HeaderText="Title.Column" />
<asp:BoundField DataField="AchievementType_String" HeaderText="AchievementType.Column" />
<asp:CheckBoxField DataField="IsTitle" HeaderText="IsTitle.Column" />
<asp:BoundField DataField="DocumentUrl_Link" HeaderText="DocumentUrl.Column" HtmlEncode="false" />
<asp:BoundField DataField="FormattedUrl" HeaderText="DocumentUrl.Column" HtmlEncode="false" />
<asp:BoundField DataField="Description" Visible="false" />
</Columns>
</asp:GridView>
Expand Down
48 changes: 6 additions & 42 deletions R7.University.Controls/EditModels/DocumentEditModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Author:
// Roman M. Yagodin <[email protected]>
//
// Copyright (c) 2015-2019 Roman M. Yagodin
// Copyright (c) 2015-2020 Roman M. Yagodin
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
Expand All @@ -21,10 +21,6 @@

using System;
using System.Web;
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Tabs;
using DotNetNuke.Services.FileSystem;
using Newtonsoft.Json;
using R7.Dnn.Extensions.Models;
using R7.Dnn.Extensions.ViewModels;
Expand Down Expand Up @@ -81,7 +77,7 @@ public override void SetTargetItemId (int targetItemId, string targetItemKey)
public int DocumentTypeID { get; set; }

[JsonIgnore]
[Obsolete ("Use DocumentTypeViewModel property instead", true)]
[Obsolete ("Use DocumentTypeViewModel property instead", true)]
public IDocumentType DocumentType { get; set; }

public DocumentTypeViewModel DocumentTypeViewModel { get; set; }
Expand Down Expand Up @@ -116,7 +112,7 @@ public override void SetTargetItemId (int targetItemId, string targetItemKey)

[JsonIgnore]
public string LocalizedType
{
{
get {
return LocalizationHelper.GetStringWithFallback (
"SystemDocumentType_" + DocumentTypeViewModel.Type + ".Text", Context.LocalResourceFile, DocumentTypeViewModel.Type
Expand All @@ -125,41 +121,9 @@ public string LocalizedType
}

[JsonIgnore]
public string FormattedUrl
{
get {
var label = string.Empty;
var title = string.Empty;

if (Globals.GetURLType (Url) == TabType.File) {
var file = FileManager.Instance.GetFile (int.Parse (Url.ToUpperInvariant ().Replace ("FILEID=", "")));
if (file != null) {
label = file.FileName;
title = file.RelativePath;
}
else {
label = Context.LocalizeString ("FileNotFound.Text");
}
}
else if (Globals.GetURLType (Url) == TabType.Tab) {
var tab = TabController.Instance.GetTab (int.Parse (Url), Context.Module.PortalId);
if (tab != null) {
label = Context.LocalizeString ("Page.Text") + " " + tab.LocalizedTabName;
title = tab.TabPath.Replace ("//", "/");
}
else {
label = Context.LocalizeString ("PageNotFound.Text");
}
}
else {
label = HttpUtility.HtmlEncode (HtmlUtils.Shorten (Url, 25, ""));
title = HttpUtility.HtmlAttributeEncode (Url);
}

var url = UniversityUrlHelper.LinkClickIdnHack (Url, Context.Module.TabId, Context.Module.ModuleId);
return $"<a href={url} target=\"_blank\" title=\"{title}\">{label}</a>";
}
}
public string FormattedUrl =>
UniversityUrlHelper.FormatNiceDocumentUrl (Url, Context.Module.ModuleId, Context.Module.TabId,
Context.Module.PortalId, Context.LocalResourceFile);

#endregion
}
Expand Down
21 changes: 6 additions & 15 deletions R7.University.Controls/EditModels/EmployeeAchievementEditModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Author:
// Roman M. Yagodin <[email protected]>
//
// Copyright (c) 2015-2019 Roman M. Yagodin
// Copyright (c) 2015-2020 Roman M. Yagodin
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
Expand Down Expand Up @@ -144,20 +144,11 @@ public string Title_String
{
get { return Title + " " + TitleSuffix; }
}

[JsonIgnore]
public string DocumentUrl_Link
{
get {
if (!string.IsNullOrWhiteSpace (DocumentURL)) {
return string.Format ("<a href=\"{0}\" target=\"_blank\">{1}</a>",
UniversityUrlHelper.LinkClickIdnHack (DocumentURL, Context.Module.TabId, Context.Module.ModuleId),
Localization.GetString ("DocumentUrl.Text", Context.LocalResourceFile));
}

return string.Empty;
}
}

[JsonIgnore]
public string FormattedUrl =>
UniversityUrlHelper.FormatNiceDocumentUrl (DocumentURL, Context.Module.ModuleId, Context.Module.TabId,
Context.Module.PortalId, Context.LocalResourceFile);

#endregion
}
Expand Down
39 changes: 37 additions & 2 deletions R7.University/Utilities/UniversityUrlHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Portals;
using DotNetNuke.Entities.Tabs;
using DotNetNuke.Services.FileSystem;
using DotNetNuke.Services.Localization;
using DotNetNuke.UI.Modules;

namespace R7.University.Utilities
Expand Down Expand Up @@ -111,7 +113,7 @@ public static string IESafeEditUrl (IModuleControl module, HttpRequest request,
if (browserName.StartsWith ("IE", StringComparison.Ordinal)
|| browserName.Contains ("MSIE")
|| browserName == "INTERNETEXPLORER") {
return Globals.NavigateURL (controlKey, keyName, keyValue,
return Globals.NavigateURL (controlKey, keyName, keyValue,
"mid", module.ModuleContext.ModuleId.ToString ());
}
}
Expand All @@ -120,6 +122,39 @@ public static string IESafeEditUrl (IModuleControl module, HttpRequest request,
// popups disabled, it's safe to use default implementation
return module.ModuleContext.EditUrl (keyName, keyValue, controlKey);
}
}

public static string FormatNiceDocumentUrl (string url, int moduleId, int tabId, int portalId, string resourceFile)
{
var label = string.Empty;
var title = string.Empty;

if (Globals.GetURLType (url) == TabType.File) {
var file = FileManager.Instance.GetFile (int.Parse (url.ToUpperInvariant ().Replace ("FILEID=", "")));
if (file != null) {
label = file.FileName;
title = file.RelativePath;
}
else {
label = Localization.GetString ("FileNotFound.Text", resourceFile);
}
}
else if (Globals.GetURLType (url) == TabType.Tab) {
var tab = TabController.Instance.GetTab (int.Parse (url), portalId);
if (tab != null) {
label = Localization.GetString ("Page.Text", resourceFile) + " " + tab.LocalizedTabName;
title = tab.TabPath.Replace ("//", "/");
}
else {
label = Localization.GetString ("PageNotFound.Text", resourceFile);
}
}
else {
label = HttpUtility.HtmlEncode (HtmlUtils.Shorten (url, 32, ""));
title = HttpUtility.HtmlAttributeEncode (url);
}

return $"<a href={LinkClickIdnHack (url, tabId, moduleId)} target=\"_blank\" title=\"{title}\">{label}</a>";
}
}
}

0 comments on commit e70ebea

Please sign in to comment.