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

hide active field in project form (#9204)

ulferts2b7f71958cf4
diff --git a/frontend/src/app/modules/projects/components/projects/projects.component.ts b/frontend/src/app/modules/projects/components/projects/projects.component.ts
index 8aa0e8f67a0..2d2ec6d61ef 100644
--- a/frontend/src/app/modules/projects/components/projects/projects.component.ts
+++ b/frontend/src/app/modules/projects/components/projects/projects.component.ts
@@ -13,8 +13,9 @@ import { IOPFormlyFieldSettings } from "core-app/modules/common/dynamic-forms/ty
export class ProjectsComponent extends UntilDestroyedMixin implements OnInit {
resourceId:string;
projectsPath:string;
- text:{[key:string]:string};
+ text:{ [key:string]:string };
dynamicFieldsSettingsPipe:(dynamicFieldsSettings:IOPFormlyFieldSettings[]) => IOPFormlyFieldSettings[];
+ hiddenFields = ['identifier', 'active'];
constructor(
private _uIRouterGlobals:UIRouterGlobals,
@@ -24,13 +25,13 @@ export class ProjectsComponent extends UntilDestroyedMixin implements OnInit {
super();
}
- ngOnInit(): void {
+ ngOnInit():void {
this.projectsPath = this._pathHelperService.projectsPath();
this.resourceId = this._uIRouterGlobals.params.projectPath;
this.dynamicFieldsSettingsPipe = (dynamicFieldsSettings) => {
return dynamicFieldsSettings
.reduce((formattedDynamicFieldsSettings, dynamicFormField) => {
- if (dynamicFormField.key === 'identifier') {
+ if (this.isFieldHidden(dynamicFormField.key)) {
dynamicFormField = {
...dynamicFormField,
hide: true,
@@ -48,4 +49,8 @@ export class ProjectsComponent extends UntilDestroyedMixin implements OnInit {
this._$state.go('.', { ...this._$state.params, projectPath: formResource.identifier });
}
}
+
+ private isFieldHidden(name:string|undefined) {
+ return this.hiddenFields.includes(name || '');
+ }
}
diff --git a/spec/features/projects/projects_spec.rb b/spec/features/projects/projects_spec.rb
index 1f5ea5f115d..1f007758f40 100644
--- a/spec/features/projects/projects_spec.rb
+++ b/spec/features/projects/projects_spec.rb
@@ -45,7 +45,7 @@ describe 'Projects', type: :feature, js: true do
it 'can create a project' do
click_on 'New project'
- fill_in 'project[name]', with: 'Foo bar'
+ fill_in 'Name', with: 'Foo bar'
click_on 'Create'
expect(page).to have_content 'Successful creation.'
@@ -58,7 +58,7 @@ describe 'Projects', type: :feature, js: true do
it 'creates a project and redirects to settings' do
click_on 'New project'
- fill_in 'project[name]', with: 'Foo bar'
+ fill_in 'Name', with: 'Foo bar'
click_on 'Create'
expect(page).to have_content 'Successful creation.'
@@ -202,42 +202,65 @@ describe 'Projects', type: :feature, js: true do
describe 'form' do
let(:project) { FactoryBot.build(:project, name: 'Foo project', identifier: 'foo-project') }
- let!(:optional_custom_field) do
- FactoryBot.create(:custom_field, name: 'Optional Foo',
- type: ProjectCustomField,
- is_for_all: true)
+
+ context 'when creating' do
+ it 'hides the active field and the identifier' do
+ visit new_project_path
+
+ expect(page).not_to have_field 'Active'
+ expect(page).not_to have_field 'Identifier'
+ end
end
- let!(:required_custom_field) do
- FactoryBot.create(:custom_field, name: 'Required Foo',
- type: ProjectCustomField,
- is_for_all: true,
- is_required: true)
+
+ context 'when editing' do
+ it 'hides the active field' do
+ project.save!
+
+ visit settings_generic_project_path(project.id)
+
+ expect(page).not_to have_field 'Active'
+ expect(page).not_to have_field 'Identifier'
+ end
end
- it 'seperates optional and required custom fields for new' do
- visit new_project_path
+ context 'with optional and required custom fields' do
+ let!(:optional_custom_field) do
+ FactoryBot.create(:custom_field, name: 'Optional Foo',
+ type: ProjectCustomField,
+ is_for_all: true)
+ end
+ let!(:required_custom_field) do
+ FactoryBot.create(:custom_field, name: 'Required Foo',
+ type: ProjectCustomField,
+ is_for_all: true,
+ is_required: true)
+ end
- expect(page).to have_content 'Required Foo'
+ it 'seperates optional and required custom fields for new' do
+ visit new_project_path
- click_on 'Advanced settings'
+ expect(page).to have_content 'Required Foo'
- within('#advanced-project-settings') do
- expect(page).to have_content 'Optional Foo'
- expect(page).not_to have_content 'Required Foo'
+ click_on 'Advanced settings'
+
+ within('#advanced-project-settings') do
+ expect(page).to have_content 'Optional Foo'
+ expect(page).not_to have_content 'Required Foo'
+ end
end
- end
- it 'shows optional and required custom fields for edit without an seperation' do
- project.custom_field_values.last.value = 'FOO'
- project.save!
+ it 'shows optional and required custom fields for edit without a separation' do
+ project.custom_field_values.last.value = 'FOO'
+ project.save!
- visit settings_generic_project_path(project.id)
+ visit settings_generic_project_path(project.id)
- expect(page).to have_content 'Required Foo'
- expect(page).to have_content 'Optional Foo'
+ expect(page).to have_content 'Required Foo'
+ expect(page).to have_content 'Optional Foo'
+ end
end
- context 'with a restricted custom field' do
+ context 'with a length restricted custom field' do
let(:project) { FactoryBot.create(:project, name: 'Foo project', identifier: 'foo-project') }
let!(:required_custom_field) do
FactoryBot.create(:string_project_custom_field,