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

Filter owners and groups dropdown lists #592

Merged
merged 7 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
38 changes: 21 additions & 17 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,7 @@ <h4>Legend</h4>
role="dialog"
aria-hidden="true"
>
<div class="modal-dialog modal-lg">
<div class="modal-dialog modal-lg" style="--bs-modal-width: 900px">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Open</h5>
Expand All @@ -1035,8 +1035,8 @@ <h5 class="modal-title">Open</h5>
<table class="table table-sm">
<thead>
<tr>
<th style="width: 7%"></th>
<th style="width: 45%">
<th></th>
<th>
<form class="row" role="form">
<div class="col-auto">
<label class="col-sm-2 control-label">Name</label>
Expand All @@ -1062,8 +1062,8 @@ <h5 class="modal-title">Open</h5>
</div>
</form>
</th>
<th style="width: 25%">
<form class="row" role="form">
<th>
<form class="row" role="form" style="flex-wrap: nowrap;">
<div class="col-auto">
<label class="col-sm-2 control-label">Created</label>
</div>
Expand All @@ -1081,39 +1081,43 @@ <h5 class="modal-title">Open</h5>
</button>
</form>
</th>
<th style="width: 12%">
<div class="btn-group" title="Filter files by owner">
<th>
Group:<br>
<div class="btn-group" title="Filter files by group">
<button
style="max-width: 120px; overflow: hidden;"
type="button"
class="btn dropdown-toggle"
class="btn dropdown-toggle btn-outline-secondary"
data-bs-toggle="dropdown"
>
<b>Owner</b> <span class="caret"></span>
<span id="selected_group">Group</span> <span class="caret"></span>
</button>
<ul
id="owner-menu"
id="group-menu"
class="dropdown-menu float-end"
role="menu"
>
<!-- owners added here -->
<!-- groups added here -->
</ul>
</div>
</th>
<th style="width: 12%">
<div class="btn-group" title="Filter files by group">
<th>
Owner:<br>
<div class="btn-group" title="Filter files by owner">
<button
style="max-width: 120px; overflow: hidden;"
type="button"
class="btn dropdown-toggle"
class="btn dropdown-toggle btn-outline-secondary"
data-bs-toggle="dropdown"
>
<b>Group</b> <span class="caret"></span>
<span id="selected_owner">Owner</span> <span class="caret"></span>
</button>
<ul
id="group-menu"
id="owner-menu"
class="dropdown-menu float-end"
role="menu"
>
<!-- groups added here -->
<!-- owners added here -->
</ul>
</div>
</th>
Expand Down
41 changes: 30 additions & 11 deletions src/js/views/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export var FigureFile = Backbone.Model.extend({
},

isVisible: function(filter) {
if (filter.owner) {
if (filter.owner !== undefined) {
if (this.get('owner').id !== filter.owner) {
return false;
}
Expand Down Expand Up @@ -232,7 +232,7 @@ export var FileListView = Backbone.View.extend({
filter = {},
filterVal = this.$fileFilter.val(),
currentFileId = this.figureModel.get('fileId');
if (this.owner && this.owner != -1) {
if (this.owner !== undefined && this.owner != -1) {
filter.owner = this.owner;
}
if (this.group && this.group != -1) {
Expand All @@ -248,15 +248,22 @@ export var FileListView = Backbone.View.extend({
"</td></tr>";
self.$tbody.html(msg);
}
_.each(this.model.models, function (file) {
if (file.isVisible(filter)) {
var disabled = currentFileId === file.get('id') ? true: false;
file.set('disabled', disabled);
var e = new FileListItemView({model:file, listview:self}).render().el;
self.$tbody.prepend(e);
}
let visibleFiles = this.model.models.filter(file => file.isVisible(filter));
_.each(visibleFiles, function (file) {
var disabled = currentFileId === file.get('id') ? true: false;
file.set('disabled', disabled);
var e = new FileListItemView({model:file, listview:self}).render().el;
self.$tbody.prepend(e);
});
var owners = this.model.pluck("owner");
// Lookup owner by ID "before" filtering, in case the chosen owner is filtered out
let owner = owners.find(o => o.id == filter.owner);
let ownerName = owner ? `${owner.firstName} ${owner.lastName}`: "Show All";

if (filter.group) {
let ownerIds = this.model.models.filter(f => f.get('group').id == filter.group).map(f => f.get('owner').id);
owners = owners.filter(o => ownerIds.includes(o.id));
}
var ownersByName = {};
owners.forEach(function(o){
let name = o.firstName + " " + o.lastName;
Expand All @@ -274,9 +281,14 @@ export var FileListView = Backbone.View.extend({
var ownersHtml = "<li><a class='dropdown-item pick-owner' href='#' data-id='-1'> -- Show All -- </a></li>";
ownersHtml += "<li class='divider'></li>";
_.each(ownersNames, function(name) {
ownersHtml += "<li><a class='dropdown-item pick-owner' data-id='" + ownersByName[name] + "' href='#'>" + _.escape(name) + "</a></li>";
ownersHtml += `<li>
<a class='dropdown-item pick-owner' data-id='${ownersByName[name]}' href='#'>
<i class='bi-check-lg' style='visibility: ${ownersByName[name] === filter.owner ? "visible" : "hidden"}'></i>
${_.escape(name)}
</a></li>`;
});
$("#owner-menu").html(ownersHtml);
$("#selected_owner").html(ownerName);

// render groups chooser
var groups = this.model.pluck("group");
Expand All @@ -287,8 +299,15 @@ export var FileListView = Backbone.View.extend({
var groupNames = Object.keys(groupsByName);
groupNames.sort();
var groupsHtml = "<li><a class='dropdown-item pick-group' href='#' data-id='-1'> -- Show All -- </a></li><li class='divider'></li>";
groupsHtml += groupNames.map(function (name) { return "<li><a class='dropdown-item pick-group' data-id='" + groupsByName[name] + "' href='#'>" + _.escape(name) + "</a></li>"}).join('\n');
groupsHtml += groupNames.map(name => `<li>
<a class='dropdown-item pick-group' data-id='${groupsByName[name]}' href='#'>
<i class='bi-check-lg' style='visibility: ${groupsByName[name] === filter.group ? "visible" : "hidden"}'></i>
${_.escape(name)}
</a></li>`).join('\n');
$("#group-menu").html(groupsHtml);
let group = groups.find(g => g.id == filter.group);
let groupName = group ? group.name: "Show All";
$("#selected_group").html(groupName);
return this;
}
});
Expand Down
4 changes: 2 additions & 2 deletions src/templates/files/figure_file_item.template.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
<%= formatDate(creationDate) %>
</td>
<td>
<%- ownerFullName %>
<%- group.name %>
</td>
<td>
<%- group.name %>
<%- ownerFullName %>
</td>