aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoranika-ahluwalia <anika.ahluwalia@gmail.com>2020-06-30 12:03:22 -0500
committeranika-ahluwalia <anika.ahluwalia@gmail.com>2020-06-30 12:03:22 -0500
commit8c01af79d62b94488dcef2964e89ee6a943c5663 (patch)
tree0841ded920ea17809fbab770f835bbfa0cfaefcd /src
parent6ca206d098ff745fff9a009ddf783995cab23df0 (diff)
parent5d7823da144191930ead98a60aedd6543748d4a1 (diff)
Merge branch 'master' of https://github.com/browngraphicslab/Dash-Web into anika_schema_view
Diffstat (limited to 'src')
-rw-r--r--src/client/documents/DocumentTypes.ts2
-rw-r--r--src/client/documents/Documents.ts15
-rw-r--r--src/client/util/CurrentUserUtils.ts3
-rw-r--r--src/client/util/DragManager.ts4
-rw-r--r--src/client/util/GroupManager.scss136
-rw-r--r--src/client/util/GroupManager.tsx360
-rw-r--r--src/client/util/GroupMemberView.scss68
-rw-r--r--src/client/util/GroupMemberView.tsx75
-rw-r--r--src/client/util/LinkManager.ts15
-rw-r--r--src/client/util/SearchUtil.ts2
-rw-r--r--src/client/util/SettingsManager.scss1
-rw-r--r--src/client/util/SharingManager.scss104
-rw-r--r--src/client/util/SharingManager.tsx209
-rw-r--r--src/client/views/MainView.scss50
-rw-r--r--src/client/views/MainView.tsx18
-rw-r--r--src/client/views/collections/CollectionStackingViewFieldColumn.tsx2
-rw-r--r--src/client/views/collections/CollectionSubView.tsx16
-rw-r--r--src/client/views/collections/CollectionTreeView.tsx10
-rw-r--r--src/client/views/collections/CollectionView.tsx31
-rw-r--r--src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx1
-rw-r--r--src/client/views/nodes/DocumentView.tsx5
-rw-r--r--src/client/views/nodes/VideoBox.tsx28
-rw-r--r--src/client/views/nodes/formattedText/FormattedTextBox.tsx11
-rw-r--r--src/client/views/nodes/formattedText/marks_rts.ts1
-rw-r--r--src/fields/Doc.ts36
25 files changed, 1040 insertions, 163 deletions
diff --git a/src/client/documents/DocumentTypes.ts b/src/client/documents/DocumentTypes.ts
index 7ba21b2f6..7578b7df0 100644
--- a/src/client/documents/DocumentTypes.ts
+++ b/src/client/documents/DocumentTypes.ts
@@ -32,8 +32,10 @@ export enum DocumentType {
YOUTUBE = "youtube", // youtube directory (view of you tube search results)
DOCHOLDER = "docholder", // nested document (view of a document)
COMPARISON = "comparison", // before/after view with slider (view of 2 images)
+ GROUP = "group", // group of users
LINKDB = "linkdb", // database of links ??? why do we have this
SCRIPTDB = "scriptdb", // database of scripts
RECOMMENDATION = "recommendation", // view of a recommendation
+ GROUPDB = "groupdb" // database of groups
} \ No newline at end of file
diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts
index 24e86bca6..3d4694bc5 100644
--- a/src/client/documents/Documents.ts
+++ b/src/client/documents/Documents.ts
@@ -312,6 +312,14 @@ export namespace Docs {
[DocumentType.COMPARISON, {
layout: { view: ComparisonBox, dataField: defaultDataKey },
}],
+ [DocumentType.GROUPDB, {
+ data: new List<Doc>(),
+ layout: { view: EmptyBox, dataField: defaultDataKey },
+ options: { childDropAction: "alias", title: "Global Group Database" }
+ }],
+ [DocumentType.GROUP, {
+ layout: { view: EmptyBox, dataField: defaultDataKey }
+ }]
]);
// All document prototypes are initialized with at least these values
@@ -375,6 +383,13 @@ export namespace Docs {
}
/**
+ * A collection of all groups in the database
+ */
+ export function MainGroupDocument() {
+ return Prototypes.get(DocumentType.GROUPDB);
+ }
+
+ /**
* This is a convenience method that is used to initialize
* prototype documents for the first time.
*
diff --git a/src/client/util/CurrentUserUtils.ts b/src/client/util/CurrentUserUtils.ts
index d0ca0e57e..09e4d2bb1 100644
--- a/src/client/util/CurrentUserUtils.ts
+++ b/src/client/util/CurrentUserUtils.ts
@@ -654,7 +654,7 @@ export class CurrentUserUtils {
// Finally, setup the list of buttons to display in the sidebar
if (doc["tabs-buttons"] === undefined) {
- doc["tabs-buttons"] = new PrefetchProxy(Docs.Create.StackingDocument([searchBtn, libraryBtn, toolsBtn], {
+ doc["tabs-buttons"] = new PrefetchProxy(Docs.Create.StackingDocument([libraryBtn, searchBtn, toolsBtn], {
_width: 500, _height: 80, boxShadow: "0 0", _pivotField: "title", _columnsHideIfEmpty: true, ignoreClick: true, _chromeStatus: "view-mode",
title: "sidebar btn row stack", backgroundColor: "dimGray",
}));
@@ -777,6 +777,7 @@ export class CurrentUserUtils {
await this.setupSidebarButtons(doc); // the pop-out left sidebar of tools/panels
doc.globalLinkDatabase = Docs.Prototypes.MainLinkDocument();
doc.globalScriptDatabase = Docs.Prototypes.MainScriptDocument();
+ doc.globalGroupDatabase = Docs.Prototypes.MainGroupDocument();
// setup reactions to change the highlights on the undo/redo buttons -- would be better to encode this in the undo/redo buttons, but the undo/redo stacks are not wired up that way yet
doc["dockedBtn-undo"] && reaction(() => UndoManager.undoStack.slice(), () => Doc.GetProto(doc["dockedBtn-undo"] as Doc).opacity = UndoManager.CanUndo() ? 1 : 0.4, { fireImmediately: true });
diff --git a/src/client/util/DragManager.ts b/src/client/util/DragManager.ts
index 0db3963b2..2ceafff30 100644
--- a/src/client/util/DragManager.ts
+++ b/src/client/util/DragManager.ts
@@ -202,7 +202,6 @@ export namespace DragManager {
dropDoc instanceof Doc && DocUtils.MakeLinkToActiveAudio(dropDoc);
return dropDoc;
};
- const batch = UndoManager.StartBatch("dragging");
const finishDrag = (e: DragCompleteEvent) => {
const docDragData = e.docDragData;
if (docDragData && !docDragData.droppedDocuments.length) {
@@ -216,7 +215,6 @@ export namespace DragManager {
const remProps = (dragData?.removeDropProperties || []).concat(Array.from(dragProps));
remProps.map(prop => drop[prop] = undefined);
});
- batch.end();
}
return e;
};
@@ -315,6 +313,7 @@ export namespace DragManager {
export let docsBeingDragged: Doc[] = [];
export let CanEmbed = false;
export function StartDrag(eles: HTMLElement[], dragData: { [id: string]: any }, downX: number, downY: number, options?: DragOptions, finishDrag?: (dropData: DragCompleteEvent) => void) {
+ const batch = UndoManager.StartBatch("dragging");
eles = eles.filter(e => e);
CanEmbed = false;
if (!dragDiv) {
@@ -449,6 +448,7 @@ export namespace DragManager {
document.removeEventListener("pointermove", moveHandler, true);
document.removeEventListener("pointerup", upHandler);
SnappingManager.clearSnapLines();
+ batch.end();
});
AbortDrag = () => {
diff --git a/src/client/util/GroupManager.scss b/src/client/util/GroupManager.scss
new file mode 100644
index 000000000..544a79e98
--- /dev/null
+++ b/src/client/util/GroupManager.scss
@@ -0,0 +1,136 @@
+@import "../views/globalCssVariables";
+
+.group-interface {
+ background-color: whitesmoke !important;
+ color: grey;
+ width: 450px;
+ height: 300px;
+
+ .dialogue-box {
+ width: 450;
+ height: 300;
+ }
+
+ button {
+ background: $lighter-alt-accent;
+ outline: none;
+ border-radius: 5px;
+ border: 0px;
+ color: #fcfbf7;
+ text-transform: uppercase;
+ letter-spacing: 2px;
+ font-size: 75%;
+ padding: 10px;
+ margin: 10px;
+ transition: transform 0.2s;
+ margin: 2px;
+ }
+}
+
+.group-interface {
+ display: flex;
+ flex-direction: column;
+
+ .overlay {
+ transform: translate(-20px, -20px);
+ border-radius: 10px;
+ }
+
+ button {
+ width: 100%;
+ align-self: center;
+ background: $darker-alt-accent;
+ }
+
+ .delete-button {
+ background: rgb(227, 86, 86);
+ }
+
+ .close-button {
+ position: absolute;
+ right: 1em;
+ top: 1em;
+ cursor: pointer;
+ z-index: 999;
+ }
+
+ .group-heading {
+ letter-spacing: .5em;
+ }
+
+
+ .group-body {
+ display: flex;
+ justify-content: space-between;
+ max-height: 80%;
+
+ .group-create {
+ display: flex;
+ flex-direction: column;
+ flex-basis: 30%;
+ margin-left: 5px;
+
+ input {
+ border-radius: 5px;
+ border: none;
+ padding: 4px;
+ min-width: 100%;
+ margin: 4px 0 4px 0;
+ }
+
+ }
+
+ .group-content {
+ padding-left: 1em;
+ padding-right: 1em;
+ justify-content: space-around;
+ text-align: left;
+
+ overflow-y: auto;
+ width: 100%;
+
+ .group-row {
+ display: flex;
+ position: relative;
+ margin-bottom: 5px;
+ min-height: 40px;
+ border: 1px solid;
+ border-radius: 10px;
+ align-items: center;
+
+ .group-name {
+ position: relative;
+ max-width: 65%;
+ left: 10;
+ }
+
+ button {
+ position: absolute;
+ width: 30%;
+ right: 2;
+ margin-top: 0;
+ }
+ }
+
+ ::placeholder {
+ color: $intermediate-color;
+ }
+
+ input {
+ border-radius: 5px;
+ border: none;
+ padding: 4px;
+ min-width: 100%;
+ margin: 2px 0;
+ }
+
+ }
+ }
+
+ h1 {
+ color: $dark-color;
+ text-transform: uppercase;
+ letter-spacing: 2px;
+ font-size: 120%;
+ }
+} \ No newline at end of file
diff --git a/src/client/util/GroupManager.tsx b/src/client/util/GroupManager.tsx
new file mode 100644
index 000000000..7c68fc2a0
--- /dev/null
+++ b/src/client/util/GroupManager.tsx
@@ -0,0 +1,360 @@
+import * as React from "react";
+import { observable, action, runInAction, computed } from "mobx";
+import { SelectionManager } from "./SelectionManager";
+import MainViewModal from "../views/MainViewModal";
+import { observer } from "mobx-react";
+import { Doc, DocListCast, Opt } from "../../fields/Doc";
+import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
+import * as fa from '@fortawesome/free-solid-svg-icons';
+import { library } from "@fortawesome/fontawesome-svg-core";
+import SharingManager, { User } from "./SharingManager";
+import { Utils } from "../../Utils";
+import * as RequestPromise from "request-promise";
+import Select from 'react-select';
+import "./GroupManager.scss";
+import { StrCast } from "../../fields/Types";
+import GroupMemberView from "./GroupMemberView";
+
+library.add(fa.faWindowClose);
+
+export interface UserOptions {
+ label: string;
+ value: string;
+}
+
+@observer
+export default class GroupManager extends React.Component<{}> {
+
+ static Instance: GroupManager;
+ @observable isOpen: boolean = false; // whether the GroupManager is to be displayed or not.
+ @observable private dialogueBoxOpacity: number = 1; // opacity of the dialogue box div of the MainViewModal.
+ @observable private overlayOpacity: number = 0.4; // opacity of the overlay div of the MainViewModal.
+ @observable private users: string[] = []; // list of users populated from the database.
+ @observable private selectedUsers: UserOptions[] | null = null; // list of users selected in the "Select users" dropdown.
+ @observable currentGroup: Opt<Doc>; // the currently selected group.
+ private inputRef: React.RefObject<HTMLInputElement> = React.createRef(); // the ref for the input box.
+
+ constructor(props: Readonly<{}>) {
+ super(props);
+ GroupManager.Instance = this;
+ }
+
+ // sets up the list of users
+ componentDidMount() {
+ this.populateUsers().then(resolved => runInAction(() => this.users = resolved));
+ }
+
+ /**
+ * Fetches the list of users stored on the database and @returns a list of the emails.
+ */
+ populateUsers = async () => {
+ const userList: User[] = JSON.parse(await RequestPromise.get(Utils.prepend("/getUsers")));
+ const currentUserIndex = userList.findIndex(user => user.email === Doc.CurrentUserEmail);
+ currentUserIndex !== -1 && userList.splice(currentUserIndex, 1);
+ return userList.map(user => user.email);
+ }
+
+ /**
+ * @returns the options to be rendered in the dropdown menu to add users and create a group.
+ */
+ @computed get options() {
+ return this.users.map(user => ({ label: user, value: user }));
+ }
+
+ /**
+ * Makes the GroupManager visible.
+ */
+ @action
+ open = () => {
+ SelectionManager.DeselectAll();
+ this.isOpen = true;
+ }
+
+ /**
+ * Hides the GroupManager.
+ */
+ @action
+ close = () => {
+ this.isOpen = false;
+ this.currentGroup = undefined;
+ }
+
+ /**
+ * @returns the database of groups.
+ */
+ get GroupManagerDoc(): Doc | undefined {
+ return Doc.UserDoc().globalGroupDatabase as Doc;
+ }
+
+ /**
+ * @returns a list of all group documents.
+ */
+ private getAllGroups(): Doc[] {
+ const groupDoc = this.GroupManagerDoc;
+ return groupDoc ? DocListCast(groupDoc.data) : [];
+ }
+
+ /**
+ * @returns a group document based on the group name.
+ * @param groupName
+ */
+ private getGroup(groupName: string): Doc | undefined {
+ const groupDoc = this.getAllGroups().find(group => group.groupName === groupName);
+ return groupDoc;
+ }
+
+ /**
+ * @returns a readonly copy of a single group document
+ */
+ getGroupCopy(groupName: string): Doc | undefined {
+ const groupDoc = this.getGroup(groupName);
+ if (groupDoc) {
+ const { members, owners } = groupDoc;
+ return Doc.assign(new Doc, { groupName, members: StrCast(members), owners: StrCast(owners) });
+ }
+ return undefined;
+ }
+ /**
+ * @returns a readonly copy of the list of group documents
+ */
+ getAllGroupsCopy(): Doc[] {
+ return this.getAllGroups().map(({ groupName, owners, members }) =>
+ Doc.assign(new Doc, { groupName: (StrCast(groupName)), owners: (StrCast(owners)), members: (StrCast(members)) })
+ );
+ }
+
+ /**
+ * @returns the members of the admin group.
+ */
+ get adminGroupMembers(): string[] {
+ return this.getGroup("admin") ? JSON.parse(StrCast(this.getGroup("admin")!.members)) : "";
+ }
+
+ /**
+ * @returns a boolean indicating whether the current user has access to edit group documents.
+ * @param groupDoc
+ */
+ hasEditAccess(groupDoc: Doc): boolean {
+ if (!groupDoc) return false;
+ const accessList: string[] = JSON.parse(StrCast(groupDoc.owners));
+ return accessList.includes(Doc.CurrentUserEmail) || this.adminGroupMembers?.includes(Doc.CurrentUserEmail);
+ }
+
+ /**
+ * Helper method that sets up the group document.
+ * @param groupName
+ * @param memberEmails
+ */
+ createGroupDoc(groupName: string, memberEmails: string[] = []) {
+ const groupDoc = new Doc;
+ groupDoc.groupName = groupName;
+ groupDoc.owners = JSON.stringify([Doc.CurrentUserEmail]);
+ groupDoc.members = JSON.stringify(memberEmails);
+ this.addGroup(groupDoc);
+ }
+
+ /**
+ * Helper method that adds a group document to the database of group documents and @returns whether it was successfully added or not.
+ * @param groupDoc
+ */
+ addGroup(groupDoc: Doc): boolean {
+ if (this.GroupManagerDoc) {
+ Doc.AddDocToList(this.GroupManagerDoc, "data", groupDoc);
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Deletes a group from the database of group documents and @returns whether the group was deleted or not.
+ * @param group
+ */
+ deleteGroup(group: Doc): boolean {
+ if (group) {
+ if (this.GroupManagerDoc && this.hasEditAccess(group)) {
+ Doc.RemoveDocFromList(this.GroupManagerDoc, "data", group);
+ SharingManager.Instance.setInternalGroupSharing(group, "Not Shared");
+ if (group === this.currentGroup) {
+ runInAction(() => this.currentGroup = undefined);
+ }
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Adds a member to a group.
+ * @param groupDoc
+ * @param email
+ */
+ addMemberToGroup(groupDoc: Doc, email: string) {
+ if (this.hasEditAccess(groupDoc)) {
+ const memberList: string[] = JSON.parse(StrCast(groupDoc.members));
+ !memberList.includes(email) && memberList.push(email);
+ groupDoc.members = JSON.stringify(memberList);
+ }
+ }
+
+ /**
+ * Removes a member from the group.
+ * @param groupDoc
+ * @param email
+ */
+ removeMemberFromGroup(groupDoc: Doc, email: string) {
+ if (this.hasEditAccess(groupDoc)) {
+ const memberList: string[] = JSON.parse(StrCast(groupDoc.members));
+ const index = memberList.indexOf(email);
+ index !== -1 && memberList.splice(index, 1);
+ groupDoc.members = JSON.stringify(memberList);
+ }
+ }
+
+ /**
+ * Handles changes in the users selected in the "Select users" dropdown.
+ * @param selectedOptions
+ */
+ @action
+ handleChange = (selectedOptions: any) => {
+ this.selectedUsers = selectedOptions as UserOptions[];
+ }
+
+ /**
+ * Creates the group when the enter key has been pressed (when in the input).
+ * @param e
+ */
+ handleKeyDown = (e: React.KeyboardEvent) => {
+ e.key === "Enter" && this.createGroup();
+ }
+
+ /**
+ * Handles the input of required fields in the setup of a group and resets the relevant variables.
+ */
+ @action
+ createGroup = () => {
+ if (!this.inputRef.current?.value) {
+ alert("Please enter a group name");
+ return;
+ }
+ if (this.getAllGroups().find(group => group.groupName === this.inputRef.current!.value)) { // why do I need a null check here?
+ alert("Please select a unique group name");
+ return;
+ }
+ this.createGroupDoc(this.inputRef.current.value, this.selectedUsers?.map(user => user.value));
+ this.selectedUsers = null;
+ this.inputRef.current.value = "";
+ }
+
+ /**
+ * A getter that @returns the interface rendered to view an individual group.
+ */
+ private get editingInterface() {
+ const members: string[] = this.currentGroup ? JSON.parse(StrCast(this.currentGroup.members)) : [];
+ const options: UserOptions[] = this.currentGroup ? this.options.filter(option => !(JSON.parse(StrCast(this.currentGroup!.members)) as string[]).includes(option.value)) : [];
+ return (!this.currentGroup ? null :
+ <div className="editing-interface">
+ <div className="editing-header">
+ <b>{this.currentGroup.groupName}</b>
+ <div className={"close-button"} onClick={action(() => this.currentGroup = undefined)}>
+ <FontAwesomeIcon icon={fa.faWindowClose} size={"lg"} />
+ </div>
+
+ {this.hasEditAccess(this.currentGroup) ?
+ <div className="group-buttons">
+ <div className="add-member-dropdown">
+ <Select
+ // isMulti={true}
+ isSearchable={true}
+ options={options}
+ onChange={selectedOption => this.addMemberToGroup(this.currentGroup!, (selectedOption as UserOptions).value)}
+ placeholder={"Add members"}
+ value={null}
+ closeMenuOnSelect={true}
+ />
+ </div>
+ <button onClick={() => this.deleteGroup(this.currentGroup!)}>Delete group</button>
+ </div> :
+ null}
+ </div>
+ <div className="editing-contents">
+ {members.map(member => (
+ <div className="editing-row">
+ <div className="user-email">
+ {member}
+ </div>
+ {this.hasEditAccess(this.currentGroup!) ? <button onClick={() => this.removeMemberFromGroup(this.currentGroup!, member)}> Remove </button> : null}
+ </div>
+ ))}
+ </div>
+ </div>
+ );
+
+ }
+
+ /**
+ * A getter that @returns the main interface for the GroupManager.
+ */
+ private get groupInterface() {
+ return (
+ <div className="group-interface">
+ {/* <MainViewModal
+ contents={this.editingInterface}
+ isDisplayed={this.currentGroup ? true : false}
+ interactive={true}
+ dialogueBoxDisplayedOpacity={this.dialogueBoxOpacity}
+ overlayDisplayedOpacity={this.overlayOpacity}
+ /> */}
+ {this.currentGroup ?
+ <GroupMemberView
+ group={this.currentGroup}
+ onCloseButtonClick={() => this.currentGroup = undefined}
+ />
+ : null}
+ <div className="group-heading">
+ <h1>Groups</h1>
+ <div className={"close-button"} onClick={this.close}>
+ <FontAwesomeIcon icon={fa.faWindowClose} size={"lg"} />
+ </div>
+ </div>
+ <div className="group-body">
+ <div className="group-create">
+ <button onClick={this.createGroup}>Create group</button>
+ <input ref={this.inputRef} onKeyDown={this.handleKeyDown} type="text" placeholder="Group name" />
+ <Select
+ isMulti={true}
+ isSearchable={true}
+ options={this.options}
+ onChange={this.handleChange}
+ placeholder={"Select users"}
+ value={this.selectedUsers}
+ closeMenuOnSelect={false}
+ />
+ </div>
+ <div className="group-content">
+ {this.getAllGroups().map(group =>
+ <div className="group-row">
+ <div className="group-name">{group.groupName}</div>
+ <button onClick={action(() => this.currentGroup = group)}>
+ {this.hasEditAccess(group) ? "Edit" : "View"}
+ </button>
+ </div>
+ )}
+ </div>
+ </div>
+ </div>
+ );
+ }
+
+ render() {
+ return (
+ <MainViewModal
+ contents={this.groupInterface}
+ isDisplayed={this.isOpen}
+ interactive={true}
+ dialogueBoxDisplayedOpacity={this.dialogueBoxOpacity}
+ overlayDisplayedOpacity={this.overlayOpacity}
+ />
+ );
+ }
+
+} \ No newline at end of file
diff --git a/src/client/util/GroupMemberView.scss b/src/client/util/GroupMemberView.scss
new file mode 100644
index 000000000..7833c485f
--- /dev/null
+++ b/src/client/util/GroupMemberView.scss
@@ -0,0 +1,68 @@
+@import "../views/globalCssVariables";
+
+.editing-interface {
+ background-color: whitesmoke !important;
+ color: grey;
+ width: 100%;
+ height: 100%;
+
+ button {
+ background: $darker-alt-accent;
+ outline: none;
+ border-radius: 5px;
+ border: 0px;
+ color: #fcfbf7;
+ text-transform: uppercase;
+ letter-spacing: 2px;
+ font-size: 75%;
+ padding: 10px;
+ margin: 10px;
+ transition: transform 0.2s;
+ margin: 2px;
+ }
+
+ .memberView-closeButton {
+ position: absolute;
+ right: 1em;
+ top: 1em;
+ cursor: pointer;
+ z-index: 1000;
+ }
+
+ .editing-header {
+ margin-bottom: 5;
+
+ .group-buttons {
+ display: flex;
+ margin-top: 5;
+
+ .add-member-dropdown {
+ width: 100%;
+ margin: 0 5;
+ }
+ }
+ }
+
+ .editing-contents {
+ overflow-y: auto;
+ // max-height: 67%;
+ height: 67%;
+ width: 100%;
+
+ .editing-row {
+ display: flex;
+ align-items: center;
+ // border: 1px solid;
+ // border-radius: 10px;
+
+ .user-email {
+ // position: relative;
+ min-width: 65%;
+ word-break: break-all;
+ padding: 0 5;
+ }
+ }
+ }
+
+
+} \ No newline at end of file
diff --git a/src/client/util/GroupMemberView.tsx b/src/client/util/GroupMemberView.tsx
new file mode 100644
index 000000000..b2d75158e
--- /dev/null
+++ b/src/client/util/GroupMemberView.tsx
@@ -0,0 +1,75 @@
+import * as React from "react";
+import MainViewModal from "../views/MainViewModal";
+import { observer } from "mobx-react";
+import GroupManager, { UserOptions } from "./GroupManager";
+import { library } from "@fortawesome/fontawesome-svg-core";
+import { StrCast } from "../../fields/Types";
+import { action } from "mobx";
+import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
+import * as fa from '@fortawesome/free-solid-svg-icons';
+import Select from "react-select";
+import { Doc, Opt } from "../../fields/Doc";
+import "./GroupMemberView.scss";
+
+library.add(fa.faWindowClose);
+
+interface GroupMemberViewProps {
+ group: Doc;
+ onCloseButtonClick: () => void;
+}
+
+@observer
+export default class GroupMemberView extends React.Component<GroupMemberViewProps> {
+
+ private get editingInterface() {
+ const members: string[] = this.props.group ? JSON.parse(StrCast(this.props.group.members)) : [];
+ const options: UserOptions[] = this.props.group ? GroupManager.Instance.options.filter(option => !(JSON.parse(StrCast(this.props.group.members)) as string[]).includes(option.value)) : [];
+ return (!this.props.group ? null :
+ <div className="editing-interface">
+ <div className="editing-header">
+ <b>{this.props.group.groupName}</b>
+ <div className={"memberView-closeButton"} onClick={action(this.props.onCloseButtonClick)}>
+ <FontAwesomeIcon icon={fa.faWindowClose} size={"lg"} />
+ </div>
+
+ {GroupManager.Instance.hasEditAccess(this.props.group) ?
+ <div className="group-buttons">
+ <div className="add-member-dropdown">
+ <Select
+ isSearchable={true}
+ options={options}
+ onChange={selectedOption => GroupManager.Instance.addMemberToGroup(this.props.group, (selectedOption as UserOptions).value)}
+ placeholder={"Add members"}
+ value={null}
+ closeMenuOnSelect={true}
+ />
+ </div>
+ <button onClick={() => GroupManager.Instance.deleteGroup(this.props.group)}>Delete group</button>
+ </div> :
+ null}
+ </div>
+ <div className="editing-contents">
+ {members.map(member => (
+ <div className="editing-row">
+ <div className="user-email">
+ {member}
+ </div>
+ {GroupManager.Instance.hasEditAccess(this.props.group) ? <button onClick={() => GroupManager.Instance.removeMemberFromGroup(this.props.group, member)}> Remove </button> : null}
+ </div>
+ ))}
+ </div>
+ </div>
+ );
+
+ }
+
+ render() {
+ return <MainViewModal
+ isDisplayed={true}
+ interactive={true}
+ contents={this.editingInterface}
+ />;
+ }
+
+
+} \ No newline at end of file
diff --git a/src/client/util/LinkManager.ts b/src/client/util/LinkManager.ts
index 0aec81ab0..9b4dc2630 100644
--- a/src/client/util/LinkManager.ts
+++ b/src/client/util/LinkManager.ts
@@ -41,24 +41,17 @@ export class LinkManager {
}
public addLink(linkDoc: Doc): boolean {
- const linkList = LinkManager.Instance.getAllLinks();
- linkList.push(linkDoc);
if (LinkManager.Instance.LinkManagerDoc) {
- LinkManager.Instance.LinkManagerDoc.data = new List<Doc>(linkList);
+ Doc.AddDocToList(LinkManager.Instance.LinkManagerDoc, "data", linkDoc);
return true;
}
return false;
}
public deleteLink(linkDoc: Doc): boolean {
- const linkList = LinkManager.Instance.getAllLinks();
- const index = LinkManager.Instance.getAllLinks().indexOf(linkDoc);
- if (index > -1) {
- linkList.splice(index, 1);
- if (LinkManager.Instance.LinkManagerDoc) {
- LinkManager.Instance.LinkManagerDoc.data = new List<Doc>(linkList);
- return true;
- }
+ if (LinkManager.Instance.LinkManagerDoc) {
+ Doc.RemoveDocFromList(LinkManager.Instance.LinkManagerDoc, "data", linkDoc);
+ return true;
}
return false;
}
diff --git a/src/client/util/SearchUtil.ts b/src/client/util/SearchUtil.ts
index 5679c0a14..1ac68480e 100644
--- a/src/client/util/SearchUtil.ts
+++ b/src/client/util/SearchUtil.ts
@@ -74,7 +74,7 @@ export namespace SearchUtil {
const docs = ids.map((id: string) => docMap[id]).map(doc => doc as Doc);
for (let i = 0; i < ids.length; i++) {
const testDoc = docs[i];
- if (testDoc instanceof Doc && testDoc.type !== DocumentType.KVP && (options.allowAliases || theDocs.findIndex(d => Doc.AreProtosEqual(d, testDoc)) === -1)) {
+ if (testDoc instanceof Doc && testDoc.type !== DocumentType.KVP && (options.allowAliases || testDoc.proto === undefined || theDocs.findIndex(d => Doc.AreProtosEqual(d, testDoc)) === -1)) {
theDocs.push(testDoc);
theLines.push([]);
}
diff --git a/src/client/util/SettingsManager.scss b/src/client/util/SettingsManager.scss
index 6513cb223..fa2609ca2 100644
--- a/src/client/util/SettingsManager.scss
+++ b/src/client/util/SettingsManager.scss
@@ -41,6 +41,7 @@
position: absolute;
right: 1em;
top: 1em;
+ cursor: pointer;
}
.settings-heading {
diff --git a/src/client/util/SharingManager.scss b/src/client/util/SharingManager.scss
index dec9f751a..fcbc05f8a 100644
--- a/src/client/util/SharingManager.scss
+++ b/src/client/util/SharingManager.scss
@@ -1,13 +1,75 @@
+@import "../views/globalCssVariables";
+
.sharing-interface {
display: flex;
flex-direction: column;
+ width: 730px;
+
+ .dialogue-box {
+ width: 450;
+ height: 300;
+ }
+
+ .overlay {
+ transform: translate(-20px, -20px);
+ }
+
+ .sharing-contents {
+ display: flex;
+
+ button {
+ background: $darker-alt-accent;
+ outline: none;
+ border-radius: 5px;
+ border: 0px;
+ color: #fcfbf7;
+ text-transform: uppercase;
+ letter-spacing: 2px;
+ font-size: 75%;
+ padding: 0 10;
+ margin: 0 5;
+ transition: transform 0.2s;
+ height: 25;
+ }
+
+ .individual-container,
+ .group-container {
+ width: 50%;
+
+ .share-groups,
+ .share-individual {
+ margin-top: 20px;
+ margin-bottom: 20px;
+ }
+
+ .groups-list,
+ .users-list {
+ font-style: italic;
+ background: white;
+ border: 1px solid black;
+ padding-left: 10px;
+ padding-right: 10px;
+ overflow-y: scroll;
+ overflow-x: hidden;
+ text-align: left;
+ display: flex;
+ align-content: center;
+ align-items: center;
+ text-align: center;
+ justify-content: center;
+ color: red;
+ height: 150px;
+ margin: 0 2;
+ }
+ }
+ }
.focus-span {
text-decoration: underline;
}
p {
- font-size: 20px;
+ font-size: 15px;
text-align: left;
font-style: italic;
padding: 0;
@@ -36,33 +98,10 @@
}
}
- .share-individual {
- margin-top: 20px;
- margin-bottom: 20px;
- }
-
- .users-list {
- font-style: italic;
- background: white;
- border: 1px solid black;
- padding-left: 10px;
- padding-right: 10px;
- max-height: 200px;
- overflow: scroll;
- height: -webkit-fill-available;
- text-align: left;
- display: flex;
- align-content: center;
- align-items: center;
- text-align: center;
- justify-content: center;
- color: red;
- }
-
.container {
- display: block;
+ display: flex;
position: relative;
- margin-top: 10px;
+ margin-top: 5px;
margin-bottom: 10px;
font-size: 22px;
-webkit-user-select: none;
@@ -74,18 +113,27 @@
max-width: 700px;
text-align: left;
font-style: normal;
- font-size: 15;
+ font-size: 14;
font-weight: normal;
padding: 0;
+ align-items: baseline;
.padding {
- padding: 0 0 0 20px;
+ padding: 0 10px 0 0;
color: black;
}
.permissions-dropdown {
outline: none;
+ height: 25;
}
+
+ .edit-actions {
+ display: flex;
+ position: absolute;
+ right: 51.5%;
+ }
+
}
.no-users {
diff --git a/src/client/util/SharingManager.tsx b/src/client/util/SharingManager.tsx
index dc67145fc..127ee33ce 100644
--- a/src/client/util/SharingManager.tsx
+++ b/src/client/util/SharingManager.tsx
@@ -17,6 +17,8 @@ import { SelectionManager } from "./SelectionManager";
import { DocumentManager } from "./DocumentManager";
import { CollectionView } from "../views/collections/CollectionView";
import { DictationOverlay } from "../views/DictationOverlay";
+import GroupManager from "./GroupManager";
+import GroupMemberView from "./GroupMemberView";
library.add(fa.faCopy);
@@ -28,17 +30,30 @@ export interface User {
export enum SharingPermissions {
None = "Not Shared",
View = "Can View",
- Comment = "Can Comment",
+ Add = "Can Add",
Edit = "Can Edit"
}
const ColorMapping = new Map<string, string>([
[SharingPermissions.None, "red"],
[SharingPermissions.View, "maroon"],
- [SharingPermissions.Comment, "blue"],
+ [SharingPermissions.Add, "blue"],
[SharingPermissions.Edit, "green"]
]);
+const HierarchyMapping = new Map<string, string>([
+ [SharingPermissions.None, "0"],
+ [SharingPermissions.View, "1"],
+ [SharingPermissions.Add, "2"],
+ [SharingPermissions.Edit, "3"],
+
+ ["0", SharingPermissions.None],
+ ["1", SharingPermissions.View],
+ ["2", SharingPermissions.Add],
+ ["3", SharingPermissions.Edit]
+
+]);
+
const SharingKey = "sharingPermissions";
const PublicKey = "publicLinkPermissions";
const DefaultColor = "black";
@@ -55,11 +70,13 @@ export default class SharingManager extends React.Component<{}> {
public static Instance: SharingManager;
@observable private isOpen = false;
@observable private users: ValidatedUser[] = [];
+ @observable private groups: Doc[] = [];
@observable private targetDoc: Doc | undefined;
@observable private targetDocView: DocumentView | undefined;
@observable private copied = false;
@observable private dialogueBoxOpacity = 1;
@observable private overlayOpacity = 0.4;
+ @observable private groupToView: Opt<Doc>;
private get linkVisible() {
return this.sharingDoc ? this.sharingDoc[PublicKey] !== SharingPermissions.None : false;
@@ -76,6 +93,8 @@ export default class SharingManager extends React.Component<{}> {
this.sharingDoc = new Doc;
}
}));
+
+ runInAction(() => this.groups = GroupManager.Instance.getAllGroupsCopy());
}
public close = action(() => {
@@ -121,26 +140,71 @@ export default class SharingManager extends React.Component<{}> {
return Promise.all(evaluating);
}
- setInternalSharing = async (recipient: ValidatedUser, state: string) => {
+ setInternalGroupSharing = (group: Doc, permission: string) => {
+ const members: string[] = JSON.parse(StrCast(group.members));
+ const users: ValidatedUser[] = this.users.filter(user => members.includes(user.user.email));
+
+ const sharingDoc = this.sharingDoc!;
+ if (permission === SharingPermissions.None) {
+ const metadata = sharingDoc[StrCast(group.groupName)];
+ if (metadata) sharingDoc[StrCast(group.groupName)] = undefined;
+ }
+ else {
+ sharingDoc[StrCast(group.groupName)] = permission;
+ }
+
+ users.forEach(user => {
+ this.setInternalSharing(user, permission, group);
+ });
+ }
+
+ setInternalSharing = async (recipient: ValidatedUser, state: string, group: Opt<Doc>) => {
const { user, notificationDoc } = recipient;
const target = this.targetDoc!;
const manager = this.sharingDoc!;
const key = user.userDocumentId;
- if (state === SharingPermissions.None) {
- const metadata = (await DocCastAsync(manager[key]));
- if (metadata) {
- const sharedAlias = (await DocCastAsync(metadata.sharedAlias))!;
- Doc.RemoveDocFromList(notificationDoc, storage, sharedAlias);
- manager[key] = undefined;
- }
- } else {
- const sharedAlias = Doc.MakeAlias(target);
- Doc.AddDocToList(notificationDoc, storage, sharedAlias);
- const metadata = new Doc;
- metadata.permissions = state;
- metadata.sharedAlias = sharedAlias;
- manager[key] = metadata;
+
+ let metadata = await DocCastAsync(manager[key]);
+ const permissions: { [key: string]: number } = metadata?.permissions ? JSON.parse(StrCast(metadata.permissions)) : {};
+ permissions[StrCast(group ? group.groupName : Doc.CurrentUserEmail)] = parseInt(HierarchyMapping.get(state)!);
+ const max = Math.max(...Object.values(permissions));
+
+ // let max = 0;
+ // const keys: string[] = [];
+ // for (const [key, value] of Object.entries(permissions)) {
+ // if (value === max && max !== 0) {
+ // keys.push(key);
+ // }
+ // else if (value > max) {
+ // keys.splice(0, keys.length);
+ // keys.push(key);
+ // max = value;
+ // }
+ // }
+
+ switch (max) {
+ case 0:
+ if (metadata) {
+ const sharedAlias = (await DocCastAsync(metadata.sharedAlias))!;
+ Doc.RemoveDocFromList(notificationDoc, storage, sharedAlias);
+ manager[key] = undefined;
+ }
+ break;
+
+ case 1: case 2: case 3:
+ if (!metadata) {
+ metadata = new Doc;
+ const sharedAlias = Doc.MakeAlias(target);
+ Doc.AddDocToList(notificationDoc, storage, sharedAlias);
+ metadata.sharedAlias = sharedAlias;
+ manager[key] = metadata;
+ }
+ metadata.permissions = JSON.stringify(permissions);
+ // metadata.usersShared = JSON.stringify(keys);
+ break;
}
+
+ if (metadata) metadata.maxPermission = HierarchyMapping.get(`${max}`);
}
private setExternalSharing = (state: string) => {
@@ -211,17 +275,27 @@ export default class SharingManager extends React.Component<{}> {
if (!sharingDoc) {
return SharingPermissions.None;
}
- const metadata = sharingDoc[userKey] as Doc;
+ const metadata = sharingDoc[userKey] as Doc | string;
if (!metadata) {
return SharingPermissions.None;
}
- return StrCast(metadata.permissions, SharingPermissions.None);
+ return StrCast(metadata instanceof Doc ? metadata.maxPermission : metadata, SharingPermissions.None);
}
private get sharingInterface() {
const existOtherUsers = this.users.length > 0;
+ const existGroups = this.groups.length > 0;
+
+ // const manager = this.sharingDoc!;
+
return (
<div className={"sharing-interface"}>
+ {this.groupToView ?
+ <GroupMemberView
+ group={this.groupToView}
+ onCloseButtonClick={action(() => this.groupToView = undefined)}
+ /> :
+ null}
<p className={"share-link"}>Manage the public link to {this.focusOn("this document...")}</p>
{!this.linkVisible ? (null) :
<div className={"link-container"}>
@@ -252,31 +326,77 @@ export default class SharingManager extends React.Component<{}> {
</select>
</div>
<div className={"hr-substitute"} />
- <p className={"share-individual"}>Privately share {this.focusOn("this document")} with an individual...</p>
- <div className={"users-list"} style={{ display: existOtherUsers ? "block" : "flex", minHeight: existOtherUsers ? undefined : 200 }}>
- {!existOtherUsers ? "There are no other users in your database." :
- this.users.map(({ user, notificationDoc }) => {
- const userKey = user.userDocumentId;
- const permissions = this.computePermissions(userKey);
- const color = ColorMapping.get(permissions);
- return (
- <div
- key={userKey}
- className={"container"}
- >
- <select
- className={"permissions-dropdown"}
- value={permissions}
- style={{ color, borderColor: color }}
- onChange={e => this.setInternalSharing({ user, notificationDoc }, e.currentTarget.value)}
- >
- {this.sharingOptions}
- </select>
- <span className={"padding"}>{user.email}</span>
- </div>
- );
- })
- }
+ <div className="sharing-contents">
+ <div className={"individual-container"}>
+ <p className={"share-individual"}>Privately share {this.focusOn("this document")} with an individual...</p>
+ <div className={"users-list"} style={{ display: existOtherUsers ? "block" : "flex", minHeight: existOtherUsers ? undefined : 150 }}>{/*200*/}
+ {!existOtherUsers ? "There are no other users in your database." :
+ this.users.map(({ user, notificationDoc }) => { // can't use async here
+ const userKey = user.userDocumentId;
+ const permissions = this.computePermissions(userKey);
+ const color = ColorMapping.get(permissions);
+
+ // console.log(manager);
+ // const metadata = manager[userKey] as Doc;
+ // const usersShared = StrCast(metadata?.usersShared, "");
+ // console.log(usersShared)
+
+
+ return (
+ <div
+ key={userKey}
+ className={"container"}
+ >
+ <span className={"padding"}>{user.email}</span>
+ {/* <div className={"shared-by"}>{usersShared}</div> */}
+ <div className="edit-actions">
+ <select
+ className={"permissions-dropdown"}
+ value={permissions}
+ style={{ color, borderColor: color }}
+ onChange={e => this.setInternalSharing({ user, notificationDoc }, e.currentTarget.value, undefined)}
+ >
+ {this.sharingOptions}
+ </select>
+ </div>
+ </div>
+ );
+ })
+ }
+ </div>
+ </div>
+ <div className={"group-container"}>
+ <p className={"share-groups"}>Privately share {this.focusOn("this document")} with a group...</p>
+ <div className={"groups-list"} style={{ display: existGroups ? "block" : "flex", minHeight: existOtherUsers ? undefined : 150 }}>{/*200*/}
+ {!existGroups ? "There are no groups in your database." :
+ this.groups.map(group => {
+ const permissions = this.computePermissions(StrCast(group.groupName));
+ const color = ColorMapping.get(permissions);
+ return (
+ <div
+ key={StrCast(group.groupName)}
+ className={"container"}
+ >
+ <span className={"padding"}>{group.groupName}</span>
+ <div className="edit-actions">
+ <select
+ className={"permissions-dropdown"}
+ value={permissions}
+ style={{ color, borderColor: color }}
+ onChange={e => this.setInternalGroupSharing(group, e.currentTarget.value)}
+ >
+ {this.sharingOptions}
+ </select>
+ <button onClick={action(() => this.groupToView = group)}>Edit</button>
+ </div>
+ </div>
+ );
+ })
+
+ }
+
+ </div>
+ </div>
</div>
<div className={"close-button"} onClick={this.close}>Done</div>
</div>
@@ -284,6 +404,7 @@ export default class SharingManager extends React.Component<{}> {
}
render() {
+ // console.log(this.sharingDoc);
return (
<MainViewModal
contents={this.sharingInterface}
diff --git a/src/client/views/MainView.scss b/src/client/views/MainView.scss
index e84969565..5b142ffda 100644
--- a/src/client/views/MainView.scss
+++ b/src/client/views/MainView.scss
@@ -28,10 +28,11 @@
left: 0;
width: 100%;
height: 100%;
- pointer-events:none;
+ pointer-events: none;
}
-.mainView-container, .mainView-container-dark {
+.mainView-container,
+.mainView-container-dark {
width: 100%;
height: 100%;
position: absolute;
@@ -40,40 +41,50 @@
left: 0;
z-index: 1;
touch-action: none;
+
.searchBox-container {
background: lightgray;
}
}
.mainView-container {
- color:dimgray;
+ color: dimgray;
+
.lm_title {
background: #cacaca;
- color:black;
+ color: black;
}
}
.mainView-container-dark {
color: lightgray;
+
.lm_goldenlayout {
background: dimgray;
}
+
.lm_title {
background: black;
- color:unset;
+ color: unset;
}
+
.marquee {
border-color: white;
}
+
#search-input {
background: lightgray;
}
- .searchBox-container {
- background: rgb(45,45,45);
+
+ .searchBox-container {
+ background: rgb(45, 45, 45);
}
- .contextMenu-cont, .contextMenu-item {
+
+ .contextMenu-cont,
+ .contextMenu-item {
background: dimGray;
}
+
.contextMenu-item:hover {
background: gray;
}
@@ -108,20 +119,27 @@
overflow: hidden;
}
+.buttonContainer {
-.mainView-settings {
position: absolute;
- left: 0;
bottom: 0;
- border-radius: 25%;
- margin-left: -5px;
- background: darkblue;
-}
-.mainView-settings:hover {
- transform: none !important;
+ .mainView-settings {
+ // position: absolute;
+ // left: 0;
+ // bottom: 0;
+ border-radius: 25%;
+ margin-left: -5px;
+ background: darkblue;
+ }
+
+ .mainView-settings:hover {
+ transform: none !important;
+ }
}
+
+
.mainView-logout {
position: absolute;
right: 0;
diff --git a/src/client/views/MainView.tsx b/src/client/views/MainView.tsx
index 8f5a31b6c..200486279 100644
--- a/src/client/views/MainView.tsx
+++ b/src/client/views/MainView.tsx
@@ -30,6 +30,7 @@ import { HistoryUtil } from '../util/History';
import RichTextMenu from './nodes/formattedText/RichTextMenu';
import { Scripting } from '../util/Scripting';
import SettingsManager from '../util/SettingsManager';
+import GroupManager from '../util/GroupManager';
import SharingManager from '../util/SharingManager';
import { Transform } from '../util/Transform';
import { CollectionDockingView } from './collections/CollectionDockingView';
@@ -382,7 +383,8 @@ export class MainView extends React.Component {
doc.dockingConfig ? this.openWorkspace(doc) :
CollectionDockingView.AddRightSplit(doc, libraryPath);
}
- mainContainerXf = () => new Transform(0, -this._buttonBarHeight, 1);
+ sidebarScreenToLocal = () => new Transform(0, RichTextMenu.Instance.Pinned ? -35 : 0, 1);
+ mainContainerXf = () => this.sidebarScreenToLocal().translate(0, -this._buttonBarHeight);
@computed get flyout() {
const sidebarContent = this.userDoc?.["tabs-panelContainer"];
@@ -401,7 +403,7 @@ export class MainView extends React.Component {
pinToPres={emptyFunction}
removeDocument={undefined}
onClick={undefined}
- ScreenToLocalTransform={Transform.Identity}
+ ScreenToLocalTransform={this.sidebarScreenToLocal}
ContentScaling={returnOne}
NativeHeight={returnZero}
NativeWidth={returnZero}
@@ -443,9 +445,14 @@ export class MainView extends React.Component {
docFilters={returnEmptyFilter}
ContainingCollectionView={undefined}
ContainingCollectionDoc={undefined} />
- <button className="mainView-settings" key="settings" onClick={() => SettingsManager.Instance.open()}>
- <FontAwesomeIcon icon="cog" size="lg" />
- </button>
+ <div className="buttonContainer" >
+ <button className="mainView-settings" key="settings" onClick={() => SettingsManager.Instance.open()}>
+ <FontAwesomeIcon icon="cog" size="lg" />
+ </button>
+ <button className="mainView-settings" key="groups" onClick={() => GroupManager.Instance.open()}>
+ <FontAwesomeIcon icon="columns" size="lg" />
+ </button>
+ </div>
</div>
{this.docButtons}
</div>;
@@ -591,6 +598,7 @@ export class MainView extends React.Component {
<DictationOverlay />
<SharingManager />
<SettingsManager />
+ <GroupManager />
<GoogleAuthenticationManager />
<DocumentDecorations />
<GestureOverlay>
diff --git a/src/client/views/collections/CollectionStackingViewFieldColumn.tsx b/src/client/views/collections/CollectionStackingViewFieldColumn.tsx
index b147b089b..2f4a25bfe 100644
--- a/src/client/views/collections/CollectionStackingViewFieldColumn.tsx
+++ b/src/client/views/collections/CollectionStackingViewFieldColumn.tsx
@@ -362,7 +362,7 @@ export class CollectionStackingViewFieldColumn extends React.Component<CSVFieldC
{this.props.parent.Document._columnsHideIfEmpty ? (null) : headingView}
{
this.collapsed ? (null) :
- <div>
+ <div style={{ marginTop: 5 }}>
<div key={`${heading}-stack`} className={`collectionStackingView-masonry${singleColumn ? "Single" : "Grid"}`}
style={{
padding: singleColumn ? `${columnYMargin}px ${0}px ${style.yMargin}px ${0}px` : `${columnYMargin}px ${0}px`,
diff --git a/src/client/views/collections/CollectionSubView.tsx b/src/client/views/collections/CollectionSubView.tsx
index 49480e759..d107db86b 100644
--- a/src/client/views/collections/CollectionSubView.tsx
+++ b/src/client/views/collections/CollectionSubView.tsx
@@ -1,13 +1,13 @@
import { action, computed, IReactionDisposer, reaction } from "mobx";
import { basename } from 'path';
import CursorField from "../../../fields/CursorField";
-import { Doc, Opt } from "../../../fields/Doc";
+import { Doc, Opt, Field } from "../../../fields/Doc";
import { Id } from "../../../fields/FieldSymbols";
import { List } from "../../../fields/List";
import { listSpec } from "../../../fields/Schema";
import { ScriptField } from "../../../fields/ScriptField";
import { WebField } from "../../../fields/URLField";
-import { Cast, ScriptCast, NumCast } from "../../../fields/Types";
+import { Cast, ScriptCast, NumCast, StrCast } from "../../../fields/Types";
import { GestureUtils } from "../../../pen-gestures/GestureUtils";
import { Upload } from "../../../server/SharedMediaTypes";
import { Utils, returnFalse, returnEmptyFilter } from "../../../Utils";
@@ -136,8 +136,12 @@ export function CollectionSubView<T, X>(schemaCtor: (doc: Doc) => T, moreProps?:
const filteredDocs = docFilters.length && !this.props.dontRegisterView ? childDocs.filter(d => {
for (const facetKey of Object.keys(filterFacets)) {
const facet = filterFacets[facetKey];
- const satisfiesFacet = Object.keys(facet).some(value =>
- (facet[value] === "x") !== Doc.matchFieldValue(d, facetKey, value));
+ const satisfiesFacet = Object.keys(facet).some(value => {
+ if (facet[value] === "match") {
+ return d[facetKey] === undefined || Field.toString(d[facetKey] as Field).includes(value);
+ }
+ return (facet[value] === "x") !== Doc.matchFieldValue(d, facetKey, value);
+ });
if (!satisfiesFacet) {
return false;
}
@@ -208,7 +212,6 @@ export function CollectionSubView<T, X>(schemaCtor: (doc: Doc) => T, moreProps?:
addDocument = (doc: Doc | Doc[]) => this.props.addDocument(doc);
- @undoBatch
@action
protected onInternalDrop(e: Event, de: DragManager.DropEvent): boolean {
const docDragData = de.complete.docDragData;
@@ -355,7 +358,7 @@ export function CollectionSubView<T, X>(schemaCtor: (doc: Doc) => T, moreProps?:
}
if (text) {
- if (text.includes("www.youtube.com/watch")) {
+ if (text.includes("www.youtube.com/watch") || text.includes("www.youtube.com/embed")) {
const url = text.replace("youtube.com/watch?v=", "youtube.com/embed/").split("&")[0];
addDocument(Docs.Create.VideoDocument(url, {
...options,
@@ -473,3 +476,4 @@ import { DocumentType } from "../../documents/DocumentTypes";
import { FormattedTextBox, GoogleRef } from "../nodes/formattedText/FormattedTextBox";
import { CollectionView } from "./CollectionView";
import { SelectionManager } from "../../util/SelectionManager";
+
diff --git a/src/client/views/collections/CollectionTreeView.tsx b/src/client/views/collections/CollectionTreeView.tsx
index f6f6fb7cc..620b977fa 100644
--- a/src/client/views/collections/CollectionTreeView.tsx
+++ b/src/client/views/collections/CollectionTreeView.tsx
@@ -304,7 +304,7 @@ class TreeView extends React.Component<TreeViewProps> {
}
rtfWidth = () => Math.min(this.layoutDoc?.[WidthSym](), this.props.panelWidth() - 20);
- rtfHeight = () => this.rtfWidth() < this.layoutDoc?.[WidthSym]() ? Math.min(this.layoutDoc?.[HeightSym](), this.MAX_EMBED_HEIGHT) : this.MAX_EMBED_HEIGHT;
+ rtfHeight = () => this.rtfWidth() <= this.layoutDoc?.[WidthSym]() ? Math.min(this.layoutDoc?.[HeightSym](), this.MAX_EMBED_HEIGHT) : this.MAX_EMBED_HEIGHT;
@computed get renderContent() {
TraceMobx();
@@ -332,8 +332,8 @@ class TreeView extends React.Component<TreeViewProps> {
</div></ul>;
} else {
const layoutDoc = this.layoutDoc;
- const panelHeight = layoutDoc.type === DocumentType.RTF ? this.rtfHeight : this.docHeight;
- const panelWidth = layoutDoc.type === DocumentType.RTF ? this.rtfWidth : this.docWidth;
+ const panelHeight = StrCast(Doc.LayoutField(layoutDoc)).includes("FormattedTextBox") ? this.rtfHeight : this.docHeight;
+ const panelWidth = StrCast(Doc.LayoutField(layoutDoc)).includes("FormattedTextBox") ? this.rtfWidth : this.docWidth;
return <div ref={this._dref} style={{ display: "inline-block", height: panelHeight() }} key={this.doc[Id]}>
<ContentFittingDocumentView
Document={layoutDoc}
@@ -386,8 +386,8 @@ class TreeView extends React.Component<TreeViewProps> {
e.stopPropagation();
}
- @computed
- get renderBullet() {
+ @computed get renderBullet() {
+ TraceMobx();
const checked = this.doc.type === DocumentType.COL ? undefined : this.onCheckedClick ? (this.doc.treeViewChecked ?? "unchecked") : undefined;
return <div className="bullet"
title={this.childDocs?.length ? `click to see ${this.childDocs?.length} items` : "view fields"}
diff --git a/src/client/views/collections/CollectionView.tsx b/src/client/views/collections/CollectionView.tsx
index f2ffe7835..6acf78af7 100644
--- a/src/client/views/collections/CollectionView.tsx
+++ b/src/client/views/collections/CollectionView.tsx
@@ -47,6 +47,8 @@ import { CollectionGridView } from './collectionGrid/CollectionGridView';
import './CollectionView.scss';
import { CollectionViewBaseChrome } from './CollectionViewChromes';
import { UndoManager } from '../../util/UndoManager';
+import { RichTextField } from '../../../fields/RichTextField';
+import { TextField } from '../../util/ProsemirrorCopy/prompt';
const higflyout = require("@hig/flyout");
export const { anchorPoints } = higflyout;
export const Flyout = higflyout.default;
@@ -357,8 +359,9 @@ export class CollectionView extends Touchable<FieldViewProps & CollectionViewCus
return viewSpecScript ? docs.filter(d => viewSpecScript.script.run({ doc: d }, console.log).result) : docs;
}
@computed get _allFacets() {
- const facets = new Set<string>();
- this.childDocs.filter(child => child).forEach(child => Object.keys(Doc.GetProto(child)).forEach(key => facets.add(key)));
+ TraceMobx();
+ const facets = new Set<string>(["type", "text", "data", "author", "ACL"]);
+ this.childDocs.filter(child => child).forEach(child => child && Object.keys(Doc.GetProto(child)).forEach(key => facets.add(key)));
Doc.AreProtosEqual(this.dataDoc, this.props.Document) && this.childDocs.filter(child => child).forEach(child => Object.keys(child).forEach(key => facets.add(key)));
return Array.from(facets).filter(f => !f.startsWith("_") && !["proto", "zIndex", "isPrototype", "context", "text-noTemplate"].includes(f)).sort();
}
@@ -387,8 +390,13 @@ export class CollectionView extends Touchable<FieldViewProps & CollectionViewCus
}
} else {
const allCollectionDocs = DocListCast(this.dataDoc[this.props.fieldKey]);
- const facetValues = Array.from(allCollectionDocs.reduce((set, child) =>
- set.add(Field.toString(child[facetHeader] as Field)), new Set<string>()));
+ var rtfields = 0;
+ const facetValues = Array.from(allCollectionDocs.reduce((set, child) => {
+ const field = child[facetHeader] as Field;
+ const fieldStr = Field.toString(field);
+ if (field instanceof RichTextField || (typeof (field) === "string" && fieldStr.split(" ").length > 2)) rtfields++;
+ return set.add(fieldStr);
+ }, new Set<string>()));
let nonNumbers = 0;
let minVal = Number.MAX_VALUE, maxVal = -Number.MAX_VALUE;
@@ -402,13 +410,18 @@ export class CollectionView extends Touchable<FieldViewProps & CollectionViewCus
}
});
let newFacet: Opt<Doc>;
- if (nonNumbers / allCollectionDocs.length < .1) {
- newFacet = Docs.Create.SliderDocument({ title: facetHeader });
+ if (facetHeader === "text" || rtfields / allCollectionDocs.length > 0.1) {
+ newFacet = Docs.Create.TextDocument("", { _width: 100, _height: 25, treeViewExpandedView: "layout", title: facetHeader, treeViewOpen: true, forceActive: true, ignoreClick: true });
+ Doc.GetProto(newFacet).type = DocumentType.COL; // forces item to show an open/close button instead ofa checkbox
+ newFacet.target = this.props.Document;
+ newFacet._textBoxPadding = 4;
+ const scriptText = `setDocFilter(this.target, "${facetHeader}", text, "match")`;
+ newFacet.onTextChanged = ScriptField.MakeScript(scriptText, { this: Doc.name, text: "string" });
+ } else if (nonNumbers / facetValues.length < .1) {
+ newFacet = Docs.Create.SliderDocument({ title: facetHeader, treeViewExpandedView: "layout", treeViewOpen: true });
const newFacetField = Doc.LayoutFieldKey(newFacet);
const ranged = Doc.readDocRangeFilter(this.props.Document, facetHeader);
Doc.GetProto(newFacet).type = DocumentType.COL; // forces item to show an open/close button instead ofa checkbox
- newFacet.treeViewExpandedView = "layout";
- newFacet.treeViewOpen = true;
const extendedMinVal = minVal - Math.min(1, Math.abs(maxVal - minVal) * .05);
const extendedMaxVal = maxVal + Math.min(1, Math.abs(maxVal - minVal) * .05);
newFacet[newFacetField + "-min"] = ranged === undefined ? extendedMinVal : ranged[0];
@@ -418,7 +431,6 @@ export class CollectionView extends Touchable<FieldViewProps & CollectionViewCus
newFacet.target = this.props.Document;
const scriptText = `setDocFilterRange(this.target, "${facetHeader}", range)`;
newFacet.onThumbChanged = ScriptField.MakeScript(scriptText, { this: Doc.name, range: "number" });
-
Doc.AddDocToList(facetCollection, this.props.fieldKey + "-filter", newFacet);
} else {
newFacet = new Doc();
@@ -445,6 +457,7 @@ export class CollectionView extends Touchable<FieldViewProps & CollectionViewCus
return ScriptField.MakeScript(scriptText, { this: Doc.name, heading: "string", checked: "string", containingTreeView: Doc.name });
}
@computed get filterView() {
+ TraceMobx();
const facetCollection = this.props.Document;
const flyout = (
<div className="collectionTimeView-flyout" style={{ width: `${this.facetWidth()}`, height: this.props.PanelHeight() - 30 }} onWheel={e => e.stopPropagation()}>
diff --git a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
index ba20e9830..546a4307c 100644
--- a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
+++ b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
@@ -194,7 +194,6 @@ export class CollectionFreeFormView extends CollectionSubView<PanZoomDocument, P
return (pt => super.onExternalDrop(e, { x: pt[0], y: pt[1] }))(this.getTransform().transformPoint(e.pageX, e.pageY));
}
- @undoBatch
@action
internalDocDrop(e: Event, de: DragManager.DropEvent, docDragData: DragManager.DocumentDragData, xp: number, yp: number) {
if (!super.onInternalDrop(e, de)) return false;
diff --git a/src/client/views/nodes/DocumentView.tsx b/src/client/views/nodes/DocumentView.tsx
index 3a3bef2e0..21b6d8310 100644
--- a/src/client/views/nodes/DocumentView.tsx
+++ b/src/client/views/nodes/DocumentView.tsx
@@ -689,7 +689,7 @@ export class DocumentView extends DocComponent<DocumentViewProps, Document>(Docu
@undoBatch
@action
- setAcl = (acl: "readOnly" | "addOnly" | "ownerOnly") => {
+ setAcl = (acl: "readOnly" | "addOnly" | "ownerOnly" | "write") => {
this.dataDoc.ACL = this.props.Document.ACL = acl;
DocListCast(this.dataDoc[Doc.LayoutFieldKey(this.dataDoc)]).map(d => {
if (d.author === Doc.CurrentUserEmail) d.ACL = acl;
@@ -699,7 +699,7 @@ export class DocumentView extends DocComponent<DocumentViewProps, Document>(Docu
}
@undoBatch
@action
- testAcl = (acl: "readOnly" | "addOnly" | "ownerOnly") => {
+ testAcl = (acl: "readOnly" | "addOnly" | "ownerOnly" | "write") => {
this.dataDoc.author = this.props.Document.author = "ADMIN";
this.dataDoc.ACL = this.props.Document.ACL = acl;
DocListCast(this.dataDoc[Doc.LayoutFieldKey(this.dataDoc)]).map(d => {
@@ -811,6 +811,7 @@ export class DocumentView extends DocComponent<DocumentViewProps, Document>(Docu
aclItems.push({ description: "Make Add Only", event: () => this.setAcl("addOnly"), icon: "concierge-bell" });
aclItems.push({ description: "Make Read Only", event: () => this.setAcl("readOnly"), icon: "concierge-bell" });
aclItems.push({ description: "Make Private", event: () => this.setAcl("ownerOnly"), icon: "concierge-bell" });
+ aclItems.push({ description: "Make Editable", event: () => this.setAcl("write"), icon: "concierge-bell" });
aclItems.push({ description: "Test Private", event: () => this.testAcl("ownerOnly"), icon: "concierge-bell" });
aclItems.push({ description: "Test Readonly", event: () => this.testAcl("readOnly"), icon: "concierge-bell" });
!existingAcls && cm.addItem({ description: "Privacy...", subitems: aclItems, icon: "question" });
diff --git a/src/client/views/nodes/VideoBox.tsx b/src/client/views/nodes/VideoBox.tsx
index 71556bfd3..a5c6c4a48 100644
--- a/src/client/views/nodes/VideoBox.tsx
+++ b/src/client/views/nodes/VideoBox.tsx
@@ -19,6 +19,7 @@ import { FieldView, FieldViewProps } from './FieldView';
import "./VideoBox.scss";
import { documentSchema } from "../../../fields/documentSchemas";
import { Networking } from "../../Network";
+import { SnappingManager } from "../../util/SnappingManager";
const path = require('path');
export const timeSchema = createSchema({
@@ -58,21 +59,21 @@ export class VideoBox extends ViewBoxAnnotatableComponent<FieldViewProps, VideoD
@action public Play = (update: boolean = true) => {
this._playing = true;
- update && this.player && this.player.play();
- update && this._youtubePlayer && this._youtubePlayer.playVideo();
+ update && this.player?.play();
+ update && this._youtubePlayer?.playVideo();
this._youtubePlayer && !this._playTimer && (this._playTimer = setInterval(this.updateTimecode, 5));
this.updateTimecode();
}
@action public Seek(time: number) {
- this._youtubePlayer && this._youtubePlayer.seekTo(Math.round(time), true);
+ this._youtubePlayer?.seekTo(Math.round(time), true);
this.player && (this.player.currentTime = time);
}
@action public Pause = (update: boolean = true) => {
this._playing = false;
- update && this.player && this.player.pause();
- update && this._youtubePlayer && this._youtubePlayer.pauseVideo && this._youtubePlayer.pauseVideo();
+ update && this.player?.pause();
+ update && this._youtubePlayer?.pauseVideo();
this._youtubePlayer && this._playTimer && clearInterval(this._playTimer);
this._playTimer = undefined;
this.updateTimecode();
@@ -261,21 +262,20 @@ export class VideoBox extends ViewBoxAnnotatableComponent<FieldViewProps, VideoD
const onYoutubePlayerStateChange = (event: any) => runInAction(() => {
if (started && event.data === YT.PlayerState.PLAYING) {
started = false;
- this._youtubePlayer && this._youtubePlayer.unMute();
- this.Pause();
+ this._youtubePlayer?.unMute();
+ //this.Pause();
return;
}
if (event.data === YT.PlayerState.PLAYING && !this._playing) this.Play(false);
if (event.data === YT.PlayerState.PAUSED && this._playing) this.Pause(false);
});
const onYoutubePlayerReady = (event: any) => {
- this._reactionDisposer && this._reactionDisposer();
- this._youtubeReactionDisposer && this._youtubeReactionDisposer();
+ this._reactionDisposer?.();
+ this._youtubeReactionDisposer?.();
this._reactionDisposer = reaction(() => this.layoutDoc.currentTimecode, () => !this._playing && this.Seek((this.layoutDoc.currentTimecode || 0)));
- this._youtubeReactionDisposer = reaction(() => [this.props.isSelected(), DocumentDecorations.Instance.Interacting, Doc.GetSelectedTool()], () => {
- const interactive = Doc.GetSelectedTool() === InkTool.None && this.props.isSelected(true) && !DocumentDecorations.Instance.Interacting;
- iframe.style.pointerEvents = interactive ? "all" : "none";
- }, { fireImmediately: true });
+ this._youtubeReactionDisposer = reaction(
+ () => Doc.GetSelectedTool() === InkTool.None && this.props.isSelected(true) && !SnappingManager.GetIsDragging() && !DocumentDecorations.Instance.Interacting,
+ (interactive) => iframe.style.pointerEvents = interactive ? "all" : "none", { fireImmediately: true });
};
this._youtubePlayer = new YT.Player(`${this.youtubeVideoId + this._youtubeIframeId}-player`, {
events: {
@@ -346,7 +346,7 @@ export class VideoBox extends ViewBoxAnnotatableComponent<FieldViewProps, VideoD
const start = untracked(() => Math.round((this.layoutDoc.currentTimecode || 0)));
return <iframe key={this._youtubeIframeId} id={`${this.youtubeVideoId + this._youtubeIframeId}-player`}
onLoad={this.youtubeIframeLoaded} className={`${style}`} width={(this.layoutDoc._nativeWidth || 640)} height={(this.layoutDoc._nativeHeight || 390)}
- src={`https://www.youtube.com/embed/${this.youtubeVideoId}?enablejsapi=1&rel=0&showinfo=1&autoplay=1&mute=1&start=${start}&modestbranding=1&controls=${VideoBox._showControls ? 1 : 0}`} />;
+ src={`https://www.youtube.com/embed/${this.youtubeVideoId}?enablejsapi=1&rel=0&showinfo=1&autoplay=0&mute=1&start=${start}&modestbranding=1&controls=${VideoBox._showControls ? 1 : 0}`} />;
}
@action.bound
diff --git a/src/client/views/nodes/formattedText/FormattedTextBox.tsx b/src/client/views/nodes/formattedText/FormattedTextBox.tsx
index 90f379525..2cb55e0fa 100644
--- a/src/client/views/nodes/formattedText/FormattedTextBox.tsx
+++ b/src/client/views/nodes/formattedText/FormattedTextBox.tsx
@@ -22,7 +22,7 @@ import { PrefetchProxy } from '../../../../fields/Proxy';
import { RichTextField } from "../../../../fields/RichTextField";
import { RichTextUtils } from '../../../../fields/RichTextUtils';
import { createSchema, makeInterface } from "../../../../fields/Schema";
-import { Cast, DateCast, NumCast, StrCast } from "../../../../fields/Types";
+import { Cast, DateCast, NumCast, StrCast, ScriptCast } from "../../../../fields/Types";
import { TraceMobx, OVERRIDE_ACL } from '../../../../fields/util';
import { addStyleSheet, addStyleSheetRule, clearStyleSheetRules, emptyFunction, numberRange, returnOne, returnZero, Utils, setupMoveUpEvents } from '../../../../Utils';
import { GoogleApiClientUtils, Pulls, Pushes } from '../../../apis/google_docs/GoogleApiClientUtils';
@@ -203,13 +203,14 @@ export class FormattedTextBox extends ViewBoxAnnotatableComponent<(FieldViewProp
if (!this.dataDoc[AclSym]) {
if (!this._applyingChange && json.replace(/"selection":.*/, "") !== curProto?.Data.replace(/"selection":.*/, "")) {
this._applyingChange = true;
- this.dataDoc[this.props.fieldKey + "-lastModified"] = new DateField(new Date(Date.now()));
+ (curText !== Cast(this.dataDoc[this.fieldKey], RichTextField)?.Text) && (this.dataDoc[this.props.fieldKey + "-lastModified"] = new DateField(new Date(Date.now())));
if ((!curTemp && !curProto) || curText || curLayout?.Data.includes("dash")) { // if no template, or there's text that didn't come from the layout template, write it to the document. (if this is driven by a template, then this overwrites the template text which is intended)
if (json !== curLayout?.Data) {
!curText && tx.storedMarks?.map(m => m.type.name === "pFontSize" && (Doc.UserDoc().fontSize = this.layoutDoc._fontSize = m.attrs.fontSize));
!curText && tx.storedMarks?.map(m => m.type.name === "pFontFamily" && (Doc.UserDoc().fontFamily = this.layoutDoc._fontFamily = m.attrs.fontFamily));
this.dataDoc[this.props.fieldKey] = new RichTextField(json, curText);
this.dataDoc[this.props.fieldKey + "-noTemplate"] = (curTemp?.Text || "") !== curText; // mark the data field as being split from the template if it has been edited
+ ScriptCast(this.layoutDoc.onTextChanged, null)?.script.run({ this: this.layoutDoc, self: this.rootDoc, text: curText });
}
} else { // if we've deleted all the text in a note driven by a template, then restore the template data
this.dataDoc[this.props.fieldKey] = undefined;
@@ -970,7 +971,9 @@ export class FormattedTextBox extends ViewBoxAnnotatableComponent<(FieldViewProp
}
(selectOnLoad /* || !rtfField?.Text*/) && this._editorView!.focus();
// add user mark for any first character that was typed since the user mark that gets set in KeyPress won't have been called yet.
- this._editorView!.state.storedMarks = [...(this._editorView!.state.storedMarks ? this._editorView!.state.storedMarks : []), schema.marks.user_mark.create({ userid: Doc.CurrentUserEmail, modified: Math.floor(Date.now() / 1000) })];
+ if (!this._editorView!.state.storedMarks || !this._editorView!.state.storedMarks.some(mark => mark.type === schema.marks.user_mark)) {
+ this._editorView!.state.storedMarks = [...(this._editorView!.state.storedMarks ? this._editorView!.state.storedMarks : []), schema.marks.user_mark.create({ userid: Doc.CurrentUserEmail, modified: Math.floor(Date.now() / 1000) })];
+ }
}
getFont(font: string) {
switch (font) {
@@ -1305,7 +1308,7 @@ export class FormattedTextBox extends ViewBoxAnnotatableComponent<(FieldViewProp
onScroll={this.onscrolled} onDrop={this.ondrop} >
<div className={`formattedTextBox-inner${rounded}${selclass}`} ref={this.createDropTarget}
style={{
- padding: `${Math.max(0, NumCast(this.layoutDoc._yMargin, this.props.yMargin || 0) + selPad)}px ${NumCast(this.layoutDoc._xMargin, this.props.xMargin || 0) + selPad}px`,
+ padding: this.layoutDoc._textBoxPadding ? this.layoutDoc._textBoxPadding : `${Math.max(0, NumCast(this.layoutDoc._yMargin, this.props.yMargin || 0) + selPad)}px ${NumCast(this.layoutDoc._xMargin, this.props.xMargin || 0) + selPad}px`,
pointerEvents: !this.props.isSelected() ? ((this.layoutDoc.isLinkButton || this.props.onClick) ? "none" : "all") : undefined
}}
/>
diff --git a/src/client/views/nodes/formattedText/marks_rts.ts b/src/client/views/nodes/formattedText/marks_rts.ts
index b09ac0678..54b61aa20 100644
--- a/src/client/views/nodes/formattedText/marks_rts.ts
+++ b/src/client/views/nodes/formattedText/marks_rts.ts
@@ -270,6 +270,7 @@ export const marks: { [index: string]: MarkSpec } = {
userid: { default: "" },
modified: { default: "when?" }, // 1 second intervals since 1970
},
+ excludes: "user_mark",
group: "inline",
toDOM(node: any) {
const uid = node.attrs.userid.replace(".", "").replace("@", "");
diff --git a/src/fields/Doc.ts b/src/fields/Doc.ts
index dd7117594..e4d11dd4d 100644
--- a/src/fields/Doc.ts
+++ b/src/fields/Doc.ts
@@ -96,6 +96,7 @@ export const AclSym = Symbol("Acl");
export const AclPrivate = Symbol("AclOwnerOnly");
export const AclReadonly = Symbol("AclReadOnly");
export const AclAddonly = Symbol("AclAddonly");
+export const AclReadWrite = Symbol("AclReadWrite");
export const UpdatingFromServer = Symbol("UpdatingFromServer");
const CachedUpdates = Symbol("Cached updates");
@@ -113,6 +114,8 @@ export function fetchProto(doc: Doc) {
case "addOnly":
doc[AclSym] = AclAddonly;
break;
+ case "write":
+ doc[AclSym] = AclReadWrite;
}
}
@@ -942,20 +945,27 @@ export namespace Doc {
// filters document in a container collection:
// all documents with the specified value for the specified key are included/excluded
// based on the modifiers :"check", "x", undefined
- export function setDocFilter(container: Doc, key: string, value: any, modifiers?: "check" | "x" | undefined) {
+ export function setDocFilter(container: Doc, key: string, value: any, modifiers?: "match" | "check" | "x" | undefined) {
const docFilters = Cast(container._docFilters, listSpec("string"), []);
- for (let i = 0; i < docFilters.length; i += 3) {
- if (docFilters[i] === key && docFilters[i + 1] === value) {
- docFilters.splice(i, 3);
- break;
+ runInAction(() => {
+ for (let i = 0; i < docFilters.length; i += 3) {
+ if (docFilters[i] === key && (docFilters[i + 1] === value || modifiers === "match")) {
+ if (docFilters[i + 2] === modifiers && modifiers && docFilters[i + 1] === value) return;
+ docFilters.splice(i, 3);
+ break;
+ }
}
- }
- if (typeof modifiers === "string") {
- docFilters.push(key);
- docFilters.push(value);
- docFilters.push(modifiers);
- container._docFilters = new List<string>(docFilters);
- }
+ if (typeof modifiers === "string") {
+ if (!docFilters.length && modifiers === "match" && value === undefined) {
+ container._docFilters = undefined;
+ } else {
+ docFilters.push(key);
+ docFilters.push(value);
+ docFilters.push(modifiers);
+ container._docFilters = new List<string>(docFilters);
+ }
+ }
+ })
}
export function readDocRangeFilter(doc: Doc, key: string) {
const docRangeFilters = Cast(doc._docRangeFilters, listSpec("string"), []);
@@ -1165,5 +1175,5 @@ Scripting.addGlobal(function selectedDocs(container: Doc, excludeCollections: bo
(!excludeCollections || d.type !== DocumentType.COL || !Cast(d.data, listSpec(Doc), null)));
return docs.length ? new List(docs) : prevValue;
});
-Scripting.addGlobal(function setDocFilter(container: Doc, key: string, value: any, modifiers?: "check" | "x" | undefined) { Doc.setDocFilter(container, key, value, modifiers); });
+Scripting.addGlobal(function setDocFilter(container: Doc, key: string, value: any, modifiers?: "match" | "check" | "x" | undefined) { Doc.setDocFilter(container, key, value, modifiers); });
Scripting.addGlobal(function setDocFilterRange(container: Doc, key: string, range: number[]) { Doc.setDocFilterRange(container, key, range); }); \ No newline at end of file