diff options
| author | Tyler Schicke <tyler_schicke@brown.edu> | 2019-02-19 21:53:57 -0500 |
|---|---|---|
| committer | Tyler Schicke <tyler_schicke@brown.edu> | 2019-02-19 21:53:57 -0500 |
| commit | ef10a6bdf753f75cbc5b5d8b7dcc53c3d4c219ad (patch) | |
| tree | 6fd1cfe02eaeaf1dc074a26cc4cde39c3313d1f3 /src/client/views/collections/CollectionFreeFormView.tsx | |
| parent | 337c41ace806e841763d23a0a94e026508e69b41 (diff) | |
cleanup and made bring to front work better
Diffstat (limited to 'src/client/views/collections/CollectionFreeFormView.tsx')
| -rw-r--r-- | src/client/views/collections/CollectionFreeFormView.tsx | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/src/client/views/collections/CollectionFreeFormView.tsx b/src/client/views/collections/CollectionFreeFormView.tsx index ce480acd1..54757cce5 100644 --- a/src/client/views/collections/CollectionFreeFormView.tsx +++ b/src/client/views/collections/CollectionFreeFormView.tsx @@ -179,18 +179,18 @@ export class CollectionFreeFormView extends CollectionViewBase { bringToFront(doc: DocumentView) { const { fieldKey: fieldKey, Document: Document } = this.props; - const value: Document[] = Document.GetList<Document>(fieldKey, []); - var topmost = value.reduce((topmost, d) => Math.max(d.GetNumber(KeyStore.ZIndex, 0), topmost), -1000); - value.map(d => { - var zind = d.GetNumber(KeyStore.ZIndex, 0); - if (zind != topmost - 1 - (topmost - zind) && d != doc.props.Document) { - d.SetData(KeyStore.ZIndex, topmost - 1 - (topmost - zind), NumberField); + const value: Document[] = Document.GetList<Document>(fieldKey, []).slice(); + value.sort((doc1, doc2) => { + if (doc1 === doc.props.Document) { + return 1; } - }) - - if (doc.props.Document.GetNumber(KeyStore.ZIndex, 0) != 0) { - doc.props.Document.SetData(KeyStore.ZIndex, 0, NumberField); - } + if (doc2 === doc.props.Document) { + return -1; + } + return doc1.GetNumber(KeyStore.ZIndex, 0) - doc2.GetNumber(KeyStore.ZIndex, 0); + }).map((doc, index) => { + doc.SetNumber(KeyStore.ZIndex, index + 1) + }); } @computed |
