From a78a73d55293a43cfd2bc0ab2d1b86e82f6678a3 Mon Sep 17 00:00:00 2001 From: zinyando Date: Mon, 8 Aug 2016 18:39:28 +0200 Subject: [PATCH 01/25] Create user model and push user data into store --- app/app/models/user.js | 44 +++++++++++++++++++++++++++++++++++++ app/app/serializers/user.js | 11 ++++++++++ app/app/services/user.js | 25 +++++++++++++-------- 3 files changed, 71 insertions(+), 9 deletions(-) create mode 100644 app/app/models/user.js create mode 100644 app/app/serializers/user.js diff --git a/app/app/models/user.js b/app/app/models/user.js new file mode 100644 index 000000000..95357bd09 --- /dev/null +++ b/app/app/models/user.js @@ -0,0 +1,44 @@ +import Model from 'ember-data/model'; +import attr from 'ember-data/attr'; +import Ember from 'ember'; +// import { belongsTo, hasMany } from 'ember-data/relationships'; + +export default Model.extend({ + firstname: attr('string'), + lastname: attr('string'), + email: attr('string'), + initials: attr('string'), + active: attr('boolean', { defaultValue: false }), + editor: attr('boolean', { defaultValue: false }), + admin: attr('boolean', { defaultValue: false }), + accounts: attr(), + created: attr(), + revised: attr(), + + fullname: Ember.computed('firstname', 'lastname', function () { + return `${this.get('firstname')} ${this.get('lastname')}`; + }), + + generateInitials() { + let first = this.get('firstname').trim(); + let last = this.get('lastname').trim(); + this.set('initials', first.substr(0, 1) + last.substr(0, 1)); + }, + // + // copy() { + // let copy = UserModel.create(); + // copy.id = this.id; + // copy.created = this.created; + // copy.revised = this.revised; + // copy.firstname = this.firstname; + // copy.lastname = this.lastname; + // copy.email = this.email; + // copy.initials = this.initials; + // copy.active = this.active; + // copy.editor = this.editor; + // copy.admin = this.admin; + // copy.accounts = this.accounts; + // + // return copy; + // } +}); diff --git a/app/app/serializers/user.js b/app/app/serializers/user.js new file mode 100644 index 000000000..05b576e6c --- /dev/null +++ b/app/app/serializers/user.js @@ -0,0 +1,11 @@ +import JSONAPISerializer from 'ember-data/serializers/json-api'; + +export default JSONAPISerializer.extend({ + normalize(modelClass, resourceHash) { + return { + id: resourceHash.id, + type: modelClass.modelName, + attributes: resourceHash + }; + } +}); diff --git a/app/app/services/user.js b/app/app/services/user.js index 28df54e94..f9afd0d76 100644 --- a/app/app/services/user.js +++ b/app/app/services/user.js @@ -10,21 +10,22 @@ // https://documize.com import Ember from 'ember'; -import models from '../utils/model'; +// import models from '../utils/model'; export default Ember.Service.extend({ sessionService: Ember.inject.service('session'), ajax: Ember.inject.service(), + store: Ember.inject.service(), // Adds a new user. add(user) { - return this.get('ajax').request(`users`, { type: 'POST', data: JSON.stringify(user), contentType: 'json' - }).then(function (response) { - return models.UserModel.create(response); + }).then((response) => { + let user = this.get('store').normalize('user', response); + return this.get('store').push({ data: user }); }); }, @@ -35,15 +36,17 @@ export default Ember.Service.extend({ return this.get('ajax').request(url, { type: 'GET' }).then((response) => { - return models.UserModel.create(response); + let user = this.get('store').normalize('user', response); + return this.get('store').push({ data: user }); }); }, // Returns all users for organization. getAll() { return this.get('ajax').request(`users`).then((response) => { - return response.map(function (obj) { - return models.UserModel.create(obj); + return response.map((obj) => { + let user = this.get('store').normalize('user', obj); + return this.get('store').push({ data: user }); }); }); }, @@ -56,8 +59,9 @@ export default Ember.Service.extend({ method: "GET" }).then((response) => { let data = []; - _.each(response, function (obj) { - data.pushObject(models.UserModel.create(obj)); + _.each(response, (obj) => { + let user = this.get('store').normalize('user', obj); + data.pushObject(this.get('store').push({ data: user })); }); return data; @@ -91,6 +95,9 @@ export default Ember.Service.extend({ return this.get('ajax').request(url, { method: 'DELETE' + }).then(() => { + let user = this.get('store').peekRecord('user', `${userId}`); + return user.deleteRecord(); }); }, From 624d00402e25bc80e6969fa171766a6ec5e58217 Mon Sep 17 00:00:00 2001 From: zinyando Date: Tue, 9 Aug 2016 13:16:29 +0200 Subject: [PATCH 02/25] Add document model and push document data to store --- app/app/models/attachment.js | 14 ++++++ app/app/models/document.js | 23 ++++++++++ app/app/models/folder.js | 7 +++ app/app/models/organization.js | 7 +++ app/app/models/page-meta.js | 14 ++++++ app/app/models/page.js | 32 +++++++++++++ app/app/models/template.js | 7 +++ .../serializers/{user.js => application.js} | 0 app/app/services/document.js | 45 ++++++++++++------- app/app/services/folder.js | 12 ++--- 10 files changed, 140 insertions(+), 21 deletions(-) create mode 100644 app/app/models/attachment.js create mode 100644 app/app/models/document.js create mode 100644 app/app/models/folder.js create mode 100644 app/app/models/organization.js create mode 100644 app/app/models/page-meta.js create mode 100644 app/app/models/page.js create mode 100644 app/app/models/template.js rename app/app/serializers/{user.js => application.js} (100%) diff --git a/app/app/models/attachment.js b/app/app/models/attachment.js new file mode 100644 index 000000000..f1cfa8d86 --- /dev/null +++ b/app/app/models/attachment.js @@ -0,0 +1,14 @@ +import Model from 'ember-data/model'; +import attr from 'ember-data/attr'; +// import { belongsTo, hasMany } from 'ember-data/relationships'; + +export default Model.extend({ + documentId: attr('string'), + extension: attr('string'), + fileId: attr('string'), + filename: attr('string'), + job: attr('string'), + orgId: attr('string'), + created: attr(), + revised: attr(), +}); diff --git a/app/app/models/document.js b/app/app/models/document.js new file mode 100644 index 000000000..5f7cad5f2 --- /dev/null +++ b/app/app/models/document.js @@ -0,0 +1,23 @@ +import Model from 'ember-data/model'; +import attr from 'ember-data/attr'; +import Ember from 'ember'; +import stringUtil from '../utils/string'; +// import { belongsTo, hasMany } from 'ember-data/relationships'; + +export default Model.extend({ + name: attr('string'), + excerpt: attr('string'), + job: attr('string'), + location: attr('string'), + orgId: attr('string'), + folderId: attr('string'), + userId: attr('string'), + tags: attr('string'), + template: attr('string'), + + // client-side property + selected: attr('boolean', { defaultValue: false }), + slug: Ember.computed('name', function () { + return stringUtil.makeSlug(this.get('name')); + }) +}); diff --git a/app/app/models/folder.js b/app/app/models/folder.js new file mode 100644 index 000000000..1246b0de1 --- /dev/null +++ b/app/app/models/folder.js @@ -0,0 +1,7 @@ +import Model from 'ember-data/model'; +// import attr from 'ember-data/attr'; +// import { belongsTo, hasMany } from 'ember-data/relationships'; + +export default Model.extend({ + +}); diff --git a/app/app/models/organization.js b/app/app/models/organization.js new file mode 100644 index 000000000..1246b0de1 --- /dev/null +++ b/app/app/models/organization.js @@ -0,0 +1,7 @@ +import Model from 'ember-data/model'; +// import attr from 'ember-data/attr'; +// import { belongsTo, hasMany } from 'ember-data/relationships'; + +export default Model.extend({ + +}); diff --git a/app/app/models/page-meta.js b/app/app/models/page-meta.js new file mode 100644 index 000000000..015345145 --- /dev/null +++ b/app/app/models/page-meta.js @@ -0,0 +1,14 @@ +import Model from 'ember-data/model'; +import attr from 'ember-data/attr'; +// import { belongsTo, hasMany } from 'ember-data/relationships'; + +export default Model.extend({ + pageId: attr('string'), + documentId: attr('string'), + orgId: attr('string'), + rawBody: attr('string'), + config: attr(), + externalSource: attr('boolean', { defaultValue: false }), + created: attr(), + revised: attr(), +}); diff --git a/app/app/models/page.js b/app/app/models/page.js new file mode 100644 index 000000000..48d6fb57d --- /dev/null +++ b/app/app/models/page.js @@ -0,0 +1,32 @@ +import Model from 'ember-data/model'; +import attr from 'ember-data/attr'; +import Ember from 'ember'; +// import { belongsTo, hasMany } from 'ember-data/relationships'; + +export default Model.extend({ + documentId: attr('string'), + orgId: attr('string'), + contentType: attr('string'), + level: attr('number', { defaultValue: 1 }), + sequence: attr('number', { defaultValue: 0 }), + revisions: attr('number', { defaultValue: 0 }), + title: attr('string'), + body: attr('string'), + rawBody: attr('string'), + meta: attr(), + created: attr(), + revised: attr(), + + tagName: Ember.computed('level', function () { + return "h" + this.get('level'); + }), + + tocIndent: Ember.computed('level', function () { + return (this.get('level') - 1) * 20; + }), + + tocIndentCss: Ember.computed('tocIndent', function () { + let tocIndent = this.get('tocIndent'); + return `margin-left-${tocIndent}`; + }) +}); diff --git a/app/app/models/template.js b/app/app/models/template.js new file mode 100644 index 000000000..1246b0de1 --- /dev/null +++ b/app/app/models/template.js @@ -0,0 +1,7 @@ +import Model from 'ember-data/model'; +// import attr from 'ember-data/attr'; +// import { belongsTo, hasMany } from 'ember-data/relationships'; + +export default Model.extend({ + +}); diff --git a/app/app/serializers/user.js b/app/app/serializers/application.js similarity index 100% rename from app/app/serializers/user.js rename to app/app/serializers/application.js diff --git a/app/app/services/document.js b/app/app/services/document.js index 1108e1589..96d0e9c81 100644 --- a/app/app/services/document.js +++ b/app/app/services/document.js @@ -10,18 +10,23 @@ // https://documize.com import Ember from 'ember'; -import models from '../utils/model'; + +const { + inject: { service } +} = Ember; export default Ember.Service.extend({ - sessionService: Ember.inject.service('session'), - ajax: Ember.inject.service(), + sessionService: service('session'), + ajax: service(), + store: service(), // Returns document model for specified document id. getDocument(documentId) { return this.get('ajax').request(`documents/${documentId}`, { method: "GET" }).then((response) => { - return models.DocumentModel.create(response); + let doc = this.get('store').normalize('document', response); + return this.get('store').push({ data: doc }); }); }, @@ -34,8 +39,9 @@ export default Ember.Service.extend({ content: Ember.A([]) }); - _.each(response, function (doc) { - let documentModel = models.DocumentModel.create(doc); + _.each(response, (doc) => { + let data = this.get('store').normalize('document', doc); + let documentModel = this.get('store').push({ data: data }); documents.pushObject(documentModel); }); @@ -53,7 +59,8 @@ export default Ember.Service.extend({ }); _.each(response, function (doc) { - let documentModel = models.DocumentModel.create(doc); + let data = this.get('store').normalize('document', doc); + let documentModel = this.get('store').push({ data: data }); documents.pushObject(documentModel); }); @@ -192,8 +199,10 @@ export default Ember.Service.extend({ method: 'GET' }).then((response) => { let data = []; - _.each(response, function (obj) { - data.pushObject(models.PageModel.create(obj)); + _.each(response, (obj) => { + let data = this.get('store').normalize('page', obj); + let tableOfContents = this.get('store').push({ data: data }); + data.pushObject(tableOfContents); }); return data; @@ -208,8 +217,10 @@ export default Ember.Service.extend({ }).then((response) => { let pages = []; - _.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); }); return pages; @@ -222,8 +233,8 @@ export default Ember.Service.extend({ return this.get('ajax').request(`documents/${documentId}/pages/${pageId}`, { method: 'GET' }).then((response) => { - let page = models.PageModel.create(response); - return page; + let data = this.get('store').normalize('page', response); + return this.get('store').push({ data: data }); }); }, @@ -233,8 +244,8 @@ export default Ember.Service.extend({ return this.get('ajax').request(`documents/${documentId}/pages/${pageId}/meta`, { method: 'GET' }).then((response) => { - let meta = models.PageMetaModel.create(response); - return meta; + let data = this.get('store').normalize('page-meta', response); + return this.get('store').push({ data: data }); }); }, @@ -246,7 +257,9 @@ export default Ember.Service.extend({ }).then((response) => { let data = []; _.each(response, function (obj) { - data.pushObject(models.AttachmentModel.create(obj)); + let data = this.get('store').normalize('attachment', obj); + let attachments = this.get('store').push({ data: data }); + data.pushObject(attachments); }); return data; }); diff --git a/app/app/services/folder.js b/app/app/services/folder.js index b8ac6f65f..c8f5cfad7 100644 --- a/app/app/services/folder.js +++ b/app/app/services/folder.js @@ -14,13 +14,15 @@ import models from '../utils/model'; import BaseService from '../services/base'; const { - get + get, + inject: { service } } = Ember; export default BaseService.extend({ - sessionService: Ember.inject.service('session'), - ajax: Ember.inject.service(), - localStorage: Ember.inject.service(), + sessionService: service('session'), + ajax: service(), + localStorage: service(), + store: service(), // selected folder currentFolder: null, @@ -203,4 +205,4 @@ export default BaseService.extend({ }); }); }, -}); \ No newline at end of file +}); From 87f7631880ea3d231fa71f0954c9bf63145f6af1 Mon Sep 17 00:00:00 2001 From: zinyando Date: Thu, 11 Aug 2016 10:47:53 +0200 Subject: [PATCH 03/25] Create folder model and push data into the store --- app/app/models/folder-permission.js | 12 +++++ app/app/models/folder.js | 28 ++++++++++- .../models/protected-folder-participant.js | 17 +++++++ app/app/serializers/folder-permission.js | 11 +++++ app/app/services/folder.js | 46 +++++++++++-------- 5 files changed, 93 insertions(+), 21 deletions(-) create mode 100644 app/app/models/folder-permission.js create mode 100644 app/app/models/protected-folder-participant.js create mode 100644 app/app/serializers/folder-permission.js diff --git a/app/app/models/folder-permission.js b/app/app/models/folder-permission.js new file mode 100644 index 000000000..2a979b517 --- /dev/null +++ b/app/app/models/folder-permission.js @@ -0,0 +1,12 @@ +import Model from 'ember-data/model'; +import attr from 'ember-data/attr'; +// import { belongsTo, hasMany } from 'ember-data/relationships'; + +export default Model.extend({ + orgId: attr('string'), + folderId: attr('string'), + userId: attr('string'), + fullname: attr('string'), + canView: attr('boolean', { defaultValue: false }), + canEdit: attr('boolean', { defaultValue: false }) +}); diff --git a/app/app/models/folder.js b/app/app/models/folder.js index 1246b0de1..e00735b2c 100644 --- a/app/app/models/folder.js +++ b/app/app/models/folder.js @@ -1,7 +1,33 @@ import Model from 'ember-data/model'; -// import attr from 'ember-data/attr'; +import attr from 'ember-data/attr'; +import constants from '../utils/constants'; +import stringUtil from '../utils/string'; // import { belongsTo, hasMany } from 'ember-data/relationships'; export default Model.extend({ + name: attr('string'), + orgId: attr('string'), + userId: attr('string'), + folderType: constants.FolderType.Private, + slug: Ember.computed('name', function () { + return stringUtil.makeSlug(this.get('name')); + }), + + markAsRestricted: function () { + this.set('folderType', constants.FolderType.Protected); + }, + + markAsPrivate: function () { + this.set('folderType', constants.FolderType.Private); + }, + + markAsPublic: function () { + this.set('folderType', constants.FolderType.Public); + }, + + // client-side prop that holds who can see this folder + sharedWith: attr(), + created: attr(), + revised: attr() }); diff --git a/app/app/models/protected-folder-participant.js b/app/app/models/protected-folder-participant.js new file mode 100644 index 000000000..995a391f3 --- /dev/null +++ b/app/app/models/protected-folder-participant.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({ + userId: attr('string'), + email: attr('string'), + firstname: attr('string'), + lastname: attr('string'), + name: attr('string'), + folderId: attr('string'), + folderType: attr('number', { defaultValue: 0 }), + + fullname: Ember.computed('firstname', 'lastname', function () { + return `${this.get('firstname')} ${this.get('lastname')}`; + }) +}); diff --git a/app/app/serializers/folder-permission.js b/app/app/serializers/folder-permission.js new file mode 100644 index 000000000..34f7b4d7a --- /dev/null +++ b/app/app/serializers/folder-permission.js @@ -0,0 +1,11 @@ +import ApplicationSerializer from './application'; + +export default ApplicationSerializer.extend({ + normalize(modelClass, resourceHash) { + return { + id: resourceHash.folderId, + type: modelClass.modelName, + attributes: resourceHash + }; + } +}); diff --git a/app/app/services/folder.js b/app/app/services/folder.js index c8f5cfad7..3230a8a9e 100644 --- a/app/app/services/folder.js +++ b/app/app/services/folder.js @@ -10,8 +10,8 @@ // https://documize.com import Ember from 'ember'; -import models from '../utils/model'; import BaseService from '../services/base'; +import models from '../utils/model'; const { get, @@ -35,8 +35,8 @@ export default BaseService.extend({ contentType: 'json', data: JSON.stringify(folder) }).then((folder) => { - let folderModel = models.FolderModel.create(folder); - return folderModel; + let data = this.get('store').normalize('folder', folder); + return this.get('store').push({ data: data }); }); }, @@ -45,19 +45,18 @@ export default BaseService.extend({ return this.get('ajax').request(`folders/${id}`, { method: 'GET' - }).then((response) => { - let folder = models.FolderModel.create(response); - return folder; + }).then((folder) => { + let data = this.get('store').normalize('folder', folder); + return this.get('store').push({ data: data }); }); }, // Returns all folders that user can see. getAll() { - let self = this; if (this.get('folders') != null) { - return new Ember.RSVP.Promise(function (resolve) { - resolve(self.get('folders')); + return new Ember.RSVP.Promise((resolve) => { + resolve(this.get('folders')); }); } else { return this.reload(); @@ -75,7 +74,7 @@ export default BaseService.extend({ }); }, - remove: function (folderId, moveToId) { + remove(folderId, moveToId) { let url = `folders/${folderId}/move/${moveToId}`; return this.get('ajax').request(url, { @@ -83,7 +82,7 @@ export default BaseService.extend({ }); }, - onboard: function (folderId, payload) { + onboard(folderId, payload) { let url = `public/share/${folderId}`; return this.get('ajax').post(url, { @@ -93,13 +92,16 @@ export default BaseService.extend({ }, // getProtectedFolderInfo returns non-private folders and who has access to them. - getProtectedFolderInfo: function () { + getProtectedFolderInfo() { return this.get('ajax').request(`folders?filter=viewers`, { method: "GET" }).then((response) => { let data = []; - _.each(response, function (obj) { - data.pushObject(models.ProtectedFolderParticipant.create(obj)); + _.each(response, (obj) => { + debugger; + let participantData = this.get('store').normalize('protected-folder-participant', obj); + let participant = this.get('store').push({ data: participantData }); + data.pushObject(participant); }); return data; @@ -113,8 +115,10 @@ export default BaseService.extend({ method: "GET" }).then((response) => { let data = []; - _.each(response, function (obj) { - data.pushObject(models.FolderModel.create(obj)); + _.each(response, (obj) => { + let folderData = this.get('store').normalize('folder', obj); + let folder = this.get('store').push({ data: folderData }); + data.pushObject(folder); }); return data; @@ -128,8 +132,10 @@ export default BaseService.extend({ method: "GET" }).then((response) => { let data = []; - _.each(response, function (obj) { - data.pushObject(models.FolderPermissionModel.create(obj)); + _.each(response, (obj) => { + let permissionData = this.get('store').normalize('folder-permission', obj); + let permission = this.get('store').push({ data: permissionData }); + data.pushObject(permission); }); return data; @@ -183,7 +189,7 @@ export default BaseService.extend({ let result = []; let folderId = folder.get('id'); - folderPermissions.forEach(function (item) { + folderPermissions.forEach((item) => { if (item.folderId === folderId) { result.push(item); } @@ -191,7 +197,7 @@ export default BaseService.extend({ let canEdit = false; - result.forEach(function (permission) { + result.forEach((permission) => { if (permission.userId === userId) { canEdit = permission.canEdit; } From d47f1e11b8d30f3e018c2dfcbf58a87f6858e752 Mon Sep 17 00:00:00 2001 From: zinyando Date: Thu, 11 Aug 2016 11:35:14 +0200 Subject: [PATCH 04/25] Push a user into store when a session is created --- app/app/services/session.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/app/services/session.js b/app/app/services/session.js index 00b4c8786..5194923e8 100644 --- a/app/app/services/session.js +++ b/app/app/services/session.js @@ -22,6 +22,7 @@ const { export default SimpleAuthSession.extend({ ajax: service(), appMeta: service(), + store: service(), isMac: false, isMobile: false, @@ -37,10 +38,11 @@ export default SimpleAuthSession.extend({ user: computed('isAuthenticated', 'session.content.authenticated.user', function () { if (this.get('isAuthenticated')) { let user = this.get('session.content.authenticated.user') || { id: '' }; - return models.UserModel.create(user); + let data = this.get('store').normalize('user', user); + return this.get('store').push({ data: data }); } }), folderPermissions: null, currentFolder: null -}); \ No newline at end of file +}); From b638d6a1145a61895da2ff1a049bafafc2a0e6c2 Mon Sep 17 00:00:00 2001 From: zinyando Date: Thu, 11 Aug 2016 14:38:36 +0200 Subject: [PATCH 05/25] Create attachment model and push attachment data into store --- app/app/components/layout/zone-navigation.js | 2 +- app/app/models/template.js | 14 ++- app/app/services/document.js | 6 +- app/app/services/session.js | 5 +- app/app/services/template.js | 89 +++++++++++--------- 5 files changed, 67 insertions(+), 49 deletions(-) diff --git a/app/app/components/layout/zone-navigation.js b/app/app/components/layout/zone-navigation.js index cf52fc08d..6ec0c85b1 100644 --- a/app/app/components/layout/zone-navigation.js +++ b/app/app/components/layout/zone-navigation.js @@ -19,7 +19,7 @@ export default Ember.Component.extend({ didInitAttrs() { if (this.get("session.authenticated")) { - this.get("session.user.accounts").forEach((account)=>{ + this.get("session.user.accounts").forEach((account) => { // TODO: do not mutate account.active here account.active = account.orgId === this.get("appMeta.orgId"); }); diff --git a/app/app/models/template.js b/app/app/models/template.js index 1246b0de1..2f9cbac8b 100644 --- a/app/app/models/template.js +++ b/app/app/models/template.js @@ -1,7 +1,19 @@ import Model from 'ember-data/model'; -// import attr from 'ember-data/attr'; +import attr from 'ember-data/attr'; +import stringUtil from '../utils/string'; +import Ember from 'ember'; // import { belongsTo, hasMany } from 'ember-data/relationships'; export default Model.extend({ + author: attr('string'), + dated: attr(), + description: attr('string'), + title: attr('string'), + type: attr('number', { defaultValue: 0 }), + slug: Ember.computed('title', function () { + return stringUtil.makeSlug(this.get('title')); + }), + created: attr(), + revised: attr() }); diff --git a/app/app/services/document.js b/app/app/services/document.js index 96d0e9c81..d0fa32838 100644 --- a/app/app/services/document.js +++ b/app/app/services/document.js @@ -256,9 +256,9 @@ export default Ember.Service.extend({ method: 'GET' }).then((response) => { let data = []; - _.each(response, function (obj) { - let data = this.get('store').normalize('attachment', obj); - let attachments = this.get('store').push({ data: data }); + _.each(response, (obj) => { + let attachmentData = this.get('store').normalize('attachment', obj); + let attachments = this.get('store').push({ data: attachmentData }); data.pushObject(attachments); }); return data; diff --git a/app/app/services/session.js b/app/app/services/session.js index 5194923e8..d95bdf5d4 100644 --- a/app/app/services/session.js +++ b/app/app/services/session.js @@ -38,8 +38,9 @@ export default SimpleAuthSession.extend({ user: computed('isAuthenticated', 'session.content.authenticated.user', function () { if (this.get('isAuthenticated')) { let user = this.get('session.content.authenticated.user') || { id: '' }; - let data = this.get('store').normalize('user', user); - return this.get('store').push({ data: data }); + // let data = this.get('store').normalize('user', user); + // return this.get('store').push({ data: data }); + return models.UserModel.create(user); } }), diff --git a/app/app/services/template.js b/app/app/services/template.js index eeea06464..9f9af1d85 100644 --- a/app/app/services/template.js +++ b/app/app/services/template.js @@ -12,52 +12,58 @@ import Ember from 'ember'; import models from '../utils/model'; +const { + inject: { service } +} = Ember; + export default Ember.Service.extend({ - sessionService: Ember.inject.service('session'), - ajax: Ember.inject.service(), + sessionService: service('session'), + ajax: service(), + store: service(), - importStockTemplate: function(folderId, templateId) { - let url = `templates/${templateId}/folder/${folderId}?type=stock`; + importStockTemplate: function (folderId, templateId) { + let url = `templates/${templateId}/folder/${folderId}?type=stock`; - return this.get('ajax').request(url, { - method: "POST" - }); - }, + return this.get('ajax').request(url, { + method: "POST" + }); + }, - importSavedTemplate: function(folderId, templateId) { - let url = `templates/${templateId}/folder/${folderId}?type=saved`; + importSavedTemplate: function (folderId, templateId) { + let url = `templates/${templateId}/folder/${folderId}?type=saved`; - return this.get('ajax').post(url).then((doc)=>{ - let docModel = models.DocumentModel.create(doc); - return docModel; - }); - }, + return this.get('ajax').post(url).then((doc) => { + let data = this.get('store').normalize('document', doc); + return this.get('store').push({ data: data }); + }); + }, - getSavedTemplates() { - return this.get('ajax').request(`templates`, { - method: 'GET' - }).then((response) => { - if (is.not.array(response)) { - response = []; - } - let templates = Ember.ArrayProxy.create({ - content: Ember.A([]) - }); + getSavedTemplates() { + return this.get('ajax').request(`templates`, { + method: 'GET' + }).then((response) => { + if (is.not.array(response)) { + response = []; + } + let templates = Ember.ArrayProxy.create({ + content: Ember.A([]) + }); - _.each(response, function(template) { - let templateModel = models.TemplateModel.create(template); - templates.pushObject(templateModel); - }); + _.each(response, (template) => { + let data = this.get('store').normalize('template', template); + let templateModel = this.get('store').push({ data: data }); + templates.pushObject(templateModel); + }); - return templates; - }); - }, + return templates; + }); + }, - getStockTemplates() { - return this.get('ajax').request(`templates/stock`, { - method: 'GET' - }); - }, + getStockTemplates() { + return this.get('ajax').request(`templates/stock`, { + method: 'GET' + }); + }, saveAsTemplate(documentId, name, excerpt) { let payload = { @@ -66,10 +72,9 @@ export default Ember.Service.extend({ Excerpt: excerpt }; - return this.get('ajax').request(`templates`, { - method: 'POST', - data: JSON.stringify(payload) - }).then(() => { - }); + return this.get('ajax').request(`templates`, { + method: 'POST', + data: JSON.stringify(payload) + }).then(() => {}); } }); From f6febf765c75203027efdd1f4f98cfb23b3ef526 Mon Sep 17 00:00:00 2001 From: zinyando Date: Thu, 11 Aug 2016 15:18:39 +0200 Subject: [PATCH 06/25] Create section model and push data into the store --- app/app/models/section.js | 17 ++++++++ app/app/services/section.js | 86 ++++++++++++++++++++----------------- 2 files changed, 63 insertions(+), 40 deletions(-) create mode 100644 app/app/models/section.js diff --git a/app/app/models/section.js b/app/app/models/section.js new file mode 100644 index 000000000..958fdc909 --- /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 9ea55d7ce..1d7d0d2c4 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; + }); + } }); From 6121e640d82516bc6da4301c6f6d3abff869a330 Mon Sep 17 00:00:00 2001 From: zinyando Date: Fri, 12 Aug 2016 14:02:57 +0200 Subject: [PATCH 07/25] Cleanup and fixes --- app/app/models/folder.js | 6 ++-- app/app/models/organization.js | 9 ++++-- app/app/services/document.js | 33 +++++++++---------- app/app/services/folder.js | 30 ++++++++---------- app/app/services/organization.js | 54 +++++++++++++++++--------------- app/app/services/section.js | 15 ++++----- app/app/services/template.js | 6 ++-- app/app/services/user.js | 8 ++--- 8 files changed, 79 insertions(+), 82 deletions(-) diff --git a/app/app/models/folder.js b/app/app/models/folder.js index e00735b2c..474ba4ac7 100644 --- a/app/app/models/folder.js +++ b/app/app/models/folder.js @@ -14,15 +14,15 @@ export default Model.extend({ return stringUtil.makeSlug(this.get('name')); }), - markAsRestricted: function () { + markAsRestricted() { this.set('folderType', constants.FolderType.Protected); }, - markAsPrivate: function () { + markAsPrivate() { this.set('folderType', constants.FolderType.Private); }, - markAsPublic: function () { + markAsPublic() { this.set('folderType', constants.FolderType.Public); }, diff --git a/app/app/models/organization.js b/app/app/models/organization.js index 1246b0de1..acaa9dc74 100644 --- a/app/app/models/organization.js +++ b/app/app/models/organization.js @@ -1,7 +1,12 @@ import Model from 'ember-data/model'; -// import attr from 'ember-data/attr'; +import attr from 'ember-data/attr'; // import { belongsTo, hasMany } from 'ember-data/relationships'; export default Model.extend({ - + title: attr('string'), + message: attr('string'), + email: attr('string'), + allowAnonymousAccess: attr('boolean', { defaultValue: false }), + created: attr(), + revised: attr() }); diff --git a/app/app/services/document.js b/app/app/services/document.js index d0fa32838..e1195640d 100644 --- a/app/app/services/document.js +++ b/app/app/services/document.js @@ -25,8 +25,8 @@ export default Ember.Service.extend({ return this.get('ajax').request(`documents/${documentId}`, { method: "GET" }).then((response) => { - let doc = this.get('store').normalize('document', response); - return this.get('store').push({ data: doc }); + let data = this.get('store').normalize('document', response); + return this.get('store').push({ data: data }); }); }, @@ -39,10 +39,9 @@ export default Ember.Service.extend({ content: Ember.A([]) }); - _.each(response, (doc) => { + documents = response.map((doc) => { let data = this.get('store').normalize('document', doc); - let documentModel = this.get('store').push({ data: data }); - documents.pushObject(documentModel); + return this.get('store').push({ data: data }); }); return documents; @@ -58,10 +57,9 @@ export default Ember.Service.extend({ content: Ember.A([]) }); - _.each(response, function (doc) { + documents = response.map((doc) => { let data = this.get('store').normalize('document', doc); - let documentModel = this.get('store').push({ data: data }); - documents.pushObject(documentModel); + return this.get('store').push({ data: data }); }); return documents; @@ -199,10 +197,9 @@ export default Ember.Service.extend({ method: 'GET' }).then((response) => { let data = []; - _.each(response, (obj) => { + data = response.map((obj) => { let data = this.get('store').normalize('page', obj); - let tableOfContents = this.get('store').push({ data: data }); - data.pushObject(tableOfContents); + return this.get('store').push({ data: data }); }); return data; @@ -217,10 +214,9 @@ export default Ember.Service.extend({ }).then((response) => { let pages = []; - _.each(response, (page) => { + pages = response.map((page) => { let data = this.get('store').normalize('page', page); - let pageData = this.get('store').push({ data: data }); - pages.pushObject(pageData); + return this.get('store').push({ data: data }); }); return pages; @@ -256,11 +252,12 @@ export default Ember.Service.extend({ method: 'GET' }).then((response) => { let data = []; - _.each(response, (obj) => { - let attachmentData = this.get('store').normalize('attachment', obj); - let attachments = this.get('store').push({ data: attachmentData }); - data.pushObject(attachments); + + data = response.map((obj) => { + let data = this.get('store').normalize('attachment', obj); + return this.get('store').push({ data: data }); }); + return data; }); }, diff --git a/app/app/services/folder.js b/app/app/services/folder.js index 3230a8a9e..5de258dde 100644 --- a/app/app/services/folder.js +++ b/app/app/services/folder.js @@ -11,7 +11,6 @@ import Ember from 'ember'; import BaseService from '../services/base'; -import models from '../utils/model'; const { get, @@ -55,9 +54,7 @@ export default BaseService.extend({ getAll() { if (this.get('folders') != null) { - return new Ember.RSVP.Promise((resolve) => { - resolve(this.get('folders')); - }); + return new Ember.RSVP.resolve(this.get('folders')); } else { return this.reload(); } @@ -97,11 +94,10 @@ export default BaseService.extend({ method: "GET" }).then((response) => { let data = []; - _.each(response, (obj) => { - debugger; - let participantData = this.get('store').normalize('protected-folder-participant', obj); - let participant = this.get('store').push({ data: participantData }); - data.pushObject(participant); + + data = response.map((obj) => { + let data = this.get('store').normalize('protected-folder-participant', obj); + return this.get('store').push({ data: data }); }); return data; @@ -115,10 +111,10 @@ export default BaseService.extend({ method: "GET" }).then((response) => { let data = []; - _.each(response, (obj) => { - let folderData = this.get('store').normalize('folder', obj); - let folder = this.get('store').push({ data: folderData }); - data.pushObject(folder); + + data = response.map((obj) => { + let data = this.get('store').normalize('folder', obj); + return this.get('store').push({ data: data }); }); return data; @@ -132,10 +128,10 @@ export default BaseService.extend({ method: "GET" }).then((response) => { let data = []; - _.each(response, (obj) => { - let permissionData = this.get('store').normalize('folder-permission', obj); - let permission = this.get('store').push({ data: permissionData }); - data.pushObject(permission); + + data = response.map((obj) => { + let data = this.get('store').normalize('folder-permission', obj); + return this.get('store').push({ data: data }); }); return data; diff --git a/app/app/services/organization.js b/app/app/services/organization.js index cfe86fea1..5740d2859 100644 --- a/app/app/services/organization.js +++ b/app/app/services/organization.js @@ -10,35 +10,39 @@ // https://documize.com import Ember from 'ember'; -import models from '../utils/model'; + +const { + inject: { service } +} = Ember; export default Ember.Service.extend({ - sessionService: Ember.inject.service('session'), - ajax: Ember.inject.service(), - appMeta: Ember.inject.service(), + sessionService: service('session'), + ajax: service(), + appMeta: service(), + store: service(), - // Returns attributes for specified org id. - getOrg(id) { - return this.get('ajax').request(`organizations/${id}`, { - method: 'GET' - }).then((response) =>{ - let org = models.OrganizationModel.create(response); - return org; - }); - }, + // Returns attributes for specified org id. + getOrg(id) { + return this.get('ajax').request(`organizations/${id}`, { + method: 'GET' + }).then((response) => { + let data = this.get('store').normalize('organization', response); + return this.get('store').push({ data: data }); + }); + }, - // Updates an existing organization record. - save(org) { - let id = org.get('id'); + // Updates an existing organization record. + save(org) { + let id = org.get('id'); - this.get('appMeta').setProperties({ - message: org.message, - title: org.title - }); + this.get('appMeta').setProperties({ + message: org.message, + title: org.title + }); - return this.get('ajax').request(`organizations/${id}`, { - method: 'PUT', - data: JSON.stringify(org) - }); - } + return this.get('ajax').request(`organizations/${id}`, { + method: 'PUT', + data: JSON.stringify(org) + }); + } }); diff --git a/app/app/services/section.js b/app/app/services/section.js index 1d7d0d2c4..0f304bda3 100644 --- a/app/app/services/section.js +++ b/app/app/services/section.js @@ -10,7 +10,6 @@ // https://documize.com import Ember from 'ember'; -import models from '../utils/model'; import BaseService from '../services/base'; export default BaseService.extend({ @@ -24,11 +23,10 @@ export default BaseService.extend({ 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); + + data = response.map((obj) => { + let data = this.get('store').normalize('section', obj); + return this.get('store').push({ data: data }); }); return data; @@ -58,10 +56,9 @@ export default BaseService.extend({ let pages = []; if (is.not.null(response) && is.array(response) && response.length > 0) { - _.each(response, (page) => { + pages = response.map((page) => { let data = this.get('store').normalize('page', page); - let pageData = this.get('store').push({ data: data }); - pages.pushObject(pageData); + return this.get('store').push({ data: data }); }); } diff --git a/app/app/services/template.js b/app/app/services/template.js index 9f9af1d85..ad5c9d020 100644 --- a/app/app/services/template.js +++ b/app/app/services/template.js @@ -10,7 +10,6 @@ // https://documize.com import Ember from 'ember'; -import models from '../utils/model'; const { inject: { service } @@ -49,10 +48,9 @@ export default Ember.Service.extend({ content: Ember.A([]) }); - _.each(response, (template) => { + templates = response.map((template) => { let data = this.get('store').normalize('template', template); - let templateModel = this.get('store').push({ data: data }); - templates.pushObject(templateModel); + return this.get('store').push({ data: data }); }); return templates; diff --git a/app/app/services/user.js b/app/app/services/user.js index f9afd0d76..618e31044 100644 --- a/app/app/services/user.js +++ b/app/app/services/user.js @@ -10,7 +10,6 @@ // https://documize.com import Ember from 'ember'; -// import models from '../utils/model'; export default Ember.Service.extend({ sessionService: Ember.inject.service('session'), @@ -59,9 +58,10 @@ export default Ember.Service.extend({ method: "GET" }).then((response) => { let data = []; - _.each(response, (obj) => { - let user = this.get('store').normalize('user', obj); - data.pushObject(this.get('store').push({ data: user })); + + data = response.map((obj) => { + let data = this.get('store').normalize('user', obj); + return this.get('store').push({ data: data }) }); return data; From a63a6cd709e25dc3ab4eee1b9d27ccad512ac4f1 Mon Sep 17 00:00:00 2001 From: zinyando Date: Tue, 16 Aug 2016 13:34:09 +0200 Subject: [PATCH 08/25] Clean up --- app/app/models/folder.js | 1 + .../models/protected-folder-participant.js | 1 + app/app/models/section.js | 1 + app/app/services/ajax.js | 9 ++--- app/app/services/audit.js | 8 +++-- app/app/services/document.js | 8 +++++ app/app/services/folder.js | 4 +-- app/app/services/search.js | 22 +++++++----- app/app/services/section.js | 10 ++++-- app/app/services/user.js | 34 +++++++++++-------- 10 files changed, 64 insertions(+), 34 deletions(-) diff --git a/app/app/models/folder.js b/app/app/models/folder.js index 474ba4ac7..1c2363471 100644 --- a/app/app/models/folder.js +++ b/app/app/models/folder.js @@ -2,6 +2,7 @@ import Model from 'ember-data/model'; import attr from 'ember-data/attr'; import constants from '../utils/constants'; import stringUtil from '../utils/string'; +import Ember from 'ember'; // import { belongsTo, hasMany } from 'ember-data/relationships'; export default Model.extend({ diff --git a/app/app/models/protected-folder-participant.js b/app/app/models/protected-folder-participant.js index 995a391f3..709153495 100644 --- a/app/app/models/protected-folder-participant.js +++ b/app/app/models/protected-folder-participant.js @@ -1,5 +1,6 @@ import Model from 'ember-data/model'; import attr from 'ember-data/attr'; +import Ember from 'ember'; // import { belongsTo, hasMany } from 'ember-data/relationships'; export default Model.extend({ diff --git a/app/app/models/section.js b/app/app/models/section.js index 958fdc909..30fdd40d4 100644 --- a/app/app/models/section.js +++ b/app/app/models/section.js @@ -1,5 +1,6 @@ import Model from 'ember-data/model'; import attr from 'ember-data/attr'; +import Ember from 'ember'; // import { belongsTo, hasMany } from 'ember-data/relationships'; export default Model.extend({ diff --git a/app/app/services/ajax.js b/app/app/services/ajax.js index ebab3af98..c28f5dcc8 100644 --- a/app/app/services/ajax.js +++ b/app/app/services/ajax.js @@ -1,11 +1,11 @@ // Copyright 2016 Documize Inc. . All rights reserved. // -// This software (Documize Community Edition) is licensed under +// This software (Documize Community Edition) is licensed under // GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html // // You can operate outside the AGPL restrictions by purchasing // Documize Enterprise Edition and obtaining a commercial license -// by contacting . +// by contacting . // // https://documize.com @@ -14,6 +14,7 @@ import AjaxService from 'ember-ajax/services/ajax'; import config from '../config/environment'; const { + computed, inject: { service } } = Ember; @@ -22,7 +23,7 @@ export default AjaxService.extend({ host: config.apiHost, namespace: config.apiNamespace, - headers: Ember.computed('session.session.content.authenticated.token', { + headers: computed('session.session.content.authenticated.token', { get() { let headers = {}; const token = this.get('session.session.content.authenticated.token'); @@ -33,4 +34,4 @@ export default AjaxService.extend({ return headers; } }) -}); \ No newline at end of file +}); diff --git a/app/app/services/audit.js b/app/app/services/audit.js index 50d375100..742e66f99 100644 --- a/app/app/services/audit.js +++ b/app/app/services/audit.js @@ -13,9 +13,13 @@ import Ember from 'ember'; import netUtil from '../utils/net'; import config from '../config/environment'; +const { + inject: { service } +} = Ember; + export default Ember.Service.extend({ - session: Ember.inject.service('session'), - appMeta: Ember.inject.service(), + session: service('session'), + appMeta: service(), ready: false, enabled: config.APP.auditEnabled, appId: config.APP.intercomKey, diff --git a/app/app/services/document.js b/app/app/services/document.js index e1195640d..8c8fe45e0 100644 --- a/app/app/services/document.js +++ b/app/app/services/document.js @@ -253,6 +253,10 @@ export default Ember.Service.extend({ }).then((response) => { let data = []; + if (isObject(response)) { + return data; + } + data = response.map((obj) => { let data = this.get('store').normalize('attachment', obj); return this.get('store').push({ data: data }); @@ -270,3 +274,7 @@ export default Ember.Service.extend({ }); }, }); + +function isObject(a) { + return (!!a) && (a.constructor === Object); +} diff --git a/app/app/services/folder.js b/app/app/services/folder.js index 5de258dde..183a35792 100644 --- a/app/app/services/folder.js +++ b/app/app/services/folder.js @@ -14,6 +14,7 @@ import BaseService from '../services/base'; const { get, + RSVP: { resolve }, inject: { service } } = Ember; @@ -29,7 +30,6 @@ export default BaseService.extend({ // Add a new folder. add(folder) { - return this.get('ajax').post(`folders`, { contentType: 'json', data: JSON.stringify(folder) @@ -54,7 +54,7 @@ export default BaseService.extend({ getAll() { if (this.get('folders') != null) { - return new Ember.RSVP.resolve(this.get('folders')); + return new resolve(this.get('folders')); } else { return this.reload(); } diff --git a/app/app/services/search.js b/app/app/services/search.js index a669a67c2..e962b45a7 100644 --- a/app/app/services/search.js +++ b/app/app/services/search.js @@ -11,16 +11,20 @@ import Ember from 'ember'; +const { + inject: { service } +} = Ember; + export default Ember.Service.extend({ - sessionService: Ember.inject.service('session'), - ajax: Ember.inject.service(), + sessionService: service('session'), + ajax: service(), - // getUsers returns all users for organization. - find(keywords) { - let url = "search?keywords=" + encodeURIComponent(keywords); + // getUsers returns all users for organization. + find(keywords) { + let url = "search?keywords=" + encodeURIComponent(keywords); - return this.get('ajax').request(url, { - method: "GET" - }); - }, + return this.get('ajax').request(url, { + method: "GET" + }); + }, }); diff --git a/app/app/services/section.js b/app/app/services/section.js index 0f304bda3..000a8ef7f 100644 --- a/app/app/services/section.js +++ b/app/app/services/section.js @@ -12,10 +12,14 @@ import Ember from 'ember'; import BaseService from '../services/base'; +const { + inject: { service } +} = Ember; + export default BaseService.extend({ - sessionService: Ember.inject.service('session'), - ajax: Ember.inject.service(), - store: Ember.inject.service(), + sessionService: service('session'), + ajax: service(), + store: service(), // Returns all available sections. getAll() { diff --git a/app/app/services/user.js b/app/app/services/user.js index 618e31044..e28bc3949 100644 --- a/app/app/services/user.js +++ b/app/app/services/user.js @@ -11,10 +11,16 @@ import Ember from 'ember'; +const { + isEmpty, + RSVP, + inject: { service } +} = Ember; + export default Ember.Service.extend({ - sessionService: Ember.inject.service('session'), - ajax: Ember.inject.service(), - store: Ember.inject.service(), + sessionService: service('session'), + ajax: service(), + store: service(), // Adds a new user. add(user) { @@ -23,8 +29,8 @@ export default Ember.Service.extend({ data: JSON.stringify(user), contentType: 'json' }).then((response) => { - let user = this.get('store').normalize('user', response); - return this.get('store').push({ data: user }); + let data = this.get('store').normalize('user', response); + return this.get('store').push({ data: data }); }); }, @@ -35,8 +41,8 @@ export default Ember.Service.extend({ return this.get('ajax').request(url, { type: 'GET' }).then((response) => { - let user = this.get('store').normalize('user', response); - return this.get('store').push({ data: user }); + let data = this.get('store').normalize('user', response); + return this.get('store').push({ data: data }); }); }, @@ -44,8 +50,8 @@ export default Ember.Service.extend({ getAll() { return this.get('ajax').request(`users`).then((response) => { return response.map((obj) => { - let user = this.get('store').normalize('user', obj); - return this.get('store').push({ data: user }); + let data = this.get('store').normalize('user', obj); + return this.get('store').push({ data: data }); }); }); }, @@ -61,7 +67,7 @@ export default Ember.Service.extend({ data = response.map((obj) => { let data = this.get('store').normalize('user', obj); - return this.get('store').push({ data: data }) + return this.get('store').push({ data: data }); }); return data; @@ -105,8 +111,8 @@ export default Ember.Service.extend({ forgotPassword(email) { let url = `public/forgot`; - if (is.empty(email)) { - return Ember.RSVP.reject("invalid"); + if (isEmpty(email)) { + return RSVP.reject("invalid"); } let data = JSON.stringify({ @@ -124,8 +130,8 @@ export default Ember.Service.extend({ resetPassword(token, password) { var url = `public/reset/${token}`; - if (is.empty(token) || is.empty(password)) { - return Ember.RSVP.reject("invalid"); + if (isEmpty(token) || isEmpty(password)) { + return RSVP.reject("invalid"); } return this.get('ajax').request(url, { From 30d1318d92b4d51da96f482071f40d1c9f750fb7 Mon Sep 17 00:00:00 2001 From: zinyando Date: Tue, 16 Aug 2016 13:36:26 +0200 Subject: [PATCH 09/25] Add license information to javascript files --- app/app/models/attachment.js | 11 +++++++++++ app/app/models/document.js | 11 +++++++++++ app/app/models/folder-permission.js | 11 +++++++++++ app/app/models/folder.js | 11 +++++++++++ app/app/models/organization.js | 11 +++++++++++ app/app/models/page-meta.js | 11 +++++++++++ app/app/models/page.js | 11 +++++++++++ app/app/models/protected-folder-participant.js | 11 +++++++++++ app/app/models/section.js | 11 +++++++++++ app/app/models/template.js | 11 +++++++++++ app/app/models/user.js | 11 +++++++++++ 11 files changed, 121 insertions(+) diff --git a/app/app/models/attachment.js b/app/app/models/attachment.js index f1cfa8d86..473a497ba 100644 --- a/app/app/models/attachment.js +++ b/app/app/models/attachment.js @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + import Model from 'ember-data/model'; import attr from 'ember-data/attr'; // import { belongsTo, hasMany } from 'ember-data/relationships'; diff --git a/app/app/models/document.js b/app/app/models/document.js index 5f7cad5f2..2b9642288 100644 --- a/app/app/models/document.js +++ b/app/app/models/document.js @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + import Model from 'ember-data/model'; import attr from 'ember-data/attr'; import Ember from 'ember'; diff --git a/app/app/models/folder-permission.js b/app/app/models/folder-permission.js index 2a979b517..58f01b048 100644 --- a/app/app/models/folder-permission.js +++ b/app/app/models/folder-permission.js @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + import Model from 'ember-data/model'; import attr from 'ember-data/attr'; // import { belongsTo, hasMany } from 'ember-data/relationships'; diff --git a/app/app/models/folder.js b/app/app/models/folder.js index 1c2363471..662e045cf 100644 --- a/app/app/models/folder.js +++ b/app/app/models/folder.js @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + import Model from 'ember-data/model'; import attr from 'ember-data/attr'; import constants from '../utils/constants'; diff --git a/app/app/models/organization.js b/app/app/models/organization.js index acaa9dc74..db50b26e0 100644 --- a/app/app/models/organization.js +++ b/app/app/models/organization.js @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + import Model from 'ember-data/model'; import attr from 'ember-data/attr'; // import { belongsTo, hasMany } from 'ember-data/relationships'; diff --git a/app/app/models/page-meta.js b/app/app/models/page-meta.js index 015345145..593b41a99 100644 --- a/app/app/models/page-meta.js +++ b/app/app/models/page-meta.js @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + import Model from 'ember-data/model'; import attr from 'ember-data/attr'; // import { belongsTo, hasMany } from 'ember-data/relationships'; diff --git a/app/app/models/page.js b/app/app/models/page.js index 48d6fb57d..f09557823 100644 --- a/app/app/models/page.js +++ b/app/app/models/page.js @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + import Model from 'ember-data/model'; import attr from 'ember-data/attr'; import Ember from 'ember'; diff --git a/app/app/models/protected-folder-participant.js b/app/app/models/protected-folder-participant.js index 709153495..ddfe1f35e 100644 --- a/app/app/models/protected-folder-participant.js +++ b/app/app/models/protected-folder-participant.js @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + import Model from 'ember-data/model'; import attr from 'ember-data/attr'; import Ember from 'ember'; diff --git a/app/app/models/section.js b/app/app/models/section.js index 30fdd40d4..8887648be 100644 --- a/app/app/models/section.js +++ b/app/app/models/section.js @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + import Model from 'ember-data/model'; import attr from 'ember-data/attr'; import Ember from 'ember'; diff --git a/app/app/models/template.js b/app/app/models/template.js index 2f9cbac8b..7f6a02ff3 100644 --- a/app/app/models/template.js +++ b/app/app/models/template.js @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + import Model from 'ember-data/model'; import attr from 'ember-data/attr'; import stringUtil from '../utils/string'; diff --git a/app/app/models/user.js b/app/app/models/user.js index 95357bd09..d2eaa8694 100644 --- a/app/app/models/user.js +++ b/app/app/models/user.js @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + import Model from 'ember-data/model'; import attr from 'ember-data/attr'; import Ember from 'ember'; From e87b33a8c24a15a894cbdff1cc717f899baeeb96 Mon Sep 17 00:00:00 2001 From: zinyando Date: Wed, 17 Aug 2016 15:37:46 +0200 Subject: [PATCH 10/25] More refactoring and fixes --- app/app/components/folder/folder-settings.js | 194 ++++++++++--------- app/app/components/folder/folders-list.js | 119 ++++++------ app/app/models/folder.js | 2 +- app/app/pods/folders/folder/route.js | 6 +- app/app/pods/folders/route.js | 2 +- app/app/pods/folders/settings/route.js | 36 ++-- app/app/services/document.js | 4 + app/app/services/folder.js | 14 +- app/app/services/organization.js | 6 +- 9 files changed, 196 insertions(+), 187 deletions(-) diff --git a/app/app/components/folder/folder-settings.js b/app/app/components/folder/folder-settings.js index 5339437dc..7b065f56a 100644 --- a/app/app/components/folder/folder-settings.js +++ b/app/app/components/folder/folder-settings.js @@ -11,100 +11,104 @@ import Ember from 'ember'; +const { + inject: { service } +} = Ember; + export default Ember.Component.extend({ - folderService: Ember.inject.service('folder'), - appMeta: Ember.inject.service(), - users: [], - folders: [], - folder: {}, - moveTarget: null, - inviteEmail: "", - inviteMessage: "", - roleMessage: "", - permissions: {}, - - getDefaultInvitationMessage() { - return "Hey there, I am sharing the " + this.folder.get('name') + " (in " + this.get("appMeta.title") + ") with you so we can both access the same documents."; - }, - - willRender() { - if (this.inviteMessage.length === 0) { - this.set('inviteMessage', this.getDefaultInvitationMessage()); - } - - if (this.roleMessage.length === 0) { - this.set('roleMessage', this.getDefaultInvitationMessage()); - } - }, - - actions: { - rename() { - if (is.empty(this.folder.get('name'))) { - $("#folderName").addClass("error").focus(); - return; - } - - this.sendAction("onRename", this.folder); - }, - - remove() { - if (is.null(this.get('moveTarget'))) { - $("#delete-target > select").addClass("error").focus(); - return; - } - - this.sendAction("onRemove", this.get('moveTarget').get('id')); - }, - - share() { - var email = this.get('inviteEmail').trim().replace(/ /g, ''); - var message = this.get('inviteMessage').trim(); - - if (message.length === 0) { - message = this.getDefaultInvitationMessage(); - } - - if (email.length === 0) { - $("#inviteEmail").addClass("error").focus(); - return; - } - - var result = { - Message: message, - Recipients: [] - }; - - // Check for multiple email addresses - if (email.indexOf(",") > -1) { - result.Recipients = email.split(','); - } - if (email.indexOf(";") > -1 && result.Recipients.length === 0) { - result.Recipients = email.split(';'); - } - - // Handle just one email address - if (result.Recipients.length === 0 && email.length > 0) { - result.Recipients.push(email); - } - - this.set('inviteEmail', ""); - - this.sendAction("onShare", result); - }, - - setPermissions() { - var message = this.get('roleMessage').trim(); - - if (message.length === 0) { - message = this.getDefaultInvitationMessage(); - } - - this.get('permissions').forEach(function(permission, index) /* jshint ignore:line */ { - Ember.set(permission, 'canView', $("#canView-" + permission.userId).prop('checked')); - Ember.set(permission, 'canEdit', $("#canEdit-" + permission.userId).prop('checked')); - }); - - this.sendAction("onPermission", this.get('folder'), message, this.get('permissions')); - } - } + folderService: service('folder'), + appMeta: service(), + users: [], + folders: [], + folder: {}, + moveTarget: null, + inviteEmail: "", + inviteMessage: "", + roleMessage: "", + permissions: {}, + + getDefaultInvitationMessage() { + return "Hey there, I am sharing the " + this.folder.get('name') + " (in " + this.get("appMeta.title") + ") with you so we can both access the same documents."; + }, + + willRender() { + if (this.inviteMessage.length === 0) { + this.set('inviteMessage', this.getDefaultInvitationMessage()); + } + + if (this.roleMessage.length === 0) { + this.set('roleMessage', this.getDefaultInvitationMessage()); + } + }, + + actions: { + rename() { + if (is.empty(this.folder.get('name'))) { + $("#folderName").addClass("error").focus(); + return; + } + + this.sendAction("onRename", this.folder); + }, + + remove() { + if (is.null(this.get('moveTarget'))) { + $("#delete-target > select").addClass("error").focus(); + return; + } + + this.sendAction("onRemove", this.get('moveTarget').get('id')); + }, + + share() { + var email = this.get('inviteEmail').trim().replace(/ /g, ''); + var message = this.get('inviteMessage').trim(); + + if (message.length === 0) { + message = this.getDefaultInvitationMessage(); + } + + if (email.length === 0) { + $("#inviteEmail").addClass("error").focus(); + return; + } + + var result = { + Message: message, + Recipients: [] + }; + + // Check for multiple email addresses + if (email.indexOf(",") > -1) { + result.Recipients = email.split(','); + } + if (email.indexOf(";") > -1 && result.Recipients.length === 0) { + result.Recipients = email.split(';'); + } + + // Handle just one email address + if (result.Recipients.length === 0 && email.length > 0) { + result.Recipients.push(email); + } + + this.set('inviteEmail', ""); + + this.sendAction("onShare", result); + }, + + setPermissions() { + var message = this.get('roleMessage').trim(); + + if (message.length === 0) { + message = this.getDefaultInvitationMessage(); + } + + this.get('permissions').forEach((permission, index) => { /* jshint ignore:line */ + Ember.set(permission, 'canView', $("#canView-" + permission.userId).prop('checked')); + Ember.set(permission, 'canEdit', $("#canEdit-" + permission.userId).prop('checked')); + }); + + this.sendAction("onPermission", this.get('folder'), message, this.get('permissions')); + } + } }); diff --git a/app/app/components/folder/folders-list.js b/app/app/components/folder/folders-list.js index 7f7308509..31a61e44f 100644 --- a/app/app/components/folder/folders-list.js +++ b/app/app/components/folder/folders-list.js @@ -1,11 +1,11 @@ // Copyright 2016 Documize Inc. . All rights reserved. // -// This software (Documize Community Edition) is licensed under +// This software (Documize Community Edition) is licensed under // GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html // // You can operate outside the AGPL restrictions by purchasing // Documize Enterprise Edition and obtaining a commercial license -// by contacting . +// by contacting . // // https://documize.com @@ -14,71 +14,70 @@ import constants from '../../utils/constants'; import TooltipMixin from '../../mixins/tooltip'; export default Ember.Component.extend(TooltipMixin, { - folderService: Ember.inject.service('folder'), - publicFolders: [], - protectedFolders: [], - privateFolders: [], - hasPublicFolders: false, - hasProtectedFolders: false, - hasPrivateFolders: false, - newFolder: "", + folderService: Ember.inject.service('folder'), + publicFolders: [], + protectedFolders: [], + privateFolders: [], + hasPublicFolders: false, + hasProtectedFolders: false, + hasPrivateFolders: false, + newFolder: "", - didInsertElement() { - this._super(...arguments); - if (this.session.authenticated) { - this.addTooltip(document.getElementById("add-folder-button")); - } - }, + didInsertElement() { + this._super(...arguments); + if (this.session.authenticated) { + this.addTooltip(document.getElementById("add-folder-button")); + } + }, - didReceiveAttrs() { - let folders = this.get('folders'); - let self = this; + didReceiveAttrs() { + let folders = this.get('folders'); - // clear out state - this.set('publicFolders', []); - this.set('protectedFolders', []); - this.set('privateFolders', []); + // clear out state + this.set('publicFolders', []); + this.set('protectedFolders', []); + this.set('privateFolders', []); - _.each(folders, folder => { - if (folder.folderType === constants.FolderType.Public) { - let folders = self.get('publicFolders'); - folders.pushObject(folder); - self.set('publicFolders', folders); - } - if (folder.folderType === constants.FolderType.Private) { - let folders = self.get('privateFolders'); - folders.pushObject(folder); - self.set('privateFolders', folders); - } - if (folder.folderType === constants.FolderType.Protected) { - let folders = self.get('protectedFolders'); - folders.pushObject(folder); - self.set('protectedFolders', folders); - } - }); + _.each(folders, folder => { + if (folder.get('folderType') === constants.FolderType.Public) { + let folders = this.get('publicFolders'); + folders.pushObject(folder); + this.set('publicFolders', folders); + } + if (folder.get('folderType') === constants.FolderType.Private) { + let folders = this.get('privateFolders'); + folders.pushObject(folder); + this.set('privateFolders', folders); + } + if (folder.get('folderType') === constants.FolderType.Protected) { + let folders = this.get('protectedFolders'); + folders.pushObject(folder); + this.set('protectedFolders', folders); + } + }); - this.set('hasPublicFolders', this.get('publicFolders.length') > 0); - this.set('hasPrivateFolders', this.get('privateFolders.length') > 0); - this.set('hasProtectedFolders', this.get('protectedFolders.length') > 0); - }, + this.set('hasPublicFolders', this.get('publicFolders.length') > 0); + this.set('hasPrivateFolders', this.get('privateFolders.length') > 0); + this.set('hasProtectedFolders', this.get('protectedFolders.length') > 0); + }, - willDestroyElement() { - this.destroyTooltips(); - }, + willDestroyElement() { + this.destroyTooltips(); + }, - actions: { - addFolder() { - var folderName = this.get('newFolder'); + actions: { + addFolder() { + var folderName = this.get('newFolder'); - if (is.empty(folderName)) { - $("#new-folder-name").addClass("error").focus(); - return false; - } + if (is.empty(folderName)) { + $("#new-folder-name").addClass("error").focus(); + return false; + } - this.attrs.onFolderAdd(folderName); + this.attrs.onFolderAdd(folderName); - this.set('newFolder', ""); - return true; - } - } -}); \ No newline at end of file + this.set('newFolder', ""); + return true; + } + } +}); diff --git a/app/app/models/folder.js b/app/app/models/folder.js index 662e045cf..b8d35a712 100644 --- a/app/app/models/folder.js +++ b/app/app/models/folder.js @@ -20,7 +20,7 @@ export default Model.extend({ name: attr('string'), orgId: attr('string'), userId: attr('string'), - folderType: constants.FolderType.Private, + folderType: attr('number', { defaultValue: 2 }), slug: Ember.computed('name', function () { return stringUtil.makeSlug(this.get('name')); diff --git a/app/app/pods/folders/folder/route.js b/app/app/pods/folders/folder/route.js index 50ab6b7f3..329faf8f6 100644 --- a/app/app/pods/folders/folder/route.js +++ b/app/app/pods/folders/folder/route.js @@ -1,11 +1,11 @@ // Copyright 2016 Documize Inc. . All rights reserved. // -// This software (Documize Community Edition) is licensed under +// This software (Documize Community Edition) is licensed under // GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html // // You can operate outside the AGPL restrictions by purchasing // Documize Enterprise Edition and obtaining a commercial license -// by contacting . +// by contacting . // // https://documize.com @@ -31,4 +31,4 @@ export default Ember.Route.extend(AuthenticatedRouteMixin, { this.browser.setTitle(model.folder.get('name')); this.get('folderService').setCurrentFolder(model.folder); } -}); \ No newline at end of file +}); diff --git a/app/app/pods/folders/route.js b/app/app/pods/folders/route.js index d525af187..27b77e8f8 100644 --- a/app/app/pods/folders/route.js +++ b/app/app/pods/folders/route.js @@ -27,7 +27,7 @@ export default Ember.Route.extend(AuthenticatedRouteMixin, { }, afterModel: function (model) { - + debugger; let params = this.paramsFor('folders.folder'); if (is.empty(params)) { diff --git a/app/app/pods/folders/settings/route.js b/app/app/pods/folders/settings/route.js index a75a0f97e..66b6c0205 100644 --- a/app/app/pods/folders/settings/route.js +++ b/app/app/pods/folders/settings/route.js @@ -1,11 +1,11 @@ // Copyright 2016 Documize Inc. . All rights reserved. // -// This software (Documize Community Edition) is licensed under +// This software (Documize Community Edition) is licensed under // GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html // // You can operate outside the AGPL restrictions by purchasing // Documize Enterprise Edition and obtaining a commercial license -// by contacting . +// by contacting . // // https://documize.com @@ -13,11 +13,16 @@ import Ember from 'ember'; import models from '../../../utils/model'; import NotifierMixin from '../../../mixins/notifier'; +const { + inject: { service } +} = Ember; + export default Ember.Route.extend(NotifierMixin, { - folderService: Ember.inject.service('folder'), - userService: Ember.inject.service('user'), + folderService: service('folder'), + userService: service('user'), folder: {}, tab: "", + localStorage: service(), beforeModel: function (transition) { this.tab = is.not.undefined(transition.queryParams.tab) ? transition.queryParams.tab : "tabGeneral"; @@ -100,36 +105,33 @@ export default Ember.Route.extend(NotifierMixin, { }, onRemove(moveId) { - let self = this; - this.get('folderService').remove(this.folder.get('id'), moveId).then(function () { /* jshint ignore:line */ - self.showNotification("Deleted"); - self.session.clearSessionItem('folder'); + this.get('folderService').remove(this.folder.get('id'), moveId).then(() => { /* jshint ignore:line */ + this.showNotification("Deleted"); + this.get('localStorage').clearSessionItem('folder'); - self.get('folderService').getFolder(moveId).then(function (folder) { - self.get('folderService').setCurrentFolder(folder); - self.transitionTo('folders.folder', folder.get('id'), folder.get('slug')); + this.get('folderService').getFolder(moveId).then((folder) => { + this.get('folderService').setCurrentFolder(folder); + this.transitionTo('folders.folder', folder.get('id'), folder.get('slug')); }); }); }, onShare: function (invitation) { - let self = this; - this.get('folderService').share(this.folder.get('id'), invitation).then(function () { - self.showNotification("Shared"); + this.get('folderService').share(this.folder.get('id'), invitation).then(() => { + this.showNotification("Shared"); }); }, onPermission: function (folder, message, permissions) { - var self = this; var data = permissions.map(function (obj) { return obj.getProperties('orgId', 'folderId', 'userId', 'canEdit', 'canView'); }); var payload = { Message: message, Roles: data }; - this.get('folderService').savePermissions(folder.get('id'), payload).then(function () { - self.showNotification("Saved"); + this.get('folderService').savePermissions(folder.get('id'), payload).then(() => { + this.showNotification("Saved"); }); var hasEveryone = _.find(data, function (permission) { diff --git a/app/app/services/document.js b/app/app/services/document.js index 8c8fe45e0..237f343c9 100644 --- a/app/app/services/document.js +++ b/app/app/services/document.js @@ -39,6 +39,10 @@ export default Ember.Service.extend({ content: Ember.A([]) }); + if (isObject(response)) { + return documents; + } + documents = response.map((doc) => { let data = this.get('store').normalize('document', doc); return this.get('store').push({ data: data }); diff --git a/app/app/services/folder.js b/app/app/services/folder.js index 183a35792..b79631c6c 100644 --- a/app/app/services/folder.js +++ b/app/app/services/folder.js @@ -14,7 +14,7 @@ import BaseService from '../services/base'; const { get, - RSVP: { resolve }, + RSVP, inject: { service } } = Ember; @@ -41,7 +41,6 @@ export default BaseService.extend({ // Returns folder model for specified folder id. getFolder(id) { - return this.get('ajax').request(`folders/${id}`, { method: 'GET' }).then((folder) => { @@ -52,12 +51,14 @@ export default BaseService.extend({ // Returns all folders that user can see. getAll() { + let folders = this.get('folders'); - if (this.get('folders') != null) { - return new resolve(this.get('folders')); - } else { - return this.reload(); + if (folders != null) { + return new RSVP.resolve(folders); } + + return this.reload(); + }, // Updates an existing folder record. @@ -140,7 +141,6 @@ export default BaseService.extend({ // persist folder permissions savePermissions(folderId, payload) { - return this.get('ajax').request(`folders/${folderId}/permissions`, { method: 'PUT', contentType: 'json', diff --git a/app/app/services/organization.js b/app/app/services/organization.js index 5740d2859..5b804a18e 100644 --- a/app/app/services/organization.js +++ b/app/app/services/organization.js @@ -33,11 +33,11 @@ export default Ember.Service.extend({ // Updates an existing organization record. save(org) { - let id = org.get('id'); + let id = org.id; this.get('appMeta').setProperties({ - message: org.message, - title: org.title + message: org.get('message'), + title: org.get('title') }); return this.get('ajax').request(`organizations/${id}`, { From ee977c977a905c0a673f2e61601863882f5def46 Mon Sep 17 00:00:00 2001 From: zinyando Date: Tue, 23 Aug 2016 10:13:29 +0200 Subject: [PATCH 11/25] Fix setting folder permmision action --- app/app/pods/folders/route.js | 1 - app/app/pods/folders/settings/route.js | 76 ++++++++++++++---------- app/app/serializers/folder-permission.js | 2 +- 3 files changed, 47 insertions(+), 32 deletions(-) diff --git a/app/app/pods/folders/route.js b/app/app/pods/folders/route.js index 27b77e8f8..e2a284e83 100644 --- a/app/app/pods/folders/route.js +++ b/app/app/pods/folders/route.js @@ -27,7 +27,6 @@ export default Ember.Route.extend(AuthenticatedRouteMixin, { }, afterModel: function (model) { - debugger; let params = this.paramsFor('folders.folder'); if (is.empty(params)) { diff --git a/app/app/pods/folders/settings/route.js b/app/app/pods/folders/settings/route.js index 66b6c0205..abf7b7d87 100644 --- a/app/app/pods/folders/settings/route.js +++ b/app/app/pods/folders/settings/route.js @@ -23,6 +23,7 @@ export default Ember.Route.extend(NotifierMixin, { folder: {}, tab: "", localStorage: service(), + store: service(), beforeModel: function (transition) { this.tab = is.not.undefined(transition.queryParams.tab) ? transition.queryParams.tab : "tabGeneral"; @@ -43,54 +44,61 @@ export default Ember.Route.extend(NotifierMixin, { controller.set('tabDelete', false); controller.set(this.get('tab'), true); - this.get('folderService').getAll().then(function (folders) { + this.get('folderService').getAll().then((folders) => { controller.set('folders', folders.rejectBy('id', model.get('id'))); }); - this.get('userService').getAll().then(function (users) { + this.get('userService').getAll().then((users) => { controller.set('users', users); var folderPermissions = []; - var u = models.FolderPermissionModel.create({ + users.forEach((user) => { + let isActive = user.get('active'); + + let u = { + userId: user.get('id'), + fullname: user.get('fullname'), + orgId: model.get('orgId'), + folderId: model.get('id'), + canEdit: false, + canView: false, + canViewPrevious: false + }; + + if (isActive) { + folderPermissions.pushObject(u); + } + }); + + var u = { userId: "", fullname: " Everyone", orgId: model.get('orgId'), folderId: model.get('id'), canEdit: false, canView: false - }); + }; folderPermissions.pushObject(u); - users.forEach(function (user, index) /* jshint ignore:line */ { - if (user.get('active')) { - var u = models.FolderPermissionModel.create({ - userId: user.get('id'), - fullname: user.get('fullname'), - orgId: model.get('orgId'), - folderId: model.get('id'), - canEdit: false, - canView: false, - canViewPrevious: false - }); - - folderPermissions.pushObject(u); - } - }); - - self.get('folderService').getPermissions(model.id).then(function (permissions) { - permissions.forEach(function (permission, index) /* jshint ignore:line */ { - var folderPermission = folderPermissions.findBy('userId', permission.userId); + this.get('folderService').getPermissions(model.id).then((permissions) => { + permissions.forEach((permission, index) => { /* jshint ignore:line */ + var folderPermission = folderPermissions.findBy('userId', permission.get('userId')); if (is.not.undefined(folderPermission)) { - Ember.set(folderPermission, 'orgId', permission.orgId); - Ember.set(folderPermission, 'folderId', permission.folderId); - Ember.set(folderPermission, 'canEdit', permission.canEdit); - Ember.set(folderPermission, 'canView', permission.canView); - Ember.set(folderPermission, 'canViewPrevious', permission.canView); + Ember.set(folderPermission, 'orgId', permission.get('orgId')); + Ember.set(folderPermission, 'folderId', permission.get('folderId')); + Ember.set(folderPermission, 'canEdit', permission.get('canEdit')); + Ember.set(folderPermission, 'canView', permission.get('canView')); + Ember.set(folderPermission, 'canViewPrevious', permission.get('canView')); } }); + folderPermissions.map((permission) => { + let data = this.get('store').normalize('folder-permission', permission); + return this.get('store').push({ data: data }); + }); + controller.set('permissions', folderPermissions.sortBy('fullname')); }); }); @@ -125,8 +133,16 @@ export default Ember.Route.extend(NotifierMixin, { }, onPermission: function (folder, message, permissions) { - var data = permissions.map(function (obj) { - return obj.getProperties('orgId', 'folderId', 'userId', 'canEdit', 'canView'); + var data = permissions.map((obj) => { + let permission = { + 'orgId': obj.orgId, + 'folderId': obj.folderId, + 'userId': obj.userId, + 'canEdit': obj.canEdit, + 'canView': obj.canView + }; + + return permission; }); var payload = { Message: message, Roles: data }; diff --git a/app/app/serializers/folder-permission.js b/app/app/serializers/folder-permission.js index 34f7b4d7a..72751e4df 100644 --- a/app/app/serializers/folder-permission.js +++ b/app/app/serializers/folder-permission.js @@ -3,7 +3,7 @@ import ApplicationSerializer from './application'; export default ApplicationSerializer.extend({ normalize(modelClass, resourceHash) { return { - id: resourceHash.folderId, + id: resourceHash.userId ? resourceHash.userId : 'public', type: modelClass.modelName, attributes: resourceHash }; From abac9347e162b8eeb796ba2f2537da1883bcd11c Mon Sep 17 00:00:00 2001 From: zinyando Date: Wed, 24 Aug 2016 13:09:38 +0200 Subject: [PATCH 12/25] Fix change folder owner action --- app/app/pods/customize/folders/controller.js | 17 ++++++++--------- app/app/pods/customize/folders/route.js | 16 ++++++++-------- app/app/services/folder.js | 2 +- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/app/app/pods/customize/folders/controller.js b/app/app/pods/customize/folders/controller.js index 83be5a115..c250dff4c 100644 --- a/app/app/pods/customize/folders/controller.js +++ b/app/app/pods/customize/folders/controller.js @@ -1,11 +1,11 @@ // Copyright 2016 Documize Inc. . All rights reserved. // -// This software (Documize Community Edition) is licensed under +// This software (Documize Community Edition) is licensed under // GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html // // You can operate outside the AGPL restrictions by purchasing // Documize Enterprise Edition and obtaining a commercial license -// by contacting . +// by contacting . // // https://documize.com @@ -27,17 +27,16 @@ export default Ember.Controller.extend(NotifierMixin, { actions: { changeOwner: function (folderId, userId) { - let self = this; - this.get('folderService').getFolder(folderId).then(function (folder) { + this.get('folderService').getFolder(folderId).then((folder) => { folder.set('userId', userId); - self.get('folderService').save(folder).then(function () { - self.showNotification("Changed"); - self.audit.record('changed-folder-owner'); + this.get('folderService').save(folder).then(() => { + this.showNotification("Changed"); + this.audit.record('changed-folder-owner'); }); - self.send('onChangeOwner'); + this.send('onChangeOwner'); }); } } -}); \ No newline at end of file +}); diff --git a/app/app/pods/customize/folders/route.js b/app/app/pods/customize/folders/route.js index 9a2a5df2d..445d4b894 100644 --- a/app/app/pods/customize/folders/route.js +++ b/app/app/pods/customize/folders/route.js @@ -1,11 +1,11 @@ // Copyright 2016 Documize Inc. . All rights reserved. // -// This software (Documize Community Edition) is licensed under +// This software (Documize Community Edition) is licensed under // GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html // // You can operate outside the AGPL restrictions by purchasing // Documize Enterprise Edition and obtaining a commercial license -// by contacting . +// by contacting . // // https://documize.com @@ -29,17 +29,17 @@ export default Ember.Route.extend(AuthenticatedRouteMixin, { let nonPrivateFolders = model.rejectBy('folderType', 2); controller.set('folders', nonPrivateFolders); - this.get('folderService').getProtectedFolderInfo().then(function (people) { - people.forEach(function (person) { - person.isEveryone = person.userId === ''; - person.isOwner = false; + this.get('folderService').getProtectedFolderInfo().then((people) => { + people.forEach((person) => { + person.set('isEveryone', person.get('userId') === ''); + person.set('isOwner', false); }); nonPrivateFolders.forEach(function (folder) { let shared = people.filterBy('folderId', folder.get('id')); let person = shared.findBy('userId', folder.get('userId')); if (is.not.undefined(person)) { - person.isOwner = true; + person.set('isOwner', true); } folder.set('sharedWith', shared); @@ -56,4 +56,4 @@ export default Ember.Route.extend(AuthenticatedRouteMixin, { this.refresh(); } } -}); \ No newline at end of file +}); diff --git a/app/app/services/folder.js b/app/app/services/folder.js index b79631c6c..d55d598f7 100644 --- a/app/app/services/folder.js +++ b/app/app/services/folder.js @@ -98,7 +98,7 @@ export default BaseService.extend({ data = response.map((obj) => { let data = this.get('store').normalize('protected-folder-participant', obj); - return this.get('store').push({ data: data }); + return this.get('store').push(data); }); return data; From 052ffa309070bebc6a6b432f865bef7c56f03e2f Mon Sep 17 00:00:00 2001 From: zinyando Date: Wed, 24 Aug 2016 13:10:54 +0200 Subject: [PATCH 13/25] Fix user edit and adding document section --- app/app/components/settings/user-list.js | 15 ++-- app/app/models/page.js | 6 +- app/app/models/user.js | 19 +---- app/app/pods/document/wizard/controller.js | 85 ++++++++++--------- app/app/serializers/page-meta.js | 11 +++ app/app/serializers/page.js | 11 +++ .../protected-folder-participant.js | 13 +++ app/app/services/user.js | 2 +- 8 files changed, 95 insertions(+), 67 deletions(-) create mode 100644 app/app/serializers/page-meta.js create mode 100644 app/app/serializers/page.js create mode 100644 app/app/serializers/protected-folder-participant.js diff --git a/app/app/components/settings/user-list.js b/app/app/components/settings/user-list.js index c03ec12b3..32bc4a252 100644 --- a/app/app/components/settings/user-list.js +++ b/app/app/components/settings/user-list.js @@ -1,11 +1,11 @@ // Copyright 2016 Documize Inc. . All rights reserved. // -// This software (Documize Community Edition) is licensed under +// This software (Documize Community Edition) is licensed under // GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html // // You can operate outside the AGPL restrictions by purchasing // Documize Enterprise Edition and obtaining a commercial license -// by contacting . +// by contacting . // // https://documize.com @@ -54,7 +54,8 @@ export default Ember.Component.extend({ let self = this; let user = this.users.findBy("id", id); - this.set('editUser', user.copy()); + let userCopy = user.getProperties('id', 'created', 'revised', 'firstname', 'lastname', 'email', 'initials', 'active', 'editor', 'admin', 'accounts'); + this.set('editUser', userCopy); this.set('password', { password: "", confirmation: "" @@ -112,15 +113,15 @@ export default Ember.Component.extend({ let user = this.get('editUser'); let password = this.get('password'); - if (is.empty(user.get('firstname'))) { + if (is.empty(user.firstname)) { $("#edit-firstname").addClass("error").focus(); return; } - if (is.empty(user.get('lastname'))) { + if (is.empty(user.lastname)) { $("#edit-lastname").addClass("error").focus(); return; } - if (is.empty(user.get('email'))) { + if (is.empty(user.email)) { $("#edit-email").addClass("error").focus(); return; } @@ -144,4 +145,4 @@ export default Ember.Component.extend({ this.attrs.onDelete(user); } } -}); \ No newline at end of file +}); diff --git a/app/app/models/page.js b/app/app/models/page.js index f09557823..bf7a5b4b0 100644 --- a/app/app/models/page.js +++ b/app/app/models/page.js @@ -25,8 +25,6 @@ export default Model.extend({ body: attr('string'), rawBody: attr('string'), meta: attr(), - created: attr(), - revised: attr(), tagName: Ember.computed('level', function () { return "h" + this.get('level'); @@ -39,5 +37,7 @@ export default Model.extend({ tocIndentCss: Ember.computed('tocIndent', function () { let tocIndent = this.get('tocIndent'); return `margin-left-${tocIndent}`; - }) + }), + created: attr(), + revised: attr() }); diff --git a/app/app/models/user.js b/app/app/models/user.js index d2eaa8694..7c3fc94f8 100644 --- a/app/app/models/user.js +++ b/app/app/models/user.js @@ -34,22 +34,5 @@ export default Model.extend({ let first = this.get('firstname').trim(); let last = this.get('lastname').trim(); this.set('initials', first.substr(0, 1) + last.substr(0, 1)); - }, - // - // copy() { - // let copy = UserModel.create(); - // copy.id = this.id; - // copy.created = this.created; - // copy.revised = this.revised; - // copy.firstname = this.firstname; - // copy.lastname = this.lastname; - // copy.email = this.email; - // copy.initials = this.initials; - // copy.active = this.active; - // copy.editor = this.editor; - // copy.admin = this.admin; - // copy.accounts = this.accounts; - // - // return copy; - // } + } }); diff --git a/app/app/pods/document/wizard/controller.js b/app/app/pods/document/wizard/controller.js index a67d82ee8..d2421e3d8 100644 --- a/app/app/pods/document/wizard/controller.js +++ b/app/app/pods/document/wizard/controller.js @@ -3,47 +3,56 @@ import models from '../../../utils/model'; import NotifierMixin from '../../../mixins/notifier'; export default Ember.Controller.extend(NotifierMixin, { - documentService: Ember.inject.service('document'), + documentService: Ember.inject.service('document'), - actions: { - onCancel() { - this.transitionToRoute('document'); - }, + actions: { + onCancel() { + this.transitionToRoute('document'); + }, - onAddSection(section) { + onAddSection(section) { let self = this; + debugger; + + console.log(section.get('contentType')); this.audit.record("added-section"); - this.audit.record("added-section-" + section.contentType); - - let page = models.PageModel.create({ - documentId: this.get('model.document.id'), - title: `${section.title} Section`, - level: 1, - sequence: 2048, - body: "", - contentType: section.contentType - }); - - let meta = models.PageMetaModel.create({ - documentId: this.get('model.document.id'), - rawBody: "", - config: "" - }); - - let model = { - page: page, - meta: meta - }; - - this.get('documentService').addPage(this.get('model.document.id'), model).then(function(newPage) { - self.transitionToRoute('document.edit', - self.get('model.folder.id'), - self.get('model.folder.slug'), - self.get('model.document.id'), - self.get('model.document.slug'), - newPage.id); - }); - } - } + this.audit.record("added-section-" + section.get('contentType')); + + let page = { + documentId: this.get('model.document.id'), + title: `${section.get('contentType')} Section`, + level: 1, + sequence: 2048, + body: "", + contentType: section.get('contentType') + }; + + let data = this.get('store').normalize('page', page); + let pageData = this.get('store').push({ data: data }); + + let meta = { + documentId: this.get('model.document.id'), + rawBody: "", + config: "" + }; + + let metaData = this.get('store').normalize('page-meta', meta); + let pageMetaData = this.get('store').push({ data: metaData }); + + let model = { + page: pageData, + meta: pageMetaData + }; + + this.get('documentService').addPage(this.get('model.document.id'), model).then((newPage) => { + this.transitionToRoute('document.edit', + this.get('model.folder.id'), + this.get('model.folder.slug'), + this.get('model.document.id'), + this.get('model.document.slug'), + newPage.id); + }); + } + } }); diff --git a/app/app/serializers/page-meta.js b/app/app/serializers/page-meta.js new file mode 100644 index 000000000..6372f5241 --- /dev/null +++ b/app/app/serializers/page-meta.js @@ -0,0 +1,11 @@ +import ApplicationSerializer from './application'; + +export default ApplicationSerializer.extend({ + normalize(modelClass, resourceHash) { + return { + id: resourceHash.id ? resourceHash.id : resourceHash.documentId, + type: modelClass.modelName, + attributes: resourceHash + }; + } +}); diff --git a/app/app/serializers/page.js b/app/app/serializers/page.js new file mode 100644 index 000000000..6372f5241 --- /dev/null +++ b/app/app/serializers/page.js @@ -0,0 +1,11 @@ +import ApplicationSerializer from './application'; + +export default ApplicationSerializer.extend({ + normalize(modelClass, resourceHash) { + return { + id: resourceHash.id ? resourceHash.id : resourceHash.documentId, + type: modelClass.modelName, + attributes: resourceHash + }; + } +}); diff --git a/app/app/serializers/protected-folder-participant.js b/app/app/serializers/protected-folder-participant.js new file mode 100644 index 000000000..d38ff5dda --- /dev/null +++ b/app/app/serializers/protected-folder-participant.js @@ -0,0 +1,13 @@ +import ApplicationSerializer from './application'; + +export default ApplicationSerializer.extend({ + normalize(modelClass, resourceHash) { + return { + data: { + id: resourceHash.id ? resourceHash.id : resourceHash.folderId + resourceHash.userId, + type: modelClass.modelName, + attributes: resourceHash + } + }; + } +}); diff --git a/app/app/services/user.js b/app/app/services/user.js index e28bc3949..5cdea303b 100644 --- a/app/app/services/user.js +++ b/app/app/services/user.js @@ -76,7 +76,7 @@ export default Ember.Service.extend({ // Updates an existing user record. save(user) { - let userId = user.get('id'); + let userId = user.id; let url = `users/${userId}`; return this.get('ajax').request(url, { From 19f77855fd90c34620aa8a77517458fa940c0f70 Mon Sep 17 00:00:00 2001 From: zinyando Date: Fri, 26 Aug 2016 13:02:54 +0200 Subject: [PATCH 14/25] Tweak format of returned data --- app/app/serializers/application.js | 8 +++++--- app/app/serializers/folder-permission.js | 8 +++++--- app/app/serializers/page-meta.js | 8 +++++--- app/app/serializers/page.js | 8 +++++--- app/app/serializers/user.js | 13 +++++++++++++ 5 files changed, 33 insertions(+), 12 deletions(-) create mode 100644 app/app/serializers/user.js diff --git a/app/app/serializers/application.js b/app/app/serializers/application.js index 05b576e6c..beea6668e 100644 --- a/app/app/serializers/application.js +++ b/app/app/serializers/application.js @@ -3,9 +3,11 @@ import JSONAPISerializer from 'ember-data/serializers/json-api'; export default JSONAPISerializer.extend({ normalize(modelClass, resourceHash) { return { - id: resourceHash.id, - type: modelClass.modelName, - attributes: resourceHash + data: { + id: resourceHash.id, + type: modelClass.modelName, + attributes: resourceHash + } }; } }); diff --git a/app/app/serializers/folder-permission.js b/app/app/serializers/folder-permission.js index 72751e4df..2c2733a52 100644 --- a/app/app/serializers/folder-permission.js +++ b/app/app/serializers/folder-permission.js @@ -3,9 +3,11 @@ import ApplicationSerializer from './application'; export default ApplicationSerializer.extend({ normalize(modelClass, resourceHash) { return { - id: resourceHash.userId ? resourceHash.userId : 'public', - type: modelClass.modelName, - attributes: resourceHash + data: { + id: resourceHash.userId ? resourceHash.userId : 0, + type: modelClass.modelName, + attributes: resourceHash + } }; } }); diff --git a/app/app/serializers/page-meta.js b/app/app/serializers/page-meta.js index 6372f5241..811356f5b 100644 --- a/app/app/serializers/page-meta.js +++ b/app/app/serializers/page-meta.js @@ -3,9 +3,11 @@ import ApplicationSerializer from './application'; export default ApplicationSerializer.extend({ normalize(modelClass, resourceHash) { return { - id: resourceHash.id ? resourceHash.id : resourceHash.documentId, - type: modelClass.modelName, - attributes: resourceHash + data: { + id: resourceHash.id ? resourceHash.id : resourceHash.documentId, + type: modelClass.modelName, + attributes: resourceHash + } }; } }); diff --git a/app/app/serializers/page.js b/app/app/serializers/page.js index 6372f5241..811356f5b 100644 --- a/app/app/serializers/page.js +++ b/app/app/serializers/page.js @@ -3,9 +3,11 @@ import ApplicationSerializer from './application'; export default ApplicationSerializer.extend({ normalize(modelClass, resourceHash) { return { - id: resourceHash.id ? resourceHash.id : resourceHash.documentId, - type: modelClass.modelName, - attributes: resourceHash + data: { + id: resourceHash.id ? resourceHash.id : resourceHash.documentId, + type: modelClass.modelName, + attributes: resourceHash + } }; } }); diff --git a/app/app/serializers/user.js b/app/app/serializers/user.js new file mode 100644 index 000000000..bdc8cff86 --- /dev/null +++ b/app/app/serializers/user.js @@ -0,0 +1,13 @@ +import ApplicationSerializer from './application'; + +export default ApplicationSerializer.extend({ + normalize(modelClass, resourceHash) { + return { + data: { + id: resourceHash.id ? resourceHash.id : 0, + type: modelClass.modelName, + attributes: resourceHash + } + }; + } +}); From 9483c4456169e0efc5d2e3521a8efba912c7c6c8 Mon Sep 17 00:00:00 2001 From: zinyando Date: Fri, 26 Aug 2016 13:13:26 +0200 Subject: [PATCH 15/25] fix broken session after move to ember data objects --- app/app/components/layout/zone-navigation.js | 13 ++++++++---- app/app/models/document.js | 4 +++- app/app/pods/document/wizard/controller.js | 12 +++-------- app/app/pods/folders/settings/route.js | 4 +--- app/app/services/document.js | 16 +++++++-------- app/app/services/folder.js | 8 ++++---- app/app/services/organization.js | 2 +- app/app/services/section.js | 4 ++-- app/app/services/session.js | 21 ++++++++++++-------- app/app/services/template.js | 4 ++-- app/app/services/user.js | 8 ++++---- 11 files changed, 50 insertions(+), 46 deletions(-) diff --git a/app/app/components/layout/zone-navigation.js b/app/app/components/layout/zone-navigation.js index 6ec0c85b1..bb34826c2 100644 --- a/app/app/components/layout/zone-navigation.js +++ b/app/app/components/layout/zone-navigation.js @@ -12,17 +12,22 @@ import Ember from 'ember'; import netUtil from '../../utils/net'; +const { + inject: { service } +} = Ember; + export default Ember.Component.extend({ folderService: Ember.inject.service('folder'), folder: null, appMeta: Ember.inject.service(), + session: service(), didInitAttrs() { if (this.get("session.authenticated")) { - this.get("session.user.accounts").forEach((account) => { - // TODO: do not mutate account.active here - account.active = account.orgId === this.get("appMeta.orgId"); - }); + // this.get("session.session.content.authenticated.user.accounts").forEach((account) => { + // // TODO: do not mutate account.active here + // account.active = account.orgId === this.get("appMeta.orgId"); + // }); } }, diff --git a/app/app/models/document.js b/app/app/models/document.js index 2b9642288..ab787864d 100644 --- a/app/app/models/document.js +++ b/app/app/models/document.js @@ -30,5 +30,7 @@ export default Model.extend({ selected: attr('boolean', { defaultValue: false }), slug: Ember.computed('name', function () { return stringUtil.makeSlug(this.get('name')); - }) + }), + created: attr(), + revised: attr() }); diff --git a/app/app/pods/document/wizard/controller.js b/app/app/pods/document/wizard/controller.js index d2421e3d8..2087a398c 100644 --- a/app/app/pods/document/wizard/controller.js +++ b/app/app/pods/document/wizard/controller.js @@ -1,5 +1,4 @@ import Ember from 'ember'; -import models from '../../../utils/model'; import NotifierMixin from '../../../mixins/notifier'; export default Ember.Controller.extend(NotifierMixin, { @@ -11,11 +10,6 @@ export default Ember.Controller.extend(NotifierMixin, { }, onAddSection(section) { - let self = this; - debugger; - - console.log(section.get('contentType')); - this.audit.record("added-section"); this.audit.record("added-section-" + section.get('contentType')); @@ -29,7 +23,7 @@ export default Ember.Controller.extend(NotifierMixin, { }; let data = this.get('store').normalize('page', page); - let pageData = this.get('store').push({ data: data }); + let pageData = this.get('store').push(data); let meta = { documentId: this.get('model.document.id'), @@ -37,8 +31,8 @@ export default Ember.Controller.extend(NotifierMixin, { config: "" }; - let metaData = this.get('store').normalize('page-meta', meta); - let pageMetaData = this.get('store').push({ data: metaData }); + let pageMeta = this.get('store').normalize('page-meta', meta); + let pageMetaData = this.get('store').push(pageMeta); let model = { page: pageData, diff --git a/app/app/pods/folders/settings/route.js b/app/app/pods/folders/settings/route.js index abf7b7d87..94bd50cc5 100644 --- a/app/app/pods/folders/settings/route.js +++ b/app/app/pods/folders/settings/route.js @@ -10,7 +10,6 @@ // https://documize.com import Ember from 'ember'; -import models from '../../../utils/model'; import NotifierMixin from '../../../mixins/notifier'; const { @@ -34,7 +33,6 @@ export default Ember.Route.extend(NotifierMixin, { }, setupController(controller, model) { - var self = this; this.folder = model; controller.set('model', model); @@ -96,7 +94,7 @@ export default Ember.Route.extend(NotifierMixin, { folderPermissions.map((permission) => { let data = this.get('store').normalize('folder-permission', permission); - return this.get('store').push({ data: data }); + return this.get('store').push(data); }); controller.set('permissions', folderPermissions.sortBy('fullname')); diff --git a/app/app/services/document.js b/app/app/services/document.js index 237f343c9..b5b52c156 100644 --- a/app/app/services/document.js +++ b/app/app/services/document.js @@ -26,7 +26,7 @@ export default Ember.Service.extend({ method: "GET" }).then((response) => { let data = this.get('store').normalize('document', response); - return this.get('store').push({ data: data }); + return this.get('store').push(data); }); }, @@ -45,7 +45,7 @@ export default Ember.Service.extend({ documents = response.map((doc) => { let data = this.get('store').normalize('document', doc); - return this.get('store').push({ data: data }); + return this.get('store').push(data); }); return documents; @@ -63,7 +63,7 @@ export default Ember.Service.extend({ documents = response.map((doc) => { let data = this.get('store').normalize('document', doc); - return this.get('store').push({ data: data }); + return this.get('store').push(data); }); return documents; @@ -203,7 +203,7 @@ export default Ember.Service.extend({ let data = []; data = response.map((obj) => { let data = this.get('store').normalize('page', obj); - return this.get('store').push({ data: data }); + return this.get('store').push(data); }); return data; @@ -220,7 +220,7 @@ export default Ember.Service.extend({ pages = response.map((page) => { let data = this.get('store').normalize('page', page); - return this.get('store').push({ data: data }); + return this.get('store').push(data); }); return pages; @@ -234,7 +234,7 @@ export default Ember.Service.extend({ method: 'GET' }).then((response) => { let data = this.get('store').normalize('page', response); - return this.get('store').push({ data: data }); + return this.get('store').push(data); }); }, @@ -245,7 +245,7 @@ export default Ember.Service.extend({ method: 'GET' }).then((response) => { let data = this.get('store').normalize('page-meta', response); - return this.get('store').push({ data: data }); + return this.get('store').push(data); }); }, @@ -263,7 +263,7 @@ export default Ember.Service.extend({ data = response.map((obj) => { let data = this.get('store').normalize('attachment', obj); - return this.get('store').push({ data: data }); + return this.get('store').push(data); }); return data; diff --git a/app/app/services/folder.js b/app/app/services/folder.js index d55d598f7..630d3112a 100644 --- a/app/app/services/folder.js +++ b/app/app/services/folder.js @@ -35,7 +35,7 @@ export default BaseService.extend({ data: JSON.stringify(folder) }).then((folder) => { let data = this.get('store').normalize('folder', folder); - return this.get('store').push({ data: data }); + return this.get('store').push(data); }); }, @@ -45,7 +45,7 @@ export default BaseService.extend({ method: 'GET' }).then((folder) => { let data = this.get('store').normalize('folder', folder); - return this.get('store').push({ data: data }); + return this.get('store').push(data); }); }, @@ -115,7 +115,7 @@ export default BaseService.extend({ data = response.map((obj) => { let data = this.get('store').normalize('folder', obj); - return this.get('store').push({ data: data }); + return this.get('store').push(data); }); return data; @@ -132,7 +132,7 @@ export default BaseService.extend({ data = response.map((obj) => { let data = this.get('store').normalize('folder-permission', obj); - return this.get('store').push({ data: data }); + return this.get('store').push(data); }); return data; diff --git a/app/app/services/organization.js b/app/app/services/organization.js index 5b804a18e..3e9284cfc 100644 --- a/app/app/services/organization.js +++ b/app/app/services/organization.js @@ -27,7 +27,7 @@ export default Ember.Service.extend({ method: 'GET' }).then((response) => { let data = this.get('store').normalize('organization', response); - return this.get('store').push({ data: data }); + return this.get('store').push(data); }); }, diff --git a/app/app/services/section.js b/app/app/services/section.js index 000a8ef7f..fdac0d359 100644 --- a/app/app/services/section.js +++ b/app/app/services/section.js @@ -30,7 +30,7 @@ export default BaseService.extend({ data = response.map((obj) => { let data = this.get('store').normalize('section', obj); - return this.get('store').push({ data: data }); + return this.get('store').push(data); }); return data; @@ -62,7 +62,7 @@ export default BaseService.extend({ if (is.not.null(response) && is.array(response) && response.length > 0) { pages = response.map((page) => { let data = this.get('store').normalize('page', page); - return this.get('store').push({ data: data }); + return this.get('store').push(data); }); } diff --git a/app/app/services/session.js b/app/app/services/session.js index d95bdf5d4..9e486ef4b 100644 --- a/app/app/services/session.js +++ b/app/app/services/session.js @@ -10,12 +10,10 @@ // https://documize.com import Ember from 'ember'; -import models from '../utils/model'; import SimpleAuthSession from 'ember-simple-auth/services/session'; const { inject: { service }, - computed: { oneWay, or, notEmpty }, computed } = Ember; @@ -26,9 +24,17 @@ export default SimpleAuthSession.extend({ isMac: false, isMobile: false, - authenticated: notEmpty('user.id'), - isAdmin: oneWay('user.admin'), - isEditor: or('user.admin', 'user.editor'), + authenticated: computed('user.id', function () { + return this.get('user.id') !== '0'; + }), + isAdmin: computed('user', function () { + let data = this.get('user'); + return data.get('admin'); + }), + isEditor: computed('user', function () { + let data = this.get('user'); + return data.get('editor'); + }), init: function () { this.set('isMac', is.mac()); @@ -38,9 +44,8 @@ export default SimpleAuthSession.extend({ user: computed('isAuthenticated', 'session.content.authenticated.user', function () { if (this.get('isAuthenticated')) { let user = this.get('session.content.authenticated.user') || { id: '' }; - // let data = this.get('store').normalize('user', user); - // return this.get('store').push({ data: data }); - return models.UserModel.create(user); + let data = this.get('store').normalize('user', user); + return this.get('store').push(data); } }), diff --git a/app/app/services/template.js b/app/app/services/template.js index ad5c9d020..e3d2eb57f 100644 --- a/app/app/services/template.js +++ b/app/app/services/template.js @@ -33,7 +33,7 @@ export default Ember.Service.extend({ return this.get('ajax').post(url).then((doc) => { let data = this.get('store').normalize('document', doc); - return this.get('store').push({ data: data }); + return this.get('store').push(data); }); }, @@ -50,7 +50,7 @@ export default Ember.Service.extend({ templates = response.map((template) => { let data = this.get('store').normalize('template', template); - return this.get('store').push({ data: data }); + return this.get('store').push(data); }); return templates; diff --git a/app/app/services/user.js b/app/app/services/user.js index 5cdea303b..138d16d19 100644 --- a/app/app/services/user.js +++ b/app/app/services/user.js @@ -30,7 +30,7 @@ export default Ember.Service.extend({ contentType: 'json' }).then((response) => { let data = this.get('store').normalize('user', response); - return this.get('store').push({ data: data }); + return this.get('store').push(data); }); }, @@ -42,7 +42,7 @@ export default Ember.Service.extend({ type: 'GET' }).then((response) => { let data = this.get('store').normalize('user', response); - return this.get('store').push({ data: data }); + return this.get('store').push(data); }); }, @@ -51,7 +51,7 @@ export default Ember.Service.extend({ return this.get('ajax').request(`users`).then((response) => { return response.map((obj) => { let data = this.get('store').normalize('user', obj); - return this.get('store').push({ data: data }); + return this.get('store').push(data); }); }); }, @@ -67,7 +67,7 @@ export default Ember.Service.extend({ data = response.map((obj) => { let data = this.get('store').normalize('user', obj); - return this.get('store').push({ data: data }); + return this.get('store').push(data); }); return data; From 37049819649d50f1d089fa86f4469c2d54e91f90 Mon Sep 17 00:00:00 2001 From: zinyando Date: Fri, 26 Aug 2016 13:36:12 +0200 Subject: [PATCH 16/25] Fix user accounts issue in zone navigation --- app/app/components/layout/zone-navigation.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/app/components/layout/zone-navigation.js b/app/app/components/layout/zone-navigation.js index bb34826c2..4995c0522 100644 --- a/app/app/components/layout/zone-navigation.js +++ b/app/app/components/layout/zone-navigation.js @@ -24,10 +24,10 @@ export default Ember.Component.extend({ didInitAttrs() { if (this.get("session.authenticated")) { - // this.get("session.session.content.authenticated.user.accounts").forEach((account) => { - // // TODO: do not mutate account.active here - // account.active = account.orgId === this.get("appMeta.orgId"); - // }); + this.get("session.session.content.authenticated.user.accounts").forEach((account) => { + // TODO: do not mutate account.active here + account.active = account.orgId === this.get("appMeta.orgId"); + }); } }, From 98951bc5ef7fe1d0e9ed38a61e4585c134da9583 Mon Sep 17 00:00:00 2001 From: zinyando Date: Mon, 29 Aug 2016 12:23:07 +0200 Subject: [PATCH 17/25] Saving work on tag fix --- app/app/components/settings/user-list.js | 1 + app/app/pods/folders/settings/route.js | 12 +++++++----- app/app/services/document.js | 4 +++- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/app/app/components/settings/user-list.js b/app/app/components/settings/user-list.js index 32bc4a252..f87bc847d 100644 --- a/app/app/components/settings/user-list.js +++ b/app/app/components/settings/user-list.js @@ -112,6 +112,7 @@ export default Ember.Component.extend({ save() { let user = this.get('editUser'); let password = this.get('password'); + debugger; if (is.empty(user.firstname)) { $("#edit-firstname").addClass("error").focus(); diff --git a/app/app/pods/folders/settings/route.js b/app/app/pods/folders/settings/route.js index 94bd50cc5..008ccf081 100644 --- a/app/app/pods/folders/settings/route.js +++ b/app/app/pods/folders/settings/route.js @@ -84,11 +84,13 @@ export default Ember.Route.extend(NotifierMixin, { permissions.forEach((permission, index) => { /* jshint ignore:line */ var folderPermission = folderPermissions.findBy('userId', permission.get('userId')); if (is.not.undefined(folderPermission)) { - Ember.set(folderPermission, 'orgId', permission.get('orgId')); - Ember.set(folderPermission, 'folderId', permission.get('folderId')); - Ember.set(folderPermission, 'canEdit', permission.get('canEdit')); - Ember.set(folderPermission, 'canView', permission.get('canView')); - Ember.set(folderPermission, 'canViewPrevious', permission.get('canView')); + Ember.setProperties(folderPermission, { + orgId: permission.get('orgId'), + folderId: permission.get('folderId'), + canEdit: permission.get('canEdit'), + canView: permission.get('canView'), + canViewPrevious: permission.get('canView') + }); } }); diff --git a/app/app/services/document.js b/app/app/services/document.js index b5b52c156..176db9ff3 100644 --- a/app/app/services/document.js +++ b/app/app/services/document.js @@ -73,10 +73,12 @@ export default Ember.Service.extend({ // saveDocument updates an existing document record. save(doc) { let id = doc.get('id'); + let data = doc.toJSON(); + Ember.set(data, 'id', id) return this.get('ajax').request(`documents/${id}`, { method: 'PUT', - data: JSON.stringify(doc) + data: JSON.stringify(data) }); }, From a33232dea4e466e236bcf15ade049d5330cae090 Mon Sep 17 00:00:00 2001 From: zinyando Date: Mon, 29 Aug 2016 16:06:13 +0200 Subject: [PATCH 18/25] Fix model for adding a new tag to a document --- app/app/models/document.js | 2 +- app/app/services/document.js | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/app/app/models/document.js b/app/app/models/document.js index ab787864d..b32b25450 100644 --- a/app/app/models/document.js +++ b/app/app/models/document.js @@ -24,7 +24,7 @@ export default Model.extend({ folderId: attr('string'), userId: attr('string'), tags: attr('string'), - template: attr('string'), + template: attr('boolean'), // client-side property selected: attr('boolean', { defaultValue: false }), diff --git a/app/app/services/document.js b/app/app/services/document.js index 176db9ff3..b5b52c156 100644 --- a/app/app/services/document.js +++ b/app/app/services/document.js @@ -73,12 +73,10 @@ export default Ember.Service.extend({ // saveDocument updates an existing document record. save(doc) { let id = doc.get('id'); - let data = doc.toJSON(); - Ember.set(data, 'id', id) return this.get('ajax').request(`documents/${id}`, { method: 'PUT', - data: JSON.stringify(data) + data: JSON.stringify(doc) }); }, From 6817f5083e419292fa3ed327eebe14ef14a64761 Mon Sep 17 00:00:00 2001 From: zinyando Date: Mon, 29 Aug 2016 18:44:30 +0200 Subject: [PATCH 19/25] Fix broken mata id on updatePage action --- app/app/components/settings/user-list.js | 1 - app/app/models/page-meta.js | 4 ++-- app/app/models/page.js | 3 ++- app/app/pods/document/edit/controller.js | 10 +++++----- app/app/services/document.js | 1 + 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/app/app/components/settings/user-list.js b/app/app/components/settings/user-list.js index f87bc847d..32bc4a252 100644 --- a/app/app/components/settings/user-list.js +++ b/app/app/components/settings/user-list.js @@ -112,7 +112,6 @@ export default Ember.Component.extend({ save() { let user = this.get('editUser'); let password = this.get('password'); - debugger; if (is.empty(user.firstname)) { $("#edit-firstname").addClass("error").focus(); diff --git a/app/app/models/page-meta.js b/app/app/models/page-meta.js index 593b41a99..d584d70bc 100644 --- a/app/app/models/page-meta.js +++ b/app/app/models/page-meta.js @@ -11,13 +11,13 @@ import Model from 'ember-data/model'; import attr from 'ember-data/attr'; -// import { belongsTo, hasMany } from 'ember-data/relationships'; +// import { belongsTo } from 'ember-data/relationships'; export default Model.extend({ pageId: attr('string'), documentId: attr('string'), orgId: attr('string'), - rawBody: attr('string'), + rawBody: attr(), config: attr(), externalSource: attr('boolean', { defaultValue: false }), created: attr(), diff --git a/app/app/models/page.js b/app/app/models/page.js index bf7a5b4b0..586991b49 100644 --- a/app/app/models/page.js +++ b/app/app/models/page.js @@ -12,7 +12,7 @@ import Model from 'ember-data/model'; import attr from 'ember-data/attr'; import Ember from 'ember'; -// import { belongsTo, hasMany } from 'ember-data/relationships'; +// import { hasMany } from 'ember-data/relationships'; export default Model.extend({ documentId: attr('string'), @@ -25,6 +25,7 @@ export default Model.extend({ body: attr('string'), rawBody: attr('string'), meta: attr(), + // meta: hasMany('page-meta'), tagName: Ember.computed('level', function () { return "h" + this.get('level'); diff --git a/app/app/pods/document/edit/controller.js b/app/app/pods/document/edit/controller.js index 8d95b6f38..91a2f2b08 100644 --- a/app/app/pods/document/edit/controller.js +++ b/app/app/pods/document/edit/controller.js @@ -1,11 +1,11 @@ // Copyright 2016 Documize Inc. . All rights reserved. // -// This software (Documize Community Edition) is licensed under +// This software (Documize Community Edition) is licensed under // GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html // // You can operate outside the AGPL restrictions by purchasing // Documize Enterprise Edition and obtaining a commercial license -// by contacting . +// by contacting . // // https://documize.com @@ -29,8 +29,8 @@ export default Ember.Controller.extend(NotifierMixin, { this.showNotification("Saving"); let model = { - page: page, - meta: meta + page: page.toJSON({ includeId: true }), + meta: meta.toJSON({ includeId: true }) }; this.get('documentService').updatePage(page.get('documentId'), page.get('id'), model).then(function () { @@ -43,4 +43,4 @@ export default Ember.Controller.extend(NotifierMixin, { }); } } -}); \ No newline at end of file +}); diff --git a/app/app/services/document.js b/app/app/services/document.js index b5b52c156..de3f093af 100644 --- a/app/app/services/document.js +++ b/app/app/services/document.js @@ -124,6 +124,7 @@ export default Ember.Service.extend({ updatePage: function (documentId, pageId, payload, skipRevision) { var revision = skipRevision ? "?r=true" : "?r=false"; let url = `documents/${documentId}/pages/${pageId}${revision}`; + Ember.set(payload.meta, 'id', parseInt(payload.meta.id)); return this.get('ajax').request(url, { method: 'PUT', From f199366a5a166e9646f5e3f248c757eda5907886 Mon Sep 17 00:00:00 2001 From: zinyando Date: Mon, 29 Aug 2016 20:49:57 +0200 Subject: [PATCH 20/25] Section title fix --- app/app/pods/document/wizard/controller.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/app/pods/document/wizard/controller.js b/app/app/pods/document/wizard/controller.js index 2087a398c..b3e7a9739 100644 --- a/app/app/pods/document/wizard/controller.js +++ b/app/app/pods/document/wizard/controller.js @@ -15,7 +15,7 @@ export default Ember.Controller.extend(NotifierMixin, { let page = { documentId: this.get('model.document.id'), - title: `${section.get('contentType')} Section`, + title: `${section.get('title')} Section`, level: 1, sequence: 2048, body: "", From 833c4628723c4a1fb6c2d82fef05f1011741e620 Mon Sep 17 00:00:00 2001 From: zinyando Date: Mon, 29 Aug 2016 21:34:35 +0200 Subject: [PATCH 21/25] Set proper isAdmin in zone-navigation --- app/app/components/layout/zone-navigation.js | 4 ++-- app/app/templates/components/layout/zone-navigation.hbs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/app/components/layout/zone-navigation.js b/app/app/components/layout/zone-navigation.js index 4995c0522..b3eb42e85 100644 --- a/app/app/components/layout/zone-navigation.js +++ b/app/app/components/layout/zone-navigation.js @@ -17,9 +17,9 @@ const { } = Ember; export default Ember.Component.extend({ - folderService: Ember.inject.service('folder'), + folderService: service('folder'), folder: null, - appMeta: Ember.inject.service(), + appMeta: service(), session: service(), didInitAttrs() { diff --git a/app/app/templates/components/layout/zone-navigation.hbs b/app/app/templates/components/layout/zone-navigation.hbs index 90cb95f24..011d1e952 100644 --- a/app/app/templates/components/layout/zone-navigation.hbs +++ b/app/app/templates/components/layout/zone-navigation.hbs @@ -50,7 +50,7 @@
  • {{#link-to 'profile'}}Profile{{/link-to}}
  • - {{#if session.isAdmin}} + {{#if session.session.content.authenticated.user.admin}}
  • {{#link-to 'customize.general'}}Settings{{/link-to}}
  • From 899281044e2234b1b5a2f4b5529fa41b938f2edd Mon Sep 17 00:00:00 2001 From: zinyando Date: Tue, 30 Aug 2016 21:22:34 +0200 Subject: [PATCH 22/25] Saving wip on toc refactor --- .../document/document-sidebar-edits.js | 84 +++++++++---------- app/app/pods/document/index/controller.js | 10 +-- app/app/utils/toc.js | 70 ++++++++-------- 3 files changed, 82 insertions(+), 82 deletions(-) diff --git a/app/app/components/document/document-sidebar-edits.js b/app/app/components/document/document-sidebar-edits.js index da17e7514..957fea8ac 100644 --- a/app/app/components/document/document-sidebar-edits.js +++ b/app/app/components/document/document-sidebar-edits.js @@ -1,64 +1,64 @@ // Copyright 2016 Documize Inc. . All rights reserved. // -// This software (Documize Community Edition) is licensed under +// This software (Documize Community Edition) is licensed under // GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html // // You can operate outside the AGPL restrictions by purchasing // Documize Enterprise Edition and obtaining a commercial license -// by contacting . +// by contacting . // // https://documize.com import Ember from 'ember'; export default Ember.Component.extend({ - document: {}, - meta: [], - pages: [], + document: {}, + meta: [], + pages: [], - didReceiveAttrs() { - let editors = this.get('meta.editors'); - let toc = this.get('pages'); + didReceiveAttrs() { + let editors = this.get('meta.editors'); + let toc = this.get('pages'); - if (is.null(editors)) { - return; - } + if (is.null(editors)) { + return; + } - editors.forEach(function(item) { - Ember.set(item, "added", item.action === "add-page"); - Ember.set(item, "changed", item.action === "update-page"); - Ember.set(item, "deleted", item.action === "remove-page"); + editors.forEach(function (item) { + Ember.set(item, "added", item.action === "add-page"); + Ember.set(item, "changed", item.action === "update-page"); + Ember.set(item, "deleted", item.action === "remove-page"); - let page = _.findWhere(toc, { - id: item.pageId - }); - let title = ""; + let page = _.findWhere(toc, { + id: item.pageId + }); + let title = ""; - if (is.not.undefined(page)) { - title = page.title; + if (is.not.undefined(page)) { + title = page.get('title'); - if (item.added) { - Ember.set(item, 'changeLabel', "added " + title); - } + if (item.added) { + Ember.set(item, 'changeLabel', "added " + title); + } - if (item.changed) { - Ember.set(item, 'changeLabel', "changed " + title); - } - } else { - Ember.set(item, "deleted", true); + if (item.changed) { + Ember.set(item, 'changeLabel', "changed " + title); + } + } else { + Ember.set(item, "deleted", true); - if (item.added) { - Ember.set(item, 'changeLabel', "added section (since removed)"); - } + if (item.added) { + Ember.set(item, 'changeLabel', "added section (since removed)"); + } - if (item.changed) { - Ember.set(item, 'changeLabel', "changed section (since removed)"); - } + if (item.changed) { + Ember.set(item, 'changeLabel', "changed section (since removed)"); + } - if (item.deleted) { - Ember.set(item, 'changeLabel', "removed section"); - } - } - }); - } -}); \ No newline at end of file + if (item.deleted) { + Ember.set(item, 'changeLabel', "removed section"); + } + } + }); + } +}); diff --git a/app/app/pods/document/index/controller.js b/app/app/pods/document/index/controller.js index 7c190f994..6971d5507 100644 --- a/app/app/pods/document/index/controller.js +++ b/app/app/pods/document/index/controller.js @@ -1,11 +1,11 @@ // Copyright 2016 Documize Inc. . All rights reserved. // -// This software (Documize Community Edition) is licensed under +// This software (Documize Community Edition) is licensed under // GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html // // You can operate outside the AGPL restrictions by purchasing // Documize Enterprise Edition and obtaining a commercial license -// by contacting . +// by contacting . // // https://documize.com @@ -79,7 +79,7 @@ export default Ember.Controller.extend(NotifierMixin, { } }); - self.set('pages', _.sortBy(self.get('pages'), "sequence")); + self.set('pages', self.get('pages').sortBy('sequence')); }); }, @@ -98,7 +98,7 @@ export default Ember.Controller.extend(NotifierMixin, { }); let pages = self.get('pages'); - pages = _.sortBy(pages, "sequence"); + pages = pages.sortBy('sequence') self.set('pages', []); self.set('pages', pages); }); @@ -216,4 +216,4 @@ export default Ember.Controller.extend(NotifierMixin, { }); } } -}); \ No newline at end of file +}); diff --git a/app/app/utils/toc.js b/app/app/utils/toc.js index 4ed9b5722..183aef341 100644 --- a/app/app/utils/toc.js +++ b/app/app/utils/toc.js @@ -12,17 +12,17 @@ function getState(toc, page) { let state = { tocTools: { - upTarget: "", - downTarget: "", + upTarget: "", + downTarget: "", indentIncrement: 0, - allowIndent: false, - allowOutdent: false - }, - actionablePage: false, - upDisabled: true, - downDisabled: true, - indentDisabled: true, - outdentDisabled: true, + allowIndent: false, + allowOutdent: false + }, + actionablePage: false, + upDisabled: true, + downDisabled: true, + indentDisabled: true, + outdentDisabled: true, }; if (is.undefined(page)) { @@ -55,19 +55,19 @@ function getState(toc, page) { if (index2 !== -1) { // up for (var i = index2; i >= 0; i--) { - if (page.level > toc[i].level) { + if (page.get('level') > toc[i].get('level')) { break; } - if (page.level === toc[i].level) { + if (page.get('level') === toc[i].get('level')) { state.tocTools.upTarget = toc[i].id; break; } } // indent? - state.tocTools.allowIndent = upPage.level >= page.level; - state.tocTools.indentIncrement = upPage.level - page.level; + state.tocTools.allowIndent = upPage.get('level') >= page.get('level'); + state.tocTools.indentIncrement = upPage.get('level') - page.get('level'); if (state.tocTools.indentIncrement === 0) { state.tocTools.indentIncrement = 1; @@ -115,7 +115,7 @@ function getState(toc, page) { state.upDisabled = state.tocTools.upTarget === ''; state.downDisabled = state.tocTools.downTarget === ''; - state.indentDisabled = !state.tocTools.allowIndent; + state.indentDisabled = !state.tocTools.allowIndent; state.outdentDisabled = !state.tocTools.allowOutdent; state.actionablePage = is.not.empty(state.tocTools.upTarget) || @@ -141,8 +141,8 @@ function moveUp(state, pages, current) { page2 = pages[index1 - 1]; } - var sequence1 = page1.sequence; - var sequence2 = is.not.null(page2) && is.not.undefined(page2) ? page2.sequence : 0; + var sequence1 = page1.get('sequence'); + var sequence2 = is.not.null(page2) && is.not.undefined(page2) ? page2.get('sequence') : 0; var index = _.indexOf(pages, current, false); if (index !== -1) { @@ -154,11 +154,11 @@ function moveUp(state, pages, current) { }); for (var i = index + 1; i < pages.length; i++) { - if (pages[i].level <= current.level) { + if (pages[i].get('level') <= current.get('level')) { break; } - sequence = (sequence + page1.sequence) / 2; + sequence = (sequence + page1.get('sequence')) / 2; pendingChanges.push({ pageId: pages[i].id, @@ -184,28 +184,28 @@ function moveDown(state, pages, current) { var startingSequence = 0; var upperSequence = 0; var cutOff = _.rest(pages, downTargetIndex); - var siblings = _.reject(cutOff, function(p) { - return p.level !== current.level || p.id === current.id || p.id === downTarget.id; + var siblings = _.reject(cutOff, function (p) { + return p.get('level') !== current.get('level') || p.id === current.id || p.id === downTarget.id; }); if (siblings.length > 0) { var aboveThisGuy = siblings[0]; var belowThisGuy = pages[_.indexOf(pages, aboveThisGuy, false) - 1]; - if (is.not.null(belowThisGuy) && belowThisGuy.level > current.level) { - startingSequence = (aboveThisGuy.sequence + belowThisGuy.sequence) / 2; - upperSequence = aboveThisGuy.sequence; + if (is.not.null(belowThisGuy) && belowThisGuy.get('level') > current.get('level')) { + startingSequence = (aboveThisGuy.get('sequence') + belowThisGuy.get('sequence')) / 2; + upperSequence = aboveThisGuy.get('sequence'); } else { var otherGuy = pages[downTargetIndex + 1]; - startingSequence = (otherGuy.sequence + downTarget.sequence) / 2; - upperSequence = otherGuy.sequence; + startingSequence = (otherGuy.get('sequence') + downTarget.get('sequence')) / 2; + upperSequence = otherGuy.get('sequence'); } } else { // startingSequence = downTarget.sequence * 2; - startingSequence = cutOff[cutOff.length-1].sequence * 2; + startingSequence = cutOff[cutOff.length - 1].sequence * 2; upperSequence = startingSequence * 2; - } + } pendingChanges.push({ pageId: current.id, @@ -215,7 +215,7 @@ function moveDown(state, pages, current) { var sequence = (startingSequence + upperSequence) / 2; for (var i = pageIndex + 1; i < pages.length; i++) { - if (pages[i].level <= current.level) { + if (pages[i].get('level') <= current.get('level')) { break; } @@ -237,17 +237,17 @@ function indent(state, pages, current) { pendingChanges.push({ pageId: current.id, - level: current.level + state.tocTools.indentIncrement + level: current.get('level') + state.tocTools.indentIncrement }); for (var i = pageIndex + 1; i < pages.length; i++) { - if (pages[i].level <= current.level) { + if (pages[i].get('level') <= current.get('level')) { break; } pendingChanges.push({ pageId: pages[i].id, - level: pages[i].level + state.tocTools.indentIncrement + level: pages[i].get('level') + state.tocTools.indentIncrement }); } @@ -260,17 +260,17 @@ function outdent(state, pages, current) { pendingChanges.push({ pageId: current.id, - level: current.level - 1 + level: current.get('level') - 1 }); for (var i = pageIndex + 1; i < pages.length; i++) { - if (pages[i].level <= current.level) { + if (pages[i].get('level') <= current.get('level')) { break; } pendingChanges.push({ pageId: pages[i].id, - level: pages[i].level - 1 + level: pages[i].get('level') - 1 }); } From 2e9fafe9660e06cb84ab8b063ec67f3bd4f95d28 Mon Sep 17 00:00:00 2001 From: zinyando Date: Wed, 31 Aug 2016 11:43:06 +0200 Subject: [PATCH 23/25] Fix page outdent function in toc --- app/app/utils/toc.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/app/utils/toc.js b/app/app/utils/toc.js index 183aef341..27f139d66 100644 --- a/app/app/utils/toc.js +++ b/app/app/utils/toc.js @@ -94,24 +94,24 @@ function getState(toc, page) { if (index3 !== -1) { for (var i3 = index3; i3 < toc.length; i3++) { - if (toc[i3].level < page.level) { + if (toc[i3].get('level') < page.get('level')) { break; } - if (page.level === toc[i3].level) { + if (page.get('level') === toc[i3].get('level')) { state.tocTools.downTarget = toc[i3].id; break; } } } - if (page.level > downPage.level) { + if (page.get('level') > downPage.get('level')) { state.tocTools.downTarget = ''; } } // can we outdent? - state.tocTools.allowOutdent = page.level > 1; + state.tocTools.allowOutdent = page.get('level') > 1; state.upDisabled = state.tocTools.upTarget === ''; state.downDisabled = state.tocTools.downTarget === ''; From 11f30ddba67e50f6df3d97246dd1d063c0ae52e3 Mon Sep 17 00:00:00 2001 From: zinyando Date: Wed, 14 Sep 2016 11:42:50 +0200 Subject: [PATCH 24/25] Add Missing semicolon --- app/app/pods/document/index/controller.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/app/pods/document/index/controller.js b/app/app/pods/document/index/controller.js index 6971d5507..d73cbf8a6 100644 --- a/app/app/pods/document/index/controller.js +++ b/app/app/pods/document/index/controller.js @@ -98,7 +98,7 @@ export default Ember.Controller.extend(NotifierMixin, { }); let pages = self.get('pages'); - pages = pages.sortBy('sequence') + pages = pages.sortBy('sequence'); self.set('pages', []); self.set('pages', pages); }); From 69e1a199b8461e4b11f822b5ffe9f83b2f14d6fb Mon Sep 17 00:00:00 2001 From: Harvey Kandola Date: Fri, 16 Sep 2016 11:29:01 -0700 Subject: [PATCH 25/25] bump version --- core/product.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/product.go b/core/product.go index c7845bbbf..74b3b312b 100644 --- a/core/product.go +++ b/core/product.go @@ -26,7 +26,7 @@ type ProdInfo struct { // Product returns product edition details func Product() (p ProdInfo) { p.Major = "0" - p.Minor = "19" + p.Minor = "20" p.Patch = "0" p.Version = fmt.Sprintf("%s.%s.%s", p.Major, p.Minor, p.Patch) p.Edition = "Community"