Update mithril types
This commit is contained in:
1 parent
cd8d264f03
commit
cc885e7d04
8 files changed
+80
-44
No files matched your search
Generated
+3
-3
@@ -492,9 +492,9 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"@types/mithril": {
|
"@types/mithril": {
|
||||||
"version": "2.0.6",
|
"version": "2.0.8",
|
||||||
"resolved": "https://registry.npmjs.org/@types/mithril/-/mithril-2.0.6.tgz",
|
"resolved": "https://registry.npmjs.org/@types/mithril/-/mithril-2.0.8.tgz",
|
||||||
"integrity": "sha512-oOyFr99rKH+94uKHjIVKTL9uaUaxtXJgtZOZkjhWIAY8twr9YzxfEmYARMJkWC3aVg52We8d4wtLhqQ99+fXpw==",
|
"integrity": "sha512-QzVV70DqUhWfLFpMFDBI9rRxtzeUUpbhiFDpUJYSV92AePgl+Qfficgv2MOb1Ceb+lBOQU8+L+Hjf2UielQjEw==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"@types/mongodb": {
|
"@types/mongodb": {
|
||||||
|
|||||||
+1
-1
@@ -45,7 +45,7 @@
|
|||||||
"@types/koa-compress": "^4.0.1",
|
"@types/koa-compress": "^4.0.1",
|
||||||
"@types/koa-router": "^7.4.1",
|
"@types/koa-router": "^7.4.1",
|
||||||
"@types/koa-static": "^4.0.1",
|
"@types/koa-static": "^4.0.1",
|
||||||
"@types/mithril": "^2.0.6",
|
"@types/mithril": "^2.0.8",
|
||||||
"@types/mongodb": "^3.6.9",
|
"@types/mongodb": "^3.6.9",
|
||||||
"@types/node": "^14.14.34",
|
"@types/node": "^14.14.34",
|
||||||
"@types/parsimmon": "^1.10.6",
|
"@types/parsimmon": "^1.10.6",
|
||||||
|
|||||||
@@ -17,17 +17,23 @@
|
|||||||
* along with GenieACS. If not, see <http://www.gnu.org/licenses/>.
|
* along with GenieACS. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { VnodeDOM, ClosureComponent, Component } from "mithril";
|
import { VnodeDOM, ClosureComponent } from "mithril";
|
||||||
import * as notifications from "./notifications";
|
import * as notifications from "./notifications";
|
||||||
import { changePassword } from "./store";
|
import { changePassword } from "./store";
|
||||||
import { m } from "./components";
|
import { m } from "./components";
|
||||||
|
|
||||||
const component: ClosureComponent = (): Component => {
|
interface Attrs {
|
||||||
|
noAuth?: boolean;
|
||||||
|
username?: string;
|
||||||
|
onPasswordChange: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const component: ClosureComponent<Attrs> = () => {
|
||||||
return {
|
return {
|
||||||
view: (vnode) => {
|
view: (vnode) => {
|
||||||
const onPasswordChange = vnode.attrs["onPasswordChange"];
|
const onPasswordChange = vnode.attrs.onPasswordChange;
|
||||||
const enforceAuth = !vnode.attrs["noAuth"];
|
const enforceAuth = !vnode.attrs.noAuth;
|
||||||
const username = vnode.attrs["username"];
|
const username = vnode.attrs.username;
|
||||||
|
|
||||||
if (username) vnode.state["username"] = username;
|
if (username) vnode.state["username"] = username;
|
||||||
|
|
||||||
|
|||||||
+24
-14
@@ -17,44 +17,54 @@
|
|||||||
* along with GenieACS. If not, see <http://www.gnu.org/licenses/>.
|
* along with GenieACS. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { ClosureComponent, Component } from "mithril";
|
import { Editor } from "codemirror";
|
||||||
|
import { ClosureComponent } from "mithril";
|
||||||
import { m } from "./components";
|
import { m } from "./components";
|
||||||
import { codeMirror } from "./dynamic-loader";
|
import { codeMirror } from "./dynamic-loader";
|
||||||
|
|
||||||
const component: ClosureComponent = (): Component => {
|
interface Attrs {
|
||||||
|
id: string;
|
||||||
|
value: string;
|
||||||
|
mode: string;
|
||||||
|
readOnly?: boolean;
|
||||||
|
focus?: boolean;
|
||||||
|
onSubmit?: (dom: Element) => void;
|
||||||
|
onChange?: (value: string) => void;
|
||||||
|
onReady?: (editor: Editor) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const component: ClosureComponent<Attrs> = () => {
|
||||||
return {
|
return {
|
||||||
view: (vnode) => {
|
view: (vnode) => {
|
||||||
return m("textarea", {
|
return m("textarea", {
|
||||||
name: vnode.attrs["id"],
|
name: vnode.attrs.id,
|
||||||
value: vnode.attrs["value"],
|
value: vnode.attrs.value,
|
||||||
oncreate: (_vnode) => {
|
oncreate: (_vnode) => {
|
||||||
const editor = codeMirror.fromTextArea(
|
const editor = codeMirror.fromTextArea(
|
||||||
_vnode.dom as HTMLTextAreaElement,
|
_vnode.dom as HTMLTextAreaElement,
|
||||||
{
|
{
|
||||||
mode: vnode.attrs["mode"],
|
mode: vnode.attrs.mode,
|
||||||
lineNumbers: true,
|
lineNumbers: true,
|
||||||
readOnly: vnode.attrs["readOnly"],
|
readOnly: vnode.attrs.readOnly,
|
||||||
extraKeys: {
|
extraKeys: {
|
||||||
"Ctrl-Enter": () => {
|
"Ctrl-Enter": () => {
|
||||||
if (vnode.attrs["onSubmit"])
|
if (vnode.attrs.onSubmit) vnode.attrs.onSubmit(_vnode.dom);
|
||||||
vnode.attrs["onSubmit"](_vnode.dom);
|
|
||||||
},
|
},
|
||||||
"Cmd-Enter": () => {
|
"Cmd-Enter": () => {
|
||||||
if (vnode.attrs["onSubmit"])
|
if (vnode.attrs.onSubmit) vnode.attrs.onSubmit(_vnode.dom);
|
||||||
vnode.attrs["onSubmit"](_vnode.dom);
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
if (vnode.attrs["onChange"]) {
|
if (vnode.attrs.onChange) {
|
||||||
editor.on("change", (e) => {
|
editor.on("change", (e) => {
|
||||||
vnode.attrs["onChange"](e.getValue());
|
vnode.attrs.onChange(e.getValue());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vnode.attrs["focus"]) editor.focus();
|
if (vnode.attrs.focus) editor.focus();
|
||||||
if (vnode.attrs["onReady"]) vnode.attrs["onReady"](editor);
|
if (vnode.attrs.onReady) vnode.attrs.onReady(editor);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
+2
-2
@@ -22,7 +22,7 @@ import m, {
|
|||||||
Attributes,
|
Attributes,
|
||||||
Children,
|
Children,
|
||||||
ComponentTypes,
|
ComponentTypes,
|
||||||
Lifecycle,
|
CommonAttributes,
|
||||||
ClosureComponent,
|
ClosureComponent,
|
||||||
Vnode,
|
Vnode,
|
||||||
} from "mithril";
|
} from "mithril";
|
||||||
@@ -81,7 +81,7 @@ interface MC extends Static {
|
|||||||
<Attrs, State>(
|
<Attrs, State>(
|
||||||
ctx: Attributes,
|
ctx: Attributes,
|
||||||
component: ComponentTypes<Attrs, State>,
|
component: ComponentTypes<Attrs, State>,
|
||||||
attributes: Attrs & Lifecycle<Attrs, State> & { key?: string | number },
|
attributes: Attrs & CommonAttributes<Attrs, State>,
|
||||||
...args: Children[]
|
...args: Children[]
|
||||||
): Vnode<Attrs, State>;
|
): Vnode<Attrs, State>;
|
||||||
};
|
};
|
||||||
|
|||||||
+4
-4
@@ -154,7 +154,7 @@ function renderTable(confsResponse, searchString): Children {
|
|||||||
{
|
{
|
||||||
base: conf,
|
base: conf,
|
||||||
actionHandler: (action, object) => {
|
actionHandler: (action, object) => {
|
||||||
return new Promise((resolve) => {
|
return new Promise<void>((resolve) => {
|
||||||
putActionHandler(action, object, false)
|
putActionHandler(action, object, false)
|
||||||
.then((errors) => {
|
.then((errors) => {
|
||||||
const ErrorList = errors ? Object.values(errors) : [];
|
const ErrorList = errors ? Object.values(errors) : [];
|
||||||
@@ -164,11 +164,11 @@ function renderTable(confsResponse, searchString): Children {
|
|||||||
} else {
|
} else {
|
||||||
overlay.close(cb);
|
overlay.close(cb);
|
||||||
}
|
}
|
||||||
resolve(null);
|
resolve();
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
notifications.push("error", err.message);
|
notifications.push("error", err.message);
|
||||||
resolve(null);
|
resolve();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -322,7 +322,7 @@ export const component: ClosureComponent = (): Component => {
|
|||||||
uiConfigComponent,
|
uiConfigComponent,
|
||||||
Object.assign(
|
Object.assign(
|
||||||
{
|
{
|
||||||
onUpdate: (errs: string[]) => {
|
onUpdate: (errs: Record<string, string>) => {
|
||||||
const errors = errs ? Object.values(errs) : [];
|
const errors = errs ? Object.values(errs) : [];
|
||||||
if (errors.length) {
|
if (errors.length) {
|
||||||
for (const err of errors)
|
for (const err of errors)
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
* along with GenieACS. If not, see <http://www.gnu.org/licenses/>.
|
* along with GenieACS. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { VnodeDOM, ClosureComponent, Component, Children } from "mithril";
|
import { VnodeDOM, ClosureComponent, Children } from "mithril";
|
||||||
import { m } from "./components";
|
import { m } from "./components";
|
||||||
import codeEditorComponent from "./code-editor-component";
|
import codeEditorComponent from "./code-editor-component";
|
||||||
import { getDatalistId } from "./datalist";
|
import { getDatalistId } from "./datalist";
|
||||||
@@ -175,13 +175,25 @@ function createField(current, attr, focus): Children {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const component: ClosureComponent = (): Component => {
|
interface Attrs {
|
||||||
|
base?: Record<string, any>;
|
||||||
|
actionHandler: (action: string, object: any) => Promise<void>;
|
||||||
|
resource: string;
|
||||||
|
attributes: {
|
||||||
|
id: string;
|
||||||
|
label: string;
|
||||||
|
type?: string;
|
||||||
|
options?: string[];
|
||||||
|
}[];
|
||||||
|
}
|
||||||
|
|
||||||
|
const component: ClosureComponent<Attrs> = () => {
|
||||||
return {
|
return {
|
||||||
view: (vnode) => {
|
view: (vnode) => {
|
||||||
const actionHandler = vnode.attrs["actionHandler"];
|
const actionHandler = vnode.attrs.actionHandler;
|
||||||
const attributes = vnode.attrs["attributes"];
|
const attributes = vnode.attrs.attributes;
|
||||||
const resource = vnode.attrs["resource"];
|
const resource = vnode.attrs.resource;
|
||||||
const base = vnode.attrs["base"] || {};
|
const base = vnode.attrs.base || {};
|
||||||
if (!vnode.state["current"]) {
|
if (!vnode.state["current"]) {
|
||||||
vnode.state["current"] = {
|
vnode.state["current"] = {
|
||||||
isNew: !base["_id"],
|
isNew: !base["_id"],
|
||||||
@@ -226,7 +238,7 @@ const component: ClosureComponent = (): Component => {
|
|||||||
onclick: (e) => {
|
onclick: (e) => {
|
||||||
e.redraw = false;
|
e.redraw = false;
|
||||||
e.target.disabled = true;
|
e.target.disabled = true;
|
||||||
actionHandler("delete", current.object).then(() => {
|
actionHandler("delete", current.object).finally(() => {
|
||||||
e.target.disabled = false;
|
e.target.disabled = false;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -255,7 +267,7 @@ const component: ClosureComponent = (): Component => {
|
|||||||
// e.target.onsubmit = null;
|
// e.target.onsubmit = null;
|
||||||
(submit.dom as HTMLFormElement).disabled = true;
|
(submit.dom as HTMLFormElement).disabled = true;
|
||||||
// submit.dom.textContent = "Loading ...";
|
// submit.dom.textContent = "Loading ...";
|
||||||
actionHandler("save", current.object).then(() => {
|
actionHandler("save", current.object).finally(() => {
|
||||||
// submit.dom.textContent = "Save";
|
// submit.dom.textContent = "Save";
|
||||||
// e.target.onsubmit = onsubmit;
|
// e.target.onsubmit = onsubmit;
|
||||||
(submit.dom as HTMLFormElement).disabled = false;
|
(submit.dom as HTMLFormElement).disabled = false;
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
* along with GenieACS. If not, see <http://www.gnu.org/licenses/>.
|
* along with GenieACS. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { ClosureComponent, Component } from "mithril";
|
import { ClosureComponent } from "mithril";
|
||||||
import { m } from "./components";
|
import { m } from "./components";
|
||||||
import * as store from "./store";
|
import * as store from "./store";
|
||||||
import { yaml } from "./dynamic-loader";
|
import { yaml } from "./dynamic-loader";
|
||||||
@@ -86,12 +86,20 @@ function putActionHandler(prefix: string[], dataYaml: string): Promise<any> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const component: ClosureComponent = (): Component => {
|
interface Attrs {
|
||||||
|
prefix: string;
|
||||||
|
name: string;
|
||||||
|
data: { _id: string; value: string }[];
|
||||||
|
onUpdate: (errs: Record<string, string>) => void;
|
||||||
|
onError: (err: Error) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const component: ClosureComponent<Attrs> = () => {
|
||||||
return {
|
return {
|
||||||
view: (vnode) => {
|
view: (vnode) => {
|
||||||
const prefix = vnode.attrs["prefix"].split(".");
|
const prefix = vnode.attrs.prefix.split(".");
|
||||||
const name = vnode.attrs["name"];
|
const name = vnode.attrs.name;
|
||||||
const data = vnode.attrs["data"];
|
const data = vnode.attrs.data;
|
||||||
|
|
||||||
if (prefix[prefix.length - 1] === "") prefix.pop();
|
if (prefix[prefix.length - 1] === "") prefix.pop();
|
||||||
|
|
||||||
@@ -135,8 +143,8 @@ const component: ClosureComponent = (): Component => {
|
|||||||
vnode.state["updatedYaml"] = yamlString;
|
vnode.state["updatedYaml"] = yamlString;
|
||||||
|
|
||||||
putActionHandler(prefix, vnode.state["updatedYaml"])
|
putActionHandler(prefix, vnode.state["updatedYaml"])
|
||||||
.then(vnode.attrs["onUpdate"])
|
.then(vnode.attrs.onUpdate)
|
||||||
.catch(vnode.attrs["onError"]);
|
.catch(vnode.attrs.onError);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
[code, m(".actions-bar", [submit])]
|
[code, m(".actions-bar", [submit])]
|
||||||
|
|||||||
Reference in new issue
Block a user