From 3dbba33c3d83947f8acdfcb718e76e304db43593 Mon Sep 17 00:00:00 2001 From: Martin Constante Date: Mon, 21 Nov 2022 13:44:49 +0100 Subject: [PATCH 1/2] Fix scrool and increase coverage --- cen/static/example.md | 4 -- cen/static/js/delivery.js | 136 -------------------------------------- cen/static/js/settings.js | 4 +- cen/static/settings.html | 6 +- tests/settings.spec.js | 62 ++++++++++++++--- 5 files changed, 54 insertions(+), 158 deletions(-) delete mode 100644 cen/static/js/delivery.js diff --git a/cen/static/example.md b/cen/static/example.md index 26b3fec..cb4b3b7 100644 --- a/cen/static/example.md +++ b/cen/static/example.md @@ -1,20 +1,16 @@ ![logo](https://www.cloudblue.com/assets/images/navlogo-dark.png) # Sample activation email template - Dear **{{request.asset.tiers.customer.name}}** Your subscription **{{request.asset.id}}** for **{{request.asset.product.name}}** has been activated. - This subscription contains the following items: - {% for item in request.asset['items'] %} {{ item.display_name }} : {{ item.quantity }} {% endfor %} Your subscription has been enabled using following parameters that maybe useful in order to use your subscription. - {% for param in request.asset['params'] %} {{ param.id }} : {{ param.value }} {% endfor %} diff --git a/cen/static/js/delivery.js b/cen/static/js/delivery.js deleted file mode 100644 index a0e6b12..0000000 --- a/cen/static/js/delivery.js +++ /dev/null @@ -1,136 +0,0 @@ -import createApp from '/static/js/toolkit.js'; -const app = createApp({}); - -app.listen('$init', main); - -export async function getEmailLogsList(limit, offset, search) { - const response = await fetch(`/api/email_tasks?search=${search}&limit=${limit}&offset=${offset}`); - let body = await response.json(); - return body; -} - -async function main() { - - let offset = 0; - let search = ''; - document.getElementById("EmailLogsTable").style.display = 'inline'; - var t = $('#task-list-table').DataTable({ - 'paging': false, - 'searching': false, - 'info': false, - 'serverSide': true, - 'processing': true, - 'buttons': [ - 'searchPanes' - ], - 'ajax': async function (data, callback, settings) { - - const limit = $('#select-rows-per-page').val(); - let res = await getEmailLogsList(limit, offset, $('#search-input').val()); - let count = res.count; - res = { 'data': res.results }; - if (offset <= 1) { - $('#page-down').addClass('disabled'); - } else { - $('#page-down').removeClass('disabled'); - } - let pageMax = parseFloat(offset) + parseFloat(limit) - 1; - if (pageMax >= count) { - $('#page-up').addClass('disabled'); - pageMax = count; - } else { - $('#page-up').removeClass('disabled'); - } - - $('#page-total').html(count); - $('#page-min').html(parseFloat(offset)+1); - $('#page-max').html(pageMax); - callback(res); - }, - 'columns': [ - { 'data': 'id' }, - { - 'data': 'product_logo', render: function (data, type, row, meta) { - return `
Logo
-
${row['product_name']}
-
${row['product_id']}
-
` - } - }, - { 'data': 'email_to' }, - { - 'data': 'date', render: function (data, type, row, meta) { - return moment.utc(data).format('MMMM Do YYYY, h:mm:ss a'); - } - }, - { - 'data': 'date', render: function (data, type, row, meta) { - return ``; - } - }, - ], - }); - - $('#search-input').keyup(function () { - if ($(this).val().length==0 || $(this).val().length>3) { - console.log('Redrawing table, searching for', $(this).val()); - t.ajax.reload(); - } - - }); - - $('#select-rows-per-page').change(function () { - t.ajax.reload(); - }); - - $('#page-down').click(function () { - const limit = $('#select-rows-per-page').val(); - offset = (parseFloat(offset) - parseFloat(limit)); - if (offset < 0) offset = 0; - t.ajax.reload(); - }); - - $('#page-up').click(function () { - const limit = $('#select-rows-per-page').val(); - offset = parseFloat(offset) + parseFloat(limit); - t.ajax.reload(); - }); - - const mailDetailModal = document.getElementById('mailDetailModal'); - mailDetailModal.addEventListener('show.mdb.modal', async (e) => { - console.log('pepito'); - const button = e.relatedTarget; - const recipient = button.getAttribute('data-mdb-whatever'); - const response = await fetch(`/api/email_task/${recipient}`); - const body = await response.json(); - console.log(body); - const dateEmail = moment.utc(body['date']).format('MMMM Do YYYY, h:mm:ss a'); - - $('#email-from').html(body['email_from']); - $('#email-to').html(body['email_to']); - $('#date').html(dateEmail); - $('#product-id').html(body['product_id']); - $('#product-name').html(body['product_name']); - $('#asset-id').html(body['asset_id']); - $('#request-id').html(body['request_id']); - $('#email-content').html(body['body']); - - const modalBody = mailDetailModal.getElementsByClassName('modal-dialog')[0]; - const container = document.getElementById('container'); - - if (modalBody.offsetHeight >= container.offsetHeight) { - const height = modalBody.offsetHeight + 150; - app.emit('$size', { height }); - } - }); - - mailDetailModal.addEventListener('hide.mdb.modal', async (e) => { - const container = document.getElementById('container'); - const height = container.offsetHeight; - app.emit('$size', { height }); - t.destroy(); - main(); - }); - app.emit('$size', { height: 800 }); -} diff --git a/cen/static/js/settings.js b/cen/static/js/settings.js index bb1adb1..fde071f 100644 --- a/cen/static/js/settings.js +++ b/cen/static/js/settings.js @@ -17,13 +17,13 @@ export async function getSettings() { return body; } -async function getRule(id) { +export async function getRule(id) { const response = await fetch(`/api/rules/${id}`); const body = await response.json(); return body; } -async function getRulesProducts() { +export async function getRulesProducts() { const response = await fetch('/api/products'); const body = await response.json(); return body; diff --git a/cen/static/settings.html b/cen/static/settings.html index afe1d86..49d5c08 100644 --- a/cen/static/settings.html +++ b/cen/static/settings.html @@ -105,10 +105,6 @@