diff --git a/app/app/models/section.js b/app/app/models/section.js new file mode 100644 index 00000000..958fdc90 --- /dev/null +++ b/app/app/models/section.js @@ -0,0 +1,17 @@ +import Model from 'ember-data/model'; +import attr from 'ember-data/attr'; +// import { belongsTo, hasMany } from 'ember-data/relationships'; + +export default Model.extend({ + contentType: attr('string'), + title: attr('string'), + description: attr('string'), + iconFont: attr('string'), + iconFile: attr('string'), + + hasImage: Ember.computed('iconFont', 'iconFile', function () { + return this.get('iconFile').length > 0; + }), + created: attr(), + revised: attr() +}); diff --git a/app/app/services/section.js b/app/app/services/section.js index 9ea55d7c..1d7d0d2c 100644 --- a/app/app/services/section.js +++ b/app/app/services/section.js @@ -14,52 +14,58 @@ import models from '../utils/model'; import BaseService from '../services/base'; export default BaseService.extend({ - sessionService: Ember.inject.service('session'), - ajax: Ember.inject.service(), + sessionService: Ember.inject.service('session'), + ajax: Ember.inject.service(), + store: Ember.inject.service(), - // Returns all available sections. - getAll() { - return this.get('ajax').request(`sections`,{ - method: 'GET' - }).then((response)=>{ - let data = []; - _.each(response, function(obj) { - data.pushObject(models.SectionModel.create(obj)); - }); + // Returns all available sections. + getAll() { + return this.get('ajax').request(`sections`, { + method: 'GET' + }).then((response) => { + let data = []; + _.each(response, (obj) => { + debugger; + let sectionData = this.get('store').normalize('section', obj); + let section = this.get('store').push({ data: sectionData }); + data.pushObject(section); + }); - return data; - }); - }, + return data; + }); + }, - // Requests data from the specified section handler, passing the method and document ID - // and POST payload. - fetch(page, method, data) { - let documentId = page.get('documentId'); - let section = page.get('contentType'); - let url = `sections?documentID=${documentId}§ion=${section}&method=${method}`; + // Requests data from the specified section handler, passing the method and document ID + // and POST payload. + fetch(page, method, data) { + let documentId = page.get('documentId'); + let section = page.get('contentType'); + let url = `sections?documentID=${documentId}§ion=${section}&method=${method}`; - return this.get('ajax').post(url, { - data: JSON.stringify(data), - contentType: "application/json" - }); - }, + return this.get('ajax').post(url, { + data: JSON.stringify(data), + contentType: "application/json" + }); + }, - // Did any dynamic sections change? Fetch and send up for rendering? - refresh(documentId) { - let url = `sections/refresh?documentID=${documentId}`; + // Did any dynamic sections change? Fetch and send up for rendering? + refresh(documentId) { + let url = `sections/refresh?documentID=${documentId}`; - return this.get('ajax').request(url, { - method: 'GET' - }).then((response)=>{ - let pages = []; + return this.get('ajax').request(url, { + method: 'GET' + }).then((response) => { + let pages = []; - if (is.not.null(response) && is.array(response) && response.length > 0) { - _.each(response, function(page) { - pages.pushObject(models.PageModel.create(page)); - }); - } + if (is.not.null(response) && is.array(response) && response.length > 0) { + _.each(response, (page) => { + let data = this.get('store').normalize('page', page); + let pageData = this.get('store').push({ data: data }); + pages.pushObject(pageData); + }); + } - return pages; - }); - } + return pages; + }); + } });