1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-24 15:49:44 +02:00

refactored appMeta URL property

This commit is contained in:
Harvey Kandola 2016-07-08 16:08:23 -07:00
parent 1c92691bdb
commit 786ba6e8d6
6 changed files with 324 additions and 350 deletions

View file

@ -14,128 +14,129 @@ import NotifierMixin from '../../mixins/notifier';
import TooltipMixin from '../../mixins/tooltip';
export default Ember.Component.extend(NotifierMixin, TooltipMixin, {
userService: Ember.inject.service('user'),
localStorage: Ember.inject.service(),
drop: null,
users: [],
saveTemplate: {
name: "",
description: ""
},
appMeta: Ember.inject.service(),
userService: Ember.inject.service('user'),
localStorage: Ember.inject.service(),
drop: null,
users: [],
saveTemplate: {
name: "",
description: ""
},
didReceiveAttrs() {
this.set('saveTemplate.name', this.get('document.name'));
this.set('saveTemplate.description', this.get('document.excerpt'));
},
didRender() {
if (this.get('isEditor')) {
this.addTooltip(document.getElementById("attachment-button"));
this.addTooltip(document.getElementById("save-template-button"));
this.addTooltip(document.getElementById("set-meta-button"));
didRender() {
if (this.get('isEditor')) {
this.addTooltip(document.getElementById("attachment-button"));
this.addTooltip(document.getElementById("save-template-button"));
this.addTooltip(document.getElementById("set-meta-button"));
this.addTooltip(document.getElementById("delete-document-button"));
this.addTooltip(document.getElementById("add-section-button"));
}
}
this.addTooltip(document.getElementById("print-document-button"));
},
},
didInsertElement() {
if (this.get('isEditor')) {
let self = this;
let documentId = this.get('document.id');
let url = this.get('appMeta.url');
let uploadUrl = `${url}/documents/${documentId}/attachments`;
didInsertElement() {
if (this.get('isEditor')) {
let self = this;
let documentId = this.get('document.id');
let url = this.get('appMeta.endpoint');
let uploadUrl = `${url}/documents/${documentId}/attachments`;
let dzone = new Dropzone("#attachment-button > i", {
headers: {
'Authorization': 'Bearer ' + self.get('localStorage').getSessionItem('session.session.authenticated.token')
},
url: uploadUrl,
method: "post",
paramName: 'attachment',
clickable: true,
maxFilesize: 10,
parallelUploads: 3,
uploadMultiple: false,
addRemoveLinks: false,
autoProcessQueue: true,
let dzone = new Dropzone("#attachment-button > i", {
headers: {
'Authorization': 'Bearer ' + self.get('localStorage').getSessionItem('token')
},
url: uploadUrl,
method: "post",
paramName: 'attachment',
clickable: true,
maxFilesize: 10,
parallelUploads: 3,
uploadMultiple: false,
addRemoveLinks: false,
autoProcessQueue: true,
init: function() {
this.on("success", function(file /*, response*/ ) {
self.showNotification(`Attached ${file.name}`);
});
init: function () {
this.on("success", function (file /*, response*/ ) {
self.showNotification(`Attached ${file.name}`);
});
this.on("queuecomplete", function() {
self.attrs.onAttachmentUpload();
});
this.on("queuecomplete", function () {
self.attrs.onAttachmentUpload();
});
this.on("addedfile", function( /*file*/ ) {
self.audit.record('attached-file');
});
}
});
this.on("addedfile", function ( /*file*/ ) {
self.audit.record('attached-file');
});
}
});
dzone.on("complete", function(file) {
dzone.removeFile(file);
});
dzone.on("complete", function (file) {
dzone.removeFile(file);
});
this.set('drop', dzone);
}
},
this.set('drop', dzone);
}
},
willDestroyElement() {
if (is.not.null(this.get('drop'))) {
this.get('drop').destroy();
this.set('drop', null);
}
willDestroyElement() {
if (is.not.null(this.get('drop'))) {
this.get('drop').destroy();
this.set('drop', null);
}
this.destroyTooltips();
},
this.destroyTooltips();
},
actions: {
actions: {
deleteDocument() {
this.attrs.onDocumentDelete();
},
},
printDocument() {
window.print();
},
},
saveTemplate() {
var name = this.get('saveTemplate.name');
var excerpt = this.get('saveTemplate.description');
saveTemplate() {
var name = this.get('saveTemplate.name');
var excerpt = this.get('saveTemplate.description');
if (is.empty(name)) {
$("#new-template-name").addClass("error").focus();
return false;
}
if (is.empty(name)) {
$("#new-template-name").addClass("error").focus();
return false;
}
if (is.empty(excerpt)) {
$("#new-template-desc").addClass("error").focus();
return false;
}
if (is.empty(excerpt)) {
$("#new-template-desc").addClass("error").focus();
return false;
}
this.showNotification('Template saved');
this.attrs.onSaveTemplate(name, excerpt);
this.showNotification('Template saved');
this.attrs.onSaveTemplate(name, excerpt);
return true;
},
return true;
},
saveMeta() {
let doc = this.get('document');
saveMeta() {
let doc = this.get('document');
if (is.empty(doc.get('excerpt'))) {
$("meta-excerpt").addClass("error").focus();
return false;
}
if (is.empty(doc.get('excerpt'))) {
$("meta-excerpt").addClass("error").focus();
return false;
}
doc.set('excerpt', doc.get('excerpt').substring(0, 250));
doc.set('userId', this.get('owner.id'));
this.showNotification("Saved");
doc.set('excerpt', doc.get('excerpt').substring(0, 250));
doc.set('userId', this.get('owner.id'));
this.showNotification("Saved");
this.attrs.onDocumentChange(doc);
return true;
},
}
});
this.attrs.onDocumentChange(doc);
return true;
},
}
});

View file

@ -13,110 +13,109 @@ import Ember from 'ember';
import NotifierMixin from '../../mixins/notifier';
export default Ember.Component.extend(NotifierMixin, {
localStorage: Ember.inject.service(),
tagName: 'span',
selectedTemplate: {
id: "0"
},
canEditTemplate: "",
localStorage: Ember.inject.service(),
tagName: 'span',
selectedTemplate: {
id: "0"
},
canEditTemplate: "",
drop: null,
appMeta: Ember.inject.service(),
appMeta: Ember.inject.service(),
didReceiveAttrs() {
this.send('setTemplate', this.get('savedTemplates')[0]);
},
didReceiveAttrs() {
this.send('setTemplate', this.get('savedTemplates')[0]);
},
willDestroyElement() {
if (is.not.null(this.get('drop'))) {
this.get('drop').destroy();
this.set('drop', null);
}
this.get('drop').destroy();
this.set('drop', null);
}
},
actions: {
setTemplate(chosen) {
if (is.undefined(chosen)) {
return;
}
actions: {
setTemplate(chosen) {
if (is.undefined(chosen)) {
return;
}
this.set('selectedTemplate', chosen);
this.set('canEditTemplate', chosen.id !== "0" ? "Edit" : "");
this.set('selectedTemplate', chosen);
this.set('canEditTemplate', chosen.id !== "0" ? "Edit" : "");
let templates = this.get('savedTemplates');
let templates = this.get('savedTemplates');
templates.forEach(template => {
Ember.set(template, 'selected', template.id === chosen.id);
});
},
templates.forEach(template => {
Ember.set(template, 'selected', template.id === chosen.id);
});
},
editTemplate() {
let template = this.get('selectedTemplate');
editTemplate() {
let template = this.get('selectedTemplate');
this.audit.record('edited-saved-template');
this.attrs.onEditTemplate(template);
this.audit.record('edited-saved-template');
this.attrs.onEditTemplate(template);
return true;
},
return true;
},
startDocument() {
let template = this.get('selectedTemplate');
startDocument() {
let template = this.get('selectedTemplate');
this.audit.record('used-saved-template');
this.attrs.onDocumentTemplate(template.id, template.title, "private");
return true;
},
this.audit.record('used-saved-template');
this.attrs.onDocumentTemplate(template.id, template.title, "private");
return true;
},
onOpenCallback() {
onOpenCallback() {
if (is.not.null(this.get('drop'))) {
return;
}
let self = this;
let folderId = this.get('folder.id');
let url = this.get('appMeta.url');
let importUrl = `${url}/import/folder/${folderId}`;
let folderId = this.get('folder.id');
let url = this.get('appMeta.endpoint');
let importUrl = `${url}/import/folder/${folderId}`;
Dropzone.options.uploadDocuments = false;
let dzone = new Dropzone("#upload-documents", {
headers: {
'Authorization': 'Bearer ' + self.get('localStorage').getSessionItem('session.session.authenticated.token')
},
url: importUrl,
method: "post",
paramName: 'attachment',
acceptedFiles: ".doc,.docx,.txt,.md,.markdown",
clickable: true,
maxFilesize: 10,
parallelUploads: 3,
uploadMultiple: false,
addRemoveLinks: false,
autoProcessQueue: true,
let dzone = new Dropzone("#upload-documents", {
headers: {
'Authorization': 'Bearer ' + self.get('localStorage').getSessionItem('token')
},
url: importUrl,
method: "post",
paramName: 'attachment',
acceptedFiles: ".doc,.docx,.txt,.md,.markdown",
clickable: true,
maxFilesize: 10,
parallelUploads: 3,
uploadMultiple: false,
addRemoveLinks: false,
autoProcessQueue: true,
init: function() {
this.on("success", function(document) {
self.attrs.onDocumentImported(document.name, document);
});
this.on("error", function(x) {
console.log("Conversion failed for ", x.name, " obj ", x); // TODO proper error handling
});
this.on("queuecomplete", function() {
init: function () {
this.on("success", function (document) {
self.attrs.onDocumentImported(document.name, document);
});
this.on("addedfile", function(file) {
self.attrs.onDocumentImporting(file.name);
self.audit.record('converted-document');
});
}
});
this.on("error", function (x) {
console.log("Conversion failed for ", x.name, " obj ", x); // TODO proper error handling
});
dzone.on("complete", function(file) {
dzone.removeFile(file);
});
this.on("queuecomplete", function () {});
this.on("addedfile", function (file) {
self.attrs.onDocumentImporting(file.name);
self.audit.record('converted-document');
});
}
});
dzone.on("complete", function (file) {
dzone.removeFile(file);
});
this.set('drop', dzone);
}
}
});
}
}
});

View file

@ -21,7 +21,7 @@ const {
export default Ember.Service.extend({
ajax: service(),
url: `${config.apiHost}/${config.apiNamespace}`,
endpoint: `${config.apiHost}/${config.apiNamespace}`,
orgId: '',
title: '',
version: '',
@ -44,13 +44,13 @@ export default Ember.Service.extend({
title: htmlSafe("Documize Setup"),
allowAnonymousAccess: false
});
return resolve();
}
return this.get('ajax').request('public/meta')
.then((response) => {
this.setProperties(response);
return response;
});
return this.get('ajax').request('public/meta').then((response) => {
this.setProperties(response);
return response;
});
}
});

View file

@ -15,7 +15,7 @@
{{#each attachments key="id" as |a index|}}
<li class="item">
<img class="icon" src="assets/img/attachments/{{document/file-icon a.extension}}" />
<a href="{{ appMeta.apiUrl }}api/public/attachments/{{ appMeta.orgId }}/{{ a.job }}/{{ a.fileId }}">
<a href="{{ appMeta.endpoint }}/public/attachments/{{ appMeta.orgId }}/{{ a.job }}/{{ a.fileId }}">
<span class="file">{{ a.filename }}</span>
</a>
{{#if isEditor}}

View file

@ -11,237 +11,211 @@
import Ember from 'ember';
import stringUtil from '../utils/string';
import config from '../config/environment';
import constants from '../utils/constants';
let BaseModel = Ember.Object.extend({
id: "",
created: null,
revised: null,
id: "",
created: null,
revised: null,
setSafe(attr, value) {
this.set(attr, Ember.String.htmlSafe(Ember.Handlebars.Utils.escapeExpression(value)));
}
});
let AppMeta = BaseModel.extend({
host: "",
namespace: "",
url: "",
orgId: "",
title: "",
message: "",
allowAnonymousAccess: false,
init() {
this.set('host', config.apiHost);
this.set('namespace', config.apiNamespace);
this.set('url', [config.apiHost, config.apiNamespace, ""].join('/'));
},
getBaseUrl(endpoint) {
return [this.get('host'), endpoint].join('/');
},
getUrl(endpoint) {
return [this.get('host'), this.get('namespace'), endpoint].join('/');
}
setSafe(attr, value) {
this.set(attr, Ember.String.htmlSafe(Ember.Handlebars.Utils.escapeExpression(value)));
}
});
let FolderPermissionModel = Ember.Object.extend({
orgId: "",
folderId: "",
userId: "",
fullname: "",
canView: false,
canEdit: false
orgId: "",
folderId: "",
userId: "",
fullname: "",
canView: false,
canEdit: false
});
// ProtectedFolderParticipant used to display folder participants that can
// then be marked as folder owner.
let ProtectedFolderParticipant = Ember.Object.extend({
userId: "",
email: "",
firstname: "",
lastname: "",
name: "",
folderId: "",
folderType: 0,
userId: "",
email: "",
firstname: "",
lastname: "",
name: "",
folderId: "",
folderType: 0,
fullname: Ember.computed('firstname', 'lastname', function() {
return `${this.get('firstname')} ${this.get('lastname')}`;
})
fullname: Ember.computed('firstname', 'lastname', function () {
return `${this.get('firstname')} ${this.get('lastname')}`;
})
});
let UserModel = BaseModel.extend({
firstname: "",
lastname: "",
email: "",
initials: "",
active: false,
editor: false,
admin: false,
accounts: [],
firstname: "",
lastname: "",
email: "",
initials: "",
active: false,
editor: false,
admin: false,
accounts: [],
fullname: Ember.computed('firstname', 'lastname', function() {
return `${this.get('firstname')} ${this.get('lastname')}`;
}),
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));
},
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;
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;
}
return copy;
}
});
let OrganizationModel = BaseModel.extend({
title: "",
message: "",
email: "",
allowAnonymousAccess: false,
title: "",
message: "",
email: "",
allowAnonymousAccess: false,
});
let DocumentModel = BaseModel.extend({
name: "",
excerpt: "",
job: "",
location: "",
orgId: "",
folderId: "",
userId: "",
tags: "",
template: "",
name: "",
excerpt: "",
job: "",
location: "",
orgId: "",
folderId: "",
userId: "",
tags: "",
template: "",
slug: Ember.computed('name', function() {
return stringUtil.makeSlug(this.get('name'));
}),
slug: Ember.computed('name', function () {
return stringUtil.makeSlug(this.get('name'));
}),
// client-side property
selected: false
// client-side property
selected: false
});
let TemplateModel = BaseModel.extend({
author: "",
dated: null,
description: "",
title: "",
type: 0,
author: "",
dated: null,
description: "",
title: "",
type: 0,
slug: Ember.computed('title', function() {
return stringUtil.makeSlug(this.get('title'));
}),
slug: Ember.computed('title', function () {
return stringUtil.makeSlug(this.get('title'));
}),
});
let FolderModel = BaseModel.extend({
name: "",
orgId: "",
userId: "",
folderType: constants.FolderType.Private,
name: "",
orgId: "",
userId: "",
folderType: constants.FolderType.Private,
slug: Ember.computed('name', function() {
return stringUtil.makeSlug(this.get('name'));
}),
slug: Ember.computed('name', function () {
return stringUtil.makeSlug(this.get('name'));
}),
markAsRestricted: function() {
this.set('folderType', constants.FolderType.Protected);
},
markAsRestricted: function () {
this.set('folderType', constants.FolderType.Protected);
},
markAsPrivate: function() {
this.set('folderType', constants.FolderType.Private);
},
markAsPrivate: function () {
this.set('folderType', constants.FolderType.Private);
},
markAsPublic: function() {
this.set('folderType', constants.FolderType.Public);
},
markAsPublic: function () {
this.set('folderType', constants.FolderType.Public);
},
// client-side prop that holds who can see this folder
sharedWith: [],
// client-side prop that holds who can see this folder
sharedWith: [],
});
let AttachmentModel = BaseModel.extend({
documentId: "",
extension: "",
fileId: "",
filename: "",
job: "",
orgId: ""
documentId: "",
extension: "",
fileId: "",
filename: "",
job: "",
orgId: ""
});
let PageModel = BaseModel.extend({
documentId: "",
orgId: "",
contentType: "",
level: 1,
sequence: 0,
revisions: 0,
title: "",
body: "",
rawBody: "",
meta: {},
documentId: "",
orgId: "",
contentType: "",
level: 1,
sequence: 0,
revisions: 0,
title: "",
body: "",
rawBody: "",
meta: {},
tagName: Ember.computed('level', function() {
return "h" + this.get('level');
}),
tagName: Ember.computed('level', function () {
return "h" + this.get('level');
}),
tocIndent: Ember.computed('level', function() {
return (this.get('level') - 1) * 20;
}),
tocIndent: Ember.computed('level', function () {
return (this.get('level') - 1) * 20;
}),
tocIndentCss: Ember.computed('tocIndent', function() {
tocIndentCss: Ember.computed('tocIndent', function () {
let tocIndent = this.get('tocIndent');
return `margin-left-${tocIndent}`;
}),
return `margin-left-${tocIndent}`;
}),
});
let PageMetaModel = BaseModel.extend({
pageId: "",
documentId: "",
orgId: "",
rawBody: "",
config: {},
externalSource: false,
pageId: "",
documentId: "",
orgId: "",
rawBody: "",
config: {},
externalSource: false,
});
let SectionModel = BaseModel.extend({
contentType: "",
title: "",
description: "",
iconFont: "",
iconFile: "",
contentType: "",
title: "",
description: "",
iconFont: "",
iconFile: "",
hasImage: Ember.computed('iconFont', 'iconFile', function() {
return this.get('iconFile').length > 0;
}),
hasImage: Ember.computed('iconFont', 'iconFile', function () {
return this.get('iconFile').length > 0;
}),
});
export default {
AppMeta,
TemplateModel,
AttachmentModel,
DocumentModel,
FolderModel,
FolderPermissionModel,
OrganizationModel,
PageModel,
PageMetaModel,
ProtectedFolderParticipant,
UserModel,
SectionModel
};
TemplateModel,
AttachmentModel,
DocumentModel,
FolderModel,
FolderPermissionModel,
OrganizationModel,
PageModel,
PageMetaModel,
ProtectedFolderParticipant,
UserModel,
SectionModel
};

View file

@ -97,4 +97,4 @@ module.exports = function (environment) {
ENV.contentSecurityPolicy = null;
return ENV;
};
};