Skip to content

Instantly share code, notes, and snippets.

@sbosell
sbosell / app.js
Last active August 29, 2015 13:56
App Config for Umbraco Angular SPA
angular.module('darkweekend', ['ngRoute', 'ngAnimate', 'ui.router', 'dw.controllers', 'dw.services'])
.config(['$urlRouterProvider', '$stateProvider', '$locationProvider', function ($urlRouterProvider, $stateProvider, $locationProvider) {
//$urlRouterProvider.otherwise("/ab"); $locationProvider.html5Mode(true);
$locationProvider.html5Mode(true);
$stateProvider
.state("home", {
url: "*path",
templateProvider: function (templateService, contentService, $q, $stateParams) {
var d = $q.defer();
@sbosell
sbosell / Content.cshtml
Created February 17, 2014 14:57
Content View
@inherits Umbraco.Web.Mvc.UmbracoViewPage<AngRenderModel>
@{
Layout = Model.isApp ? "Blank.cshtml" : "Static.cshtml";
}
@section Content {
@if(Model.isApp) {
<div ng-bind-html="html(content.body)"></div>
<img umb-media="content.Properties.image.DataValue" />
@sbosell
sbosell / routecontroller.js
Created February 17, 2014 15:24
RouteController
//
app.controller('RouteController', ['$scope', 'PublishedContent', '$sce', 'contentService', function ($scope, PublishedContent, $sce, contentService) {
// we set the content to be the published content. Now the view has access to all of its properties.
$scope.content = PublishedContent;
$scope.html = function (s) {
return $sce.trustAsHtml(s);
}
}]);
angular.module('dw.controllers', ['dw.services']).
controller('AppController', ['$rootScope', '$scope', '$location', '$routeParams', 'contentService', function ($rootScope, $scope, $location, $routeParams, contentService) {
$rootScope.safeApply = function (fn) {
var phase = this.$root.$$phase;
if (phase == '$apply' || phase == '$digest') {
if (fn && (typeof (fn) === 'function')) {
fn();
}
} else {
@sbosell
sbosell / services.js
Created February 17, 2014 22:16
Umbraco Angular Services
angular.module('dw.services', [])
.value('serviceBase', "/umbraco/api/pagegenapi/")
.factory('serviceApi', ['serviceBase', function (serviceBase) {
var service = {
base: serviceBase,
getMedia: serviceBase + 'GetMedia',
getContent: serviceBase + 'getContent',
getPath: serviceBase + 'getPage',
getChildren: serviceBase + 'getChildren'
@sbosell
sbosell / umbnode.js
Created February 17, 2014 22:34
Umbraco node values
{
"Id": 1053,
"Name": "Site",
"Url": "/",
"Path": "-1,1053",
"ContentTypeAlias": "SiteMaster",
"Properties": {
"umbracoRedirect": {
"DataValue": "",
"HasValue": false,
@sbosell
sbosell / PageApiGenController.cs
Created February 17, 2014 23:28
Umbraco Angular MVC Controllers
namespace MvcApplication1.Controllers
{
// mvc needs a class to serialize a post, this is for a url
public class UrlModel
{
public string url { get; set; }
}
// id class for post
public class IdModel
@sbosell
sbosell / PageViewModel.cs
Created February 17, 2014 23:31
Umbraco Angular PageViewModel
namespace MvcApplication1.Models
{
public class PropertyViewModel
{
public object DataValue { get; set; }
public bool HasValue { get; set; }
public string PropertyTypeAlias { get; set; }
public object Value { get; set; }
public object XPathValue { get; set; }
@sbosell
sbosell / angrendermodel.cs
Created February 17, 2014 23:52
Umbraco Angular AngRenderModel
namespace App.Models
{
public class AngRenderModel : Umbraco.Web.Models.RenderModel
{
public bool isApp { get; set; }
public AngRenderModel(): base(UmbracoContext.Current.PublishedContentRequest.PublishedContent)
{
}
}
@sbosell
sbosell / DefaultController.js
Created February 17, 2014 23:59
Umbraco Angular Default Controller
namespace MvcApplication1.Controllers
{
public class DefaultController : Umbraco.Web.Mvc.RenderMvcController
{
//
// GET: /Default/
public ActionResult Index(AngRenderModel model)
{