Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bootstrap 5 Upgrade #1147

Merged
merged 59 commits into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
9fe0c9f
add bootstrap 5 sass assets (temporarily)
MattBudz Apr 28, 2023
366843e
add bootstrap 5 js assets (temporarily)
MattBudz Apr 28, 2023
af9fc1f
remove underline from links
MattBudz Apr 28, 2023
e654f60
update breakpoints
MattBudz Apr 28, 2023
9521715
update new xxl breakpoint to our xxl breakpoint
MattBudz Apr 28, 2023
cd35a6b
re-add `position: relative` to columns
MattBudz Apr 28, 2023
19907e8
update layout files
MattBudz May 4, 2023
67a1302
update how we call modals
MattBudz May 4, 2023
1cd6049
update simple form config
MattBudz May 4, 2023
d307d09
update projects#show
MattBudz May 4, 2023
7121842
fix breadcrumb styles
MattBudz May 4, 2023
7e5255d
init tooltips the bs5 way
MattBudz May 4, 2023
840d250
update attachments box
MattBudz May 4, 2023
a64cef8
update boards views
MattBudz May 4, 2023
144a96e
update alerts
MattBudz May 4, 2023
2660799
update simple_form gem for BS5 compatiblitly
MattBudz May 4, 2023
8b7c4c2
fix attachment collapse
MattBudz May 4, 2023
0e13e98
update missed classes in add_node modal
MattBudz May 4, 2023
9ce534d
update sidebar collection collapse + dropdown
MattBudz May 4, 2023
939cdb2
update cards views
MattBudz May 4, 2023
ae5ba0b
simple form tweaks
MattBudz May 4, 2023
1f87467
update comments views
MattBudz May 5, 2023
0c71053
fix secondary sidebar position
MattBudz May 5, 2023
b5607d8
update configurations views
MattBudz May 5, 2023
858f2c0
update console
MattBudz May 5, 2023
43d5e3e
differentiate between our placeholder class and bs5's placeholder classs
MattBudz May 5, 2023
86a5c65
update evidence views
MattBudz May 5, 2023
a7b5ef4
update main app export view
MattBudz May 5, 2023
164313e
update field partial
MattBudz May 5, 2023
f8dacde
update js that opens dropdowns programatically
MattBudz May 5, 2023
99f5288
update js for switching tabs
MattBudz May 5, 2023
08da893
update issues views
MattBudz May 5, 2023
7578ef7
update nodes views
MattBudz May 5, 2023
f591ca0
update notes views
MattBudz May 5, 2023
16599d6
update notifications views/partials
MattBudz May 5, 2023
d1a9e22
update QA views
MattBudz May 8, 2023
734fd9b
fix rounded button styles in QA widget
MattBudz May 8, 2023
1dd486c
update revisions view
MattBudz May 8, 2023
4010173
update search style
MattBudz May 8, 2023
fb14218
update style guide
MattBudz May 8, 2023
2924e66
update tag views
MattBudz May 9, 2023
7996397
update upload view
MattBudz May 9, 2023
1c85556
fix uploads table
MattBudz May 9, 2023
2252607
use bootstrap gem
MattBudz May 9, 2023
e3e4cf3
EOF
MattBudz May 9, 2023
9f9d4d7
update missed class changes
MattBudz May 9, 2023
9738bc1
update changelog
MattBudz May 9, 2023
2e2f560
lint
MattBudz May 9, 2023
5a42459
update missed ml-* classes
MattBudz May 9, 2023
4633be1
update specs
MattBudz May 9, 2023
43b30cc
fix header alignment
MattBudz May 9, 2023
8a25f6f
update missed data-attributes
MattBudz May 9, 2023
d139334
render dropdown menus on top of datatable footers
MattBudz May 9, 2023
10eda69
update missed `sr-only` classes
MattBudz May 9, 2023
32ba7be
show default export tab with bs classes
MattBudz May 9, 2023
c5dd4f8
update alert rendered by datatables
MattBudz May 9, 2023
5121ef6
fix datatable alerts
MattBudz May 11, 2023
bbb01bb
consistent export tabs
MattBudz May 12, 2023
b86898f
init tooltips for `<script type='text/x-tmpl'>`
MattBudz May 16, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
- [entity]:
- [future tense verb] [feature]
- Upgraded gems:
- [gem]
- bootstrap, popper_js, simple_form
- Bugs fixes:
- [entity]:
- [future tense verb] [bug fix]
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ gem 'jbuilder', '~> 2.7'
gem 'bootsnap', '>= 1.12.0', require: false

# ---------------------------------------------------- Dradis Community Edition
gem 'bootstrap', '~> 4.3.1'
gem 'bootstrap', '~> 5.2.3'
gem 'jquery-rails'
gem 'jquery-ui-rails'
gem 'jquery-fileupload-rails', '~> 0.3.4'
Expand Down
26 changes: 13 additions & 13 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,16 @@ GEM
addressable (2.8.0)
public_suffix (>= 2.0.2, < 5.0)
ast (2.4.2)
autoprefixer-rails (9.7.4)
execjs
autoprefixer-rails (10.4.13.0)
execjs (~> 2)
bcrypt (3.1.12)
bindex (0.8.1)
blankslate (3.1.3)
bootsnap (1.12.0)
msgpack (~> 1.2)
bootstrap (4.3.1)
bootstrap (5.2.3)
autoprefixer-rails (>= 9.1.0)
popper_js (>= 1.14.3, < 2)
popper_js (>= 2.11.6, < 3)
sassc-rails (>= 2.0.0)
brakeman (5.4.0)
builder (3.2.4)
Expand Down Expand Up @@ -214,7 +214,7 @@ GEM
html-pipeline (2.12.3)
activesupport (>= 2)
nokogiri (>= 1.4)
i18n (1.12.0)
i18n (1.13.0)
concurrent-ruby (~> 1.0)
image_size (1.3.1)
jbuilder (2.10.0)
Expand Down Expand Up @@ -270,7 +270,7 @@ GEM
matrix (0.4.2)
method_source (0.9.2)
mini_mime (1.1.2)
mini_portile2 (2.8.1)
mini_portile2 (2.8.2)
mini_racer (0.6.2)
libv8-node (~> 16.10.0.0)
minitest (5.18.0)
Expand Down Expand Up @@ -311,15 +311,15 @@ GEM
parslet (1.6.2)
blankslate (>= 2.0, <= 4.0)
pg (1.4.5)
popper_js (1.16.0)
popper_js (2.11.7)
pry (0.12.2)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
public_suffix (4.0.6)
puma (5.6.4)
nio4r (~> 2.0)
racc (1.6.2)
rack (2.2.6.4)
rack (2.2.7)
rack-mini-profiler (2.3.0)
rack (>= 1.2.0)
rack-protection (2.2.3)
Expand Down Expand Up @@ -443,9 +443,9 @@ GEM
shellany (0.0.1)
shoulda-matchers (3.1.3)
activesupport (>= 4.0.0)
simple_form (5.0.2)
actionpack (>= 5.0)
activemodel (>= 5.0)
simple_form (5.2.0)
actionpack (>= 5.2)
activemodel (>= 5.2)
sinatra (2.2.3)
mustermann (~> 2.0)
rack (~> 2.2)
Expand Down Expand Up @@ -497,7 +497,7 @@ GEM
chronic (>= 0.6.3)
xpath (3.2.0)
nokogiri (~> 1.8)
zeitwerk (2.6.7)
zeitwerk (2.6.8)

PLATFORMS
arm64-darwin
Expand All @@ -510,7 +510,7 @@ DEPENDENCIES
acts_as_tree (~> 2.9.1)
bcrypt (= 3.1.12)
bootsnap (>= 1.12.0)
bootstrap (~> 4.3.1)
bootstrap (~> 5.2.3)
brakeman
builder
bundler-audit
Expand Down
113 changes: 68 additions & 45 deletions app/assets/javascripts/shared/behaviors.js
Original file line number Diff line number Diff line change
@@ -1,73 +1,94 @@
(function($, window){
(function ($, window) {
function initBehaviors(parentElement) {
// Activate jQuery.Textile
$(parentElement).find('.textile').textile();

// Activate DataTables
$(parentElement).find('[data-behavior~=dradis-datatable]').each(function() {
new DradisDatatable(this);
});
$(parentElement)
.find('[data-behavior~=dradis-datatable]')
.each(function () {
new DradisDatatable(this);
});

// Activate Rich Toolbars for the editor
$(parentElement).find('[data-behavior~=rich-toolbar]').each(function() {
new EditorToolbar($(this));
$(parentElement)
.find('[data-behavior~=rich-toolbar]')
.each(function () {
new EditorToolbar($(this));

// Activate QuoteSelector after Rich toolbars
// This can be globally scoped because the QuoteSelector does not allow
// double binding
$('[data-behavior~=content-textile]').each(function() {
new QuoteSelector(this);
// Activate QuoteSelector after Rich toolbars
// This can be globally scoped because the QuoteSelector does not allow
// double binding
$('[data-behavior~=content-textile]').each(function () {
new QuoteSelector(this);
});
});
});

// Activate local auto save
$(parentElement).find('[data-behavior~=local-auto-save]').each(function() {
new LocalAutoSave(this);
});
$(parentElement)
.find('[data-behavior~=local-auto-save]')
.each(function () {
new LocalAutoSave(this);
});

// Fetch content
$(parentElement).find('[data-behavior~=fetch]').each(function() {
var that = this;
$.ajax(that.dataset.path, { credentials: 'include' })
.then(function(response) { return response; })
.then(function(html) {
$(that).html(html);
$(that).trigger('dradis:fetch');
initBehaviors(that);
});
});
$(parentElement)
.find('[data-behavior~=fetch]')
.each(function () {
var that = this;
$.ajax(that.dataset.path, { credentials: 'include' })
.then(function (response) {
return response;
})
.then(function (html) {
$(that).html(html);
$(that).trigger('dradis:fetch');
initBehaviors(that);
});
});

// Allow page anchors to work
$(parentElement).find('[data-behavior~=deeplinks] >* a').click(function (e) {
history.pushState(null, null, $(e.target).attr('href'));
});
$(parentElement)
.find('[data-behavior~=deeplinks] >* a')
.click(function (e) {
history.pushState(null, null, $(e.target).attr('href'));
});

// Show the pane for a given anchor
$(parentElement).find('[data-behavior~=deeplinks] >* a').each(function() {
if (window.location.hash == $(this).attr('href')) {
$(this).tab('show');
}
});
$(parentElement)
.find('[data-behavior~=deeplinks] >* a')
.each(function () {
if (window.location.hash == $(this).attr('href')) {
$(this).tab('show');
}
});

// Init Bootstrap tooltips
$('[data-toggle~=tooltip]').tooltip();
// Init Bootstrap tooltips with 1ms delay for tooltips within <script type='text/x-tmpl'>
setTimeout(function () {
const tooltipTriggerList = document.querySelectorAll(
'[data-bs-toggle="tooltip"]'
);
[...tooltipTriggerList].map(
(tooltipTriggerEl) => new bootstrap.Tooltip(tooltipTriggerEl)
);
}, 1);

// Navigate to tab
let searchParams = new URLSearchParams(window.location.search)
let searchParams = new URLSearchParams(window.location.search);
if (searchParams.has('tab')) {
let tab = searchParams.get('tab')
$($(`[data-toggle~=tab][href="#${tab}"]`)).tab('show');
let tab = searchParams.get('tab');
$($(`[data-bs-toggle~=tab][href="#${tab}"]`)).tab('show');
}

// Update address bar with current tab param
$('[data-toggle~=tab]').on('shown.bs.tab', function (e) {
$('[data-bs-toggle~=tab]').on('shown.bs.tab', function (e) {
let currentTab = $(e.target).attr('href').substring(1);
searchParams.set('tab', currentTab);
history.pushState(null, null, `?${searchParams.toString()}`);
})
});
}

document.addEventListener('turbolinks:load', function() {
document.addEventListener('turbolinks:load', function () {
initBehaviors(document.querySelector('body'));
});

Expand All @@ -76,11 +97,13 @@
//
// In particular we're after jquery.textile forms that get rendered post page
// load via ajax.
$(document).on('textile:formLoaded', '.textile-form', function(event){
$(document).on('textile:formLoaded', '.textile-form', function (event) {
// We trigger a single formLoaded event for the containing form, but we
// have to attach EditorToolbar to individual textareas within it.
$(event.target).find('[data-behavior~=rich-toolbar]').each(function() {
new EditorToolbar($(this));
});
$(event.target)
.find('[data-behavior~=rich-toolbar]')
.each(function () {
new EditorToolbar($(this));
});
});
})($, window);
73 changes: 42 additions & 31 deletions app/assets/javascripts/shared/datatable/delete.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
DradisDatatable.prototype.bulkDelete = function() {
DradisDatatable.prototype.bulkDelete = function () {
var that = this;
var destroyConfirmation = that.$paths.data('table-destroy-confirmation') || 'Are you sure?\n\nProceeding will delete the selected item(s).';
var destroyConfirmation =
that.$paths.data('table-destroy-confirmation') ||
'Are you sure?\n\nProceeding will delete the selected item(s).';
var answer = confirm(destroyConfirmation);

if (!answer) {
Expand All @@ -16,22 +18,22 @@ DradisDatatable.prototype.bulkDelete = function() {
method: 'DELETE',
dataType: 'json',
data: { ids: that.rowIds(selectedRows) },
success: function(data) {
success: function (data) {
that.handleBulkDeleteSuccess(selectedRows, data);
that.$table.trigger('dradis:datatable:bulkDelete');
},
error: function() {
error: function () {
that.handleBulkDeleteError(selectedRows);
}
})
}
},
});
};

DradisDatatable.prototype.handleBulkDeleteSuccess = function(rows, data) {
DradisDatatable.prototype.handleBulkDeleteSuccess = function (rows, data) {
var that = this;
this.toggleLoadingState(rows, false);

// Remove links from sidebar
that.rowIds(rows).forEach(function(id) {
that.rowIds(rows).forEach(function (id) {
$(`#${that.itemName}_${id}_link`).remove();
});

Expand All @@ -52,46 +54,55 @@ DradisDatatable.prototype.handleBulkDeleteSuccess = function(rows, data) {
} else {
this.showAlert(data.msg, 'error');
}
}
};

DradisDatatable.prototype.handleBulkDeleteError = function(rows) {
DradisDatatable.prototype.handleBulkDeleteError = function (rows) {
this.toggleLoadingState(rows, false);

rows.nodes().toArray().forEach(function(tr) {
$(tr).find('[data-behavior~=select-checkbox]').html('<span class="text-error pl-5" data-behavior="error-loading">Error. Try again</span>');
})
}

DradisDatatable.prototype.showAlert = function(msg, klass) {
rows
.nodes()
.toArray()
.forEach(function (tr) {
$(tr)
.find('[data-behavior~=select-checkbox]')
.html(
'<span class="text-error ps-5" data-behavior="error-loading">Error. Try again</span>'
);
});
};

DradisDatatable.prototype.showAlert = function (msg, klass) {
this.$table.parent().find('.alert').remove();

this.$table.parent().prepend(`
<div class="alert alert-${klass}">
<a class="close" data-dismiss="alert" href="javascript:void(0)">x</a>
<div class="alert alert-${klass} alert-dismissible">
<a class="btn-close" data-bs-dismiss="alert" href="javascript:void(0)"><span class="visually-hidden">Close alert</span></a>
${msg}
</div>
`);
}
};

DradisDatatable.prototype.setupBulkDeleteButtonToggle = function() {
DradisDatatable.prototype.setupBulkDeleteButtonToggle = function () {
if (this.$paths.data('table-destroy-url') === undefined) {
return;
}

this.dataTable.on('select.dt deselect.dt', function() {
var selectedCount = this.dataTable.rows({selected:true}).count();
this.toggleBulkDeleteBtn(selectedCount !== 0);
}.bind(this));

}
this.dataTable.on(
'select.dt deselect.dt',
function () {
var selectedCount = this.dataTable.rows({ selected: true }).count();
this.toggleBulkDeleteBtn(selectedCount !== 0);
}.bind(this)
);
};

DradisDatatable.prototype.toggleBulkDeleteBtn = function(isShown) {
DradisDatatable.prototype.toggleBulkDeleteBtn = function (isShown) {
// https://datatables.net/reference/api/buttons()
var bulkDeleteBtn = this.dataTable.buttons('bulkDeleteBtn:name');
$(bulkDeleteBtn[0].node).toggleClass('d-none', !isShown);
}
};

DradisDatatable.prototype.showConsole = function(jobId) {
DradisDatatable.prototype.showConsole = function (jobId) {
// the table may set the url to redirect to when closing the console
var closeUrl = this.$paths.data('table-close-console-url');

Expand All @@ -109,4 +120,4 @@ DradisDatatable.prototype.showConsole = function(jobId) {
// start console
ConsoleUpdater.parsing = true;
setTimeout(ConsoleUpdater.updateConsole, 1000);
}
};
Loading