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

Only show groups when any filtered results in group #14505

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,34 @@ angular.module("umbraco")
function ($scope, localizationService, $filter) {

var unsubscribe = [];
var vm = this;
const vm = this;

vm.navigation = [];

vm.filterSearchTerm = '';
vm.filter = {
searchTerm: ""
};

vm.filteredItems = [];

// Ensure groupKey value, as we need it to be present for the filtering logic.
$scope.model.availableItems.forEach(item => {
item.blockConfigModel.groupKey = item.blockConfigModel.groupKey || null;
});

unsubscribe.push($scope.$watch('vm.filterSearchTerm', updateFiltering));
unsubscribe.push($scope.$watch('vm.filter.searchTerm', updateFiltering));

function updateFiltering() {
vm.filteredItems = $filter('umbCmsBlockCard')($scope.model.availableItems, vm.filterSearchTerm);
vm.filteredItems = $filter('umbCmsBlockCard')($scope.model.availableItems, vm.filter.searchTerm);
}

vm.filterByGroup = function (group) {

const items = $filter('filter')(vm.filteredItems, { blockConfigModel: { groupKey: group?.key || null } });

return items;
};

localizationService.localizeMany(["blockEditor_tabCreateEmpty", "blockEditor_tabClipboard"]).then(
function (data) {

Expand All @@ -47,9 +57,7 @@ angular.module("umbraco")
} else {
vm.activeTab = vm.navigation[0];
}




vm.activeTab.active = true;
}
);
Expand All @@ -61,12 +69,13 @@ angular.module("umbraco")
};

vm.clickClearClipboard = function () {
vm.model.clipboardItems = [];// This dialog is not connected via the clipboardService events, so we need to update manually.
vm.model.clipboardItems = []; // This dialog is not connected via the clipboardService events, so we need to update manually.
vm.model.clickClearClipboard();

if (vm.model.singleBlockMode !== true && vm.model.openClipboard !== true)
{
vm.onNavigationChanged(vm.navigation[0]);
vm.navigation[1].disabled = true;// disabled ws determined when creating the navigation, so we need to update it here.
vm.navigation[1].disabled = true; // disabled ws determined when creating the navigation, so we need to update it here.
}
else {
vm.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,34 @@
<div class="umb-control-group" ng-if="vm.model.filter === true" style="margin-bottom: 20px;">
<umb-search-filter
input-id="block-search"
model="vm.filterSearchTerm"
model="vm.filter.searchTerm"
label-key="placeholders_filter"
text="Type to filter..."
css-class="w-100"
auto-focus="true">
</umb-search-filter>
</div>

<div class="umb-block-card-grid" ng-if="vm.filteredItems.length > 0">
<div class="umb-block-card-grid" ng-if="vm.filterByGroup(null).length > 0">

<umb-block-card
class="umb-outline"
ng-repeat="block in (vm.filteredItems | filter:{blockConfigModel:{groupKey: null}})"
ng-repeat="block in vm.filterByGroup(null)"
block-config-model="block.blockConfigModel"
element-type-model="block.elementTypeModel"
ng-click="vm.selectItem(block, $event)">
</umb-block-card>

</div>

<div ng-repeat="blockGroup in model.blockGroups" ng-if="vm.filteredItems.length > 0">
<div ng-repeat="blockGroup in model.blockGroups" ng-if="vm.filterByGroup(blockGroup).length > 0">
<h5>{{blockGroup.name}}</h5>

<div class="umb-block-card-grid">

<umb-block-card
class="umb-outline"
ng-repeat="block in (vm.filteredItems | filter:{blockConfigModel:{groupKey: blockGroup.key}})"
ng-repeat="block in vm.filterByGroup(blockGroup)"
block-config-model="block.blockConfigModel"
element-type-model="block.elementTypeModel"
ng-click="vm.selectItem(block, $event)">
Expand Down
Loading