mirror of
https://gitlab.silvrtree.co.uk/martind2000/censis-obrand.git
synced 2025-01-10 21:35:07 +00:00
”2016-03-30”
This commit is contained in:
parent
f44ce7e5f9
commit
5dc2f8b45f
@ -1,3 +1,3 @@
|
||||
{
|
||||
"ignore_dirs": ["tmp", "dist"]
|
||||
"ignore_dirs": ["tmp", "dist", "static"]
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ import Ember from 'ember';
|
||||
const { service , store } = Ember.inject;
|
||||
export default Ember.Controller.extend({
|
||||
session: service('session'),
|
||||
sessionAccount: service('session-account'),
|
||||
sessionAccount: service('session-account'),
|
||||
actions: {
|
||||
savePage: function() {
|
||||
|
||||
@ -11,7 +11,7 @@ export default Ember.Controller.extend({
|
||||
var model = this.get('model');
|
||||
|
||||
var account = this.get('sessionAccount.account');
|
||||
|
||||
|
||||
model.save()
|
||||
.then(function(d) {
|
||||
console.log(d);
|
||||
@ -25,7 +25,7 @@ export default Ember.Controller.extend({
|
||||
|
||||
// This.set('isEditing', false);
|
||||
|
||||
//this.transitionTo('company');
|
||||
//This.transitionTo('company');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -2,9 +2,11 @@ import DS from 'ember-data';
|
||||
|
||||
export default DS.Model.extend({
|
||||
cid: DS.attr('string'),
|
||||
vid: DS.attr('string'),
|
||||
pid: DS.attr('string'),
|
||||
category: DS.attr(),
|
||||
title: DS.attr('string'),
|
||||
content: DS.attr(),
|
||||
imageUrl: DS.attr('string'),
|
||||
link1Text: DS.attr('string'),
|
||||
link1Url: DS.attr('string'),
|
||||
|
@ -6,11 +6,12 @@ export default Ember.Route.extend({
|
||||
sessionAccount: service('session-account'),
|
||||
model: function(params) {
|
||||
'use strict';
|
||||
const cid = this.get('sessionAccount.account.memberOf');
|
||||
const cid = this.get('sessionAccount.account.memberof');
|
||||
console.log(cid);
|
||||
|
||||
var newPage = this.store.createRecord('page',{});
|
||||
newPage.set('cid', cid);
|
||||
newPage.set('imageUrl','http://lorempixel.com/300/300');
|
||||
var newPage = this.store.createRecord('page',{cid:cid,vid:'JPnbDnRzwDSNLTCcS4miFq', content:0, imageUrl:'http://lorempixel.com/300/300'});
|
||||
// newPage.set('cid', cid);
|
||||
// newPage.set('imageUrl','http://lorempixel.com/300/300');
|
||||
return newPage;
|
||||
|
||||
}
|
||||
|
@ -51,6 +51,7 @@
|
||||
"events": "^1.1.0",
|
||||
"express": "^4.13.4",
|
||||
"glob": "^4.5.3",
|
||||
"jade": "^1.11.0",
|
||||
"loader.js": "^4.0.0",
|
||||
"md-utils": "git+http://gitlab.silvrtree.co.uk/martind2000/md-utils.git",
|
||||
"morgan": "^1.7.0",
|
||||
|
@ -14,6 +14,7 @@ module.exports = function(app) {
|
||||
var mocks = globSync('./mocks/**/*.js', { cwd: __dirname }).map(require);
|
||||
var proxies = globSync('./proxies/**/*.js', { cwd: __dirname }).map(require);
|
||||
|
||||
|
||||
// Log proxy requests
|
||||
var morgan = require('morgan');
|
||||
app.use(morgan('dev'));
|
||||
|
@ -0,0 +1,32 @@
|
||||
doctype html
|
||||
html(lang="en")
|
||||
head
|
||||
meta(name='viewport', content='width=device-width, initial-scale=1.0')
|
||||
link(rel='stylesheet', href='http://yui.yahooapis.com/pure/0.6.0/pure-min.css')
|
||||
link(rel='stylesheet', href='css/obrand.css')
|
||||
title= title
|
||||
|
||||
body
|
||||
.pure-g
|
||||
.pure-u-1
|
||||
h1.textcenter= title
|
||||
#image.pure-u-1
|
||||
if image_url
|
||||
img.centerblock(src=image_url)
|
||||
#links.pure-u-1.pure-menu
|
||||
ul.pure-menu-list
|
||||
if link1_text
|
||||
li.pure-menu-item
|
||||
a.pure-menu-link.textcenter(href=link1_url)=link1_text
|
||||
|
||||
if link2_text
|
||||
li.pure-menu-item
|
||||
a.pure-menu-link.textcenter(href=link2_url)=link2_text
|
||||
|
||||
if link3_text
|
||||
li.pure-menu-item
|
||||
a.pure-menu-link.textcenter(href=link3_url)=link3_text
|
||||
|
||||
if link4_text
|
||||
li.pure-menu-item
|
||||
a.pure-menu-link.textcenter(href=link4_url)=link4_text
|
@ -1,24 +1,82 @@
|
||||
/*jshint node:true*/
|
||||
'use strict';
|
||||
var db = require('../units/db-connector').dbConnection;
|
||||
var dbPages = require('../units/db-pages')(db);
|
||||
var $U = require('md-utils');
|
||||
var Events = require('events');
|
||||
var jade = require('jade');
|
||||
var fs = require('fs');
|
||||
|
||||
var eventHandler = new Events();
|
||||
|
||||
var util = require('util');
|
||||
|
||||
var templates = {
|
||||
basic: {path: __dirname + '/jade/type0.jade', compiled: null}
|
||||
};
|
||||
|
||||
var eventRenderPage = (page) => {
|
||||
console.log('+++ eventRenderPage');
|
||||
doRenderPage(page)
|
||||
};
|
||||
|
||||
var doRenderPage = (page) => {
|
||||
console.log('+ doRenderPage');
|
||||
|
||||
var compiledhtml, _page = $U.unDashObject(page);
|
||||
var htmlfile = __dirname + '/static/' + _page.pid + '.html';
|
||||
|
||||
if (templates.basic.compiled === null) {
|
||||
templates.basic.compiled = jade.compileFile(templates.basic.path);
|
||||
}
|
||||
|
||||
compiledhtml = templates.basic.compiled(_page);
|
||||
|
||||
fs.writeFileSync(htmlfile, compiledhtml);
|
||||
console.log('- doRenderPage');
|
||||
};
|
||||
|
||||
|
||||
eventHandler.on('renderPage', eventRenderPage);
|
||||
|
||||
|
||||
|
||||
module.exports = function(app) {
|
||||
var express = require('express');
|
||||
var pagesRouter = express.Router();
|
||||
|
||||
pagesRouter.get('/', function(req, res) {
|
||||
res.send({
|
||||
'pages': []
|
||||
pages: []
|
||||
});
|
||||
});
|
||||
|
||||
pagesRouter.post('/', function(req, res) {
|
||||
console.log(util.inspect(req.body.data));
|
||||
res.status(201).end();
|
||||
|
||||
dbPages.addNewPage(req.body.data)
|
||||
.then(function(data) {
|
||||
|
||||
let response = {
|
||||
data: data
|
||||
};
|
||||
|
||||
eventHandler.emit('renderPage',data.attributes);
|
||||
|
||||
console.log('Finalising...');
|
||||
console.log(response);
|
||||
res.status(200).send(response);
|
||||
|
||||
})
|
||||
.catch((err)=> {
|
||||
console.error(err);
|
||||
res.status(401).end();
|
||||
});
|
||||
});
|
||||
|
||||
pagesRouter.get('/:id', function(req, res) {
|
||||
res.send({
|
||||
'pages': {
|
||||
pages: {
|
||||
id: req.params.id
|
||||
}
|
||||
});
|
||||
@ -26,7 +84,7 @@ module.exports = function(app) {
|
||||
|
||||
pagesRouter.put('/:id', function(req, res) {
|
||||
res.send({
|
||||
'pages': {
|
||||
pages: {
|
||||
id: req.params.id
|
||||
}
|
||||
});
|
||||
@ -40,12 +98,12 @@ module.exports = function(app) {
|
||||
// because the body-parser is not included by default.
|
||||
// To use req.body, run:
|
||||
|
||||
// npm install --save-dev body-parser
|
||||
// Npm install --save-dev body-parser
|
||||
app.use('/api/pages', require('body-parser').json({type: 'application/vnd.api+json'}));
|
||||
|
||||
// After installing, you need to `use` the body-parser for
|
||||
// this mock uncommenting the following line:
|
||||
//
|
||||
//app.use('/api/pages', require('body-parser').json());
|
||||
//App.use('/api/pages', require('body-parser').json());
|
||||
app.use('/api/pages', pagesRouter);
|
||||
};
|
||||
|
@ -0,0 +1 @@
|
||||
<!DOCTYPE html><html lang="en"><head><meta name="viewport" content="width=device-width, initial-scale=1.0"><link rel="stylesheet" href="http://yui.yahooapis.com/pure/0.6.0/pure-min.css"><link rel="stylesheet" href="css/obrand.css"><title>A simple page</title></head><body><div class="pure-g"><div class="pure-u-1"><h1 class="textcenter">A simple page</h1></div><div id="image" class="pure-u-1"><img src="http://lorempixel.com/300/300" class="centerblock"></div><div id="links" class="pure-u-1 pure-menu"><ul class="pure-menu-list"><li class="pure-menu-item"><a href="http://www.google.com" class="pure-menu-link textcenter">Google</a></li><li class="pure-menu-item"><a href="http://www.lycos.com" class="pure-menu-link textcenter">Lycos</a></li><li class="pure-menu-item"></li><a href="http://www.excite.com" class="pure-menu-link textcenter">Excite</a><li class="pure-menu-item"></li><a href="http://altavista.digital.com" class="pure-menu-link textcenter">Altavista</a></ul></div></div></body></html>
|
@ -0,0 +1,23 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link rel="stylesheet" href="http://yui.yahooapis.com/pure/0.6.0/pure-min.css">
|
||||
<link rel="stylesheet" href="css/obrand.css">
|
||||
<title>My page</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="pure-g">
|
||||
<div class="pure-u-1">
|
||||
<h1 class="textcenter">My page</h1>
|
||||
</div>
|
||||
<div id="image" class="pure-u-1"><img src="http://lorempixel.com/300/300" class="centerblock">
|
||||
</div>
|
||||
<div id="links" class="pure-u-1 pure-menu">
|
||||
<ul class="pure-menu-list">
|
||||
<li class="pure-menu-item"> <a href="http://www.google.com" class="pure-menu-link textcenter">this is my link</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1 @@
|
||||
<!DOCTYPE html><html lang="en"><head><title>My page</title></head><body><h1>My page</h1><div id="image"><img src="http://lorempixel.com/300/300"></div><div id="links"><ul><li><a href="http://www.google.com">this is my link</a></li></ul></div></body></html>
|
@ -0,0 +1,9 @@
|
||||
.textcenter {
|
||||
text-align: center !important;
|
||||
}
|
||||
|
||||
.centerblock {
|
||||
display: block;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
'use strict';
|
||||
|
||||
var mdErrors = require('./md-errors');
|
||||
var newId = require('uuid-pure').newId;
|
||||
var $U = require('md-utils');
|
||||
/**
|
||||
*
|
||||
* User: Martin Donnelly
|
||||
* Date: 2016-03-24
|
||||
* Time: 11:10
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
module.exports = function(db) {
|
||||
|
||||
var module = {};
|
||||
|
||||
module.sqlInsertPage = function(data) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
db.func('upsert_page',data)
|
||||
.then((d)=> {
|
||||
console.log(d);
|
||||
console.log('+sqlInsertPage OK');
|
||||
return resolve('ok');
|
||||
})
|
||||
.catch((err)=> {
|
||||
console.log('+sqlInsertPage failed');
|
||||
console.log(err);
|
||||
return reject(err);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
module.addNewPage = function(data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let _data, _jsonData;
|
||||
|
||||
console.log(data);
|
||||
_data = $U.cloneTrim(data.attributes);
|
||||
|
||||
if (typeof _data.pid === 'undefined' || _data.pid === null) {
|
||||
_data.pid = newId();
|
||||
}
|
||||
|
||||
_jsonData = $U.newObjectFrom(_data, ['title','image-url','link1-text','link1-url','link2-text','link2-url','link3-text','link3-url','link4-text','link4-url']);
|
||||
|
||||
const sqlData = [_data.cid, _data.vid, _data.pid, _data.content, _data.title, JSON.stringify(_jsonData)];
|
||||
|
||||
console.log(sqlData);
|
||||
this.sqlInsertPage(sqlData)
|
||||
.then(function(d) {
|
||||
console.log('Inserted');
|
||||
console.log(d);
|
||||
data.attributes = _data;
|
||||
return resolve(data);
|
||||
})
|
||||
.catch(function(err) {
|
||||
console.log('Failed to insert');
|
||||
return reject(err);
|
||||
});
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
return module;
|
||||
|
||||
};
|
Loading…
Reference in New Issue
Block a user