Skip to content
This repository was archived by the owner on Sep 1, 2023. It is now read-only.

Commit d191550

Browse files
committed
1.0.9: Added (undocumented) support for 'file' input type
- Added a new expectedInput type, 'file' - Enables devs to specify that (API and UI) clients should supply a file input for the job. The UI renders this as an <input type="file" /> - Using a file input in a template expression (e.g. '${inputs.someFile}') automatically coerces the user-supplied file into a local filepath that your application can read. - This is effectively sugar for '${toFile(inputs.foo)}', but with some extra quality-of-life benefits. - The main QOL benefit is that Jobson will try to leave the user-supplied filename untouched, which is useful if your application relies on extension matching - This feature is currently undocumented due to time constraints. The final API of the released version *should* (famous last words) be identical.
2 parents 6859b1c + 60e1143 commit d191550

File tree

30 files changed

+614
-42
lines changed

30 files changed

+614
-42
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ Requires java (8+):
4848
4949
```bash
5050
# install and add to PATH
51-
wget https://github.com/adamkewley/jobson/releases/download/1.0.8/jobson-nix-1.0.8.tar.gz
52-
tar xvf jobson-nix-1.0.8.tar.gz
53-
export PATH=$PATH:jobson-nix-1.0.8/bin
51+
wget https://github.com/adamkewley/jobson/releases/download/1.0.9/jobson-nix-1.0.9.tar.gz
52+
tar xvf jobson-nix-1.0.9.tar.gz
53+
export PATH=$PATH:jobson-nix-1.0.9/bin
5454

5555
# create demo workspace
5656
jobson new --demo

jobson-deb/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>com.github.jobson</groupId>
99
<artifactId>jobson-project</artifactId>
10-
<version>1.0.8</version>
10+
<version>1.0.9</version>
1111
</parent>
1212

1313
<artifactId>jobson-deb</artifactId>
@@ -17,7 +17,7 @@
1717
<dependency>
1818
<groupId>com.github.jobson</groupId>
1919
<artifactId>jobson-nix</artifactId>
20-
<version>1.0.8</version>
20+
<version>1.0.9</version>
2121
<type>tar.gz</type>
2222
</dependency>
2323
</dependencies>

jobson-docker/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>com.github.jobson</groupId>
99
<artifactId>jobson-project</artifactId>
10-
<version>1.0.8</version>
10+
<version>1.0.9</version>
1111
</parent>
1212

1313
<artifactId>jobson-docker</artifactId>
@@ -17,7 +17,7 @@
1717
<dependency>
1818
<groupId>com.github.jobson</groupId>
1919
<artifactId>jobson-deb</artifactId>
20-
<version>1.0.8</version>
20+
<version>1.0.9</version>
2121
<type>deb</type>
2222
</dependency>
2323
</dependencies>

jobson-docs/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
<parent>
88
<groupId>com.github.jobson</groupId>
99
<artifactId>jobson-project</artifactId>
10-
<version>1.0.8</version>
10+
<version>1.0.9</version>
1111
</parent>
1212

1313
<artifactId>jobson-docs</artifactId>
14-
<version>1.0.8</version>
14+
<version>1.0.9</version>
1515
<packaging>pom</packaging>
1616

1717
<dependencies>

jobson-nix/pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>com.github.jobson</groupId>
99
<artifactId>jobson-project</artifactId>
10-
<version>1.0.8</version>
10+
<version>1.0.9</version>
1111
</parent>
1212

1313
<artifactId>jobson-nix</artifactId>
@@ -17,18 +17,18 @@
1717
<dependency>
1818
<groupId>com.github.jobson</groupId>
1919
<artifactId>jobson</artifactId>
20-
<version>1.0.8</version>
20+
<version>1.0.9</version>
2121
</dependency>
2222
<dependency>
2323
<groupId>com.github.jobson</groupId>
2424
<artifactId>jobson-docs</artifactId>
25-
<version>1.0.8</version>
25+
<version>1.0.9</version>
2626
<type>tar.gz</type>
2727
</dependency>
2828
<dependency>
2929
<groupId>com.github.jobson</groupId>
3030
<artifactId>jobson-ui</artifactId>
31-
<version>1.0.8</version>
31+
<version>1.0.9</version>
3232
<type>tar.gz</type>
3333
</dependency>
3434
</dependencies>

jobson-swagger-ui/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
<parent>
88
<groupId>com.github.jobson</groupId>
99
<artifactId>jobson-project</artifactId>
10-
<version>1.0.8</version>
10+
<version>1.0.9</version>
1111
</parent>
1212

1313
<artifactId>jobson-swagger-ui</artifactId>
14-
<version>1.0.8</version>
14+
<version>1.0.9</version>
1515
<packaging>pom</packaging>
1616

1717
<dependencies>

jobson-swagger/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@
77
<parent>
88
<groupId>com.github.jobson</groupId>
99
<artifactId>jobson-project</artifactId>
10-
<version>1.0.8</version>
10+
<version>1.0.9</version>
1111
</parent>
1212

1313
<artifactId>jobson-swagger</artifactId>
14-
<version>1.0.8</version>
14+
<version>1.0.9</version>
1515
<packaging>pom</packaging>
1616

1717
<dependencies>
1818
<dependency>
1919
<groupId>com.github.jobson</groupId>
2020
<artifactId>jobson</artifactId>
21-
<version>1.0.8</version>
21+
<version>1.0.9</version>
2222
<exclusions>
2323
<exclusion>
2424
<groupId>com.fasterxml</groupId>

jobson-ui/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
<parent>
88
<groupId>com.github.jobson</groupId>
99
<artifactId>jobson-project</artifactId>
10-
<version>1.0.8</version>
10+
<version>1.0.9</version>
1111
</parent>
1212

1313
<artifactId>jobson-ui</artifactId>
14-
<version>1.0.8</version>
14+
<version>1.0.9</version>
1515
<packaging>pom</packaging>
1616

1717
<build>
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import {Component, ReactElement} from "react";
21+
import {InputEditorProps} from "./InputEditor";
22+
import * as React from "react";
23+
import {InputEditorUpdate} from "./updates/InputEditorUpdate";
24+
25+
const enum States {
26+
Showing,
27+
Loading,
28+
}
29+
30+
interface ShowingState {
31+
type: States.Showing;
32+
error: string | null;
33+
}
34+
35+
interface LoadingState {
36+
type: States.Loading;
37+
}
38+
39+
type State = ShowingState | LoadingState;
40+
41+
function toB64(file: File): Promise<string> {
42+
return new Promise((resolve, reject) => {
43+
const reader = new FileReader();
44+
reader.onload = e => {
45+
const contents = e.target.result as ArrayBuffer;
46+
const b64 = btoa(String.fromCharCode.apply(null, new Uint8Array(contents)));
47+
resolve(b64);
48+
};
49+
reader.onerror = e => {
50+
reject(e);
51+
};
52+
reader.onabort = e => {
53+
reject(e);
54+
};
55+
reader.readAsArrayBuffer(file);
56+
});
57+
}
58+
59+
export class FileInputEditor extends Component<InputEditorProps, State> {
60+
61+
public state: State = {
62+
type: States.Showing,
63+
error: null,
64+
};
65+
66+
private fileInput: React.RefObject<HTMLInputElement> = React.createRef();
67+
68+
public render(): ReactElement<any> {
69+
switch (this.state.type) {
70+
case States.Showing:
71+
return this.renderShowingState();
72+
case States.Loading:
73+
return this.renderLoadingState();
74+
}
75+
}
76+
77+
private renderShowingState(): ReactElement<any> {
78+
return (
79+
<div>
80+
<input type="file"
81+
ref={this.fileInput}
82+
onChange={e => this.onFileInputChanged(e)}
83+
required />
84+
</div>
85+
);
86+
}
87+
88+
private renderLoadingState(): ReactElement<any> {
89+
return (
90+
<div>
91+
<input type="file"
92+
ref={this.fileInput}
93+
onChange={e => this.onFileInputChanged(e)}
94+
required />
95+
Loading...
96+
</div>
97+
);
98+
}
99+
100+
private onFileInputChanged(e: React.FormEvent): void {
101+
const file: File = this.fileInput.current.files[0];
102+
const filename = file.name;
103+
104+
this.setState({
105+
type: States.Loading,
106+
}, () => {
107+
toB64(file)
108+
.then(b64Str => {
109+
const upd = InputEditorUpdate.value({
110+
filename: file.name,
111+
data: b64Str,
112+
});
113+
this.props.onJobInputUpdate(upd);
114+
this.setState({
115+
type: States.Showing,
116+
error: null,
117+
});
118+
})
119+
.catch(err => {
120+
this.setState({
121+
type: States.Showing,
122+
error: err,
123+
});
124+
})
125+
});
126+
}
127+
}

jobson-ui/src/ts/components/inputeditors/InputEditor.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {UnknownInputTypeInputEditor} from "./UnknownInputTypeInputEditor";
2626
import {IntegerInputEditor} from "./IntegerInputEditor";
2727
import {Constants} from "../../Constants";
2828
import {DecimalInputEditor} from "./DecimalInputEditor";
29+
import {FileInputEditor} from "./FileInputEditor";
2930
import {APIExpectedInput} from "../../apitypes/APIExpectedInput";
3031
import {InputEditorUpdate} from "./updates/InputEditorUpdate";
3132
import {Component, ReactElement} from "react";
@@ -75,15 +76,19 @@ export class InputEditor extends Component<InputEditorProps> {
7576
max: Constants.F64_MAX,
7677
typeName: "double"
7778
}, props),
79+
"file": props => new FileInputEditor(props),
7880
};
7981

82+
private static unknownInputCtor = props => new UnknownInputTypeInputEditor(props);
83+
8084
public static getSupportedInputEditors(): string[] {
8185
return Object.keys(this.expectedInputUiComponentCtors);
8286
}
8387

8488
public render(): ReactElement<any> {
85-
const unknownCtor = (props: InputEditorProps) => new UnknownInputTypeInputEditor(props);
86-
const inputEditor = InputEditor.expectedInputUiComponentCtors[this.props.expectedInput.type] || unknownCtor;
89+
const inputEditor =
90+
InputEditor.expectedInputUiComponentCtors[this.props.expectedInput.type] ||
91+
InputEditor.unknownInputCtor;
8792
const expectedInput = this.props.expectedInput;
8893

8994
const editorProps = {

0 commit comments

Comments
 (0)