Convert button to dynamic buttons

This commit is contained in:
y.yerli 2024-09-03 11:45:48 +03:00 committed by Clemente Raposo
parent 9d1626e299
commit 30e8dec179
11 changed files with 87 additions and 35 deletions

View file

@ -40,6 +40,7 @@ export interface ButtonInterface {
iconKlass?: string;
labelModule?: string;
section?: string;
disabled?: boolean;
}
export class Button implements ButtonInterface {

View file

@ -28,6 +28,7 @@
<button type="button"
[ngClass]="config.klass"
(click)="runClick($event)"
[disabled]="config?.disabled || ''"
[title]="(language.getFieldLabel(config.titleKey) || config?.title) || ''">
<scrm-image *ngIf="config.icon"
[image]="config.icon"

View file

@ -33,6 +33,7 @@ import {ModuleNavigation} from '../../../../services/navigation/module-navigatio
import {NotificationStore} from '../../../../store/notification/notification.store';
import {RecentlyViewedService} from "../../../../services/navigation/recently-viewed/recently-viewed.service";
import {RecordPaginationService} from "../../store/record-pagination/record-pagination.service";
import {SystemConfigStore} from "../../../../store/system-config/system-config.store";
@Injectable({
providedIn: 'root'
@ -46,6 +47,7 @@ export class RecordSaveContinueAction extends RecordActionHandler {
protected message: MessageService,
protected navigation: ModuleNavigation,
protected notificationStore: NotificationStore,
protected systemConfigStore: SystemConfigStore,
protected recentlyViewedService: RecentlyViewedService,
protected recordPaginationService: RecordPaginationService
) {
@ -81,9 +83,13 @@ export class RecordSaveContinueAction extends RecordActionHandler {
}
shouldDisplay(data: RecordActionData): boolean {
const isEnabled = this.systemConfigStore.getConfigValue('enable_record_pagination');
if (!isEnabled) {
return false;
}
const totalRecords = this.recordPaginationService.getTotalRecords();
const offset = this.recordPaginationService.offset;
if (!totalRecords || !offset ||
(offset >= totalRecords) ||
(offset <= 0) ) {

View file

@ -27,24 +27,10 @@
-->
<div class="record-pagination-container d-flex align-items-center justify-content-end" *ngIf="(vm$ | async) as vm">
<ng-container *ngIf="vm.paginationEnabled">
<button class="record-pagination-button pagination-previous"
[disabled]="currentIndex === 1 || isRecordsLoading"
[class.disabled]="currentIndex === 1"
aria-label="Previous page"
(click)="prevRecord()">
<scrm-image class="sicon-2x" image="paginate_previous" [title]="vm.appStrings['LBL_SEARCH_PREV'] || ''">
</scrm-image>
</button>
<scrm-button [config]="prevButton"></scrm-button>
<span class="pagination-count">
{{currentIndex}} {{vm.appStrings['LBL_LIST_OF'] || ''}} {{vm.pageCount.total}}
</span>
<button class="record-pagination-button pagination-next"
[disabled]="currentIndex === totalRecordsCount || isRecordsLoading"
[class.disabled]="currentIndex === totalRecordsCount"
aria-label="Navigate to last page"
(click)="nextRecord()">
<scrm-image class="sicon-2x" image="paginate_next" [title]="vm.appStrings['LBL_SEARCH_NEXT'] || ''">
</scrm-image>
</button>
<scrm-button [config]="nextButton"></scrm-button>
</ng-container>
</div>

View file

@ -27,7 +27,7 @@
import {ChangeDetectionStrategy, Component, OnDestroy, OnInit} from '@angular/core';
import {CommonModule} from "@angular/common";
import {ActivatedRoute, Router} from "@angular/router";
import {PaginationCount, PageSelection, PaginationType, ObjectMap, ViewMode, ModalButtonInterface} from "common";
import {PaginationCount, PageSelection, PaginationType, ObjectMap, ViewMode, ButtonInterface, ModalButtonInterface} from "common";
import {combineLatestWith, Observable, Subscription} from "rxjs";
import {filter, map, tap} from "rxjs/operators";
import {toNumber} from "lodash-es";
@ -39,10 +39,10 @@ import {LocalStorageService} from "../../../../services/local-storage/local-stor
import {LanguageStore, LanguageStringMap} from "../../../../store/language/language.store";
import {SystemConfigStore} from "../../../../store/system-config/system-config.store";
import {RecordViewStore} from "../../store/record-view/record-view.store";
import {ImageModule} from "../../../../components/image/image.module";
import {RecordPaginationService} from "../../store/record-pagination/record-pagination.service";
import {RecordPaginationStore} from "../../store/record-pagination/record-pagination.store";
import {NgbModal} from "@ng-bootstrap/ng-bootstrap";
import {ButtonModule} from "../../../../components/button/button.module";
interface RecordPaginationViewModel {
appStrings: LanguageStringMap;
@ -55,7 +55,7 @@ interface RecordPaginationViewModel {
templateUrl: './record-pagination.component.html',
styles: [],
standalone: true,
imports: [CommonModule, ImageModule],
imports: [CommonModule, ButtonModule],
changeDetection: ChangeDetectionStrategy.OnPush,
})
@ -72,6 +72,9 @@ export class RecordPaginationComponent implements OnInit, OnDestroy {
recordIds: ObjectMap[];
subs: Subscription[] = [];
prevButton: ButtonInterface = null;
nextButton: ButtonInterface = null;
appStrings$: Observable<LanguageStringMap> = this.languageStore.appStrings$;
recordIds$: Observable<ObjectMap[]> = this.recordPaginationStore.recordIds$;
mode$: Observable<ViewMode> = this.recordViewStore.mode$;
@ -109,6 +112,30 @@ export class RecordPaginationComponent implements OnInit, OnDestroy {
this.mode = mode;
}));
this.prevButton = {
klass: {
'record-pagination-button': true,
'pagination-previous': true,
disabled: this.currentIndex === 1
},
icon: 'paginate_previous',
iconKlass: 'sicon-2x',
disabled: this.currentIndex === 1 || this.isRecordsLoading,
onClick: () => this.prevRecord()
} as ButtonInterface;
this.nextButton = {
klass: {
'record-pagination-button': true,
'pagination-next': true,
disabled: this.currentIndex === this.totalRecordsCount
},
icon: 'paginate_next',
iconKlass: 'sicon-2x',
disabled: this.currentIndex === this.totalRecordsCount || this.isRecordsLoading,
onClick: () => this.nextRecord()
} as ButtonInterface;
this.vm$ = this.appStrings$.pipe(
combineLatestWith(this.recordPaginationStore.pagination$, this.recordPaginationStore.paginationEnabled$),
map(([appStrings, pageCount, paginationEnabled]: [LanguageStringMap, PaginationCount, boolean]) => {
@ -120,6 +147,9 @@ export class RecordPaginationComponent implements OnInit, OnDestroy {
if (!isRecordPaginationExist || !isRecordValid || (this.currentIndex > this.totalRecordsCount)) {
paginationEnabled = false;
}
this.prevButton = { ...this.prevButton, titleKey: appStrings['LBL_SEARCH_PREV'] || '' } as ButtonInterface;
this.nextButton = { ...this.nextButton, titleKey: appStrings['LBL_SEARCH_NEXT'] || '' } as ButtonInterface;
return { appStrings, pageCount, paginationEnabled };
})
);
@ -146,12 +176,12 @@ export class RecordPaginationComponent implements OnInit, OnDestroy {
}));
}
ngOnDestroy() : void {
ngOnDestroy(): void {
this.subs.forEach(sub => sub.unsubscribe());
this.recordPaginationStore.clear();
}
prevRecord(): void {
protected prevRecord(): void {
if (this.currentIndex <= 0) {
return;
}
@ -170,7 +200,7 @@ export class RecordPaginationComponent implements OnInit, OnDestroy {
}
}
nextRecord(): void {
protected nextRecord(): void {
if (this.currentIndex >= this.totalRecordsCount) {
return;
}

View file

@ -99,7 +99,7 @@ export class RecordPaginationStore {
protected enableRecordPagination(): void {
let isEnabled = this.systemConfigStore.getConfigValue('enable_record_pagination');
if (isEnabled === "" || (Array.isArray(isEnabled) && isEnabled.length === 0)) {
if (isEnabled === "") {
isEnabled = false;
}
this.updateState({...this.internalState, paginationEnabled: !!(isEnabled ?? false)});

View file

@ -41,6 +41,11 @@
padding: 0;
margin: 0.3em;
border-radius: 0.4em;
.sicon-2x {
width: 1.9em;
height: 1.9em;
}
}
.record-pagination-button.disabled {

View file

@ -46,14 +46,20 @@ class RecordPaginationConfigMapper implements SystemConfigMapperInterface
public function map(SystemConfig $config): void
{
$isRecordPaginationEnabled = $config->getValue();
if($isRecordPaginationEnabled === "") {
if ($isRecordPaginationEnabled === null) {
$config->setValue(true);
return;
}
if ($isRecordPaginationEnabled === "" || is_array($isRecordPaginationEnabled)) {
$config->setValue(false);
return;
}
if(is_array($isRecordPaginationEnabled)) {
if ($isRecordPaginationEnabled) {
$config->setValue(isTrue($isRecordPaginationEnabled));
} else {
$config->setValue(false);
return;
}
$config->setValue($isRecordPaginationEnabled);
}
}

View file

@ -81,7 +81,17 @@ class DetailView extends ListView
global $list_view_row_count;
global $current_offset;
$recordPaginationEnabled = isset($sugar_config['enable_record_pagination']) ? $sugar_config['enable_record_pagination'] : (!isset($sugar_config['disable_vcr']) || !$sugar_config['disable_vcr']);
if (array_key_exists('enable_record_pagination', $GLOBALS['sugar_config'])) {
$recordPaginationEnabled = isTrue($sugar_config['enable_record_pagination']);
} else {
$recordPaginationEnabled = true;
if (isset($sugar_config['disable_vcr']) && $sugar_config['disable_vcr']) {
$recordPaginationEnabled = !$sugar_config['disable_vcr'];
}
}
if (!$recordPaginationEnabled) {
$seed->retrieve($_REQUEST['record']);
return $seed;

View file

@ -92,11 +92,14 @@ class DetailView2 extends EditView
$this->tpl = get_custom_file_if_exists($tpl);
$this->module = $module;
$this->metadataFile = $metadataFile;
if (isset($GLOBALS['sugar_config']['enable_record_pagination'])) {
$this->showVCRControl = $GLOBALS['sugar_config']['enable_record_pagination'];
if (array_key_exists('enable_record_pagination', $GLOBALS['sugar_config'])) {
$this->showVCRControl = isTrue($GLOBALS['sugar_config']['enable_record_pagination']);
} else {
$this->showVCRControl = !$GLOBALS['sugar_config']['disable_vcr'];
$this->showVCRControl = true;
if (isset($GLOBALS['sugar_config']['disable_vcr'])) {
$this->showVCRControl = !$GLOBALS['sugar_config']['disable_vcr'];
}
}
if (!empty($this->metadataFile) && file_exists($this->metadataFile)) {

View file

@ -242,9 +242,13 @@ class EditView
$this->metadataFile = $metadataFile;
if (isset($GLOBALS['sugar_config']['enable_record_pagination'])) {
$this->showVCRControl = $GLOBALS['sugar_config']['enable_record_pagination'];
$this->showVCRControl = isTrue($GLOBALS['sugar_config']['enable_record_pagination']);
} else {
$this->showVCRControl = !$GLOBALS['sugar_config']['disable_vcr'];
$this->showVCRControl = true;
if (isset($GLOBALS['sugar_config']['disable_vcr'])) {
$this->showVCRControl = !$GLOBALS['sugar_config']['disable_vcr'];
}
}
if (!empty($this->metadataFile) && file_exists($this->metadataFile)) {