diff --git a/service/fling/src/main/java/net/friedl/fling/model/dto/FlingDto.java b/service/fling/src/main/java/net/friedl/fling/model/dto/FlingDto.java index 8e8db37..7b4ea54 100644 --- a/service/fling/src/main/java/net/friedl/fling/model/dto/FlingDto.java +++ b/service/fling/src/main/java/net/friedl/fling/model/dto/FlingDto.java @@ -54,18 +54,19 @@ public class FlingDto { @JsonProperty("expiration") private void unpackExpiration(Map expiration) { - String type = (String) expiration.getOrDefault("expirationType", null); + String type = (String) expiration.getOrDefault("type", null); if(type == null) return; switch(type) { case "time": this.expirationClicks = null; // json can only handle int, long must be given as string - this.expirationTime = Instant.ofEpochMilli(Long.parseLong((String) expiration.get("value"))); + // TODO: this back and forth conversion is a bit hack-ish + this.expirationTime = Instant.ofEpochMilli(Long.valueOf(expiration.get("value").toString())); break; case "clicks": this.expirationTime = null; - this.expirationClicks = (Integer) expiration.get("value"); + this.expirationClicks = Integer.valueOf(expiration.get("value").toString()); break; default: throw new IllegalArgumentException("Unexpected value '"+type+"'"); diff --git a/service/fling/src/main/java/net/friedl/fling/service/FlingService.java b/service/fling/src/main/java/net/friedl/fling/service/FlingService.java index 62ddd6f..e3956ea 100644 --- a/service/fling/src/main/java/net/friedl/fling/service/FlingService.java +++ b/service/fling/src/main/java/net/friedl/fling/service/FlingService.java @@ -65,8 +65,8 @@ public class FlingService { mergeNonEmpty(flingDto::getAllowUpload, flingEntity::setAllowUpload); mergeNonEmpty(flingDto::getDirectDownload, flingEntity::setDirectDownload); - mergeNonEmpty(flingDto::getExpirationClicks, flingEntity::setExpirationClicks); - mergeNonEmpty(flingDto::getExpirationTime, flingEntity::setExpirationTime); + mergeWithEmpty(flingDto::getExpirationClicks, flingEntity::setExpirationClicks); + mergeWithEmpty(flingDto::getExpirationTime, flingEntity::setExpirationTime); mergeNonEmpty(flingDto::getName, flingEntity::setName); mergeNonEmpty(flingDto::getShared, flingEntity::setShared); mergeNonEmpty(flingDto::getShareUrl, flingEntity::setShareUrl); @@ -131,4 +131,9 @@ public class FlingService { T r = sup.get(); if(r != null) con.accept(r); } + + private void mergeWithEmpty(Supplier sup, Consumer con) { + T r = sup.get(); + con.accept(r); + } } diff --git a/web/fling/src/components/admin/Settings.jsx b/web/fling/src/components/admin/Settings.jsx index 2d4c268..1738be9 100644 --- a/web/fling/src/components/admin/Settings.jsx +++ b/web/fling/src/components/admin/Settings.jsx @@ -6,14 +6,20 @@ import classNames from 'classnames'; import {flingClient} from '../../util/flingclient'; export default function Settings(props) { - let [fling, setFling] = useState({name: "", sharing: {directDownload: false, allowUpload: true, shared: true, shareUrl: ""}}); + let [fling, setFling] = useState({name: "", sharing: {directDownload: false, allowUpload: true, shared: true, shareUrl: "", authCode: ""}, + expiration: {type: "clicks", value: 0}}); let [shareUrlUnique, setShareUrlUnique] = useState(true); useEffect(() => { if(props.activeFling) { flingClient.getFling(props.activeFling) .then(result => { - setFling(result); + let f = {...fling, ...result}; + let s = {...fling.sharing, ...result.sharing}; + let e = {...fling.expiration, ...result.expiration}; + f.sharing = s; + f.expiration = e; + setFling(f); }); } }, [props.activeFling]); @@ -80,6 +86,61 @@ export default function Settings(props) { }); } + function setName(ev) { + let f = {...fling}; + let value = ev.currentTarget.value; + + f.name = value; + setFling(f); + } + + function setExpirationType(ev) { + let f = {...fling}; + let e = {...fling.expiration}; //TODO: sharing is not cloned + let value = ev.currentTarget.value; + + if(value === "never") { + e = {}; + } else { + e.type = value; + e.value = ""; + } + + f.expiration = e; + setFling(f); + } + + function setExpirationValue(ev) { + let f = {...fling}; + let e = {...fling.expiration}; //TODO: sharing is not cloned + let value = e.type === "time" ? ev.currentTarget.valueAsNumber: ev.currentTarget.value; + + e.value = value; + + f.expiration = e; + setFling(f); + } + + function formatExpirationTime() { + if (!fling.expiration || !fling.expiration.value || fling.expiration.type !== "time") + return ""; + + + let date = new Date(fling.expiration.value); + let fmt = date.toISOString().split("T")[0]; + return fmt; + } + + function setAuthCode(ev) { + let f = {...fling}; + let s = {...fling.sharing}; + let value = ev.currentTarget.value; + + s.authCode = value; + f.sharing = s; + setFling(f); + } + function handleSubmit(ev) { ev.preventDefault(); log.info(fling); @@ -88,37 +149,100 @@ export default function Settings(props) { return(
- {log.info(props)}
-
-
+
+
- - - - - - +
+ +
+
+ +
+
+
+
+ +
+
+ + +
- +
+ +
+
+
+ + - - - +
+
- +
+
+ +
+
+
+ +
+ +
+
+ Expire after + + Clicks +
+
+ +
+
+ Expire after + +
+
+
+
+ +
+
+ +
+
+ + + + +
+
+ +
diff --git a/web/fling/src/components/admin/Upload.jsx b/web/fling/src/components/admin/Upload.jsx index 022c0b1..437243f 100644 --- a/web/fling/src/components/admin/Upload.jsx +++ b/web/fling/src/components/admin/Upload.jsx @@ -169,10 +169,9 @@ export default function Upload(props) { onDragEnter={handleOnDragEnter} onDragLeave={handleOnDragLeave}> -
+
+ onDragLeave={stopEvent} onChange={handleFileInputChange} /> {zoneContent(dragging)}
@@ -186,7 +185,7 @@ export default function Upload(props) {
-
+
Total Size: {totalSize()}
diff --git a/web/fling/src/style/fling.scss b/web/fling/src/style/fling.scss index a39832e..96e8def 100644 --- a/web/fling/src/style/fling.scss +++ b/web/fling/src/style/fling.scss @@ -207,11 +207,6 @@ tbody td { .total-upload { float: left; - align-self: flex-start; -} - -.btn-upload { - align-self: flex-end; } .my-input { @@ -221,3 +216,16 @@ tbody td { height: 100%; z-index: 0; } + +.upload-command-line { + display: flex; + justify-content: space-between; + align-items: flex-end; +} + +/************\ +| Settings | +\************/ + +.share-settings { +}