mirror of
https://github.com/documize/community.git
synced 2025-07-24 15:49:44 +02:00
improve level code
This commit is contained in:
parent
049b83e0b9
commit
5f59e95495
25 changed files with 1104 additions and 461 deletions
|
@ -10,7 +10,6 @@
|
|||
// https://documize.com
|
||||
|
||||
import { set } from '@ember/object';
|
||||
|
||||
import { A } from '@ember/array';
|
||||
import ArrayProxy from '@ember/array/proxy';
|
||||
import Service, { inject as service } from '@ember/service';
|
||||
|
@ -21,6 +20,10 @@ export default Service.extend({
|
|||
ajax: service(),
|
||||
store: service(),
|
||||
|
||||
//**************************************************
|
||||
// Document
|
||||
//**************************************************
|
||||
|
||||
// Returns document model for specified document id.
|
||||
getDocument(documentId) {
|
||||
return this.get('ajax').request(`documents/${documentId}`, {
|
||||
|
@ -62,24 +65,6 @@ export default Service.extend({
|
|||
});
|
||||
},
|
||||
|
||||
changePageSequence(documentId, payload) {
|
||||
let url = `documents/${documentId}/pages/sequence`;
|
||||
|
||||
return this.get('ajax').post(url, {
|
||||
data: JSON.stringify(payload),
|
||||
contentType: 'json'
|
||||
});
|
||||
},
|
||||
|
||||
changePageLevel(documentId, payload) {
|
||||
let url = `documents/${documentId}/pages/level`;
|
||||
|
||||
return this.get('ajax').post(url, {
|
||||
data: JSON.stringify(payload),
|
||||
contentType: 'json'
|
||||
});
|
||||
},
|
||||
|
||||
deleteDocument(documentId) {
|
||||
let url = `documents/${documentId}`;
|
||||
|
||||
|
@ -88,6 +73,20 @@ export default Service.extend({
|
|||
});
|
||||
},
|
||||
|
||||
//**************************************************
|
||||
// Page
|
||||
//**************************************************
|
||||
|
||||
// addPage inserts new page to an existing document.
|
||||
addPage(documentId, payload) {
|
||||
let url = `documents/${documentId}/pages`;
|
||||
|
||||
return this.get('ajax').post(url, {
|
||||
data: JSON.stringify(payload),
|
||||
contentType: 'json'
|
||||
});
|
||||
},
|
||||
|
||||
updatePage(documentId, pageId, payload, skipRevision) {
|
||||
var revision = skipRevision ? "?r=true" : "?r=false";
|
||||
let url = `documents/${documentId}/pages/${pageId}${revision}`;
|
||||
|
@ -104,106 +103,6 @@ export default Service.extend({
|
|||
});
|
||||
},
|
||||
|
||||
// addPage inserts new page to an existing document.
|
||||
addPage(documentId, payload) {
|
||||
let url = `documents/${documentId}/pages`;
|
||||
|
||||
return this.get('ajax').post(url, {
|
||||
data: JSON.stringify(payload),
|
||||
contentType: 'json'
|
||||
});
|
||||
},
|
||||
|
||||
// Nukes multiple pages from the document.
|
||||
deletePages(documentId, pageId, payload) {
|
||||
let url = `documents/${documentId}/pages`;
|
||||
|
||||
return this.get('ajax').request(url, {
|
||||
data: JSON.stringify(payload),
|
||||
contentType: 'json',
|
||||
method: 'DELETE'
|
||||
});
|
||||
},
|
||||
|
||||
// Nukes a single page from the document.
|
||||
deletePage(documentId, pageId) {
|
||||
let url = `documents/${documentId}/pages/${pageId}`;
|
||||
|
||||
return this.get('ajax').request(url, {
|
||||
method: 'DELETE'
|
||||
});
|
||||
},
|
||||
|
||||
getDocumentRevisions(documentId) {
|
||||
let url = `documents/${documentId}/revisions`;
|
||||
|
||||
return this.get('ajax').request(url, {
|
||||
method: "GET"
|
||||
});
|
||||
},
|
||||
|
||||
getPageRevisions(documentId, pageId) {
|
||||
let url = `documents/${documentId}/pages/${pageId}/revisions`;
|
||||
|
||||
return this.get('ajax').request(url, {
|
||||
method: "GET"
|
||||
});
|
||||
},
|
||||
|
||||
getPageRevisionDiff(documentId, pageId, revisionId) {
|
||||
let url = `documents/${documentId}/pages/${pageId}/revisions/${revisionId}`;
|
||||
|
||||
return this.get('ajax').request(url, {
|
||||
method: "GET",
|
||||
dataType: 'text'
|
||||
}).then((response) => {
|
||||
return response;
|
||||
}).catch(() => {
|
||||
return "";
|
||||
});
|
||||
},
|
||||
|
||||
rollbackPage(documentId, pageId, revisionId) {
|
||||
let url = `documents/${documentId}/pages/${pageId}/revisions/${revisionId}`;
|
||||
|
||||
return this.get('ajax').request(url, {
|
||||
method: "POST"
|
||||
});
|
||||
},
|
||||
|
||||
// document meta referes to number of views, edits, approvals, etc.
|
||||
getActivity(documentId) {
|
||||
return this.get('ajax').request(`documents/${documentId}/activity`, {
|
||||
method: "GET"
|
||||
}).then((response) => {
|
||||
let data = [];
|
||||
data = response.map((obj) => {
|
||||
let data = this.get('store').normalize('documentActivity', obj);
|
||||
return this.get('store').push(data);
|
||||
});
|
||||
|
||||
return data;
|
||||
}).catch(() => {
|
||||
return [];
|
||||
});
|
||||
},
|
||||
|
||||
// Returns all pages without the content
|
||||
getTableOfContents(documentId) {
|
||||
|
||||
return this.get('ajax').request(`documents/${documentId}/pages?content=0`, {
|
||||
method: 'GET'
|
||||
}).then((response) => {
|
||||
let data = [];
|
||||
data = response.map((obj) => {
|
||||
let data = this.get('store').normalize('page', obj);
|
||||
return this.get('store').push(data);
|
||||
});
|
||||
|
||||
return data;
|
||||
});
|
||||
},
|
||||
|
||||
// Returns all document pages with content
|
||||
getPages(documentId) {
|
||||
return this.get('ajax').request(`documents/${documentId}/pages`, {
|
||||
|
@ -243,6 +142,130 @@ export default Service.extend({
|
|||
});
|
||||
},
|
||||
|
||||
// Nukes multiple pages from the document.
|
||||
deletePages(documentId, pageId, payload) {
|
||||
let url = `documents/${documentId}/pages`;
|
||||
|
||||
return this.get('ajax').request(url, {
|
||||
data: JSON.stringify(payload),
|
||||
contentType: 'json',
|
||||
method: 'DELETE'
|
||||
});
|
||||
},
|
||||
|
||||
// Nukes a single page from the document.
|
||||
deletePage(documentId, pageId) {
|
||||
let url = `documents/${documentId}/pages/${pageId}`;
|
||||
|
||||
return this.get('ajax').request(url, {
|
||||
method: 'DELETE'
|
||||
});
|
||||
},
|
||||
|
||||
//**************************************************
|
||||
// Page Revisions
|
||||
//**************************************************
|
||||
|
||||
getDocumentRevisions(documentId) {
|
||||
let url = `documents/${documentId}/revisions`;
|
||||
|
||||
return this.get('ajax').request(url, {
|
||||
method: "GET"
|
||||
});
|
||||
},
|
||||
|
||||
getPageRevisions(documentId, pageId) {
|
||||
let url = `documents/${documentId}/pages/${pageId}/revisions`;
|
||||
|
||||
return this.get('ajax').request(url, {
|
||||
method: "GET"
|
||||
});
|
||||
},
|
||||
|
||||
getPageRevisionDiff(documentId, pageId, revisionId) {
|
||||
let url = `documents/${documentId}/pages/${pageId}/revisions/${revisionId}`;
|
||||
|
||||
return this.get('ajax').request(url, {
|
||||
method: "GET",
|
||||
dataType: 'text'
|
||||
}).then((response) => {
|
||||
return response;
|
||||
}).catch(() => {
|
||||
return "";
|
||||
});
|
||||
},
|
||||
|
||||
rollbackPage(documentId, pageId, revisionId) {
|
||||
let url = `documents/${documentId}/pages/${pageId}/revisions/${revisionId}`;
|
||||
|
||||
return this.get('ajax').request(url, {
|
||||
method: "POST"
|
||||
});
|
||||
},
|
||||
|
||||
//**************************************************
|
||||
// Activity
|
||||
//**************************************************
|
||||
|
||||
// document meta referes to number of views, edits, approvals, etc.
|
||||
getActivity(documentId) {
|
||||
return this.get('ajax').request(`documents/${documentId}/activity`, {
|
||||
method: "GET"
|
||||
}).then((response) => {
|
||||
let data = [];
|
||||
data = response.map((obj) => {
|
||||
let data = this.get('store').normalize('documentActivity', obj);
|
||||
return this.get('store').push(data);
|
||||
});
|
||||
|
||||
return data;
|
||||
}).catch(() => {
|
||||
return [];
|
||||
});
|
||||
},
|
||||
|
||||
//**************************************************
|
||||
// Table of contents
|
||||
//**************************************************
|
||||
|
||||
// Returns all pages without the content
|
||||
getTableOfContents(documentId) {
|
||||
|
||||
return this.get('ajax').request(`documents/${documentId}/pages?content=0`, {
|
||||
method: 'GET'
|
||||
}).then((response) => {
|
||||
let data = [];
|
||||
data = response.map((obj) => {
|
||||
let data = this.get('store').normalize('page', obj);
|
||||
return this.get('store').push(data);
|
||||
});
|
||||
|
||||
return data;
|
||||
});
|
||||
},
|
||||
|
||||
changePageSequence(documentId, payload) {
|
||||
let url = `documents/${documentId}/pages/sequence`;
|
||||
|
||||
return this.get('ajax').post(url, {
|
||||
data: JSON.stringify(payload),
|
||||
contentType: 'json'
|
||||
});
|
||||
},
|
||||
|
||||
changePageLevel(documentId, payload) {
|
||||
let url = `documents/${documentId}/pages/level`;
|
||||
|
||||
return this.get('ajax').post(url, {
|
||||
data: JSON.stringify(payload),
|
||||
contentType: 'json'
|
||||
});
|
||||
},
|
||||
|
||||
//**************************************************
|
||||
// Attachments
|
||||
//**************************************************
|
||||
|
||||
// document attachments without the actual content
|
||||
getAttachments(documentId) {
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue