Merge pull request #1838 from umbraco/temp-u4-9665

u4-9665
This commit is contained in:
Shannon Deminick
2017-03-29 18:06:28 +11:00
committed by GitHub
6 changed files with 156 additions and 79 deletions

View File

@@ -2,13 +2,13 @@
* @ngdoc service
* @name umbraco.resources.macroResource
* @description Deals with data for macros
*
*
**/
function macroResource($q, $http, umbRequestHelper) {
//the factory object returned
return {
/**
* @ngdoc method
* @name umbraco.resources.macroResource#getMacroParameters
@@ -20,7 +20,7 @@ function macroResource($q, $http, umbRequestHelper) {
* @param {int} macroId The macro id to get parameters for
*
*/
getMacroParameters: function (macroId) {
getMacroParameters: function (macroId) {
return umbRequestHelper.resourcePromise(
$http.get(
umbRequestHelper.getApiUrl(
@@ -29,7 +29,7 @@ function macroResource($q, $http, umbRequestHelper) {
[{ macroId: macroId }])),
'Failed to retrieve macro parameters for macro with id ' + macroId);
},
/**
* @ngdoc method
* @name umbraco.resources.macroResource#getMacroResult
@@ -55,6 +55,27 @@ function macroResource($q, $http, umbRequestHelper) {
macroParams: macroParamDictionary
}),
'Failed to retrieve macro result for macro with alias ' + macroAlias);
},
/**
*
* @param {} filename
* @returns {}
*/
createPartialViewMacroWithFile: function(parent, filename) {
return umbRequestHelper.resourcePromise(
$http.post(
umbRequestHelper.getApiUrl(
"macroApiBaseUrl",
"CreatePartialViewMacroWithFile"), {
parent: parent,
filename: filename
}
),
'Failed to create macro "' + filename + '"'
);
}
};
}

View File

@@ -1,47 +1,42 @@
(function () {
"use strict";
function PartialViewMacrosCreateController($scope, codefileResource, $location, navigationService, formHelper, localizationService, appState) {
function PartialViewMacrosCreateController($scope, codefileResource, macroResource, $location, navigationService, formHelper, localizationService, appState) {
var vm = this;
var node = $scope.dialogOptions.currentNode;
var localizeCreateFolder = localizationService.localize("defaultdialog_createFolder");
vm.snippets = [];
vm.showSnippets = false;
vm.creatingFolder = false;
vm.snippet = "Empty";
vm.createMacro = false;
vm.createFolderError = "";
vm.folderName = "";
vm.fileName = "";
vm.creatingFolder = false;
vm.creatingFile = false;
vm.createPartialViewMacro = createPartialViewMacro;
vm.showCreateFolder = showCreateFolder;
vm.showCreateFile = showCreateFile;
vm.createFolder = createFolder;
vm.showCreateFromSnippet = showCreateFromSnippet;
vm.createFile = createFile;
function onInit() {
codefileResource.getSnippets('partialViewMacros')
.then(function(snippets) {
.then(function (snippets) {
vm.snippets = snippets;
});
}
function createPartialViewMacro(selectedSnippet) {
var snippet = null;
if(selectedSnippet && selectedSnippet.fileName) {
snippet = selectedSnippet.fileName;
}
$location.path("/developer/partialviewmacros/edit/" + node.id).search("create", "true").search("snippet", snippet);
navigationService.hideMenu();
}
function showCreateFolder() {
vm.creatingFolder = true;
}
function showCreateFile() {
vm.creatingFile = true;
}
function createFolder(form) {
if (formHelper.submitForm({scope: $scope, formCtrl: form, statusMessage: localizeCreateFolder})) {
@@ -75,11 +70,32 @@
});
}
}
function showCreateFromSnippet() {
vm.showSnippets = true;
function createFile(form) {
if (formHelper.submitForm({ scope: $scope, formCtrl: form, statusMessage: 'create file' })) {
if (vm.createMacro) {
var path = decodeURIComponent(node.id);
macroResource.createPartialViewMacroWithFile(path, vm.fileName).then(function(created) {
$location.path("/developer/partialviewmacros/edit/" + node.id).search("create", "true").search("name", vm.fileName).search("snippet", vm.snippet);
navigationService.hideMenu();
}, function(err) {
vm.createFileError = err;
//show any notifications
if (angular.isArray(err.data.notifications)) {
for (var i = 0; i < err.data.notifications.length; i++) {
notificationsService.showNotification(err.data.notifications[i]);
}
}
});
} else {
$location.path("/developer/partialviewmacros/edit/" + node.id).search("create", "true").search("name", vm.fileName).search("snippet", vm.snippet);
navigationService.hideMenu();
}
}
}
onInit();
}

View File

@@ -2,46 +2,61 @@
<div class="umbracoDialog umb-dialog-body with-footer">
<div class="umb-pane" ng-if="!vm.creatingFolder">
<div class="umb-pane" ng-if="!vm.creatingFolder && !vm.creatingFile">
<h5><localize key="create_createUnder">Create an item under</localize> {{currentNode.name}}</h5>
<!-- Main options -->
<div ng-if="!vm.showSnippets">
<ul class="umb-actions umb-actions-child">
<li>
<a href="" ng-click="vm.createPartialViewMacro()" umb-auto-focus>
<i class="large icon-article"></i>
<span class="menu-label"><localize key="create_newEmptyPartialViewMacro">New empty partial view macro</localize></span>
</a>
</li>
<li>
<a href="" ng-click="vm.showCreateFromSnippet()">
<i class="large icon-article"></i>
<span class="menu-label"><localize key="create_newPartialViewMacroFromSnippet">New partial view macro from snippet</localize></span>
</a>
</li>
<li>
<a href="" ng-click="vm.showCreateFolder()">
<i class="large icon-folder"></i>
<span class="menu-label"><localize key="general_folder"></localize></span>
</a>
</li>
</ul>
</div>
<ul class="umb-actions umb-actions-child">
<li>
<a href="" ng-click="vm.showCreateFile()" umb-auto-focus>
<i class="large icon-article"></i>
<span class="menu-label"><localize key="create_newPartialViewMacro">New partial view macro</localize></span>
</a>
</li>
<li>
<a href="" ng-click="vm.showCreateFolder()">
<i class="large icon-folder"></i>
<span class="menu-label"><localize key="general_folder"></localize></span>
</a>
</li>
</ul>
<!-- Snippets list -->
<div ng-if="vm.showSnippets">
<ul class="umb-actions umb-actions-child">
<li ng-repeat="snippet in vm.snippets">
<a href="" ng-click="vm.createPartialViewMacro(snippet)" style="padding-top: 6px; padding-bottom: 6px;">
<i class="icon-article" style="font-size: 20px;"></i>
<span class="menu-label" style="margin-left: 0; padding-left: 5px;">{{ snippet.name }}</span>
</a>
</li>
</ul>
</div>
</div>
<!-- Create file -->
<div class="umb-pane" ng-if="vm.creatingFile">
<form novalidate name="createFileForm"
ng-submit="vm.createFile(createFileForm)"
val-form-manager>
<div ng-show="vm.createFileError">
<h5 class="text-error">{{vm.createFileError.errorMsg}}</h5>
<p class="text-error">{{vm.createFileError.data.message}}</p>
</div>
<umb-control-group label="Enter a file name" hide-label="false">
<input type="text" name="fileName" ng-model="vm.fileName" class="umb-textstring textstring input-block-level" umb-auto-focus required no-dirty-check />
<div>
<label class="checkbox">
<input type="checkbox" name="createMacro" ng-model="vm.createMacro" ng-true-value="true" ng-false-value="false" no-dirty-check/>
Create corresponding macro
</label>
</div>
</umb-control-group>
<umb-control-group label="Select a snippet (or create an empty file)" hide-label="false">
<select name="snippet"
class="umb-editor umb-dropdown"
ng-model="vm.snippet"
ng-options="snippet.fileName as snippet.name for snippet in vm.snippets"></select>
</umb-control-group>
<button type="submit" class="btn btn-primary"><localize key="general_create">Create</localize></button>
</form>
</div>
<!-- Create folder -->
@@ -49,14 +64,14 @@
<form novalidate name="createFolderForm"
ng-submit="vm.createFolder(createFolderForm)"
val-form-manager>
<div ng-show="vm.createFolderError">
<h5 class="text-error">{{vm.createFolderError.errorMsg}}</h5>
<p class="text-error">{{vm.createFolderError.data.message}}</p>
</div>
<umb-control-group label="Enter a folder name" hide-label="false">
<input type="text" name="folderName" ng-model="vm.folderName" class="umb-textstring textstring input-block-level" umb-auto-focus required />
<input type="text" name="folderName" ng-model="vm.folderName" class="umb-textstring textstring input-block-level" umb-auto-focus required no-dirty-check />
</umb-control-group>
<button type="submit" class="btn btn-primary"><localize key="general_create">Create</localize></button>

View File

@@ -26,7 +26,7 @@
/* Functions bound to view model */
function save() {
vm.page.saveButtonState = "busy";
vm.partialViewMacro.content = vm.editor.getValue();
@@ -70,7 +70,7 @@
}, function (err) {
vm.page.saveButtonState = "error";
localizationService.localize("speechBubbles_validationFailedHeader").then(function (headerValue) {
localizationService.localize("speechBubbles_validationFailedMessage").then(function(msgValue) {
notificationsService.error(headerValue, msgValue);
@@ -104,7 +104,7 @@
var code = templateHelper.getInsertDictionarySnippet(model.insert.node.name);
insert(code);
break;
case "umbracoField":
insert(model.insert.umbracoField);
break;
@@ -169,7 +169,7 @@
vm.pageFieldOverlay.show = false;
vm.pageFieldOverlay = null;
// focus editor
vm.editor.focus();
vm.editor.focus();
}
};
}
@@ -212,7 +212,7 @@
var code = templateHelper.getQuerySnippet(model.result.queryExpression);
insert(code);
vm.queryBuilderOverlay.show = false;
vm.queryBuilderOverlay = null;
},
@@ -222,7 +222,7 @@
vm.queryBuilderOverlay.show = false;
vm.queryBuilderOverlay = null;
// focus editor
vm.editor.focus();
vm.editor.focus();
}
};
}
@@ -232,9 +232,9 @@
function init() {
//we need to load this somewhere, for now its here.
assetsService.loadCss("lib/ace-razor-mode/theme/razor_chrome.css");
if ($routeParams.create) {
var snippet = "Empty";
if($routeParams.snippet) {
@@ -242,6 +242,9 @@
}
codefileResource.getScaffold("partialViewMacros", $routeParams.id, snippet).then(function (partialViewMacro) {
if ($routeParams.name) {
partialViewMacro.name = $routeParams.name;
}
ready(partialViewMacro, false);
});
@@ -276,7 +279,7 @@
},
onLoad: function(_editor) {
vm.editor = _editor;
// initial cursor placement
// Keep cursor in name field if we are create a new template
// else set the cursor at the bottom of the code editor
@@ -316,7 +319,7 @@
}
function setFormState(state) {
// get the current form
var currentForm = angularHelper.getCurrentForm($scope);
@@ -328,7 +331,7 @@
}
}
init();
}

View File

@@ -201,6 +201,7 @@
<key alias="newDataType">New data type</key>
<key alias="newJavascriptFile">New javascript file</key>
<key alias="newEmptyPartialView">New empty partial view</key>
<key alias="newPartialViewMacro">New partial view macro</key>
<key alias="newPartialViewFromSnippet">New partial view from snippet</key>
<key alias="newEmptyPartialViewMacro">New empty partial view macro</key>
<key alias="newPartialViewMacroFromSnippet">New partial view macro from snippet</key>

View File

@@ -10,6 +10,7 @@ using Umbraco.Web.Models.ContentEditing;
using Umbraco.Web.Mvc;
using umbraco;
using Umbraco.Core;
using Umbraco.Core.Models;
namespace Umbraco.Web.Editors
{
@@ -29,7 +30,7 @@ namespace Umbraco.Web.Editors
/// </summary>
/// <returns></returns>
/// <remarks>
/// Note that ALL logged in users have access to this method because editors will need to isnert macros into rte (content/media/members) and it's used for
/// Note that ALL logged in users have access to this method because editors will need to isnert macros into rte (content/media/members) and it's used for
/// inserting into templates/views/etc... it doesn't expose any sensitive data.
/// </remarks>
public IEnumerable<MacroParameter> GetMacroParameters(int macroId)
@@ -50,9 +51,9 @@ namespace Umbraco.Web.Editors
/// <param name="pageId"></param>
/// <param name="macroParams">
/// To send a dictionary as a GET parameter the query should be structured like:
///
///
/// ?macroAlias=Test&pageId=3634&macroParams[0].key=myKey&macroParams[0].value=myVal&macroParams[1].key=anotherKey&macroParams[1].value=anotherVal
///
///
/// </param>
/// <returns></returns>
[HttpGet]
@@ -129,6 +130,26 @@ namespace Umbraco.Web.Editors
"text/html");
return result;
}
[HttpPost]
public HttpResponseMessage CreatePartialViewMacroWithFile(CreatePartialViewMacroWithFileModel model)
{
var macro = new Macro
{
Alias = model.Filename,
Name = model.Filename, // will be "aliased"
ScriptPath = "~/Views/MacroPartials/" + model.Parent + "/" + model.Filename + ".cshtml"
};
Services.MacroService.Save(macro); // may throw
return new HttpResponseMessage(HttpStatusCode.OK);
}
public class CreatePartialViewMacroWithFileModel
{
public string Parent { get; set; }
public string Filename { get; set; }
}
}
}