Skip to content
This repository has been archived by the owner on Jun 9, 2021. It is now read-only.

Commit

Permalink
Merge pull request #33 from contentful/update-diff-sample
Browse files Browse the repository at this point in the history
Updated the diff extension.
  • Loading branch information
floelhoeffel committed Jan 29, 2018
2 parents ad88b48 + f7c5ca8 commit 51c5ad2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 51 deletions.
41 changes: 4 additions & 37 deletions samples/diff/README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,12 @@
# Diff UI Extensions

[https://www.contentful.com](Contentful) is a content management platform for web applications, mobile apps and connected devices. It allows you to create, edit & manage content in the cloud and publish it anywhere via powerful API. Contentful offers tools for managing editorial teams and enabling cooperation between organizations.
The diff editor extension shows the diff between the draft value and the published value of a short text field.

![Screenshot of Diff extension](http://contentful.github.io/extensions/assets/diff-extension.png)

The diff editor extension shows the diff between the draft value and the published value of a short text field.

## Installation and usage

[Check you have the requirements needed](../README.md#extensions-samples) to use our extensions and [have the extensions SDK installed](https://github.com/contentful/ui-extensions-sdk).

Install the dependencies needed with `npm install`.

Create a _.env_ configuration file with your Contentful credentials:

```bash
export SPACE_ID=<space-id>
export CONTENTFUL_MANAGEMENT_ACCESS_TOKEN=<content-management-access-token>
```

Add the variables to your environment.

```bash
source .env
```

## Upload the extension to Contentful

Create the extension in the space specified in the _.env_ file:

```bash
npm run create
```
Check you have the [requirements](../README.md#requirements) needed to use extensions.

## Local development

Expand All @@ -41,22 +16,14 @@ Start a local server, changing the port if needed:
python -m SimpleHTTPServer 3030
```

Tell Contentful to render the widget from your local machine:
Don't use the `extension.json` descriptor file but instead use 3rd party hosting from `localhost`

```bash
npm run dev
contentful extension update --force --src 'http://localhost:3030/index.html' --id diff --name diff --field-types Symbol -field-types Text
```

The [same constraints](../README.md#debugging-on-your-local-environment) apply to loading unsafe scripts.

## Update the extension

If you want to update the extension, run:

```bash
npm run update
```

## Using the extension in the Contentful web app

Enable the extension in the Contentful web app for a "Short text" field by opening the _Settings_ for a field and selecting the widget in the _appearance_ tab.
9 changes: 8 additions & 1 deletion samples/diff/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,14 @@
// Load published value from CDA.
loadPublishedValue(entry.getSys().id)
.then(function (entries) {
publishedValue = entries.items[0].fields[fieldId][fieldLocale];
var field = entries.items[0].fields[fieldId];
if (field !== undefined) {
publishedValue = field[fieldLocale];
} else {
// An empty string was published.
publishedValue = "";
}

draftTextEl.disabled = false;
renderDiff();
}
Expand Down
15 changes: 2 additions & 13 deletions samples/diff/package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
{
"name": "draftPublishedDiff",
"name": "Diff extension for Contentful",
"version": "1.0.0",
"description": "Diffing UI extension for Contentful's web app.",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"create": "contentful-extension create --space-id $SPACE_ID",
"update": "contentful-extension update --space-id $SPACE_ID --force",
"dev": "contentful-extension update --space-id $SPACE_ID --force --src 'http://localhost:3030/index.html'"
},
"author": "frederik@contentful.com",
"license": "MIT",
"devDependencies": {
"contentful-extension-cli": "^2.0.0"
},
"dependencies": {
}
"license": "MIT"
}

0 comments on commit 51c5ad2

Please sign in to comment.