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

Fix/329 submit required #388

Open
wants to merge 2 commits into
base: hotfix
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions core/app/common/src/lib/components/button/button.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* feasible for technical reasons, the Appropriate Legal Notices must display
* the words "Supercharged by SuiteCRM".
*/
import {Observable} from 'rxjs';

export declare type ButtonCallback = (...args) => void;

Expand All @@ -37,6 +38,7 @@ export interface ButtonInterface {
icon?: string;
iconKlass?: string;
labelModule?: string;
disabled$?: Observable<boolean>;
}

export class Button implements ButtonInterface {
Expand Down
10 changes: 6 additions & 4 deletions core/app/common/src/lib/metadata/metadata.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export interface Panel {
displayState: BehaviorSubject<boolean>;
display$: Observable<boolean>;
meta: TabDefinition;
isCollapsed: boolean;
}

export interface PanelRow {
Expand All @@ -60,10 +61,11 @@ export interface PanelRow {

export interface PanelCell extends ViewFieldDefinition {
name?: string;
required_f_submit?: boolean;
}

export interface ViewFieldDefinitionMap {
[key: string]: ViewFieldDefinition
[key: string]: ViewFieldDefinition;
}

export interface TabDefinitions {
Expand All @@ -86,12 +88,12 @@ export interface LogicDefinition {
modes: Array<string>;
params: {
activeOnFields?: {
[key:string]: LogicRuleValues[];
}
[key: string]: LogicRuleValues[];
};
displayState?: boolean;
fieldDependencies: Array<string>;
asyncProcessHandler?: string;
}
};
}

export interface LogicRuleValues{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class ActionGroupMenuComponent implements OnInit {
@Input() buttonGroupClass = '';
@Input() actionContext: ActionContext;
@Input() config: ActionDataSource;
@Input() actionLimitConfig: string = 'recordview_actions_limits';
@Input() actionLimitConfig = 'recordview_actions_limits';
configState = new BehaviorSubject<ButtonGroupInterface>({buttons: []});
config$ = this.configState.asObservable();

Expand Down Expand Up @@ -170,7 +170,7 @@ export class ActionGroupMenuComponent implements OnInit {
this.triggerTemporaryLoading();
const callback = (): void => {
this.config.runAction(action, this.actionContext);
}
};
this.initInlineConfirmation(action, callback);

return;
Expand Down Expand Up @@ -204,11 +204,16 @@ export class ActionGroupMenuComponent implements OnInit {
Button.appendClasses(button, action.klass);
}

if(action.disabled$){
button.disabled$ = action.disabled$;
}

return button;
}

protected triggerTemporaryLoading() {
protected triggerTemporaryLoading(): void {
this.loading = true;
// eslint-disable-next-line radix
const delay = parseInt(this.systemConfigStore.getUi('inline_confirmation_loading_delay')) ?? 200;
setTimeout(() => {
this.loading = false;
Expand All @@ -221,8 +226,8 @@ export class ActionGroupMenuComponent implements OnInit {
this.confirmationLabel = action?.params?.confirmationLabel ?? '';
this.confirmationDynamicLabel = action?.params?.confirmationDynamicLabel ?? '';

this.inlineCancelButton = this.buildInlineCancelButton(cancelConfig)
this.inlineConfirmButton = this.buildInlineConfirmButton(confirmConfig, callback)
this.inlineCancelButton = this.buildInlineCancelButton(cancelConfig);
this.inlineConfirmButton = this.buildInlineConfirmButton(confirmConfig, callback);
this.inlineConfirmationEnabled = true;
}

Expand All @@ -237,7 +242,7 @@ export class ActionGroupMenuComponent implements OnInit {
button.onClick = (): void => {
this.triggerTemporaryLoading();
this.resetInlineConfirmation();
}
};

return button;
}
Expand All @@ -254,7 +259,7 @@ export class ActionGroupMenuComponent implements OnInit {
this.triggerTemporaryLoading();
callback();
this.resetInlineConfirmation();
}
};

return button;
}
Expand Down
2 changes: 2 additions & 0 deletions core/app/core/src/lib/components/button/button.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
-->
<button type="button"
[ngClass]="config.klass"
[class.disabled]="disabled"
(click)="runClick()"
[disabled]="disabled"
[title]="language.getFieldLabel(config.titleKey) || ''">
<scrm-image *ngIf="config.icon"
[image]="config.icon"
Expand Down
10 changes: 9 additions & 1 deletion core/app/core/src/lib/components/button/button.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {debounceTime} from 'rxjs/operators';
export class ButtonComponent implements OnInit, OnDestroy {
@Input() config: ButtonInterface;
clickCallBack: ButtonCallback;
disabled = false;
protected clickBuffer = new Subject<any>();
protected clickBuffer$: Observable<any> = this.clickBuffer.asObservable();
protected subs: Subscription[] = [];
Expand All @@ -55,6 +56,12 @@ export class ButtonComponent implements OnInit, OnDestroy {
this.clickCallBack(input);
}));
}

if(this.config.disabled$) {
this.subs.push(this.config.disabled$.subscribe(value => {
this.disabled = value;
}));
}
}


Expand All @@ -79,7 +86,8 @@ export class ButtonComponent implements OnInit, OnDestroy {

/**
* Get debounce time
* @return number
*
* @returns number
* @protected
*/
protected getDebounceTime(): number {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<div *ngIf="config && config.layout === 'panels'" class="record-content panel-layout container-fluid pl-0 pr-0">
<div class="row no-gutters mb-3" *ngFor="let panel of panels">
<div class="col">
<scrm-panel [title]="panel.label" mode="collapsible">
<scrm-panel [title]="panel.label" [isCollapsed$]="(panel.isCollapsed | toObservable)" mode="collapsible">
<div panel-body class="panel-{{panel.key}}">
<scrm-field-layout [dataSource]="getLayoutDataSource(panel)"></scrm-field-layout>
</div>
Expand Down Expand Up @@ -64,7 +64,7 @@
<ng-container *ngIf="(panel.display$ | async) as panelDisplay">
<div class="row no-gutters mt-3" *ngIf="!!panelDisplay">
<div class="col" *ngIf="j==active-1">
<scrm-panel [title]="panel.label" mode="collapsible">
<scrm-panel [title]="panel.label" [isCollapsed$]="(panel.isCollapsed | toObservable)" mode="collapsible">
<div panel-body class="panel-{{panel.key}}">
<scrm-field-layout [dataSource]="getLayoutDataSource(panel)"></scrm-field-layout>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ export class RecordContentComponent implements OnInit, OnDestroy {
}));
this.subs.push(this.dataSource.getPanels().subscribe(panels => {
this.panels = [...panels];
if (this?.config?.layout === 'tabs') {
this.updatePanelsArray();
if (this?.config?.layout === 'panels') {
this.updatePanelCollapseState();
} else {
this.updatePanelsInTabs();
}
}));
this.subs.push(this.dataSource.getRecord().subscribe(record => {
Expand All @@ -74,28 +76,19 @@ export class RecordContentComponent implements OnInit, OnDestroy {
this.subs.forEach(sub => sub.unsubscribe());
}

updatePanelsArray(): void {
updatePanelsInTabs(): void {
let tempPanels = [];
let prevTabKey = '';

const panelsMap = this.buildPanelMap();

const tabDefs = this.mapTabDefs();

if(!Object.keys(tabDefs ?? {}).length) {
Object.keys(panelsMap ?? {}).forEach(key => {
tabDefs[key.toUpperCase()] = {
newTab: true,
panelDefault: 'expanded'
};
});
}

Object.keys(tabDefs).forEach(tabDefKey => {
const tabDef = tabDefs[tabDefKey];

if (isTrue(tabDef.newTab)) {
tempPanels = [...tempPanels, panelsMap[tabDefKey]]
tempPanels = [...tempPanels, panelsMap[tabDefKey]];
prevTabKey = tabDefKey;
} else {
const prevTab = tabDefs[prevTabKey];
Expand Down Expand Up @@ -126,12 +119,28 @@ export class RecordContentComponent implements OnInit, OnDestroy {

}

updatePanelCollapseState(): void {
const panelMap = this.buildPanelMap();

this.panels.forEach(panel => {
const panelKey = panel.key.toUpperCase();
if (panelMap[panelKey]) {
panel.isCollapsed = panelMap[panelKey].isCollapsed;
}
});
}

buildPanelMap(): any {
const panelMap = {};

this.panels.forEach(panel => {
let isCollapsed = false;
panel.label = panel?.label?.toUpperCase() ?? '';
const panelKey = panel?.key?.toUpperCase() ?? '';
if (panel.meta.panelDefault === 'collapsed') {
isCollapsed = true;
}
panel.isCollapsed = isCollapsed;
panelMap[panelKey] = panel;
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {NgbModule} from '@ng-bootstrap/ng-bootstrap';
import {RecordContentComponent} from './record-content.component';
import {PanelModule} from '../panel/panel.module';
import {FieldLayoutModule} from '../field-layout/field-layout.module';
import {ToObservableModule} from '../../pipes/toObservable/toObservable.module';


@NgModule({
Expand All @@ -43,7 +44,8 @@ import {FieldLayoutModule} from '../field-layout/field-layout.module';
CommonModule,
PanelModule,
NgbModule,
FieldLayoutModule
FieldLayoutModule,
ToObservableModule,
]
})
export class RecordContentModule {
Expand Down
2 changes: 2 additions & 0 deletions core/app/core/src/lib/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,8 @@ export * from './pipes/format-number/format-number.module';
export * from './pipes/format-number/format-number.pipe';
export * from './pipes/html-sanitize/html-sanitize.module';
export * from './pipes/html-sanitize/html-sanitize.pipe';
export * from './pipes/toObservable/toObservable.module';
export * from './pipes/toObservable/toObservable.pipe';
export * from './services/actions/base-action-manager.service';
export * from './services/actions/base-action.adapter';
export * from './services/actions/base-record-action.adapter';
Expand Down
44 changes: 44 additions & 0 deletions core/app/core/src/lib/pipes/toObservable/toObservable.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* SuiteCRM is a customer relationship management program developed by SalesAgility Ltd.
* Copyright (C) 2023 SalesAgility Ltd.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SALESAGILITY, SALESAGILITY DISCLAIMS THE
* WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* In accordance with Section 7(b) of the GNU Affero General Public License
* version 3, these Appropriate Legal Notices must retain the display of the
* "Supercharged by SuiteCRM" logo. If the display of the logos is not reasonably
* feasible for technical reasons, the Appropriate Legal Notices must display
* the words "Supercharged by SuiteCRM".
*/

import {NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
import {ToObservablePipe} from './toObservable.pipe';


@NgModule({
declarations: [
ToObservablePipe
],
exports: [
ToObservablePipe
],
imports: [
CommonModule
]
})
export class ToObservableModule {
}
37 changes: 37 additions & 0 deletions core/app/core/src/lib/pipes/toObservable/toObservable.pipe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* SuiteCRM is a customer relationship management program developed by SalesAgility Ltd.
* Copyright (C) 2023 SalesAgility Ltd.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SALESAGILITY, SALESAGILITY DISCLAIMS THE
* WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* In accordance with Section 7(b) of the GNU Affero General Public License
* version 3, these Appropriate Legal Notices must retain the display of the
* "Supercharged by SuiteCRM" logo. If the display of the logos is not reasonably
* feasible for technical reasons, the Appropriate Legal Notices must display
* the words "Supercharged by SuiteCRM".
*/

import { Pipe, PipeTransform } from '@angular/core';
import { Observable, of } from 'rxjs';

@Pipe({
name: 'toObservable'
})
export class ToObservablePipe implements PipeTransform {
transform(value: any): Observable<any> {
return of(value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {MessageService} from '../../../../services/message/message.service';
import {Record, ViewMode} from 'common';
import {RecordStoreFactory} from '../../../../store/record/record.store.factory';
import {UserPreferenceStore} from '../../../../store/user-preference/user-preference.store';
import {PanelLogicManager} from '../../../../components/panel-logic/panel-logic.manager';

@Injectable()
export class CreateViewStore extends RecordViewStore {
Expand All @@ -64,7 +65,8 @@ export class CreateViewStore extends RecordViewStore {
protected statisticsBatch: StatisticsBatch,
protected auth: AuthService,
protected recordStoreFactory: RecordStoreFactory,
protected preferences: UserPreferenceStore
protected preferences: UserPreferenceStore,
protected panelLogicManager: PanelLogicManager
) {
super(
recordFetchGQL,
Expand All @@ -80,7 +82,8 @@ export class CreateViewStore extends RecordViewStore {
recordManager,
statisticsBatch,
recordStoreFactory,
preferences
preferences,
panelLogicManager
);
}

Expand Down Expand Up @@ -177,6 +180,7 @@ export class CreateViewStore extends RecordViewStore {
tap((data: Record) => {
data.id = '';
data.attributes.id = '';
// eslint-disable-next-line camelcase,@typescript-eslint/camelcase
data.attributes.date_entered = '';
this.recordManager.injectParamFields(this.params, data, this.getVardefs());
this.recordStore.setRecord(data);
Expand Down
Loading