Skip to content

Instantly share code, notes, and snippets.

View nathanwoulfe's full-sized avatar

Nathan Woulfe nathanwoulfe

View GitHub Profile
@nathanwoulfe
nathanwoulfe / parent-scope.js
Created April 3, 2023 08:48
Get ancestor scope in AngularJs
  getEditorScope = $scope => {
    let editorScope = $scope.$parent;
    do {
      editorScope = editorScope.$parent;
    } while (!Object.prototype.hasOwnProperty.call(editorScope, 'contentForm'));
    this.editorScope = editorScope;
  }
@nathanwoulfe
nathanwoulfe / scripts.sql
Created October 19, 2022 06:52
Inheritance to composition
-- CREATES THE COMPOSITION FROM THE INHERITED TYPE
DECLARE @CompositionId int;
DECLARE @CompositionsFolder int;
DECLARE @PropertyTab int;
DECLARE @CompositionGUID uniqueidentifier;
-- Generate a unique guid for the metadata composition
SET @CompositionGUID = 'f583bcf5-b007-47d4-992e-c193f225f76c'
DECLARE @PropertyTagGUID uniqueidentifier;
@nathanwoulfe
nathanwoulfe / change-content-type.cs
Created March 15, 2022 21:34
Change content type via reflection
public class ChangeContentTypeController : UmbracoAuthorizedApiController
{
private readonly IContentTypeService _contentTypeService;
private readonly IContentService _contentService;
public ChangeContentTypeController(IContentTypeService contentTypeService, IContentService contentService) {
_contentTypeService = contentTypeService;
_contentService = contentService;
}
@nathanwoulfe
nathanwoulfe / test.cs
Created April 12, 2021 23:57
Mock IUmbracoContextFactory
private readonly IUmbracoContextFactory _context;
private readonly string _pluginPath;
public LicensingService(ILogger logger, IUmbracoContextFactory context) : base(logger)
{
_context = context ?? throw new ArgumentNullException(nameof(context));
_pluginPath = $"{IOHelper.ResolveUrl(SystemDirectories.AppPlugins).TrimEnd('/')}/plumber/";
}
public Tuple<string, string> GetLicenseAndKey() {
@nathanwoulfe
nathanwoulfe / test-content-event-component.cs
Created November 24, 2020 23:01
Minimal component for testing
using System;
using System.Linq;
using System.Web.Http.Filters;
using Umbraco.Core;
using Umbraco.Core.Composing;
using Umbraco.Web.Editors;
using Umbraco.Web.Models.ContentEditing;
namespace Foo.Bar.AppCode
{
@nathanwoulfe
nathanwoulfe / nested-form.js
Created June 13, 2020 07:12
How clean are my children?
this.workflowResource.saveNodeConfig(this.node.id, this.approvalPath, this.variant)
.then(() => {
this.notificationsService.success('SUCCESS', 'Workflow configuration updated');
this.$rootScope.$broadcast('configUpdated');
this.$scope.contentFlowForm.$setPristine();
// shouldn't need to do this...
// check that all child forms of the contentForm are pristine, then reset contentForm
let parentPristine = this.$scope.contentFlowForm.$$parentForm.$$controls
.filter(c => Object.prototype.hasOwnProperty.call(c, '$submitted'))
@nathanwoulfe
nathanwoulfe / compile.js
Created May 18, 2020 23:24
Compiling HTML into the Umbraco 8 backoffice
// in u7 we could grab scope off any element via angular.element('selector').scope()
// not the case in u8, since debugInfoEnabled has been set to false (which is a good thing)
// this is happening in the context of a content app controller
// but could be refactored to working with an interceptor
export class AppController {
constructor($scope, $compile, $element) {
// from the content app scope, find the content form scope
@nathanwoulfe
nathanwoulfe / render-macros.cs
Last active March 2, 2020 23:02
Processing Umbraco macros
///
/// Extension on UmbracoHelper to return a processed macro as a string...
///
public static IHtmlString RenderMacroScript(this UmbracoHelper helper, string language, string fileLocation, IDictionary<string, object> parameters)
{
var ctrl = new umbraco.presentation.templateControls.Macro
{
Language = language,
FileLocation = fileLocation,
};
@nathanwoulfe
nathanwoulfe / angularjs-events.js
Created February 6, 2020 01:52
Log all events in an AngularJs application
angular.module('myModule', [])
.config(['$provide', $provide => {
$provide.decorator("$rootScope", function ($delegate) {
var Scope = $delegate.constructor;
var origBroadcast = Scope.prototype.$broadcast;
var origEmit = Scope.prototype.$emit;
Scope.prototype.$broadcast = function () {
console.log("$broadcast was called on $scope " + Scope.$id + " with arguments:", arguments);
return origBroadcast.apply(this, arguments);
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Web.Http;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Services;
using Umbraco.Web;
using Umbraco.Web.WebApi;