Add linting rules
This commit is contained in:
1 parent
75a5a42296
commit
c702003c32
43 files changed
+705
-576
No files matched your search
+37
-29
@@ -34,10 +34,10 @@ const unpackSmartQuery = memoize(query => {
|
||||
|
||||
function putActionHandler(action, object, isNew) {
|
||||
if (action === "save") {
|
||||
let id = object["_id"];
|
||||
const id = object["_id"];
|
||||
delete object["_id"];
|
||||
|
||||
if (!id) return notifications.push("error", "ID can not be empty");
|
||||
if (!id) return void notifications.push("error", "ID can not be empty");
|
||||
|
||||
store
|
||||
.resourceExists("provisions", id)
|
||||
@@ -85,14 +85,14 @@ function putActionHandler(action, object, isNew) {
|
||||
}
|
||||
}
|
||||
|
||||
let formData = {
|
||||
const formData = {
|
||||
resource: "provisions",
|
||||
attributes: attributes
|
||||
};
|
||||
|
||||
const getDownloadUrl = memoize(filter => {
|
||||
let cols = {};
|
||||
for (let attr of attributes) cols[attr.label] = attr.id;
|
||||
const cols = {};
|
||||
for (const attr of attributes) cols[attr.label] = attr.id;
|
||||
return `/api/provisions.csv?${m.buildQueryString({
|
||||
filter: filter,
|
||||
columns: JSON.stringify(cols)
|
||||
@@ -100,10 +100,11 @@ const getDownloadUrl = memoize(filter => {
|
||||
});
|
||||
|
||||
function init(args) {
|
||||
if (!window.authorizer.hasAccess("provisions", 2))
|
||||
if (!window.authorizer.hasAccess("provisions", 2)) {
|
||||
return Promise.reject(
|
||||
new Error("You are not authorized to view this page")
|
||||
);
|
||||
}
|
||||
|
||||
const sort = args.sort;
|
||||
const filter = args.filter;
|
||||
@@ -131,16 +132,17 @@ function renderTable(
|
||||
type: "checkbox",
|
||||
checked: provisions.length && selected.size === provisions.length,
|
||||
onchange: e => {
|
||||
for (let provision of provisions)
|
||||
for (const provision of provisions) {
|
||||
if (e.target.checked) selected.add(provision["_id"]);
|
||||
else selected.delete(provision["_id"]);
|
||||
}
|
||||
},
|
||||
disabled: !total
|
||||
});
|
||||
|
||||
const labels = [m("th", selectAll)];
|
||||
for (let attr of attributes) {
|
||||
let label = attr.label;
|
||||
for (const attr of attributes) {
|
||||
const label = attr.label;
|
||||
|
||||
let direction = 1;
|
||||
|
||||
@@ -148,7 +150,7 @@ function renderTable(
|
||||
if (sort[attr.id] > 0) symbol = "\u2bc6";
|
||||
else if (sort[attr.id] < 0) symbol = "\u2bc5";
|
||||
|
||||
let sortable = m(
|
||||
const sortable = m(
|
||||
"button",
|
||||
{
|
||||
onclick: () => {
|
||||
@@ -162,9 +164,9 @@ function renderTable(
|
||||
labels.push(m("th", [label, sortable]));
|
||||
}
|
||||
|
||||
let rows = [];
|
||||
for (let provision of provisions) {
|
||||
let checkbox = m("input", {
|
||||
const rows = [];
|
||||
for (const provision of provisions) {
|
||||
const checkbox = m("input", {
|
||||
type: "checkbox",
|
||||
checked: selected.has(provision["_id"]),
|
||||
onchange: e => {
|
||||
@@ -177,11 +179,12 @@ function renderTable(
|
||||
}
|
||||
});
|
||||
|
||||
let tds = [m("td", checkbox)];
|
||||
for (let attr of attributes)
|
||||
const tds = [m("td", checkbox)];
|
||||
for (const attr of attributes) {
|
||||
if (attr.id == "script")
|
||||
tds.push(m("td", { title: provision[attr.id] }, provision[attr.id]));
|
||||
else tds.push(m("td", provision[attr.id]));
|
||||
}
|
||||
|
||||
tds.push(
|
||||
m(
|
||||
@@ -190,7 +193,7 @@ function renderTable(
|
||||
"a",
|
||||
{
|
||||
onclick: () => {
|
||||
let cb = () => {
|
||||
const cb = () => {
|
||||
return m(
|
||||
putForm,
|
||||
Object.assign(
|
||||
@@ -232,12 +235,13 @@ function renderTable(
|
||||
);
|
||||
}
|
||||
|
||||
if (!rows.length)
|
||||
if (!rows.length) {
|
||||
rows.push(
|
||||
m("tr.empty", m("td", { colspan: labels.length }, "No provisions"))
|
||||
);
|
||||
}
|
||||
|
||||
let footerElements = [];
|
||||
const footerElements = [];
|
||||
if (total != null) footerElements.push(`${provisions.length}/${total}`);
|
||||
else footerElements.push(`${provisions.length}`);
|
||||
|
||||
@@ -253,12 +257,13 @@ function renderTable(
|
||||
)
|
||||
);
|
||||
|
||||
if (downloadUrl)
|
||||
if (downloadUrl) {
|
||||
footerElements.push(
|
||||
m("a.download-csv", { href: downloadUrl, download: "" }, "Download")
|
||||
);
|
||||
}
|
||||
|
||||
let tfoot = m(
|
||||
const tfoot = m(
|
||||
"tfoot",
|
||||
m("tr", m("td", { colspan: labels.length }, footerElements))
|
||||
);
|
||||
@@ -290,14 +295,14 @@ function renderTable(
|
||||
)
|
||||
];
|
||||
|
||||
if (window.authorizer.hasAccess("provisions", 3))
|
||||
if (window.authorizer.hasAccess("provisions", 3)) {
|
||||
buttons.push(
|
||||
m(
|
||||
"button.primary",
|
||||
{
|
||||
title: "Create new provision",
|
||||
onclick: () => {
|
||||
let cb = () => {
|
||||
const cb = () => {
|
||||
return m(
|
||||
putForm,
|
||||
Object.assign(
|
||||
@@ -317,6 +322,7 @@ function renderTable(
|
||||
"New"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return [
|
||||
m(
|
||||
@@ -339,13 +345,13 @@ const component = {
|
||||
}
|
||||
|
||||
function onFilterChanged(filter) {
|
||||
let ops = { filter };
|
||||
const ops = { filter };
|
||||
if (vnode.attrs.sort) ops.sort = vnode.attrs.sort;
|
||||
m.route.set("/provisions", ops);
|
||||
}
|
||||
|
||||
function onSortChange(sort) {
|
||||
let ops = { sort };
|
||||
const ops = { sort };
|
||||
if (vnode.attrs.filter) ops.filter = vnode.attrs.filter;
|
||||
m.route.set("/provisions", ops);
|
||||
}
|
||||
@@ -354,18 +360,20 @@ const component = {
|
||||
let filter = vnode.attrs.filter ? memoizedParse(vnode.attrs.filter) : true;
|
||||
filter = unpackSmartQuery(filter);
|
||||
|
||||
let provisions = store.fetch("provisions", filter, {
|
||||
const provisions = store.fetch("provisions", filter, {
|
||||
limit: vnode.state.showCount || PAGE_SIZE,
|
||||
sort: sort
|
||||
});
|
||||
|
||||
let count = store.count("provisions", filter);
|
||||
const count = store.count("provisions", filter);
|
||||
|
||||
let selected = new Set();
|
||||
if (vnode.state.selected)
|
||||
for (let provision of provisions.value)
|
||||
const selected = new Set();
|
||||
if (vnode.state.selected) {
|
||||
for (const provision of provisions.value) {
|
||||
if (vnode.state.selected.has(provision["_id"]))
|
||||
selected.add(provision["_id"]);
|
||||
}
|
||||
}
|
||||
vnode.state.selected = selected;
|
||||
|
||||
const downloadUrl = getDownloadUrl(vnode.attrs.filter);
|
||||
|
||||
Reference in new issue
Block a user