Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#59037] Primerize "Log time" dialog #17268

Draft
wants to merge 16 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions app/forms/custom_fields/custom_field_rendering.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
module CustomFields::CustomFieldRendering
include ActiveSupport::Concern

def render_custom_fields(form:)
custom_fields.each do |custom_field|
form.fields_for(:custom_field_values) do |builder|
custom_field_input(builder, custom_field)
end
end
end

# override if you want to pass more attributes
def additional_custom_field_input_arguments
{}
end

def custom_fields
raise NotImplementedError, "#custom_fields method needs to be overwritten and provide all custom fields we want to show"
end

private

def custom_field_input(builder, custom_field)
if custom_field.multi_value?
multi_value_custom_field_input(builder, custom_field)
else
single_value_custom_field_input(builder, custom_field)
end
end

def form_arguments(custom_field)
{
custom_field: custom_field,
object: model
}.merge(additional_custom_field_input_arguments)
end

# TBD: transform inputs called below to primer form dsl instead of form classes?
# TODOS:
# - initial values for user inputs are not displayed
# - allow/disallow-non-open version setting is not yet respected in the version selector
# - rich text editor is not yet supported

def single_value_custom_field_input(builder, custom_field)
form_args = form_arguments(custom_field)

case custom_field.field_format
when "string", "link"
CustomFields::Inputs::String.new(builder, **form_args)
when "text"
CustomFields::Inputs::Text.new(builder, **form_args)
when "int"
CustomFields::Inputs::Int.new(builder, **form_args)
when "float"
CustomFields::Inputs::Float.new(builder, **form_args)
when "list"
CustomFields::Inputs::SingleSelectList.new(builder, **form_args)
when "date"
CustomFields::Inputs::Date.new(builder, **form_args)
when "bool"
CustomFields::Inputs::Bool.new(builder, **form_args)
when "user"
CustomFields::Inputs::SingleUserSelectList.new(builder, **form_args)
when "version"
CustomFields::Inputs::SingleVersionSelectList.new(builder, **form_args)
end
end

def multi_value_custom_field_input(builder, custom_field)
form_args = form_arguments(custom_field)

case custom_field.field_format
when "list"
CustomFields::Inputs::MultiSelectList.new(builder, **form_args)
when "user"
CustomFields::Inputs::MultiUserSelectList.new(builder, **form_args)
when "version"
CustomFields::Inputs::MultiVersionSelectList.new(builder, **form_args)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,17 @@ def search_key
end

def filters
[
filters = [
{ name: "type", operator: "=", values: ["User", "Group", "PlaceholderUser"] },
{ name: "member", operator: "=", values: [@object.id.to_s] },
{ name: "status", operator: "!", values: [Principal.statuses["locked"].to_s] }
]

if @object.is_a?(Project)
filters << { name: "member", operator: "=", values: [@object.id.to_s] }
elsif @object.respond_to?(:project_id)
filters << { name: "member", operator: "=", values: [@object.project_id.to_s] }
end

filters
end
end
2 changes: 2 additions & 0 deletions app/forms/custom_fields/inputs/base/input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class CustomFields::Inputs::Base::Input < ApplicationForm
attr_reader :options

def initialize(custom_field:, object:, **options)
super()

@custom_field = custom_field
@object = object
@options = options
Expand Down
10 changes: 6 additions & 4 deletions app/forms/custom_fields/inputs/multi_select_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,18 @@ class CustomFields::Inputs::MultiSelectList < CustomFields::Inputs::Base::Autoco
# autocompleter does not set key with blank value if nothing is selected or input is cleared
# in order to let acts_as_customizable handle the clearing of the value, we need to set the value to blank via a hidden field
# which sends blank if autocompleter is cleared
custom_value_form.hidden(**input_attributes.merge(
custom_value_form.hidden(
**input_attributes,
scope_name_to_model: false,
name: "#{@object.class.name.downcase}[custom_field_values][#{input_attributes[:name]}][]",
name: "#{@object.model_name.element}[custom_field_values][#{input_attributes[:name]}][]",
value:
))
)

custom_value_form.autocompleter(**input_attributes) do |list|
@custom_field.custom_options.each do |custom_option|
list.option(
label: custom_option.value, value: custom_option.id,
label: custom_option.value,
value: custom_option.id,
selected: selected?(custom_option)
)
end
Expand Down
7 changes: 4 additions & 3 deletions app/forms/custom_fields/inputs/multi_user_select_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ class CustomFields::Inputs::MultiUserSelectList < CustomFields::Inputs::Base::Au
# autocompleter does not set key with blank value if nothing is selected or input is cleared
# in order to let acts_as_customizable handle the clearing of the value, we need to set the value to blank via a hidden field
# which sends blank if autocompleter is cleared
custom_value_form.hidden(**input_attributes.merge(
custom_value_form.hidden(
**input_attributes,
scope_name_to_model: false,
name: "#{@object.class.name.downcase}[custom_field_values][#{input_attributes[:name]}][]",
name: "#{@object.model_name.element}[custom_field_values][#{input_attributes[:name]}][]",
value:
))
)

custom_value_form.autocompleter(**input_attributes)
end
Expand Down
10 changes: 6 additions & 4 deletions app/forms/custom_fields/inputs/multi_version_select_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,18 @@ class CustomFields::Inputs::MultiVersionSelectList < CustomFields::Inputs::Base:
# autocompleter does not set key with blank value if nothing is selected or input is cleared
# in order to let acts_as_customizable handle the clearing of the value, we need to set the value to blank via a hidden field
# which sends blank if autocompleter is cleared
custom_value_form.hidden(**input_attributes.merge(
custom_value_form.hidden(
**input_attributes,
scope_name_to_model: false,
name: "#{@object.class.name.downcase}[custom_field_values][#{input_attributes[:name]}][]",
name: "#{@object.model_name.element}[custom_field_values][#{input_attributes[:name]}][]",
value:
))
)

custom_value_form.autocompleter(**input_attributes) do |list|
assignable_custom_field_values(@custom_field).each do |version|
list.option(
label: version.name, value: version.id,
label: version.name,
value: version.id,
selected: selected?(version)
)
end
Expand Down
65 changes: 8 additions & 57 deletions app/forms/projects/custom_fields/form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@
#++
module Projects::CustomFields
class Form < ApplicationForm
include CustomFields::CustomFieldRendering

form do |custom_fields_form|
custom_fields.each do |custom_field|
custom_fields_form.fields_for(:custom_field_values) do |builder|
custom_field_input(builder, custom_field)
end
end
render_custom_fields(form: custom_fields_form)
end

def initialize(project:, custom_field_section: nil, custom_field: nil, wrapper_id: nil)
Expand All @@ -48,6 +46,11 @@ def initialize(project:, custom_field_section: nil, custom_field: nil, wrapper_i
end
end

# override since we want to add the model with @project
def additional_custom_field_input_arguments
{ model: @project, wrapper_id: @wrapper_id }
end

private

def custom_fields
Expand All @@ -62,57 +65,5 @@ def custom_fields
@project.available_custom_fields
end
end

def custom_field_input(builder, custom_field)
if custom_field.multi_value?
multi_value_custom_field_input(builder, custom_field)
else
single_value_custom_field_input(builder, custom_field)
end
end

# TBD: transform inputs called below to primer form dsl instead of form classes?
# TODOS:
# - initial values for user inputs are not displayed
# - allow/disallow-non-open version setting is not yet respected in the version selector
# - rich text editor is not yet supported

def single_value_custom_field_input(builder, custom_field)
form_args = { custom_field:, object: @project, wrapper_id: @wrapper_id }

case custom_field.field_format
when "string", "link"
CustomFields::Inputs::String.new(builder, **form_args)
when "text"
CustomFields::Inputs::Text.new(builder, **form_args)
when "int"
CustomFields::Inputs::Int.new(builder, **form_args)
when "float"
CustomFields::Inputs::Float.new(builder, **form_args)
when "list"
CustomFields::Inputs::SingleSelectList.new(builder, **form_args)
when "date"
CustomFields::Inputs::Date.new(builder, **form_args)
when "bool"
CustomFields::Inputs::Bool.new(builder, **form_args)
when "user"
CustomFields::Inputs::SingleUserSelectList.new(builder, **form_args)
when "version"
CustomFields::Inputs::SingleVersionSelectList.new(builder, **form_args)
end
end

def multi_value_custom_field_input(builder, custom_field)
form_args = { custom_field:, object: @project, wrapper_id: @wrapper_id }

case custom_field.field_format
when "list"
CustomFields::Inputs::MultiSelectList.new(builder, **form_args)
when "user"
CustomFields::Inputs::MultiUserSelectList.new(builder, **form_args)
when "version"
CustomFields::Inputs::MultiVersionSelectList.new(builder, **form_args)
end
end
end
end
44 changes: 44 additions & 0 deletions frontend/src/stimulus/controllers/dynamic/time-entry.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* -- copyright
* OpenProject is an open source project management software.
* Copyright (C) the OpenProject GmbH
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 3.
*
* OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
* Copyright (C) 2006-2013 Jean-Philippe Lang
* Copyright (C) 2010-2013 the ChiliProject Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* See COPYRIGHT and LICENSE files for more details.
* ++
*/

import { Controller } from '@hotwired/stimulus';

export default class TimeEntryController extends Controller {
static targets = ['startTimeInput', 'endTimeInput', 'hoursInput'];

declare readonly startTimeInputTarget:HTMLInputElement;
declare readonly endTimeInputTarget:HTMLInputElement;
declare readonly choursInputTarget:HTMLInputElement;

startTimeInputTargetConnected() {
// console.log('We have a start input');
this.startTimeInputTarget.value = '12:00';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<%= render(Primer::Alpha::Dialog.new(title: 'Log Time', size: :large, id: MODAL_ID, data: { "controller" => "time-entry", "application-target" => "dynamic" })) do |d| %>
<% d.with_header(variant: :large, mb: 3) %>
<%= render(TimeEntries::TimeEntryFormComponent.new(time_entry: time_entry)) %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# frozen_string_literal: true

# -- copyright
# OpenProject is an open source project management software.
# Copyright (C) the OpenProject GmbH
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2013 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See COPYRIGHT and LICENSE files for more details.
# ++

module TimeEntries
class EntryDialogComponent < ApplicationComponent
include OpTurbo::Streamable

MODAL_ID = "time-entry-dialog"

def initialize(time_entry:, open: false)
super()
@time_entry = time_entry
@open = open
end

private

attr_reader :time_entry, :open
end
end
Loading
Loading