mirror of
https://github.com/documize/community.git
synced 2025-07-25 08:09:43 +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'
|
||||
}).then((response) => {
|
||||
let data = [];
|
||||
if (is.not.array(response)) response = [];
|
||||
|
||||
data = response.map((obj) => {
|
||||
let data = this.get('store').normalize('category', obj);
|
||||
|
@ -52,6 +53,7 @@ export default BaseService.extend({
|
|||
method: 'GET'
|
||||
}).then((response) => {
|
||||
let data = [];
|
||||
if (is.not.array(response)) response = [];
|
||||
|
||||
data = response.map((obj) => {
|
||||
let data = this.get('store').normalize('category', obj);
|
||||
|
@ -89,6 +91,7 @@ export default BaseService.extend({
|
|||
}).then((response) => {
|
||||
// return response;
|
||||
let data = [];
|
||||
if (is.not.array(response)) response = [];
|
||||
|
||||
data = response.map((obj) => {
|
||||
let data = this.get('store').normalize('category-permission', obj);
|
||||
|
@ -105,6 +108,7 @@ export default BaseService.extend({
|
|||
method: 'GET'
|
||||
}).then((response) => {
|
||||
let data = [];
|
||||
if (is.not.array(response)) response = [];
|
||||
|
||||
data = response.map((obj) => {
|
||||
let data = this.get('store').normalize('user', obj);
|
||||
|
@ -173,6 +177,7 @@ export default BaseService.extend({
|
|||
membership: [],
|
||||
summary: []
|
||||
};
|
||||
if (is.not.array(response)) response = [];
|
||||
|
||||
let cats = response.category.map((obj) => {
|
||||
let data = this.get('store').normalize('category', obj);
|
||||
|
|
|
@ -45,6 +45,7 @@ export default Service.extend({
|
|||
let documents = ArrayProxy.create({
|
||||
content: A([])
|
||||
});
|
||||
if (is.not.array(response)) response = [];
|
||||
|
||||
documents = response.map((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`, {
|
||||
method: 'GET'
|
||||
}).then((response) => {
|
||||
if (is.not.array(response)) response = [];
|
||||
let pages = [];
|
||||
|
||||
pages = response.map((page) => {
|
||||
|
@ -214,6 +216,8 @@ export default Service.extend({
|
|||
return this.get('ajax').request(`documents/${documentId}/pages?content=0`, {
|
||||
method: 'GET'
|
||||
}).then((response) => {
|
||||
if (is.not.array(response)) response = [];
|
||||
|
||||
let data = [];
|
||||
data = response.map((obj) => {
|
||||
let data = this.get('store').normalize('page', obj);
|
||||
|
@ -282,6 +286,7 @@ export default Service.extend({
|
|||
return this.get('ajax').request(`sections/targets`, {
|
||||
method: 'GET'
|
||||
}).then((response) => {
|
||||
if (is.not.array(response)) response = [];
|
||||
let data = [];
|
||||
|
||||
data = response.map((obj) => {
|
||||
|
|
|
@ -102,6 +102,7 @@ export default BaseService.extend({
|
|||
method: "GET"
|
||||
}).then((response) => {
|
||||
let data = [];
|
||||
if (is.not.array(response)) response = [];
|
||||
|
||||
data = response.map((obj) => {
|
||||
let data = this.get('store').normalize('folder', obj);
|
||||
|
@ -118,6 +119,7 @@ export default BaseService.extend({
|
|||
method: "GET"
|
||||
}).then((response) => {
|
||||
let data = [];
|
||||
if (is.not.array(response)) response = [];
|
||||
|
||||
data = response.map((obj) => {
|
||||
let data = this.get('store').normalize('space-permission', obj);
|
||||
|
@ -176,6 +178,7 @@ export default BaseService.extend({
|
|||
method: "GET"
|
||||
}).then((response) => {
|
||||
let data = [];
|
||||
if (is.not.array(response)) response = [];
|
||||
|
||||
data = response.map((obj) => {
|
||||
let data = this.get('store').normalize('folder', obj);
|
||||
|
|
|
@ -35,6 +35,7 @@ export default BaseService.extend({
|
|||
method: 'GET'
|
||||
}).then((response) => {
|
||||
let data = [];
|
||||
if (is.not.array(response)) response = [];
|
||||
|
||||
data = response.map((obj) => {
|
||||
let data = this.get('store').normalize('group', obj);
|
||||
|
@ -81,7 +82,7 @@ export default BaseService.extend({
|
|||
return data;
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
// join adds user to group.
|
||||
join(groupId, userId) {
|
||||
return this.get('ajax').request(`group/${groupId}/join/${userId}`, {
|
||||
|
|
|
@ -25,7 +25,7 @@ export default Service.extend({
|
|||
this._super(...arguments);
|
||||
this.pins = [];
|
||||
},
|
||||
|
||||
|
||||
getUserPins() {
|
||||
let userId = this.get('session.user.id');
|
||||
|
||||
|
@ -93,9 +93,8 @@ export default Service.extend({
|
|||
method: 'POST',
|
||||
data: JSON.stringify(data)
|
||||
}).then((response) => {
|
||||
if (is.not.array(response)) {
|
||||
response = [];
|
||||
}
|
||||
if (is.not.array(response)) response = [];
|
||||
|
||||
let pins = ArrayProxy.create({
|
||||
content: A([])
|
||||
});
|
||||
|
|
|
@ -25,6 +25,8 @@ export default Service.extend({
|
|||
data: JSON.stringify(payload),
|
||||
contentType: 'json'
|
||||
}).then((response) => {
|
||||
if (is.not.array(response)) response = [];
|
||||
|
||||
let results = ArrayProxy.create({
|
||||
content: A([])
|
||||
});
|
||||
|
|
|
@ -24,6 +24,7 @@ export default BaseService.extend({
|
|||
method: 'GET'
|
||||
}).then((response) => {
|
||||
let data = [];
|
||||
if (is.not.array(response)) response = [];
|
||||
|
||||
data = response.map((obj) => {
|
||||
let data = this.get('store').normalize('section', obj);
|
||||
|
@ -55,6 +56,7 @@ export default BaseService.extend({
|
|||
method: 'GET'
|
||||
}).then((response) => {
|
||||
let pages = [];
|
||||
if (is.not.array(response)) response = [];
|
||||
|
||||
if (is.not.null(response) && is.array(response) && response.length > 0) {
|
||||
pages = response.map((page) => {
|
||||
|
@ -103,6 +105,7 @@ export default BaseService.extend({
|
|||
method: 'GET'
|
||||
}).then((response) => {
|
||||
let data = [];
|
||||
if (is.not.array(response)) response = [];
|
||||
|
||||
data = response.map((obj) => {
|
||||
let data = this.get('store').normalize('block', obj);
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
import { inject as service } from '@ember/service';
|
||||
import { computed } from '@ember/object';
|
||||
import { Promise as EmberPromise } from 'rsvp';
|
||||
import miscUtil from '../utils/misc';
|
||||
import SimpleAuthSession from 'ember-simple-auth/services/session';
|
||||
|
||||
export default SimpleAuthSession.extend({
|
||||
|
@ -88,7 +89,8 @@ export default SimpleAuthSession.extend({
|
|||
hasWhatsNew() {
|
||||
return new EmberPromise((resolve) => {
|
||||
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}`, {
|
||||
method: 'GET'
|
||||
}).then((response) => {
|
||||
if (is.not.array(response)) {
|
||||
response = [];
|
||||
}
|
||||
if (is.not.array(response)) response = [];
|
||||
|
||||
let templates = ArrayProxy.create({
|
||||
content: A([])
|
||||
});
|
||||
|
|
|
@ -56,6 +56,8 @@ export default Service.extend({
|
|||
// Returns all active users for organization.
|
||||
getAll() {
|
||||
return this.get('ajax').request(`users?active=1`).then((response) => {
|
||||
if (is.not.array(response)) response = [];
|
||||
|
||||
return response.map((obj) => {
|
||||
let data = this.get('store').normalize('user', obj);
|
||||
return this.get('store').push(data);
|
||||
|
@ -71,6 +73,8 @@ export default Service.extend({
|
|||
if (filter.length > 0) filter = encodeURIComponent(filter);
|
||||
|
||||
return this.get('ajax').request(`users?active=0&filter=${filter}`).then((response) => {
|
||||
if (is.not.array(response)) response = [];
|
||||
|
||||
return response.map((obj) => {
|
||||
let data = this.get('store').normalize('user', obj);
|
||||
return this.get('store').push(data);
|
||||
|
@ -86,6 +90,7 @@ export default Service.extend({
|
|||
method: "GET"
|
||||
}).then((response) => {
|
||||
let data = [];
|
||||
if (is.not.array(response)) response = [];
|
||||
|
||||
data = response.map((obj) => {
|
||||
let data = this.get('store').normalize('user', obj);
|
||||
|
@ -167,10 +172,11 @@ export default Service.extend({
|
|||
return this.get('ajax').request('users/match', {
|
||||
method: 'POST',
|
||||
dataType: 'json',
|
||||
contentType: 'text',
|
||||
contentType: 'text',
|
||||
data: text
|
||||
}).then((response) => {
|
||||
let data = [];
|
||||
if (is.not.array(response)) response = [];
|
||||
|
||||
data = response.map((obj) => {
|
||||
let data = this.get('store').normalize('user', obj);
|
||||
|
@ -179,5 +185,5 @@ export default Service.extend({
|
|||
|
||||
return data;
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue