From 0810b806f7605a75b080ea4a6fc9010c6552095c Mon Sep 17 00:00:00 2001 From: Sean Fridman Date: Sat, 11 Apr 2015 01:41:34 -0400 Subject: Implement admin interface resource reordering --- examples/db.json | 63 +++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 53 insertions(+), 10 deletions(-) (limited to 'examples/db.json') diff --git a/examples/db.json b/examples/db.json index 148391a..20d4510 100644 --- a/examples/db.json +++ b/examples/db.json @@ -3,8 +3,8 @@ "bread": [ { "type": "pretzel", - "description": "really a very tasty bread! yup yes", - "color": "green", + "description": "really a very tasty bread!", + "color": "red", "id": "pretzel", "title": "Pretzel Chips", "images": [ @@ -23,7 +23,8 @@ "token": "", "title": "", "thumb": "" - } + }, + "__index": 0 }, { "type": "bagel", @@ -38,31 +39,73 @@ "token": "112498725", "title": "FW14-2H-VIDEO-V4 2", "thumb": "http://i.vimeocdn.com/video/497493142_640.jpg" - } + }, + "__index": 1 }, { "type": "pumpernickel", - "description": "grandma's recipe", + "description": "yup", "id": "pumpernickel", - "title": "Pumpernickel", + "title": "ok", "images": [ { "uri": "cool", "caption": "cool" } - ] + ], + "color": "red", + "video": { + "url": "", + "type": "", + "token": "", + "title": "", + "thumb": "" + }, + "__index": 2 + }, + { + "type": "cracker", + "title": "", + "description": "once upon a time this noble creature etc", + "color": "red", + "video": { + "url": "", + "type": "", + "token": "", + "title": "", + "thumb": "" + }, + "__index": 4, + "id": "cracker" + }, + { + "type": "croissant", + "title": "", + "description": "wow just wow", + "color": "red", + "video": { + "url": "", + "type": "", + "token": "", + "title": "", + "thumb": "" + }, + "__index": 3, + "id": "croissant" } ], "page": [ { "title": "About Us", "body": "Just a small bakery", - "id": "about" + "id": "about", + "__index": 1 }, { - "title": "contact", + "title": "ok...", "body": "2406 Old Rd, San Juan Bautista", - "id": "contact" + "id": "contact", + "__index": 0 } ] } \ No newline at end of file -- cgit v1.2.3-70-g09d2 From 8898bbe48285c7f9f11760ef420cca43d683d5e0 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Mon, 28 Mar 2016 13:59:50 -0400 Subject: modify links field to specify text and uri --- app/index.js | 1 + app/node_modules/okdb/index.js | 2 +- app/node_modules/okschema/index.js | 17 +++++++- examples/db.json | 9 +++- examples/index.js | 5 ++- package.json | 2 +- themes/okadmin/public/css/main.css | 8 ++++ themes/okadmin/public/js/app.js | 34 ++++++--------- themes/okadmin/templates/partials/inputs.liquid | 56 +++++++++++++++++++------ 9 files changed, 93 insertions(+), 41 deletions(-) (limited to 'examples/db.json') diff --git a/app/index.js b/app/index.js index 6a1c74f..06b1591 100644 --- a/app/index.js +++ b/app/index.js @@ -28,6 +28,7 @@ function OKCMS(options) { var app = express(); app.enable('strict routing'); + app.disable('x-powered-by'); var root = this._root = options.root || 'public'; var adminConfig = options.admin || {}; diff --git a/app/node_modules/okdb/index.js b/app/node_modules/okdb/index.js index 4820c8c..ad8d9a7 100644 --- a/app/node_modules/okdb/index.js +++ b/app/node_modules/okdb/index.js @@ -97,7 +97,7 @@ FSDB.prototype.update = function(collection, id, data) { } var result = chain.assign(cloneDeep(data)).value(); - if (result ) { + if (result) { return resolve(cloneDeep(result)); } else { return resolve(null, new Error('Problem updating document')); diff --git a/app/node_modules/okschema/index.js b/app/node_modules/okschema/index.js index 330ad6b..82aa13f 100644 --- a/app/node_modules/okschema/index.js +++ b/app/node_modules/okschema/index.js @@ -63,8 +63,21 @@ var types = { assertValid: function(spec, value) {} }, 'tag-list': { - parent: 'string', - assertValid: function(spec, value) {} + parent: [{ + uri: { type: 'string' }, + text: { type: 'string' } + }], + assertValid: function(spec, value) { + var message; + var actual; + if (!value || !value.length) { + throw [{ + message: 'Not an array', + expected: JSON.stringify(this.parent), + actual: value + }]; + } + } }, 'date': { parent: 'string', diff --git a/examples/db.json b/examples/db.json index 20d4510..4319237 100644 --- a/examples/db.json +++ b/examples/db.json @@ -99,7 +99,14 @@ "title": "About Us", "body": "Just a small bakery", "id": "about", - "__index": 1 + "__index": "1", + "links": [ + { + "text": "asdf2", + "uri": "asdf" + } + ], + "dateCreated": "" }, { "title": "ok...", diff --git a/examples/index.js b/examples/index.js index 3e9f509..bf51dfc 100644 --- a/examples/index.js +++ b/examples/index.js @@ -10,7 +10,8 @@ var app = okcms.createApp({ page: { id: {type: 'string'}, title: {type: 'string'}, - body: {type: 'text'} + body: {type: 'text'}, + links: {type: 'link-list'}, }, bread: { type: {type: 'string', id: true}, @@ -19,7 +20,7 @@ var app = okcms.createApp({ color: {type: 'enum', options: ["red","blue","green"]}, video: {type: 'video'}, images: {type: 'captioned-image-list'} - } + }, }, resources: [ diff --git a/package.json b/package.json index 192685c..faf3cc9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "okcms", - "version": "0.1.18", + "version": "0.1.19", "description": "great", "main": "app/index.js", "scripts": { diff --git a/themes/okadmin/public/css/main.css b/themes/okadmin/public/css/main.css index a5fbdeb..9289fdf 100644 --- a/themes/okadmin/public/css/main.css +++ b/themes/okadmin/public/css/main.css @@ -305,6 +305,14 @@ button, input[type=submit] { .main.resource form .video-element input[type=text] { width: 15em; } +.main.resource form .group input[type=text].link-input, +.main.resource form .group input[type=text].link-input-new { + width: 13.05em; + padding: 0 0 0 0.5em; +} +.main.resource form .links li { + height: auto; +} .main .link-list .add-link-btn, .main .link-list .remove-link-btn { margin: 0; diff --git a/themes/okadmin/public/js/app.js b/themes/okadmin/public/js/app.js index edf9980..17b35d0 100644 --- a/themes/okadmin/public/js/app.js +++ b/themes/okadmin/public/js/app.js @@ -120,35 +120,25 @@ var OKAdmin = function(){ e.stopPropagation() var $delegate = $(e.delegateTarget) var $list = $delegate.find('.links') - var length = $list.find('input').length - var name = $delegate.parent('.property').data('name') - var $new = $delegate.find('.link-input-new') - var input = document.createElement('input') - var delBtn = document.createElement('button') - var inputName = name + '[' + length + ']' - $(input).attr({ - name: inputName, - type: 'text', - value: $new.val() - }) - $list.append(input) - $(delBtn).addClass('remove-link-btn') - $(delBtn).data('for', inputName) - delBtn.innerHTML = '-' - $list.append(delBtn) - $new.val('') + var $linkText = $delegate.find(".link-input-new.link-text") + var $linkURI = $delegate.find(".link-input-new.link-uri") + + var template = $delegate.find(".link-template").html() + var $el = $(template) + $el.find(".link-text").val( $linkText.val() ) + $el.find(".link-uri").val( $linkURI.val() ) + $list.append($el) + console.log($list, template) + $linkText.val("") + $linkURI.val("") }) // Remove a link from the list $('.link-list').on('click', '.remove-link-btn', function(e) { e.preventDefault() e.stopPropagation() - var $delegate = $(e.delegateTarget) var $target = $(e.target) - var inputName = $target.data('for') - var $input = $delegate.find('[name="' + inputName + '"]') - $input.remove() - $target.remove() + $target.closest("li").remove() }) // fix post indexing in list-driven inputs diff --git a/themes/okadmin/templates/partials/inputs.liquid b/themes/okadmin/templates/partials/inputs.liquid index c6efc68..55d5fb8 100644 --- a/themes/okadmin/templates/partials/inputs.liquid +++ b/themes/okadmin/templates/partials/inputs.liquid @@ -79,26 +79,58 @@ value="{{spec.value}}" placeholder="Enter a comma separated list of tags."> - {% elsif type == 'link-list' %} + {% elsif type == 'link-list' %} {% elsif type == 'media-list' %} -- cgit v1.2.3-70-g09d2 From ea9a94f3e1f980153588da1aee3fc7e456e292b5 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Mon, 28 Mar 2016 14:39:44 -0400 Subject: okschema: replace array-type data with empty list if unspecified (due to constraint of querystring body-parser) --- app/node_modules/okschema/index.js | 74 ++++++++++++++++++++++++++------------ examples/db.json | 23 ++++++++---- 2 files changed, 68 insertions(+), 29 deletions(-) (limited to 'examples/db.json') diff --git a/app/node_modules/okschema/index.js b/app/node_modules/okschema/index.js index 82aa13f..cf041fb 100644 --- a/app/node_modules/okschema/index.js +++ b/app/node_modules/okschema/index.js @@ -41,43 +41,25 @@ var types = { } }, 'captioned-image-list': { + isArray: true, parent: [{ uri: { type: 'string' }, // TODO Implement URI type caption: { type: 'string' } }], - assertValid: function(spec, value) { - var message; - var actual; - if (!value || !value.length) { - throw [{ - message: 'Not an array', - expected: JSON.stringify(this.parent), - actual: value - }]; - } - } + assertValid: function(spec, value) {} }, // Special type for resource meta information 'meta': { parent: 'string', assertValid: function(spec, value) {} }, - 'tag-list': { + 'link-list': { + isArray: true, parent: [{ uri: { type: 'string' }, text: { type: 'string' } }], - assertValid: function(spec, value) { - var message; - var actual; - if (!value || !value.length) { - throw [{ - message: 'Not an array', - expected: JSON.stringify(this.parent), - actual: value - }]; - } - } + assertValid: function(spec, value) {} }, 'date': { parent: 'string', @@ -90,8 +72,38 @@ var types = { 'foreign-key': { parent: 'enum', assertValid: function(spec, value) {} + }, + 'media-list': { + isArray: true, + parent: [], + assertValid: function(spec, value) {} + }, + 'double-captioned-image-list': { + isArray: true, + parent: [], + assertValid: function(spec, value) {} + }, + 'triple-captioned-image-list': { + isArray: true, + parent: [], + assertValid: function(spec, value) {} + }, +} + +/* +function checkArrayLength (spec, value) { + var message; + var actual; + if (!value || !value.length) { + throw [{ + message: 'Not an array', + expected: JSON.stringify(this.parent), + actual: value + }]; } } +*/ + /** * OKSchema! @@ -162,9 +174,25 @@ function OKSchema(spec) { }); } +OKSchema.prototype.checkDataForMissingArrays = function(data) { + data = data || {}; + var spec = this.spec; + + // The qs body-parser module does not have a way to represent + // empty lists. If you delete all elements from a list, + // check against the spec so we know to replace with an empty list. + Object.keys(spec).forEach(function(prop){ + var type = spec[prop].type; + if (types[type] && types[type].isArray && ! data[prop]) { + data[prop] = [] + } + }) +} + OKSchema.prototype.assertValid = function(data) { data = data || {}; var spec = this.spec; + this.checkDataForMissingArrays(data) // Run through custom validators, they'll throw if invalid Object.keys(data).forEach(function(prop) { var type = spec[prop].type; diff --git a/examples/db.json b/examples/db.json index 4319237..5e10d60 100644 --- a/examples/db.json +++ b/examples/db.json @@ -92,6 +92,22 @@ }, "__index": 3, "id": "croissant" + }, + { + "type": "Test", + "title": "Testing", + "description": "", + "color": "red", + "video": { + "url": "", + "type": "", + "token": "", + "title": "", + "thumb": "" + }, + "__index": "5", + "dateCreated": "Mon, 28 Mar 2016 18:49:32 GMT", + "images": [] } ], "page": [ @@ -100,12 +116,7 @@ "body": "Just a small bakery", "id": "about", "__index": "1", - "links": [ - { - "text": "asdf2", - "uri": "asdf" - } - ], + "links": [], "dateCreated": "" }, { -- cgit v1.2.3-70-g09d2 From 49fe25c8e884c14ab3258d22240a62f0b57da490 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Mon, 28 Mar 2016 16:15:46 -0400 Subject: make links sortable --- examples/db.json | 33 ++++++++++++------------- themes/okadmin/public/css/main.css | 9 ++++++- themes/okadmin/public/js/app.js | 19 ++++++++++---- themes/okadmin/templates/partials/inputs.liquid | 19 ++++++++------ 4 files changed, 49 insertions(+), 31 deletions(-) (limited to 'examples/db.json') diff --git a/examples/db.json b/examples/db.json index 5e10d60..9ab7233 100644 --- a/examples/db.json +++ b/examples/db.json @@ -92,22 +92,6 @@ }, "__index": 3, "id": "croissant" - }, - { - "type": "Test", - "title": "Testing", - "description": "", - "color": "red", - "video": { - "url": "", - "type": "", - "token": "", - "title": "", - "thumb": "" - }, - "__index": "5", - "dateCreated": "Mon, 28 Mar 2016 18:49:32 GMT", - "images": [] } ], "page": [ @@ -123,7 +107,22 @@ "title": "ok...", "body": "2406 Old Rd, San Juan Bautista", "id": "contact", - "__index": 0 + "__index": "0", + "links": [ + { + "text": "US Bread Board", + "uri": "http://bread.com/" + }, + { + "text": "National Council on Grain", + "uri": "http://grain.org/" + }, + { + "text": "USDA", + "uri": "http://usda.gov/" + } + ], + "dateCreated": "" } ] } \ No newline at end of file diff --git a/themes/okadmin/public/css/main.css b/themes/okadmin/public/css/main.css index 9289fdf..df0ca43 100644 --- a/themes/okadmin/public/css/main.css +++ b/themes/okadmin/public/css/main.css @@ -310,8 +310,15 @@ button, input[type=submit] { width: 13.05em; padding: 0 0 0 0.5em; } +.handle { + display: block; + width: 1em; + height: 2em; + background: #ddd; + float: left; +} .main.resource form .links li { - height: auto; + height: 2em; } .main .link-list .add-link-btn, .main .link-list .remove-link-btn { diff --git a/themes/okadmin/public/js/app.js b/themes/okadmin/public/js/app.js index 17b35d0..da398eb 100644 --- a/themes/okadmin/public/js/app.js +++ b/themes/okadmin/public/js/app.js @@ -91,7 +91,7 @@ var OKAdmin = function(){ }) // make the region sortable with drag-and-drop - $(".media-list ol, .image-list ol").sortable() + $(".media-list ol, .image-list ol, .link-list .links").sortable() $(".media-list ol, .image-list ol").disableSelection() // populate a video field with info from our url parser @@ -115,20 +115,22 @@ var OKAdmin = function(){ })) // Add a new link to the list - $('.link-list').on('click', '.add-link-btn', function(e) { - e.preventDefault() - e.stopPropagation() + $('.link-list').on('click', '.add-link-btn', function addNewLink (e) { + e.preventDefault && e.preventDefault() + e.stopPropagation && e.stopPropagation() var $delegate = $(e.delegateTarget) var $list = $delegate.find('.links') + var linkCount = $list.find("li").length + var $linkText = $delegate.find(".link-input-new.link-text") var $linkURI = $delegate.find(".link-input-new.link-uri") var template = $delegate.find(".link-template").html() + template = template.replace(/\[\]/g, "[" + linkCount + "]") var $el = $(template) $el.find(".link-text").val( $linkText.val() ) $el.find(".link-uri").val( $linkURI.val() ) $list.append($el) - console.log($list, template) $linkText.val("") $linkURI.val("") }) @@ -195,6 +197,13 @@ var OKAdmin = function(){ input.checked = true } }) + + $(".link-list").each(function(){ + var $inputs = $(this).find(".link-input-new") + if ($inputs.eq(0).val() && $inputs.eq(1).val()) { + $(this).find(".add-link-btn").trigger("click") + } + }) $("ol").each(function(){ $("li", this).each(function(index){ diff --git a/themes/okadmin/templates/partials/inputs.liquid b/themes/okadmin/templates/partials/inputs.liquid index 55d5fb8..4acb435 100644 --- a/themes/okadmin/templates/partials/inputs.liquid +++ b/themes/okadmin/templates/partials/inputs.liquid @@ -82,17 +82,18 @@ {% elsif type == 'link-list' %}