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

SearchKit - Use combo button+dropdown for creating new search or segment #24199

Merged
merged 1 commit into from
Aug 10, 2022
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
SearchKit - Use combo button+dropdown for creating new search or segment
  • Loading branch information
colemanw committed Aug 9, 2022
commit 5e07fd071625e9ae32cce29f8941b9e11a416c84
6 changes: 5 additions & 1 deletion ext/search_kit/ang/crmSearchAdmin.module.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
})

// Controller for tabbed view of SavedSearches
.controller('searchList', function($scope, $timeout, searchMeta, formatForSelect2, dialogService) {
.controller('searchList', function($scope, $timeout, searchMeta, formatForSelect2) {
var ts = $scope.ts = CRM.ts('org.civicrm.search_kit'),
ctrl = $scope.$ctrl = this;
searchEntity = 'SavedSearch';
Expand All @@ -59,6 +59,10 @@
return {results: formatForSelect2(CRM.crmSearchAdmin.tags, 'id', 'name', ['color', 'description'])};
};

this.getPrimaryEntities = function() {
this.primaryEntities = _.filter(CRM.crmSearchAdmin.schema, {searchable: 'primary'});
};

// Tabs include a rowCount which will be updated by the search controller
this.tabs = [
{name: 'custom', title: ts('Custom Searches'), icon: 'fa-search-plus', rowCount: null, filters: {has_base: false}},
Expand Down
48 changes: 40 additions & 8 deletions ext/search_kit/ang/crmSearchAdmin/searchListing/searchList.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,46 @@ <h1 crm-page-title>{{:: ts('Saved Searches') }}</h1>
</a>
</li>
</ul>
<a class="btn btn-primary" href="#/create/Contact/" ng-if="$ctrl.tab !== 'segment'">
<i class="crm-i fa-plus"></i>
{{:: ts('New Search') }}
</a>
<a class="btn btn-primary" href ng-if="$ctrl.tab === 'segment'" title="{{:: ts('New Data Segment') }}" crm-dialog-popup="searchSegmentDialog" popup-tpl="~/crmSearchAdmin/searchSegment/editDialog.html">
<i class="crm-i fa-plus"></i>
{{:: ts('New Segment') }}
</a>
<div class="btn-group" ng-if="$ctrl.tab !== 'segment'">
<a class="btn btn-primary" href="#/create/Contact" >
<i class="crm-i fa-plus"></i>
{{:: ts('New Search') }}
</a>
<button type="button" ng-click="$ctrl.getPrimaryEntities()" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="caret"></span>
</button>
<ul class="dropdown-menu dropdown-menu-right">
<li ng-repeat="entity in $ctrl.primaryEntities">
<a ng-href="#/create/{{ entity.name }}">
<i class="crm-i {{:: entity.icon }}"></i>
{{:: entity.title_plural }}
</a>
</li>
<li title="{{:: ts('Choose other entities on the search screen') }}">
<a href="#/create/Contact">{{:: ts('More...') }}</a>
</li>
</ul>
</div>
<div class="btn-group" ng-if="$ctrl.tab === 'segment'">
<a class="btn btn-primary" href title="{{:: ts('New Data Segment') }}" crm-dialog-popup="searchSegmentDialog" popup-tpl="~/crmSearchAdmin/searchSegment/editDialog.html">
<i class="crm-i fa-plus"></i>
{{:: ts('New Data Segment') }}
</a>
<button type="button" ng-click="$ctrl.getPrimaryEntities()" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="caret"></span>
</button>
<ul class="dropdown-menu dropdown-menu-right">
<li ng-repeat="entity in $ctrl.primaryEntities">
<a href title="{{:: ts('New Data Segment') }}" crm-dialog-popup="searchSegmentDialog" popup-tpl="~/crmSearchAdmin/searchSegment/editDialog.html" popup-data="{entity_name: entity.name}">
<i class="crm-i {{:: entity.icon }}"></i>
{{:: entity.title_plural }}
</a>
</li>
<li title="{{:: ts('Choose other entities on the search screen') }}">
<a href title="{{:: ts('New Data Segment') }}" crm-dialog-popup="searchSegmentDialog" popup-tpl="~/crmSearchAdmin/searchSegment/editDialog.html">{{:: ts('More...') }}</a>
</li>
</ul>
</div>
</div>

<div ng-repeat="tab in $ctrl.tabs" ng-show="$ctrl.tab === tab.name">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

angular.module('crmSearchAdmin').component('crmSearchAdminSegment', {
bindings: {
segmentId: '<',
segment: '<',
},
templateUrl: '~/crmSearchAdmin/searchSegment/crmSearchAdminSegment.html',
controller: function ($scope, searchMeta, dialogService, crmApi4, crmStatus) {
Expand All @@ -15,7 +15,6 @@
this.entitySelect = searchMeta.getPrimaryAndSecondaryEntitySelect();

ctrl.saving = false;
ctrl.segment = {items: []};

// Drag-n-drop settings for reordering items
this.sortableOptions = {
Expand All @@ -33,17 +32,20 @@
};

this.$onInit = function() {
if (ctrl.segmentId) {
if (ctrl.segment.id) {
$('.ui-dialog:visible').block();
crmApi4('SearchSegment', 'get', {
where: [['id', '=', ctrl.segmentId]]
where: [['id', '=', ctrl.segment.id]]
}, 0).then(function(segment) {
ctrl.segment = segment;
originalEntity = segment.entity_name;
originalField = 'segment_' + segment.name;
searchMeta.loadFieldOptions([segment.entity_name]);
$('.ui-dialog:visible').unblock();
});
} else {
ctrl.segment.items = [];
ctrl.onChangeEntity();
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<br>
<div class="form-inline">
<label for="search-segment-entity_name">{{:: ts('For') }} <span class="crm-marker">*</span></label>
<input id="search-segment-entity_name" class="form-control collapsible-optgroups" required ng-model="$ctrl.segment.entity_name" ng-change="$ctrl.onChangeEntity()" crm-ui-select="{allowClear: false, data: $ctrl.entitySelect, placeholder: ts('Entity')}">
<input id="search-segment-entity_name" class="form-control huge collapsible-optgroups" required ng-model="$ctrl.segment.entity_name" ng-change="$ctrl.onChangeEntity()" crm-ui-select="{allowClear: false, data: $ctrl.entitySelect, placeholder: ts('Entity')}">
</div>
<br>
<fieldset>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<div crm-dialog="searchSegmentDialog">
<crm-search-admin-segment segment-id="model.data.id"></crm-search-admin-segment>
<crm-search-admin-segment segment="model"></crm-search-admin-segment>
</div>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="text-right">
<div class="btn-group btn-group-xs">
<a class="btn btn-primary" href crm-dialog-popup="searchSegmentDialog" popup-tpl="~/crmSearchAdmin/searchSegment/editDialog.html" popup-data="row" title="{{:: ts('Edit Data Segment') }}">
<a class="btn btn-primary" href crm-dialog-popup="searchSegmentDialog" popup-tpl="~/crmSearchAdmin/searchSegment/editDialog.html" popup-data="row.data" title="{{:: ts('Edit Data Segment') }}">
<i class="crm-i fa-pencil"></i>
{{:: ts('Edit') }}
</a>
Expand Down
2 changes: 1 addition & 1 deletion ext/search_kit/css/crmSearchAdmin.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#bootstrap-theme .crm-search-nav-tabs {
position: relative;
}
#bootstrap-theme .crm-search-nav-tabs > a.btn {
#bootstrap-theme .crm-search-nav-tabs > div.btn-group {
position: absolute;
right: 0;
top: 0;
Expand Down