summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2016-04-05 11:46:47 -0400
committerJules Laplace <jules@okfoc.us>2016-04-05 11:46:47 -0400
commitcd929e1c38c02c1d048abe702c04c7d4d6188011 (patch)
treeec2b32caa4a71f5de7e998c64e7e9dfd994b295e
parent39b95380e6f81734d8a54bfbbfda13216d400247 (diff)
Fix sorting bug when savingv0.1.25
-rw-r--r--app/node_modules/okschema/index.js23
-rw-r--r--examples/db.json20
-rw-r--r--examples/index.js2
-rw-r--r--themes/okadmin/public/js/app.js4
-rw-r--r--themes/okadmin/public/js/parser.js2
-rw-r--r--themes/okadmin/templates/partials/inputs.liquid2
6 files changed, 45 insertions, 8 deletions
diff --git a/app/node_modules/okschema/index.js b/app/node_modules/okschema/index.js
index cf041fb..8162fd4 100644
--- a/app/node_modules/okschema/index.js
+++ b/app/node_modules/okschema/index.js
@@ -174,8 +174,7 @@ function OKSchema(spec) {
});
}
-OKSchema.prototype.checkDataForMissingArrays = function(data) {
- data = data || {};
+OKSchema.prototype.fixMissingLists = function(data) {
var spec = this.spec;
// The qs body-parser module does not have a way to represent
@@ -189,10 +188,22 @@ OKSchema.prototype.checkDataForMissingArrays = function(data) {
})
}
+OKSchema.prototype.fixIndexField = function(data) {
+ // Likewise numbers always come in as strings. The field used to sort
+ // records, __index, is of type "meta", so the parseFloat in
+ // assertValid (below) never fires and we end up with sorting issues.
+ if (data.__index && typeof data.__index == "string") {
+ var __index = parseInt(data.__index)
+ if (! isNaN(__index)) {
+ data.__index = __index
+ }
+ }
+}
+
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;
@@ -210,6 +221,12 @@ OKSchema.prototype.assertValid = function(data) {
if (!result.valid) {
throw result.errors;
}
+
+ // Fix various issues with our data, having to do
+ // with use of the "qs" body-parser module.
+ // TODO: just send JSON?
+ this.fixMissingLists(data)
+ this.fixIndexField(data)
};
/**
diff --git a/examples/db.json b/examples/db.json
index bdad6c8..1d045c3 100644
--- a/examples/db.json
+++ b/examples/db.json
@@ -150,8 +150,8 @@
],
"test": [
{
- "id": "test",
- "title": "tEst",
+ "id": "red",
+ "title": "Red",
"media": [
{
"uri": "http://asdf.us/",
@@ -159,8 +159,22 @@
"type": "link"
}
],
- "__index": "0",
+ "__index": 0,
"dateCreated": "Mon, 28 Mar 2016 23:02:45 GMT"
+ },
+ {
+ "id": "blue",
+ "title": "Blue",
+ "__index": 2,
+ "dateCreated": "Tue, 05 Apr 2016 15:17:54 GMT",
+ "media": []
+ },
+ {
+ "id": "green",
+ "title": "Green",
+ "__index": 1,
+ "dateCreated": "Tue, 05 Apr 2016 15:17:57 GMT",
+ "media": []
}
]
} \ No newline at end of file
diff --git a/examples/index.js b/examples/index.js
index 4bf385f..81d9241 100644
--- a/examples/index.js
+++ b/examples/index.js
@@ -4,7 +4,7 @@ var app = okcms.createApp({
root: 'public',
- debug: false,
+ debug: true,
schemas: {
page: {
diff --git a/themes/okadmin/public/js/app.js b/themes/okadmin/public/js/app.js
index e7f902d..e79f704 100644
--- a/themes/okadmin/public/js/app.js
+++ b/themes/okadmin/public/js/app.js
@@ -56,6 +56,7 @@ var OKAdmin = function(){
$el.addClass("loaded")
$el.find(".video-type").val( media.type )
$el.find(".video-token").val( media.token )
+ $el.find(".video-uri").val( media.uri )
$el.find(".video-title").val( media.title )
$el.find(".video-thumb").val( media.thumbnail )
$el.find(".video-width").val( media.width )
@@ -125,8 +126,11 @@ var OKAdmin = function(){
$el.parent().addClass("loaded")
$el.parent().find(".video-type").val( media.type )
$el.parent().find(".video-token").val( media.token )
+ $el.parent().find(".video-uri").val( media.uri )
$el.parent().find(".video-title").val( media.title )
$el.parent().find(".video-thumb").val( media.thumbnail )
+ $el.parent().find(".video-width").val( media.width )
+ $el.parent().find(".video-height").val( media.height )
})
}))
diff --git a/themes/okadmin/public/js/parser.js b/themes/okadmin/public/js/parser.js
index 6c964f7..b4a087d 100644
--- a/themes/okadmin/public/js/parser.js
+++ b/themes/okadmin/public/js/parser.js
@@ -39,7 +39,7 @@ var Parser = {
done({
url: url,
type: "video",
- token: "",
+ token: url,
thumbnail: "http://okfocus.s3.amazonaws.com/misc/okcms/video.png",
title: filename,
width: width,
diff --git a/themes/okadmin/templates/partials/inputs.liquid b/themes/okadmin/templates/partials/inputs.liquid
index fa03e48..e618c61 100644
--- a/themes/okadmin/templates/partials/inputs.liquid
+++ b/themes/okadmin/templates/partials/inputs.liquid
@@ -164,6 +164,7 @@
<div style="float: left">
<input name="{{name}}[][type]" type="hidden" class="video-type" hidden>
<input name="{{name}}[][token]" type="hidden" class="video-token" hidden>
+ <input name="{{name}}[][uri]" type="hidden" class="video-uri" hidden>
<input name="{{name}}[][width]" value="{{image.width}}" type="hidden" class="video-width" hidden>
<input name="{{name}}[][height]" value="{{image.height}}" type="hidden" class="video-height" hidden>
<label>Caption</label>
@@ -192,6 +193,7 @@
<div style="float: left">
<input name="{{name}}[{{forloop.index0}}][type]" value="{{image.type}}" type="hidden" class="video-type" hidden>
<input name="{{name}}[{{forloop.index0}}][token]" value="{{image.token}}" type="hidden" class="video-token" hidden>
+ <input name="{{name}}[{{forloop.index0}}][uri]" value="{{image.uri}}" type="hidden" class="video-uri" hidden>
<input name="{{name}}[{{forloop.index0}}][width]" value="{{image.width}}" type="hidden" class="video-width" hidden>
<input name="{{name}}[{{forloop.index0}}][height]" value="{{image.height}}" type="hidden" class="video-height" hidden>
<label>Caption</label>