From 30e8dec179288d1f73fa8608313f05ba186ae155 Mon Sep 17 00:00:00 2001 From: "y.yerli" Date: Tue, 3 Sep 2024 11:45:48 +0300 Subject: [PATCH] Convert button to dynamic buttons --- .../src/lib/components/button/button.model.ts | 1 + .../components/button/button.component.html | 1 + .../record-save-continue.action.ts | 8 +++- .../record-pagination.component.html | 18 +------- .../record-pagination.component.ts | 42 ++++++++++++++++--- .../record-pagination.store.ts | 2 +- .../css/components/_record-pagination.scss | 5 +++ .../RecordPaginationConfigMapper.php | 14 +++++-- .../legacy/include/DetailView/DetailView.php | 12 +++++- .../legacy/include/DetailView/DetailView2.php | 11 +++-- public/legacy/include/EditView/EditView2.php | 8 +++- 11 files changed, 87 insertions(+), 35 deletions(-) diff --git a/core/app/common/src/lib/components/button/button.model.ts b/core/app/common/src/lib/components/button/button.model.ts index a4cc53d25..ac30d0e97 100644 --- a/core/app/common/src/lib/components/button/button.model.ts +++ b/core/app/common/src/lib/components/button/button.model.ts @@ -40,6 +40,7 @@ export interface ButtonInterface { iconKlass?: string; labelModule?: string; section?: string; + disabled?: boolean; } export class Button implements ButtonInterface { diff --git a/core/app/core/src/lib/components/button/button.component.html b/core/app/core/src/lib/components/button/button.component.html index d3f1dd96e..74b4c2835 100644 --- a/core/app/core/src/lib/components/button/button.component.html +++ b/core/app/core/src/lib/components/button/button.component.html @@ -28,6 +28,7 @@ + {{currentIndex}} {{vm.appStrings['LBL_LIST_OF'] || ''}} {{vm.pageCount.total}} - + diff --git a/core/app/core/src/lib/views/record/components/record-pagination/record-pagination.component.ts b/core/app/core/src/lib/views/record/components/record-pagination/record-pagination.component.ts index 18552e10a..52481db12 100644 --- a/core/app/core/src/lib/views/record/components/record-pagination/record-pagination.component.ts +++ b/core/app/core/src/lib/views/record/components/record-pagination/record-pagination.component.ts @@ -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 = this.languageStore.appStrings$; recordIds$: Observable = this.recordPaginationStore.recordIds$; mode$: Observable = 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; } diff --git a/core/app/core/src/lib/views/record/store/record-pagination/record-pagination.store.ts b/core/app/core/src/lib/views/record/store/record-pagination/record-pagination.store.ts index d03222986..b813d29ca 100644 --- a/core/app/core/src/lib/views/record/store/record-pagination/record-pagination.store.ts +++ b/core/app/core/src/lib/views/record/store/record-pagination/record-pagination.store.ts @@ -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)}); diff --git a/core/app/shell/src/themes/suite8/css/components/_record-pagination.scss b/core/app/shell/src/themes/suite8/css/components/_record-pagination.scss index 07a91b1a9..f6419bfb2 100644 --- a/core/app/shell/src/themes/suite8/css/components/_record-pagination.scss +++ b/core/app/shell/src/themes/suite8/css/components/_record-pagination.scss @@ -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 { diff --git a/core/backend/SystemConfig/LegacyHandler/RecordPaginationConfigMapper.php b/core/backend/SystemConfig/LegacyHandler/RecordPaginationConfigMapper.php index 9b295e3df..452629bac 100644 --- a/core/backend/SystemConfig/LegacyHandler/RecordPaginationConfigMapper.php +++ b/core/backend/SystemConfig/LegacyHandler/RecordPaginationConfigMapper.php @@ -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); } } diff --git a/public/legacy/include/DetailView/DetailView.php b/public/legacy/include/DetailView/DetailView.php index 85c753113..67184a77c 100755 --- a/public/legacy/include/DetailView/DetailView.php +++ b/public/legacy/include/DetailView/DetailView.php @@ -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; diff --git a/public/legacy/include/DetailView/DetailView2.php b/public/legacy/include/DetailView/DetailView2.php index 4df66dbe8..09510f09a 100755 --- a/public/legacy/include/DetailView/DetailView2.php +++ b/public/legacy/include/DetailView/DetailView2.php @@ -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)) { diff --git a/public/legacy/include/EditView/EditView2.php b/public/legacy/include/EditView/EditView2.php index f1285c25b..a2baaf3c3 100755 --- a/public/legacy/include/EditView/EditView2.php +++ b/public/legacy/include/EditView/EditView2.php @@ -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)) {