mirror of
https://github.com/documize/community.git
synced 2025-07-24 07:39:43 +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()
|
||||
});
|
|
@ -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;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue