summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2016-09-08 19:59:41 -0400
committerJules Laplace <jules@okfoc.us>2016-09-08 19:59:41 -0400
commit50fac2191fbf0dd101d6071242c03dfad295b3ed (patch)
tree2624310093338b64faf8e9e946d11be21afd5a63
parentb938e3d1d2d108b887c9624249ee7021cfd83a1f (diff)
makin okcms okadminview frontend lib workv0.1.41
-rw-r--r--app/node_modules/okadminview/index.js1
-rw-r--r--examples/db.json15
-rw-r--r--examples/index.js3
-rw-r--r--package.json6
-rw-r--r--themes/okadmin/public/js/okcms.js28
-rw-r--r--themes/okcards/public/css/main.css0
-rw-r--r--themes/okcards/public/js/app.js15
-rw-r--r--themes/okcards/templates/404.liquid54
-rw-r--r--themes/okcards/templates/5xx.liquid54
-rw-r--r--themes/okcards/templates/index.liquid6
-rw-r--r--themes/okcards/templates/partials/app.liquid8
-rw-r--r--themes/okcards/templates/partials/flash.liquid20
-rw-r--r--themes/okcards/templates/partials/head.liquid13
-rw-r--r--themes/okcards/templates/partials/tail.liquid9
-rw-r--r--themes/okcards/templates/resource.liquid6
-rw-r--r--themes/okcards/templates/resource_new.liquid6
16 files changed, 218 insertions, 26 deletions
diff --git a/app/node_modules/okadminview/index.js b/app/node_modules/okadminview/index.js
index e0905bf..1121852 100644
--- a/app/node_modules/okadminview/index.js
+++ b/app/node_modules/okadminview/index.js
@@ -354,7 +354,6 @@ OKAdminView.prototype.renderJSON = function(req, res, data) {
*/
function fetchIndexTemplateData(meta, queries, dashboardConfig) {
var resourceConfig = dashboardConfig.resources || {}
-
return Q.promise(function(resolve, reject) {
Q.all(queries.map(function(query) {
return query.get();
diff --git a/examples/db.json b/examples/db.json
index b6ab96b..5f8554f 100644
--- a/examples/db.json
+++ b/examples/db.json
@@ -233,20 +233,7 @@
"flagged": true
}
],
- "flour": [
- {
- "id": "test",
- "title": "TEST",
- "image": {
- "uri": "https://ltho.s3.amazonaws.com/okcms-example/7be163d0-080b-11e6-8a7d-f30231d4ec26.png",
- "caption": "",
- "width": "800",
- "height": "800"
- },
- "__index": 0,
- "dateCreated": "Thu, 21 Apr 2016 21:52:44 GMT"
- }
- ],
+ "flour": [],
"card": [
{
"id": "1",
diff --git a/examples/index.js b/examples/index.js
index f1fabfa..a4f3ac3 100644
--- a/examples/index.js
+++ b/examples/index.js
@@ -2,6 +2,7 @@ var okcms = require('..');
var isProduction = process.env.OK_PRODUCTION === 'true'
var port = process.env.PORT || 1337;
+var path = require('path')
var app = okcms.createApp({
@@ -11,6 +12,8 @@ var app = okcms.createApp({
production: isProduction,
admin: {
+ root: path.join(__dirname, '../themes/okcards/public'),
+ templateRoot: path.join(__dirname, '../themes/okcards/templates'),
dashboard: {
resources: {
card: {
diff --git a/package.json b/package.json
index d9e159c..bcb338f 100644
--- a/package.json
+++ b/package.json
@@ -10,6 +10,10 @@
"author": "OKFocus",
"license": "UNLICENSED",
"dependencies": {
- "dotenv": "^1.1.0"
+ "dotenv": "^1.1.0",
+ "express": "^4.14.0",
+ "object-assign": "^4.1.0",
+ "q": "^1.4.1",
+ "request": "^2.74.0"
}
}
diff --git a/themes/okadmin/public/js/okcms.js b/themes/okadmin/public/js/okcms.js
index 69a8f86..c53092f 100644
--- a/themes/okadmin/public/js/okcms.js
+++ b/themes/okadmin/public/js/okcms.js
@@ -28,15 +28,17 @@ var OKCMS = (function(){
// data.resources[types].data[]
// data.resources[types].data[0][groupBy][group]
var resources = this.resources = {}
- this.types = Object.keys(data.resources)
- this.types.forEach(function(type){
+ var plural_types = Object.keys(data.resources)
+ var types = this.types = []
+ plural_types.forEach(function(type){
var resource = data.resources[type]
resources[resource.type] = resource
resource.lookup = {}
+ resource.index = []
+ types.push( resource.type )
if (resource.groupBy) {
var group_lookup = resource.data[0][resource.groupBy]
var groups = Object.keys(group_lookup)
- resource.index = []
groups.forEach(function(group){
var list = group_lookup[group]
list.forEach(function(record){
@@ -48,6 +50,7 @@ var OKCMS = (function(){
else {
resource.data.forEach(function(record){
resource.lookup[record.id] = record
+ resource.index.push(record)
})
}
})
@@ -79,13 +82,13 @@ var OKCMS = (function(){
}
OKCMS.prototype.get = function(type, id){
var resource = this.getResource(type)
- if (id in resource.index) {
- return resource.index[id]
+ if (id in resource.lookup) {
+ return resource.lookup[id]
}
throw new Error ("Key not found: " + type + ":" + id)
}
OKCMS.prototype.new = function(type){
- var resource = this.resource(type)
+ var resource = this.getResource(type)
var spec = this.spec(type)
var record = {}
Object.keys(spec).forEach(function(key){
@@ -170,8 +173,9 @@ var OKCMS = (function(){
data.id = slugify( data.title )
}
$.ajax({
- url: [ "", adminRoot, type ].join("/"),
+ url: [ "", adminRoot, type, "" ].join("/"),
type: "POST",
+ data: data,
success: function(){
cb && cb()
}
@@ -180,20 +184,24 @@ var OKCMS = (function(){
OKCMS.prototype.update = function(type, data, cb){
var resource = this.getResource(type)
var id = data.id
-
+ console.log(id, [ "", adminRoot, type, id ].join("/") )
// /admin/:type/:id/
$.ajax({
- url: [ "", adminRoot, type, id ].join("/"),
+ url: [ "", adminRoot, type, id, "" ].join("/"),
type: "PUT",
data: data,
success: function(){
+ console.log(" OK" )
cb && cb()
}
})
}
OKCMS.prototype.destroy = function(type, id, cb){
+ if (typeof id == "object") {
+ id = id.id
+ }
$.ajax({
- url: [ "", adminRoot, type, id ].join("/"),
+ url: [ "", adminRoot, type, id, "" ].join("/"),
type: "DELETE",
success: function(){
cb && cb()
diff --git a/themes/okcards/public/css/main.css b/themes/okcards/public/css/main.css
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/themes/okcards/public/css/main.css
diff --git a/themes/okcards/public/js/app.js b/themes/okcards/public/js/app.js
new file mode 100644
index 0000000..1e710e9
--- /dev/null
+++ b/themes/okcards/public/js/app.js
@@ -0,0 +1,15 @@
+var app = (function(){
+ var app = {}
+ var cms
+
+ app.init = function(){
+ cms = app.cms = new OKCMS ({ ready: app.ready })
+ }
+ app.ready = function(){
+ console.log ("READY")
+ }
+
+ return app
+})()
+
+window.addEventListener("DOMContentLoaded", app.init) \ No newline at end of file
diff --git a/themes/okcards/templates/404.liquid b/themes/okcards/templates/404.liquid
new file mode 100644
index 0000000..87f5342
--- /dev/null
+++ b/themes/okcards/templates/404.liquid
@@ -0,0 +1,54 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>404</title>
+ <style type="text/css">
+ html, body {
+ margin: 0;
+ padding: 0;
+ font-family: "Helvetica", sans-serif;
+ background-image: url('http://okfoc.us/assets/images/photocopy.png');
+ background-position: bottom center;
+ background-repeat: repeat;
+ background-attachment: scroll;
+ height: 100%;
+ font-size: 1.75em;
+ font-weight: bold;
+ color: #FFFFFF;
+ }
+
+ a {
+ color: #8888FF;
+ text-decoration: none;
+ }
+
+ a:hover {
+ border-bottom: 3px solid #8888FF;
+ }
+
+ a:visited {
+ color: #8888FF;
+ }
+
+ .message {
+ width: 700px;
+ padding: 1em 1em 1em 1em;
+ background-color: #0000FF;
+ margin: 0 auto;
+ margin-top: 1em;
+ }
+
+ .message p:first-child {
+ margin-top: 0;
+ }
+ </style>
+ </head>
+ <body>
+ <div class="message">
+ <p>¯\_(ツ)_/¯</p>
+ <p>We couldn't find that page.</p>
+ <p>Sure you have the right URL?</p>
+ <a href="javascript:history.back()">Back</a>
+ </div>
+ </body>
+</html>
diff --git a/themes/okcards/templates/5xx.liquid b/themes/okcards/templates/5xx.liquid
new file mode 100644
index 0000000..f245545
--- /dev/null
+++ b/themes/okcards/templates/5xx.liquid
@@ -0,0 +1,54 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>404</title>
+ <style type="text/css">
+ html, body {
+ margin: 0;
+ padding: 0;
+ font-family: "Helvetica", sans-serif;
+ background-image: url('http://okfoc.us/assets/images/photocopy.png');
+ background-position: bottom center;
+ background-repeat: repeat;
+ background-attachment: scroll;
+ height: 100%;
+ font-size: 1.75em;
+ font-weight: bold;
+ color: #FFFFFF;
+ }
+
+ a {
+ color: #8888FF;
+ text-decoration: none;
+ }
+
+ a:hover {
+ border-bottom: 3px solid #8888FF;
+ }
+
+ a:visited {
+ color: #8888FF;
+ }
+
+ .message {
+ width: 700px;
+ padding: 0 1em 1em 1em;
+ background-color: #0000FF;
+ margin: 0 auto;
+ margin-top: 1em;
+ }
+
+ .message p:first-child {
+ margin-top: 0;
+ }
+ </style>
+ </head>
+ <body>
+ <div class="message">
+ <p>(;一_一)</p>
+ <p>Looks like we experienced an error.</p>
+ <p>Sorry about that. Maybe try again later.</p>
+ <a href="javascript:history.back()">Back</a>
+ </div>
+ </body>
+</html>
diff --git a/themes/okcards/templates/index.liquid b/themes/okcards/templates/index.liquid
new file mode 100644
index 0000000..7dee4be
--- /dev/null
+++ b/themes/okcards/templates/index.liquid
@@ -0,0 +1,6 @@
+{% include 'partials/head' %}
+
+{% include 'partials/flash' %}
+{% include 'partials/app' %}
+
+{% include 'partials/tail' %}
diff --git a/themes/okcards/templates/partials/app.liquid b/themes/okcards/templates/partials/app.liquid
new file mode 100644
index 0000000..46c19e4
--- /dev/null
+++ b/themes/okcards/templates/partials/app.liquid
@@ -0,0 +1,8 @@
+<script type="text/html" id="stack-template">
+</script>
+
+<script type="text/html" id="card-template">
+</script>
+
+<div id="stacks">
+</div> \ No newline at end of file
diff --git a/themes/okcards/templates/partials/flash.liquid b/themes/okcards/templates/partials/flash.liquid
new file mode 100644
index 0000000..e51a86b
--- /dev/null
+++ b/themes/okcards/templates/partials/flash.liquid
@@ -0,0 +1,20 @@
+{% if success.length > 0 %}
+<div class="success">
+ <div class="message">Changes saved.</div>
+ <!--
+ {% for info in success %}
+ <div class="message">{{info.action}}</div>
+ {% endfor %}
+ -->
+</div>
+{% endif %}
+
+{% if errors.length > 0 %}
+<div class="errors">
+ {% for error in errors %}
+ <div class="error">
+ <div class="message">{{error.message}}</div>
+ </div>
+ {% endfor %}
+</div>
+{% endif %} \ No newline at end of file
diff --git a/themes/okcards/templates/partials/head.liquid b/themes/okcards/templates/partials/head.liquid
new file mode 100644
index 0000000..e9c27dc
--- /dev/null
+++ b/themes/okcards/templates/partials/head.liquid
@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf8">
+ <title>{{meta.project}} Admin</title>
+ <link rel="stylesheet" href="{{meta.static}}/css/main.css">
+ </head>
+ <body>
+ <header class="admin-header">
+ <span class="breadcrumb"><b>{{meta.project}}</b> Admin</span>
+ <a class="site-link" href="/">View Site</a>
+ </header>
+ <div class="container"> \ No newline at end of file
diff --git a/themes/okcards/templates/partials/tail.liquid b/themes/okcards/templates/partials/tail.liquid
new file mode 100644
index 0000000..7727d69
--- /dev/null
+++ b/themes/okcards/templates/partials/tail.liquid
@@ -0,0 +1,9 @@
+ </body>
+ <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
+ <script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/3.6.0/lodash.min.js"></script>
+ <script src="/admin/_lib/js/jqueryui-draggable.js"></script>
+ <script src="/admin/_lib/js/upload.js"></script>
+ <script src="/admin/_lib/js/parser.js"></script>
+ <script src="/admin/_lib/js/okcms.js"></script>
+ <script src="/admin/js/app.js"></script>
+</html>
diff --git a/themes/okcards/templates/resource.liquid b/themes/okcards/templates/resource.liquid
new file mode 100644
index 0000000..7dee4be
--- /dev/null
+++ b/themes/okcards/templates/resource.liquid
@@ -0,0 +1,6 @@
+{% include 'partials/head' %}
+
+{% include 'partials/flash' %}
+{% include 'partials/app' %}
+
+{% include 'partials/tail' %}
diff --git a/themes/okcards/templates/resource_new.liquid b/themes/okcards/templates/resource_new.liquid
new file mode 100644
index 0000000..7dee4be
--- /dev/null
+++ b/themes/okcards/templates/resource_new.liquid
@@ -0,0 +1,6 @@
+{% include 'partials/head' %}
+
+{% include 'partials/flash' %}
+{% include 'partials/app' %}
+
+{% include 'partials/tail' %}