”2016-03-29”

This commit is contained in:
System Administrator 2016-03-29 16:45:03 +01:00
parent bf969ce01b
commit 4df6d53584
12 changed files with 274 additions and 16 deletions

View File

@ -0,0 +1,5 @@
import ApplicationAdapter from './application';
export default ApplicationAdapter.extend({
namespace:'api'
});

View File

@ -1,4 +1,48 @@
import Ember from 'ember';
const { service , store } = Ember.inject;
export default Ember.Controller.extend({
session: service('session'),
sessionAccount: service('session-account'),
actions: {
savePage: function() {
console.log('save page');
var store = this.get('store');
var model = this.get('model');
var pageContent = model.get('content');
var account = this.get('sessionAccount.account');
console.log(pageContent.get('title'));
model.set('cid', this.get('sessionAccount.account.memberof'));
model.save()
.then(function(d) {
console.log(d);
})
.catch(function(err) {
console.log(err);
});
pageContent.save().then(function(d) {
console.log(d);
})
.catch(function(err) {
console.log(err);
});
console.log(pageContent.serialize());
// This.set('isEditing', false);
//this.transitionTo('company');
}
}
});

View File

@ -1,6 +1,9 @@
'use strict';
import DS from 'ember-data';
export default DS.Model.extend({
page: DS.belongsTo('page'),
title: DS.attr('string'),
imageUrl: DS.attr('string'),
link1Text: DS.attr('string'),
@ -10,5 +13,20 @@ export default DS.Model.extend({
link3Text: DS.attr('string'),
link3Url: DS.attr('string'),
link4Text: DS.attr('string'),
link4Url: DS.attr('string')
link4Url: DS.attr('string'),
visibleLink1: function() {
return !((Ember.isBlank(this.get('link1Text'))) || (Ember.isBlank(this.get('link1Url'))));
}.property('link1Url','link1Text'),
visibleLink2: function() {
return !((Ember.isBlank(this.get('link2Text'))) && (Ember.isBlank(this.get('link2Url'))));
}.property('link2Url','link2Text'),
visibleLink3: function() {
return !((Ember.isBlank(this.get('link3Text'))) && (Ember.isBlank(this.get('link3Url'))));
}.property('link3Url','link3Text'),
visibleLink4: function() {
return !((Ember.isBlank(this.get('link4Text'))) && (Ember.isBlank(this.get('link4Url'))));
}.property('link4Url','link4Text'),
noImage: function() {
return Ember.isBlank(this.get('imageUrl'));
}.property('imageUrl')
});

View File

@ -5,5 +5,5 @@ export default DS.Model.extend({
pid: DS.attr('string'),
category: DS.attr(),
title: DS.attr('string'),
content: DS.belongsTo('page-content')
content: DS.belongsTo('page-content', {embedded: 'always'})
});

View File

@ -8,10 +8,12 @@ export default Ember.Route.extend({
'use strict';
const cid = this.get('sessionAccount.account.memberOf');
var newPageContent = this.store.createRecord('page-content',{});
var newPageContent = this.store.createRecord('page-content',{imageUrl:'http://lorempixel.com/300/300'});
var newPage = this.store.createRecord('page',{});
newPage.set('cid', cid);
newPage.set('content',newPageContent);
newPageContent.set('page',newPage);
return newPage;
}

View File

@ -0,0 +1,37 @@
import DS from 'ember-data';
export default DS.JSONAPISerializer.extend({
serializeBelongsTo: function(record, json, relationship) {
var key = relationship.key,
belongsTo = Ember.get(record, key);
key = this.keyForRelationship ? this.keyForRelationship(key, "belongsTo") : key;
if (relationship.options.embedded === 'always') {
json[key] = belongsTo.serialize();
}
else {
return this._super(record, json, relationship);
}
},
serializeHasMany: function(record, json, relationship) {
var key = relationship.key,
hasMany = Ember.get(record, key),
relationshipType = DS.RelationshipChange.determineRelationshipType(record.constructor, relationship);
if (relationship.options.embedded === 'always') {
if (hasMany && relationshipType === 'manyToNone' || relationshipType === 'manyToMany' ||
relationshipType === 'manyToOne') {
json[key] = [];
hasMany.forEach(function(item, index){
json[key].push(item.serialize());
});
}
}
else {
return this._super(record, json, relationship);
}
}
});

View File

@ -52,3 +52,8 @@ body {
box-shadow: 0px 4px 5px 0px rgba(0,0,0,0.43);
border-radius: 0.25rem;
}
.image300 {
max-width: 300px;
max-height: 300px;
}

View File

@ -12,31 +12,99 @@
<label for="title">Title:</label>
{{input id='title' placeholder='title' value=model.content.title class="form-control" required="required"}}
</div>
<div class="col-md-12 form-inline">
<label for="imageUrl">Image URL:</label>
{{input id='imageUrl' placeholder='URL to your image' value=model.content.imageUrl class="form-control" required="required"}}
</div>
<div class="col-md-12 form-inline">
<div>Link One</div>
<label for="link1title">Text:</label>
{{input id='link1title' placeholder='Text' value=model.content.link1Text class="form-control"}}
<label for="link1title">Text:</label>
{{input id='link1title' placeholder='Text' value=model.content.link1Text class="form-control"}}
<label for="link1url">URL:</label>
{{input id='link1url' placeholder='http://something.com/link' value=model.content.link1Url class="form-control"}}
</div>
<div class="col-md-12 form-inline">
<div>Link Two</div>
<label for="link2title">Text:</label>
{{input id='link2title' placeholder='Text' value=model.content.link2Text class="form-control"}}
<label for="link2url">URL:</label>
{{input id='link2url' placeholder='http://something.com/link' value=model.content.link2Url class="form-control"}}
</div>
<div class="col-md-12 form-inline">
<div>Link Three</div>
<label for="link3title">Text:</label>
{{input id='link3title' placeholder='Text' value=model.content.link3Text class="form-control"}}
<label for="link3url">URL:</label>
{{input id='link3url' placeholder='http://something.com/link' value=model.content.link3Url class="form-control"}}
</div>
<div class="col-md-12 form-inline">
<div>Link Four</div>
<label for="link4title">Text:</label>
{{input id='link4title' placeholder='Text' value=model.content.link4Text class="form-control"}}
<label for="link4url">URL:</label>
{{input id='link4url' placeholder='http://something.com/link' value=model.content.link4Url class="form-control"}}
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">Save</button>
</div>
</div>
</form>
</div>
<div></div>
<div class="col-md-8 content">
<div id="fakeDevice" class="fakeDevice">
<h1 class="text-xs-center">{{ model.content.title }}</h1>
<img src="http://pipes.silvrtree.co.uk/assets/fm.png"
class="center-block"/>
{{#if model.content.noImage }}
<img src="http://pipes.silvrtree.co.uk/assets/fm.png"
class="center-block image300"/>
{{else}}
<img src="{{model.content.imageUrl}}"
class="center-block image300"/>
{{/if}}
<ul class="list-group">
{{#if model.content.link1Url }}
<li class="list-group-item">{{#link-to model.content.link1Url}}{{model.content.link1Text}}{{/link-to}}</li>
{{#if model.content.visibleLink1 }}
<li class="list-group-item text-xs-center"><a
href="{{model.content.link1Url}}"
target="_blank">{{model.content.link1Text}}</a></li>
{{else}}
<li class="list-group-item text-muted text-xs-center">
<em>Your link here</em></li>
{{/if}}
<li class="list-group-item">List item 2</li>
<li class="list-group-item">List item 3</li>
<li class="list-group-item">List item 4</li>
{{#if model.content.visibleLink2 }}
<li class="list-group-item"><a
href="{{model.content.link2Url}}"
target="_blank">{{model.content.link2Text}}</a></li>
{{else}}
<li class="list-group-item text-muted text-xs-center">
<em>Your link here</em></li>
{{/if}}
{{#if model.content.visibleLink3 }}
<li class="list-group-item"><a
href="{{model.content.link3Url}}"
target="_blank">{{model.content.link3Text}}</a></li>
{{else}}
<li class="list-group-item text-muted text-xs-center">
<em>Your link here</em></li>
{{/if}}
{{#if model.content.visibleLink4 }}
<li class="list-group-item"><a
href="{{model.content.link4Url}}"
target="_blank">{{model.content.link4Text}}</a></li>
{{else}}
<li class="list-group-item text-muted text-xs-center">
<em>Your link here</em></li>
{{/if}}
</ul>
</div>
</div>

View File

@ -52,11 +52,12 @@
"express": "^4.13.4",
"glob": "^4.5.3",
"loader.js": "^4.0.0",
"md-utils": "git+http://gitlab.silvrtree.co.uk/martind2000/md-utils.git",
"morgan": "^1.7.0",
"node-validator": "git+http://gitlab.silvrtree.co.uk/martind2000/node-validator.git",
"md-utils": "git+http://gitlab.silvrtree.co.uk/martind2000/md-utils.git",
"oauth2-server": "^2.4.1",
"pg-promise": "^3.3.0"
"pg-promise": "^3.3.0",
"util": "^0.10.3"
},
"dependencies": {
"bcrypt": "^0.8.5",

View File

@ -0,0 +1,51 @@
/*jshint node:true*/
var util = require('util');
module.exports = function(app) {
var express = require('express');
var pagesRouter = express.Router();
pagesRouter.get('/', function(req, res) {
res.send({
'pages': []
});
});
pagesRouter.post('/', function(req, res) {
console.log(util.inspect(req.body.data));
res.status(201).end();
});
pagesRouter.get('/:id', function(req, res) {
res.send({
'pages': {
id: req.params.id
}
});
});
pagesRouter.put('/:id', function(req, res) {
res.send({
'pages': {
id: req.params.id
}
});
});
pagesRouter.delete('/:id', function(req, res) {
res.status(204).end();
});
// The POST and PUT call will not contain a request body
// because the body-parser is not included by default.
// To use req.body, run:
// 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', pagesRouter);
};

View File

@ -0,0 +1,12 @@
import { moduleFor, test } from 'ember-qunit';
moduleFor('adapter:page', 'Unit | Adapter | page', {
// Specify the other units that are required for this test.
// needs: ['serializer:foo']
});
// Replace this with your real tests.
test('it exists', function(assert) {
let adapter = this.subject();
assert.ok(adapter);
});

View File

@ -0,0 +1,15 @@
import { moduleForModel, test } from 'ember-qunit';
moduleForModel('useful', 'Unit | Serializer | useful', {
// Specify the other units that are required for this test.
needs: ['serializer:useful']
});
// Replace this with your real tests.
test('it serializes records', function(assert) {
let record = this.subject();
let serializedRecord = record.serialize();
assert.ok(serializedRecord);
});