Skip to content

Commit

Permalink
Prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
isc committed Nov 4, 2023
1 parent 9df2195 commit 87c4811
Show file tree
Hide file tree
Showing 12 changed files with 322 additions and 85 deletions.
50 changes: 34 additions & 16 deletions app/assets/javascripts/advanced_search.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 = $('<tr>').append(resp).appendTo($('.filters'))
selectFilter = filterDiv.find('td.operators select').focus()
updateFilterForm(selectFilter)
})
$.get(
`/settings/${table}`,
{ column_name, assoc: optgroup.data('name') },
resp => {
filterDiv = $('<tr>').append(resp).appendTo($('.filters'))
selectFilter = filterDiv.find('td.operators select').focus()
updateFilterForm(selectFilter)
}
)
})
}

Expand Down
16 changes: 12 additions & 4 deletions app/assets/javascripts/autolinks.js
Original file line number Diff line number Diff line change
@@ -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(` <a target="_blank" title='send an email to this address' href="mailto:${text}"><i class='fa fa-envelope subtle'></i></a>`)
$(this).append(
` <a target="_blank" title='send an email to this address' href="mailto:${text}"><i class='fa fa-envelope subtle'></i></a>`
)
} else {
if (text.match(/\d+\.\d+/)) {
return // Skip processing for numeric patterns with a dot
}
if (text.match(/^((http|ftp|https):\/\/)?[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&amp;:\/~\+#]*[\w\-\@?^=%&amp;\/~\+#])?$/)) {
if (
text.match(
/^((http|ftp|https):\/\/)?[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&amp;:\/~\+#]*[\w\-\@?^=%&amp;\/~\+#])?$/
)
) {
const link = text.match('://') ? text : `http://${text}`
$(this).append(` <a target="_blank" href="${link}" title='open a new page to this URL'><i class='fa fa-external-link subtle'></i></a>`)
$(this).append(
` <a target="_blank" href="${link}" title='open a new page to this URL'><i class='fa fa-external-link subtle'></i></a>`
)
}
}
})
Expand Down
9 changes: 7 additions & 2 deletions app/assets/javascripts/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})

Expand Down
14 changes: 9 additions & 5 deletions app/assets/javascripts/cell_filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
$('<i class="fa fa-indent cell-action"" title="Select rows with this value">').appendTo(td)
$('<i class="fa fa-outdent cell-action"" title="Exclude rows with this value">').appendTo(td)
$(
'<i class="fa fa-indent cell-action"" title="Select rows with this value">'
).appendTo(td)
$(
'<i class="fa fa-outdent cell-action"" title="Exclude rows with this value">'
).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))
18 changes: 12 additions & 6 deletions app/assets/javascripts/collaborators.js
Original file line number Diff line number Diff line change
@@ -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))
)
6 changes: 4 additions & 2 deletions app/assets/javascripts/docs.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
$('#cancel_tip').on('ajax:complete', (et, e) => {
if (!JSON.parse(e.responseText)) return
$("#welcome-modal .modal-footer").html("<p class='alert alert-info'>Okay, tips will not appear anymore</p>")
setTimeout(() => $("#welcome-modal").modal('hide'), 1500)
$('#welcome-modal .modal-footer').html(
"<p class='alert alert-info'>Okay, tips will not appear anymore</p>"
)
setTimeout(() => $('#welcome-modal').modal('hide'), 1500)
})
22 changes: 13 additions & 9 deletions app/assets/javascripts/enumerate_input.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 $('<div>').addClass('label label-info').css('background-color', this.values[state.id].color).text(state.text)
else
return state.text
return $('<div>')
.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)
})
})
34 changes: 25 additions & 9 deletions app/assets/javascripts/forms.js
Original file line number Diff line number Diff line change
@@ -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
})
})
}

Expand Down
28 changes: 23 additions & 5 deletions app/assets/javascripts/settings.js
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -13,15 +13,33 @@ const setupValidations = () => {
$('<td>').text(validator.text()).appendTo(tr)
$('<td>').text(column_name.text()).appendTo(tr)
$('<td>').append($('<i class="fa fa-minus-circle remove">')).appendTo(tr)
pane.find('.params').append($('<input type="hidden">').attr({ name: "validations[][validator]", value: validator.val() }))
pane.find('.params').append($('<input type="hidden">').attr({ name: "validations[][column_name]", value: column_name.val() }))
pane
.find('.params')
.append(
$('<input type="hidden">').attr({
name: 'validations[][validator]',
value: validator.val()
})
)
pane
.find('.params')
.append(
$('<input type="hidden">').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'))
})
}

Expand Down
4 changes: 2 additions & 2 deletions app/assets/javascripts/sorted_table.js
Original file line number Diff line number Diff line change
@@ -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')
Expand Down
Loading

0 comments on commit 87c4811

Please sign in to comment.