add support for getScaffold for scripts, partialViews and partialViewMacros editor

This commit is contained in:
Mads Rasmussen
2017-02-01 13:54:16 +01:00
parent 6a1d7d2586
commit e439302b93
4 changed files with 56 additions and 37 deletions

View File

@@ -77,39 +77,6 @@ function codefileResource($q, $http, umbDataFormatter, umbRequestHelper) {
"Failed to retrieve data for template with alias: " + alias);
},
/**
* @ngdoc method
* @name umbraco.resources.codefileResource#getScaffold
* @methodOf umbraco.resources.codefileResource
*
* @description
* Returns a scaffold of an empty codefile item
*
* The scaffold is used to build editors for code file editors that has not yet been populated with data.
*
* ##usage
* <pre>
* codefileResource.getScaffold()
* .then(function(template) {
* alert('its here!');
* });
* </pre>
*
* @returns {Promise} resourcePromise object containing the codefile scaffold.
*
*/
getScaffold: function (id) {
return umbRequestHelper.resourcePromise(
$http.get(
umbRequestHelper.getApiUrl(
"templateApiBaseUrl",
"GetScaffold",
[{ id: id }])),
"Failed to retrieve data for empty template");
},
/**
* @ngdoc method
* @name umbraco.resources.codefileResource#deleteByPath
@@ -188,7 +155,7 @@ function codefileResource($q, $http, umbDataFormatter, umbRequestHelper) {
*
* ##usage
* <pre>
* codefileResource.getSnippets(fileType)
* codefileResource.getSnippets("partialViews")
* .then(function(snippets) {
* alert('its here!');
* });
@@ -205,6 +172,39 @@ function codefileResource($q, $http, umbDataFormatter, umbRequestHelper) {
"codeFileApiBaseUrl",
"GetSnippets?type=" + fileType )),
"Failed to get snippet for" + fileType);
},
/**
* @ngdoc method
* @name umbraco.resources.codefileResource#getScaffold
* @methodOf umbraco.resources.codefileResource
*
* @description
* Returns a scaffold of an empty codefile item.
*
* The scaffold is used to build editors for code file editors that has not yet been populated with data.
*
* ##usage
* <pre>
* codefileResource.getScaffold("partialViews", "Breadcrumb")
* .then(function(data) {
* alert('its here!');
* });
* </pre>
*
* @param {string} File type: (scripts, partialViews, partialViewMacros).
* @param {string} Snippet name (Ex. Breadcrumb).
* @returns {Promise} resourcePromise object.
*
*/
getScaffold: function (type, snippetName) {
return umbRequestHelper.resourcePromise(
$http.get(
umbRequestHelper.getApiUrl(
"codeFileApiBaseUrl",
"GetScaffold?type=" + type + "&snippetName=" + snippetName)),
"Failed to get scaffold for" + type);
}
};

View File

@@ -227,10 +227,19 @@
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) {
codefileResource.getScaffold().then(function (partialViewMacro) {
var snippet = "Empty";
if($routeParams.snippet) {
snippet = $routeParams.snippet;
}
codefileResource.getScaffold("partialViewMacros", snippet).then(function (partialViewMacro) {
ready(partialViewMacro);
});
} else {
codefileResource.getByPath('partialViewMacros', $routeParams.id).then(function (partialViewMacro) {
ready(partialViewMacro);

View File

@@ -227,15 +227,25 @@
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) {
codefileResource.getScaffold().then(function (partialView) {
var snippet = "Empty";
if($routeParams.snippet) {
snippet = $routeParams.snippet;
}
codefileResource.getScaffold("partialViews", snippet).then(function (partialView) {
ready(partialView);
});
} else {
codefileResource.getByPath('partialViews', $routeParams.id).then(function (partialView) {
ready(partialView);
});
}
}
function ready(partialView) {

View File

@@ -79,7 +79,7 @@
assetsService.loadCss("lib/ace-razor-mode/theme/razor_chrome.css");
if ($routeParams.create) {
codefileResource.getScaffold().then(function (script) {
codefileResource.getScaffold("scripts").then(function(script) {
ready(script);
});
} else {