mirror of
https://github.com/documize/community.git
synced 2025-07-26 00:29:47 +02:00
Create section model and push data into the store
This commit is contained in:
parent
b638d6a114
commit
f6febf765c
2 changed files with 63 additions and 40 deletions
17
app/app/models/section.js
Normal file
17
app/app/models/section.js
Normal file
|
@ -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()
|
||||
});
|
|
@ -16,6 +16,7 @@ import BaseService from '../services/base';
|
|||
export default BaseService.extend({
|
||||
sessionService: Ember.inject.service('session'),
|
||||
ajax: Ember.inject.service(),
|
||||
store: Ember.inject.service(),
|
||||
|
||||
// Returns all available sections.
|
||||
getAll() {
|
||||
|
@ -23,8 +24,11 @@ export default BaseService.extend({
|
|||
method: 'GET'
|
||||
}).then((response) => {
|
||||
let data = [];
|
||||
_.each(response, function(obj) {
|
||||
data.pushObject(models.SectionModel.create(obj));
|
||||
_.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;
|
||||
|
@ -54,8 +58,10 @@ export default BaseService.extend({
|
|||
let pages = [];
|
||||
|
||||
if (is.not.null(response) && is.array(response) && response.length > 0) {
|
||||
_.each(response, function(page) {
|
||||
pages.pushObject(models.PageModel.create(page));
|
||||
_.each(response, (page) => {
|
||||
let data = this.get('store').normalize('page', page);
|
||||
let pageData = this.get('store').push({ data: data });
|
||||
pages.pushObject(pageData);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue