diff --git a/_config.yml b/_config.yml
index c866fcdd9..5f686dcc7 100644
--- a/_config.yml
+++ b/_config.yml
@@ -41,7 +41,8 @@ collections:
output: true
permalink: /datasets/:path/
organizations:
- output: false
+ output: true
+ permalink: /organizations/:path/
# Collections (cont'd)
defaults:
@@ -52,6 +53,11 @@ defaults:
layout: dataset
category: Uncategorized
organization: N/A
+ - scope:
+ path: ""
+ type: organizations
+ values:
+ layout: organization
# Markdown settings
markdown: kramdown
diff --git a/_data/schemas/default.yml b/_data/schemas/default.yml
index bbbed08d9..ce3d6a004 100644
--- a/_data/schemas/default.yml
+++ b/_data/schemas/default.yml
@@ -45,3 +45,11 @@ resource_fields:
- kmz
- shp
- xml
+
+organization_fields:
+ - field_name: title
+ label: Title
+ - field_name: description
+ label: Description
+ - field_name: logo
+ label: Logo
diff --git a/_includes/organization-form.html b/_includes/organization-form.html
new file mode 100644
index 000000000..110100ca9
--- /dev/null
+++ b/_includes/organization-form.html
@@ -0,0 +1,17 @@
+
+ {% if page.logo %}
+
+

+
+
+ {% else %}
+
+ {% endif %}
+
+ {{ page.title }}
+ Edit
+
+
{{ page.description }}
+ {% assign dataset_count = site.datasets | where: "organization", page.title | size %}
+
{{ dataset_count }} datasets
+
+
+
+
+
+ {% include organization-form.html organization=page %}
+
+
+
+
+
diff --git a/css/main.css b/css/main.css
index 7481a0b71..b8538412e 100644
--- a/css/main.css
+++ b/css/main.css
@@ -36,6 +36,7 @@ dataset {
/* Hidden from guests */
.add-dataset-btn,
.edit-dataset-btn,
+.edit-organization-btn,
.admin-link-list-item,
.user-issue {
display: none;
diff --git a/scripts/src/index.js b/scripts/src/index.js
index 2b58a5e86..d70321e2f 100644
--- a/scripts/src/index.js
+++ b/scripts/src/index.js
@@ -9,6 +9,7 @@ import NavView from './views/nav'
import DatasetsView from './views/datasets'
import DatasetView from './views/dataset'
import AddDatasetView from './views/add-dataset'
+import OrganizationView from './views/organization'
import AdminView from './views/admin'
import SetupView from './views/setup'
import {queryByHook, setParams} from './util'
@@ -61,6 +62,16 @@ const router = {
})
AddDatasetView({el: elements.main, file})
},
+ '/organizations/(.+)/': function () {
+ const file = new FileModel({
+ user,
+ repoOwner: settings.REPO_OWNER,
+ repoName: settings.REPO_NAME,
+ repoBranch: settings.BRANCH,
+ filePath: settings.FILE_PATH
+ })
+ OrganizationView({el: elements.main, user, file})
+ },
'/admin/': function () {
const file = new FileModel({
user,
diff --git a/scripts/src/views/organization.js b/scripts/src/views/organization.js
new file mode 100644
index 000000000..76d00adca
--- /dev/null
+++ b/scripts/src/views/organization.js
@@ -0,0 +1,68 @@
+import {queryByHook} from '../util'
+
+export default function (opts) {
+ const elements = {
+ editButton: queryByHook('edit-button', opts.el),
+ readView: queryByHook('read-view', opts.el),
+ editView: queryByHook('edit-view', opts.el),
+ form: queryByHook('organization-form', opts.el),
+ cancelButton: queryByHook('cancel-button', opts.el),
+ deleteButton: queryByHook('delete-button', opts.el),
+ alert: queryByHook('alert', opts.el),
+ commitUrl: queryByHook('commit-url', opts.el)
+ }
+
+ // If user is logged in and a collaborator, show the Edit Dataset button
+ if (opts.user.username && opts.user.isCollaborator) elements.editButton.show()
+ opts.user.on('change', (user) => {
+ if (user.username && user.isCollaborator) elements.editButton.show()
+ })
+
+ // Edit/Cancel buttons toggle read/edit views
+ elements.editButton.add(elements.cancelButton).on('click', (e) => {
+ switchView()
+ e.preventDefault()
+ })
+
+ // Edit form submission
+ elements.form.on('submit', function (e) {
+ const formData = elements.form.serializeJSON({useIntKeysAsArrayIndex: true})
+ const yaml = opts.file.formatFrontMatter(formData)
+ opts.file.save(yaml)
+ .then((response) => {
+ switchView()
+ alert('success', response.commit.html_url)
+ }).catch((msg) => {
+ alert('error')
+ console.error(msg)
+ })
+ e.preventDefault()
+ })
+
+ // Delete button
+ elements.deleteButton.on('click', function (e) {
+ if (window.confirm('Delete this organization?')) {
+ opts.file.remove()
+ .then((response) => {
+ alert('success', response.commit.html_url)
+ }).catch((msg) => {
+ alert('error')
+ console.error(msg)
+ })
+ }
+ e.preventDefault()
+ })
+
+ function switchView () {
+ elements.readView.add(elements.editView).toggle()
+ }
+
+ // Show alert box on page
+ function alert (type, commitUrl) {
+ elements.alert.hide()
+ $('[data-hook~=alert-' + type +']').show()
+ if (type === 'success' && commitUrl) {
+ elements.commitUrl.attr('href', commitUrl)
+ }
+ }
+}