Skip to content
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

Feature/sc 32516/wysiwyg for master #2324

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 4 additions & 21 deletions sourcesheets/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1053,8 +1053,6 @@ def sheet_to_html_string(sheet):
Create the html string of sheet with sheet_id.
"""
sheet["sources"] = annotate_user_links(sheet["sources"])
sheet = resolve_options_of_sources(sheet)

try:
owner = User.objects.get(id=sheet["owner"])
author = owner.first_name + " " + owner.last_name
Expand All @@ -1079,23 +1077,6 @@ def sheet_to_html_string(sheet):
return render_to_string('gdocs_sheet.html', context)


def resolve_options_of_sources(sheet):
for source in sheet['sources']:
if 'text' not in source:
continue
options = source.setdefault('options', {})
if not options.get('sourceLanguage'):
source['options']['sourceLanguage'] = sheet['options'].get(
'language', 'bilingual')
if not options.get('sourceLayout'):
source['options']['sourceLayout'] = sheet['options'].get(
'layout', 'sideBySide')
if not options.get('sourceLangLayout'):
source['options']['sourceLangLayout'] = sheet['options'].get(
'langLayout', 'heRight')
return sheet



@gauth_required(scope=['openid', 'https://www.googleapis.com/auth/drive.file', 'https://www.googleapis.com/auth/userinfo.email'], ajax=True)
def export_to_drive(request, credential, sheet_id):
Expand All @@ -1105,16 +1086,18 @@ def export_to_drive(request, credential, sheet_id):
# Using credentials in google-api-python-client.
service = build('drive', 'v3', credentials=credential, cache_discovery=False)
user_info_service = build('oauth2', 'v2', credentials=credential, cache_discovery=False)

sheet = get_sheet(sheet_id)
if 'error' in sheet:
return jsonResponse({'error': {'message': sheet["error"]}})

options = {'language': request.GET.get("language", "bilingual"),
'layout': request.GET.get("layout", "heRight")}
stevekaplan123 marked this conversation as resolved.
Show resolved Hide resolved
sheet['options'] = sheet['options'] | options

file_metadata = {
'name': strip_tags(sheet['title'].strip()),
'mimeType': 'application/vnd.google-apps.document'
}

html_string = bytes(sheet_to_html_string(sheet), "utf8")

media = MediaIoBaseUpload(
Expand Down
15 changes: 13 additions & 2 deletions static/js/ConnectionsPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,8 @@ class ConnectionsPanel extends Component {
{this.props.masterPanelMode === "Sheet" ? <SheetToolsList
toggleSignUpModal={this.props.toggleSignUpModal}
setConnectionsMode={this.props.setConnectionsMode}
masterPanelLanguage={this.props.masterPanelLanguage}
masterPanelLayout={this.props.masterPanelLayout}
masterPanelSheetId={this.props.masterPanelSheetId} /> : null}
<ToolsList
setConnectionsMode={this.props.setConnectionsMode}
Expand Down Expand Up @@ -712,6 +714,7 @@ ConnectionsPanel.propTypes = {
interfaceLang: PropTypes.string,
contentLang: PropTypes.string,
masterPanelLanguage: PropTypes.oneOf(["english", "bilingual", "hebrew"]),
masterPanelLayout: PropTypes.string,
masterPanelMode: PropTypes.string,
masterPanelSheetId: PropTypes.number,
versionFilter: PropTypes.array,
Expand Down Expand Up @@ -799,7 +802,7 @@ const AboutSheetButtons = ({ setConnectionsMode, masterPanelSheetId }) => {
</div>);
}

const SheetToolsList = ({ toggleSignUpModal, masterPanelSheetId, setConnectionsMode }) => {
const SheetToolsList = ({ toggleSignUpModal, masterPanelSheetId, setConnectionsMode, masterPanelLanguage, masterPanelLayout }) => {
stevekaplan123 marked this conversation as resolved.
Show resolved Hide resolved

// const [isOwner, setIsOwner] = useState(false);
// const [isPublished, setIsPublished] = useState(false);
Expand Down Expand Up @@ -827,7 +830,7 @@ const SheetToolsList = ({ toggleSignUpModal, masterPanelSheetId, setConnectionsM
history.replaceState("", document.title, window.location.pathname + window.location.search); // remove exportToDrive hash once it's used to trigger export
$.ajax({
type: "POST",
url: "/api/sheets/" + sheet.id + "/export_to_drive",
url: "/api/sheets/" + sheet.id + `/export_to_drive?language=${masterPanelLanguage}&layout=${masterPanelLayout}`,
success: function (data) {
if ("error" in data) {
console.log(data.error.message);
Expand Down Expand Up @@ -931,6 +934,14 @@ const SheetToolsList = ({ toggleSignUpModal, masterPanelSheetId, setConnectionsM
</div>
)
}
SheetToolsList.propTypes = {
toggleSignUpModal: PropTypes.func.isRequired,
masterPanelSheetId: PropTypes.string.isRequired,
setConnectionsMode: PropTypes.func.isRequired,
masterPanelLanguage: PropTypes.string.isRequired,
masterPanelLayout: PropTypes.string.isRequired
};

class SheetNodeConnectionTools extends Component {
// A list of Resources in addition to connections
render() {
Expand Down
1 change: 1 addition & 0 deletions static/js/ReaderApp.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2202,6 +2202,7 @@ toggleSignUpModal(modalContentKind = SignUpModalKind.Default) {
panelsOpen={panelStates.length}
allOpenRefs={allOpenRefs}
hasSidebar={this.doesPanelHaveSidebar(i)}
masterPanelLayout={panel.mode === "Connections" ? panelStates[i-1].settings.biLayout : ""}
masterPanelLanguage={panel.mode === "Connections" ? panelStates[i-1].settings.language : panel.settings.language}
masterPanelMode={panel.mode === "Connections" ? panelStates[i-1].mode : null}
masterPanelSheetId={panel.mode === "Connections" ? panelStates[i-1].sheetID : null}
Expand Down
2 changes: 2 additions & 0 deletions static/js/ReaderPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,7 @@ class ReaderPanel extends Component {
clearSelectedWords={this.clearSelectedWords}
clearNamedEntity={this.props.clearNamedEntity}
setSidebarSearchQuery={this.props.setSidebarSearchQuery}
masterPanelLayout={this.props.masterPanelLayout}
masterPanelLanguage={this.props.masterPanelLanguage}
masterPanelMode={this.props.initialState.mode === "SheetAndConnections" && this.props.multiPanel === false ? "Sheet" : this.props.masterPanelMode}
masterPanelSheetId={this.props.initialState.mode === "SheetAndConnections" && this.props.multiPanel === false ? this.props.initialState.sheetID : this.props.masterPanelSheetId}
Expand Down Expand Up @@ -1189,6 +1190,7 @@ ReaderPanel.propTypes = {
highlightedRefs: PropTypes.array,
multiPanel: PropTypes.bool,
masterPanelLanguage: PropTypes.string,
masterPanelLayout: PropTypes.string,
panelsOpen: PropTypes.number,
allOpenRefs: PropTypes.array,
hasSidebar: PropTypes.bool,
Expand Down
21 changes: 13 additions & 8 deletions templates/gdocs_sheet.html
Original file line number Diff line number Diff line change
Expand Up @@ -2107,21 +2107,21 @@ <h1 id="title" style="text-align:center">{{ title|striptags|strip_html_entities
<li class="source sheetItem {{ source.options.indented }}">
<div class="customTitle">{{ source.title }}</div>

{% if source.options.sourceLanguage == "hebrew" %}
{% if sheet.options.language == "hebrew" %}
{% include "gdocs_text_source.html" with lang="he" source=source boxed=sheet.options.boxed %}
{% elif source.options.sourceLanguage == "english" %}
{% elif sheet.options.language == "english" %}
{% include "gdocs_text_source.html" with lang="en" source=source boxed=sheet.options.boxed %}
{% else %}
{% if source.options.sourceLayout == "stacked" %}
{% if sheet.options.layout == "stacked" %}
{% include "gdocs_text_source.html" with lang="he" source=source boxed=sheet.options.boxed %}
{% include "gdocs_text_source.html" with lang="en" source=source boxed=sheet.options.boxed %}
{% else %}
<table border="0"><tr><td>
{% if source.options.sourceLangLayout == "heLeft" %}
{% if sheet.options.layout == "heLeft" %}
{% include "gdocs_text_source.html" with lang="he" source=source boxed=sheet.options.boxed %}
</td><td>
{% include "gdocs_text_source.html" with lang="en" source=source boxed=sheet.options.boxed %}
{% else %}
{% elif sheet.options.layout == "heRight" %}
{% include "gdocs_text_source.html" with lang="en" source=source boxed=sheet.options.boxed %}
</td><td>
{% include "gdocs_text_source.html" with lang="he" source=source boxed=sheet.options.boxed %}
Expand All @@ -2141,17 +2141,22 @@ <h1 id="title" style="text-align:center">{{ title|striptags|strip_html_entities
<table border="1"><tr><td>
{% endif %}

{% if sheet.options.language == "hebrew" %}
<div class="he">{{ source.outsideBiText.he }}</div>
{% elif sheet.options.language == "english" %}
<div class="en">{{ source.outsideBiText.en }}</div>
{% else %}
<div class="text">
{% if sheet.options.layout == "stacked" %}
<div class="he">{{ source.outsideBiText.he }}</div>
<div class="en">{{ source.outsideBiText.en }}</div>
{% else %}
<table border="0"><tr><td>
{% if sheet.options.langLayout == "heLeft" %}
{% if sheet.options.layout == "heLeft" %}
<div class="he">{{ source.outsideBiText.he }}</div>
</td><td>
<div class="en">{{ source.outsideBiText.en }}</div>
{% else %}
{% elif sheet.options.layout == "heRight" %}
<div class="en">{{ source.outsideBiText.en }}</div>
</td><td>
<div class="he">{{ source.outsideBiText.he }}</div>
Expand All @@ -2160,7 +2165,7 @@ <h1 id="title" style="text-align:center">{{ title|striptags|strip_html_entities
{% endif %}
<!-- <div class="clear"></div> -->
</div>

{% endif %}
<!-- End box the source -->
{% if sheet.options.boxed %}
</td></tr></table>
Expand Down
Loading