1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-08-05 05:25:27 +02:00

moved emberjs to gui folder

This commit is contained in:
Harvey Kandola 2017-07-19 14:48:33 +01:00
parent 6a18d18f91
commit dc49dbbeff
999 changed files with 677 additions and 651 deletions

View file

@ -0,0 +1,43 @@
// Copyright 2016 Documize Inc. <legal@documize.com>. 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 <sales@documize.com>.
//
// https://documize.com
export default {
FolderType: {
Public: 1,
Private: 2,
Protected: 3
},
AuthProvider: {
Documize: 'documize',
Keycloak: 'keycloak'
},
DocumentActionType: {
Read: 1,
Feedback: 2,
Contribute: 3,
Approve: 4
},
UserActivityType: {
Created: 1,
Read: 2,
Edited: 3,
Deleted: 4,
Archived: 5,
Approved: 6,
Reverted: 7,
PublishedTemplate: 8,
PublishedBlock: 9,
Feedback: 10
}
};

40
gui/app/utils/date.js Normal file
View file

@ -0,0 +1,40 @@
// Copyright 2016 Documize Inc. <legal@documize.com>. 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 <sales@documize.com>.
//
// https://documize.com
// "2014/02/05"
function toShortDate(date) {
return moment(new Date(date)).format('YYYY/MM/DD');
}
// ISO date format
function toIsoDate(date, format) {
return moment(date).format(format);
}
function formatDate(date, format) {
return moment(toIsoDate(date, format));
}
function timeAgo(date) {
return moment(new Date(date)).fromNow();
}
function timeAgoUTC(date) {
return moment.utc((new Date(date))).local().fromNow();
}
export default {
toShortDate,
toIsoDate,
formatDate,
timeAgo,
timeAgoUTC
};

110
gui/app/utils/encoding.js Normal file
View file

@ -0,0 +1,110 @@
// Copyright 2016 Documize Inc. <legal@documize.com>. 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 <sales@documize.com>.
//
// https://documize.com
//*************************************
// Base64 Object
//*************************************
var Base64 = {
_keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
encode: function (e) {
var t = "";
var n, r, i, s, o, u, a;
var f = 0;
e = Base64._utf8_encode(e);
while (f < e.length) {
n = e.charCodeAt(f++);
r = e.charCodeAt(f++);
i = e.charCodeAt(f++);
s = n >> 2;
o = (n & 3) << 4 | r >> 4;
u = (r & 15) << 2 | i >> 6;
a = i & 63;
if (isNaN(r)) {
u = a = 64;
} else if (isNaN(i)) {
a = 64;
}
t = t + this._keyStr.charAt(s) + this._keyStr.charAt(o) + this._keyStr.charAt(u) + this._keyStr.charAt(a);
}
return t;
},
decode: function (e) {
var t = "";
var n, r, i;
var s, o, u, a;
var f = 0;
e = e.replace(/[^A-Za-z0-9\+\/\=]/g, "");
while (f < e.length) {
s = this._keyStr.indexOf(e.charAt(f++));
o = this._keyStr.indexOf(e.charAt(f++));
u = this._keyStr.indexOf(e.charAt(f++));
a = this._keyStr.indexOf(e.charAt(f++));
n = s << 2 | o >> 4;
r = (o & 15) << 4 | u >> 2;
i = (u & 3) << 6 | a;
t = t + String.fromCharCode(n);
if (u !== 64) {
t = t + String.fromCharCode(r);
}
if (a !== 64) {
t = t + String.fromCharCode(i);
}
}
t = Base64._utf8_decode(t);
return t;
},
_utf8_encode: function (e) {
e = e.replace(/\r\n/g, "\n");
var t = "";
for (var n = 0; n < e.length; n++) {
var r = e.charCodeAt(n);
if (r < 128) {
t += String.fromCharCode(r);
} else if (r > 127 && r < 2048) {
t += String.fromCharCode(r >> 6 | 192);
t += String.fromCharCode(r & 63 | 128);
} else {
t += String.fromCharCode(r >> 12 | 224);
t += String.fromCharCode(r >> 6 & 63 | 128);
t += String.fromCharCode(r & 63 | 128);
}
}
return t;
},
_utf8_decode: function (e) {
var t = "";
var n = 0;
let r = 0;
// let c1 = 0;
let c2 = 0;
while (n < e.length) {
r = e.charCodeAt(n);
if (r < 128) {
t += String.fromCharCode(r);
n++;
} else if (r > 191 && r < 224) {
c2 = e.charCodeAt(n + 1);
t += String.fromCharCode((r & 31) << 6 | c2 & 63);
n += 2;
} else {
c2 = e.charCodeAt(n + 1);
let c3 = e.charCodeAt(n + 2);
t += String.fromCharCode((r & 15) << 12 | (c2 & 63) << 6 | c3 & 63);
n += 3;
}
}
return t;
}
}; //jshint ignore:line
export default {
Base64
};

68
gui/app/utils/misc.js Normal file
View file

@ -0,0 +1,68 @@
// Copyright 2016 Documize Inc. <legal@documize.com>. 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 <sales@documize.com>.
//
// https://documize.com
// from http://thecodeship.com/web-development/alternative-to-javascript-evil-setinterval/
function interval(func, wait, times) {
var interv = function (w, t) {
return function () {
if (typeof t === "undefined" || t-- > 0) {
setTimeout(interv, w);
try {
func.call(null);
} catch (e) {
t = 0;
throw e.toString();
}
}
};
}(wait, times);
setTimeout(interv, wait);
}
// Function wrapping code.
// fn - reference to function.
// context - what you want "this" to be.
// params - array of parameters to pass to function.
// e.g. var fun1 = wrapFunction(sayStuff, this, ["Hello, world!"]);
// http://stackoverflow.com/questions/899102/how-do-i-store-javascript-functions-in-a-queue-for-them-to-be-executed-eventuall
function wrapFunction(fn, context, params) {
return function () {
fn.apply(context, params);
};
}
function insertAtCursor(myField, myValue) {
//IE support
if (document.selection) {
myField.focus();
let sel = document.selection.createRange();
sel.text = myValue;
}
//MOZILLA and others
else if (myField.selectionStart || myField.selectionStart === '0') {
var startPos = myField.selectionStart;
var endPos = myField.selectionEnd;
myField.value = myField.value.substring(0, startPos) +
myValue +
myField.value.substring(endPos, myField.value.length);
myField.selectionStart = startPos + myValue.length;
myField.selectionEnd = startPos + myValue.length;
} else {
myField.value += myValue;
}
}
export default {
interval,
wrapFunction,
insertAtCursor
};

221
gui/app/utils/model.js Normal file
View file

@ -0,0 +1,221 @@
// Copyright 2016 Documize Inc. <legal@documize.com>. 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 <sales@documize.com>.
//
// https://documize.com
import Ember from 'ember';
import stringUtil from '../utils/string';
import constants from '../utils/constants';
let BaseModel = Ember.Object.extend({
id: "",
created: null,
revised: null,
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
});
// 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,
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: [],
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;
}
});
let OrganizationModel = BaseModel.extend({
title: "",
message: "",
email: "",
allowAnonymousAccess: false,
});
let DocumentModel = BaseModel.extend({
name: "",
excerpt: "",
job: "",
location: "",
orgId: "",
folderId: "",
userId: "",
tags: "",
template: "",
slug: Ember.computed('name', function () {
return stringUtil.makeSlug(this.get('name'));
}),
// client-side property
selected: false
});
let TemplateModel = BaseModel.extend({
author: "",
dated: null,
description: "",
title: "",
type: 0,
slug: Ember.computed('title', function () {
return stringUtil.makeSlug(this.get('title'));
}),
});
let FolderModel = BaseModel.extend({
name: "",
orgId: "",
userId: "",
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: [],
});
let AttachmentModel = BaseModel.extend({
documentId: "",
extension: "",
fileId: "",
filename: "",
job: "",
orgId: ""
});
let PageModel = BaseModel.extend({
documentId: "",
orgId: "",
contentType: "",
level: 1,
sequence: 0,
revisions: 0,
title: "",
body: "",
rawBody: "",
meta: {},
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}`;
}),
});
let PageMetaModel = BaseModel.extend({
pageId: "",
documentId: "",
orgId: "",
rawBody: "",
config: {},
externalSource: false,
});
let SectionModel = BaseModel.extend({
contentType: "",
title: "",
description: "",
iconFont: "",
iconFile: "",
hasImage: Ember.computed('iconFont', 'iconFile', function () {
return this.get('iconFile').length > 0;
}),
});
export default {
TemplateModel,
AttachmentModel,
DocumentModel,
FolderModel,
FolderPermissionModel,
OrganizationModel,
PageModel,
PageMetaModel,
ProtectedFolderParticipant,
UserModel,
SectionModel
};

91
gui/app/utils/net.js Normal file
View file

@ -0,0 +1,91 @@
// Copyright 2016 Documize Inc. <legal@documize.com>. 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 <sales@documize.com>.
//
// https://documize.com
function getSubdomain() {
if (is.ipv4(window.location.host)) {
return "";
}
let domain = "";
let parts = window.location.host.split(".");
if (parts.length > 1) {
domain = parts[0].toLowerCase();
}
return domain;
}
function getAppUrl(domain) {
let parts = window.location.host.split(".");
parts.removeAt(0);
let leftOvers = parts.join(".");
if (is.empty(domain)) {
domain = "";
} else {
domain = domain + ".";
}
return window.location.protocol + "//" + domain + leftOvers;
}
function isAjaxAccessError(reason) {
if (typeof reason === "undefined") {
return false;
}
// Sometimes we get not error code back so we detect failure to get all spaces for user.
if (reason.message === 'Ajax authorization failed') {
return true;
}
if (typeof reason.errors !== "undefined") {
if (reason.errors.length > 0 && (reason.errors[0].status === "401" || reason.errors[0].status === "403")) {
return true;
}
}
return false;
}
function isAjaxNotFoundError(reason) {
if (typeof reason === "undefined" || typeof reason.errors === "undefined") {
return false;
}
if (reason.errors.length > 0 && (reason.errors[0].status === "404")) {
return true;
}
return false;
}
function isInvalidLicenseError(reason) {
if (typeof reason === "undefined" || typeof reason.errors === "undefined") {
return false;
}
if (reason.errors.length > 0 && reason.errors[0].status === "402") {
return true;
}
return false;
}
export default {
getSubdomain,
getAppUrl,
isAjaxAccessError,
isAjaxNotFoundError,
isInvalidLicenseError,
};

39
gui/app/utils/string.js Normal file
View file

@ -0,0 +1,39 @@
// Copyright 2016 Documize Inc. <legal@documize.com>. 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 <sales@documize.com>.
//
// https://documize.com
// Make url friendly slug from specified text.
// Has to handle non-english character text "Общее" text!
function makeSlug(text) {
return slug(text, { mode: 'rfc3986', lower: true});
//return text.toLowerCase().replace(/[^\w ]+/g, '').replace(/ +/g, '-');
}
function makeId(len) {
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for (var i = 0; i < len; i++) {
text += possible.charAt(Math.floor(Math.random() * possible.length));
}
return text;
}
function endsWith(str, suffix) {
return str.indexOf(suffix, str.length - suffix.length) !== -1;
}
export default {
makeSlug,
makeId,
endsWith
};

274
gui/app/utils/toc.js Normal file
View file

@ -0,0 +1,274 @@
// Copyright 2016 Documize Inc. <legal@documize.com>. 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 <sales@documize.com>.
//
// https://documize.com
function getState(toc, page) {
let state = {
tocTools: {
upTarget: "",
downTarget: "",
indentIncrement: 0,
allowIndent: false,
allowOutdent: false
},
actionablePage: false,
upDisabled: true,
downDisabled: true,
indentDisabled: true,
outdentDisabled: true,
};
if (is.undefined(page)) {
return state;
}
var index = _.indexOf(toc, page, false);
if (index === -1) {
return state;
}
var upPage = toc[index - 1];
var downPage = toc[index + 1];
if (_.isUndefined(upPage)) {
state.tocTools.upTarget = '';
}
if (_.isUndefined(downPage)) {
state.tocTools.downTarget = '';
}
// can we go up?
// can we indent?
if (!_.isUndefined(upPage)) {
// can only go up if someone is same or higher level?
var index2 = _.indexOf(toc, upPage, false);
if (index2 !== -1) {
// up
for (var i = index2; i >= 0; i--) {
if (page.get('level') > toc[i].get('level')) {
break;
}
if (page.get('level') === toc[i].get('level')) {
state.tocTools.upTarget = toc[i].id;
break;
}
}
// indent?
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;
}
}
}
// can we go down?
if (!_.isUndefined(downPage)) {
// can only go down if someone below is at our level or higher
var index3 = _.indexOf(toc, downPage, false);
if (index3 !== -1) {
for (var i3 = index3; i3 < toc.length; i3++) {
if (toc[i3].get('level') < page.get('level')) {
break;
}
if (page.get('level') === toc[i3].get('level')) {
state.tocTools.downTarget = toc[i3].get('id');
break;
}
}
}
if (page.get('level') > downPage.get('level')) {
state.tocTools.downTarget = '';
}
}
// can we outdent?
state.tocTools.allowOutdent = page.get('level') > 1;
state.upDisabled = state.tocTools.upTarget === '';
state.downDisabled = state.tocTools.downTarget === '';
state.indentDisabled = !state.tocTools.allowIndent;
state.outdentDisabled = !state.tocTools.allowOutdent;
state.actionablePage = is.not.empty(state.tocTools.upTarget) ||
is.not.empty(state.tocTools.downTarget) ||
state.tocTools.allowIndent || state.tocTools.allowOutdent;
return state;
}
// move up page and any associated kids
function moveUp(state, pages, current) {
var page1 = _.findWhere(pages, { id: state.tocTools.upTarget });
var page2 = null;
var pendingChanges = [];
if (is.undefined(current) || is.undefined(page1)) {
return pendingChanges;
}
var index1 = _.indexOf(pages, page1, false);
if (index1 !== -1) {
page2 = pages[index1 - 1];
}
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) {
var sequence = (sequence1 + sequence2) / 2;
pendingChanges.push({
pageId: current.get('id'),
sequence: sequence
});
for (var i = index + 1; i < pages.length; i++) {
if (pages[i].get('level') <= current.get('level')) {
break;
}
sequence = (sequence + page1.get('sequence')) / 2;
pendingChanges.push({
pageId: pages[i].get('id'),
sequence: sequence
});
}
}
return pendingChanges;
}
// move down page and any associated kids
function moveDown(state, pages, current) {
var pageIndex = _.indexOf(pages, current, false);
var downTarget = _.findWhere(pages, { id: state.tocTools.downTarget });
var downTargetIndex = _.indexOf(pages, downTarget, false);
var pendingChanges = [];
if (pageIndex === -1 || downTargetIndex === -1) {
return pendingChanges;
}
var startingSequence = 0;
var upperSequence = 0;
var cutOff = _.rest(pages, downTargetIndex);
var siblings = _.reject(cutOff, function (p) {
return p.get('level') !== current.get('level') || p.get('id') === current.get('id') || p.get('id') === downTarget.get('id');
});
if (siblings.length > 0) {
var aboveThisGuy = siblings[0];
var belowThisGuy = pages[_.indexOf(pages, aboveThisGuy, false) - 1];
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.get('sequence') + downTarget.get('sequence')) / 2;
upperSequence = otherGuy.get('sequence');
}
} else {
// startingSequence = downTarget.sequence * 2;
startingSequence = cutOff[cutOff.length - 1].get('sequence') * 2;
upperSequence = startingSequence * 2;
}
pendingChanges.push({
pageId: current.get('id'),
sequence: startingSequence
});
var sequence = (startingSequence + upperSequence) / 2;
for (var i = pageIndex + 1; i < pages.length; i++) {
if (pages[i].get('level') <= current.get('level')) {
break;
}
var sequence2 = (sequence + upperSequence) / 2;
pendingChanges.push({
pageId: pages[i].get('id'),
sequence: sequence2
});
}
return pendingChanges;
}
// indent page and any associated kisds
function indent(state, pages, current) {
var pageIndex = _.indexOf(pages, current, false);
var pendingChanges = [];
pendingChanges.push({
pageId: current.get('id'),
level: current.get('level') + state.tocTools.indentIncrement
});
for (var i = pageIndex + 1; i < pages.length; i++) {
if (pages[i].get('level') <= current.get('level')) {
break;
}
pendingChanges.push({
pageId: pages[i].get('id'),
level: pages[i].get('level') + state.tocTools.indentIncrement
});
}
return pendingChanges;
}
function outdent(state, pages, current) {
var pageIndex = _.indexOf(pages, current, false);
var pendingChanges = [];
pendingChanges.push({
pageId: current.get('id'),
level: current.get('level') - 1
});
for (var i = pageIndex + 1; i < pages.length; i++) {
if (pages[i].get('level') <= current.get('level')) {
break;
}
pendingChanges.push({
pageId: pages[i].get('id'),
level: pages[i].get('level') - 1
});
}
return pendingChanges;
}
export default {
getState,
moveUp,
moveDown,
indent,
outdent
};