Skip to content

Commit 1390644

Browse files
committed
minor tweaks and enhancements
1 parent c802a4a commit 1390644

6 files changed

Lines changed: 145 additions & 1 deletion

File tree

domino-ui/src/main/java/org/dominokit/domino/ui/cards/CardHeader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public static CardHeader create() {
6363
subHeader = LazyChild.of(div().addCss(dui_card_sub_header), element);
6464
title = LazyChild.of(div().addCss(dui_card_title), mainHeader);
6565
mainTitle = LazyChild.of(h(2).addCss(dui_card_main_title), title);
66-
description = LazyChild.of(small().addCss(dui_card_description), mainTitle);
66+
description = LazyChild.of(small().addCss(dui_card_description), title);
6767

6868
init(this);
6969
}

domino-ui/src/main/java/org/dominokit/domino/ui/datatable/plugins/grouping/GroupCell.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public class GroupCell<T>
2626
extends TableCell<
2727
T, HTMLTableCellElement, GroupCellInfo<T>, GroupCellRenderer<T>, GroupCell<T>> {
2828

29+
private GroupingPlugin.DataGroup<T> dataGroup;
30+
2931
/**
3032
* Constructs a new {@code RowCell} with the given cell information and column configuration.
3133
*
@@ -35,6 +37,14 @@ public GroupCell(GroupCellInfo<T> cellInfo) {
3537
super(cellInfo);
3638
}
3739

40+
public GroupingPlugin.DataGroup<T> getDataGroup() {
41+
return dataGroup;
42+
}
43+
44+
void setDataGroup(GroupingPlugin.DataGroup<T> dataGroup) {
45+
this.dataGroup = dataGroup;
46+
}
47+
3848
@Override
3949
protected GroupCellRenderer<T> getDefaultCellRenderer() {
4050
return cellInfo -> elements.text();

domino-ui/src/main/java/org/dominokit/domino/ui/datatable/plugins/grouping/GroupingPlugin.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ public void appendRow(DataTable<T> dataTable, TableRow<T> tableRow) {
136136
GroupCell<T> groupCell = new GroupCell<>(cellInfo);
137137
DataGroup<T> dataGroup = new DataGroup<>(tableRow, groupCell);
138138

139+
groupCell.setDataGroup(dataGroup);
140+
139141
ToggleIcon<?, ?> groupToggleIcon =
140142
groupExpandedCollapseIconSupplier
141143
.get()
@@ -344,6 +346,10 @@ private boolean isOdd(TableRow<T> tableRow) {
344346
public void render() {
345347
groupRenderer.render(groupCell);
346348
}
349+
350+
public List<TableRow<T>> getGroupRows() {
351+
return new ArrayList<>(groupRows);
352+
}
347353
}
348354

349355
/**

domino-ui/src/main/java/org/dominokit/domino/ui/datatable/store/LocalListDataStore.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,33 @@ public void updateRecords(int startIndex, Collection<T> records) {
690690
load();
691691
}
692692

693+
/**
694+
* Inserts a new record if it does not exist, or updates the existing record if it is already
695+
* present.
696+
*
697+
* @param record The record to be inserted or updated.
698+
*/
699+
public void upsertRecord(T record) {
700+
if (original.contains(record)) {
701+
updateRecord(record);
702+
} else {
703+
addRecord(record);
704+
}
705+
}
706+
707+
/**
708+
* Inserts or updates a collection of records in the data store. Each record in the collection is
709+
* processed individually, and the upsert operation is performed for each record.
710+
*
711+
* @param records the collection of records to be inserted or updated, where each record
712+
* represents an entity to be persisted in the data store
713+
*/
714+
public void upsertRecords(Collection<T> records) {
715+
for (T record : records) {
716+
upsertRecord(record);
717+
}
718+
}
719+
693720
/**
694721
* Internal method to update a single record at a specified index, updating both the original and
695722
* filtered lists.

domino-ui/src/main/java/org/dominokit/domino/ui/forms/UploadBox.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
import static java.util.Objects.nonNull;
1919
import static org.dominokit.domino.ui.utils.Domino.*;
2020

21+
import elemental2.core.Uint8Array;
2122
import elemental2.dom.File;
2223
import elemental2.dom.HTMLInputElement;
24+
import elemental2.promise.Promise;
2325
import java.util.ArrayList;
2426
import java.util.List;
2527
import java.util.stream.Collectors;
@@ -309,4 +311,18 @@ public UploadBox setMultiple(boolean multiple) {
309311
public boolean getMultiple() {
310312
return this.getInputElement().element().multiple;
311313
}
314+
315+
public Promise<List<Uint8Array>> getValueAsUint8Arrays() {
316+
if (nonNull(getInputElement().element().files)) {
317+
return FileUtil.filesToUint8Arrays(getValue());
318+
}
319+
return Promise.resolve(new ArrayList<>());
320+
}
321+
322+
public Promise<List<byte[]>> getValueAsBytesArrays() {
323+
if (nonNull(getInputElement().element().files)) {
324+
return FileUtil.filesToByteArrays(getValue());
325+
}
326+
return Promise.resolve(new ArrayList<>());
327+
}
312328
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* Copyright © 2019 Dominokit
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.dominokit.domino.ui.utils;
17+
18+
import elemental2.core.ArrayBuffer;
19+
import elemental2.core.Uint8Array;
20+
import elemental2.dom.File;
21+
import elemental2.promise.Promise;
22+
import java.util.ArrayList;
23+
import java.util.List;
24+
import jsinterop.base.Js;
25+
26+
public class FileUtil {
27+
28+
public static Promise<Uint8Array> fileToUint8Array(File file) {
29+
return file.arrayBuffer()
30+
.then(
31+
buffer -> {
32+
ArrayBuffer ab = Js.uncheckedCast(buffer);
33+
return Promise.resolve(new Uint8Array(ab));
34+
});
35+
}
36+
37+
public static Promise<byte[]> fileToByteArray(File file) {
38+
return fileToUint8Array(file)
39+
.then(
40+
jsBytes -> {
41+
byte[] bytes = new byte[(int) jsBytes.length];
42+
for (int i = 0; i < jsBytes.length; i++) {
43+
int value = jsBytes.getAt(i).intValue() & 0xFF;
44+
bytes[i] = (byte) value;
45+
}
46+
return Promise.resolve(bytes);
47+
});
48+
}
49+
50+
public static Promise<List<Uint8Array>> filesToUint8Arrays(List<File> files) {
51+
return filesToUint8Arrays(files, 0, new ArrayList<>());
52+
}
53+
54+
private static Promise<List<Uint8Array>> filesToUint8Arrays(
55+
List<File> files, int index, List<Uint8Array> result) {
56+
if (index >= files.size()) {
57+
return Promise.resolve(result);
58+
}
59+
60+
return fileToUint8Array(files.get(index))
61+
.then(
62+
bytes -> {
63+
result.add(bytes);
64+
return filesToUint8Arrays(files, index + 1, result);
65+
});
66+
}
67+
68+
public static Promise<List<byte[]>> filesToByteArrays(List<File> files) {
69+
return filesToByteArrays(files, 0, new ArrayList<>());
70+
}
71+
72+
private static Promise<List<byte[]>> filesToByteArrays(
73+
List<File> files, int index, List<byte[]> result) {
74+
if (index >= files.size()) {
75+
return Promise.resolve(result);
76+
}
77+
78+
return fileToByteArray(files.get(index))
79+
.then(
80+
bytes -> {
81+
result.add(bytes);
82+
return filesToByteArrays(files, index + 1, result);
83+
});
84+
}
85+
}

0 commit comments

Comments
 (0)