move server calls to resource

This commit is contained in:
Mads Rasmussen
2018-11-06 21:24:55 +01:00
parent 5e884fe06c
commit 89266d4876
2 changed files with 73 additions and 22 deletions

View File

@@ -243,6 +243,77 @@ function codefileResource($q, $http, umbDataFormatter, umbRequestHelper) {
"PostCreateContainer",
{ type: type, parentId: parentId, name: encodeURIComponent(name) })),
'Failed to create a folder under parent id ' + parentId);
},
/**
* @ngdoc method
* @name umbraco.resources.codefileResource#interpolateStylesheetRules
* @methodOf umbraco.resources.codefileResource
*
* @description
* Takes all rich text editor styling rules and turns them into css
*
* ##usage
* <pre>
* codefileResource.interpolateStylesheetRules(".box{background:purple;}", "[{name: "heading", selector: "h1", styles: "color: red"}]")
* .then(function(data) {
* alert('its here!');
* });
* </pre>
*
* @param {string} content The style sheet content.
* @param {string} rules The rich text editor rules
* @returns {Promise} resourcePromise object.
*
*/
interpolateStylesheetRules: function (content, rules) {
var payload = {
content: content,
rules: rules
};
return umbRequestHelper.resourcePromise(
$http.post(
umbRequestHelper.getApiUrl(
"codeFileApiBaseUrl",
"PostInterpolateStylesheetRules"),
payload),
"Failed to interpolate sheet rules");
},
/**
* @ngdoc method
* @name umbraco.resources.codefileResource#extractStylesheetRules
* @methodOf umbraco.resources.codefileResource
*
* @description
* Find all rich text editor styles in the style sheets and turns them into "rules"
*
* ##usage
* <pre>
*
* var conntent
* codefileResource.extractStylesheetRules(".box{background:purple;}")
* .then(function(data) {
* alert('its here!');
* });
* </pre>
*
* @param {string} content The style sheet content.
* @returns {Promise} resourcePromise object.
*
*/
extractStylesheetRules: function(content) {
var payload = {
content: content,
rules: null
};
return umbRequestHelper.resourcePromise(
$http.post(
umbRequestHelper.getApiUrl(
"codeFileApiBaseUrl",
"PostExtractStylesheetRules"),
payload),
"Failed to extract style sheet rules");
}
};

View File

@@ -240,31 +240,11 @@
}
function interpolateRules() {
var payload = {
content: vm.stylesheet.content,
rules: vm.stylesheet.rules
};
return umbRequestHelper.resourcePromise(
$http.post(
umbRequestHelper.getApiUrl(
"codeFileApiBaseUrl",
"PostInterpolateStylesheetRules"),
payload),
"Failed to interpolate sheet rules");
return codefileResource.interpolateStylesheetRules(vm.stylesheet.content, vm.stylesheet.rules);
}
function extractRules() {
var payload = {
content: vm.stylesheet.content,
rules: null
};
return umbRequestHelper.resourcePromise(
$http.post(
umbRequestHelper.getApiUrl(
"codeFileApiBaseUrl",
"PostExtractStylesheetRules"),
payload),
"Failed to extract style sheet rules");
return codefileResource.extractStylesheetRules(vm.stylesheet.content, null);
}
$scope.selectApp = function (app) {