aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/PresBox.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/views/nodes/PresBox.tsx')
-rw-r--r--src/client/views/nodes/PresBox.tsx221
1 files changed, 64 insertions, 157 deletions
diff --git a/src/client/views/nodes/PresBox.tsx b/src/client/views/nodes/PresBox.tsx
index 4180ee255..e7434feaa 100644
--- a/src/client/views/nodes/PresBox.tsx
+++ b/src/client/views/nodes/PresBox.tsx
@@ -1,21 +1,17 @@
import React = require("react");
import { library } from '@fortawesome/fontawesome-svg-core';
-import { faArrowLeft, faArrowRight, faEdit, faMinus, faPlay, faPlus, faStop, faTimes } from '@fortawesome/free-solid-svg-icons';
+import { faArrowLeft, faArrowRight, faEdit, faMinus, faPlay, faPlus, faStop, faHandPointLeft, faTimes } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { action, computed, IReactionDisposer, observable, reaction, runInAction } from "mobx";
import { observer } from "mobx-react";
-import { Doc, DocListCast, DocListCastAsync } from "../../../new_fields/Doc";
+import { Doc, DocListCast } from "../../../new_fields/Doc";
import { InkTool } from "../../../new_fields/InkField";
-import { listSpec } from "../../../new_fields/Schema";
-import { BoolCast, Cast, FieldValue, NumCast } from "../../../new_fields/Types";
-import { CurrentUserUtils } from "../../../server/authentication/models/current_user_utils";
+import { BoolCast, Cast, FieldValue, NumCast, StrCast } from "../../../new_fields/Types";
import { returnFalse } from "../../../Utils";
import { DocumentManager } from "../../util/DocumentManager";
import { undoBatch } from "../../util/UndoManager";
import { CollectionDockingView } from "../collections/CollectionDockingView";
import { CollectionView, CollectionViewType } from "../collections/CollectionView";
-import { ContextMenu } from "../ContextMenu";
-import { ContextMenuProps } from "../ContextMenuItem";
import { InkingControl } from "../InkingControl";
import { FieldView, FieldViewProps } from './FieldView';
import "./PresBox.scss";
@@ -24,6 +20,7 @@ library.add(faArrowLeft);
library.add(faArrowRight);
library.add(faPlay);
library.add(faStop);
+library.add(faHandPointLeft);
library.add(faPlus);
library.add(faTimes);
library.add(faMinus);
@@ -44,63 +41,39 @@ export class PresBox extends React.Component<FieldViewProps> {
}
@computed get childDocs() { return DocListCast(this.props.Document[this.props.fieldKey]); }
+ @computed get currentIndex() { return NumCast(this.props.Document._itemIndex); }
- next = async () => {
- runInAction(() => Doc.UserDoc().curPresentation = this.props.Document);
- const current = NumCast(this.props.Document._itemIndex);
- //asking to get document at current index
- const docAtCurrentNext = await this.getDocAtIndex(current + 1);
- if (docAtCurrentNext !== undefined) {
- const presDocs = DocListCast(this.props.Document[this.props.fieldKey]);
- let nextSelected = current + 1;
-
- for (; nextSelected < presDocs.length - 1; nextSelected++) {
- if (!presDocs[nextSelected + 1].groupButton) {
+ updateCurrentPresentation = action(() => Doc.UserDoc().curPresentation = this.props.Document);
+
+ next = () => {
+ this.updateCurrentPresentation();
+ if (this.childDocs[this.currentIndex + 1] !== undefined) {
+ let nextSelected = this.currentIndex + 1;
+ this.gotoDocument(nextSelected, this.currentIndex);
+
+ for (nextSelected = nextSelected + 1; nextSelected < this.childDocs.length; nextSelected++) {
+ if (!this.childDocs[nextSelected].groupButton) {
break;
+ } else {
+ this.gotoDocument(nextSelected, this.currentIndex);
}
}
-
- this.gotoDocument(nextSelected, current);
}
}
- back = async () => {
- action(() => Doc.UserDoc().curPresentation = this.props.Document);
- const current = NumCast(this.props.Document._itemIndex);
- //requesting for the doc at current index
- const docAtCurrent = await this.getDocAtIndex(current);
- if (docAtCurrent !== undefined) {
-
- //asking for its presentation id.
- let prevSelected = current;
- let zoomOut: boolean = false;
-
- const presDocs = await DocListCastAsync(this.props.Document[this.props.fieldKey]);
- const currentsArray: Doc[] = [];
- for (; presDocs && prevSelected > 0 && presDocs[prevSelected].groupButton; prevSelected--) {
- currentsArray.push(presDocs[prevSelected]);
+ back = () => {
+ this.updateCurrentPresentation();
+ const docAtCurrent = this.childDocs[this.currentIndex];
+ if (docAtCurrent) {
+ //check if any of the group members had used zooming in including the current document
+ //If so making sure to zoom out, which goes back to state before zooming action
+ let prevSelected = this.currentIndex;
+ let didZoom = docAtCurrent.zoomButton;
+ for (; !didZoom && prevSelected > 0 && this.childDocs[prevSelected].groupButton; prevSelected--) {
+ didZoom = this.childDocs[prevSelected].zoomButton;
}
prevSelected = Math.max(0, prevSelected - 1);
- //checking if any of the group members had used zooming in
- currentsArray.forEach((doc: Doc) => {
- if (doc.showButton) {
- zoomOut = true;
- return;
- }
- });
-
- // if a group set that flag to zero or a single element
- //If so making sure to zoom out, which goes back to state before zooming action
- if (current > 0) {
- if (zoomOut || docAtCurrent.showButton) {
- const prevScale = NumCast(this.childDocs[prevSelected].viewScale, null);
- const curScale = DocumentManager.Instance.getScaleOfDocView(this.childDocs[current]);
- if (prevScale !== undefined && prevScale !== curScale) {
- DocumentManager.Instance.zoomIntoScale(docAtCurrent, prevScale);
- }
- }
- }
- this.gotoDocument(prevSelected, current);
+ this.gotoDocument(prevSelected, this.currentIndex);
}
}
@@ -114,7 +87,7 @@ export class PresBox extends React.Component<FieldViewProps> {
* Hide Until Presented, Hide After Presented, Fade After Presented
*/
showAfterPresented = (index: number) => {
- action(() => Doc.UserDoc().curPresentation = this.props.Document);
+ this.updateCurrentPresentation();
this.childDocs.forEach((doc, ind) => {
//the order of cases is aligned based on priority
if (doc.hideTillShownButton && ind <= index) {
@@ -135,7 +108,7 @@ export class PresBox extends React.Component<FieldViewProps> {
* Hide Until Presented, Hide After Presented, Fade After Presented
*/
hideIfNotPresented = (index: number) => {
- action(() => Doc.UserDoc().curPresentation = this.props.Document);
+ this.updateCurrentPresentation();
this.childDocs.forEach((key, ind) => {
//the order of cases is aligned based on priority
@@ -157,7 +130,7 @@ export class PresBox extends React.Component<FieldViewProps> {
* te option open, navigates to that element.
*/
navigateToElement = async (curDoc: Doc, fromDocIndex: number) => {
- action(() => Doc.UserDoc().curPresentation = this.props.Document);
+ this.updateCurrentPresentation();
const fromDoc = this.childDocs[fromDocIndex].presentationTargetDoc as Doc;
let docToJump = curDoc;
let willZoom = false;
@@ -177,7 +150,7 @@ export class PresBox extends React.Component<FieldViewProps> {
docToJump = doc;
willZoom = false;
}
- if (doc.showButton) {
+ if (doc.zoomButton) {
docToJump = doc;
willZoom = true;
}
@@ -185,74 +158,36 @@ export class PresBox extends React.Component<FieldViewProps> {
//docToJump stayed same meaning, it was not in the group or was the last element in the group
const aliasOf = await Cast(docToJump.aliasOf, Doc);
- const srcContext = aliasOf && await Cast(aliasOf.anchor1Context, Doc);
+ const srcContext = aliasOf && await Cast(aliasOf.context, Doc);
if (docToJump === curDoc) {
//checking if curDoc has navigation open
const target = await Cast(curDoc.presentationTargetDoc, Doc);
if (curDoc.navButton && target) {
DocumentManager.Instance.jumpToDocument(target, false, undefined, srcContext);
- } else if (curDoc.showButton && target) {
- const curScale = DocumentManager.Instance.getScaleOfDocView(fromDoc);
+ } else if (curDoc.zoomButton && target) {
//awaiting jump so that new scale can be found, since jumping is async
await DocumentManager.Instance.jumpToDocument(target, true, undefined, srcContext);
- curDoc.viewScale = DocumentManager.Instance.getScaleOfDocView(target);
-
- //saving the scale user was on before zooming in
- if (curScale !== 1) {
- fromDoc.viewScale = curScale;
- }
-
}
return;
}
- const curScale = DocumentManager.Instance.getScaleOfDocView(fromDoc);
//awaiting jump so that new scale can be found, since jumping is async
const presTargetDoc = await docToJump.presentationTargetDoc as Doc;
await DocumentManager.Instance.jumpToDocument(presTargetDoc, willZoom, undefined, srcContext);
- const newScale = DocumentManager.Instance.getScaleOfDocView(await curDoc.presentationTargetDoc as Doc);
- curDoc.viewScale = newScale;
- //saving the scale that user was on
- if (curScale !== 1) {
- fromDoc.viewScale = curScale;
- }
-
- }
-
- /**
- * Async function that supposedly return the doc that is located at given index.
- */
- getDocAtIndex = async (index: number) => {
- const list = FieldValue(Cast(this.props.Document[this.props.fieldKey], listSpec(Doc)));
- if (list && index >= 0 && index < list.length) {
- this.props.Document._itemIndex = index;
- //awaiting async call to finish to get Doc instance
- return list[index];
- }
- return undefined;
}
@undoBatch
public removeDocument = (doc: Doc) => {
- const value = FieldValue(Cast(this.props.Document[this.props.fieldKey], listSpec(Doc)));
- if (value) {
- const indexOfDoc = value.indexOf(doc);
- if (indexOfDoc !== - 1) {
- value.splice(indexOfDoc, 1)[0];
- return true;
- }
- }
- return false;
+ return Doc.RemoveDocFromList(this.props.Document, this.props.fieldKey, doc);
}
//The function that is called when a document is clicked or reached through next or back.
//it'll also execute the necessary actions if presentation is playing.
- public gotoDocument = async (index: number, fromDoc: number) => {
- action(() => Doc.UserDoc().curPresentation = this.props.Document);
+ public gotoDocument = (index: number, fromDoc: number) => {
+ this.updateCurrentPresentation();
Doc.UnBrushAllDocs();
- const list = FieldValue(Cast(this.props.Document[this.props.fieldKey], listSpec(Doc)));
- if (list && index >= 0 && index < list.length) {
+ if (index >= 0 && index < this.childDocs.length) {
this.props.Document._itemIndex = index;
if (!this.props.Document.presStatus) {
@@ -260,24 +195,21 @@ export class PresBox extends React.Component<FieldViewProps> {
this.startPresentation(index);
}
- const doc = await list[index];
- if (this.props.Document.presStatus) {
- this.navigateToElement(doc, fromDoc);
- this.hideIfNotPresented(index);
- this.showAfterPresented(index);
- }
+ this.navigateToElement(this.childDocs[index], fromDoc);
+ this.hideIfNotPresented(index);
+ this.showAfterPresented(index);
}
}
//The function that starts or resets presentaton functionally, depending on status flag.
startOrResetPres = () => {
- action(() => Doc.UserDoc().curPresentation = this.props.Document);
+ this.updateCurrentPresentation();
if (this.props.Document.presStatus) {
this.resetPresentation();
} else {
this.props.Document.presStatus = true;
this.startPresentation(0);
- this.gotoDocument(0, NumCast(this.props.Document._itemIndex));
+ this.gotoDocument(0, this.currentIndex);
}
}
@@ -291,79 +223,54 @@ export class PresBox extends React.Component<FieldViewProps> {
//The function that resets the presentation by removing every action done by it. It also
//stops the presentaton.
resetPresentation = () => {
- action(() => Doc.UserDoc().curPresentation = this.props.Document);
- this.childDocs.forEach((doc: Doc) => {
- doc.opacity = 1;
- doc.viewScale = 1;
- });
+ this.updateCurrentPresentation();
+ this.childDocs.forEach(doc => (doc.presentationTargetDoc as Doc).opacity = 1);
this.props.Document._itemIndex = 0;
this.props.Document.presStatus = false;
- if (this.childDocs.length !== 0) {
- DocumentManager.Instance.zoomIntoScale(this.childDocs[0], 1);
- }
}
//The function that starts the presentation, also checking if actions should be applied
//directly at start.
startPresentation = (startIndex: number) => {
- action(() => Doc.UserDoc().curPresentation = this.props.Document);
+ this.updateCurrentPresentation();
this.childDocs.map(doc => {
if (doc.hideTillShownButton && this.childDocs.indexOf(doc) > startIndex) {
- doc.opacity = 0;
+ (doc.presentationTargetDoc as Doc).opacity = 0;
}
if (doc.hideAfterButton && this.childDocs.indexOf(doc) < startIndex) {
- doc.opacity = 0;
+ (doc.presentationTargetDoc as Doc).opacity = 0;
}
if (doc.fadeButton && this.childDocs.indexOf(doc) < startIndex) {
- doc.opacity = 0.5;
+ (doc.presentationTargetDoc as Doc).opacity = 0.5;
}
});
}
- updateMinimize = undoBatch(action((e: React.ChangeEvent, mode: number) => {
- const toggle = BoolCast(this.props.Document.inOverlay) !== (mode === CollectionViewType.Invalid);
- if (toggle) {
+ updateMinimize = undoBatch(action((e: React.ChangeEvent, mode: CollectionViewType) => {
+ if (BoolCast(this.props.Document.inOverlay) !== (mode === CollectionViewType.Invalid)) {
if (this.props.Document.inOverlay) {
- Doc.RemoveDocFromList((CurrentUserUtils.UserDocument.overlays as Doc), this.props.fieldKey, this.props.Document);
+ Doc.RemoveDocFromList((Doc.UserDoc().overlays as Doc), undefined, this.props.Document);
CollectionDockingView.AddRightSplit(this.props.Document);
this.props.Document.inOverlay = false;
} else {
this.props.Document.x = this.props.ScreenToLocalTransform().inverse().transformPoint(0, 0)[0];// 500;//e.clientX + 25;
this.props.Document.y = this.props.ScreenToLocalTransform().inverse().transformPoint(0, 0)[1];////e.clientY - 25;
this.props.addDocTab?.(this.props.Document, "close");
- Doc.AddDocToList((CurrentUserUtils.UserDocument.overlays as Doc), this.props.fieldKey, this.props.Document);
+ Doc.AddDocToList((Doc.UserDoc().overlays as Doc), undefined, this.props.Document);
}
}
}));
- specificContextMenu = (e: React.MouseEvent): void => {
- const funcs: ContextMenuProps[] = [];
- funcs.push({ description: "Show as Slideshow", event: action(() => this.props.Document._viewType = CollectionViewType.Carousel), icon: "asterisk" });
- funcs.push({ description: "Show as Timeline", event: action(() => this.props.Document._viewType = CollectionViewType.Time), icon: "asterisk" });
- funcs.push({ description: "Show as List", event: action(() => this.props.Document._viewType = CollectionViewType.Invalid), icon: "asterisk" });
- ContextMenu.Instance.addItem({ description: "Presentation Funcs...", subitems: funcs, icon: "asterisk" });
- }
-
- /**
- * Initially every document starts with a viewScale 1, which means
- * that they will be displayed in a canvas with scale 1.
- */
- initializeScaleViews = (docList: Doc[], viewtype: number) => {
+ initializeViewAliases = (docList: Doc[], viewtype: CollectionViewType) => {
const hgt = (viewtype === CollectionViewType.Tree) ? 50 : 46;
- docList.forEach((doc: Doc) => {
- doc.presBox = this.props.Document;
- doc.presBoxKey = this.props.fieldKey;
- doc.collapsedHeight = hgt;
- const curScale = NumCast(doc.viewScale, null);
- if (curScale === undefined) {
- doc.viewScale = 1;
- }
+ docList.forEach(doc => {
+ doc.presBox = this.props.Document; // give contained documents a reference to the presentation
+ doc.collapsedHeight = hgt; // set the collpased height for documents based on the type of view (Tree or Stack) they will be displaye din
});
}
selectElement = (doc: Doc) => {
- const index = DocListCast(this.props.Document[this.props.fieldKey]).indexOf(doc);
- index !== -1 && this.gotoDocument(index, NumCast(this.props.Document._itemIndex));
+ this.gotoDocument(this.childDocs.indexOf(doc), NumCast(this.props.Document._itemIndex));
}
getTransform = () => {
@@ -376,18 +283,18 @@ export class PresBox extends React.Component<FieldViewProps> {
@undoBatch
viewChanged = action((e: React.ChangeEvent) => {
//@ts-ignore
- this.props.Document._viewType = Number(e.target.selectedOptions[0].value);
+ this.props.Document._viewType = e.target.selectedOptions[0].value;
+ this.props.Document._viewType === CollectionViewType.Stacking && (this.props.Document._pivotField = undefined); // pivot field may be set by the user in timeline view (or some other way) -- need to reset it here
this.updateMinimize(e, Number(this.props.Document._viewType));
});
childLayoutTemplate = () => this.props.Document._viewType === CollectionViewType.Stacking ? Cast(Doc.UserDoc().presentationTemplate, Doc, null) : undefined;
render() {
- const mode = NumCast(this.props.Document._viewType, CollectionViewType.Invalid);
- this.initializeScaleViews(this.childDocs, mode);
- return <div className="presBox-cont" onContextMenu={this.specificContextMenu} style={{ minWidth: this.props.Document.inOverlay ? 240 : undefined, pointerEvents: this.active() || this.props.Document.inOverlay ? "all" : "none" }} >
+ const mode = StrCast(this.props.Document._viewType) as CollectionViewType;
+ this.initializeViewAliases(this.childDocs, mode);
+ return <div className="presBox-cont" style={{ minWidth: this.props.Document.inOverlay ? 240 : undefined, pointerEvents: this.active() || this.props.Document.inOverlay ? "all" : "none" }} >
<div className="presBox-buttons" style={{ display: this.props.Document._chromeStatus === "disabled" ? "none" : undefined }}>
- <select style={{ minWidth: 50, width: "5%", height: "25", position: "relative", display: "inline-block" }}
- className="collectionViewBaseChrome-viewPicker"
+ <select className="collectionViewBaseChrome-viewPicker"
onPointerDown={e => e.stopPropagation()}
onChange={this.viewChanged}
value={mode}>