From 87c481105179c1032f2b50543ff0d27dfc375560 Mon Sep 17 00:00:00 2001 From: Ivan Schneider Date: Sat, 4 Nov 2023 13:34:37 +0100 Subject: [PATCH] Prettier --- app/assets/javascripts/advanced_search.js | 50 ++++-- app/assets/javascripts/autolinks.js | 16 +- app/assets/javascripts/bootstrap.js | 9 +- app/assets/javascripts/cell_filters.js | 14 +- app/assets/javascripts/collaborators.js | 18 +- app/assets/javascripts/docs.js | 6 +- app/assets/javascripts/enumerate_input.js | 22 ++- app/assets/javascripts/forms.js | 34 +++- app/assets/javascripts/settings.js | 28 ++- app/assets/javascripts/sorted_table.js | 4 +- app/assets/javascripts/text_edition.js | 196 ++++++++++++++++++--- app/assets/javascripts/timezone_select2.js | 10 +- 12 files changed, 322 insertions(+), 85 deletions(-) diff --git a/app/assets/javascripts/advanced_search.js b/app/assets/javascripts/advanced_search.js index ac4b6452..a60d53e1 100644 --- a/app/assets/javascripts/advanced_search.js +++ b/app/assets/javascripts/advanced_search.js @@ -1,7 +1,17 @@ -const unary_operators = ['null', 'not_null', 'present', 'blank', 'is_true', 'is_false', 'today', 'yesterday', - 'this_week', 'last_week'] +const unary_operators = [ + 'null', + 'not_null', + 'present', + 'blank', + 'is_true', + 'is_false', + 'today', + 'yesterday', + 'this_week', + 'last_week' +] -const updateFilterForm = (select) => { +const updateFilterForm = select => { const operator = select.val() const operand = select.parents('tr').find('.operand') const visibility = unary_operators.indexOf(operator) === -1 @@ -10,28 +20,36 @@ const updateFilterForm = (select) => { if (operand.data('type') === 'integer' && operator !== 'IN') { if (operand.data('original-type') !== 'integer') operand.get(0).step = 'any' type = 'number' - } else if (operand.data('type') === 'date') - type = 'date' - else - type = 'text' + } else if (operand.data('type') === 'date') type = 'date' + else type = 'text' operand.get(0).type = type } const setupAdvancedSearch = () => { - $('table.filters').on('click', 'span.btn', function(){ $(this).parents('tr').remove() }) - $('table.filters').on('change', 'td.operators select', (evt) => updateFilterForm($(evt.currentTarget))) - $('table.filters td.operators select').each((_, select) => { updateFilterForm($(select)) }) - $("#new_filter").on('change', (event) => { + $('table.filters').on('click', 'span.btn', function () { + $(this).parents('tr').remove() + }) + $('table.filters').on('change', 'td.operators select', evt => + updateFilterForm($(evt.currentTarget)) + ) + $('table.filters td.operators select').each((_, select) => + updateFilterForm($(select)) + ) + $('#new_filter').on('change', event => { const column_name = event.target.value if (!column_name) return const optgroup = $(event.target).find(':selected').closest('optgroup') $('#new_filter').val('').trigger('change') const table = $('#new_filter').data('table') - $.get(`/settings/${table}`, {column_name, assoc: optgroup.data('name')}, (resp) => { - filterDiv = $('').append(resp).appendTo($('.filters')) - selectFilter = filterDiv.find('td.operators select').focus() - updateFilterForm(selectFilter) - }) + $.get( + `/settings/${table}`, + { column_name, assoc: optgroup.data('name') }, + resp => { + filterDiv = $('').append(resp).appendTo($('.filters')) + selectFilter = filterDiv.find('td.operators select').focus() + updateFilterForm(selectFilter) + } + ) }) } diff --git a/app/assets/javascripts/autolinks.js b/app/assets/javascripts/autolinks.js index 2b3f5b27..e1b5a3cc 100644 --- a/app/assets/javascripts/autolinks.js +++ b/app/assets/javascripts/autolinks.js @@ -1,15 +1,23 @@ const autolinkQueryResults = () => { - $('.table td, dl dd').each(function(){ + $('.table td, dl dd').each(function () { const text = $(this).text() if (text.match(/^\S+@\S+\.\S+$/)) { - $(this).append(` `) + $(this).append( + ` ` + ) } else { if (text.match(/\d+\.\d+/)) { return // Skip processing for numeric patterns with a dot } - if (text.match(/^((http|ftp|https):\/\/)?[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?$/)) { + if ( + text.match( + /^((http|ftp|https):\/\/)?[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?$/ + ) + ) { const link = text.match('://') ? text : `http://${text}` - $(this).append(` `) + $(this).append( + ` ` + ) } } }) diff --git a/app/assets/javascripts/bootstrap.js b/app/assets/javascripts/bootstrap.js index af023593..07daa35e 100644 --- a/app/assets/javascripts/bootstrap.js +++ b/app/assets/javascripts/bootstrap.js @@ -13,8 +13,13 @@ const adminiumSelect2Matcher = (params, data) => { } $(() => { - $('span[rel=tooltip], button[rel=tooltip], a[rel*=tooltip], i[rel=tooltip]').tooltip({ container: 'body' }) - $("a.text-more, span.text-more, i.text-more").popover({ trigger: 'hover', html: true }) + $( + 'span[rel=tooltip], button[rel=tooltip], a[rel*=tooltip], i[rel=tooltip]' + ).tooltip({ container: 'body' }) + $('a.text-more, span.text-more, i.text-more').popover({ + trigger: 'hover', + html: true + }) sh_highlightDocument() }) diff --git a/app/assets/javascripts/cell_filters.js b/app/assets/javascripts/cell_filters.js index f3b4ba68..070a8f36 100644 --- a/app/assets/javascripts/cell_filters.js +++ b/app/assets/javascripts/cell_filters.js @@ -11,15 +11,19 @@ const addClause = (clauseType, elt) => { location.href = updatedHref } -const setupCellFilter = (elt) => { +const setupCellFilter = elt => { td = $(elt.currentTarget) if (!td.find('i.fa-indent').length) { - $('').appendTo(td) - $('').appendTo(td) + $( + '' + ).appendTo(td) + $( + '' + ).appendTo(td) } } $('.items-list') .on('mouseover', 'td[data-raw-value], td.nilclass', setupCellFilter) - .on('click', 'td i.fa-indent', (elt) => addClause('where', elt)) - .on('click', 'td i.fa-outdent', (elt) => addClause('exclude', elt)) + .on('click', 'td i.fa-indent', elt => addClause('where', elt)) + .on('click', 'td i.fa-outdent', elt => addClause('exclude', elt)) diff --git a/app/assets/javascripts/collaborators.js b/app/assets/javascripts/collaborators.js index a0e5afb7..7cdb9abf 100644 --- a/app/assets/javascripts/collaborators.js +++ b/app/assets/javascripts/collaborators.js @@ -1,12 +1,18 @@ -$("input[name=all_actions]").click(function(){ - const scope = $(this).closest("tr").find("input:not(:first)") +$('input[name=all_actions]').click(function () { + const scope = $(this).closest('tr').find('input:not(:first)') scope.prop('checked', this.checked) }) -const column_check = (index) => { +const column_check = index => { return () => { - const checked = $("table").find(`tr:first-child th:nth-child(${index+2}) input[type=checkbox]`).get(0).checked - const scope = $("table").find(`td:nth-child(${index+3}) input[type=checkbox]`) + const checked = $('table') + .find(`tr:first-child th:nth-child(${index + 2}) input[type=checkbox]`) + .get(0).checked + const scope = $('table').find( + `td:nth-child(${index + 3}) input[type=checkbox]` + ) scope.prop('checked', checked) } } -["create", "read", "update", "delete"].forEach((action, index) => $(`input[name=${action}_all]`).click(column_check(index))) +;['create', 'read', 'update', 'delete'].forEach((action, index) => + $(`input[name=${action}_all]`).click(column_check(index)) +) diff --git a/app/assets/javascripts/docs.js b/app/assets/javascripts/docs.js index 4df0ea97..cd8bc44f 100644 --- a/app/assets/javascripts/docs.js +++ b/app/assets/javascripts/docs.js @@ -1,5 +1,7 @@ $('#cancel_tip').on('ajax:complete', (et, e) => { if (!JSON.parse(e.responseText)) return - $("#welcome-modal .modal-footer").html("

Okay, tips will not appear anymore

") - setTimeout(() => $("#welcome-modal").modal('hide'), 1500) + $('#welcome-modal .modal-footer').html( + "

Okay, tips will not appear anymore

" + ) + setTimeout(() => $('#welcome-modal').modal('hide'), 1500) }) diff --git a/app/assets/javascripts/enumerate_input.js b/app/assets/javascripts/enumerate_input.js index 12da5407..95e6f141 100644 --- a/app/assets/javascripts/enumerate_input.js +++ b/app/assets/javascripts/enumerate_input.js @@ -3,23 +3,27 @@ class EnumerateInput { if (!input[0]) return const column = input[0].name.match(/\[(.*)\]/)[1] this.values = adminium_column_options[column].values - input.select2({ templateResult: (state) => { return this.format(state) } }) + input.select2({ templateResult: state => this.format(state) }) if (action) input.select2(action) } - format(state){ + format(state) { if (this.values[state.id]) - return $('
').addClass('label label-info').css('background-color', this.values[state.id].color).text(state.text) - else - return state.text + return $('
') + .addClass('label label-info') + .css('background-color', this.values[state.id].color) + .text(state.text) + else return state.text } } $(() => { const editForm = $('body.resources.edit form') if (!editForm.length) return - Object.keys(adminium_column_options).filter((key) => adminium_column_options[key].is_enum).forEach((key) => { - const field = editForm.find(`select[id*=_${key}]`) - new EnumerateInput(field) - }) + Object.keys(adminium_column_options) + .filter(key => adminium_column_options[key].is_enum) + .forEach(key => { + const field = editForm.find(`select[id*=_${key}]`) + new EnumerateInput(field) + }) }) diff --git a/app/assets/javascripts/forms.js b/app/assets/javascripts/forms.js index 14f96d3a..60842686 100644 --- a/app/assets/javascripts/forms.js +++ b/app/assets/javascripts/forms.js @@ -1,27 +1,43 @@ const hstoreInput = () => { - $(document).on('click', '.hstore-row .btn', function(){ + $(document).on('click', '.hstore-row .btn', function () { row = $(this).closest('.hstore-row') row.next().find('input, a.btn').get(0).focus() row.remove() }) - $(document).on('click', '.hstore-new-row .btn', function(){ + $(document).on('click', '.hstore-new-row .btn', function () { parent = $(this).closest('.hstore-edition') - parent.find('.hstore-row.hidden').first().clone() - .insertBefore(parent.find('.hstore-new-row')).removeClass('hidden') - .find('input').val('').get(0).focus() + parent + .find('.hstore-row.hidden') + .first() + .clone() + .insertBefore(parent.find('.hstore-new-row')) + .removeClass('hidden') + .find('input') + .val('') + .get(0) + .focus() }) } const autofocusResourceForm = () => { if (!$('form.resource-form').length) return - $('form.resource-form').find('input, select').filter(':visible:not([readonly])')[0]?.focus() - NullifiableInput.setup('form.resource-form input, form.resource-form textarea', false) + $('form.resource-form') + .find('input, select') + .filter(':visible:not([readonly])')[0] + ?.focus() + NullifiableInput.setup( + 'form.resource-form input, form.resource-form textarea', + false + ) } const newCollaboratorForm = () => { if (!$('#new_collaborator').length) return - $('#new_collaborator input.radio_buttons').on('change', function(){ - $('#new_collaborator input.check_boxes').attr({ disabled: this.value === 'true', checked: this.value === false }) + $('#new_collaborator input.radio_buttons').on('change', function () { + $('#new_collaborator input.check_boxes').attr({ + disabled: this.value === 'true', + checked: this.value === false + }) }) } diff --git a/app/assets/javascripts/settings.js b/app/assets/javascripts/settings.js index 845d12e0..e34aef8b 100644 --- a/app/assets/javascripts/settings.js +++ b/app/assets/javascripts/settings.js @@ -1,6 +1,6 @@ const setupValidations = () => { const pane = $('#validations_pane') - pane.on('click', '.remove', function(){ + pane.on('click', '.remove', function () { index = $(this).closest('tr').index() $(this).closest('tr').remove() input = pane.find('.params input').eq(index * 2) @@ -13,15 +13,33 @@ const setupValidations = () => { $('').text(validator.text()).appendTo(tr) $('').text(column_name.text()).appendTo(tr) $('').append($('')).appendTo(tr) - pane.find('.params').append($('').attr({ name: "validations[][validator]", value: validator.val() })) - pane.find('.params').append($('').attr({ name: "validations[][column_name]", value: column_name.val() })) + pane + .find('.params') + .append( + $('').attr({ + name: 'validations[][validator]', + value: validator.val() + }) + ) + pane + .find('.params') + .append( + $('').attr({ + name: 'validations[][column_name]', + value: column_name.val() + }) + ) return false }) } const masterCheckboxes = () => { - $('.master_checkbox input').on('change', function(){ - $(this).closest('ul').next().find('input[type="checkbox"]').prop('checked', $(this).prop('checked')) + $('.master_checkbox input').on('change', function () { + $(this) + .closest('ul') + .next() + .find('input[type="checkbox"]') + .prop('checked', $(this).prop('checked')) }) } diff --git a/app/assets/javascripts/sorted_table.js b/app/assets/javascripts/sorted_table.js index cf129a01..787c3244 100644 --- a/app/assets/javascripts/sorted_table.js +++ b/app/assets/javascripts/sorted_table.js @@ -1,7 +1,7 @@ -const makeSortable = (selector) => { +const makeSortable = selector => { const table = $(selector) if (!table.length) return - table.on('click', 'th', (e) => { + table.on('click', 'th', e => { order = $(e.currentTarget).data('order') || 'desc' orderMul = order === 'desc' ? -1 : 1 $(e.currentTarget).data('order', order === 'desc' ? 'asc' : 'desc') diff --git a/app/assets/javascripts/text_edition.js b/app/assets/javascripts/text_edition.js index 43c9ab2a..208ba9de 100644 --- a/app/assets/javascripts/text_edition.js +++ b/app/assets/javascripts/text_edition.js @@ -1,49 +1,199 @@ -const fullTagList = ["a", "abbr", "acronym", "address", "applet", "area", "article", "aside", "audio", "b", "base", "basefont", "bdi", "bdo", "bgsound", "big", "blink", "blockquote", "body", "br", "button", "canvas", "caption", "center", "cite", "code", "col", "colgroup", "command", "data", "datalist", "dd", "del", "details", "dfn", "dir", "div", "dl", "dt", "em", "embed", "fieldset", "figcaption", "figure", "font", "footer", "form", "frame", "frameset", "h1", "h2", "h3", "h4", "h5", "h6", "head", "header", "hgroup", "hr", "html", "i", "iframe", "img", "input", "ins", "isindex", "kbd", "keygen", "label", "legend", "li", "link", "listing", "main", "map", "mark", "marquee", "menu", "meta", "meter", "nav", "nobr", "noframes", "noscript", "object", "ol", "optgroup", "option", "output", "p", "param", "plaintext", "pre", "progress", "q", "rp", "rt", "ruby", "s", "samp", "script", "section", "select", "small", "source", "spacer", "span", "strike", "strong", "style", "sub", "summary", "sup", "table", "tbody", "td", "textarea", "tfoot", "th", "thead", "time", "title", "tr", "track", "tt", "u", "ul", "var", "video", "wbr", "xmp"] +const fullTagList = [ + 'a', + 'abbr', + 'acronym', + 'address', + 'applet', + 'area', + 'article', + 'aside', + 'audio', + 'b', + 'base', + 'basefont', + 'bdi', + 'bdo', + 'bgsound', + 'big', + 'blink', + 'blockquote', + 'body', + 'br', + 'button', + 'canvas', + 'caption', + 'center', + 'cite', + 'code', + 'col', + 'colgroup', + 'command', + 'data', + 'datalist', + 'dd', + 'del', + 'details', + 'dfn', + 'dir', + 'div', + 'dl', + 'dt', + 'em', + 'embed', + 'fieldset', + 'figcaption', + 'figure', + 'font', + 'footer', + 'form', + 'frame', + 'frameset', + 'h1', + 'h2', + 'h3', + 'h4', + 'h5', + 'h6', + 'head', + 'header', + 'hgroup', + 'hr', + 'html', + 'i', + 'iframe', + 'img', + 'input', + 'ins', + 'isindex', + 'kbd', + 'keygen', + 'label', + 'legend', + 'li', + 'link', + 'listing', + 'main', + 'map', + 'mark', + 'marquee', + 'menu', + 'meta', + 'meter', + 'nav', + 'nobr', + 'noframes', + 'noscript', + 'object', + 'ol', + 'optgroup', + 'option', + 'output', + 'p', + 'param', + 'plaintext', + 'pre', + 'progress', + 'q', + 'rp', + 'rt', + 'ruby', + 's', + 'samp', + 'script', + 'section', + 'select', + 'small', + 'source', + 'spacer', + 'span', + 'strike', + 'strong', + 'style', + 'sub', + 'summary', + 'sup', + 'table', + 'tbody', + 'td', + 'textarea', + 'tfoot', + 'th', + 'thead', + 'time', + 'title', + 'tr', + 'track', + 'tt', + 'u', + 'ul', + 'var', + 'video', + 'wbr', + 'xmp' +] class TextEdition { - constructor(){ - this.pref = localStorage.getItem('text_edition_preference') || 'rich_text_editor' + constructor() { + this.pref = + localStorage.getItem('text_edition_preference') || 'rich_text_editor' this.applyPreference() - $(document).on('click', '.text-edition-switch', () => { this.switchEditionPreference() }) + $(document).on('click', '.text-edition-switch', () => + this.switchEditionPreference() + ) } - applyPreference(){ - if (this.pref === 'rich_text_editor') - this.enableRichTextEditor() - else - this.disableRichTextEditor() + applyPreference() { + if (this.pref === 'rich_text_editor') this.enableRichTextEditor() + else this.disableRichTextEditor() this.addSwitchingLinks() } - enableRichTextEditor(){ + enableRichTextEditor() { const parserRules = { tags: {} } - fullTagList.forEach((tag) => { - parserRules.tags[tag] = {check_attributes: {}} - }) + fullTagList.forEach( + tag => (parserRules.tags[tag] = { check_attributes: {} }) + ) parserRules.tags['a'].check_attributes = { href: 'url', target: 'alt' } - $('form.resource-form textarea').wysihtml5({ html: true, parserRules: parserRules, toolbar: {fa: true} }) + $('form.resource-form textarea').wysihtml5({ + html: true, + parserRules: parserRules, + toolbar: { fa: true } + }) } - disableRichTextEditor(){ + disableRichTextEditor() { $("iframe.wysihtml5-sandbox, input[name='_wysihtml5_mode']").remove() - $("body").removeClass("wysihtml5-supported") + $('body').removeClass('wysihtml5-supported') $('.wysihtml5-toolbar').remove() $('form.resource-form textarea').css('display', 'block') } - addSwitchingLinks(){ + addSwitchingLinks() { $('.text-edition-switch').remove() - const text = this.pref === 'rich_text_editor' ? ' Plain text area' : ' Rich text editor' + const text = + this.pref === 'rich_text_editor' + ? ' Plain text area' + : ' Rich text editor' $('form.resource-form textarea').each((_, textarea) => - $(textarea).parent().append($('').html(text).attr('href', '#').addClass('text-edition-switch')) + $(textarea) + .parent() + .append( + $('') + .html(text) + .attr('href', '#') + .addClass('text-edition-switch') + ) ) } - switchEditionPreference(){ - this.pref = this.pref === 'rich_text_editor' ? 'plain_text_area' : 'rich_text_editor' + switchEditionPreference() { + this.pref = + this.pref === 'rich_text_editor' ? 'plain_text_area' : 'rich_text_editor' localStorage.setItem('text_edition_preference', this.pref) this.applyPreference() } } - -$(() => { new TextEdition() }) + +$(() => { + new TextEdition() +}) diff --git a/app/assets/javascripts/timezone_select2.js b/app/assets/javascripts/timezone_select2.js index 75ee16ba..aac9e7ee 100644 --- a/app/assets/javascripts/timezone_select2.js +++ b/app/assets/javascripts/timezone_select2.js @@ -1,4 +1,10 @@ $(() => { - const format = (state) => $('').html(state.text.replace(')', ')').replace('(GMT', '(GMT')) - $('.timezone_select2').select2({ templateResult: format, placeholder: '(GMT+00:00) UTC' }) + const format = state => + $('').html( + state.text.replace(')', ')').replace('(GMT', '(GMT') + ) + $('.timezone_select2').select2({ + templateResult: format, + placeholder: '(GMT+00:00) UTC' + }) })