Skip to content

Commit

Permalink
Merge dev
Browse files Browse the repository at this point in the history
  • Loading branch information
hkalexling committed Aug 19, 2022
1 parent f8c569f commit 5bdeca9
Showing 1 changed file with 71 additions and 79 deletions.
150 changes: 71 additions & 79 deletions public/js/subscription-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,86 +13,78 @@ const component = () => {
if (!data.success) throw new Error(data.error);
this.plugins = data.plugins;

let pid = localStorage.getItem("plugin");
if (!pid || !this.plugins.find((p) => p.id === pid)) {
pid = this.plugins[0].id;
}
let pid = localStorage.getItem('plugin');
if (!pid || !this.plugins.find((p) => p.id === pid)) {
pid = this.plugins[0].id;
}

this.pid = pid;
this.list(pid);
})
.catch((e) => {
alert(
"danger",
`Failed to list the available plugins. Error: ${e}`
);
});
},
pluginChanged() {
localStorage.setItem("plugin", this.pid);
this.list(this.pid);
},
list(pid) {
if (!pid) return;
fetch(
`${base_url}api/admin/plugin/subscriptions?${new URLSearchParams(
{
plugin: pid,
}
)}`,
{
method: "GET",
}
)
.then((response) => response.json())
.then((data) => {
if (!data.success) throw new Error(data.error);
this.subscriptions = data.subscriptions;
})
.catch((e) => {
alert(
"danger",
`Failed to list subscriptions. Error: ${e}`
);
});
},
renderStrCell(str) {
const maxLength = 40;
if (str.length > maxLength)
return `<td><span>${str.substring(
0,
maxLength
)}...</span><div uk-dropdown>${str}</div></td>`;
return `<td>${str}</td>`;
},
renderDateCell(timestamp) {
return `<td>${moment
.duration(moment.unix(timestamp).diff(moment()))
.humanize(true)}</td>`;
},
selected(event, modal) {
const id = event.currentTarget.getAttribute("sid");
this.subscription = this.subscriptions.find((s) => s.id === id);
UIkit.modal(modal).show();
},
renderFilterRow(ft) {
const key = ft.key;
let type = ft.type;
switch (type) {
case "number-min":
type = "number (minimum value)";
break;
case "number-max":
type = "number (maximum value)";
break;
case "date-min":
type = "minimum date";
break;
case "date-max":
type = "maximum date";
break;
}
let value = ft.value;
this.pid = pid;
this.list(pid);
})
.catch((e) => {
alert('danger', `Failed to list the available plugins. Error: ${e}`);
});
},
pluginChanged() {
localStorage.setItem('plugin', this.pid);
this.list(this.pid);
},
list(pid) {
if (!pid) return;
fetch(
`${base_url}api/admin/plugin/subscriptions?${new URLSearchParams({
plugin: pid,
})}`,
{
method: 'GET',
},
)
.then((response) => response.json())
.then((data) => {
if (!data.success) throw new Error(data.error);
this.subscriptions = data.subscriptions;
})
.catch((e) => {
alert('danger', `Failed to list subscriptions. Error: ${e}`);
});
},
renderStrCell(str) {
const maxLength = 40;
if (str.length > maxLength)
return `<td><span>${str.substring(
0,
maxLength,
)}...</span><div uk-dropdown>${str}</div></td>`;
return `<td>${str}</td>`;
},
renderDateCell(timestamp) {
return `<td>${moment
.duration(moment.unix(timestamp).diff(moment()))
.humanize(true)}</td>`;
},
selected(event, modal) {
const id = event.currentTarget.getAttribute('sid');
this.subscription = this.subscriptions.find((s) => s.id === id);
UIkit.modal(modal).show();
},
renderFilterRow(ft) {
const key = ft.key;
let type = ft.type;
switch (type) {
case 'number-min':
type = 'number (minimum value)';
break;
case 'number-max':
type = 'number (maximum value)';
break;
case 'date-min':
type = 'minimum date';
break;
case 'date-max':
type = 'maximum date';
break;
}
let value = ft.value;

if (ft.type.startsWith('number') && isNaN(value)) value = '';
else if (ft.type.startsWith('date') && value)
Expand Down

0 comments on commit 5bdeca9

Please sign in to comment.