From 80f039a6568973b9b7348de2df59dee68f2228ea Mon Sep 17 00:00:00 2001 From: bobzel Date: Sun, 23 Aug 2020 10:25:32 -0400 Subject: added curPage to propertiesView. cleaned up curPage code in PDFBox/viewer. fixed warnings --- .../collectionFreeForm/PropertiesView.scss | 6 +- .../collectionFreeForm/PropertiesView.tsx | 64 +++++++++++----------- src/client/views/nodes/PDFBox.tsx | 8 +-- src/client/views/pdf/PDFViewer.tsx | 30 ++++------ 4 files changed, 51 insertions(+), 57 deletions(-) (limited to 'src') diff --git a/src/client/views/collections/collectionFreeForm/PropertiesView.scss b/src/client/views/collections/collectionFreeForm/PropertiesView.scss index 535581f2e..278f3b964 100644 --- a/src/client/views/collections/collectionFreeForm/PropertiesView.scss +++ b/src/client/views/collections/collectionFreeForm/PropertiesView.scss @@ -731,8 +731,10 @@ border: none; padding: 6px; padding-bottom: 2px; - - + background: #eeeeee; + border-top: 1px solid; + border-left: 1px solid; + &:hover { border: 0.75px solid rgb(122, 28, 28); } diff --git a/src/client/views/collections/collectionFreeForm/PropertiesView.tsx b/src/client/views/collections/collectionFreeForm/PropertiesView.tsx index cbce6448f..50597f2eb 100644 --- a/src/client/views/collections/collectionFreeForm/PropertiesView.tsx +++ b/src/client/views/collections/collectionFreeForm/PropertiesView.tsx @@ -181,40 +181,38 @@ export class PropertiesView extends React.Component { const doc = this.dataDoc; doc && Object.keys(doc).forEach(key => !(key in ids) && doc[key] !== ComputedField.undefined && (ids[key] = key)); const rows: JSX.Element[] = []; - for (const key of Object.keys(ids).slice().sort()) { - if ((key[0] === key[0].toUpperCase() && key.substring(0, 3) !== "ACL" && key !== "UseCors") - || key[0] === "#" || key === "author" || - key === "creationDate" || key.indexOf("lastModified") !== -1) { - - const contents = doc[key]; - if (key[0] === "#") { + const noviceReqFields = ["author", "creationDate"]; + const noviceLayoutFields = ["curPage"]; + const noviceKeys = [...Array.from(Object.keys(ids)).filter(key => key[0] === "#" || key.indexOf("lastModified") !== -1 || (key[0] === key[0].toUpperCase() && !key.startsWith("ACL") && key !== "UseCors")), + ...noviceReqFields, ...noviceLayoutFields] + for (const key of noviceKeys.sort()) { + const contents = this.selectedDoc[key]; + if (key[0] === "#") { + rows.push(
+ {key} +   +
); + } else if (contents !== undefined) { + const value = Field.toString(contents as Field); + if (noviceReqFields.includes(key) || key.indexOf("lastModified") !== -1) { rows.push(
- {key} -   -
); + {key + ": "} +
{value}
+ ); } else { - const value = Field.toString(contents as Field); - if (key === "author" || key === "creationDate" || key.indexOf("lastModified") !== -1) { - rows.push(
- {key + ": "} -
{value}
-
); - } else { - let contentElement: (JSX.Element | null)[] | JSX.Element = []; - contentElement = Field.toKeyValueString(doc, key)} - SetValue={(value: string) => KeyValueBox.SetField(doc, key, value, true)} - />; - - rows.push(
- {key + ":"} -   - {contentElement} -
); - } + let contentElement = Field.toKeyValueString(this.selectedDoc!, key)} + SetValue={(value: string) => KeyValueBox.SetField(noviceLayoutFields.includes(key) ? this.selectedDoc! : doc, key, value, true)} + />; + + rows.push(
+ {key + ":"} +   + {contentElement} +
); } } } @@ -322,7 +320,7 @@ export class PropertiesView extends React.Component { onChange={e => this.changePermissions(e, user)}> {Object.values(SharingPermissions).map(permission => { return ( - ); })} diff --git a/src/client/views/nodes/PDFBox.tsx b/src/client/views/nodes/PDFBox.tsx index 890263a61..621a7f672 100644 --- a/src/client/views/nodes/PDFBox.tsx +++ b/src/client/views/nodes/PDFBox.tsx @@ -99,9 +99,9 @@ export class PDFBox extends ViewBoxAnnotatableComponent { this._pdfViewer?.search(string, fwd); }; public prevAnnotation = () => { this._pdfViewer?.prevAnnotation(); }; public nextAnnotation = () => { this._pdfViewer?.nextAnnotation(); }; - public backPage = () => { this._pdfViewer!.gotoPage((this.Document.curPage || 1) - 1); }; - public forwardPage = () => { this._pdfViewer!.gotoPage((this.Document.curPage || 1) + 1); }; - public gotoPage = (p: number) => { this._pdfViewer!.gotoPage(p); }; + public backPage = () => { this.Document.curPage = (this.Document.curPage || 1) - 1; }; + public forwardPage = () => { this.Document.curPage = (this.Document.curPage || 1) + 1; }; + public gotoPage = (p: number) => { this.Document.curPage = p; }; @undoBatch onKeyDown = action((e: KeyboardEvent) => { @@ -177,7 +177,7 @@ export class PDFBox extends ViewBoxAnnotatableComponent this.gotoPage(Number(e.currentTarget.value))} + onChange={e => this.Document.curPage = Number(e.currentTarget.value)} style={{ width: `${curPage > 99 ? 4 : 3}ch`, pointerEvents: "all" }} onClick={action(() => this._pageControls = !this._pageControls)} /> {this._pageControls ? pageBtns : (null)} diff --git a/src/client/views/pdf/PDFViewer.tsx b/src/client/views/pdf/PDFViewer.tsx index 67d435194..201333d95 100644 --- a/src/client/views/pdf/PDFViewer.tsx +++ b/src/client/views/pdf/PDFViewer.tsx @@ -101,13 +101,7 @@ export class PDFViewer extends ViewBoxAnnotatableComponent void); private _annotationLayer: React.RefObject = React.createRef(); - private _reactionDisposer?: IReactionDisposer; - private _selectionReactionDisposer?: IReactionDisposer; - private _annotationReactionDisposer?: IReactionDisposer; - private _scrollTopReactionDisposer?: IReactionDisposer; - private _filterReactionDisposer?: IReactionDisposer; - private _searchReactionDisposer?: IReactionDisposer; - private _searchReactionDisposer2?: IReactionDisposer; + private _disposers: { [name: string]: IReactionDisposer } = {}; private _viewer: React.RefObject = React.createRef(); private _mainCont: React.RefObject = React.createRef(); private _selectionText: string = ""; @@ -151,13 +145,13 @@ export class PDFViewer extends ViewBoxAnnotatableComponent this._showWaiting = this._showCover = true); this.props.startupLive && this.setupPdfJsViewer(); this._mainCont.current && (this._mainCont.current.scrollTop = this.layoutDoc._scrollTop || 0); - this._searchReactionDisposer = reaction(() => Doc.IsSearchMatch(this.rootDoc), + this._disposers.searchMatch = reaction(() => Doc.IsSearchMatch(this.rootDoc), m => { if (m) (this._lastSearch = true) && this.search(Doc.SearchQuery(), m.searchMatch > 0); else !(this._lastSearch = false) && setTimeout(() => !this._lastSearch && this.search("", false, true), 200); }, { fireImmediately: true }); - this._selectionReactionDisposer = reaction(() => this.props.isSelected(), + this._disposers.selected = reaction(() => this.props.isSelected(), selected => { if (!selected) { this._savedAnnotations.values().forEach(v => v.forEach(a => a.remove())); @@ -167,7 +161,7 @@ export class PDFViewer extends ViewBoxAnnotatableComponent this.Document._scrollY, (scrollY) => { if (scrollY !== undefined) { @@ -178,15 +172,15 @@ export class PDFViewer extends ViewBoxAnnotatableComponent this.Document.curPage, + (page) => page !== undefined && page !== this._pdfViewer?.currentPageNumber && this.gotoPage(page), + { fireImmediately: true } + ); } componentWillUnmount = () => { - this._reactionDisposer?.(); - this._scrollTopReactionDisposer?.(); - this._annotationReactionDisposer?.(); - this._filterReactionDisposer?.(); - this._selectionReactionDisposer?.(); - this._searchReactionDisposer?.(); + Object.values(this._disposers).forEach(disposer => disposer?.()); document.removeEventListener("copy", this.copy); } @@ -227,11 +221,11 @@ export class PDFViewer extends ViewBoxAnnotatableComponent Cast(this.layoutDoc._scrollTop, "number", null), + this._disposers.scrollTop = reaction(() => Cast(this.layoutDoc._scrollTop, "number", null), (stop) => (stop !== undefined && this.layoutDoc._scrollY === undefined && this._mainCont.current) && (this._mainCont.current.scrollTop = stop), { fireImmediately: true }); - this._filterReactionDisposer = reaction( + this._disposers.filterScript = reaction( () => Cast(this.Document.filterScript, ScriptField), action(scriptField => { const oldScript = this._script.originalScript; -- cgit v1.2.3-70-g09d2