Skip to content

Commit

Permalink
Merge pull request #13 from ONLYOFFICE/develop
Browse files Browse the repository at this point in the history
Release/1.2.0
  • Loading branch information
LinneyS authored Jan 30, 2023
2 parents d17fdff + fa02b68 commit ee950d2
Show file tree
Hide file tree
Showing 11 changed files with 2,161 additions and 1,656 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Change Log

## 1.2.0
- added component property onLoadComponentError(), fixed issue [#7](https://github.com/ONLYOFFICE/onlyoffice-alfresco/issues/7)

## 1.1.0
- added IConfig

Expand Down
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Find below the component usage example:
documentServerUrl="http://documentserver/"
:config="config"
:events_onDocumentReady="onDocumentReady"
:onLoadComponentError="onLoadComponentError"
/>
</template>
Expand Down Expand Up @@ -54,6 +55,20 @@ export default defineComponent({
methods: {
onDocumentReady() {
console.log("Document is loaded");
},
onLoadComponentError (errorCode, errorDescription) {
switch(errorCode) {
case -1: // Unknown error loading component
console.log(errorDescription);
break;
case -2: // Error load DocsAPI from http://documentserver/
console.log(errorDescription);
break;
case -3: // DocsAPI is not defined
console.log(errorDescription);
break;
}
},
});
Expand All @@ -66,7 +81,8 @@ export default defineComponent({
| ------------- | ------------- | ------------- | ------------- | ------------- |
| `id` | string | null | yes | Component unique identifier. |
| `documentServerUrl` | string | null | yes | Address ONLYOFFICE Document Server. |
| `config` | object | null | yes | Generic configuration object for opening a file with token. [Config API](https://api.onlyoffice.com/editors/config/) | |
| `config` | object | null | yes | Generic configuration object for opening a file with token. [Config API](https://api.onlyoffice.com/editors/config/) |
| `onLoadComponentError` | (errorCode: number, errorDescription: string) => void | null | no | The function called when an error occurs while loading a component |
| `document_fileType` | string | null | no | The type of the file. |
| `document_title` | string | null | no | The file name. |
| `documentType` | string | null | no | The document type. |
Expand Down
3,741 changes: 2,099 additions & 1,642 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onlyoffice/document-editor-vue",
"version": "1.1.1",
"version": "1.2.0",
"description": "Vue component for ONLYOFFICE Document Server",
"license": "Apache-2.0",
"bugs": {
Expand Down
2 changes: 1 addition & 1 deletion src/components/DocumentEditor.stories.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (c) Copyright Ascensio System SIA 2022
* (c) Copyright Ascensio System SIA 2023
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
41 changes: 35 additions & 6 deletions src/components/DocumentEditor.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (c) Copyright Ascensio System SIA 2022
* (c) Copyright Ascensio System SIA 2023
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -33,8 +33,14 @@ declare global {
export default defineComponent({
name: 'DocumentEditor',
props: {
id: String,
documentServerUrl: String,
id: {
type: String,
required: true
},
documentServerUrl: {
type: String,
required: true
},
config: {
type: Object as PropType<IConfig>,
required: true
Expand All @@ -47,6 +53,8 @@ export default defineComponent({
type: String,
width: String,
onLoadComponentError: Function,
events_onAppReady: Function,
events_onDocumentStateChange: Function,
events_onMetaChange: Function,
Expand Down Expand Up @@ -74,7 +82,7 @@ export default defineComponent({
const docApiUrl = `${url}web-apps/apps/api/documents/api.js`;
loadScript(docApiUrl, "onlyoffice-api-script")
.then(() => this.onLoad())
.catch((err) => console.error(err));
.catch(()=> {this.onError(-2)});
},
unmounted() {
const id = this.id || "";
Expand Down Expand Up @@ -104,7 +112,7 @@ export default defineComponent({
try {
const id = this.id || "";
if (!window.DocsAPI) throw new Error("DocsAPI is not defined");
if (!window.DocsAPI) this.onError(-3);
if (window?.DocEditor?.instances[id]) {
console.log("Skip loading. Instance already exists", id);
return;
Expand Down Expand Up @@ -153,7 +161,28 @@ export default defineComponent({
window.DocEditor.instances[id] = editor;
} catch (err: any) {
console.error(err);
this.events_onError!(err);
this.onError(-1);
}
},
onError(errorCode: Number) {
let message;
switch(errorCode) {
case -2:
message = "Error load DocsAPI from " + this.documentServerUrl;
break;
case -3:
message = "DocsAPI is not defined";
break;
default:
message = "Unknown error loading component";
errorCode = -1;
}
if (typeof this.onLoadComponentError == "undefined") {
console.error(message);
} else {
this.onLoadComponentError(errorCode, message);
}
},
onAppReady() {
Expand Down
2 changes: 1 addition & 1 deletion src/components/DocumentsEditor.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (c) Copyright Ascensio System SIA 2022
* (c) Copyright Ascensio System SIA 2023
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (c) Copyright Ascensio System SIA 2022
* (c) Copyright Ascensio System SIA 2023
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/model/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (c) Copyright Ascensio System SIA 2022
* (c) Copyright Ascensio System SIA 2023
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/shims-vue.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (c) Copyright Ascensio System SIA 2022
* (c) Copyright Ascensio System SIA 2023
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/utils/loadScript.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* (c) Copyright Ascensio System SIA 2022
* (c) Copyright Ascensio System SIA 2023
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down

0 comments on commit ee950d2

Please sign in to comment.