remove level list implementation

With the project selector now using the API, the rails controller action is no longer necessary
pull/10896/head
ulferts 2 years ago committed by Oliver Günther
parent b046ad1228
commit 8f581ffdd9
  1. 10
      app/controllers/projects_controller.rb
  2. 16
      app/helpers/projects_helper.rb
  3. 15
      app/models/project.rb
  4. 4
      config/routes.rb
  5. 4
      frontend/src/app/core/path-helper/path-helper.service.ts
  6. 42
      spec/helpers/projects_helper_spec.rb
  7. 8
      spec/routing/project_routing_spec.rb

@ -30,7 +30,7 @@ class ProjectsController < ApplicationController
menu_item :overview menu_item :overview
menu_item :roadmap, only: :roadmap menu_item :roadmap, only: :roadmap
before_action :find_project, except: %i[index level_list new] before_action :find_project, except: %i[index new]
before_action :authorize, only: %i[copy] before_action :authorize, only: %i[copy]
before_action :authorize_global, only: %i[new] before_action :authorize_global, only: %i[new]
before_action :require_admin, only: %i[destroy destroy_info] before_action :require_admin, only: %i[destroy destroy_info]
@ -102,14 +102,6 @@ class ProjectsController < ApplicationController
hide_project_in_layout hide_project_in_layout
end end
def level_list
projects = Project.project_level_list(Project.visible)
respond_to do |format|
format.json { render json: projects_level_list_json(projects) }
end
end
private private
def find_optional_project def find_optional_project

@ -169,22 +169,6 @@ module ProjectsHelper
end end
end end
def projects_level_list_json(projects)
projects_list = projects.map do |item|
project = item[:project]
{
id: project.id,
name: project.name,
identifier: project.identifier,
has_children: !project.leaf?,
level: item[:level]
}
end
{ projects: projects_list }
end
def projects_with_levels_order_sensitive(projects, &) def projects_with_levels_order_sensitive(projects, &)
if sorted_by_lft? if sorted_by_lft?
project_tree(projects, &) project_tree(projects, &)

@ -395,21 +395,6 @@ class Project < ApplicationRecord
project_tree_from_hierarchy(projects_hierarchy, 0, &) project_tree_from_hierarchy(projects_hierarchy, 0, &)
end end
def project_level_list(projects)
list = []
project_tree(projects) do |project, level|
element = {
project:,
level:
}
element.merge!(yield(project)) if block_given?
list << element
end
list
end
private private
def sort_by_name(project_hashes) def sort_by_name(project_hashes)

@ -202,10 +202,6 @@ OpenProject::Application.routes.draw do
get :destroy_info, as: 'confirm_destroy' get :destroy_info, as: 'confirm_destroy'
end end
collection do
get :level_list
end
resources :versions, only: %i[new create] do resources :versions, only: %i[new create] do
collection do collection do
put :close_completed put :close_completed

@ -252,10 +252,6 @@ export class PathHelperService {
return `${this.workPackagesPath()}/bulk`; return `${this.workPackagesPath()}/bulk`;
} }
public projectLevelListPath() {
return `${this.projectsPath()}/level_list.json`;
}
public textFormattingHelp() { public textFormattingHelp() {
return `${this.staticBase}/help/text_formatting`; return `${this.staticBase}/help/text_formatting`;
} }

@ -102,48 +102,6 @@ describe ProjectsHelper, type: :helper do
end end
end end
describe '#projects_level_list_json' do
subject { helper.projects_level_list_json(projects).to_json }
let(:projects) { [] }
describe 'with no project available' do
it 'renders an empty projects document' do
expect(subject).to have_json_size(0).at_path('projects')
end
end
describe 'with some projects available' do
let(:projects) do
p1 = build(:project, name: 'P1')
# a result from Project.project_level_list
[{ project: p1,
level: 0 },
{ project: build(:project, name: 'P2', parent: p1),
level: 1 },
{ project: build(:project, name: 'P3'),
level: 0 }]
end
it 'renders a projects document with the size of 3 of type array' do
expect(subject).to have_json_size(3).at_path('projects')
end
it 'renders all three projects' do
expect(subject).to be_json_eql('P1'.to_json).at_path('projects/0/name')
expect(subject).to be_json_eql('P2'.to_json).at_path('projects/1/name')
expect(subject).to be_json_eql('P3'.to_json).at_path('projects/2/name')
end
it 'renders the project levels' do
expect(subject).to be_json_eql(0.to_json).at_path('projects/0/level')
expect(subject).to be_json_eql(1.to_json).at_path('projects/1/level')
expect(subject).to be_json_eql(0.to_json).at_path('projects/2/level')
end
end
end
describe '#short_project_description' do describe '#short_project_description' do
let(:project) { build_stubbed(:project, description: (('Abcd ' * 5) + "\n") * 11) } let(:project) { build_stubbed(:project, description: (('Abcd ' * 5) + "\n") * 11) }

@ -118,12 +118,4 @@ describe ProjectsController, type: :routing do
) )
end end
end end
describe 'level_list' do
it do
expect(get('/projects/level_list.json')).to route_to(
controller: 'projects', action: 'level_list', format: 'json'
)
end
end
end end

Loading…
Cancel
Save