summaryrefslogtreecommitdiff
path: root/app/node_modules/okadminview
diff options
context:
space:
mode:
authorSean Fridman <fridman@mail.sfsu.edu>2015-04-10 21:38:31 -0400
committerSean Fridman <fridman@mail.sfsu.edu>2015-04-10 21:41:01 -0400
commit6e1f689cfd8f820090c4ab15519114f4d3bf929f (patch)
tree3ce5f2515fb37777660bb36f635071afbb9bf224 /app/node_modules/okadminview
parent5abbdf600396144fbbe32b97e83beaabf6ed5c39 (diff)
Overhaul DB impl
Make DB schema aware Add autoincrement support Add custom ID field support
Diffstat (limited to 'app/node_modules/okadminview')
-rw-r--r--app/node_modules/okadminview/index.js19
1 files changed, 10 insertions, 9 deletions
diff --git a/app/node_modules/okadminview/index.js b/app/node_modules/okadminview/index.js
index b8ade49..1668900 100644
--- a/app/node_modules/okadminview/index.js
+++ b/app/node_modules/okadminview/index.js
@@ -57,13 +57,14 @@ function OKAdminView(options) {
var config = resourceConfig[key];
var type = config.type;
var staticData = config.static || {};
+ // Get parent level resource
var resource = resourceCache.get(config.type);
if (!resource)
throw new Error('Something weird is going on');
- var id = staticData[resource.idField];
+ var id = resource.getID(staticData);
+ // Check to see if there's a more specific instance
resource = resourceCache.get(type, id) || resource;
if (resource.bound) {
- // Resource instances implement the query API
return OKQuery({resource: resource});;
} else {
return OKQuery({resource: resource, query: config.query})
@@ -166,7 +167,7 @@ function OKAdminView(options) {
resource.assertValid(data);
resource.create(data).then(function(created) {
req.flash('success', {action: 'create'});
- res.redirect(303, data[resource.idField]);
+ res.redirect(303, resource.getID(data));
}).fail(errorHandler(req, res));
} catch (errors) {
var templateData = getResourceTemplateData(metadata, resource, data);
@@ -190,7 +191,7 @@ function OKAdminView(options) {
resource.assertValid(data);
resource.update(id, data).then(function(updated) {
req.flash('success', {action: 'update'});
- res.redirect(303, '../' + updated[resource.idField]);
+ res.redirect(303, '../' + resource.getID(updated));
}).fail(errorHandler(req, res));
} catch (errors) {
var templateData = getResourceTemplateData(metadata, resource, data);
@@ -236,7 +237,7 @@ function getResourceTemplateData(meta, resource, data) {
return {
meta: meta,
resource: {
- id: data[resource.idField],
+ id: resource.getID(data),
type: resource.type,
spec: spec
}
@@ -293,14 +294,14 @@ function fetchIndexTemplateData(meta, queries) {
}
if (result.length) {
- result.forEach(addToCache)
+ result.forEach(addData)
} else {
- addToCache(result);
+ addData(result);
}
- function addToCache(data) {
+ function addData(data) {
// Report id to template under standard name
- data.id = data[resource.idField];
+ data.id = resource.getID(data);
cache[key].data.push(data);
}