Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Invite User button in dynamic SelectInputComponent (#9267)

Aleix Suaud4b54bd8dd28
diff --git a/frontend/src/app/modules/common/dynamic-forms/components/dynamic-inputs/select-input/select-input.component.html b/frontend/src/app/modules/common/dynamic-forms/components/dynamic-inputs/select-input/select-input.component.html
index 725d4f3d642..18aa6f3d6be 100644
--- a/frontend/src/app/modules/common/dynamic-forms/components/dynamic-inputs/select-input/select-input.component.html
+++ b/frontend/src/app/modules/common/dynamic-forms/components/dynamic-inputs/select-input/select-input.component.html
@@ -19,4 +19,8 @@
<ng-template ng-option-tmp let-item="item" let-search="searchTerm">
<div [ngOptionHighlight]="search" class="ng-option-label ellipsis">{{ item.name }}</div>
</ng-template>
+
+ <ng-template ng-footer-tmp *ngIf="to.showAddNewUserButton">
+ <op-invite-user-button class="op-select-footer"></op-invite-user-button>
+ </ng-template>
</ng-select>
\ No newline at end of file
diff --git a/frontend/src/app/modules/common/dynamic-forms/dynamic-forms.module.ts b/frontend/src/app/modules/common/dynamic-forms/dynamic-forms.module.ts
index 848f3947dc1..cd4c8aac4ab 100644
--- a/frontend/src/app/modules/common/dynamic-forms/dynamic-forms.module.ts
+++ b/frontend/src/app/modules/common/dynamic-forms/dynamic-forms.module.ts
@@ -22,6 +22,7 @@ import { OpenprojectCommonModule } from "core-app/modules/common/openproject-com
import { FormattableEditFieldModule } from "core-app/modules/fields/edit/field-types/formattable-edit-field/formattable-edit-field.module";
import { DatePickerModule } from "core-app/modules/common/op-date-picker/date-picker.module";
import { DynamicFieldWrapperComponent } from './components/dynamic-field-wrapper/dynamic-field-wrapper.component';
+import { InviteUserButtonModule } from "core-app/modules/invite-user-modal/button/invite-user-button.module";
@NgModule({
imports: [
@@ -57,6 +58,7 @@ import { DynamicFieldWrapperComponent } from './components/dynamic-field-wrapper
NgOptionHighlightModule,
FormattableEditFieldModule,
OpenprojectEditorModule,
+ InviteUserButtonModule,
],
declarations: [
DynamicFieldGroupWrapperComponent,
diff --git a/frontend/src/app/modules/common/dynamic-forms/services/dynamic-fields/dynamic-fields.service.ts b/frontend/src/app/modules/common/dynamic-forms/services/dynamic-fields/dynamic-fields.service.ts
index 7a08a0c812f..89005730e8d 100644
--- a/frontend/src/app/modules/common/dynamic-forms/services/dynamic-fields/dynamic-fields.service.ts
+++ b/frontend/src/app/modules/common/dynamic-forms/services/dynamic-fields/dynamic-fields.service.ts
@@ -235,23 +235,24 @@ export class DynamicFieldsService {
private getFieldTypeConfig(field:IOPFieldSchemaWithKey):IOPFormlyFieldSettings|null {
const fieldType = field.type.replace('[]', '') as OPFieldType;
let inputType = this.inputsCatalogue.find(inputType => inputType.useForFields.includes(fieldType))!;
+
if (!inputType) {
console.warn(
`Could not find a input definition for a field with the folowing type: ${fieldType}. The full field configuration is`, field
);
return null;
}
+
let inputConfig = inputType.config;
let configCustomizations;
if (inputConfig.type === 'integerInput' || inputConfig.type === 'selectInput' || inputConfig.type === 'selectProjectStatusInput') {
configCustomizations = {
className: field.name,
- ...field.type.startsWith('[]') && {
- templateOptions: {
- ...inputConfig.templateOptions,
- multiple: true
- }
+ templateOptions: {
+ ...inputConfig.templateOptions,
+ ...field.type.startsWith('[]') && {multiple: true},
+ ...fieldType === 'User' && {showAddNewUserButton: true},
},
};
} else if (inputConfig.type === 'formattableInput') {
diff --git a/frontend/src/app/modules/common/dynamic-forms/typings.d.ts b/frontend/src/app/modules/common/dynamic-forms/typings.d.ts
index a2d6dc2d2c1..e6801b2a7d1 100644
--- a/frontend/src/app/modules/common/dynamic-forms/typings.d.ts
+++ b/frontend/src/app/modules/common/dynamic-forms/typings.d.ts
@@ -24,10 +24,11 @@ export interface IOPFormlyTemplateOptions extends FormlyTemplateOptions {
collapsibleFieldGroupsCollapsed?:boolean;
helpTextAttributeScope?:string;
showValidationErrorOn?:'change' | 'blur' | 'submit' | 'never';
+ showAddNewUserButton?:boolean;
}
type OPInputType = 'formattableInput'|'selectInput'|'textInput'|'integerInput'|
- 'booleanInput'| 'dateInput' | 'formly-group'|'selectProjectStatusInput';
+ 'booleanInput'|'dateInput'|'formly-group'|'selectProjectStatusInput';
export interface IOPDynamicInputTypeSettings {
config:IOPFormlyFieldSettings,
diff --git a/frontend/src/app/modules/fields/edit/field-types/multi-select-edit-field.component.html b/frontend/src/app/modules/fields/edit/field-types/multi-select-edit-field.component.html
index 1c6607f4001..9f786613c56 100644
--- a/frontend/src/app/modules/fields/edit/field-types/multi-select-edit-field.component.html
+++ b/frontend/src/app/modules/fields/edit/field-types/multi-select-edit-field.component.html
@@ -18,7 +18,7 @@
[appendTo]="appendTo"
[dropdownPosition]="'top'"
[hideSelected]="true">
- <ng-template ng-footer-tmp>
+ <ng-template ng-footer-tmp *ngIf="showAddNewUserButton">
<op-invite-user-button (invited)="selectedOption = $event"></op-invite-user-button>
</ng-template>
</ng-select>
diff --git a/frontend/src/app/modules/fields/edit/field-types/multi-select-edit-field.component.ts b/frontend/src/app/modules/fields/edit/field-types/multi-select-edit-field.component.ts
index 1d1c08fb4d7..7ca991883c7 100644
--- a/frontend/src/app/modules/fields/edit/field-types/multi-select-edit-field.component.ts
+++ b/frontend/src/app/modules/fields/edit/field-types/multi-select-edit-field.component.ts
@@ -50,11 +50,11 @@ export class MultiSelectEditFieldComponent extends EditFieldComponent implements
save: this.I18n.t('js.inplace.button_save', { attribute: this.schema.name }),
cancel: this.I18n.t('js.inplace.button_cancel', { attribute: this.schema.name }),
};
-
public appendTo:any = null;
- private hiddenOverflowContainer = '.__hidden_overflow_container';
-
public currentValueInvalid = false;
+ public showAddNewUserButton:boolean;
+
+ private hiddenOverflowContainer = '.__hidden_overflow_container';
private nullOption:ValueOption;
private _selectedOption:ValueOption[];
@@ -63,6 +63,7 @@ export class MultiSelectEditFieldComponent extends EditFieldComponent implements
ngOnInit() {
this.nullOption = { name: this.text.placeholder, href: null };
+ this.showAddNewUserButton = this.schema.type === 'User';
this.handler
.$onUserActivate
diff --git a/frontend/src/app/modules/fields/edit/field-types/select-edit-field/select-edit-field.component.ts b/frontend/src/app/modules/fields/edit/field-types/select-edit-field/select-edit-field.component.ts
index 6be0712935a..dda4ac34c45 100644
--- a/frontend/src/app/modules/fields/edit/field-types/select-edit-field/select-edit-field.component.ts
+++ b/frontend/src/app/modules/fields/edit/field-types/select-edit-field/select-edit-field.component.ts
@@ -136,11 +136,7 @@ export class SelectEditFieldComponent extends EditFieldComponent implements OnIn
}
initializeShowAddButton() {
- if (this.schema.type === 'User') {
- this.permissionsService
- .canInviteUsersToProject()
- .subscribe(canInviteUsersToProject => this.showAddNewButton = canInviteUsersToProject);
- }
+ this.showAddNewButton = this.schema.type === 'User';
}
protected initialValueLoading() {
diff --git a/frontend/src/app/modules/invite-user-modal/button/invite-user-button.component.html b/frontend/src/app/modules/invite-user-modal/button/invite-user-button.component.html
index c450c22f3ea..15a287dfcde 100644
--- a/frontend/src/app/modules/invite-user-modal/button/invite-user-button.component.html
+++ b/frontend/src/app/modules/invite-user-modal/button/invite-user-button.component.html
@@ -2,7 +2,7 @@
class="op-select-footer--label"
type="button"
(click)="onAddNewClick($event)"
- *ngIf="showButton"
+ *ngIf="canInviteUsersToProject"
>
<span class="icon-context">
<op-icon icon-classes="icon-user-plus icon-context"></op-icon>
diff --git a/frontend/src/app/modules/invite-user-modal/button/invite-user-button.component.ts b/frontend/src/app/modules/invite-user-modal/button/invite-user-button.component.ts
index 16b66755814..44a246df5c8 100644
--- a/frontend/src/app/modules/invite-user-modal/button/invite-user-button.component.ts
+++ b/frontend/src/app/modules/invite-user-modal/button/invite-user-button.component.ts
@@ -1,9 +1,5 @@
-import { Component, Inject, OnInit, Optional } from '@angular/core';
+import { ChangeDetectorRef, Component, OnInit } from '@angular/core';
import { NgSelectComponent } from "@ng-select/ng-select";
-import { OpEditingPortalSchemaToken } from "core-app/modules/fields/edit/edit-field.component";
-import { IFieldSchema } from "core-app/modules/fields/field.base";
-import { SelectEditFieldComponent } from "core-app/modules/fields/edit/field-types/select-edit-field/select-edit-field.component";
-import { MultiSelectEditFieldComponent } from "core-app/modules/fields/edit/field-types/multi-select-edit-field.component";
import { I18nService } from "core-app/modules/common/i18n/i18n.service";
import { PermissionsService } from "core-app/core/services/permissions/permissions.service";
import { OpInviteUserModalService } from "core-app/modules/invite-user-modal/invite-user-modal.service";
@@ -14,23 +10,11 @@ import { OpInviteUserModalService } from "core-app/modules/invite-user-modal/inv
styleUrls: ['./invite-user-button.component.sass']
})
export class InviteUserButtonComponent implements OnInit {
- /* This component does not provide an output, because both primary usecases were in places where the button was
+ /** This component does not provide an output, because both primary usecases were in places where the button was
* destroyed before the modal closed, causing the data from the modal to never arrive at the parent.
* If you want to do something with the output from the modal that is opened, use the OpInviteUserModalService
* and subscribe to the `close` event there.
*/
-
- get showButton() {
- const showButton = this.schema?.type === 'User' &&
- this.canInviteUsersToProject &&
- (this.selectEditFieldComponent || this.multiSelectEditFieldComponent);
-
- return showButton;
- }
- get parentIsMultiSelectEditFieldComponent() {
- return !!this.multiSelectEditFieldComponent;
- }
-
text = {
button: this.I18n.t('js.invite_user_modal.invite'),
};
@@ -41,15 +25,16 @@ export class InviteUserButtonComponent implements OnInit {
readonly opInviteUserModalService:OpInviteUserModalService,
readonly permissionsService:PermissionsService,
readonly ngSelectComponent:NgSelectComponent,
- @Optional() readonly selectEditFieldComponent:SelectEditFieldComponent,
- @Optional() readonly multiSelectEditFieldComponent:MultiSelectEditFieldComponent,
- @Inject(OpEditingPortalSchemaToken) public schema:IFieldSchema,
+ readonly changeDetectorRef:ChangeDetectorRef,
) {}
ngOnInit():void {
this.permissionsService
.canInviteUsersToProject()
- .subscribe(canInviteUsersToProject => this.canInviteUsersToProject = canInviteUsersToProject);
+ .subscribe(canInviteUsersToProject => {
+ this.canInviteUsersToProject = canInviteUsersToProject;
+ this.changeDetectorRef.detectChanges();
+ });
}
onAddNewClick($event:Event) {
diff --git a/frontend/src/app/modules/invite-user-modal/button/invite-user-button.module.ts b/frontend/src/app/modules/invite-user-modal/button/invite-user-button.module.ts
new file mode 100644
index 00000000000..267d2439aad
--- /dev/null
+++ b/frontend/src/app/modules/invite-user-modal/button/invite-user-button.module.ts
@@ -0,0 +1,20 @@
+import { NgModule } from '@angular/core';
+import { CommonModule } from '@angular/common';
+import { InviteUserButtonComponent } from "core-app/modules/invite-user-modal/button/invite-user-button.component";
+import { IconModule } from "core-app/modules/icon/icon.module";
+
+
+
+@NgModule({
+ declarations: [
+ InviteUserButtonComponent,
+ ],
+ imports: [
+ CommonModule,
+ IconModule,
+ ],
+ exports: [
+ InviteUserButtonComponent,
+ ]
+})
+export class InviteUserButtonModule { }
diff --git a/frontend/src/app/modules/invite-user-modal/invite-user-modal.module.ts b/frontend/src/app/modules/invite-user-modal/invite-user-modal.module.ts
index 21dd47388d3..bfd2efeef4b 100644
--- a/frontend/src/app/modules/invite-user-modal/invite-user-modal.module.ts
+++ b/frontend/src/app/modules/invite-user-modal/invite-user-modal.module.ts
@@ -6,7 +6,6 @@ import { NgSelectModule } from "@ng-select/ng-select";
import { OpenprojectModalModule } from "core-app/modules/modal/modal.module";
import { OpenprojectCommonModule } from "core-app/modules/common/openproject-common.module";
import { DynamicFormsModule } from "core-app/modules/common/dynamic-forms/dynamic-forms.module";
-import { InviteUserButtonComponent } from "core-app/modules/invite-user-modal/button/invite-user-button.component";
import { OpInviteUserModalAugmentService } from "core-app/modules/invite-user-modal/invite-user-modal-augment.service";
import { OpInviteUserModalService } from "core-app/modules/invite-user-modal/invite-user-modal.service";
import { InviteUserModalComponent } from "./invite-user.component";
@@ -19,6 +18,7 @@ import { RoleSearchComponent } from "./role/role-search.component";
import { MessageComponent } from "./message/message.component";
import { SummaryComponent } from "./summary/summary.component";
import { SuccessComponent } from "./success/success.component";
+import { InviteUserButtonModule } from "core-app/modules/invite-user-modal/button/invite-user-button.module";
export function initializeServices(injector:Injector) {
return function () {
@@ -36,13 +36,13 @@ export function initializeServices(injector:Injector) {
ReactiveFormsModule,
TextFieldModule,
DynamicFormsModule,
+ InviteUserButtonModule,
],
exports: [
- InviteUserButtonComponent,
+ InviteUserButtonModule,
],
declarations: [
InviteUserModalComponent,
- InviteUserButtonComponent,
ProjectSelectionComponent,
ProjectSearchComponent,
PrincipalComponent,