Skip to content

Commit

Permalink
readme
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanwoulfe committed Feb 7, 2020
1 parent 196cf62 commit 3a9ef4e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 21 deletions.
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
[![Build status](https://ci.appveyor.com/api/projects/status/5d665tl2a8x082be?svg=true)](https://ci.appveyor.com/project/nathanwoulfe/preserver)
[![NuGet release](https://img.shields.io/nuget/dt/Preserver.Umbraco.svg)](https://www.nuget.org/packages/Preserver.Umbraco)

# Preserver
# Preserver

Have you ever been hours deep in editing an Umbraco content item, only to have the cat chew through the PC power cable, sending all your work (and the cat) off into the great beyond?

It happens to the best of us.

While Preserver can't bring your cat back (and if Pet Sematary has taught us anything, necromancy isn't a wise option), it can restore your lost content. In fact, your content isn't lost at all, it's tucked away safely in your browser's local storage, waiting to be revived.

## Installation

Grab either the nuget package - `InstallPackage Preserver.Umbraco` - or the Umbraco zip from the releases tab or the Umbraco package repository. Easy!

## Setup

Preserver is a property editor. Given that, you'll need to create a new data type using the Preserver editor and add it to any document types where you want to enable content resuscitation. Doesn't matter which group, chuck it wherever - Preserver will hide itself in the editing view so you won't even realise it's in the background being awesome.

That's it. Done. When you're editing, Preserver will monitor the editor state, keeping a snapshot in local storage incase kitty gets chewy, or Windows decides to get all BSOD on you.

When the worst happens, and you crawl back to the content item to redo your glorious changes, Preserver will prompt to restore the lost data. Click ok, data comes back, cat is sill electrocuted (v2 feature => pet resurrection).
42 changes: 22 additions & 20 deletions src/Preserver/backoffice/editor.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
*
*/
const debounce = (callback, interval) => {
let timeout = null;
let timeout = null;

return () => {
$timeout.cancel(timeout);
timeout = $timeout(() => callback.apply(this, arguments), interval);
$timeout.cancel(timeout);
timeout = $timeout(() => callback.apply(this, arguments), interval);
}
};

Expand All @@ -22,7 +22,7 @@
*/
const findAncestor = (el, cls) => {
while ((el = el.parentElement) && !el.classList.contains(cls));
return el;
return el;
};


Expand All @@ -48,7 +48,7 @@
}
}


/**
*
*/
Expand Down Expand Up @@ -92,7 +92,7 @@
propElm.style.display = 'none';
if (!propElm.nextElementSibling) {
propElm.previousElementSibling.querySelector('.control-group').classList.add('p-last-child');
}
}
}

const fromStore = localStorage.getItem(dataKey);
Expand All @@ -101,7 +101,7 @@
key: 'preserver_notice',
view: `${Umbraco.Sys.ServerVariables.umbracoSettings.appPluginsPath}/preserver/backoffice/notification.html`
});
}
}


/**
Expand All @@ -124,20 +124,22 @@
* watch for change to the editor state, with a debounce to avoid over-zealous tracking
*/
var watcher;
$scope.$watch(() => editorState.current.variants.some(x => x.isDirty), dirty => {

if (dirty) {
watcher =
$scope.$watch(() => editorState.current.variants, debounce(() => {
if (editorState.current.variants.some(x => x.isDirty)) {
localStorage.setItem(dataKey, getBasicModel(editorState.current));
}
}, 300), true);
if (editorState.current.variants) {
$scope.$watch(() => editorState.current.variants.some(x => x.isDirty), dirty => {

if (dirty) {
watcher =
$scope.$watch(() => editorState.current.variants, debounce(() => {
if (editorState.current.variants.some(x => x.isDirty)) {
localStorage.setItem(dataKey, getBasicModel(editorState.current));
}
}, 300), true);

} else {
watcher ? watcher() : angular.noop();
}
});
} else {
watcher ? watcher() : angular.noop();
}
});
}
}

angular.module('preserver').controller('preserver.editor.controller',
Expand Down

0 comments on commit 3a9ef4e

Please sign in to comment.