How to get/save data from database using draft-js - draftjs

I decided to raise the issue here. I use mysql as the database as a storage and would like to add draft-js into the web page I am building now. What is the correct way of getting and saving data into the database? Any working examples would be great!

You should use convertToRaw and convertFromRaw methods. Extracts from documentation:
convertFromRaw(rawState: RawDraftContentState): ContentState
Given a raw state, convert it to a ContentState. This is useful when
restoring contents to use within a Draft editor.
convertToRaw(contentState: ContentState): RawDraftContentState
Given a ContentState object, convert it to a raw JS structure. This is
useful when saving an editor state for storage, conversion to other formats, or other usage within an application.
I forked this pen for demonstration how these methods work. Open my pen. First, let's consider a saving editor state. I added "Log editor state" button. If you open console and click on the button, you can see current representation of editor state as JavaScript object. You can convert this object to JSON and save this JSON in your database using the appropriate API endpoint.
click to image for full size
The case when you need to show your editor on the page not empty, with a predefined content which you had previously saved in database or, for example, localstorage. Here, you should use createWithContent method and mentioned above convertFromRaw method. In my example I stored JSON string in the variable editorStateAsJSONString, for a real-world case you should request API endpoint, which returned JSON, and, after it, render the editor component as described.

Related

How to render and display rich text editor data like Images, and code block etc with express and mongoDB and show it on frontend

I am creating a full stack blog application but I am confused how can i render rich text editor data on the backend using express and mongoDB Just like this stackover flow text editor. Most important thig is how can find Images of text editor data and push it on cloudinary. help me out please
First, you should choose what editor you would like to use. One popular open source editor is Quill for example.
After you implement it in your frontend, you should listen to the events on the editor instance (image.added, image.removed...) and based on that you can upload or delete your images from the cloud.
There is also an option to store images encoded in the HTML so you don't have to upload them to cloud at all, but that is not the good practice since it will significantly increase the payload of the HTML.
After you are done with the article, the output HTML from the editor can be saved in the MongoDB, and later you can fetch it and display it in the client side.

How TO Save State in Flutter Locally

how to save state in flutter am trying to make a quantity number which is displayed in text widge there is plus and minus button once I go back from the page the quantity becomes zero even though i have made it any other number
Since your use case is simple , it only requires storing the requisite data to JSON or UTF-8 and writing this data to an editable File.
1.Saving data as JSON
The dart:convert library has converters for JSON and UTF-8, as well as support for creating additional converters. JSON is a simple text format for representing structured objects and collections. UTF-8 is a common variable-width encoding that can represent every character in the Unicode character set.
2.Creating and saving to an editable File
The I/O library enables command-line apps to read and write files and browse directories.
You can used the provider package in Flutter to manage your application state.
Here is the link to the provider package and it's documentation.
Provider Package
Provider Documentation
When asking questions on StackOverflow, it's generally preferred to share some code that you have tried.
In your case, it's likely that you need to use setState in your widget somewhere to modify the value of a variable in your widget class. But without seeing your code, it will be difficult to answer completely.

Persisting data in word document using office add-in

I'm trying to develop word add-in which allows to modify word content. One of the requirement is to select some text and mark it:
change its style (look) - and that is done
Associate that piece of text with some custom/hidden data, ex. an ID.
I want to somehow persist that data within the document, so that:
My add-in can read the document on the start and build a list of 'marked' elements
It should work on different machines - I can create a document on one machine, later open in on other machine, and add-in should be able to retrieve that data.
So far I tried to persist that data by first, getting data as HTML, and add attributes to tags, but that didn't work.
Also tried to add some hidden div, but it was only available during word app lifetime.
Recently, found this link: https://github.com/OfficeDev/Excel-Add-in-JavaScript-PersistCustomSettings , but still it allows to persist data in scope of "browser", so, I assume that on other machine it won't work.
What are my possibilities? Maybe I shouldn't store it within a document, but if not, where?
Developing it using office-js - it should work for both Word 2013 and Word 2016 (so I don't have an access to Word 2016 specific API).
Check out https://dev.office.com/reference/add-ins/shared/settings
The Office JS Settings object allows you to save custom data that persists with the document. It is pretty straight-forward to use. Getting settings is synchronous - saving settings is async. The biggest thing is that you have to remember to call Office.settings.saveAsync() after you have made your changes using Office.settings.set() in order to actually save the changes to the document.
Moreover to Nick's answer which is absolutely correct, you can use "Binding" mechanism.
Bindings are stored in document out-of-the-box, so that, you can access those later at any time.
An example, which fits my needs:
Select some text and click on button in add-in (to call some method)
Call addFromSelectionAsync() method (you can specify an id for it to reference it later)
Access it using getAllAsync() or getByIdAsync() method at any time you need it.
More about it: https://dev.office.com/docs/add-ins/develop/bind-to-regions-in-a-document-or-spreadsheet

Is it possible to upload a file as a blob of data using filepicker.io, instead of using the file selection modal?

I have this problem:
I want to make an interface where the user can drag and drop file uploads. Filepicker.io provides an easy solution to this in the form of filepicker.makeDropPane. However, this feature does not support parallel uploads without the callbacks getting confused.
So I would like to write my own drag/drop interface using standard html5 listeners, and make a direct api upload call to filepicker.io with the actual file data in string form. This way I can write the management of parallel uploads on my own.
Does filepicker.io have an api call that would allow me to do this? I only see these two things:
1) File selection modal
2) Auto drag-drop features
I don't see a way to simply upload a file directly from file data.
What can I do?
You should make use of the filepicker.store() command, which accepts a DOM file object. For example:
var input = document.getElementById("store-input");
filepicker.store(input, function(FPFile){/*your code here*/});
More details available at https://developers.filepicker.io/docs/web/#store

How can i browse file without uploading in GXT?

i'm beginner with GXT and i'm wondering if there is a way to parse a file and extract some informations without uploading it.
i created a formpanel that contains an uploadFile form but i don't know waht's next, how to get the complete path of the file so i can read/write with java io or how to retrieve the file or is there an alternatif solution, thank you.
Best Regards.
You can do it in some modern browsers using bleeding edge HTML5 apis for which you would need to use GWT JSNI code. There are no api's from GWT team as is.
HTML5 FileReader
FileReader includes four options for reading a file, asynchronously:
FileReader.readAsBinaryString(Blob|File) - The result property will contain the file/blob's data as a binary string.
FileReader.readAsText(Blob|File, opt_encoding) - The result property will contain the file/blob's data as a text string.
FileReader.readAsDataURL(Blob|File) - The result property will contain the file/blob's data encoded as a data URL.
FileReader.readAsArrayBuffer(Blob|File) - The result property will contain the file/blob's data as an ArrayBuffer object.
Example of GWT wrapper over these -
https://github.com/bradrydzewski/gwt-filesystem
You can read about it more from here - How to retrieve file from GWT FileUpload component?
IMHO you cannot read it .
Due to security reasons javascript(gwt) doesn't have access to the system drives files.
http://en.wikipedia.org/wiki/JavaScript#Security
see Opening a file in local file system in javascript
In order to get the file you need to make a server call.
Instead you can do your validation server side and throw proper messages to user.
P.S : i am not considering modern browser concept.What happens if someone opened in other than so called modern browsers?? Will the programm runs same?? Its always better to do server side validation..