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

Fixes U4-7472 - Should be possible to sort macro parameters #932

Merged
merged 5 commits into from
Feb 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/Umbraco.Web.UI/umbraco/developer/Macros/editMacro.aspx
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@
<th>
<%=umbraco.ui.Text("general", "type",UmbracoUser)%>
</th>
<th>
<%=umbraco.ui.Text("general", "sort",UmbracoUser)%>
</th>
<th></th>
</tr>
</thead>
Expand All @@ -161,6 +164,11 @@
DataTextFormatString="" DataTextField='Name' DataValueField="Alias">
</asp:DropDownList>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ControlToValidate="macroPropertySortOrder" Display="Dynamic" ForeColor="#b94a48">Required<br/></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="macroPropertySortOrder" Display="Dynamic" ForeColor="#b94a48" ValidationExpression="^\d+$">Numbers only<br/></asp:RegularExpressionValidator>
<asp:TextBox runat="server" ID="macroPropertySortOrder" Text='<%#Eval("SortOrder")%>' />
</td>
<td>
<asp:Button OnClick="deleteMacroProperty" ID="delete" Text="Delete" runat="server" CssClass="btn btn-default delete-button" />
</td>
Expand All @@ -184,6 +192,9 @@
DataSource='<%# GetMacroParameterEditors()%>'>
</asp:DropDownList>
</td>
<td>
<%-- The macro parameter will automatically get sort order when created. --%>
</td>
<td>
<asp:Button ID="createNew" Text="Add" runat="server" CssClass="btn btn-default add-button" OnClick="macroPropertyCreate" />
</td>
Expand Down
3 changes: 2 additions & 1 deletion src/Umbraco.Web/Editors/MacroController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
Expand Down Expand Up @@ -34,7 +35,7 @@ public IEnumerable<MacroParameter> GetMacroParameters(int macroId)
throw new HttpResponseException(HttpStatusCode.NotFound);
}

return Mapper.Map<IEnumerable<MacroParameter>>(macro);
return Mapper.Map<IEnumerable<MacroParameter>>(macro).OrderBy(x => x.SortOrder);
}

/// <summary>
Expand Down
3 changes: 3 additions & 0 deletions src/Umbraco.Web/Models/ContentEditing/MacroParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public class MacroParameter

[DataMember(Name = "name")]
public string Name { get; set; }

[DataMember(Name = "sortOrder")]
public int SortOrder { get; set; }

/// <summary>
/// The editor view to render for this parameter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public void deleteMacroProperty(object sender, EventArgs e)

public void macroPropertyBind()
{
macroProperties.DataSource = _macro.Properties;
macroProperties.DataSource = _macro.Properties.OrderBy(x => x.SortOrder);
macroProperties.DataBind();
}

Expand Down Expand Up @@ -333,24 +333,25 @@ void Save_Click(object sender, EventArgs e)
SetMacroValuesFromPostBack(_macro, Convert.ToInt32(tempCachePeriod), tempMacroAssembly, tempMacroType);

// Save elements
var sort = 0;
foreach (RepeaterItem item in macroProperties.Items)
{
var macroPropertyId = (HtmlInputHidden)item.FindControl("macroPropertyID");
var macroElementName = (TextBox)item.FindControl("macroPropertyName");
var macroElementAlias = (TextBox)item.FindControl("macroPropertyAlias");
var macroElementSortOrder = (TextBox)item.FindControl("macroPropertySortOrder");
var macroElementType = (DropDownList)item.FindControl("macroPropertyType");

var prop = _macro.Properties.Single(x => x.Id == int.Parse(macroPropertyId.Value));

var sortOrder = 0;
int.TryParse(macroElementSortOrder.Text, out sortOrder);

_macro.Properties.UpdateProperty(
prop.Alias,
macroElementName.Text.Trim(),
sort,
sortOrder,
macroElementType.SelectedValue,
macroElementAlias.Text.Trim());

sort++;
}

Services.MacroService.Save(_macro);
Expand All @@ -368,6 +369,8 @@ void Save_Click(object sender, EventArgs e)
new LiteralControl("<br/><button onClick=\"UmbClientMgr.openModalWindow('developer/macros/assemblyBrowser.aspx?fileName=" + macroAssembly.Text +
"&macroID=" + Request.QueryString["macroID"] + "&type=" + macroType.Text +
"', 'Browse Properties', true, 500, 475); return false\" class=\"guiInputButton\"><img src=\"../../images/editor/propertiesNew.gif\" align=\"absmiddle\" style=\"width: 18px; height: 17px; padding-right: 5px;\"/> Browse properties</button>"));

macroPropertyBind();
}

/// <summary>
Expand Down