From 2164ff77aec51107cca3820e58661a98d9c554f8 Mon Sep 17 00:00:00 2001 From: JuliaSvinareva Date: Thu, 1 Oct 2020 18:29:47 +0300 Subject: [PATCH] [mobile-react] Edit sheet --- apps/documenteditor/mobile/locale/en.json | 44 +++-- .../mobile/src/components/edit/Edit.jsx | 185 +++++++++++++----- .../mobile/src/controller/Main.jsx | 6 +- apps/documenteditor/mobile/src/pages/home.jsx | 26 +-- .../mobile/src/store/focusObjects.js | 37 ++++ .../mobile/src/store/mainStore.js | 2 + 6 files changed, 211 insertions(+), 89 deletions(-) create mode 100644 apps/documenteditor/mobile/src/store/focusObjects.js diff --git a/apps/documenteditor/mobile/locale/en.json b/apps/documenteditor/mobile/locale/en.json index ec605c06e..9df45050f 100644 --- a/apps/documenteditor/mobile/locale/en.json +++ b/apps/documenteditor/mobile/locale/en.json @@ -1,17 +1,31 @@ { - "ViewSettings": { - "textSettings": "Settings", - "textDone": "Done", - "textFindAndReplace": "Find and Replace", - "textDocumentSettings": "Document Settings", - "textApplicationSettings": "Application Settings", - "textDownload": "Download", - "textPrint": "Print", - "textDocumentInfo": "Document Info", - "textHelp": "Help", - "textAbout": "About" - }, - "Collaboration": { - "textEditUser": "Users who are editing the file:" - } + "ViewSettings": { + "textSettings": "Settings", + "textDone": "Done", + "textFindAndReplace": "Find and Replace", + "textDocumentSettings": "Document Settings", + "textApplicationSettings": "Application Settings", + "textDownload": "Download", + "textPrint": "Print", + "textDocumentInfo": "Document Info", + "textHelp": "Help", + "textAbout": "About" + }, + "Collaboration": { + "textEditUser": "Users who are editing the file:" + }, + "Edit": { + "textClose": "Close", + "textText": "Text", + "textParagraph": "Paragraph", + "textTable": "Table", + "textFooter": "Footer", + "textHeader": "Header", + "textShape": "Shape", + "textImage": "Image", + "textChart": "Chart", + "textHyperlink": "Hyperlink", + "textSelectObjectToEdit": "Select object to edit", + "textSettings": "Settings" + } } \ No newline at end of file diff --git a/apps/documenteditor/mobile/src/components/edit/Edit.jsx b/apps/documenteditor/mobile/src/components/edit/Edit.jsx index 2e5afbfe2..9a7c95de2 100644 --- a/apps/documenteditor/mobile/src/components/edit/Edit.jsx +++ b/apps/documenteditor/mobile/src/components/edit/Edit.jsx @@ -1,57 +1,140 @@ -import React, {Component} from 'react'; -import { - Page, - Navbar, - NavRight, - NavLeft, - Link, - Popup, - Tabs, - Tab -} from 'framework7-react'; +import React from 'react'; +import {observer, inject} from "mobx-react"; +import { Page, Navbar, NavRight, NavLeft, NavTitle, Link, Sheet, Tabs, Tab, View } from 'framework7-react'; +import { useTranslation } from 'react-i18next'; import EditText from "./EditText"; import EditParagraph from "./EditParagraph"; -export default class EditContainer extends Component { - constructor(props) { - super(props); - this.state = { - popupOpened: false, - }; - } - render() { - const editors = ['text', 'paragraph'];//, 'table', 'header', 'shape', 'image', 'chart', 'hyperlink']; - const tabLinks = editors.map((item, index) => - {item} - ); - const tabs = editors.map((item, index) => - - {item === 'text' && } - {item === 'paragraph' && } - {/*{item === 'table' && } - {item === 'header' && } - {item === 'shape' && } - {item === 'image' && } - {item === 'chart' && } - {item === 'hyperlink' && }*/} - - ); +const EmptyEditLayout = () => { + const { t } = useTranslation(); + return ( + +
+
+

{t("Edit.textSelectObjectToEdit")}

+
+
+
+ ) +}; + +const EditLayoutNavbar = ({ editors }) => { + const { t } = useTranslation(); + return ( + + { + editors.length > 1 ? + + {editors.map((item, index) => {item.caption})} + : + { editors[0].caption } + } + + {t("Edit.textClose")} + + + ) +}; + +const EditLayoutContent = ({ editors }) => { + if (editors.length > 1) { return ( - this.setState({popupOpened : false})}> - - - - {tabLinks} - - - Close - - - - {tabs} - - - + + {editors.map((item, index) => + + {item.component} + + )} + + ) + } else { + return ( + + {editors[0].component} + ) } -}; \ No newline at end of file +}; + +const EditSheet = props => { + const { t } = useTranslation(); + + const settings = props.storeFocusObjects.focusObjects; + const headerType = props.storeFocusObjects.headerType; + let editors = []; + if (settings.length < 1) { + editors.push({ + caption: t("Edit.textSettings"), + component: + }); + } else { + if (settings.indexOf('text') > -1) { + editors.push({ + caption: t("Edit.textText"), + id: 'edit-text', + component: + }) + } + if (settings.indexOf('paragraph') > -1) { + editors.push({ + caption: t("Edit.textParagraph"), + id: 'edit-paragraph', + component: + }) + } + /*if (settings.indexOf('table') > -1) { + editors.push({ + caption: t("Edit.textTable"), + id: 'edit-table', + component: + }) + } + if (settings.indexOf('header') > -1) { + editors.push({ + caption: headerType==2 ? t("Edit.textFooter") : t("Edit.textHeader"), + id: 'edit-header', + component: + }) + } + if (settings.indexOf('shape') > -1) { + editors.push({ + caption: t("Edit.textShape"), + id: 'edit-shape', + component: + }) + } + if (settings.indexOf('image') > -1) { + editors.push({ + caption: t("Edit.textImage"), + id: 'edit-image', + component: + }) + } + if (settings.indexOf('chart') > -1) { + editors.push({ + caption: t("Edit.textChart"), + id: 'edit-chart', + component: + }) + } + if (settings.indexOf('hyperlink') > -1) { + editors.push({ + caption: t("Edit.textHyperlink"), + id: 'edit-link', + component: + }) + }*/ + } + return ( + + + + + + + + + ) +}; + +export default inject("storeFocusObjects")(observer(EditSheet)); \ No newline at end of file diff --git a/apps/documenteditor/mobile/src/controller/Main.jsx b/apps/documenteditor/mobile/src/controller/Main.jsx index da996ac93..a645e7505 100644 --- a/apps/documenteditor/mobile/src/controller/Main.jsx +++ b/apps/documenteditor/mobile/src/controller/Main.jsx @@ -3,7 +3,7 @@ import React, {Component} from 'react' import {inject} from "mobx-react"; import CollaborationController from '../../../../common/mobile/lib/controller/Collaboration.jsx' -@inject("storeDocumentSettings") +@inject("storeDocumentSettings", "storeFocusObjects") class MainController extends Component { constructor(props) { super(props) @@ -162,6 +162,10 @@ class MainController extends Component { this.api.asc_registerCallback('asc_onPageOrient', isPortrait => { storeSettings.isPortrait = isPortrait === true; }); + const storeFocusObjects = this.props.storeFocusObjects; + this.api.asc_registerCallback('asc_onFocusObject', objects => { + storeFocusObjects.resetFocusObjects(objects); + }); } render() { diff --git a/apps/documenteditor/mobile/src/pages/home.jsx b/apps/documenteditor/mobile/src/pages/home.jsx index fbe35436a..eb3ab00e1 100644 --- a/apps/documenteditor/mobile/src/pages/home.jsx +++ b/apps/documenteditor/mobile/src/pages/home.jsx @@ -1,25 +1,7 @@ import React, { Component } from 'react'; -import { - Page, - View, - Navbar, - NavLeft, - NavTitle, - NavTitleLarge, - NavRight, - Link, - Toolbar, - Block, - BlockTitle, - List, - ListItem, - Row, - Col, - Button, - Icon, Popup -} from 'framework7-react'; +import { Page, View, Navbar, NavLeft, NavRight, Link, Icon } from 'framework7-react'; -import EditPopup from '../components/edit/Edit.jsx'; +import EditSheet from '../components/edit/Edit.jsx'; import SettingsPopup from '../components/settings/Settings.jsx'; import { CollaborationPopover, CollaborationSheet } from '../../../../common/mobile/lib/view/Collaboration.jsx' @@ -39,7 +21,7 @@ export default class Home extends Component { Redu - Edit + Edit {/*Users*/} Users Settings @@ -48,7 +30,7 @@ export default class Home extends Component { {/* Page content */} - + diff --git a/apps/documenteditor/mobile/src/store/focusObjects.js b/apps/documenteditor/mobile/src/store/focusObjects.js new file mode 100644 index 000000000..1cb46738d --- /dev/null +++ b/apps/documenteditor/mobile/src/store/focusObjects.js @@ -0,0 +1,37 @@ +import {action, observable, computed} from 'mobx'; + +export class storeFocusObjects { + @observable focusObjects = []; + @observable headerType = 1; + + @action resetFocusObjects (objects) { + this.focusObjects = objects; + let _settings = []; + for (let object of objects) { + var type = object.get_ObjectType(); + if (Asc.c_oAscTypeSelectElement.Paragraph === type) { + _settings.push('text', 'paragraph'); + } else if (Asc.c_oAscTypeSelectElement.Table === type) { + _settings.push('table'); + } else if (Asc.c_oAscTypeSelectElement.Image === type) { + if (object.get_ObjectValue().get_ChartProperties()) { + _settings.push('chart'); + } else if (object.get_ObjectValue().get_ShapeProperties()) { + _settings.push('shape'); + } else { + _settings.push('image'); + } + } else if (Asc.c_oAscTypeSelectElement.Hyperlink === type) { + _settings.push('hyperlink'); + } else if (Asc.c_oAscTypeSelectElement.Header === type) { + _settings.push('header'); + this.headerType = object.get_ObjectValue().get_Type(); + } + } + // Exclude shapes if chart exist + if (_settings.indexOf('chart') > -1) { + _settings = _settings.filter((value) => value !== 'shape'); + } + this.focusObjects = _settings.filter((value, index, self) => self.indexOf(value) === index); + } +} \ No newline at end of file diff --git a/apps/documenteditor/mobile/src/store/mainStore.js b/apps/documenteditor/mobile/src/store/mainStore.js index 18be6a125..e29f49edd 100644 --- a/apps/documenteditor/mobile/src/store/mainStore.js +++ b/apps/documenteditor/mobile/src/store/mainStore.js @@ -1,8 +1,10 @@ import {storeDocumentSettings} from './documentSettings' +import {storeFocusObjects} from "./focusObjects"; import {storeUsers} from '../../../../common/mobile/lib/store/users' export const stores = { + storeFocusObjects: new storeFocusObjects(), storeDocumentSettings: new storeDocumentSettings(), users: new storeUsers() };