Skip to content

Commit

Permalink
Make list of licenses configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
pezholio committed Apr 18, 2016
1 parent ac4ceb1 commit 56299db
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 33 deletions.
24 changes: 8 additions & 16 deletions _data/licenses.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
"https://creativecommons.org/licenses/by/4.0/":
Creative Commons Attribution
"https://creativecommons.org/licenses/by-sa/4.0/":
Creative Commons Attribution Share-Alike
"https://creativecommons.org/publicdomain/zero/1.0/":
Creative Commons CCZero
"https://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/":
UK Open Government Licence
"http://www.opendefinition.org/licenses/odc-by":
Open Data Commons Attribution License
"http://www.opendefinition.org/licenses/odc-odbl":
Open Data Commons Open Database License (ODbL)
"http://www.opendefinition.org/licenses/odc-pddl":
Open Data Commons Public Domain Dedication and Licence (PDDL)
"":
Not Applicable
'https://creativecommons.org/licenses/by/4.0/': Creative Commons Attribution
'https://creativecommons.org/licenses/by-sa/4.0/': Creative Commons Attribution Share-Alike
'https://creativecommons.org/publicdomain/zero/1.0/': Creative Commons CCZero
'https://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/': UK Open Government Licence
'http://www.opendefinition.org/licenses/odc-by': Open Data Commons Attribution License
'http://www.opendefinition.org/licenses/odc-odbl': Open Data Commons Open Database License (ODbL)
'http://www.opendefinition.org/licenses/odc-pddl': Open Data Commons Public Domain Dedication and Licence (PDDL)
'': Not Applicable
9 changes: 9 additions & 0 deletions _includes/admin-form-license.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<div class="well" data-hook="item">
<fieldset>
{% assign name = license[1] %}
{% include form/text.html field_label='License Name' field_name='licenses[][license_name]' value=name %}
{% assign url = license[0] %}
{% include form/text.html field_label='License URL' field_name='licenses[][license_url]' value=url %}
</fieldset>
<button type="button" class="btn btn-danger btn-sm" data-hook="remove-item-btn"><i class="fa fa-minus"></i> Remove</button>
</div>
4 changes: 2 additions & 2 deletions _includes/form/text.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="form-group">
<label for="{{ include.field_name }}">{{ include.field.label }}</label>
<label for="{{ include.field_name }}">{{ include.field.label | default: include.field_label }}</label>
<input type="text" class="form-control" id="{{ include.field_name }}" name="{{ include.field_name }}" placeholder="{{ include.field.placeholder | default include.field.label }}" value="{{ include.value }}">
</div>
</div>
28 changes: 28 additions & 0 deletions admin.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<li role="presentation" class="active"><a href="#general" aria-controls="general" role="tab" data-toggle="tab">General</a></li>
<li role="presentation"><a href="#authentication" aria-controls="authentication" role="tab" data-toggle="tab">Authentication</a></li>
<li role="presentation"><a href="#categories" aria-controls="categories" role="tab" data-toggle="tab">Categories</a></li>
<li role="presentation"><a href="#licenses" aria-controls="licenses" role="tab" data-toggle="tab">Licenses</a></li>
<li role="presentation"><a href="#theme" aria-controls="thtme" role="tab" data-toggle="tab">Theme</a></li>
<li role="presentation"><a href="#maintenance" aria-controls="maintenance" role="tab" data-toggle="tab">Maintenance</a></li>
</ul>
Expand Down Expand Up @@ -94,6 +95,33 @@ <h2>Categories</h2>
</form>
</div>

<div role="tabpanel" class="tab-pane" id="licenses">
<h2>Licenses</h2>
<form data-component="licenses-form editable-list" data-file-path="_data/licenses.yml" data-item-label="license">
<div data-hook="items">
{% for license in site.data.licenses %}
{% unless license[1] == 'Not Applicable' %}
{% include admin-form-license.html %}
{% endunless %}
{% endfor %}
</div>
<div class="form-group">
<button type="button" class="btn btn-default" data-hook="add-item-btn"><i class="fa fa-plus"></i> Add License</button>
</div>

<button type="submit" class="btn btn-primary">Submit</button>

<script type="text/template" data-hook="item-template">
{% include admin-form-license.html %}
</script>

<input type="hidden" name="licenses[][license_url]" value="" />
<input type="hidden" name="licenses[][license_name]" value="Not Applicable" />

</form>

</div>

<div role="tabpanel" class="tab-pane" id="theme">
<h2>Theme</h2>
<div class="theme-gallery" data-component="theme-gallery" data-file-path="_config.yml">
Expand Down
30 changes: 15 additions & 15 deletions scripts/dist/bundle.js

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions scripts/src/components/licenses-form.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import jsyaml from 'js-yaml'

import Form from './form'

export default class extends Form {
_formatData (formData) {
var list = {}
for(let license of formData.licenses) {
if (license.license_name != '') {
list[license.license_url] = license.license_name
}
}
return jsyaml.safeDump(list || [])
}
}
2 changes: 2 additions & 0 deletions scripts/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Form from './components/form'
import DatasetForm from './components/dataset-form'
import AdminForm from './components/admin-form'
import CategoriesForm from './components/categories-form'
import LicensesForm from './components/licenses-form'
import DatasetDisplay from './components/dataset-display'
import DeletePageButton from './components/delete-page-button'
import EditableList from './components/editable-list'
Expand Down Expand Up @@ -50,6 +51,7 @@ const components = [
{tag: 'dataset-form', class: DatasetForm},
{tag: 'admin-form', class: AdminForm},
{tag: 'categories-form', class: CategoriesForm},
{tag: 'licenses-form', class: LicensesForm},
{tag: 'dataset-display', class: DatasetDisplay},
{tag: 'delete-page-button', class: DeletePageButton},
{tag: 'editable-list', class: EditableList},
Expand Down

0 comments on commit 56299db

Please sign in to comment.