-
Notifications
You must be signed in to change notification settings - Fork 409
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: Implement PDF preview inside dashboards #9698
Closed
mumairr
wants to merge
1
commit into
geosolutions-it:2022.02.xx
from
mumairr:Fix-42-Implement-PDF-preview-inside-dashboards
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
web/client/components/mapviews/settings/CompactRichTextEditor.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/* | ||
* Copyright 2022, GeoSolutions Sas. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import React from 'react'; | ||
import 'react-draft-wysiwyg/dist/react-draft-wysiwyg.css'; | ||
import { Editor } from 'react-draft-wysiwyg'; | ||
import embed from 'embed-video'; | ||
import { DEFAULT_FONT_FAMILIES } from '../../../utils/GeoStoryUtils'; | ||
|
||
export const resizeBase64Image = (src, options) => { | ||
return new Promise((resolve, reject) => { | ||
const { | ||
size, | ||
type = 'image/png', | ||
quality = 0.9 | ||
} = options || {}; | ||
const img = new Image(); | ||
img.crossOrigin = 'anonymous'; | ||
img.onload = () => { | ||
const { naturalWidth, naturalHeight } = img; | ||
const imgResolution = naturalWidth / naturalHeight; | ||
const width = size; | ||
const height = size / imgResolution; | ||
const canvas = document.createElement('canvas'); | ||
canvas.setAttribute('width', width); | ||
canvas.setAttribute('height', height); | ||
const ctx = canvas.getContext('2d'); | ||
ctx.drawImage(img, 0, 0, width, height); | ||
const dataURL = canvas.toDataURL(type, quality); | ||
resolve(dataURL); | ||
}; | ||
img.onerror = (error) => { | ||
reject(error); | ||
}; | ||
img.src = src; | ||
}); | ||
}; | ||
|
||
function CompactRichTextEditor({ | ||
wrapperClassName = 'ms-compact-text-editor', | ||
toolbarOptions, | ||
...props | ||
}) { | ||
|
||
return ( | ||
<Editor | ||
{...props} | ||
editorStyle={{ minHeight: 200 }} | ||
wrapperClassName={wrapperClassName} | ||
toolbar={{ | ||
options: toolbarOptions || ['fontFamily', 'blockType', 'inline', 'textAlign', 'list', 'link', 'colorPicker', 'remove', 'image', 'embedded'], | ||
image: { | ||
urlEnabled: true, | ||
// upload controlled via props, disabled by default | ||
uploadEnabled: props.uploadEnabled || false, | ||
alignmentEnabled: false, | ||
uploadCallback: (file) => new Promise((resolve, reject) => { | ||
const reader = new FileReader(); | ||
reader.addEventListener('load', () => { | ||
resizeBase64Image(reader.result, { | ||
size: 500, | ||
type: 'image/jpeg', | ||
quality: 0.8 | ||
}).then((linkBase64) => { | ||
resolve({ data: { link: linkBase64 } }); | ||
}); | ||
}); | ||
if (file) { | ||
reader.readAsDataURL(file); | ||
} else { | ||
reject(); | ||
} | ||
}), | ||
previewImage: true, | ||
inputAccept: 'image/gif,image/jpeg,image/jpg,image/png,image/svg', | ||
alt: props.alt || { present: false, mandatory: false }, | ||
defaultSize: { | ||
height: 'auto', | ||
width: '100%' | ||
} | ||
}, | ||
fontFamily: { | ||
// Setup fonts via props or use default from GeoStories | ||
options: props.fonts || DEFAULT_FONT_FAMILIES | ||
}, | ||
link: { | ||
inDropdown: false, | ||
showOpenOptionOnHover: true, | ||
defaultTargetOption: '_self', | ||
options: ['link', 'unlink'] | ||
}, | ||
blockType: { | ||
inDropdown: true, | ||
options: ['Normal', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'Blockquote', 'Code'] | ||
}, | ||
inline: { | ||
inDropdown: true, | ||
options: ['bold', 'italic', 'underline', 'strikethrough', 'monospace'] | ||
}, | ||
textAlign: { | ||
inDropdown: true | ||
}, | ||
list: { | ||
inDropdown: true | ||
}, | ||
embedded: { | ||
embedCallback: link => { | ||
const detectedSrc = /<iframe.*? src="(.*?)"/.exec(embed(link)); | ||
return (detectedSrc && detectedSrc[1]) || link; | ||
}, | ||
defaultSize: { | ||
height: 'auto', | ||
width: '100%' | ||
} | ||
} | ||
}} | ||
/> | ||
); | ||
} | ||
|
||
export default CompactRichTextEditor; |
84 changes: 57 additions & 27 deletions
84
web/client/components/widgets/builder/wizard/text/TextOptions.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,69 @@ | ||
/* | ||
/** | ||
* Copyright 2018, GeoSolutions Sas. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { Col, Form, FormControl, FormGroup } from 'react-bootstrap'; | ||
import ReactQuill from '../../../../../libs/quill/react-quill-suspense'; | ||
import React, { useState } from "react"; | ||
import { Col, Form, FormControl, FormGroup } from "react-bootstrap"; | ||
import localizedProps from "../../../../misc/enhancers/localizedProps"; | ||
import { | ||
htmlToDraftJSEditorState, | ||
draftJSEditorStateToHtml | ||
} from "../../../../../utils/EditorUtils"; | ||
|
||
import localizedProps from '../../../../misc/enhancers/localizedProps'; | ||
import withDebounceOnCallback from "../../../../misc/enhancers/withDebounceOnCallback"; | ||
import CompactRichTextEditor from "../../../../mapviews/settings/CompactRichTextEditor"; | ||
|
||
const TitleInput = localizedProps("placeholder")(FormControl); | ||
const DescriptorEditor = withDebounceOnCallback( | ||
"onEditorStateChange", | ||
"editorState" | ||
)(CompactRichTextEditor); | ||
|
||
const Editor = localizedProps("placeholder")(ReactQuill); | ||
|
||
export default ({ data = {}, onChange = () => { }}) => ( | ||
<div> | ||
<Col key="form" xs={12}> | ||
<Form> | ||
<FormGroup controlId="title"> | ||
<Col sm={12}> | ||
<TitleInput style={{ marginBottom: 10 }} placeholder="widgets.builder.wizard.titlePlaceholder" value={data.title} type="text" onChange={e => onChange("title", e.target.value)} /> | ||
</Col> | ||
</FormGroup> | ||
</Form> | ||
</Col> | ||
<Editor modules={{ | ||
toolbar: [ | ||
[{'size': ['small', false, 'large', 'huge'] }, 'bold', 'italic', 'underline', 'blockquote'], | ||
[{'list': 'bullet' }, {'align': [] }], | ||
[{'color': [] }, {'background': [] }, 'clean'], ['image', 'link'] | ||
] | ||
}} placeholder="widgets.builder.wizard.textPlaceholder" value={data && data.text || ''} onChange={(val) => onChange("text", val)} /> | ||
</div> | ||
); | ||
function TextOptions({ data = {}, onChange = () => {} }) { | ||
const [editorState, setEditorState] = useState( | ||
htmlToDraftJSEditorState(data.text || "") | ||
); | ||
|
||
return ( | ||
<div> | ||
<Col key="form" xs={12}> | ||
<Form> | ||
<FormGroup controlId="title"> | ||
<Col sm={12}> | ||
<TitleInput | ||
style={{ marginBottom: 10 }} | ||
placeholder="widgets.builder.wizard.titlePlaceholder" | ||
value={data.title} | ||
type="text" | ||
onChange={(e) => | ||
onChange("title", e.target.value) | ||
} | ||
/> | ||
</Col> | ||
</FormGroup> | ||
</Form> | ||
</Col> | ||
<DescriptorEditor | ||
editorState={editorState} | ||
onEditorStateChange={(newEditorState) => { | ||
const previousHTML = draftJSEditorStateToHtml(editorState); | ||
const newHTML = draftJSEditorStateToHtml(newEditorState); | ||
if (newHTML !== previousHTML) { | ||
onChange( | ||
"text", | ||
draftJSEditorStateToHtml(newEditorState) | ||
); | ||
setEditorState(newEditorState); | ||
} | ||
}} | ||
// Array of custom or built in fonts can be set via props | ||
// fonts={["Arial", "Impact", "Roman"]} | ||
/> | ||
</div> | ||
); | ||
} | ||
export default TextOptions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is needed. Kindly check and revert this change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dsuren1 this was needed to solve a small bug, it came into limelight after Ellano's comment #2 on my previous PR here
Interestingly this came into play as well for this backport. If we add up a long text, links etc. in editor for geostories via map, scrollbar doesn't appear. Kindly check it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Scrollbar is present with position retained as is for
ms-wizard
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It occurs only if you add dashboard txt widget via map for a geostory. I was also confused with it and Stefano guided me how to reproduce it.