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

Allow disabled projects

Oliver Günthercc624fe5e6d4
diff --git a/frontend/src/app/shared/components/autocompleter/project-autocompleter/project-autocompleter.component.ts b/frontend/src/app/shared/components/autocompleter/project-autocompleter/project-autocompleter.component.ts
index 8d4676f64ba..298b5c394b0 100644
--- a/frontend/src/app/shared/components/autocompleter/project-autocompleter/project-autocompleter.component.ts
+++ b/frontend/src/app/shared/components/autocompleter/project-autocompleter/project-autocompleter.component.ts
@@ -90,6 +90,8 @@ export class ProjectAutocompleterComponent extends OpAutocompleterComponent<IPro
@Input() public isInlineContext = false;
+ @Input() public disabledProjects:{ [key:string]:string|boolean } = {};
+
// This function allows mapping of the results before they are fed to the tree
// structuring and destructuring algorithms used internally the this component
// to show the tree structure. By default it does not do much, but it is
@@ -140,9 +142,12 @@ export class ProjectAutocompleterComponent extends OpAutocompleterComponent<IPro
const arrayedValue = (Array.isArray(normalizedValue) ? normalizedValue : [normalizedValue]).map((p) => p.href || p.id);
return projects.map((project) => {
const isSelected = !!arrayedValue.find((selected) => selected === this.projectTracker(project));
+ const id = project.id.toString();
+ const disabled = isSelected || project.disabled || !!this.disabledProjects[id];
return {
...project,
- disabled: isSelected || project.disabled,
+ disabled,
+ disabledReason: (typeof this.disabledProjects[id] === 'string') ? this.disabledProjects[id] as string : '',
};
});
}
@@ -176,14 +181,20 @@ export class ProjectAutocompleterComponent extends OpAutocompleterComponent<IPro
},
)
.pipe(
- map((projects) => projects.map((project) => ({
- id: project.id,
- href: project._links.self.href,
- name: project.name,
- disabled: false,
- ancestors: project._links.ancestors,
- children: [],
- }))),
+ map((projects) => projects.map((project) => {
+ const id = project.id.toString();
+ const disabled = !!this.disabledProjects[id];
+
+ return {
+ id: project.id,
+ href: project._links.self.href,
+ name: project.name,
+ disabled,
+ disabledReason: (typeof this.disabledProjects[id] === 'string') ? this.disabledProjects[id] as string : '',
+ ancestors: project._links.ancestors,
+ children: [],
+ };
+ })),
map(this.mapResultsFn),
map((projects) => {
this.dataLoaded = true;
diff --git a/lib/primer/open_project/forms/dsl/project_autocompleter_input.rb b/lib/primer/open_project/forms/dsl/project_autocompleter_input.rb
index f0ed2ae09fd..5b58c0ba542 100644
--- a/lib/primer/open_project/forms/dsl/project_autocompleter_input.rb
+++ b/lib/primer/open_project/forms/dsl/project_autocompleter_input.rb
@@ -6,11 +6,17 @@ module Primer
module Dsl
class ProjectAutocompleterInput < AutocompleterInput
def derive_autocompleter_options(options)
- options.reverse_merge(
+ options.reverse_merge!(
component: "opce-project-autocompleter",
defaultData: false,
filters: [{ name: 'active', operator: '=', values: ['t'] }],
)
+
+ if options[:disabledProjects]
+ options[:disabledProjects].stringify_keys!
+ end
+
+ options
end
end
end
diff --git a/lookbook/previews/open_project/common/autocomplete_preview/project.html.erb b/lookbook/previews/open_project/common/autocomplete_preview/project.html.erb
index 1f98f6a3523..b597688638a 100644
--- a/lookbook/previews/open_project/common/autocomplete_preview/project.html.erb
+++ b/lookbook/previews/open_project/common/autocomplete_preview/project.html.erb
@@ -8,7 +8,8 @@
autocomplete_options: {
openDirectly: false,
focusDirectly: false,
- dropdownPosition: 'bottom'
+ dropdownPosition: 'bottom',
+ disabledProjects: Project.visible.take(10).pluck(:id).to_h { |id| [id, "Disabled reason!"] }
}
)
end