From 1c6a3568005bb25541d45db4b53f1955ff3b0e39 Mon Sep 17 00:00:00 2001 From: usodhi <61431818+usodhi@users.noreply.github.com> Date: Thu, 11 Mar 2021 16:22:09 -0500 Subject: adding and/or to filtering, added editableview, changed a bunch of things --- src/client/documents/Documents.ts | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'src/client/documents/Documents.ts') diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts index 1726c42d3..5ceb62cbe 100644 --- a/src/client/documents/Documents.ts +++ b/src/client/documents/Documents.ts @@ -987,6 +987,13 @@ export namespace DocUtils { } return false; } + /** + * @param docs + * @param docFilters + * @param docRangeFilters + * @param viewSpecScript + * Given a list of docs and docFilters, @returns the list of Docs that match those filters + */ export function FilterDocs(docs: Doc[], docFilters: string[], docRangeFilters: string[], viewSpecScript?: ScriptField) { const childDocs = viewSpecScript ? docs.filter(d => viewSpecScript.script.run({ doc: d }, console.log).result) : docs; if (!docFilters?.length && !docRangeFilters?.length) { @@ -1011,14 +1018,19 @@ export namespace DocUtils { if (d.cookies && (!filterFacets.cookies || !Object.keys(filterFacets.cookies).some(key => d.cookies === key))) { return false; } + + console.log(FilterBox._filterBoolean); for (const facetKey of Object.keys(filterFacets).filter(fkey => fkey !== "cookies")) { const facet = filterFacets[facetKey]; + console.log(facet) const matches = Object.keys(facet).filter(value => value !== "cookies" && facet[value] === "match"); const checks = Object.keys(facet).filter(value => facet[value] === "check"); const xs = Object.keys(facet).filter(value => facet[value] === "x"); + + if (!xs.length && !checks.length && !matches.length) return true; const failsNotEqualFacets = !xs.length ? false : xs.some(value => Doc.matchFieldValue(d, facetKey, value)); const satisfiesCheckFacets = !checks.length ? true : checks.some(value => Doc.matchFieldValue(d, facetKey, value)); - const satisfiesMatchFacets = !matches.length ? true : matches.some(value => { + const satisfiesMatchFacets = matches.some(value => { if (facetKey.startsWith("*")) { // fields starting with a '*' are used to match families of related fields. ie, *lastModified will match text-lastModified, data-lastModified, etc const allKeys = Array.from(Object.keys(d)); allKeys.push(...Object.keys(Doc.GetProto(d))); @@ -1027,11 +1039,20 @@ export namespace DocUtils { } return Field.toString(d[facetKey] as Field).includes(value); }); - if (!satisfiesCheckFacets || !satisfiesMatchFacets || failsNotEqualFacets) { - return false; + console.log(satisfiesCheckFacets, failsNotEqualFacets); + if (FilterBox._filterBoolean === "OR") { + if (satisfiesCheckFacets && !failsNotEqualFacets) { + return true; + } } + else { + if (!satisfiesCheckFacets || failsNotEqualFacets) { + return false; + } + } + } - return true; + return FilterBox._filterBoolean === "OR" ? false : true; }) : childDocs; const rangeFilteredDocs = filteredDocs.filter(d => { for (let i = 0; i < docRangeFilters.length; i += 3) { -- cgit v1.2.3-70-g09d2 From 7c6ccf0c6dce1b778163f03ae271b3c17896a560 Mon Sep 17 00:00:00 2001 From: usodhi <61431818+usodhi@users.noreply.github.com> Date: Wed, 17 Mar 2021 01:30:02 -0400 Subject: starting process of addingfilter attributes to new docs in collection --- src/client/documents/Documents.ts | 25 ++++++++++++------------- src/client/views/PropertiesView.scss | 4 ++-- src/client/views/collections/CollectionView.tsx | 16 ++++++++++++++++ src/client/views/nodes/FilterBox.tsx | 10 +++++----- 4 files changed, 35 insertions(+), 20 deletions(-) (limited to 'src/client/documents/Documents.ts') diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts index 0f1abb3ac..c13a69402 100644 --- a/src/client/documents/Documents.ts +++ b/src/client/documents/Documents.ts @@ -636,9 +636,7 @@ export namespace Docs { protoProps.system = delegateProps.system; - if (!("author" in protoProps)) { - protoProps.author = Doc.CurrentUserEmail; - } + if (!("author" in protoProps)) protoProps.author = Doc.CurrentUserEmail; if (!("creationDate" in protoProps)) { protoProps.creationDate = new DateField; @@ -1019,18 +1017,22 @@ export namespace DocUtils { return false; } - console.log(FilterBox._filterBoolean); for (const facetKey of Object.keys(filterFacets).filter(fkey => fkey !== "cookies")) { const facet = filterFacets[facetKey]; - console.log(facet) + + // facets that match some value in the field of the document (e.g. some text field) const matches = Object.keys(facet).filter(value => value !== "cookies" && facet[value] === "match"); + + // facets that have a check next to them const checks = Object.keys(facet).filter(value => facet[value] === "check"); + + // facets that have an x next to them const xs = Object.keys(facet).filter(value => facet[value] === "x"); if (!xs.length && !checks.length && !matches.length) return true; const failsNotEqualFacets = !xs.length ? false : xs.some(value => Doc.matchFieldValue(d, facetKey, value)); const satisfiesCheckFacets = !checks.length ? true : checks.some(value => Doc.matchFieldValue(d, facetKey, value)); - const satisfiesMatchFacets = matches.some(value => { + const satisfiesMatchFacets = !matches.length ? true : matches.some(value => { if (facetKey.startsWith("*")) { // fields starting with a '*' are used to match families of related fields. ie, *lastModified will match text-lastModified, data-lastModified, etc const allKeys = Array.from(Object.keys(d)); allKeys.push(...Object.keys(Doc.GetProto(d))); @@ -1039,16 +1041,13 @@ export namespace DocUtils { } return Field.toString(d[facetKey] as Field).includes(value); }); - console.log(satisfiesCheckFacets, failsNotEqualFacets); + // if we're ORing them together, the default return is false, and we return true for a doc if it satisfies any one set of criteria if (FilterBox._filterBoolean === "OR") { - if (satisfiesCheckFacets && !failsNotEqualFacets) { - return true; - } + if (satisfiesCheckFacets && !failsNotEqualFacets && satisfiesMatchFacets) return true; } + // if we're ANDing them together, the default return is true, and we return false for a doc if it doesn't satisfy any set of criteria else { - if (!satisfiesCheckFacets || failsNotEqualFacets) { - return false; - } + if (!satisfiesCheckFacets || failsNotEqualFacets || (matches.length && satisfiesMatchFacets)) return false; } } diff --git a/src/client/views/PropertiesView.scss b/src/client/views/PropertiesView.scss index 1d52136de..7c6d507b8 100644 --- a/src/client/views/PropertiesView.scss +++ b/src/client/views/PropertiesView.scss @@ -191,8 +191,8 @@ font-size: 10px; padding: 10px; margin-left: 5px; - // max-height: 40%; - overflow-y: visible; + max-height: 40%; + overflow-y: scroll; .propertiesView-buttonContainer { float: right; diff --git a/src/client/views/collections/CollectionView.tsx b/src/client/views/collections/CollectionView.tsx index 34fd20f1a..4f37747b0 100644 --- a/src/client/views/collections/CollectionView.tsx +++ b/src/client/views/collections/CollectionView.tsx @@ -38,6 +38,8 @@ import { SubCollectionViewProps } from './CollectionSubView'; import { CollectionTimeView } from './CollectionTimeView'; import { CollectionTreeView } from "./CollectionTreeView"; import './CollectionView.scss'; +import { FilterBox } from '../nodes/FilterBox'; +import { listSpec } from '../../../fields/Schema'; export const COLLECTION_BORDER_WIDTH = 2; const path = require('path'); @@ -116,6 +118,19 @@ export class CollectionView extends Touchable { whenActiveChanged = (isActive: boolean) => this.props.whenActiveChanged(this._isChildActive = isActive); + /** + * Applies the collection/dashboard's current filter attributes to the doc being added + */ + addFilterAttributes = (doc: Doc) => { + Cast(FilterBox.targetDoc._docFilters, listSpec("string"))?.forEach(attribute => { + if (attribute.charAt(0).toUpperCase() === attribute.charAt(0)) { + const fields = attribute.split(':'); + if (fields[2] === "check") doc[DataSym][fields[0]] = fields[1]; + else if (fields[2] === "x" && doc[DataSym][fields[0]] === fields[1]) doc[DataSym][fields[0]] = undefined; + } + }); + } + @action.bound addDocument = (doc: Doc | Doc[]): boolean => { if (this.props.filterAddDocument?.(doc) === false) { @@ -157,6 +172,7 @@ export class CollectionView extends Touchable { DocUtils.LeavePushpin(doc); doc._stayInCollection = undefined; doc.context = this.props.Document; + this.addFilterAttributes(doc); // }); added.map(doc => this.props.layerProvider?.(doc, true));// assigns layer values to the newly added document... testing the utility of this (targetDataDoc[this.props.fieldKey] as List).push(...added); diff --git a/src/client/views/nodes/FilterBox.tsx b/src/client/views/nodes/FilterBox.tsx index 41e274e7a..541693cdf 100644 --- a/src/client/views/nodes/FilterBox.tsx +++ b/src/client/views/nodes/FilterBox.tsx @@ -39,7 +39,7 @@ export class FilterBox extends ViewBoxBaseComponent) { super(props); - const targetDoc = this.targetDoc; + const targetDoc = FilterBox.targetDoc; if (!targetDoc) CurrentUserUtils.setupFilterDocs(targetDoc); } public static LayoutString(fieldKey: string) { return FieldView.LayoutString(FilterBox, fieldKey); } @@ -52,7 +52,7 @@ export class FilterBox extends ViewBoxBaseComponent(); - const targetDoc = this.targetDoc; + const targetDoc = FilterBox.targetDoc; if (this._loaded && targetDoc) { // if (targetDoc) { const activeTabs = DocListCast(targetDoc.data); @@ -140,7 +140,7 @@ export class FilterBox extends ViewBoxBaseComponent { console.log("remove filter"); - const targetDoc = this.targetDoc; + const targetDoc = FilterBox.targetDoc; const filterDoc = targetDoc.currentFilter as Doc; const attributes = DocListCast(filterDoc["data"]); const found = attributes.findIndex(doc => doc.title === filterName); @@ -170,7 +170,7 @@ export class FilterBox extends ViewBoxBaseComponent doc.title === facetHeader); if (found !== -1) { // comment this bit out later once the x works in treeview -- cgit v1.2.3-70-g09d2 From a8c02cba0bf96e435e062f2251890243ad8f49e0 Mon Sep 17 00:00:00 2001 From: usodhi <61431818+usodhi@users.noreply.github.com> Date: Wed, 17 Mar 2021 22:36:16 -0400 Subject: made and/or a property of the document so it's saved with the filter --- src/client/documents/Documents.ts | 4 ++-- src/client/util/CurrentUserUtils.ts | 5 +++-- src/client/views/PropertiesView.tsx | 3 +++ src/client/views/nodes/FilterBox.tsx | 9 ++++----- 4 files changed, 12 insertions(+), 9 deletions(-) (limited to 'src/client/documents/Documents.ts') diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts index 0d2f04569..ef6623f20 100644 --- a/src/client/documents/Documents.ts +++ b/src/client/documents/Documents.ts @@ -1040,7 +1040,7 @@ export namespace DocUtils { return Field.toString(d[facetKey] as Field).includes(value); }); // if we're ORing them together, the default return is false, and we return true for a doc if it satisfies any one set of criteria - if (FilterBox._filterBoolean === "OR") { + if ((FilterBox.targetDoc.currentFilter as Doc).filterBoolean === "OR") { if (satisfiesCheckFacets && !failsNotEqualFacets && satisfiesMatchFacets) return true; } // if we're ANDing them together, the default return is true, and we return false for a doc if it doesn't satisfy any set of criteria @@ -1049,7 +1049,7 @@ export namespace DocUtils { } } - return FilterBox._filterBoolean === "OR" ? false : true; + return (FilterBox.targetDoc.currentFilter as Doc).filterBoolean === "OR" ? false : true; }) : childDocs; const rangeFilteredDocs = filteredDocs.filter(d => { for (let i = 0; i < docRangeFilters.length; i += 3) { diff --git a/src/client/util/CurrentUserUtils.ts b/src/client/util/CurrentUserUtils.ts index 88bb1207f..157a88de7 100644 --- a/src/client/util/CurrentUserUtils.ts +++ b/src/client/util/CurrentUserUtils.ts @@ -810,8 +810,9 @@ export class CurrentUserUtils { _lockedPosition: true, boxShadow: "0 0", childDontRegisterViews: true, targetDropAction: "same", system: true }); const clearAll = ScriptField.MakeScript(`getProto(self).data = new List([])`); - (doc.currentFilter as any as Doc).contextMenuScripts = new List([clearAll!]); - (doc.currentFilter as any as Doc).contextMenuLabels = new List(["Clear All"]); + (doc.currentFilter as Doc).contextMenuScripts = new List([clearAll!]); + (doc.currentFilter as Doc).contextMenuLabels = new List(["Clear All"]); + (doc.currentFilter as Doc).filterBoolean = "AND"; } } diff --git a/src/client/views/PropertiesView.tsx b/src/client/views/PropertiesView.tsx index c677478cb..b4e15b536 100644 --- a/src/client/views/PropertiesView.tsx +++ b/src/client/views/PropertiesView.tsx @@ -74,6 +74,9 @@ export class PropertiesView extends React.Component { @observable openTransform: boolean = true; @observable openFilters: boolean = true; // should be false + /** + * autorun to set up the filter doc of a collection if that collection has been selected and the filters panel is open + */ private selectedDocListenerDisposer: Opt; // @observable selectedUser: string = ""; diff --git a/src/client/views/nodes/FilterBox.tsx b/src/client/views/nodes/FilterBox.tsx index d410d2b33..2ed3dc21f 100644 --- a/src/client/views/nodes/FilterBox.tsx +++ b/src/client/views/nodes/FilterBox.tsx @@ -44,7 +44,6 @@ export class FilterBox extends ViewBoxBaseComponent { - FilterBox._filterBoolean = e.currentTarget.value; + (FilterBox.targetDoc.currentFilter as Doc).filterBoolean = e.currentTarget.value; } /** @@ -388,8 +387,8 @@ export class FilterBox extends ViewBoxBaseComponent
filters in
select
@@ -465,7 +460,7 @@ export class FilterBox extends ViewBoxBaseComponentunmatched
documents
- + */}
-- cgit v1.2.3-70-g09d2 From 4df769e20b9588fea61b602ec67ca2208fc3d747 Mon Sep 17 00:00:00 2001 From: usodhi <61431818+usodhi@users.noreply.github.com> Date: Thu, 25 Mar 2021 02:25:12 -0400 Subject: filters is going to kill me the files I should look at on return to this branch are documents.ts, propertiesview, colsubview, colview, filterbox --- src/client/documents/Documents.ts | 8 ++++---- src/client/views/PropertiesView.scss | 3 +-- src/client/views/PropertiesView.tsx | 2 +- src/client/views/collections/CollectionSubView.tsx | 14 ++++++++++---- src/client/views/collections/CollectionView.tsx | 2 +- src/client/views/nodes/FilterBox.tsx | 8 ++++---- 6 files changed, 21 insertions(+), 16 deletions(-) (limited to 'src/client/documents/Documents.ts') diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts index 0c16d9f8f..3e29a4edf 100644 --- a/src/client/documents/Documents.ts +++ b/src/client/documents/Documents.ts @@ -990,7 +990,7 @@ export namespace DocUtils { * @param viewSpecScript * Given a list of docs and docFilters, @returns the list of Docs that match those filters */ - export function FilterDocs(docs: Doc[], docFilters: string[], docRangeFilters: string[], viewSpecScript?: ScriptField) { + export function FilterDocs(docs: Doc[], docFilters: string[], docRangeFilters: string[], viewSpecScript?: ScriptField, parentCollection?: Doc) { const childDocs = viewSpecScript ? docs.filter(d => viewSpecScript.script.run({ doc: d }, console.log).result) : docs; if (!docFilters?.length && !docRangeFilters?.length) { return childDocs.filter(d => !d.cookies); // remove documents that need a cookie if there are no filters to provide one @@ -1040,16 +1040,16 @@ export namespace DocUtils { return Field.toString(d[facetKey] as Field).includes(value); }); // if we're ORing them together, the default return is false, and we return true for a doc if it satisfies any one set of criteria - if ((FilterBox.targetDoc.currentFilter as Doc).filterBoolean === "OR") { + if (((FilterBox._filterScope === "Current Collection" ? parentCollection || CurrentUserUtils.ActiveDashboard : CurrentUserUtils.ActiveDashboard).currentFilter as Doc)?.filterBoolean === "OR") { if (satisfiesCheckFacets && !failsNotEqualFacets && satisfiesMatchFacets) return true; } // if we're ANDing them together, the default return is true, and we return false for a doc if it doesn't satisfy any set of criteria else { - if (!satisfiesCheckFacets || failsNotEqualFacets || (matches.length && satisfiesMatchFacets)) return false; + if (!satisfiesCheckFacets || failsNotEqualFacets || (matches.length && !satisfiesMatchFacets)) return false; } } - return (FilterBox.targetDoc.currentFilter as Doc).filterBoolean === "OR" ? false : true; + return ((FilterBox._filterScope === "Current Collection" ? parentCollection || CurrentUserUtils.ActiveDashboard : CurrentUserUtils.ActiveDashboard).currentFilter as Doc)?.filterBoolean === "OR" ? false : true; }) : childDocs; const rangeFilteredDocs = filteredDocs.filter(d => { for (let i = 0; i < docRangeFilters.length; i += 3) { diff --git a/src/client/views/PropertiesView.scss b/src/client/views/PropertiesView.scss index 7c6d507b8..04934d50b 100644 --- a/src/client/views/PropertiesView.scss +++ b/src/client/views/PropertiesView.scss @@ -191,8 +191,7 @@ font-size: 10px; padding: 10px; margin-left: 5px; - max-height: 40%; - overflow-y: scroll; + max-height: 40%;overflow-y: scroll; .propertiesView-buttonContainer { float: right; diff --git a/src/client/views/PropertiesView.tsx b/src/client/views/PropertiesView.tsx index 1f4685bf2..1e96d62d2 100644 --- a/src/client/views/PropertiesView.tsx +++ b/src/client/views/PropertiesView.tsx @@ -51,7 +51,7 @@ export class PropertiesView extends React.Component { @computed get selectedDoc() { return SelectionManager.SelectedSchemaDoc() || this.selectedDocumentView?.rootDoc; } @computed get filterDoc() { - return FilterBox.targetDoc; + return FilterBox._filterScope === "Current Collection" ? this.selectedDoc! : CurrentUserUtils.ActiveDashboard; } @computed get selectedDocumentView() { if (SelectionManager.Views().length) return SelectionManager.Views()[0]; diff --git a/src/client/views/collections/CollectionSubView.tsx b/src/client/views/collections/CollectionSubView.tsx index 05e9ac265..3e6deaf3a 100644 --- a/src/client/views/collections/CollectionSubView.tsx +++ b/src/client/views/collections/CollectionSubView.tsx @@ -82,7 +82,7 @@ export function CollectionSubView(schemaCtor: (doc: Doc) => T, moreProps?: return Cast(this.dataField, listSpec(Doc)); } docFilters = () => { - return [...this.props.docFilters(), ...Cast(this.props.Document._docFilters, listSpec("string"), [])]; + return [...this.props.docFilters(), ...Cast(FilterBox._filterScope === "Current Collection" ? this.props.Document._docFilters : CurrentUserUtils.ActiveDashboard._docFilters, listSpec("string"), [])]; } docRangeFilters = () => { return [...this.props.docRangeFilters(), ...Cast(this.props.Document._docRangeFilters, listSpec("string"), [])]; @@ -114,10 +114,15 @@ export function CollectionSubView(schemaCtor: (doc: Doc) => T, moreProps?: return childDocs.filter(cd => !cd.cookies); // remove any documents that require a cookie if there are no filters to provide one } + // console.log(CurrentUserUtils.ActiveDashboard._docFilters); + if (!this.props.Document._docFilters && this.props.Document.currentFilter) { + (this.props.Document.currentFilter as Doc).filterBoolean = (this.props.ContainingCollectionDoc?.currentFilter as Doc)?.filterBoolean; + } const docsforFilter: Doc[] = []; + console.log(this.props.Document.system); childDocs.forEach((d) => { // if (DocUtils.Excluded(d, docFilters)) return; - let notFiltered = d.z || ((!searchDocs.length || searchDocs.includes(d)) && (DocUtils.FilterDocs([d], docFilters, docRangeFilters, viewSpecScript).length > 0)); + let notFiltered = d.z || ((!searchDocs.length || searchDocs.includes(d)) && (DocUtils.FilterDocs([d], docFilters, docRangeFilters, viewSpecScript, this.props.Document).length > 0)); const fieldKey = Doc.LayoutFieldKey(d); const annos = !Field.toString(Doc.LayoutField(d) as Field).includes("CollectionView"); const data = d[annos ? fieldKey + "-annotations" : fieldKey]; @@ -125,13 +130,13 @@ export function CollectionSubView(schemaCtor: (doc: Doc) => T, moreProps?: let subDocs = DocListCast(data); if (subDocs.length > 0) { let newarray: Doc[] = []; - notFiltered = notFiltered || (!searchDocs.length && DocUtils.FilterDocs(subDocs, docFilters, docRangeFilters, viewSpecScript).length); + notFiltered = notFiltered || (!searchDocs.length && DocUtils.FilterDocs(subDocs, docFilters, docRangeFilters, viewSpecScript, this.props.Document).length); while (subDocs.length > 0 && !notFiltered) { newarray = []; subDocs.forEach((t) => { const fieldKey = Doc.LayoutFieldKey(t); const annos = !Field.toString(Doc.LayoutField(t) as Field).includes("CollectionView"); - notFiltered = notFiltered || ((!searchDocs.length || searchDocs.includes(t)) && ((!docFilters.length && !docRangeFilters.length) || DocUtils.FilterDocs([t], docFilters, docRangeFilters, viewSpecScript).length)); + notFiltered = notFiltered || ((!searchDocs.length || searchDocs.includes(t)) && ((!docFilters.length && !docRangeFilters.length) || DocUtils.FilterDocs([t], docFilters, docRangeFilters, viewSpecScript, this.props.Document).length)); DocListCast(t[annos ? fieldKey + "-annotations" : fieldKey]).forEach((newdoc) => newarray.push(newdoc)); }); subDocs = newarray; @@ -481,4 +486,5 @@ import { SelectionManager } from "../../util/SelectionManager"; import { OverlayView } from "../OverlayView"; import { Hypothesis } from "../../util/HypothesisUtils"; import { GetEffectiveAcl } from "../../../fields/util"; +import { FilterBox } from "../nodes/FilterBox"; diff --git a/src/client/views/collections/CollectionView.tsx b/src/client/views/collections/CollectionView.tsx index 4f37747b0..020bb374a 100644 --- a/src/client/views/collections/CollectionView.tsx +++ b/src/client/views/collections/CollectionView.tsx @@ -122,7 +122,7 @@ export class CollectionView extends Touchable { * Applies the collection/dashboard's current filter attributes to the doc being added */ addFilterAttributes = (doc: Doc) => { - Cast(FilterBox.targetDoc._docFilters, listSpec("string"))?.forEach(attribute => { + Cast((FilterBox._filterScope === "Current Collection" ? this.props.Document : CurrentUserUtils.ActiveDashboard)._docFilters, listSpec("string"))?.forEach(attribute => { if (attribute.charAt(0).toUpperCase() === attribute.charAt(0)) { const fields = attribute.split(':'); if (fields[2] === "check") doc[DataSym][fields[0]] = fields[1]; diff --git a/src/client/views/nodes/FilterBox.tsx b/src/client/views/nodes/FilterBox.tsx index 01372c284..b9a981e77 100644 --- a/src/client/views/nodes/FilterBox.tsx +++ b/src/client/views/nodes/FilterBox.tsx @@ -81,8 +81,9 @@ export class FilterBox extends ViewBoxBaseComponent(); const targetDoc = FilterBox.targetDoc; if (this._loaded && targetDoc) { @@ -109,7 +110,7 @@ export class FilterBox extends ViewBoxBaseComponent(noviceFields); this.allDocs.forEach(doc => SearchBox.documentKeys(doc).filter(key => keys.add(key))); return Array.from(keys.keys()).filter(key => key[0]).filter(key => key[0] === "#" || key.indexOf("lastModified") !== -1 || (key[0] === key[0].toUpperCase() && !key.startsWith("_")) || noviceFields.includes(key) || !Doc.UserDoc().noviceMode).sort(); - // return []; } -- cgit v1.2.3-70-g09d2 From f98acc39b7bd88e1f260bab9b6e072c5401b46d3 Mon Sep 17 00:00:00 2001 From: usodhi <61431818+usodhi@users.noreply.github.com> Date: Sun, 4 Apr 2021 14:51:22 -0400 Subject: stopped system docs from being filtered --- src/client/documents/Documents.ts | 2 +- src/client/views/collections/CollectionSubView.tsx | 3 +-- src/fields/Doc.ts | 3 ++- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/client/documents/Documents.ts') diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts index 12d8445b4..adebb9b1c 100644 --- a/src/client/documents/Documents.ts +++ b/src/client/documents/Documents.ts @@ -651,7 +651,7 @@ export namespace Docs { const viewKeys = ["x", "y", "system"]; // keys that should be addded to the view document even though they don't begin with an "_" const { omit: dataProps, extract: viewProps } = OmitKeys(options, viewKeys, "^_"); - dataProps.system = viewProps.system; + dataProps.system = viewProps.system ? (viewProps.system) : (viewProps.system = false); dataProps.isPrototype = true; dataProps.author = Doc.CurrentUserEmail; dataProps.creationDate = new DateField; diff --git a/src/client/views/collections/CollectionSubView.tsx b/src/client/views/collections/CollectionSubView.tsx index 79fab8b62..89df60213 100644 --- a/src/client/views/collections/CollectionSubView.tsx +++ b/src/client/views/collections/CollectionSubView.tsx @@ -119,10 +119,9 @@ export function CollectionSubView(schemaCtor: (doc: Doc) => T, moreProps?: (this.props.Document.currentFilter as Doc).filterBoolean = (this.props.ContainingCollectionDoc?.currentFilter as Doc)?.filterBoolean; } const docsforFilter: Doc[] = []; - console.log(this.props.Document.system); childDocs.forEach((d) => { // if (DocUtils.Excluded(d, docFilters)) return; - let notFiltered = d.z || ((!searchDocs.length || searchDocs.includes(d)) && (DocUtils.FilterDocs([d], docFilters, docRangeFilters, viewSpecScript, this.props.Document).length > 0)); + let notFiltered = d.z || d.system || ((!searchDocs.length || searchDocs.includes(d)) && (DocUtils.FilterDocs([d], docFilters, docRangeFilters, viewSpecScript, this.props.Document).length > 0)); const fieldKey = Doc.LayoutFieldKey(d); const annos = !Field.toString(Doc.LayoutField(d) as Field).includes("CollectionView"); const data = d[annos ? fieldKey + "-annotations" : fieldKey]; diff --git a/src/fields/Doc.ts b/src/fields/Doc.ts index c36bfb04b..44eb7536e 100644 --- a/src/fields/Doc.ts +++ b/src/fields/Doc.ts @@ -1077,7 +1077,7 @@ 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: Opt, key: string, value: any, modifiers: "remove" | "match" | "check" | "x", toggle?: boolean, fieldSuffix?: string) { + export function setDocFilter(container: Opt, key: string, value: any, modifiers: "remove" | "match" | "check" | "x", toggle?: boolean, fieldSuffix?: string, append: boolean = true) { if (!container) return; const filterField = "_" + (fieldSuffix ? fieldSuffix + "-" : "") + "docFilters"; const docFilters = Cast(container[filterField], listSpec("string"), []); @@ -1146,6 +1146,7 @@ export namespace Doc { dragFactory["dragFactory-count"] = NumCast(dragFactory["dragFactory-count"]) + 1; Doc.SetInPlace(ndoc, "title", ndoc.title + " " + NumCast(dragFactory["dragFactory-count"]).toString(), true); } + ndoc && (ndoc.system = false); return ndoc; } export function delegateDragFactory(dragFactory: Doc) { -- cgit v1.2.3-70-g09d2 From 3389e8231362e48fc0df522db1317b87c71969c6 Mon Sep 17 00:00:00 2001 From: bobzel Date: Tue, 6 Apr 2021 14:39:42 -0400 Subject: fixed initial treeViewOpen state for non-checkbox filters. --- src/client/documents/Documents.ts | 1 + src/client/views/nodes/FilterBox.tsx | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'src/client/documents/Documents.ts') diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts index adebb9b1c..65dd826ef 100644 --- a/src/client/documents/Documents.ts +++ b/src/client/documents/Documents.ts @@ -248,6 +248,7 @@ export class DocumentOptions { treeViewHideHeaderFields?: boolean; // whether to hide the drop down options for tree view items. treeViewShowClearButton?: boolean; // whether a clear button should be displayed treeViewOpenIsTransient?: boolean; // ignores the treeViewOpen Doc flag, allowing a treeViewItem's expand/collapse state to be independent of other views of the same document in the same or any other tree view + _treeViewOpen?: boolean; // whether this document is expanded in a tree view (note: need _ and regular versions since this can be specified for both proto and layout docs) treeViewOpen?: boolean; // whether this document is expanded in a tree view treeViewExpandedView?: string; // which field/thing is displayed when this item is opened in tree view treeViewExpandedViewLock?: boolean; // whether the expanded view can be changed diff --git a/src/client/views/nodes/FilterBox.tsx b/src/client/views/nodes/FilterBox.tsx index c6b5d4a0a..e1227b81d 100644 --- a/src/client/views/nodes/FilterBox.tsx +++ b/src/client/views/nodes/FilterBox.tsx @@ -219,7 +219,7 @@ export class FilterBox extends ViewBoxBaseComponent 0.1) { newFacet = Docs.Create.TextDocument("", { _width: 100, _height: 25, system: true, _stayInCollection: true, target: targetDoc, - treeViewExpandedView: "layout", title: facetHeader, treeViewOpen: true, _forceActive: true, ignoreClick: true + 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._textBoxPadding = 4; @@ -227,7 +227,7 @@ export class FilterBox extends ViewBoxBaseComponent Date: Tue, 6 Apr 2021 18:39:20 -0400 Subject: reverted back to not setting 'system' for non-system documents. --- src/client/documents/Documents.ts | 2 +- src/client/views/PropertiesView.tsx | 2 +- src/client/views/collections/CollectionSubView.tsx | 2 +- src/fields/Doc.ts | 1 - 4 files changed, 3 insertions(+), 4 deletions(-) (limited to 'src/client/documents/Documents.ts') diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts index 65dd826ef..3b40f0cc7 100644 --- a/src/client/documents/Documents.ts +++ b/src/client/documents/Documents.ts @@ -652,7 +652,7 @@ export namespace Docs { const viewKeys = ["x", "y", "system"]; // keys that should be addded to the view document even though they don't begin with an "_" const { omit: dataProps, extract: viewProps } = OmitKeys(options, viewKeys, "^_"); - dataProps.system = viewProps.system ? (viewProps.system) : (viewProps.system = false); + dataProps.system = viewProps.system; dataProps.isPrototype = true; dataProps.author = Doc.CurrentUserEmail; dataProps.creationDate = new DateField; diff --git a/src/client/views/PropertiesView.tsx b/src/client/views/PropertiesView.tsx index 0b1d75970..92fe3acb5 100644 --- a/src/client/views/PropertiesView.tsx +++ b/src/client/views/PropertiesView.tsx @@ -28,7 +28,7 @@ import { PresBox } from "./nodes/PresBox"; import { PropertiesButtons } from "./PropertiesButtons"; import { PropertiesDocContextSelector } from "./PropertiesDocContextSelector"; import "./PropertiesView.scss"; -import { DefaultStyleProvider, FilteringStyleProvider } from "./StyleProvider"; +import { DefaultStyleProvider } from "./StyleProvider"; import { CurrentUserUtils } from "../util/CurrentUserUtils"; import { FilterBox } from "./nodes/FilterBox"; import { List } from "../../fields/List"; diff --git a/src/client/views/collections/CollectionSubView.tsx b/src/client/views/collections/CollectionSubView.tsx index bc5a6129c..b998555d8 100644 --- a/src/client/views/collections/CollectionSubView.tsx +++ b/src/client/views/collections/CollectionSubView.tsx @@ -122,7 +122,7 @@ export function CollectionSubView(schemaCtor: (doc: Doc) => T, moreProps?: const docsforFilter: Doc[] = []; childDocs.forEach((d) => { // if (DocUtils.Excluded(d, docFilters)) return; - let notFiltered = d.z || d.system || ((!searchDocs.length || searchDocs.includes(d)) && (DocUtils.FilterDocs([d], docFilters, docRangeFilters, viewSpecScript, this.props.Document).length > 0)); + let notFiltered = d.z || Doc.IsSystem(d) || ((!searchDocs.length || searchDocs.includes(d)) && (DocUtils.FilterDocs([d], docFilters, docRangeFilters, viewSpecScript, this.props.Document).length > 0)); const fieldKey = Doc.LayoutFieldKey(d); const annos = !Field.toString(Doc.LayoutField(d) as Field).includes("CollectionView"); const data = d[annos ? fieldKey + "-annotations" : fieldKey]; diff --git a/src/fields/Doc.ts b/src/fields/Doc.ts index 06b1b8539..01d0a8176 100644 --- a/src/fields/Doc.ts +++ b/src/fields/Doc.ts @@ -1147,7 +1147,6 @@ export namespace Doc { dragFactory["dragFactory-count"] = NumCast(dragFactory["dragFactory-count"]) + 1; Doc.SetInPlace(ndoc, "title", ndoc.title + " " + NumCast(dragFactory["dragFactory-count"]).toString(), true); } - ndoc && (ndoc.system = false); return ndoc; } export function delegateDragFactory(dragFactory: Doc) { -- cgit v1.2.3-70-g09d2 From 797ebbe8a82c54104a96c6e570310fb1d02da69c Mon Sep 17 00:00:00 2001 From: bobzel Date: Wed, 7 Apr 2021 12:15:20 -0400 Subject: removed scope option for filters in favor of selecting dashboard. --- src/client/documents/Documents.ts | 4 +-- src/client/util/CurrentUserUtils.ts | 2 +- src/client/views/PropertiesView.tsx | 56 +++++++++++++++++------------------- src/client/views/nodes/FilterBox.tsx | 53 ++++++---------------------------- 4 files changed, 38 insertions(+), 77 deletions(-) (limited to 'src/client/documents/Documents.ts') diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts index 3b40f0cc7..560806078 100644 --- a/src/client/documents/Documents.ts +++ b/src/client/documents/Documents.ts @@ -1005,7 +1005,7 @@ export namespace DocUtils { return Field.toString(d[facetKey] as Field).includes(value); }); // if we're ORing them together, the default return is false, and we return true for a doc if it satisfies any one set of criteria - if (((FilterBox._filterScope === "Current Collection" ? parentCollection || CurrentUserUtils.ActiveDashboard : CurrentUserUtils.ActiveDashboard).currentFilter as Doc)?.filterBoolean === "OR") { + if ((parentCollection?.currentFilter as Doc)?.filterBoolean === "OR") { if (satisfiesCheckFacets && !failsNotEqualFacets && satisfiesMatchFacets) return true; } // if we're ANDing them together, the default return is true, and we return false for a doc if it doesn't satisfy any set of criteria @@ -1014,7 +1014,7 @@ export namespace DocUtils { } } - return ((FilterBox._filterScope === "Current Collection" ? parentCollection || CurrentUserUtils.ActiveDashboard : CurrentUserUtils.ActiveDashboard).currentFilter as Doc)?.filterBoolean === "OR" ? false : true; + return (parentCollection?.currentFilter as Doc)?.filterBoolean === "OR" ? false : true; }) : childDocs; const rangeFilteredDocs = filteredDocs.filter(d => { for (let i = 0; i < docRangeFilters.length; i += 3) { diff --git a/src/client/util/CurrentUserUtils.ts b/src/client/util/CurrentUserUtils.ts index 4b0a49180..417a1f405 100644 --- a/src/client/util/CurrentUserUtils.ts +++ b/src/client/util/CurrentUserUtils.ts @@ -806,7 +806,7 @@ export class CurrentUserUtils { // setup Filter item if (doc.currentFilter === undefined) { doc.currentFilter = Docs.Create.FilterDocument({ - title: "FilterDoc", _height: 150, + title: "unnamed filter", _height: 150, treeViewHideTitle: true, _xMargin: 5, _yMargin: 5, _gridGap: 5, _forceActive: true, childDropAction: "none", treeViewTruncateTitleWidth: 150, ignoreClick: true, _lockedPosition: true, boxShadow: "0 0", childDontRegisterViews: true, targetDropAction: "same", system: true, _autoHeight: true, _fitWidth: true diff --git a/src/client/views/PropertiesView.tsx b/src/client/views/PropertiesView.tsx index 92fe3acb5..bb0ad4c66 100644 --- a/src/client/views/PropertiesView.tsx +++ b/src/client/views/PropertiesView.tsx @@ -30,7 +30,6 @@ import { PropertiesDocContextSelector } from "./PropertiesDocContextSelector"; import "./PropertiesView.scss"; import { DefaultStyleProvider } from "./StyleProvider"; import { CurrentUserUtils } from "../util/CurrentUserUtils"; -import { FilterBox } from "./nodes/FilterBox"; import { List } from "../../fields/List"; const higflyout = require("@hig/flyout"); export const { anchorPoints } = higflyout; @@ -49,10 +48,7 @@ export class PropertiesView extends React.Component { @computed get MAX_EMBED_HEIGHT() { return 200; } - @computed get selectedDoc() { return SelectionManager.SelectedSchemaDoc() || this.selectedDocumentView?.rootDoc; } - @computed get filterDoc() { - return FilterBox._filterScope === "Current Collection" ? this.selectedDoc! : CurrentUserUtils.ActiveDashboard; - } + @computed get selectedDoc() { return SelectionManager.SelectedSchemaDoc() || this.selectedDocumentView?.rootDoc || CurrentUserUtils.ActiveDashboard; } @computed get selectedDocumentView() { if (SelectionManager.Views().length) return SelectionManager.Views()[0]; if (PresBox.Instance?._selectedArray.size) return DocumentManager.Instance.getDocumentView(PresBox.Instance.rootDoc); @@ -909,47 +905,47 @@ export class PropertiesView extends React.Component { * If it doesn't exist, it creates it. */ checkFilterDoc() { - if (this.filterDoc.type === DocumentType.COL && !this.filterDoc.currentFilter) CurrentUserUtils.setupFilterDocs(this.filterDoc); + if (this.selectedDoc.type === DocumentType.COL && !this.selectedDoc.currentFilter) CurrentUserUtils.setupFilterDocs(this.selectedDoc); } /** * Creates a new currentFilter for this.filterDoc, */ createNewFilterDoc = () => { - const currentDocFilters = this.filterDoc._docFilters; - const currentDocRangeFilters = this.filterDoc._docRangeFilters; - this.filterDoc._docFilters = new List(); - this.filterDoc._docRangeFilters = new List(); - (this.filterDoc.currentFilter as Doc)._docFiltersList = currentDocFilters; - (this.filterDoc.currentFilter as Doc)._docRangeFiltersList = currentDocRangeFilters; - this.filterDoc.currentFilter = undefined; - CurrentUserUtils.setupFilterDocs(this.filterDoc); + const currentDocFilters = this.selectedDoc._docFilters; + const currentDocRangeFilters = this.selectedDoc._docRangeFilters; + this.selectedDoc._docFilters = new List(); + this.selectedDoc._docRangeFilters = new List(); + (this.selectedDoc.currentFilter as Doc)._docFiltersList = currentDocFilters; + (this.selectedDoc.currentFilter as Doc)._docRangeFiltersList = currentDocRangeFilters; + this.selectedDoc.currentFilter = undefined; + CurrentUserUtils.setupFilterDocs(this.selectedDoc); } /** * Updates this.filterDoc's currentFilter and saves the docFilters on the currentFilter */ updateFilterDoc = (doc: Doc) => { - if (doc === this.filterDoc.currentFilter) return; // causes problems if you try to reapply the same doc + if (doc === this.selectedDoc.currentFilter) return; // causes problems if you try to reapply the same doc const savedDocFilters = doc._docFiltersList; - const currentDocFilters = this.filterDoc._docFilters; - this.filterDoc._docFilters = new List(); - (this.filterDoc.currentFilter as Doc)._docFiltersList = currentDocFilters; - this.filterDoc.currentFilter = doc; + const currentDocFilters = this.selectedDoc._docFilters; + this.selectedDoc._docFilters = new List(); + (this.selectedDoc.currentFilter as Doc)._docFiltersList = currentDocFilters; + this.selectedDoc.currentFilter = doc; doc._docFiltersList = new List(); - this.filterDoc._docFilters = savedDocFilters; + this.selectedDoc._docFilters = savedDocFilters; const savedDocRangeFilters = doc._docRangeFiltersList; - const currentDocRangeFilters = this.filterDoc._docRangeFilters; - this.filterDoc._docRangeFilters = new List(); - (this.filterDoc.currentFilter as Doc)._docRangeFiltersList = currentDocRangeFilters; - this.filterDoc.currentFilter = doc; + const currentDocRangeFilters = this.selectedDoc._docRangeFilters; + this.selectedDoc._docRangeFilters = new List(); + (this.selectedDoc.currentFilter as Doc)._docRangeFiltersList = currentDocRangeFilters; + this.selectedDoc.currentFilter = doc; doc._docRangeFiltersList = new List(); - this.filterDoc._docRangeFilters = savedDocRangeFilters; + this.selectedDoc._docRangeFilters = savedDocRangeFilters; } @computed get filtersSubMenu() { - return !(this.filterDoc?.currentFilter instanceof Doc) ? (null) :
+ return !(this.selectedDoc?.currentFilter instanceof Doc) ? (null) :
this.openFilters = !this.openFilters)} style={{ backgroundColor: this.openFilters ? "black" : "" }}> @@ -960,9 +956,9 @@ export class PropertiesView extends React.Component {
{ !this.openFilters ? (null) : -
+
{ removeDocument={returnFalse} ScreenToLocalTransform={this.getTransform} PanelWidth={() => this.props.width} - PanelHeight={this.filterDoc.currentFilter[HeightSym]} + PanelHeight={this.selectedDoc.currentFilter[HeightSym]} renderDepth={0} - scriptContext={this.filterDoc.currentFilter} + scriptContext={this.selectedDoc.currentFilter} focus={emptyFunction} styleProvider={DefaultStyleProvider} isContentActive={returnTrue} diff --git a/src/client/views/nodes/FilterBox.tsx b/src/client/views/nodes/FilterBox.tsx index d7f51c57b..05bb69d61 100644 --- a/src/client/views/nodes/FilterBox.tsx +++ b/src/client/views/nodes/FilterBox.tsx @@ -27,7 +27,6 @@ import Select from "react-select"; import { UserOptions } from "../../util/GroupManager"; import { DocumentViewProps } from "./DocumentView"; import { DefaultStyleProvider, StyleProp } from "../StyleProvider"; -import { CollectionViewType } from "../collections/CollectionView"; import { CurrentUserUtils } from "../../util/CurrentUserUtils"; import { EditableView } from "../EditableView"; import { undoBatch } from "../../util/UndoManager"; @@ -45,7 +44,6 @@ export class FilterBox extends ViewBoxBaseComponent this._loaded = true); }, { fireImmediately: true }); } + @observable _allDocs = [] as Doc[]; @computed get allDocs() { // trace(); - const allDocs = new Set(); const targetDoc = FilterBox.targetDoc; if (this._loaded && targetDoc) { + const allDocs = new Set(); const activeTabs = DocListCast(targetDoc.data); SearchBox.foreachRecursiveDoc(activeTabs, (doc: Doc) => allDocs.add(doc)); - setTimeout(() => targetDoc.allDocuments = new List(Array.from(allDocs))); + setTimeout(action(() => this._allDocs = Array.from(allDocs))); } - return allDocs; + return this._allDocs; } @computed get _allFacets() { @@ -270,34 +269,6 @@ export class FilterBox extends ViewBoxBaseComponent { - if (FilterBox._filterScope === "Current Dashboard" && e.currentTarget.value === "Current Collection") { - const currentDashboardDocFilters = CurrentUserUtils.ActiveDashboard._docFilters; - CurrentUserUtils.ActiveDashboard._docFilters = new List(); - (CurrentUserUtils.ActiveDashboard.currentFilter as Doc)._docFilterList = currentDashboardDocFilters; - - const currentDashboardDocRangeFilters = CurrentUserUtils.ActiveDashboard._docRangeFilters; - CurrentUserUtils.ActiveDashboard._docRangeFilters = new List(); - (CurrentUserUtils.ActiveDashboard.currentFilter as Doc)._docRangeFilterList = currentDashboardDocRangeFilters; - } - else if (FilterBox._filterScope === "Current Collection" && e.currentTarget.value === "Current Dashboard") { - const savedDashboardDocFilters = (CurrentUserUtils.ActiveDashboard.currentFilter as Doc)._docFilterList; - (CurrentUserUtils.ActiveDashboard.currentFilter as Doc)._docFilterList = undefined; - CurrentUserUtils.ActiveDashboard._docFilters = savedDashboardDocFilters; - - const savedDashboardDocRangeFilters = (CurrentUserUtils.ActiveDashboard.currentFilter as Doc)._docRangeFilterList; - (CurrentUserUtils.ActiveDashboard.currentFilter as Doc)._docRangeFilterList = undefined; - CurrentUserUtils.ActiveDashboard._docRangeFilters = savedDashboardDocRangeFilters; - } - FilterBox._filterScope = e.currentTarget.value; - } - /** * Changes whether to select matched or unmatched documents */ @@ -415,14 +386,6 @@ export class FilterBox extends ViewBoxBaseComponentOR
filters in
-
@@ -526,7 +489,9 @@ Scripting.addGlobal(function determineCheckedState(layoutDoc: Doc, facetHeader: return undefined; }); Scripting.addGlobal(function readFacetData(layoutDoc: Doc, facetHeader: string) { - const allCollectionDocs = DocListCast(layoutDoc.allDocuments); + const allCollectionDocs = new Set(); + const activeTabs = DocListCast(layoutDoc.data); + SearchBox.foreachRecursiveDoc(activeTabs, (doc: Doc) => allCollectionDocs.add(doc)); const set = new Set(); if (facetHeader === "tags") allCollectionDocs.forEach(child => Field.toString(child[facetHeader] as Field).split(":").forEach(key => set.add(key))); else allCollectionDocs.forEach(child => set.add(Field.toString(child[facetHeader] as Field))); -- cgit v1.2.3-70-g09d2