froalaEditor.file.beforeUpload Event not firing - wysiwyg

I'm attempting implement the custom file upload feature of the Angular Froala WYSIWYS Editor. I've pasted my configuration options below.
In the console, I can see that both the froalaEditor.file.beforeUpload and froalaEditor.file.inserted events are triggered, but no HTTP action of any kind is fired and neither the froalaEditor.file.uploaded nor the froalaEditor.file.error events are triggered.
Does any know why Froala is not attempting to POST to my fileUploadUrl?
options: Object = {
fileUploadUrl: 'https://localhost:5001/api/file',
events: {
'froalaEditor.file.beforeUpload': function (e: any, editor: any, files: any) {
console.log('BEFORE UPLOAD', e, editor, files, files[0]);
},
'froalaEditor.file.inserted': function (e, editor, $file, response) {
console.log('INSERTED', e, editor, $file, response);
},
'froalaEditor.file.uploaded': function (e, editor, response) {
console.log('UPLOADED', e, editor, response);
},
'froalaEditor.file.error': function (e, editor, error, response) {
console.log('ERROR', e, editor, error, response);
},
}}
Version Info:
Angular CLI: 7.3.0
angular-froala-wysiwyg: "^2.9.1"

1)
While using command froalaEditor.file.beforeUpload and froalaEditor.file.inserted, if you wish to see the HTTP response on your URL kindly have the following property included -
fileUploadMethod: 'POST'
2)
Events can be triggered using -
console.log("Custom Message")
Refer JSFiddle - https://jsfiddle.net/dyt52pqk/2/

Related

Word-Add in CreateDocoment gives AccessDenied

I've created a simple word plugin and want to create a document based off another document.
I've stripped down the code
function WordLoadDocument(msg) {
Word.run(context => {
var myNewDoc = context.application.createDocument();
myNewDoc.properties.load();
/*
myNewDoc.properties.customProperties.add("fileId", file.id);
myNewDoc.properties.customProperties.add("fileName", file.name);
myNewDoc.properties.customProperties.add("attachId", attach.id);
myNewDoc.properties.customProperties.add("attachName", attach.name);*/
myNewDoc.open();
return context.sync()
}).catch(error => {
if (error instanceof OfficeExtension.Error) {
console.log(
"Error code and message: " + JSON.stringify(error.debugInfo)
);
console.log(error)
}
});
But I just get
Error code and message: {"code":"AccessDenied","message":"AccessDenied","errorLocation":"Application.createDocument","statement":"var createDocument = v.createDocument();"...
It doesn't seem to matter what I do I just always get the error - even before I add in the data..
The manifest has ReadWriteDocument which seems to be the 'max'
https://learn.microsoft.com/en-us/javascript/api/manifest/permissions?view=word-js-1.4
Is there something I'm missing.
I'm on Word desktop and sideloading the app via network - could this be a permissions on the machine / type issue?
So I've worked this one out - basically the issue is that I had the add-in in a dialog box (displayDialogAsync). Word doesn't like it and hence the error.

In a vscode extension is there a way to programatically Invoke "repl.action.copyall" through vscode.commands.executeCommand(...)

In short, Im looking for a way to capture the text content of the debug console inside a vscode extension. The following code snippet does pretty much exactly what I want only for the Terminal instead of the debug console. You can also right click in the console and select -> copy all. In the end I wont be pasting it to a new code window but pushing it to an endpoint to automate test reporting.
vscode.commands.executeCommand('workbench.action.terminal.selectAll').then(() => {
vscode.commands.executeCommand('workbench.action.terminal.copySelection').then(() => {
vscode.commands.executeCommand('workbench.action.terminal.clearSelection').then(() => {
vscode.commands.executeCommand('workbench.action.files.newUntitledFile').then(() => {
vscode.commands.executeCommand('editor.action.clipboardPasteAction');
});
});
});
});
I have tried this but I get an error in the console.log
vscode.commands.executeCommand('repl.action.copyall').then(() => {
vscode.commands.executeCommand('workbench.action.files.newUntitledFile').then(() => {
vscode.commands.executeCommand('editor.action.clipboardPasteAction');
});
});
rejected promise not handled within 1 second: Error: command 'repl.action.copyall' not found
extensionHostProcess.js:1048
stack trace: Error: command 'repl.action.copyall' not found
at u._tryExecuteCommand (file:///Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/workbench.desktop.main.js:4213:713)
at file:///Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/workbench.desktop.main.js:4213:594
Any help pointing me in the right direction would be appreciated!
don't do callback hell with Promises
Just return a new Promise in the then() handler
vscode.commands.executeCommand('workbench.action.terminal.selectAll')
.then(() => vscode.commands.executeCommand('workbench.action.terminal.copySelection'))
.then(() => vscode.commands.executeCommand('workbench.action.terminal.clearSelection'))
.then(() => vscode.commands.executeCommand('workbench.action.files.newUntitledFile'))
.then(() => vscode.commands.executeCommand('editor.action.clipboardPasteAction'))

sails helpers and machine spec

I upgrade sails to the #^1.0.0 version and while I'm developing an API, I wanted to use a Service but the Sails document advice to use Helper now. And I don't realy use to work with the new way to discripe helper, build script or actions.
And all the try I have mad wasn't successful.
In the following exemple..
Here is my controller call:
var ob = await ails.helpers.testy('sayHello');
res.json({ob:ob});
helper
module.exports = {
friendlyName: 'Testy',
description: 'Testy something.',
inputs: {
bla: {
type: 'string'
}
},
exits: {
success: {
}
},
fn: async function (inputs, exits) {
console.log({blabla:inputs.bla})
if(!inputs.bla) return exits.error(new Error('text not found'));
var h = "Hello "+ inputs.bla;
// All done.
return exits.success(h);
}
};
I'm getting this error
error: A hook (`helpers`) failed to load!
error:
error: Attempted to `require('*-serv\api\helpers\testy.js')`, but an error occurred:
--
D:\*-serv\api\helpers\testy.js:28
fn: async function (inputs, exits) {
^^^^^^^^
SyntaxError: Unexpected token function.......
and if I remove the "async" and the "await" form the Controller, the ob object return null and I'm having this error
WARNING: A function that was initially called over 15 seconds
ago has still not actually been executed. Any chance the
source code is missing an "await"?
To assist you in hunting this down, here is a stack trace:
```
at Object.signup [as auth/signup] (D:\*-serv\api\controllers\AuthController.js:106:26)
The first guy from the comments is right.
After removing async from fn: async function (inputs, exists) {}; you need to setup sync: true which is false by default. It is described at helpers doc page at Synchronous helpers section.
So your code should look like this
module.exports = {
friendlyName: 'Testy',
description: 'Testy something.',
sync: true, // Here is essential part
inputs: {
bla: {
type: 'string'
}
},
exits: {
success: {
}
},
fn: function (inputs, exits) {
console.log({blabla:inputs.bla})
if(!inputs.bla) return exits.error(new Error('text not found'));
var h = "Hello "+ inputs.bla;
// All done.
return exits.success(h);
}
};
From the another side, you have a problem with async/await. The top most reason for this are
Not supported Node.js version - check that you current version support it
If you use sails-hook-babel or another Babel related solution, you may miss required plugin for async/await processing

Service in vue2JS - error in created hook

I'm new to vue2JS and currently I am trying to create my very first service in vue2 ever.
I've created basic file api.js with this code:
import axios from 'axios';
export default () => {
return axios.create({
baseURL: 'http://localhost:8080/',
timeout: 10000,
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
}
})
}
Code above is basic axios configuration which will be used in every service across entire app.
I import this file into my service:
import api from '../api.js';
export default {
getLatest () {
return api().get(`http://localhost/obiezaca/ob_serwer/api/article/getLatest.php`, {
headers: {
'Content-Type': 'application/json'
}
})
.then(function (response) {
console.log(response.data);
})
.catch(function (error) {
console.log(error);
});
}
}
Code above is responsible for making http request to backend rest API which give JSON in response.
And then finally I want to use this service inside my component <script></script> tags:
<script>
import { getLatest } from '../../../services/articles/getLatest';
export default {
data () {
return {
articles: []
}
},
created () {
const getLatestService = new getLatest();
console.log(getLatestService);
}
}
</script>
Here I want to execute code from service and actually execute this http request then save response in getLatestService constant and then console.log it and I should be able to see JSON in my browser console.
This doesn't work and give me this error in chrome console:
[Vue warn]: Error in created hook: "TypeError: WEBPACK_IMPORTED_MODULE_0__services_articles_getLatest.a is not a constructor"
And this error in command line:
39:35-44 "export 'getLatest' was not found in '../../../services/articles/getLatest'
Please help me to solve this problem. Additionally I want to refactor my code from service (second one) to use async await but I just can't find good example which would show me way to accomplish that.
EDIT 22.11.17
I added error which show in command line and { } when importing in component. I still didn't solve the problem.
EDIT 24.11.17
Looking for an answer I add more explanation of code I've posted and screenshot of files structure if maybe it can help.
I have check your code and what i can see is, in your api.js you have used
baseURL: 'http://localhost:8080/',
and in your service file
return api().get(`http://localhost/obiezaca/ob_serwer/api/article/getLatest.php`
In your service file you have not define your localhost port, i think it should be like
return api().get(http://localhost:8080/obiezaca/ob_serwer/api/article/getLatest.php
If above is not an your issue then you should try
const getLatestService = getLatest();
Because getLatest() is a function and not an object.
This might solve your error issue.

Error message not passed in Amplify.js request

I have this code that uses amplify.js:
amplify.request.define('data', 'ajax', {
url: "WebService.asmx/HelloWorld",
datatype: "json",
type: "POST"
});
amplify.request({
resourceId: 'data',
success: function(p1, p2, p3) {
debugger;
},
error: function(p1, p2, p3) {
debugger;
}
});
The problem is that is server reports error, then the in the error callback, the p1 is null, p2 is 'error' and p3 is undefined.
The similar jQuery.ajax fills these parameters correctly.
$.ajax({
type: "POST",
url: "WebService.asmx/HelloWorld",
success: function(p1, p2, p3) {
debugger;
},
error: function(p1, p2, p3) {
debugger;
}
});
Am I missing Amplify.js configuration to make this work?
Following this link
Amplify Support Group
looks like parsing error body is not supported by default. I will have to write my own decoder for this.
By default amplify is using Jsend decoder that you can replace with your own.
Here's my simple decoder that passes response body JSON object to both success and error callbacks:
amplify.request.decoders._default = function( data, status, ampXHR, success, error ) {
if (status === "success") {
success(data);
} else {
error(JSON.parse(ampXHR.responseText));
}
}
PS. Before doing it, consider adjusting your api responses to the jsend conventions, read more here: http://labs.omniti.com/labs/jsend