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

Issue 1930: Add custom filter for embargo type by list. #1935

Merged
merged 3 commits into from
May 10, 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
44 changes: 16 additions & 28 deletions src/main/java/org/tdl/vireo/model/repo/impl/SubmissionRepoImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -740,43 +740,31 @@ public int compare(SubmissionListColumn svc1, SubmissionListColumn svc2) {
break;

case "embargoTypes.name":
sqlBuilder = new StringBuilder()
.append("\nLEFT JOIN")
.append("\n (SELECT e.id, e.name, semt.submission_id")
.append("\n FROM embargo e")
.append("\n LEFT JOIN submission_embargo_types semt")
.append("\n ON semt.embargo_types_id=e.id) embs")
.append("\n ON embs.submission_id=s.id");

sqlJoinsBuilder.append(sqlBuilder);
sqlCountSelectBuilder.append(sqlBuilder);

if (submissionListColumn.getSortOrder() > 0) {
setColumnOrdering(submissionListColumn.getSort(), sqlAliasBuilders, sqlOrderBysBuilder, "embs.name");
}

for (String filterString : submissionListColumn.getFilters()) {
// This is not a select column but is instead only a custom filter.
if (submissionListColumn.getFilters().size() > 0) {
sqlBuilder = new StringBuilder();
sqlBuilder.append("s.id IN (SELECT submission_id FROM submission_field_values WHERE field_values_id IN (select id FROM field_value WHERE field_predicate_id IN (SELECT id FROM field_predicate WHERE value IN ('default_embargos', 'proquest_embargos')) and (");

sqlBuilder.append(" embs").append(".name = '").append(filterString).append("'");
// Note that the OR query is used inside the column, represented by both default_embargos and proquest_embargos.
boolean hasNone = false;
for (String filterString : submissionListColumn.getFilters()) {
sqlBuilder.append(" value = '").append(escapeString(filterString, false)).append("' OR");

if (filterString.equals("None")) {
sqlWhereBuilderList.add(sqlBuilder);
sqlBuilder = new StringBuilder();
sqlBuilder.append("embs.id IS NULL");
if ("None".equals(filterString)) {
hasNone = true;
}
}
sqlBuilder.setLength(sqlBuilder.length() - 3);
sqlBuilder.append(")))");

if (hasNone) {
sqlBuilder.append(" OR s.id NOT IN (SELECT submission_id FROM submission_field_values WHERE field_values_id IN (SELECT id FROM field_value WHERE field_predicate_id IN (SELECT id FROM field_predicate WHERE value IN ('default_embargos', 'proquest_embargos'))))");
}

sqlWhereBuilderList.add(sqlBuilder);
getFromBuildersMap(sqlCountWhereFilterBuilders, "embargoTypes.name").add(sqlBuilder);
}

// all column search filter
for (String filterString : allColumnSearchFilters) {
sqlBuilder = new StringBuilder();
sqlBuilder.append("LOWER(embs").append(".name) LIKE '%").append(escapeString(filterString)).append("%'");
sqlAllColumnsWhereBuilderList.add(sqlBuilder);
}

break;

case "lastEvent":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,5 +197,17 @@
"inputType": {
"name": "INPUT_TEXT"
}
},
{
"title": "Embargo Type",
"sort": "NONE",
"valuePath": [
"embargoTypes",
"name"
],
"status": null,
"inputType": {
"name": "INPUT_TEXT"
}
}
]
16 changes: 16 additions & 0 deletions src/main/webapp/app/filters/uniqueEmbargoType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
vireo.filter('uniqueEmbargoType', function() {
return function(initialValues, isActive) {
var matched = [];
var newValues = [];
if (typeof initialValues === "object") {
angular.forEach(initialValues, function(embargo) {
if (matched.includes(embargo.name)) return;
if (embargo.isActive !== isActive) return;

matched.push(embargo.name);
newValues.push(embargo);
});
}
return newValues;
};
});
4 changes: 4 additions & 0 deletions src/main/webapp/app/resources/styles/sass/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@ sidebox ul.sidebox-list input {
padding: 15px;
}

.sidebox-body ul.sidebox-list.embargotype-list,
.sidebox-body ul.sidebox-list.status-list {
padding: 0px;
}
Expand Down Expand Up @@ -1560,6 +1561,7 @@ input[type=color]:focus {
text-decoration: underline;
}

.further-filter-by .embargotype-category,
.further-filter-by .status-category {
background: #CCCCCC;
display: inline-block;
Expand All @@ -1572,6 +1574,7 @@ input[type=color]:focus {
.further-filter-by .document-type-list,
.further-filter-by .inactive-filters-sub-list,
.further-filter-by .organization-by-category-sub-list,
.further-filter-by .embargotype-list,
.further-filter-by .status-list {
max-height: 0;
overflow: hidden;
Expand All @@ -1587,6 +1590,7 @@ input[type=color]:focus {
.further-filter-by .document-type-list.expanded,
.further-filter-by .inactive-filters-sub-list.expanded,
.further-filter-by .organization-by-category-sub-list.expanded,
.further-filter-by .embargotype-list.expanded,
.further-filter-by .status-list.expanded {
max-height: 1000px;
-webkit-transition: max-height 0.5s ease-in;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<form ng-init="box.embargosLimit=box.defaultLimit;" name="{{'box.'+(column.title.split(' ').join(''))+'Form'}}">
<ul class="sidebox-list">
<li class="filter" ng-repeat="et in box.embargos | filter:{isActive: true} | limitTo:box.embargosLimit" ng-click="box[column.title.split(' ').join('')]=et.name;box.addExactMatchFilter(column);"><span ng-if="et.systemRequired" class="glyphicon glyphicon-globe"></span><span ng-if="!et.systemRequired" class="glyphicon glyphicon-user"></span> {{et.name}}</li>
<li class="more-less" ng-click="box.embargosLimit=box.embargos.length" ng-if="box.embargosLimit<=box.defaultLimit && box.embargos.length>box.defaultLimit">more...</li>
<li class="more-less" ng-click="box.embargosLimit=box.defaultLimit" ng-if="box.embargosLimit>box.defaultLimit">less...</li>
</ul>

<ul class="sidebox-list">
<li class="more-less" ng-click="box.inactiveFilterExpand=box.inactiveFilterExpand?!box.inactiveFilterExpand:true"><span ng-if="!box.inactiveFilterExpand">+</span><span ng-if="box.inactiveFilterExpand">-</span> Inactive</li>
<li ng-class="{'expanded': box.inactiveFilterExpand}" class="inactive-filters-sub-list">
<ul>
<li class="embargo-filter filter" ng-repeat="et in box.embargos | filter:{isActive: false}" ng-click="box[column.title.split(' ').join('')]=et.name;box.addExactMatchFilter(column);"><span ng-if="et.systemRequired" class="glyphicon glyphicon-globe"></span><span ng-if="!et.systemRequired" class="glyphicon glyphicon-user"></span> {{et.name}}</li>
</ul>
</li>
</ul>

<form name="{{'box.'+(column.title.split(' ').join(''))+'Form'}}">
<ul class="sidebox-list">
<li class="filter" ng-click="box[column.title.split(' ').join('')]=ss.name;box.addExactMatchFilter(column);" ng-repeat="et in box.embargos | uniqueEmbargoType">{{et.name}}</li>
<li ng-click="activeExpanded = activeExpanded ? !activeExpanded : true" class="embargotype-category">+ Active</li>
<li>
<ul class="sidebox-list embargotype-list" ng-class="{'expanded': activeExpanded}">
<li class="filter" ng-click="box[column.title.split(' ').join('')]=et.name;box.addExactMatchFilter(column);" ng-repeat="et in box.embargos | uniqueEmbargoType:true"><span ng-if="et.systemRequired" class="glyphicon glyphicon-globe"></span><span ng-if="!et.systemRequired" class="glyphicon glyphicon-user"></span> {{et.name}}</li>
</ul>
</li>
<li ng-click="inactiveExpanded = inactiveExpanded ? !inactiveExpanded : true" class="embargotype-category">+ Inactive</li>
<li>
<ul class="sidebox-list embargotype-list" ng-class="{'expanded': inactiveExpanded}">
<li class="filter" ng-click="box[column.title.split(' ').join('')]=et.name;box.addExactMatchFilter(column);" ng-repeat="et in box.embargos | uniqueEmbargoType:false"><span ng-if="et.systemRequired" class="glyphicon glyphicon-globe"></span><span ng-if="!et.systemRequired" class="glyphicon glyphicon-user"></span> {{et.name}}</li>
</ul>
</li>
</ul>
</form>
101 changes: 101 additions & 0 deletions src/main/webapp/tests/unit/filters/uniqueEmbargoTypeTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
describe("filter: uniqueEmbargoType", function () {
var $scope, MockedUser, filter;

var initializeVariables = function () {
inject(function (_$q_) {
$q = _$q_;

MockedUser = new mockUser($q);
});
};

var initializeFilter = function (settings) {
inject(function (_$filter_, _$rootScope_) {
$scope = _$rootScope_.$new();

filter = _$filter_("uniqueEmbargoType");
});
};

beforeEach(function () {
module("core");
module("vireo");
module("mock.user", function ($provide) {
var User = function () {
return MockedUser;
};
$provide.value("User", User);
});
module("mock.userService");

installPromiseMatchers();
initializeVariables();
initializeFilter();
});

afterEach(function () {
$scope.$destroy();
});

describe("Is the filter", function () {
it("defined", function () {
expect(filter).toBeDefined();
});
});

describe("Does the filter", function () {
it("return empty array on empty input", function () {
var result;

result = filter("", false);

expect(result).toEqual([]);

result = filter("", true);

expect(result).toEqual([]);

result = filter(null, false);

expect(result).toEqual([]);

result = filter(null, true);

expect(result).toEqual([]);

result = filter([], false);

expect(result).toEqual([]);

result = filter([], true);

expect(result).toEqual([]);

result = filter({}, false);

expect(result).toEqual([]);

result = filter({}, true);

expect(result).toEqual([]);
});

it("return array with duplicate removed for active", function () {
var result;
var duplicated = [ dataEmbargo1, dataEmbargo2, dataEmbargo1, dataEmbargo3 ];

result = filter(duplicated, true);

expect(result.length).toBe(2);
});

it("return array with duplicate removed for inactive", function () {
var result;
var duplicated = [ dataEmbargo3, dataEmbargo2, dataEmbargo3, dataEmbargo1 ];

result = filter(duplicated, false);

expect(result.length).toBe(1);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ private void assertSubmissionStatusTransitions(String[] expected, SubmissionStat
}

private void assertSubmissionListColumn(boolean isReload) {
assertEquals(59, submissionListColumnRepo.count(),
assertEquals(60, submissionListColumnRepo.count(),
isReload
? "Incorrect number of submissionListColumn found after reload"
: "Incorrect number of submissionListColumn found");
Expand Down
Loading