Skip to content

Commit

Permalink
Merge pull request #23702 from colemanw/loadingPlaceholders
Browse files Browse the repository at this point in the history
SearchKit - Make loading placeholders configurable
  • Loading branch information
eileenmcnaughton authored Jun 7, 2022
2 parents c4a6ea3 + 241cc62 commit 7f17854
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public function _run(\Civi\Api4\Generic\Result $result) {
'show_count' => TRUE,
'expose_limit' => TRUE,
],
'placeholder' => 5,
'sort' => [],
'columns' => [],
],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
(function(angular, $, _) {
"use strict";

angular.module('crmSearchAdmin').component('searchAdminPlaceholderConfig', {
bindings: {
display: '<',
},
templateUrl: '~/crmSearchAdmin/displays/common/searchAdminPlaceholderConfig.html',
controller: function($scope) {
var ts = $scope.ts = CRM.ts('org.civicrm.search_kit'),
ctrl = this;

this.$onInit = function() {
// Legacy support
if (!('placeholder' in this.display.settings)) {
this.display.settings.placeholder = 5;
}
};

this.togglePlaceholder = function() {
this.display.settings.placeholder = this.display.settings.placeholder ? 0 : 5;
};

}
});

})(angular, CRM.$, CRM._);
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<div class="form-inline">
<div class="checkbox-inline form-control" title="{{:: ts('Show wireframe placeholder results while waiting for data') }}">
<label>
<input type="checkbox" ng-checked="$ctrl.display.settings.placeholder" ng-click="$ctrl.togglePlaceholder()">
<span>{{:: ts('Loading Placeholders') }}</span>
</label>
<input ng-if="$ctrl.display.settings.placeholder" type="number" min="0" step="1" class="form-control" ng-model="$ctrl.display.settings.placeholder" ng-model-options="{updateOn: 'blur'}">
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<div class="form-group" ng-include="'~/crmSearchAdmin/displays/common/searchButtonConfig.html'"></div>
</div>
<search-admin-pager-config display="$ctrl.display"></search-admin-pager-config>
<search-admin-placeholder-config display="$ctrl.display"></search-admin-placeholder-config>
</fieldset>
<fieldset class="crm-search-admin-edit-columns-wrapper">
<legend>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<div class="form-group" ng-include="'~/crmSearchAdmin/displays/common/searchButtonConfig.html'"></div>
</div>
<search-admin-pager-config display="$ctrl.display"></search-admin-pager-config>
<search-admin-placeholder-config display="$ctrl.display"></search-admin-placeholder-config>
</fieldset>
<fieldset class="crm-search-admin-edit-columns-wrapper">
<legend>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
</div>
<search-admin-css-rules label="{{:: ts('Row Style') }}" item="$ctrl.display.settings"></search-admin-css-rules>
<search-admin-pager-config display="$ctrl.display"></search-admin-pager-config>
<search-admin-placeholder-config display="$ctrl.display"></search-admin-placeholder-config>
<div class="form-inline crm-search-admin-flex-row" title="{{:: ts('Text to display if the table is empty.') }}">
<label for="crm-search-admin-display-no-results-text">{{:: ts('No Results Text') }}</label>
<input class="form-control crm-flex-1" id="crm-search-admin-display-no-results-text" ng-model="$ctrl.display.settings.noResultsText" placeholder="{{:: ts('None found.') }}">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
this.limit = this.settings.limit;
this.sort = this.settings.sort ? _.cloneDeep(this.settings.sort) : [];
this.seed = Date.now();
this.placeholders = [];
var placeholderCount = 'placeholder' in this.settings ? this.settings.placeholder : 5;
for (var p=0; p < placeholderCount; ++p) {
this.placeholders.push({});
}

this.getResults = _.debounce(function() {
$scope.$apply(function() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- Placeholder shown during ajax loading -->
<div ng-repeat="num in [1,2,3,4,5] track by $index" style="width: 100px; height: 50px;">
<div ng-repeat="num in $ctrl.placeholders" style="width: 100px; height: 50px;">
<div class="crm-search-loading-placeholder"></div>
</div>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- Placeholder shown during ajax loading -->
<li ng-repeat="num in [1,2,3,4,5] track by $index">
<li ng-repeat="num in $ctrl.placeholders">
<div class="crm-search-loading-placeholder"></div>
</li>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- Placeholder table rows shown during ajax loading -->
<tr ng-repeat="num in [1,2,3,4,5] track by $index">
<tr ng-repeat="num in $ctrl.placeholders">
<td ng-if=":: $ctrl.hasExtraFirstColumn()">
<input ng-if=":: $ctrl.settings.actions" type="checkbox" disabled>
</td>
Expand Down
4 changes: 2 additions & 2 deletions ext/search_kit/css/crmSearchDisplay.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
width: 80%;
position: relative;
overflow: hidden;
background-color: rgba(0,0,0,.04);
background-color: rgba(0,0,0,.03);
display: inline-block;
}
#bootstrap-theme .crm-search-loading-placeholder::before {
Expand All @@ -37,7 +37,7 @@
top: 0;
height: 100%;
width: 150px;
background: linear-gradient(to right, transparent 0%, rgba(0,0,0,.1) 50%, transparent 100%);
background: linear-gradient(to right, transparent 0%, rgba(0,0,0,.05) 50%, transparent 100%);
animation: searchKitLoadingAnimation 1s cubic-bezier(0.4, 0.0, 0.2, 1) infinite;
}
@keyframes searchKitLoadingAnimation {
Expand Down

0 comments on commit 7f17854

Please sign in to comment.