Skip to content

Commit

Permalink
Merge pull request #10694 from opf/fix/42398-form-configuration-is-ac…
Browse files Browse the repository at this point in the history
…cessible-without-ee-token

[42398] Form configuration is accessible without EE token
  • Loading branch information
HDinger committed May 17, 2022
2 parents 7ec8c83 + 4a70e08 commit d9cfd88
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 34 deletions.
Expand Up @@ -66,7 +66,7 @@ export class GroupEditInPlaceComponent implements OnInit {
}
}

startEditing() {
startEditing():void {
this.bannerService.conditional(
() => this.bannerService.showEEOnlyHint(),
() => {
Expand All @@ -75,7 +75,7 @@ export class GroupEditInPlaceComponent implements OnInit {
);
}

saveEdition(event:FocusEvent) {
saveEdition(event:FocusEvent):boolean {
this.leaveEditingMode();
this.name = this.editedName.trim();

Expand All @@ -91,12 +91,12 @@ export class GroupEditInPlaceComponent implements OnInit {
return false;
}

reset() {
reset():void {
this.editing = false;
this.editedName = this.name;
}

leaveEditingMode() {
leaveEditingMode():void {
// Only leave Editing mode if name not empty.
if (this.editedName != null && this.editedName.trim().length > 0) {
this.editing = false;
Expand Down
Expand Up @@ -2,6 +2,7 @@ import {
ChangeDetectionStrategy, ChangeDetectorRef, Component, EventEmitter, Input, Output,
} from '@angular/core';
import { I18nService } from 'core-app/core/i18n/i18n.service';
import { TypeGroup } from 'core-app/features/admin/types/type-form-configuration.component';

@Component({
selector: 'op-type-form-query-group',
Expand All @@ -13,7 +14,7 @@ export class TypeFormQueryGroupComponent {
edit_query: this.I18n.t('js.admin.type_form.edit_query'),
};

@Input() public group:any;
@Input() public group:TypeGroup;

@Output() public editQuery = new EventEmitter<void>();

Expand All @@ -23,7 +24,7 @@ export class TypeFormQueryGroupComponent {
private cdRef:ChangeDetectorRef) {
}

rename(newValue:string) {
rename(newValue:string):void {
this.group.name = newValue;
this.cdRef.detectChanges();
}
Expand Down
Expand Up @@ -70,13 +70,16 @@ export class TypeFormConfigurationComponent extends UntilDestroyedMixin implemen

private no_filter_query:string;

constructor(private elementRef:ElementRef,
constructor(
private elementRef:ElementRef,
private I18n:I18nService,
private Gon:GonService,
private dragula:DragulaService,
private confirmDialog:ConfirmDialogService,
private toastService:ToastService,
private externalRelationQuery:ExternalRelationQueryConfigurationService) {
private externalRelationQuery:ExternalRelationQueryConfigurationService,
readonly typeBanner:TypeBannerService,
) {
super();
}

Expand Down Expand Up @@ -154,45 +157,55 @@ export class TypeFormConfigurationComponent extends UntilDestroyedMixin implemen
);
}

ngAfterViewInit() {
ngAfterViewInit():void {
const menu = jQuery(this.elementRef.nativeElement).find('.toolbar-items');
installMenuLogic(menu);
}

public deactivateAttribute(attribute:TypeFormAttribute) {
deactivateAttribute(attribute:TypeFormAttribute):void {
this.updateInactives(this.inactives.concat(attribute));
}

public addGroupAndOpenQuery():void {
addGroupAndOpenQuery():void {
const newGroup = this.createGroup('query');
this.editQuery(newGroup);
}

public editQuery(group:TypeGroup) {
// Disable display mode and timeline for now since we don't want users to enable it
const disabledTabs = {
'display-settings': I18n.t('js.work_packages.table_configuration.embedded_tab_disabled'),
timelines: I18n.t('js.work_packages.table_configuration.embedded_tab_disabled'),
};

this.externalRelationQuery.show({
currentQuery: JSON.parse(group.query),
callback: (queryProps:any) => (group.query = JSON.stringify(queryProps)),
disabledTabs,
});
editQuery(group:TypeGroup):void {
this.typeBanner.conditional(
() => this.typeBanner.showEEOnlyHint(),
() => {
// Disable display mode and timeline for now since we don't want users to enable it
const disabledTabs = {
'display-settings': I18n.t('js.work_packages.table_configuration.embedded_tab_disabled'),
timelines: I18n.t('js.work_packages.table_configuration.embedded_tab_disabled'),
};

this.externalRelationQuery.show({
currentQuery: JSON.parse(group.query),
callback: (queryProps:any) => (group.query = JSON.stringify(queryProps)),
disabledTabs,
});
},
);
}

public deleteGroup(group:TypeGroup) {
if (group.type === 'attribute') {
this.updateInactives(this.inactives.concat(group.attributes));
}
deleteGroup(group:TypeGroup):void {
this.typeBanner.conditional(
() => this.typeBanner.showEEOnlyHint(),
() => {
if (group.type === 'attribute') {
this.updateInactives(this.inactives.concat(group.attributes));
}

this.groups = this.groups.filter((el) => el !== group);
this.groups = this.groups.filter((el) => el !== group);

return group;
return group;
},
);
}

public createGroup(type:TypeGroupType, groupName = '') {
createGroup(type:TypeGroupType, groupName = ''):TypeGroup {
const group:TypeGroup = {
type,
name: groupName,
Expand All @@ -205,7 +218,7 @@ export class TypeFormConfigurationComponent extends UntilDestroyedMixin implemen
return group;
}

public resetToDefault($event:Event):boolean {
resetToDefault($event:Event):boolean {
this.confirmDialog
.confirm({
text: {
Expand All @@ -227,7 +240,7 @@ export class TypeFormConfigurationComponent extends UntilDestroyedMixin implemen
return false;
}

private updateInactives(newValue:TypeFormAttribute[]) {
private updateInactives(newValue:TypeFormAttribute[]):void {
this.inactives = [...newValue].sort((a, b) => a.translation.localeCompare(b.translation));
}

Expand All @@ -241,7 +254,7 @@ export class TypeFormConfigurationComponent extends UntilDestroyedMixin implemen
};
}

private updateHiddenFields() {
private updateHiddenFields():void {
const hiddenField = this.form.find('.admin-type-form--hidden-field');
if (this.groups.length === 0) {
// Ensure we're adding an empty group if deliberately removing
Expand Down
Expand Up @@ -9,7 +9,9 @@
<span class="button--text" [textContent]="text.reset"></span>
</button>
</li>
<li class="toolbar-item drop-down">
<li
*ngIf="!typeBanner.eeShowBanners"
class="toolbar-item drop-down">
<a class="form-configuration--add-group button -alt-highlight" aria-haspopup="true">
<op-icon icon-classes="button--icon icon-add"></op-icon>
<span class="button--text" [textContent]="text.label_group"></span>
Expand Down

0 comments on commit d9cfd88

Please sign in to comment.