mirror of
https://github.com/documize/community.git
synced 2025-07-28 17:49:41 +02:00
Default to empty array results in Ember services
This commit is contained in:
parent
38e8c4665a
commit
8d65c2d571
10 changed files with 36 additions and 11 deletions
|
@ -36,6 +36,7 @@ export default BaseService.extend({
|
||||||
method: 'GET'
|
method: 'GET'
|
||||||
}).then((response) => {
|
}).then((response) => {
|
||||||
let data = [];
|
let data = [];
|
||||||
|
if (is.not.array(response)) response = [];
|
||||||
|
|
||||||
data = response.map((obj) => {
|
data = response.map((obj) => {
|
||||||
let data = this.get('store').normalize('category', obj);
|
let data = this.get('store').normalize('category', obj);
|
||||||
|
@ -52,6 +53,7 @@ export default BaseService.extend({
|
||||||
method: 'GET'
|
method: 'GET'
|
||||||
}).then((response) => {
|
}).then((response) => {
|
||||||
let data = [];
|
let data = [];
|
||||||
|
if (is.not.array(response)) response = [];
|
||||||
|
|
||||||
data = response.map((obj) => {
|
data = response.map((obj) => {
|
||||||
let data = this.get('store').normalize('category', obj);
|
let data = this.get('store').normalize('category', obj);
|
||||||
|
@ -89,6 +91,7 @@ export default BaseService.extend({
|
||||||
}).then((response) => {
|
}).then((response) => {
|
||||||
// return response;
|
// return response;
|
||||||
let data = [];
|
let data = [];
|
||||||
|
if (is.not.array(response)) response = [];
|
||||||
|
|
||||||
data = response.map((obj) => {
|
data = response.map((obj) => {
|
||||||
let data = this.get('store').normalize('category-permission', obj);
|
let data = this.get('store').normalize('category-permission', obj);
|
||||||
|
@ -105,6 +108,7 @@ export default BaseService.extend({
|
||||||
method: 'GET'
|
method: 'GET'
|
||||||
}).then((response) => {
|
}).then((response) => {
|
||||||
let data = [];
|
let data = [];
|
||||||
|
if (is.not.array(response)) response = [];
|
||||||
|
|
||||||
data = response.map((obj) => {
|
data = response.map((obj) => {
|
||||||
let data = this.get('store').normalize('user', obj);
|
let data = this.get('store').normalize('user', obj);
|
||||||
|
@ -173,6 +177,7 @@ export default BaseService.extend({
|
||||||
membership: [],
|
membership: [],
|
||||||
summary: []
|
summary: []
|
||||||
};
|
};
|
||||||
|
if (is.not.array(response)) response = [];
|
||||||
|
|
||||||
let cats = response.category.map((obj) => {
|
let cats = response.category.map((obj) => {
|
||||||
let data = this.get('store').normalize('category', obj);
|
let data = this.get('store').normalize('category', obj);
|
||||||
|
|
|
@ -45,6 +45,7 @@ export default Service.extend({
|
||||||
let documents = ArrayProxy.create({
|
let documents = ArrayProxy.create({
|
||||||
content: A([])
|
content: A([])
|
||||||
});
|
});
|
||||||
|
if (is.not.array(response)) response = [];
|
||||||
|
|
||||||
documents = response.map((doc) => {
|
documents = response.map((doc) => {
|
||||||
let data = this.get('store').normalize('document', doc);
|
let data = this.get('store').normalize('document', doc);
|
||||||
|
@ -112,6 +113,7 @@ export default Service.extend({
|
||||||
return this.get('ajax').request(`documents/${documentId}/pages`, {
|
return this.get('ajax').request(`documents/${documentId}/pages`, {
|
||||||
method: 'GET'
|
method: 'GET'
|
||||||
}).then((response) => {
|
}).then((response) => {
|
||||||
|
if (is.not.array(response)) response = [];
|
||||||
let pages = [];
|
let pages = [];
|
||||||
|
|
||||||
pages = response.map((page) => {
|
pages = response.map((page) => {
|
||||||
|
@ -214,6 +216,8 @@ export default Service.extend({
|
||||||
return this.get('ajax').request(`documents/${documentId}/pages?content=0`, {
|
return this.get('ajax').request(`documents/${documentId}/pages?content=0`, {
|
||||||
method: 'GET'
|
method: 'GET'
|
||||||
}).then((response) => {
|
}).then((response) => {
|
||||||
|
if (is.not.array(response)) response = [];
|
||||||
|
|
||||||
let data = [];
|
let data = [];
|
||||||
data = response.map((obj) => {
|
data = response.map((obj) => {
|
||||||
let data = this.get('store').normalize('page', obj);
|
let data = this.get('store').normalize('page', obj);
|
||||||
|
@ -282,6 +286,7 @@ export default Service.extend({
|
||||||
return this.get('ajax').request(`sections/targets`, {
|
return this.get('ajax').request(`sections/targets`, {
|
||||||
method: 'GET'
|
method: 'GET'
|
||||||
}).then((response) => {
|
}).then((response) => {
|
||||||
|
if (is.not.array(response)) response = [];
|
||||||
let data = [];
|
let data = [];
|
||||||
|
|
||||||
data = response.map((obj) => {
|
data = response.map((obj) => {
|
||||||
|
|
|
@ -102,6 +102,7 @@ export default BaseService.extend({
|
||||||
method: "GET"
|
method: "GET"
|
||||||
}).then((response) => {
|
}).then((response) => {
|
||||||
let data = [];
|
let data = [];
|
||||||
|
if (is.not.array(response)) response = [];
|
||||||
|
|
||||||
data = response.map((obj) => {
|
data = response.map((obj) => {
|
||||||
let data = this.get('store').normalize('folder', obj);
|
let data = this.get('store').normalize('folder', obj);
|
||||||
|
@ -118,6 +119,7 @@ export default BaseService.extend({
|
||||||
method: "GET"
|
method: "GET"
|
||||||
}).then((response) => {
|
}).then((response) => {
|
||||||
let data = [];
|
let data = [];
|
||||||
|
if (is.not.array(response)) response = [];
|
||||||
|
|
||||||
data = response.map((obj) => {
|
data = response.map((obj) => {
|
||||||
let data = this.get('store').normalize('space-permission', obj);
|
let data = this.get('store').normalize('space-permission', obj);
|
||||||
|
@ -176,6 +178,7 @@ export default BaseService.extend({
|
||||||
method: "GET"
|
method: "GET"
|
||||||
}).then((response) => {
|
}).then((response) => {
|
||||||
let data = [];
|
let data = [];
|
||||||
|
if (is.not.array(response)) response = [];
|
||||||
|
|
||||||
data = response.map((obj) => {
|
data = response.map((obj) => {
|
||||||
let data = this.get('store').normalize('folder', obj);
|
let data = this.get('store').normalize('folder', obj);
|
||||||
|
|
|
@ -35,6 +35,7 @@ export default BaseService.extend({
|
||||||
method: 'GET'
|
method: 'GET'
|
||||||
}).then((response) => {
|
}).then((response) => {
|
||||||
let data = [];
|
let data = [];
|
||||||
|
if (is.not.array(response)) response = [];
|
||||||
|
|
||||||
data = response.map((obj) => {
|
data = response.map((obj) => {
|
||||||
let data = this.get('store').normalize('group', obj);
|
let data = this.get('store').normalize('group', obj);
|
||||||
|
|
|
@ -93,9 +93,8 @@ export default Service.extend({
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
data: JSON.stringify(data)
|
data: JSON.stringify(data)
|
||||||
}).then((response) => {
|
}).then((response) => {
|
||||||
if (is.not.array(response)) {
|
if (is.not.array(response)) response = [];
|
||||||
response = [];
|
|
||||||
}
|
|
||||||
let pins = ArrayProxy.create({
|
let pins = ArrayProxy.create({
|
||||||
content: A([])
|
content: A([])
|
||||||
});
|
});
|
||||||
|
|
|
@ -25,6 +25,8 @@ export default Service.extend({
|
||||||
data: JSON.stringify(payload),
|
data: JSON.stringify(payload),
|
||||||
contentType: 'json'
|
contentType: 'json'
|
||||||
}).then((response) => {
|
}).then((response) => {
|
||||||
|
if (is.not.array(response)) response = [];
|
||||||
|
|
||||||
let results = ArrayProxy.create({
|
let results = ArrayProxy.create({
|
||||||
content: A([])
|
content: A([])
|
||||||
});
|
});
|
||||||
|
|
|
@ -24,6 +24,7 @@ export default BaseService.extend({
|
||||||
method: 'GET'
|
method: 'GET'
|
||||||
}).then((response) => {
|
}).then((response) => {
|
||||||
let data = [];
|
let data = [];
|
||||||
|
if (is.not.array(response)) response = [];
|
||||||
|
|
||||||
data = response.map((obj) => {
|
data = response.map((obj) => {
|
||||||
let data = this.get('store').normalize('section', obj);
|
let data = this.get('store').normalize('section', obj);
|
||||||
|
@ -55,6 +56,7 @@ export default BaseService.extend({
|
||||||
method: 'GET'
|
method: 'GET'
|
||||||
}).then((response) => {
|
}).then((response) => {
|
||||||
let pages = [];
|
let pages = [];
|
||||||
|
if (is.not.array(response)) response = [];
|
||||||
|
|
||||||
if (is.not.null(response) && is.array(response) && response.length > 0) {
|
if (is.not.null(response) && is.array(response) && response.length > 0) {
|
||||||
pages = response.map((page) => {
|
pages = response.map((page) => {
|
||||||
|
@ -103,6 +105,7 @@ export default BaseService.extend({
|
||||||
method: 'GET'
|
method: 'GET'
|
||||||
}).then((response) => {
|
}).then((response) => {
|
||||||
let data = [];
|
let data = [];
|
||||||
|
if (is.not.array(response)) response = [];
|
||||||
|
|
||||||
data = response.map((obj) => {
|
data = response.map((obj) => {
|
||||||
let data = this.get('store').normalize('block', obj);
|
let data = this.get('store').normalize('block', obj);
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
import { inject as service } from '@ember/service';
|
import { inject as service } from '@ember/service';
|
||||||
import { computed } from '@ember/object';
|
import { computed } from '@ember/object';
|
||||||
import { Promise as EmberPromise } from 'rsvp';
|
import { Promise as EmberPromise } from 'rsvp';
|
||||||
|
import miscUtil from '../utils/misc';
|
||||||
import SimpleAuthSession from 'ember-simple-auth/services/session';
|
import SimpleAuthSession from 'ember-simple-auth/services/session';
|
||||||
|
|
||||||
export default SimpleAuthSession.extend({
|
export default SimpleAuthSession.extend({
|
||||||
|
@ -88,7 +89,8 @@ export default SimpleAuthSession.extend({
|
||||||
hasWhatsNew() {
|
hasWhatsNew() {
|
||||||
return new EmberPromise((resolve) => {
|
return new EmberPromise((resolve) => {
|
||||||
return this.get('userSvc').getUser(this.get('user.id')).then((user) => {
|
return this.get('userSvc').getUser(this.get('user.id')).then((user) => {
|
||||||
resolve(user.get('lastVersion') !== this.get('appMeta.version'));
|
let isNew = miscUtil.isNewVersion(user.get('lastVersion'), this.get('appMeta.version'), false);
|
||||||
|
resolve(isNew);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,9 +35,8 @@ export default Service.extend({
|
||||||
return this.get('ajax').request(`templates/${folderId}`, {
|
return this.get('ajax').request(`templates/${folderId}`, {
|
||||||
method: 'GET'
|
method: 'GET'
|
||||||
}).then((response) => {
|
}).then((response) => {
|
||||||
if (is.not.array(response)) {
|
if (is.not.array(response)) response = [];
|
||||||
response = [];
|
|
||||||
}
|
|
||||||
let templates = ArrayProxy.create({
|
let templates = ArrayProxy.create({
|
||||||
content: A([])
|
content: A([])
|
||||||
});
|
});
|
||||||
|
|
|
@ -56,6 +56,8 @@ export default Service.extend({
|
||||||
// Returns all active users for organization.
|
// Returns all active users for organization.
|
||||||
getAll() {
|
getAll() {
|
||||||
return this.get('ajax').request(`users?active=1`).then((response) => {
|
return this.get('ajax').request(`users?active=1`).then((response) => {
|
||||||
|
if (is.not.array(response)) response = [];
|
||||||
|
|
||||||
return response.map((obj) => {
|
return response.map((obj) => {
|
||||||
let data = this.get('store').normalize('user', obj);
|
let data = this.get('store').normalize('user', obj);
|
||||||
return this.get('store').push(data);
|
return this.get('store').push(data);
|
||||||
|
@ -71,6 +73,8 @@ export default Service.extend({
|
||||||
if (filter.length > 0) filter = encodeURIComponent(filter);
|
if (filter.length > 0) filter = encodeURIComponent(filter);
|
||||||
|
|
||||||
return this.get('ajax').request(`users?active=0&filter=${filter}`).then((response) => {
|
return this.get('ajax').request(`users?active=0&filter=${filter}`).then((response) => {
|
||||||
|
if (is.not.array(response)) response = [];
|
||||||
|
|
||||||
return response.map((obj) => {
|
return response.map((obj) => {
|
||||||
let data = this.get('store').normalize('user', obj);
|
let data = this.get('store').normalize('user', obj);
|
||||||
return this.get('store').push(data);
|
return this.get('store').push(data);
|
||||||
|
@ -86,6 +90,7 @@ export default Service.extend({
|
||||||
method: "GET"
|
method: "GET"
|
||||||
}).then((response) => {
|
}).then((response) => {
|
||||||
let data = [];
|
let data = [];
|
||||||
|
if (is.not.array(response)) response = [];
|
||||||
|
|
||||||
data = response.map((obj) => {
|
data = response.map((obj) => {
|
||||||
let data = this.get('store').normalize('user', obj);
|
let data = this.get('store').normalize('user', obj);
|
||||||
|
@ -171,6 +176,7 @@ export default Service.extend({
|
||||||
data: text
|
data: text
|
||||||
}).then((response) => {
|
}).then((response) => {
|
||||||
let data = [];
|
let data = [];
|
||||||
|
if (is.not.array(response)) response = [];
|
||||||
|
|
||||||
data = response.map((obj) => {
|
data = response.map((obj) => {
|
||||||
let data = this.get('store').normalize('user', obj);
|
let data = this.get('store').normalize('user', obj);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue